@@ -78,7 +78,6 @@ func (s *ParticipantDataRepository) CreateParticipantData(participantData models
7878 axonlogger .ErrorLogger .Println ("could not save participant data" , err )
7979 return models.HTTPStatus {Status : http .StatusInternalServerError , Message : http .StatusText (http .StatusInternalServerError )}
8080 }
81-
8281 }
8382
8483 axonlogger .InfoLogger .Println ("Successfully uploaded task data [studyId, userId, taskOrder]:" , participantData .StudyID , participantData .UserID , participantData .TaskOrder )
@@ -143,3 +142,46 @@ func (s *ParticipantDataRepository) GetAllParticipantDataByStudyIdAndTaskOrder(s
143142
144143 return participantData , models.HTTPStatus {Status : http .StatusOK , Message : http .StatusText (http .StatusOK )}
145144}
145+
146+ // GetParticipantDataByStudyIdWithFilters gets all participant data for the given study id with optional metadata filters
147+ // It returns a 200 or 500 status code
148+ // The filters parameter is a map of JSON path keys to values (e.g., map["wasSkipped"]="true")
149+ func (s * ParticipantDataRepository ) GetParticipantDataByStudyIdWithFilters (studyId uint , filters map [string ]string ) ([]models.ParticipantData , models.HTTPStatus ) {
150+ axonlogger .InfoLogger .Println ("PARTICIPANTDATA DATABASE: GetParticipantDataByStudyIdWithFilters()" )
151+
152+ defer func () {
153+ if err := recover (); err != nil {
154+ axonlogger .ErrorLogger .Println ("there was an error getting the participant data list with filters" , err )
155+ }
156+ }()
157+
158+ participantData := []models.ParticipantData {}
159+
160+ // Build the base query
161+ query := `
162+ SELECT user_id, study_id, task_order, participant_type, submitted_at, metadata, data
163+ FROM participant_data
164+ WHERE study_id = ?`
165+
166+ // Create slice to hold query arguments
167+ args := []interface {}{studyId }
168+
169+ // Handle specific filter: wasSkipped
170+ if skippedValue , exists := filters ["wasSkipped" ]; exists {
171+ // Use CAST(... AS CHAR) to convert JSON boolean to string for comparison
172+ query += ` AND metadata->>'$.wasSkipped' = ?`
173+ args = append (args , skippedValue )
174+ }
175+
176+ query += ";"
177+
178+ if httpStatus := baseRepositoryImpl .GetAllBy (
179+ & participantData ,
180+ query ,
181+ args ... ,
182+ ); ! common .HTTPRequestIsSuccessful (httpStatus .Status ) {
183+ return participantData , httpStatus
184+ }
185+
186+ return participantData , models.HTTPStatus {Status : http .StatusOK , Message : http .StatusText (http .StatusOK )}
187+ }
0 commit comments