Search in sources :

Example 46 with Observation

use of org.hl7.fhir.r4b.model.Observation in project quality-measure-and-cohort-service by Alvearie.

the class MeasureSupplementalDataEvaluation method processAccumulators.

public static MeasureReport processAccumulators(MeasureReport report, Map<String, Map<String, Integer>> sdeAccumulators, boolean isSingle, List<Patient> patients) {
    List<Reference> newRefList = new ArrayList<>();
    sdeAccumulators.forEach((sdeKey, sdeAccumulator) -> {
        sdeAccumulator.forEach((sdeAccumulatorKey, sdeAccumulatorValue) -> {
            Observation obs = new Observation();
            obs.setStatus(Observation.ObservationStatus.FINAL);
            obs.setId(UUID.randomUUID().toString());
            Coding valueCoding = new Coding();
            if (sdeKey.equalsIgnoreCase(SDE_SEX)) {
                valueCoding.setCode(sdeAccumulatorKey);
            } else {
                String coreCategory = sdeKey.substring(sdeKey.lastIndexOf('-'));
                patients.forEach((pt) -> {
                    pt.getExtension().forEach((ptExt) -> {
                        if (ptExt.getUrl().contains(coreCategory)) {
                            String code = ((Coding) ptExt.getExtension().get(0).getValue()).getCode();
                            if (code.equalsIgnoreCase(sdeAccumulatorKey)) {
                                valueCoding.setSystem(((Coding) ptExt.getExtension().get(0).getValue()).getSystem());
                                valueCoding.setCode(code);
                                valueCoding.setDisplay(((Coding) ptExt.getExtension().get(0).getValue()).getDisplay());
                            }
                        }
                    });
                });
            }
            CodeableConcept obsCodeableConcept = new CodeableConcept();
            Extension obsExtension = new Extension().setUrl(CQF_MEASUREINFO_URL);
            Extension extExtMeasure = new Extension().setUrl(MEASURE).setValue(new CanonicalType(CQFMEASURES_URL + report.getMeasure()));
            obsExtension.addExtension(extExtMeasure);
            Extension extExtPop = new Extension().setUrl(POPULATION_ID).setValue(new StringType(sdeKey));
            obsExtension.addExtension(extExtPop);
            obs.addExtension(obsExtension);
            obs.setValue(new IntegerType(sdeAccumulatorValue));
            if (!isSingle) {
                valueCoding.setCode(sdeAccumulatorKey);
                obsCodeableConcept.setCoding(Collections.singletonList(valueCoding));
                obs.setCode(obsCodeableConcept);
            } else {
                obs.setCode(new CodeableConcept().setText(sdeKey));
                obsCodeableConcept.setCoding(Collections.singletonList(valueCoding));
                obs.setValue(obsCodeableConcept);
            }
            newRefList.add(new Reference("#" + obs.getId()));
            report.addContained(obs);
        });
    });
    newRefList.addAll(report.getEvaluatedResource());
    report.setEvaluatedResource(newRefList);
    return report;
}
Also used : Extension(org.hl7.fhir.r4.model.Extension) IntegerType(org.hl7.fhir.r4.model.IntegerType) Coding(org.hl7.fhir.r4.model.Coding) StringType(org.hl7.fhir.r4.model.StringType) Reference(org.hl7.fhir.r4.model.Reference) ArrayList(java.util.ArrayList) Observation(org.hl7.fhir.r4.model.Observation) CanonicalType(org.hl7.fhir.r4.model.CanonicalType) CodeableConcept(org.hl7.fhir.r4.model.CodeableConcept)

Example 47 with Observation

use of org.hl7.fhir.r4b.model.Observation in project quality-measure-and-cohort-service by Alvearie.

the class CqlTemporalTests method confirmCanFindEventWithExistenceOfThirdEvent.

