Skip to content

Commit

Permalink
FM2-604: Display value should onnly be set for internal codes
Browse files Browse the repository at this point in the history
  • Loading branch information
ibacher committed Jul 12, 2023
1 parent fac5687 commit 7ab2e3a
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public CodeableConcept toFhirResource(@Nonnull Concept concept) {
CodeableConcept codeableConcept = new CodeableConcept();
codeableConcept.setText(concept.getDisplayString());
addConceptCoding(codeableConcept.addCoding(), null, concept.getUuid(), concept);
//map of <systemUrl ,<mapType , code>> ie { "http://loinc.org” : { "SAME-AS" : "108-5", "NAROOWER-THAN": "108-8" }}
//map of <systemUrl ,<mapType , code>> ie { "http://loinc.org” : { "SAME-AS" : "108-5", "NARROWER-THAN": "108-8" }}
Map<String, Map<String, String>> systemUrlToCodeMap = new HashMap<>();
for (ConceptMap mapping : concept.getConceptMappings()) {
if (mapping.getConceptMapType() != null) {
Expand Down Expand Up @@ -126,7 +126,9 @@ public Concept toOpenmrsType(@Nonnull CodeableConcept concept) {
private void addConceptCoding(Coding coding, String system, String code, Concept concept) {
coding.setSystem(system);
coding.setCode(code);
coding.setDisplay(concept.getDisplayString());
if (system == null) {
coding.setDisplay(concept.getDisplayString());
}
}

private void addSystemToCodeMap(Map<String, Map<String, String>> systemUrlToCodeMap, String systemUrl, String mapType,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ public Dosage toFhirResource(@Nonnull DrugOrder drugOrder) {
if (drugOrder == null) {
return null;
}

Dosage dosage = new Dosage();
dosage.setText(drugOrder.getDosingInstructions());
dosage.setAsNeeded(new BooleanType(drugOrder.getAsNeeded()));
Expand All @@ -59,7 +60,7 @@ public Dosage toFhirResource(@Nonnull DrugOrder drugOrder) {
if (coding != null) {
dose.setSystem(coding.getSystem());
dose.setCode(coding.getCode());
dose.setUnit(coding.getDisplay());
dose.setUnit(drugOrder.getDoseUnits().getDisplayString());
}
}
doseAndRate.setDose(dose);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ public Coding toFhirResource(@Nonnull Concept concept) {
if (codeableConcept == null) {
return null;
}

Coding coding = getCodingForSystem(codeableConcept, FhirConstants.RX_NORM_SYSTEM_URI);
if (coding == null) {
coding = getCodingForSystem(codeableConcept, FhirConstants.SNOMED_SYSTEM_URI);
Expand All @@ -43,6 +44,10 @@ public Coding toFhirResource(@Nonnull Concept concept) {
if (coding == null) {
coding = codeableConcept.getCodingFirstRep();
}

coding.setDisplay(codeableConcept.getCoding().stream().filter(c -> c.getSystem() == null || c.getSystem().isEmpty())
.findFirst().map(Coding::getDisplay).orElse(null));

return coding;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
package org.openmrs.module.fhir2.api.translators.impl;

import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.allOf;
import static org.hamcrest.Matchers.empty;
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.hasItem;
Expand Down Expand Up @@ -134,9 +135,8 @@ public void shouldTranslateLOINCMappingForLOINCMappedConcept() {
CodeableConcept result = conceptTranslator.toFhirResource(concept);
assertThat(result, notNullValue());
assertThat(result.getCoding(), not(empty()));
assertThat(result.getCoding(), hasItem(hasProperty("system", equalTo(FhirTestConstants.LOINC_SYSTEM_URL))));
assertThat(result.getCoding(), hasItem(hasProperty("code", equalTo("1000-1"))));
assertThat(result.getCoding(), hasItem(hasProperty("display", equalTo(CONCEPT_NAME))));
assertThat(result.getCoding(), hasItem(allOf(hasProperty("system", equalTo(FhirTestConstants.LOINC_SYSTEM_URL)),
hasProperty("code", equalTo("1000-1")), hasProperty("display", nullValue()))));
}

@Test
Expand All @@ -145,9 +145,8 @@ public void shouldTranslateCIELMappingForCIELMappedConcept() {
CodeableConcept result = conceptTranslator.toFhirResource(concept);
assertThat(result, notNullValue());
assertThat(result.getCoding(), not(empty()));
assertThat(result.getCoding(), hasItem(hasProperty("system", equalTo(FhirTestConstants.CIEL_SYSTEM_URN))));
assertThat(result.getCoding(), hasItem(hasProperty("code", equalTo("1650"))));
assertThat(result.getCoding(), hasItem(hasProperty("display", equalTo(CONCEPT_NAME))));
assertThat(result.getCoding(), hasItem(allOf(hasProperty("system", equalTo(FhirTestConstants.CIEL_SYSTEM_URN)),
hasProperty("code", equalTo("1650")), hasProperty("display", nullValue()))));
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,9 @@ public void toFhirResource_shouldTranslateDrugOrderDoseToDoseQuantityPreferringS

drugOrder.setDose(20.0);
drugOrder.setDoseUnits(mg);

Dosage result = dosageTranslator.toFhirResource(drugOrder);

assertThat(result, notNullValue());
assertThat(result.getDoseAndRate().get(0).getDoseQuantity().getValue().doubleValue(), equalTo(20.0));
assertThat(result.getDoseAndRate().get(0).getDoseQuantity().getUnit(), is("mg"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ public void toFhirResource_shouldTranslateMedicationQuantityPreferringRxNormIfPr
mg.addConceptMapping(new ConceptMap(new ConceptReferenceTerm(rxNorm, "rx-norm-mg-code", "rxnorm"), sameAs));

Coding result = quantityCodingTranslator.toFhirResource(mg);

assertThat(result, notNullValue());
assertThat(result.getDisplay(), is("mg"));
assertThat(result.getSystem(), is(FhirConstants.RX_NORM_SYSTEM_URI));
Expand All @@ -102,6 +103,7 @@ public void toFhirResource_shouldTranslateMedicationQuantityPreferringSnomedCtIf
mg.addConceptMapping(new ConceptMap(new ConceptReferenceTerm(snomed, "snomed-ct-mg-code", "snomed"), sameAs));

Coding result = quantityCodingTranslator.toFhirResource(mg);

assertThat(result, notNullValue());
assertThat(result.getDisplay(), is("mg"));
assertThat(result.getSystem(), is(FhirConstants.SNOMED_SYSTEM_URI));
Expand Down

0 comments on commit 7ab2e3a

Please sign in to comment.