cqframework / cqf-ruler

FHIR Clinical Reasoning Module Server
Apache License 2.0
64 stars 49 forks source link

Missing Dosage Instruction Error #30

Closed jeffeastman closed 2 years ago

jeffeastman commented 6 years ago

When I post this:

{
    "hook": "medication-prescribe",
    "hookInstance": "5bacb720-f493-4fe7-8750-c02595cbb72b",
    "fhirServer": "http://localhost:8081/cqf-ruler/baseDstu3/",
    "user": "Practitioner-2516",
    "patient": "Patient-1121",
    "context": [
        {
            "resourceType": "MedicationRequest",
            "status": "active",
            "medicationCodeableConcept": {
                "coding": [
                    {
                        "system": "http://www.nlm.nih.gov/research/umls/rxnorm",
                        "code": "197696",
                        "display": "Fentanyl 75 MCG/HR 3 Day Transdermal Patch"
                    }
                ]
            },
            "subject": {
                "reference": "Patient/Patient-1121",
                "display": "Jerry Phillip Goodwall [80]"
            },
            "authoredOn": "2017-01-01T00:00:00-05:00",
            "reasonCode": [
                {
                    "coding": [
                        {
                            "system": "http://snomed.info/sct",
                            "code": "82423001",
                            "display": "Chronic pain"
                        }
                    ],
                    "text": "Chronic pain"
                }
            ],
            "dosageInstruction": [
                {
                    "text": "Apply once every three days for pain.",
                    "timing": {
                        "repeat": {
                            "count": 1,
                            "durationUnit": "d",
                            "frequency": 1,
                            "period": 3
                        }
                    },
                    "asNeededBoolean": false,
                    "doseQuantity": {
                        "value": 1,
                        "unit": "tbl",
                        "system": "http://unitsofmeasure.org",
                        "code": "tbl"
                    }
                }
            ],
            "dispenseRequest": {
                "quantity": {
                    "value": 30,
                    "unit": "day",
                    "system": "http://unitsofmeasure.org",
                    "code": "d"
                }
            }
        }
    ]
}

I get this e500 error:

[WARNING] /cqf-ruler/cds-services/cdc-opioid-guidance
java.lang.RuntimeException: Missing dosageInstruction structure in prescription http://localhost:8081/cqf-ruler/baseDstu3/MedicationRequest/MedicationRequest-667190/_history/1
    at org.opencds.cqf.cds.OpioidGuidanceProcessor.validateContextAndPrefetchResources(OpioidGuidanceProcessor.java:124)
    at org.opencds.cqf.cds.OpioidGuidanceProcessor.process(OpioidGuidanceProcessor.java:76)
    at org.opencds.cqf.servlet.CdsServicesServlet.doPost(CdsServicesServlet.java:95)
    at ca.uhn.fhir.rest.server.RestfulServer.service(RestfulServer.java:1435)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:790)
    at org.eclipse.jetty.servlet.ServletHolder.handle(ServletHolder.java:841)
    at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1650)
jeffeastman commented 6 years ago

I also get the same error with:

{
    "hook": "medication-prescribe",
    "hookInstance": "5bacb720-f493-4fe7-8750-c02595cbb72b",
    "fhirServer": "http://localhost:8081/cqf-ruler/baseDstu3/",
    "user": "Practitioner-2516",
    "patient": "Patient-1121",
    "context": [
        {
            "resourceType": "MedicationRequest",
            "status": "active",
            "medicationCodeableConcept": {
                "coding": [
                    {
                        "system": "http://www.nlm.nih.gov/research/umls/rxnorm",
                        "code": "1791566",
                        "display": "Abuse-Deterrent 12 HR oxyCODONE 18 MG Extended Release Oral Capsule"
                    }
                ]
            },
            "subject": {
                "reference": "Patient/Patient-1121",
                "display": "Jerry Phillip Goodwall [80]"
            },
            "authoredOn": "2017-01-01T00:00:00-05:00",
            "reasonCode": [
                {
                    "coding": [
                        {
                            "system": "http://snomed.info/sct",
                            "code": "82423001",
                            "display": "Chronic pain"
                        }
                    ],
                    "text": "Chronic pain"
                }
            ],
            "dosageInstruction": [
                {
                    "text": "Take one capsule twice daily",
                    "timing": {
                        "repeat": {
                            "count": 1,
                            "durationUnit": "d",
                            "frequency": 2,
                            "period": 1
                        }
                    },
                    "asNeededBoolean": false,
                    "doseQuantity": {
                        "value": 18,
                        "unit": "mg",
                        "system": "http://unitsofmeasure.org",
                        "code": "mg"
                    }
                }
            ],
            "dispenseRequest": {
                "quantity": {
                    "value": 30,
                    "unit": "day",
                    "system": "http://unitsofmeasure.org",
                    "code": "d"
                }
            }
        }
    ]
}
jeffeastman commented 6 years ago

