Search in sources :

Example 1 with FhirConceptSource

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

the class FhirConceptSourceServiceImplTest method getFhirConceptSourceByUrl_shouldReturnConceptSourceForUrl.

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

Example 2 with FhirConceptSource

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

the class ConceptTranslatorImplTest method shouldTranslateCIELMappingForCIELMappedConcept.

@Test
public void shouldTranslateCIELMappingForCIELMappedConcept() {
    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("1650");
    when(conceptSource.getName()).thenReturn("CIEL");
    when(concept.getConceptMappings()).thenReturn(conceptMaps);
    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()));
    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)

Example 3 with FhirConceptSource

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

the class ConceptTranslatorImplTest method shouldTranslateLOINCCodeableConceptToConcept.

@Test
public void shouldTranslateLOINCCodeableConceptToConcept() {
    CodeableConcept codeableConcept = new CodeableConcept();
    Coding loincCoding = codeableConcept.addCoding();
    loincCoding.setSystem(FhirTestConstants.LOINC_SYSTEM_URL);
    loincCoding.setCode("1000-1");
    Concept concept = new Concept();
    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();
    conceptMapType.setName("SAME-AS");
    conceptMap.setConceptMapType(conceptMapType);
    concept.addConceptMapping(conceptMap);
    when(conceptService.getConceptBySourceNameAndCode("LOINC", "1000-1")).thenReturn(Optional.of(concept));
    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, notNullValue());
    assertThat(result.getConceptMappings(), notNullValue());
    assertThat(result.getConceptMappings(), not(empty()));
    assertThat(result.getConceptMappings(), hasItem(hasProperty("conceptReferenceTerm", hasProperty("code", equalTo("1000-1")))));
}
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 4 with FhirConceptSource

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

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

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