@Test
public void confirmCanFindEventWithExistenceOfThirdEvent() throws Exception {
    Patient patient = getPatient("123", Enumerations.AdministrativeGender.FEMALE, null);
    Observation observation = new Observation();
    DateTimeType observationEffective = new DateTimeType(new Date());
    observationEffective.setYear(2015);
    observationEffective.setMonth(0);
    observationEffective.setDay(5);
    observation.setEffective(observationEffective);
    FhirServerConfig fhirConfig = getFhirServerConfig();
    mockFhirResourceRetrieval("/Condition?subject=Patient%2F123&_format=json", getFhirParser(), CONDITION_IN, fhirConfig);
    mockFhirResourceRetrieval("/Encounter?subject=Patient%2F123&_format=json", getFhirParser(), ENCOUNTER_1, fhirConfig);
    mockFhirResourceRetrieval("/Observation?subject=Patient%2F123&_format=json", getFhirParser(), observation, fhirConfig);
    CqlEvaluator evaluator = setupTestFor(patient, "cql.temporal", ClasspathCqlLibraryProvider.FHIR_HELPERS_CLASSPATH);
    String expression = "ObservationWithin30DaysOfCondition";
    CqlEvaluationResult actual = evaluator.evaluate(new CqlVersionedIdentifier("Test2", "1.0.0"), null, newPatientContext("123"), Collections.singleton(expression));
    Map<String, Object> expected = new HashMap<>();
    expected.put(expression, true);
    Assert.assertEquals(expected, actual.getExpressionResults());
}
Also used : DateTimeType(org.hl7.fhir.r4.model.DateTimeType) HashMap(java.util.HashMap) Observation(org.hl7.fhir.r4.model.Observation) Patient(org.hl7.fhir.r4.model.Patient) FhirServerConfig(com.ibm.cohort.fhir.client.config.FhirServerConfig) CqlEvaluationResult(com.ibm.cohort.cql.evaluation.CqlEvaluationResult) Date(java.util.Date) CqlEvaluator(com.ibm.cohort.cql.evaluation.CqlEvaluator) CqlVersionedIdentifier(com.ibm.cohort.cql.library.CqlVersionedIdentifier) Test(org.junit.Test)

Example 48 with Observation

use of org.hl7.fhir.r4b.model.Observation in project summary-care-record-api by NHSDigital.

the class DiagnosisMapper method map.

