Search in sources :

Example 16 with ConceptMap

use of org.hl7.fhir.dstu2.model.ConceptMap in project openmrs-module-fhir2 by openmrs.

the class ConceptTranslatorImplTest method shouldTranslateLOINCMappingForLOINCMappedConcept.

@Test
public void shouldTranslateLOINCMappingForLOINCMappedConcept() {
    Collection<ConceptMap> conceptMaps = new ArrayList<>();
    ConceptMap conceptMap = mock(ConceptMap.class);
    conceptMaps.add(conceptMap);
    ConceptReferenceTerm conceptReferenceTerm = mock(ConceptReferenceTerm.class);
    ConceptSource conceptSource = mock(ConceptSource.class);
    ConceptMapType conceptMapType = mock(ConceptMapType.class);
    when(conceptMap.getConceptMapType()).thenReturn(conceptMapType);
    when(conceptMapType.getName()).thenReturn("SAME-AS");
    when(conceptMap.getConceptReferenceTerm()).thenReturn(conceptReferenceTerm);
    when(conceptReferenceTerm.getConceptSource()).thenReturn(conceptSource);
    when(conceptReferenceTerm.getCode()).thenReturn("1000-1");
    when(conceptSource.getName()).thenReturn("LOINC");
    when(concept.getConceptMappings()).thenReturn(conceptMaps);
    FhirConceptSource loinc = new FhirConceptSource();
    ConceptSource loincConceptSource = new ConceptSource();
    loincConceptSource.setName("LOINC");
    loinc.setConceptSource(loincConceptSource);
    loinc.setUrl(FhirTestConstants.LOINC_SYSTEM_URL);
    when(conceptSourceService.getFhirConceptSourceByConceptSourceName("LOINC")).thenReturn(Optional.of(loinc));
    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))));
}
Also used : ConceptMapType(org.openmrs.ConceptMapType) FhirConceptSource(org.openmrs.module.fhir2.model.FhirConceptSource) ArrayList(java.util.ArrayList) ConceptSource(org.openmrs.ConceptSource) FhirConceptSource(org.openmrs.module.fhir2.model.FhirConceptSource) ConceptMap(org.openmrs.ConceptMap) ConceptReferenceTerm(org.openmrs.ConceptReferenceTerm) CodeableConcept(org.hl7.fhir.r4.model.CodeableConcept) Test(org.junit.Test)

Example 17 with ConceptMap

use of org.hl7.fhir.dstu2.model.ConceptMap in project openmrs-module-fhir2 by openmrs.

the class ConceptTranslatorImplTest method shouldFavorConceptWithMatchingSystemOverUUID.

@Test
public void shouldFavorConceptWithMatchingSystemOverUUID() {
    CodeableConcept codeableConcept = new CodeableConcept();
    Coding baseCoding = codeableConcept.addCoding();
    baseCoding.setCode(CONCEPT_UUID);
    Coding loincCoding = codeableConcept.addCoding();
    loincCoding.setSystem(FhirTestConstants.LOINC_SYSTEM_URL);
    loincCoding.setCode("1000-1");
    Concept defaultConcept = new Concept();
    defaultConcept.setUuid(CONCEPT_UUID);
    when(conceptService.get(CONCEPT_UUID)).thenReturn(defaultConcept);
    Concept loincConcept = new Concept();
    loincConcept.setUuid(FhirUtils.newUuid());
    ConceptMap conceptMap = new ConceptMap();
    ConceptReferenceTerm conceptReferenceTerm = new ConceptReferenceTerm();
    ConceptSource loinc = new ConceptSource();
    loinc.setName("LOINC");
    conceptReferenceTerm.setConceptSource(loinc);
    conceptReferenceTerm.setCode("1000-1");
    conceptMap.setConceptReferenceTerm(conceptReferenceTerm);
    ConceptMapType conceptMapType = new ConceptMapType();
    conceptMap.setConceptMapType(conceptMapType);
    loincConcept.addConceptMapping(conceptMap);
    when(conceptService.getConceptBySourceNameAndCode("LOINC", "1000-1")).thenReturn(Optional.of(loincConcept));
    FhirConceptSource fhirLoincSource = new FhirConceptSource();
    fhirLoincSource.setConceptSource(loinc);
    fhirLoincSource.setUrl(FhirTestConstants.LOINC_SYSTEM_URL);
    when(conceptSourceService.getFhirConceptSourceByUrl(FhirTestConstants.LOINC_SYSTEM_URL)).thenReturn(Optional.of(fhirLoincSource));
    Concept result = conceptTranslator.toOpenmrsType(codeableConcept);
    assertThat(result.getUuid(), equalTo(loincConcept.getUuid()));
}
Also used : CodeableConcept(org.hl7.fhir.r4.model.CodeableConcept) Concept(org.openmrs.Concept) ConceptMapType(org.openmrs.ConceptMapType) Coding(org.hl7.fhir.r4.model.Coding) FhirConceptSource(org.openmrs.module.fhir2.model.FhirConceptSource) ConceptSource(org.openmrs.ConceptSource) FhirConceptSource(org.openmrs.module.fhir2.model.FhirConceptSource) ConceptMap(org.openmrs.ConceptMap) ConceptReferenceTerm(org.openmrs.ConceptReferenceTerm) CodeableConcept(org.hl7.fhir.r4.model.CodeableConcept) Test(org.junit.Test)

