Search in sources :

Example 6 with FhirConceptSource

use of org.openmrs.module.fhir2.model.FhirConceptSource 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 7 with FhirConceptSource

use of org.openmrs.module.fhir2.model.FhirConceptSource in project openmrs-module-fhir2 by openmrs.

the class FhirConceptSourceServiceImplTest method getFhirConceptSourceByConceptSourceName_shouldReturnConceptSourceForName.

@Test
public void getFhirConceptSourceByConceptSourceName_shouldReturnConceptSourceForName() {
    FhirConceptSource source = new FhirConceptSource();
    when(dao.getFhirConceptSourceByConceptSourceName("LOINC")).thenReturn(Optional.of(source));
    Optional<FhirConceptSource> result = fhirConceptSourceService.getFhirConceptSourceByConceptSourceName("LOINC");
    assertThat(result.isPresent(), is(true));
    assertThat(result.get(), equalTo(source));
}
Also used : FhirConceptSource(org.openmrs.module.fhir2.model.FhirConceptSource) Test(org.junit.Test)

Example 8 with FhirConceptSource

use of org.openmrs.module.fhir2.model.FhirConceptSource in project openmrs-module-fhir2 by openmrs.

the class FhirConceptSourceServiceImplTest method getFhirConceptSources_shouldReturnFhirConceptSources.

@Test
public void getFhirConceptSources_shouldReturnFhirConceptSources() {
    Collection<FhirConceptSource> sources = Lists.newArrayList(new FhirConceptSource(), new FhirConceptSource());
    when(dao.getFhirConceptSources()).thenReturn(sources);
    Collection<FhirConceptSource> result = fhirConceptSourceService.getFhirConceptSources();
    assertThat(result, notNullValue());
    assertThat(result, not(empty()));
}
Also used : FhirConceptSource(org.openmrs.module.fhir2.model.FhirConceptSource) Test(org.junit.Test)

Example 9 with FhirConceptSource

use of org.openmrs.module.fhir2.model.FhirConceptSource in project openmrs-module-fhir2 by openmrs.

the class ConceptTranslatorImplTest method shouldOnlyAddCodesThatAreMappedSAME_AS.

@Test
public void shouldOnlyAddCodesThatAreMappedSAME_AS() {
    Collection<ConceptMap> conceptMaps = new ArrayList<>();
    ConceptMap conceptMap1 = mock(ConceptMap.class);
    conceptMaps.add(conceptMap1);
    ConceptMap conceptMap2 = mock(ConceptMap.class);
    conceptMaps.add(conceptMap2);
    ConceptMapType conceptMapType1 = mock(ConceptMapType.class);
    conceptMap1.setConceptMapType(conceptMapType1);
    ConceptMapType conceptMapType2 = mock(ConceptMapType.class);
    conceptMap2.setConceptMapType(conceptMapType2);
    ConceptReferenceTerm conceptReferenceTerm = mock(ConceptReferenceTerm.class);
    ConceptSource conceptSource1 = mock(ConceptSource.class);
    when(concept.getConceptMappings()).thenReturn(conceptMaps);
    when(conceptMap1.getConceptReferenceTerm()).thenReturn(conceptReferenceTerm);
    when(conceptReferenceTerm.getConceptSource()).thenReturn(conceptSource1);
    when(conceptReferenceTerm.getCode()).thenReturn("1650");
    when(conceptSource1.getName()).thenReturn("CIEL");
    when(conceptMap1.getConceptMapType()).thenReturn(conceptMapType1);
    when(conceptMapType1.getName()).thenReturn("SAME-AS");
    when(conceptMap2.getConceptMapType()).thenReturn(conceptMapType2);
    when(conceptMapType2.getName()).thenReturn("NARROWER-THAN");
    FhirConceptSource ciel = new FhirConceptSource();
    ConceptSource cielConceptSource = new ConceptSource();
    cielConceptSource.setName("CIEL");
    ciel.setConceptSource(cielConceptSource);
    ciel.setUrl(FhirTestConstants.CIEL_SYSTEM_URN);
    when(conceptSourceService.getFhirConceptSourceByConceptSourceName("CIEL")).thenReturn(Optional.of(ciel));
    CodeableConcept result = conceptTranslator.toFhirResource(concept);
    assertThat(result, notNullValue());
    assertThat(result.getCoding(), not(empty()));
    // one SAME-AS, one UUID
    assertThat(result.getCoding(), hasSize(2));
    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))));
}
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)

Aggregations

Test (org.junit.Test)9 FhirConceptSource (org.openmrs.module.fhir2.model.FhirConceptSource)9 CodeableConcept (org.hl7.fhir.r4.model.CodeableConcept)6 ConceptMap (org.openmrs.ConceptMap)6 ConceptMapType (org.openmrs.ConceptMapType)6 ConceptReferenceTerm (org.openmrs.ConceptReferenceTerm)6 ConceptSource (org.openmrs.ConceptSource)6 ArrayList (java.util.ArrayList)3 Coding (org.hl7.fhir.r4.model.Coding)3 Concept (org.openmrs.Concept)3