@SneakyThrows
public List<Resource> map(Node document) {
    var resources = new ArrayList<Resource>();
    NodeList pertinentNodes = xmlUtils.getNodeListByXPath(document, PERTINENT_CRET_BASE_PATH);
    for (int i = 0; i < pertinentNodes.getLength(); i++) {
        Node pertinentCREType = xmlUtils.getNodeAndDetachFromParent(pertinentNodes, i);
        var pertinentCRETypeCode = xmlUtils.getValueByXPath(pertinentCREType, PERTINENT_CODE_CODE_XPATH);
        var pertinentCRETypeDisplay = xmlUtils.getValueByXPath(pertinentCREType, PERTINENT_CODE_DISPLAY_XPATH);
        NodeList diagnosisNodes = xmlUtils.getNodeListByXPath(pertinentCREType, DIAGNOSIS_BASE_PATH);
        for (int j = 0; j < diagnosisNodes.getLength(); j++) {
            Node node = xmlUtils.getNodeAndDetachFromParent(diagnosisNodes, j);
            CodedEntry entry = codedEntryMapper.getCommonCodedEntryValues(node);
            if (COVID_19_ENTRIES.contains(entry.getCodeValue())) {
                var pertinentSupportingInfo = xmlUtils.getOptionalValueByXPath(node, DIAGNOSIS_PERTINENT_SUPPORTING_INFO_XPATH);
                var condition = new Condition();
                condition.setId(entry.getId());
                condition.addIdentifier().setValue(entry.getId());
                condition.setCode(new CodeableConcept().addCoding(new Coding().setCode(entry.getCodeValue()).setSystem(SNOMED_SYSTEM).setDisplay(entry.getCodeDisplay())));
                setConditionStatus(condition, entry.getStatus());
                condition.addCategory(new CodeableConcept(new Coding().setSystem(SNOMED_SYSTEM).setCode(pertinentCRETypeCode).setDisplay(pertinentCRETypeDisplay)));
                if (entry.getEffectiveTimeHigh().isPresent()) {
                    condition.setOnset(entry.getEffectiveTimeLow().get());
                    condition.setAbatement(entry.getEffectiveTimeHigh().get());
                } else {
                    condition.setOnset(entry.getEffectiveTimeLow().get());
                }
                resources.add(condition);
                pertinentSupportingInfo.map(value -> new Annotation().setText(value)).ifPresent(condition::addNote);
                xmlUtils.getNodesByXPath(node, DIAGNOSIS_PERTINENT_FINDINGS_XPATH).stream().map(it -> xmlUtils.getValueByXPath(it, DIAGNOSIS_PERTINENT_FINDING_ID_XPATH)).map(it -> new Reference(new Observation().setId(it))).map(reference -> new Condition.ConditionEvidenceComponent().addDetail(reference)).forEach(condition::addEvidence);
                mapEncounter(node, condition, resources);
            }
        }
    }
    return resources;
}
Also used : Condition(org.hl7.fhir.r4.model.Condition) SneakyThrows(lombok.SneakyThrows) DateTimeType(org.hl7.fhir.r4.model.DateTimeType) RequiredArgsConstructor(lombok.RequiredArgsConstructor) CodeableConcept(org.hl7.fhir.r4.model.CodeableConcept) Autowired(org.springframework.beans.factory.annotation.Autowired) Condition(org.hl7.fhir.r4.model.Condition) Reference(org.hl7.fhir.r4.model.Reference) ArrayList(java.util.ArrayList) RelatedPerson(org.hl7.fhir.r4.model.RelatedPerson) Encounter(org.hl7.fhir.r4.model.Encounter) Node(org.w3c.dom.Node) CodedEntryMapper(uk.nhs.adaptors.scr.mappings.from.hl7.common.CodedEntryMapper) Observation(org.hl7.fhir.r4.model.Observation) NodeList(org.w3c.dom.NodeList) Period(org.hl7.fhir.r4.model.Period) Resource(org.hl7.fhir.r4.model.Resource) FINISHED(org.hl7.fhir.r4.model.Encounter.EncounterStatus.FINISHED) PractitionerRole(org.hl7.fhir.r4.model.PractitionerRole) EncounterParticipantComponent(org.hl7.fhir.r4.model.Encounter.EncounterParticipantComponent) Component(org.springframework.stereotype.Component) List(java.util.List) XmlToFhirMapper.parseDate(uk.nhs.adaptors.scr.mappings.from.hl7.XmlToFhirMapper.parseDate) Coding(org.hl7.fhir.r4.model.Coding) FhirHelper.randomUUID(uk.nhs.adaptors.scr.utils.FhirHelper.randomUUID) Optional(java.util.Optional) XmlUtils(uk.nhs.adaptors.scr.utils.XmlUtils) Annotation(org.hl7.fhir.r4.model.Annotation) CodedEntry(uk.nhs.adaptors.scr.mappings.from.hl7.common.CodedEntry) Reference(org.hl7.fhir.r4.model.Reference) NodeList(org.w3c.dom.NodeList) Node(org.w3c.dom.Node) ArrayList(java.util.ArrayList) Annotation(org.hl7.fhir.r4.model.Annotation) CodedEntry(uk.nhs.adaptors.scr.mappings.from.hl7.common.CodedEntry) Coding(org.hl7.fhir.r4.model.Coding) Observation(org.hl7.fhir.r4.model.Observation) CodeableConcept(org.hl7.fhir.r4.model.CodeableConcept) SneakyThrows(lombok.SneakyThrows)

Example 49 with Observation

use of org.hl7.fhir.r4b.model.Observation 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 50 with Observation

use of org.hl7.fhir.r4b.model.Observation in project openmrs-module-fhir2 by openmrs.

the class FhirObservationServiceImplTest method getLastnObservations_shouldReturnRecentNObservationsForAllPatientsWhenNoPatientIsSpecified.

