Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implementation of targetConstraint extension #1066

Open
samturneradha opened this issue Nov 27, 2024 · 3 comments
Open

Implementation of targetConstraint extension #1066

samturneradha opened this issue Nov 27, 2024 · 3 comments

Comments

@samturneradha
Copy link

Is your feature request related to a problem? Please describe.

In our Questionnaire we are collecting blood pressure values. We would like a typo checking mechanism to have the ability for the Questionnaire to give a warning prompt when the value of systolic is less than the value for diastolic.

Describe the solution you'd like

The use of the extension: https://www.hl7.org/fhir/extensions/5.1.0/StructureDefinition-targetConstraint.html looks like it would be a good fit. As it states a context of use:

Element ID Questionnaire
Element ID Questionnaire.item

Describe alternatives you've considered
N/A as yet- preference for targetConstraint

Additional context
The below is the example that I have tried in the playground renderer:

{
"resourceType": "Questionnaire",
"id": "example-questionnaire",
"status": "active",
"subjectType": ["Patient"],
"item": [
{
"linkId": "1.1",
"text": "Systolic Blood Pressure",
"type": "integer"
},
{
"linkId": "1.2",
"text": "Diastolic Blood Pressure",
"type": "integer"
}
],
"extension": [
{
"url": "http://hl7.org/fhir/StructureDefinition/targetConstraint",
"extension": [
{
"url": "key",
"valueId": "bp-constraint"
},
{
"url": "severity",
"valueCode": "warning"
},
{
"url": "expression",
"valueExpression": {
"language": "text/fhirpath",
"expression": "%resource.item.where(linkId='1.1').answer.value < %resource.item.where(linkId='1.2').answer.value"
}
},
{
"url": "human",
"valueString": "Systolic blood pressure should not be less than diastolic blood pressure."
}
]
}
]
}

@fongsean
Copy link
Collaborator

@samturneradha

Resolved as of v1.0.0-alpha.22! Try it out at https://alpha.smartforms.io/playground

If the target contraint's FHIRPath expression is evaluated as true, the renderer's internal TargetConstraint's state will have isEnabled = true and vice versa. That isEnabled prop will be used to drive whether or not it generates a validation error.

If the value is invalid (aka isEnabled = true), it should show up in QuestionnaireResponseStore's invalidItems as an invariant error.

Now, if you add a locationproperty in your extension, you can trigger an error message to appear in the UI. In this example, Systolic Blood Pressure is at Questionnaire.item[0]. Unfortunately it takes lots of work to make it yellow for warnings, so all validation errors will be standardized as red.

Feel free to close the issue if if looks ok on your end.

Advanced properties in case you are interested:
Input Questionnaire:

{
  "resourceType": "Questionnaire",
  "id": "example-questionnaire",
  "status": "active",
  "subjectType": [
    "Patient"
  ],
  "item": [
    {
      "linkId": "1.1",
      "text": "Systolic Blood Pressure",
      "type": "integer"
    },
    {
      "linkId": "1.2",
      "text": "Diastolic Blood Pressure",
      "type": "integer"
    }
  ],
  "extension": [
    {
      "url": "http://hl7.org/fhir/StructureDefinition/targetConstraint",
      "extension": [
        {
          "url": "key",
          "valueId": "bp-constraint"
        },
        {
          "url": "severity",
          "valueCode": "warning"
        },
        {
          "url": "expression",
          "valueExpression": {
            "language": "text/fhirpath",
            "expression": "%resource.item.where(linkId='1.1').answer.value < %resource.item.where(linkId='1.2').answer.value"
          }
        },
        {
          "url": "human",
          "valueString": "Systolic blood pressure should not be less than diastolic blood pressure."
        },
        // newly added
        {
          "url": "location", 
          "valueString": "Questionnaire.item[0]"
        }
      ]
    }
  ]
}

QuestionnaireStore TargetConstraints:

{
  "bp-constraint": {
    "key": "bp-constraint",
    "severityCode": "warning",
    "valueExpression": {
      "language": "text/fhirpath",
      "expression": "%resource.item.where(linkId='1.1').answer.value < %resource.item.where(linkId='1.2').answer.value"
    },
    "human": "Systolic blood pressure should not be less than diastolic blood pressure.",
    "location": "Questionnaire.item[0]",
    "isEnabled": true, // will be false or empty if FHIRPath expression doesn't satisfy
    "linkId": "1.1"
  }
}

QuestionnaireResponseStore InvalidItems:

{
  "1.1": {
    "resourceType": "OperationOutcome",
    "issue": [
      {
        "severity": "error",
        "code": "business-rule",
        "expression": [
          "%resource.item.where(linkId='1.1').answer.value < %resource.item.where(linkId='1.2').answer.value at Questionnaire.item[0]"
        ],
        "details": {
          "coding": [
            {
              "system": "http://fhir.forms-lab.com/CodeSystem/errors",
              "code": "invariant"
            }
          ]
        }
      }
    ]
  }
}

@samturneradha
Copy link
Author

That's awesome. Thank you so much for this Sean, I will get to experimenting with this.

@samturneradha
Copy link
Author

Hi Sean,
I was wondering if you might be able to shed some light on a question for me? We were hoping to utilise TargetConstraint to also further flesh out human readable responses to situations where regex rules are invalidated by user input. As opposed to the standard repetition of the rule which isnt very human readable. I am having trouble finding examples of regex being nested in TargetConstraint but I believe it can be done. Sorry to trouble you but is this something you could look at when you have time?
Thank you

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants