From 47cc43660303ce4e9e17a2b9e64cd578c37ac753 Mon Sep 17 00:00:00 2001 From: Mark Goodrich Date: Wed, 14 Aug 2024 13:38:50 -0400 Subject: [PATCH] =?UTF-8?q?FM2-638:=20Mapping=20OpenMRS=20Drug=20Order=20i?= =?UTF-8?q?nstructions=20to=20FHIR=20Dosage=20instr=E2=80=A6=20(#548)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../impl/DosageTranslatorImpl.java | 9 +++++++++ .../impl/DosageTranslatorImplTest.java | 20 +++++++++++++++++++ 2 files changed, 29 insertions(+) diff --git a/api/src/main/java/org/openmrs/module/fhir2/api/translators/impl/DosageTranslatorImpl.java b/api/src/main/java/org/openmrs/module/fhir2/api/translators/impl/DosageTranslatorImpl.java index d4d18e788..c3897c2a2 100644 --- a/api/src/main/java/org/openmrs/module/fhir2/api/translators/impl/DosageTranslatorImpl.java +++ b/api/src/main/java/org/openmrs/module/fhir2/api/translators/impl/DosageTranslatorImpl.java @@ -51,6 +51,10 @@ public Dosage toFhirResource(@Nonnull DrugOrder drugOrder) { dosage.setRoute(conceptTranslator.toFhirResource(drugOrder.getRoute())); dosage.setTiming(timingTranslator.toFhirResource(drugOrder)); + if (drugOrder.getInstructions() != null) { + dosage.addAdditionalInstruction().setText(drugOrder.getInstructions()); + } + if (drugOrder.getDose() != null) { Dosage.DosageDoseAndRateComponent doseAndRate = new Dosage.DosageDoseAndRateComponent(); Quantity dose = new SimpleQuantity(); @@ -73,6 +77,11 @@ public Dosage toFhirResource(@Nonnull DrugOrder drugOrder) { @Override public DrugOrder toOpenmrsType(@Nonnull DrugOrder drugOrder, @Nonnull Dosage dosage) { drugOrder.setDosingInstructions(dosage.getText()); + + if (dosage.hasAdditionalInstruction()) { + drugOrder.setInstructions(dosage.getAdditionalInstructionFirstRep().getText()); + } + if (dosage.getAsNeededBooleanType() != null) { drugOrder.setAsNeeded(dosage.getAsNeededBooleanType().getValue()); } diff --git a/api/src/test/java/org/openmrs/module/fhir2/api/translators/impl/DosageTranslatorImplTest.java b/api/src/test/java/org/openmrs/module/fhir2/api/translators/impl/DosageTranslatorImplTest.java index 30bb8d7f5..ef49b265b 100644 --- a/api/src/test/java/org/openmrs/module/fhir2/api/translators/impl/DosageTranslatorImplTest.java +++ b/api/src/test/java/org/openmrs/module/fhir2/api/translators/impl/DosageTranslatorImplTest.java @@ -109,6 +109,14 @@ public void toFhirResource_shouldTranslateDosingInstructionToDosageText() { assertThat(result.getText(), equalTo(DOSING_INSTRUCTION)); } + @Test + public void toFhirResource_shouldTranslateOrdersInstructionToDosageAdditionalInstructions() { + drugOrder.setInstructions(DOSING_INSTRUCTION); + Dosage result = dosageTranslator.toFhirResource(drugOrder); + assertThat(result, notNullValue()); + assertThat(result.getAdditionalInstruction().get(0).getText(), equalTo(DOSING_INSTRUCTION)); + } + @Test public void toFhirResource_shouldTranslateDrugOrderRouteToRoute() { Concept concept = new Concept(); @@ -317,4 +325,16 @@ public void toOpenmrsType_shouldTranslateDoseQuantityUnitsToDrugOrderDoseUnits() assertThat(result, notNullValue()); assertThat(result.getDoseUnits(), equalTo(mg)); } + + @Test + public void toOpenmrsType_shouldTranslateAdditionalInstructionsToOrderInstructions() { + Dosage dosage = new Dosage(); + CodeableConcept additionalInstructions = new CodeableConcept(); + additionalInstructions.setText(DOSING_INSTRUCTION); + dosage.addAdditionalInstruction(additionalInstructions); + + DrugOrder result = dosageTranslator.toOpenmrsType(new DrugOrder(), dosage); + assertThat(result, notNullValue()); + assertThat(result.getInstructions(), equalTo(DOSING_INSTRUCTION)); + } }