Example 18 with ConceptMap

use of org.hl7.fhir.dstu2.model.ConceptMap in project openmrs-module-fhir2 by openmrs.

the class ConceptTranslatorImplTest method shouldTranslateCIELCodeableConceptToConcept.

@Test
public void shouldTranslateCIELCodeableConceptToConcept() {
    CodeableConcept codeableConcept = new CodeableConcept();
    Coding cielCoding = codeableConcept.addCoding();
    cielCoding.setSystem(FhirTestConstants.CIEL_SYSTEM_URN);
    cielCoding.setCode("1650");
    Concept concept = new Concept();
    ConceptMap conceptMap = new ConceptMap();
    ConceptReferenceTerm conceptReferenceTerm = new ConceptReferenceTerm();
    ConceptSource ciel = new ConceptSource();
    ciel.setName("CIEL");
    conceptReferenceTerm.setConceptSource(ciel);
    conceptReferenceTerm.setCode("1650");
    conceptMap.setConceptReferenceTerm(conceptReferenceTerm);
    ConceptMapType conceptMapType = new ConceptMapType();
    conceptMap.setConceptMapType(conceptMapType);
    concept.addConceptMapping(conceptMap);
    when(conceptService.getConceptBySourceNameAndCode("CIEL", "1650")).thenReturn(Optional.of(concept));
    FhirConceptSource fhirCielSource = new FhirConceptSource();
    fhirCielSource.setConceptSource(ciel);
    fhirCielSource.setUrl(FhirTestConstants.CIEL_SYSTEM_URN);
    when(conceptSourceService.getFhirConceptSourceByUrl(FhirTestConstants.CIEL_SYSTEM_URN)).thenReturn(Optional.of(fhirCielSource));
    Concept result = conceptTranslator.toOpenmrsType(codeableConcept);
    assertThat(result, notNullValue());
    assertThat(result.getConceptMappings(), notNullValue());
    assertThat(result.getConceptMappings(), not(empty()));
    assertThat(result.getConceptMappings(), hasItem(hasProperty("conceptReferenceTerm", hasProperty("code", equalTo("1650")))));
}
Also used : CodeableConcept(org.hl7.fhir.r4.model.CodeableConcept) Concept(org.openmrs.Concept) ConceptMapType(org.openmrs.ConceptMapType) Coding(org.hl7.fhir.r4.model.Coding) FhirConceptSource(org.openmrs.module.fhir2.model.FhirConceptSource) ConceptSource(org.openmrs.ConceptSource) FhirConceptSource(org.openmrs.module.fhir2.model.FhirConceptSource) ConceptMap(org.openmrs.ConceptMap) ConceptReferenceTerm(org.openmrs.ConceptReferenceTerm) CodeableConcept(org.hl7.fhir.r4.model.CodeableConcept) Test(org.junit.Test)

