Skip to content

Commit

Permalink
FM2-638: Mapping OpenMRS Drug Order instructions to FHIR Dosage instr…
Browse files Browse the repository at this point in the history
…uctions
  • Loading branch information
mogoodrich committed Aug 13, 2024
1 parent 98c713f commit da2e53e
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import lombok.AccessLevel;
import lombok.Setter;
import org.hl7.fhir.r4.model.BooleanType;
import org.hl7.fhir.r4.model.CodeableConcept;
import org.hl7.fhir.r4.model.Coding;
import org.hl7.fhir.r4.model.Dosage;
import org.hl7.fhir.r4.model.Quantity;
Expand Down Expand Up @@ -51,6 +52,12 @@ public Dosage toFhirResource(@Nonnull DrugOrder drugOrder) {
dosage.setRoute(conceptTranslator.toFhirResource(drugOrder.getRoute()));
dosage.setTiming(timingTranslator.toFhirResource(drugOrder));

if (drugOrder.getInstructions() != null) {
CodeableConcept additionalInstructions = new CodeableConcept();
additionalInstructions.setText(drugOrder.getInstructions());
dosage.addAdditionalInstruction(additionalInstructions);
}

if (drugOrder.getDose() != null) {
Dosage.DosageDoseAndRateComponent doseAndRate = new Dosage.DosageDoseAndRateComponent();
Quantity dose = new SimpleQuantity();
Expand All @@ -73,6 +80,11 @@ public Dosage toFhirResource(@Nonnull DrugOrder drugOrder) {
@Override
public DrugOrder toOpenmrsType(@Nonnull DrugOrder drugOrder, @Nonnull Dosage dosage) {
drugOrder.setDosingInstructions(dosage.getText());

if (!dosage.getAdditionalInstruction().isEmpty()) {
drugOrder.setInstructions(dosage.getAdditionalInstructionFirstRep().getText());
}

if (dosage.getAsNeededBooleanType() != null) {
drugOrder.setAsNeeded(dosage.getAsNeededBooleanType().getValue());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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));
}
}

0 comments on commit da2e53e

Please sign in to comment.