Search in sources :

Example 86 with System

use of org.hl7.gravity.refimpl.sdohexchange.sdohmappings.System in project summary-care-record-api by NHSDigital.

the class ObservationMapper method mapFinding.

private static Finding mapFinding(Observation observation, Bundle bundle) {
    var finding = new Finding();
    finding.setIdRoot(observation.getIdentifierFirstRep().getValue());
    finding.setCodeCode(observation.getCode().getCodingFirstRep().getCode());
    finding.setCodeDisplayName(observation.getCode().getCodingFirstRep().getDisplay());
    finding.setStatusCodeCode(mapStatus(observation.getStatus()));
    if (observation.getEffective() instanceof DateTimeType) {
        finding.setEffectiveTimeCenter(formatDateToHl7(observation.getEffectiveDateTimeType()));
    } else if (observation.getEffective() instanceof Period) {
        var period = observation.getEffectivePeriod();
        if (period.hasStart()) {
            finding.setEffectiveTimeLow(formatDateToHl7(period.getStartElement()));
        }
        if (period.hasEnd()) {
            finding.setEffectiveTimeHigh(formatDateToHl7(period.getEndElement()));
        }
    } else {
        throw new FhirValidationException("Observation.effective must be of type DateTimeType or Period");
    }
    var encounterReference = observation.getEncounter().getReference();
    if (StringUtils.isNotBlank(encounterReference)) {
        var encounter = getResourceByReference(bundle, encounterReference, Encounter.class).orElseThrow(() -> new FhirValidationException(String.format("Bundle is Missing Encounter %s that is linked to Condition %s", observation.getEncounter().getReference(), observation.getId())));
        for (var encounterParticipant : encounter.getParticipant()) {
            Coding coding = encounterParticipant.getTypeFirstRep().getCodingFirstRep();
            if (!PARTICIPATION_TYPE_SYSTEM.equals(coding.getSystem())) {
                throw new FhirValidationException("Unsupported encounter participant system: " + coding.getSystem());
            }
            var code = coding.getCode();
            if ("AUT".equals(code)) {
                var author = mapAuthor1(bundle, encounterParticipant);
                finding.setAuthor(author);
            } else if ("INF".equals(code)) {
                var informant = mapInformant(bundle, encounterParticipant);
                finding.setInformant(informant);
            } else if ("PRF".equals(code)) {
                var performer = mapPerformer(bundle, encounterParticipant);
                finding.setPerformer(performer);
            } else {
                throw new FhirValidationException(String.format("Invalid encounter %s participant code %s", encounter.getId(), code));
            }
        }
    }
    return finding;
}
Also used : DateTimeType(org.hl7.fhir.r4.model.DateTimeType) Coding(org.hl7.fhir.r4.model.Coding) Finding(uk.nhs.adaptors.scr.models.xml.Finding) Period(org.hl7.fhir.r4.model.Period) Encounter(org.hl7.fhir.r4.model.Encounter) FhirValidationException(uk.nhs.adaptors.scr.exceptions.FhirValidationException)

Example 87 with System

use of org.hl7.gravity.refimpl.sdohexchange.sdohmappings.System in project openmrs-module-fhir2 by openmrs.

the class ServiceRequestSearchQueryTest method searchForServiceRequests_shouldSupportMappedAndUnmappedConcepts.

@Test
public void searchForServiceRequests_shouldSupportMappedAndUnmappedConcepts() {
    TokenAndListParam code = new TokenAndListParam().addAnd(new TokenParam().setSystem(FhirTestConstants.LOINC_SYSTEM_URL).setValue(TEST_ORDER_LOINC_CODE)).addAnd(new TokenParam().setValue(TEST_ORDER_CONCEPT_ID));
    SearchParameterMap theParams = new SearchParameterMap().addParameter(FhirConstants.CODED_SEARCH_HANDLER, code);
    IBundleProvider results = search(theParams);
    assertThat(results, notNullValue());
    assertThat(results.size(), equalTo(4));
    List<ServiceRequest> resultList = get(results);
    assertThat(resultList, not(empty()));
    assertThat(resultList, hasSize(equalTo(4)));
    assertThat(resultList, everyItem(allOf(hasProperty("code", hasProperty("coding", hasItem(allOf(hasProperty("code", equalTo(TEST_ORDER_LOINC_CODE)), hasProperty("system", equalTo(FhirTestConstants.LOINC_SYSTEM_URL)))))), hasProperty("code", hasProperty("coding", hasItem(hasProperty("code", equalTo(TEST_ORDER_CONCEPT_UUID))))))));
}
Also used : TokenParam(ca.uhn.fhir.rest.param.TokenParam) IBundleProvider(ca.uhn.fhir.rest.api.server.IBundleProvider) TokenAndListParam(ca.uhn.fhir.rest.param.TokenAndListParam) ServiceRequest(org.hl7.fhir.r4.model.ServiceRequest) SearchParameterMap(org.openmrs.module.fhir2.api.search.param.SearchParameterMap) BaseModuleContextSensitiveTest(org.openmrs.test.BaseModuleContextSensitiveTest) Test(org.junit.Test)

