use of org.hl7.fhir.r4.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))));
}
use of org.hl7.fhir.r4.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()));
}
use of org.hl7.fhir.r4.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")))));
}
use of org.hl7.fhir.r4.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()))));
}
use of org.hl7.fhir.r4.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;
}
Aggregations