From d17459aeef95d87c61b01aa33c301e53aca27869 Mon Sep 17 00:00:00 2001 From: manimaarans <110804183+manimaarans@users.noreply.github.com> Date: Thu, 9 Nov 2023 11:11:18 +0530 Subject: [PATCH] BS 288 | Mani| throw mismatched exceptions when dose unit doesn't match (#9) * BS 288 | Mani| throw mismatched exceptions when dose unit doesn't match * BS-288 | Mani | Addressed feedback comments * BS-288| Mani | added property to include error message on the responses * BS-288| Mani | updated the error message thrown * BS-288 | Mani | Updated the error message based on desk check comments * BS-288 | Mani | consolidated error messages together --- ...omedMedicationDefinedDailyDoseService.java | 39 +++++++-- src/main/resources/application.properties | 3 + .../MedicationOrderSelectCDSServiceTest.java | 13 +++ ...cationRequestBundleWithMismatchedDoseUnits | 82 +++++++++++++++++++ 4 files changed, 128 insertions(+), 9 deletions(-) create mode 100644 src/test/resources/medication-order-select/MedicationRequestBundleWithMismatchedDoseUnits diff --git a/src/main/java/org/snomed/cdsservice/service/medication/dose/SnomedMedicationDefinedDailyDoseService.java b/src/main/java/org/snomed/cdsservice/service/medication/dose/SnomedMedicationDefinedDailyDoseService.java index 53fb389..7af63d8 100644 --- a/src/main/java/org/snomed/cdsservice/service/medication/dose/SnomedMedicationDefinedDailyDoseService.java +++ b/src/main/java/org/snomed/cdsservice/service/medication/dose/SnomedMedicationDefinedDailyDoseService.java @@ -4,16 +4,25 @@ import net.steppschuh.markdowngenerator.list.UnorderedList; import net.steppschuh.markdowngenerator.text.Text; import org.apache.commons.lang3.StringUtils; -import org.hl7.fhir.r4.model.*; +import org.hl7.fhir.r4.model.Coding; +import org.hl7.fhir.r4.model.Dosage; +import org.hl7.fhir.r4.model.MedicationRequest; +import org.hl7.fhir.r4.model.Quantity; +import org.hl7.fhir.r4.model.Timing; import org.jetbrains.annotations.NotNull; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import org.snomed.cdsservice.model.*; +import org.snomed.cdsservice.model.AggregatedMedicationsBySubstance; +import org.snomed.cdsservice.model.CDSCard; +import org.snomed.cdsservice.model.CDSCoding; +import org.snomed.cdsservice.model.CDSIndicator; +import org.snomed.cdsservice.model.CDSReference; +import org.snomed.cdsservice.model.CDSSource; +import org.snomed.cdsservice.model.DosageComparisonByRoute; +import org.snomed.cdsservice.model.PrescribedDailyDose; import org.snomed.cdsservice.service.ArgumentAssertionUtil; import org.snomed.cdsservice.service.ServiceException; -import org.snomed.cdsservice.service.medication.dose.MedicationDoseFormsLoaderService; import org.snomed.cdsservice.service.model.ManyToOneMapEntry; -import org.snomed.cdsservice.service.medication.dose.SubstanceDefinedDailyDose; import org.snomed.cdsservice.service.tsclient.ConceptParameters; import org.snomed.cdsservice.service.tsclient.FHIRTerminologyServerClient; import org.snomed.cdsservice.service.tsclient.SnomedConceptNormalForm; @@ -21,14 +30,22 @@ import org.snomed.cdsservice.util.UnitConversion; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; +import org.springframework.http.HttpStatus; import org.springframework.stereotype.Service; +import org.springframework.web.server.ResponseStatusException; import java.io.BufferedReader; import java.io.FileReader; import java.math.BigDecimal; import java.text.DecimalFormat; import java.text.MessageFormat; -import java.util.*; +import java.util.ArrayList; +import java.util.Collections; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Optional; +import java.util.UUID; import java.util.stream.Collectors; import static java.lang.String.format; @@ -266,10 +283,14 @@ private void aggregateMedicationsBySubstance(Mapservice.call(cdsRequest) ); + } + private ConceptParameters getConceptParamsForDoseUnitMg() { String response = "{\"resourceType\":\"Parameters\",\"parameter\":[{\"name\":\"code\",\"valueString\":\"258684004\"},{\"name\":\"display\",\"valueString\":\"mg\"},{\"name\":\"name\",\"valueString\":\"SNOMED CT release 2023-05-31\"},{\"name\":\"system\",\"valueString\":\"http://snomed.info/sct\"},{\"name\":\"version\",\"valueString\":\"http://snomed.info/sct/900000000000207008/version/20230531\"},{\"name\":\"inactive\",\"valueBoolean\":false},{\"name\":\"property\",\"part\":[{\"name\":\"code\",\"valueString\":\"effectiveTime\"},{\"name\":\"valueString\",\"valueString\":\"20020131\"}]},{\"name\":\"property\",\"part\":[{\"name\":\"code\",\"valueString\":\"moduleId\"},{\"name\":\"value\",\"valueCode\":\"900000000000207008\"}]},{\"name\":\"property\",\"part\":[{\"name\":\"code\",\"valueString\":\"inactive\"},{\"name\":\"valueBoolean\",\"valueString\":\"false\"}]},{\"name\":\"property\",\"part\":[{\"name\":\"code\",\"valueString\":\"sufficientlyDefined\"},{\"name\":\"valueBoolean\",\"valueString\":\"false\"}]},{\"name\":\"property\",\"part\":[{\"name\":\"code\",\"valueString\":\"normalFormTerse\"},{\"name\":\"valueString\",\"valueString\":\"258681007\"}]},{\"name\":\"property\",\"part\":[{\"name\":\"code\",\"valueString\":\"normalForm\"},{\"name\":\"valueString\",\"valueString\":\"258681007|International System of Units unit of mass (qualifier value)|\"}]},{\"extension\":[{\"url\":\"http://snomed.info/fhir/StructureDefinition/designation-use-context\",\"extension\":[{\"url\":\"context\",\"valueCoding\":{\"system\":\"http://snomed.info/sct\",\"code\":\"900000000000509007\"}},{\"url\":\"role\",\"valueCoding\":{\"system\":\"http://snomed.info/sct\",\"code\":\"900000000000548007\",\"display\":\"PREFERRED\"}},{\"url\":\"type\",\"valueCoding\":{\"system\":\"http://snomed.info/sct\",\"code\":\"900000000000003001\",\"display\":\"Fully specified name\"}}]},{\"url\":\"http://snomed.info/fhir/StructureDefinition/designation-use-context\",\"extension\":[{\"url\":\"context\",\"valueCoding\":{\"system\":\"http://snomed.info/sct\",\"code\":\"900000000000508004\"}},{\"url\":\"role\",\"valueCoding\":{\"system\":\"http://snomed.info/sct\",\"code\":\"900000000000548007\",\"display\":\"PREFERRED\"}},{\"url\":\"type\",\"valueCoding\":{\"system\":\"http://snomed.info/sct\",\"code\":\"900000000000003001\",\"display\":\"Fully specified name\"}}]}],\"name\":\"designation\",\"part\":[{\"name\":\"language\",\"valueCode\":\"en\"},{\"name\":\"use\",\"valueCoding\":{\"system\":\"http://snomed.info/sct\",\"code\":\"900000000000003001\",\"display\":\"Fully specified name\"}},{\"name\":\"value\",\"valueString\":\"milligram (qualifier value)\"}]},{\"extension\":[{\"url\":\"http://snomed.info/fhir/StructureDefinition/designation-use-context\",\"extension\":[{\"url\":\"context\",\"valueCoding\":{\"system\":\"http://snomed.info/sct\",\"code\":\"900000000000509007\"}},{\"url\":\"role\",\"valueCoding\":{\"system\":\"http://snomed.info/sct\",\"code\":\"900000000000548007\",\"display\":\"PREFERRED\"}},{\"url\":\"type\",\"valueCoding\":{\"system\":\"http://snomed.info/sct\",\"code\":\"900000000000013009\",\"display\":\"Synonym\"}}]},{\"url\":\"http://snomed.info/fhir/StructureDefinition/designation-use-context\",\"extension\":[{\"url\":\"context\",\"valueCoding\":{\"system\":\"http://snomed.info/sct\",\"code\":\"900000000000508004\"}},{\"url\":\"role\",\"valueCoding\":{\"system\":\"http://snomed.info/sct\",\"code\":\"900000000000548007\",\"display\":\"PREFERRED\"}},{\"url\":\"type\",\"valueCoding\":{\"system\":\"http://snomed.info/sct\",\"code\":\"900000000000013009\",\"display\":\"Synonym\"}}]}],\"name\":\"designation\",\"part\":[{\"name\":\"language\",\"valueCode\":\"en\"},{\"name\":\"use\",\"valueCoding\":{\"system\":\"http://snomed.info/sct\",\"code\":\"900000000000013009\",\"display\":\"Synonym\"}},{\"name\":\"value\",\"valueString\":\"mg\"}]},{\"extension\":[{\"url\":\"http://snomed.info/fhir/StructureDefinition/designation-use-context\",\"extension\":[{\"url\":\"context\",\"valueCoding\":{\"system\":\"http://snomed.info/sct\",\"code\":\"900000000000509007\"}},{\"url\":\"role\",\"valueCoding\":{\"system\":\"http://snomed.info/sct\",\"code\":\"900000000000549004\",\"display\":\"ACCEPTABLE\"}},{\"url\":\"type\",\"valueCoding\":{\"system\":\"http://snomed.info/sct\",\"code\":\"900000000000013009\",\"display\":\"Synonym\"}}]},{\"url\":\"http://snomed.info/fhir/StructureDefinition/designation-use-context\",\"extension\":[{\"url\":\"context\",\"valueCoding\":{\"system\":\"http://snomed.info/sct\",\"code\":\"900000000000508004\"}},{\"url\":\"role\",\"valueCoding\":{\"system\":\"http://snomed.info/sct\",\"code\":\"900000000000549004\",\"display\":\"ACCEPTABLE\"}},{\"url\":\"type\",\"valueCoding\":{\"system\":\"http://snomed.info/sct\",\"code\":\"900000000000013009\",\"display\":\"Synonym\"}}]}],\"name\":\"designation\",\"part\":[{\"name\":\"language\",\"valueCode\":\"en\"},{\"name\":\"use\",\"valueCoding\":{\"system\":\"http://snomed.info/sct\",\"code\":\"900000000000013009\",\"display\":\"Synonym\"}},{\"name\":\"value\",\"valueString\":\"milligram\"}]},{\"name\":\"property\",\"part\":[{\"name\":\"code\",\"valueString\":\"parent\"},{\"name\":\"value\",\"valueCode\":\"258681007\"}]}]}"; diff --git a/src/test/resources/medication-order-select/MedicationRequestBundleWithMismatchedDoseUnits b/src/test/resources/medication-order-select/MedicationRequestBundleWithMismatchedDoseUnits new file mode 100644 index 0000000..728c5b1 --- /dev/null +++ b/src/test/resources/medication-order-select/MedicationRequestBundleWithMismatchedDoseUnits @@ -0,0 +1,82 @@ +{ + "resourceType": "Bundle", + "id": "be826c54-b905-40fb-bd90-c147a63ae4e8", + "entry": [ + { + "fullUrl": "https://r4.smarthealthit.org/MedicationRequest/5180e54d-0187-494a-9ca9-9dbfcab90ab6", + "resource": { + "resourceType": "MedicationRequest", + "id": "5180e54d-0187-494a-9ca9-9dbfcab90ab6", + "status": "active", + "intent": "order", + "medicationCodeableConcept": { + "coding": [ + { + "system": "http://snomed.info/sct", + "code": "1145419005", + "display": "Atorvastatin (as atorvastatin calcium) 10 mg oral tablet" + }, + { + "system": "http://bahmni.org/cds", + "code": "36939d4e-d325-4819-9c81-91e1a0434f9a", + "display": "Atorvastatin (as atorvastatin calcium) 10 mg oral tablet" + } + ], + "text": "Atorvastatin (as atorvastatin calcium) 10 mg oral tablet" + }, + "subject": { + "reference": "Patient/618b2992-eec7-45c9-8544-12c9f586b78c" + }, + "encounter": { + "reference": "Encounter/8f1950d4-13cc-4ea5-a9d0-855a4f4b9180" + }, + "authoredOn": "2021-01-15T04:59:42+00:00", + "requester": { + "reference": "Practitioner/96333652-ed28-41d3-bb60-d435f478c8ed" + }, + "reasonReference": [ + { + "reference": "Condition/e21522b1-8006-4723-8b8d-bda8a575b87e" + } + ], + "dosageInstruction": [ + { + "sequence": 1, + "timing": { + "repeat": { + "frequency": 3, + "period": 1, + "periodUnit": "mo" + } + }, + "asNeededBoolean": false, + "doseAndRate": [ + { + "type": { + "coding": [ + { + "system": "http://terminology.hl7.org/CodeSystem/dose-rate-type", + "code": "ordered", + "display": "Ordered" + } + ] + }, + "doseQuantity": { + "value": 10, + "unit": "mL" + } + } + ] + } + ] + }, + "search": { + "mode": "match" + }, + "response": { + "status": "200 OK", + "etag": "W/\"4\"" + } + } + ] +}