These are with the latest cqf-ruler built today

jeffeastman commented 6 years ago

Offhand, it looks like the prefetch is required for some reason, because all the tests with them like this work:

{
    "hook": "medication-prescribe",
    "hookInstance": "5bacb720-f493-4fe7-8750-c02595cbb72b",
    "fhirServer": "http://localhost:8081/cqf-ruler/baseDstu3/",
    "user": "Practitioner-2516",
    "patient": "Patient-1121",
    "context": [
        {
            "resourceType": "MedicationRequest",
            "status": "active",
            "medicationCodeableConcept": {
                "coding": [
                    {
                        "system": "http://www.nlm.nih.gov/research/umls/rxnorm",
                        "code": "197696",
                        "display": "Fentanyl 75 MCG/HR 3 Day Transdermal Patch"
                    }
                ]
            },
            "subject": {
                "reference": "Patient/Patient-1121",
                "display": "Jerry Phillip Goodwall [80]"
            },
            "authoredOn": "2017-01-01T00:00:00-05:00",
            "reasonCode": [
                {
                    "coding": [
                        {
                            "system": "http://snomed.info/sct",
                            "code": "82423001",
                            "display": "Chronic pain"
                        }
                    ],
                    "text": "Chronic pain"
                }
            ],
            "dosageInstruction": [
                {
                    "text": "Apply once every three days for pain.",
                    "timing": {
                        "repeat": {
                            "count": 1,
                            "durationUnit": "d",
                            "frequency": 1,
                            "period": 3
                        }
                    },
                    "asNeededBoolean": false,
                    "doseQuantity": {
                        "value": 1,
                        "unit": "tbl",
                        "system": "http://unitsofmeasure.org",
                        "code": "tbl"
                    }
                }
            ],
            "dispenseRequest": {
                "quantity": {
                    "value": 30,
                    "unit": "day",
                    "system": "http://unitsofmeasure.org",
                    "code": "d"
                }
            }
        }
    ],
    "prefetch": {
        "medication": {
            "resource": {
                "resourceType": "Bundle",
                "entry": [
                    {
                        "resource": {
                            "resourceType": "MedicationRequest",
                            "status": "active",
                            "medicationCodeableConcept": {
                                "coding": [
                                    {
                                        "system": "http://www.nlm.nih.gov/research/umls/rxnorm",
                                        "code": "197696",
                                        "display": "Fentanyl 75 MCG/HR 3 Day Transdermal Patch"
                                    }
                                ]
                            },
                            "subject": {
                                "reference": "Patient/Patient-1121",
                                "display": "Jerry Phillip Goodwall [80]"
                            },
                            "authoredOn": "2017-01-01T00:00:00-05:00",
                            "reasonCode": [
                                {
                                    "coding": [
                                        {
                                            "system": "http://snomed.info/sct",
                                            "code": "82423001",
                                            "display": "Chronic pain"
                                        }
                                    ],
                                    "text": "Chronic pain"
                                }
                            ],
                            "dosageInstruction": [
                                {
                                    "text": "Apply once every three days for pain.",
                                    "timing": {
                                        "repeat": {
                                            "count": 1,
                                            "durationUnit": "d",
                                            "frequency": 1,
                                            "period": 3
                                        }
                                    },
                                    "asNeededBoolean": false,
                                    "doseQuantity": {
                                        "value": 1,
                                        "unit": "tbl",
                                        "system": "http://unitsofmeasure.org",
                                        "code": "tbl"
                                    }
                                }
                            ],
                            "dispenseRequest": {
                                "quantity": {
                                    "value": 30,
                                    "unit": "day",
                                    "system": "http://unitsofmeasure.org",
                                    "code": "d"
                                }
                            }
                        }
                    }
                ]
            }
        }
    }
}
jeffeastman commented 6 years ago