Example 88 with System

use of org.hl7.gravity.refimpl.sdohexchange.sdohmappings.System in project openmrs-module-fhir2 by openmrs.

the class ServiceRequestSearchQueryTest method searchForServiceRequests_shouldReturnFromMultipleConceptMappings.

@Test
public void searchForServiceRequests_shouldReturnFromMultipleConceptMappings() {
    TokenAndListParam code = new TokenAndListParam().addAnd(new TokenParam().setSystem(FhirTestConstants.LOINC_SYSTEM_URL).setValue(TEST_ORDER_LOINC_CODE), new TokenParam().setSystem(FhirTestConstants.CIEL_SYSTEM_URN).setValue(TEST_ORDER_CIEL_CODE));
    SearchParameterMap theParams = new SearchParameterMap().addParameter(FhirConstants.CODED_SEARCH_HANDLER, code);
    IBundleProvider results = search(theParams);
    assertThat(results, notNullValue());
    assertThat(results.size(), equalTo(4));
    List<ServiceRequest> resultList = get(results);
    assertThat(resultList, not(empty()));
    assertThat(resultList, hasSize(equalTo(4)));
    assertThat(resultList, everyItem(anyOf(hasProperty("code", hasProperty("coding", hasItem(allOf(hasProperty("code", equalTo(TEST_ORDER_LOINC_CODE)), hasProperty("system", equalTo(FhirTestConstants.LOINC_SYSTEM_URL)))))), hasProperty("code", hasProperty("coding", hasItem(allOf(hasProperty("code", equalTo(TEST_ORDER_CIEL_CODE)), hasProperty("system", equalTo(FhirTestConstants.CIEL_SYSTEM_URN)))))))));
}
Also used : TokenParam(ca.uhn.fhir.rest.param.TokenParam) IBundleProvider(ca.uhn.fhir.rest.api.server.IBundleProvider) TokenAndListParam(ca.uhn.fhir.rest.param.TokenAndListParam) ServiceRequest(org.hl7.fhir.r4.model.ServiceRequest) SearchParameterMap(org.openmrs.module.fhir2.api.search.param.SearchParameterMap) BaseModuleContextSensitiveTest(org.openmrs.test.BaseModuleContextSensitiveTest) Test(org.junit.Test)

Example 89 with System

use of org.hl7.gravity.refimpl.sdohexchange.sdohmappings.System 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 90 with System

use of org.hl7.gravity.refimpl.sdohexchange.sdohmappings.System 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)

Aggregations

Test (org.junit.jupiter.api.Test)92 CodeableConcept (org.hl7.fhir.r4.model.CodeableConcept)75 ArrayList (java.util.ArrayList)70 Coding (org.hl7.fhir.r4.model.Coding)70 Identifier (org.hl7.fhir.r4.model.Identifier)62 FHIRException (org.hl7.fhir.exceptions.FHIRException)45 BundleEntryComponent (org.hl7.fhir.r4.model.Bundle.BundleEntryComponent)45 Resource (org.hl7.fhir.r4.model.Resource)45 XhtmlNode (org.hl7.fhir.utilities.xhtml.XhtmlNode)38 Test (org.junit.Test)37 Coding (org.hl7.fhir.dstu3.model.Coding)32 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)32 HashMap (java.util.HashMap)30 IBaseResource (org.hl7.fhir.instance.model.api.IBaseResource)28 List (java.util.List)27 IOException (java.io.IOException)26 Bundle (org.hl7.fhir.r4.model.Bundle)26 Patient (org.hl7.fhir.r4.model.Patient)25 CommaSeparatedStringBuilder (org.hl7.fhir.utilities.CommaSeparatedStringBuilder)24 CodeableConcept (org.hl7.fhir.dstu3.model.CodeableConcept)21