Example 19 with ConceptMap

use of org.hl7.fhir.dstu2.model.ConceptMap in project openmrs-module-fhir2 by openmrs.

the class ConceptTranslatorImplTest method shouldNotTranslateUnknownMappingCode.

@Test
public void shouldNotTranslateUnknownMappingCode() {
    Collection<ConceptMap> conceptMaps = new ArrayList<>();
    ConceptMap conceptMap = mock(ConceptMap.class);
    conceptMaps.add(conceptMap);
    ConceptMapType conceptMapType = mock(ConceptMapType.class);
    conceptMapType.setName("SAME-AS");
    conceptMap.setConceptMapType(conceptMapType);
    ConceptSource conceptSource = mock(ConceptSource.class);
    when(concept.getConceptMappings()).thenReturn(conceptMaps);
    CodeableConcept result = conceptTranslator.toFhirResource(concept);
    assertThat(result, notNullValue());
    assertThat(result.getCoding(), hasSize(1));
    assertThat(result.getCoding(), not(hasItem(hasProperty("system", notNullValue()))));
}
Also used : ConceptMapType(org.openmrs.ConceptMapType) ArrayList(java.util.ArrayList) ConceptSource(org.openmrs.ConceptSource) FhirConceptSource(org.openmrs.module.fhir2.model.FhirConceptSource) ConceptMap(org.openmrs.ConceptMap) CodeableConcept(org.hl7.fhir.r4.model.CodeableConcept) Test(org.junit.Test)

Example 20 with ConceptMap

use of org.hl7.fhir.dstu2.model.ConceptMap in project org.hl7.fhir.core by hapifhir.

the class ConceptMap10_50 method getGroup.

public static ConceptMapGroupComponent getGroup(ConceptMap map, String srcs, String tgts) {
    for (ConceptMapGroupComponent grp : map.getGroup()) {
        if (grp.getSource().equals(srcs) && grp.getTarget().equals(tgts))
            return grp;
    }
    ConceptMapGroupComponent grp = map.addGroup();
    grp.setSource(srcs);
    grp.setTarget(tgts);
    return grp;
}
Also used : ConceptMapGroupComponent(org.hl7.fhir.r5.model.ConceptMap.ConceptMapGroupComponent)

Aggregations

ConceptMap (org.hl7.fhir.dstu3.model.ConceptMap)34 Test (org.junit.Test)31 ArrayList (java.util.ArrayList)29 HashMap (java.util.HashMap)27 FHIRException (org.hl7.fhir.exceptions.FHIRException)26 ConceptMap (org.hl7.fhir.r4.model.ConceptMap)23 XhtmlNode (org.hl7.fhir.utilities.xhtml.XhtmlNode)23 ConceptMap (org.hl7.fhir.r5.model.ConceptMap)22 ConceptMapGroupComponent (org.hl7.fhir.r5.model.ConceptMap.ConceptMapGroupComponent)17 ConceptMapGroupComponent (org.hl7.fhir.dstu3.model.ConceptMap.ConceptMapGroupComponent)15 HashSet (java.util.HashSet)13 ConceptMapGroupComponent (org.hl7.fhir.r4.model.ConceptMap.ConceptMapGroupComponent)13 StructureDefinition (org.hl7.fhir.r5.model.StructureDefinition)12 FileOutputStream (java.io.FileOutputStream)11 ValueSet (org.hl7.fhir.r5.model.ValueSet)11 SourceElementComponent (org.hl7.fhir.dstu3.model.ConceptMap.SourceElementComponent)10 Test (org.junit.jupiter.api.Test)10 ConceptMap (org.hl7.fhir.dstu2016may.model.ConceptMap)9 Coding (org.hl7.fhir.r4.model.Coding)9 SourceElementComponent (org.hl7.fhir.r4.model.ConceptMap.SourceElementComponent)9