And patient Jerry Goodwall has only 1 non-opioid Rx in the database (histories 15, I think). And that Rx doesn't have a dosageInstruction. So perhaps this is the issue?

{
  "resourceType": "Bundle",
  "id": "4ef72cd1-3466-4b19-97b5-98aa84657a54",
  "meta": {
    "lastUpdated": "2018-01-17T13:32:48.972-05:00"
  },
  "type": "searchset",
  "total": 1,
  "link": [
    {
      "relation": "self",
      "url": "http://localhost:8081/cqf-ruler/baseDstu3/MedicationRequest?_pretty=true&patient=Patient%2FPatient-1121"
    }
  ],
  "entry": [
    {
      "fullUrl": "http://localhost:8081/cqf-ruler/baseDstu3/MedicationRequest/MedicationRequest-667190",
      "resource": {
        "resourceType": "MedicationRequest",
        "id": "MedicationRequest-667190",
        "meta": {
          "versionId": "1",
          "lastUpdated": "2018-01-17T12:28:45.877-05:00",
          "profile": [
            "http://hl7.org/fhir/us/hedis/StructureDefinition/hedis-medicationrequest"
          ]
        },
        "extension": [
          {
            "url": "http://mihin.org/extension/copyright",
            "valueString": "Copyright 2014-2017 Michigan Health Information Network Shared Services. Licensed under the Apache License, Version 2.0 (the 'License'); you may not use this file except in compliance with the License. You may obtain a copy of the License at  http://www.apache.org/licenses/LICENSE-2.0.  Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an 'AS IS' BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License."
          }
        ],
        "status": "active",
        "intent": "order",
        "medicationCodeableConcept": {
          "coding": [
            {
              "system": "http://test",
              "code": "Antidepressant.Medication",
              "display": "Antidepressant Medication"
            }
          ]
        },
        "subject": {
          "reference": "Patient/Patient-1121",
          "display": "Jerry Phillip Goodwall"
        },
        "context": {
          "reference": "Encounter/Encounter-3607",
          "display": "DMS_Followup_Encounter"
        },
        "authoredOn": "2017-03-20T01:00:00-04:00",
        "reasonCode": [
          {
            "coding": [
              {
                "system": "http://snomed.info/sct",
                "code": "310495003",
                "display": "Mild depression (disorder)"
              }
            ]
          }
        ]
      },
      "search": {
        "mode": "match"
      }
    }
  ]
}
jeffeastman commented 6 years ago

Once I modified the above MedicationRequest with proper coding and with a dosageInstruction, all of the Hook tests for Jerry passed. Seems like the code might be a little more forgiving because dosageInstruction is an optional field in the resource.

So leaving this open.

c-schuler commented 6 years ago

Although dosageInstruction is an optional field in the base FHIR MedicationRequest resource, it is required when using the opioidcds MedicationRequest profile, which is what the Ruler is expecting. So there is a limitation when not including the prefetch data in the response: all other active medications in the FHIR server for the patient must conform to the opioidcds profile. An optional approach would be for the Ruler to ensure that the fetched medications reference the opioidcds profile before including them for evaluation. While that is probably a more desirable approach, it gets a little sticky when DSTU2 MedicationOrders, which is still the standard for most EHR's, are used as the opioidcds profiles are STU3.

jeffeastman commented 6 years ago

For curated test data, the limitation can be worked around. For a practical database, however, the optional approach would be the only way forward since the dosageInstruction is optional.

DosageInstructions are optional in DSTU2 as well.

c-schuler commented 6 years ago

Agreed. I will add a check that only includes medications with a reference to the opioidcds profile for evaluation. I will try to resolve this issue before the connectathon this weekend. Thanks Jeff.

jeffeastman commented 6 years ago

Let me know when the fix is in. I can easily test it.

JPercival commented 2 years ago

Closing as wontfix, due to us only supporting >=DSTU3