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));
}
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))));
}
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")))));
}
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))));
}
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()));
}
Aggregations