aehrc / smart-forms

React-based form renderer implementing Structured Data Capture (SDC) FHIR specification
https://smartforms.csiro.au
Apache License 2.0
36 stars 16 forks source link

Add extractObservationBased functionallity #988

Closed ryuuzake closed 1 month ago

ryuuzake commented 2 months ago

Closes #976

Sorry for no update for a long time. I made the code to recursively extract all the results into Observation. I think the code needs many refactor to match the project structure. I would change it based on your review @fongsean

fongsean commented 1 month ago

Thanks @ryuuzake. I'll have a look soon.

ryuuzake commented 1 month ago

@fongsean please don't merge this PR yet. I still need to fix some bugs

lamurian commented 1 month ago

There's an issue that we're currently checking on. Per FHIR SDC specification, the questionnaire item is extracted only if it contains sdc-questionnaire-observationExtract extension set as true. Currently, we extract any item included in the Questionnaire resource, which does not completely comply with FHIR SDC.

Reiterating through the conceptual algorithm in SDC specification:


For testing purpose, I included a questionnaire.json file. This resource contains a PHQ-2 instrument, which consists of two questions about depression. After implementing this conceptual algorithm, @ryuuzake and I will follow this testing procedure:

  1. Render questionnaire.json in Smart Forms Playground
  2. Fill in all questions
  3. Click extract

Case 1:

Case 2:

Case 3:

Questionnaire resource: questionnaire.json

Flat text of the questionnaire resource Use this if the attachment above is not accessible. ```json { "resourceType": "Questionnaire", "id": "phq-2-questionnaire", "meta": { "versionId": "1", "lastUpdated": "2024-09-06T15:33:00Z" }, "title": "PHQ-2 Depression Screening", "status": "active", "date": "2024-08-29T12:00:00Z", "publisher": "Konsulin", "description": "Patient Health Questionnaire-2 (PHQ-2) for depression screening.", "subjectType": [ "Patient" ], "item": [ { "linkId": "phq2-1", "text": "Over the last 2 weeks, how often have you been bothered by little interest or pleasure in doing things?", "type": "choice", "code": [ { "system": "http://snomed.info/sct", "code": "28669007", "display": "Anhedonia" } ], "answerOption": [ { "valueCoding": { "code": "0", "display": "Not at all" } }, { "valueCoding": { "code": "1", "display": "Several days" } }, { "valueCoding": { "code": "2", "display": "More than half the days" } }, { "valueCoding": { "code": "3", "display": "Nearly every day" } } ], "extension": [ { "url": "http://hl7.org/fhir/uv/sdc/StructureDefinition/sdc-questionnaire-observationExtract", "valueBoolean": true } ] }, { "linkId": "phq2-2", "text": "Over the last 2 weeks, how often have you been bothered by feeling down, depressed, or hopeless?", "type": "choice", "code": [ { "system": "http://snomed.info/sct", "code": "307077003", "display": "Feeling hopeless" } ], "answerOption": [ { "valueCoding": { "code": "0", "display": "Not at all" } }, { "valueCoding": { "code": "1", "display": "Several days" } }, { "valueCoding": { "code": "2", "display": "More than half the days" } }, { "valueCoding": { "code": "3", "display": "Nearly every day" } } ], "extension": [ { "url": "http://hl7.org/fhir/uv/sdc/StructureDefinition/sdc-questionnaire-observationExtract", "valueBoolean": true } ] } ] } ```
ryuuzake commented 1 month ago

Hi @fongsean thanks for the wait. I already fix the bugs and confirm with @lamurian

fongsean commented 1 month ago

Hi both, thanks for validating with the SDC spec and putting in work to address the issues.

Code looks amazing - happy that @ryuuzake is using the generic recursive function for traversal. There are many use cases in the codebase which I previously written that can adopt it.

I've added two comments. I'll resolve my part and push it to your branch again. Other parts looks great. Once we resolve these two things, I will publish v0.40.0 and merge it into main.

Thanks!

ryuuzake commented 1 month ago

Hi @fongsean, I already integrate your changes to my PR