@Test
public void getLastnObservations_shouldReturnRecentNObservationsForAllPatientsWhenNoPatientIsSpecified() {
    Obs obs = new Obs();
    obs.setUuid(OBS_UUID);
    Observation observation = new Observation();
    observation.setId(OBS_UUID);
    NumberParam max = new NumberParam(2);
    TokenAndListParam categories = new TokenAndListParam().addAnd(new TokenParam().setValue("laboratory"));
    TokenAndListParam code = new TokenAndListParam().addAnd(new TokenParam().setSystem(FhirTestConstants.LOINC_SYSTEM_URL).setValue(LOINC_SYSTOLIC_BP), new TokenParam().setSystem(FhirTestConstants.CIEL_SYSTEM_URN).setValue(CIEL_DIASTOLIC_BP));
    SearchParameterMap theParams = new SearchParameterMap().addParameter(FhirConstants.CODED_SEARCH_HANDLER, code).addParameter(FhirConstants.CATEGORY_SEARCH_HANDLER, categories).addParameter(FhirConstants.MAX_SEARCH_HANDLER, max).addParameter(FhirConstants.LASTN_OBSERVATION_SEARCH_HANDLER, new StringParam());
    when(globalPropertyService.getGlobalProperty(anyString(), anyInt())).thenReturn(10);
    when(dao.getSearchResultUuids(any())).thenReturn(Collections.singletonList(OBS_UUID));
    when(dao.getSearchResults(any(), any())).thenReturn(Collections.singletonList(obs));
    when(searchQuery.getQueryResults(any(), any(), any(), any())).thenReturn(new SearchQueryBundleProvider<>(theParams, dao, translator, globalPropertyService, searchQueryInclude));
    when(searchQueryInclude.getIncludedResources(any(), any())).thenReturn(Collections.emptySet());
    when(translator.toFhirResource(obs)).thenReturn(observation);
    IBundleProvider results = fhirObservationService.getLastnObservations(max, null, categories, code);
    assertThat(results, notNullValue());
    assertThat(results.size(), equalTo(1));
    assertThat(results.preferredPageSize(), equalTo(10));
    List<IBaseResource> resultList = results.getResources(1, 10);
    assertThat(resultList, not(empty()));
    assertThat(resultList, hasSize(equalTo(1)));
}
Also used : Obs(org.openmrs.Obs) TokenParam(ca.uhn.fhir.rest.param.TokenParam) Observation(org.hl7.fhir.r4.model.Observation) IBundleProvider(ca.uhn.fhir.rest.api.server.IBundleProvider) StringParam(ca.uhn.fhir.rest.param.StringParam) NumberParam(ca.uhn.fhir.rest.param.NumberParam) IBaseResource(org.hl7.fhir.instance.model.api.IBaseResource) TokenAndListParam(ca.uhn.fhir.rest.param.TokenAndListParam) SearchParameterMap(org.openmrs.module.fhir2.api.search.param.SearchParameterMap) Test(org.junit.Test)

Aggregations

Observation (org.hl7.fhir.r4.model.Observation)237 Test (org.junit.Test)235 MockHttpServletResponse (org.springframework.mock.web.MockHttpServletResponse)114 Test (org.junit.jupiter.api.Test)107 IBaseResource (org.hl7.fhir.instance.model.api.IBaseResource)106 Observation (org.hl7.fhir.dstu3.model.Observation)94 Bundle (org.hl7.fhir.r4.model.Bundle)88 IBundleProvider (ca.uhn.fhir.rest.api.server.IBundleProvider)64 ArrayList (java.util.ArrayList)62 BundleEntryComponent (org.hl7.fhir.r4.model.Bundle.BundleEntryComponent)59 Resource (org.hl7.fhir.r4.model.Resource)55 Bundle (org.hl7.fhir.dstu3.model.Bundle)53 CodeableConcept (org.hl7.fhir.r4.model.CodeableConcept)47 Coding (org.hl7.fhir.r4.model.Coding)46 Reference (org.hl7.fhir.r4.model.Reference)41 TokenAndListParam (ca.uhn.fhir.rest.param.TokenAndListParam)37 TokenParam (ca.uhn.fhir.rest.param.TokenParam)37 Date (java.util.Date)34 ReferenceAndListParam (ca.uhn.fhir.rest.param.ReferenceAndListParam)32 ReferenceOrListParam (ca.uhn.fhir.rest.param.ReferenceOrListParam)32