Search in sources :

Example 61 with Observation

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

the class DiagnosticReportTranslatorImplTest method toFhirResource_shouldConvertResult.

@Test
public void toFhirResource_shouldConvertResult() {
    DiagnosticReport result = translator.toFhirResource(fhirDiagnosticReport);
    assertThat(result, notNullValue());
    assertThat(result.getId(), equalTo(PARENT_UUID));
    assertThat(result.getResult(), notNullValue());
    assertThat(result.getResult().size(), equalTo(1));
    assertThat(result.getResult(), contains(hasProperty("reference", equalTo("Observation/" + CHILD_UUID))));
}
Also used : DiagnosticReport(org.hl7.fhir.r4.model.DiagnosticReport) FhirDiagnosticReport(org.openmrs.module.fhir2.model.FhirDiagnosticReport) Test(org.junit.Test)

Example 62 with Observation

use of org.hl7.fhir.r5.model.Observation in project elexis-server by elexis.

the class ObservationResourceProvider method createObservation.

@Create
public MethodOutcome createObservation(@ResourceParam Observation observation) {
    MethodOutcome outcome = new MethodOutcome();
    Optional<IObservation> exists = getTransformer().getLocalObject(observation);
    if (exists.isPresent()) {
        outcome.setCreated(false);
        outcome.setId(new IdType(observation.getId()));
    } else {
        Optional<IObservation> created = getTransformer().createLocalObject(observation);
        if (created.isPresent()) {
            outcome.setCreated(true);
            outcome.setId(new IdType(created.get().getId()));
        } else {
            throw new InternalErrorException("Creation failed");
        }
    }
    return outcome;
}
Also used : InternalErrorException(ca.uhn.fhir.rest.server.exceptions.InternalErrorException) MethodOutcome(ca.uhn.fhir.rest.api.MethodOutcome) IObservation(ch.elexis.core.findings.IObservation) IdType(org.hl7.fhir.r4.model.IdType) Create(ca.uhn.fhir.rest.annotation.Create)

Example 63 with Observation

use of org.hl7.fhir.r5.model.Observation in project elexis-server by elexis.

the class ObservationResourceProvider method filterCode.

private List<Observation> filterCode(List<Observation> observations, CodeType code) {
    ArrayList<Observation> ret = new ArrayList<>();
    String systemString = CodeTypeUtil.getSystem(code).orElse("");
    String codeString = CodeTypeUtil.getCode(code).orElse("");
    for (Observation observation : observations) {
        if (systemString.equals(CodingSystem.ELEXIS_LOCAL_LABORATORY_VITOLABKEY.getSystem())) {
            if (CodeTypeUtil.isVitoLabkey(modelService, observation, codeString)) {
                ret.add(observation);
            }
        } else if (CodeTypeUtil.isCodeInConcept(observation.getCode(), systemString, codeString)) {
            ret.add(observation);
        }
    }
    return ret;
}
Also used : Observation(org.hl7.fhir.r4.model.Observation) IObservation(ch.elexis.core.findings.IObservation) ArrayList(java.util.ArrayList)

Example 64 with Observation

use of org.hl7.fhir.r5.model.Observation in project elexis-server by elexis.

the class EncounterTest method createEncounter.

@Test
public void createEncounter() {
    Condition problem = new Condition();
    problem.setCode(new CodeableConcept().addCoding(new Coding("http://hl7.org/fhir/sid/icpc-2", "A04", "Müdigkeit")));
    problem.setSubject(new Reference("Patient/" + AllTests.getTestDatabaseInitializer().getPatient().getId()));
    problem.addCategory().addCoding(new Coding(ConditionCategory.PROBLEMLISTITEM.getSystem(), ConditionCategory.PROBLEMLISTITEM.toCode(), ConditionCategory.PROBLEMLISTITEM.getDisplay()));
    MethodOutcome problemOutcome = client.create().resource(problem).execute();
    Encounter encounter = new Encounter();
    EncounterParticipantComponent participant = new EncounterParticipantComponent();
    participant.setIndividual(new Reference("Practitioner/" + TestDatabaseInitializer.getMandant().getId()));
    encounter.addParticipant(participant);
    encounter.setPeriod(new Period().setStart(AllTests.getDate(LocalDate.now().atStartOfDay())).setEnd(AllTests.getDate(LocalDate.now().atTime(23, 59, 59))));
    encounter.setSubject(new Reference("Patient/" + AllTests.getTestDatabaseInitializer().getPatient().getId()));
    encounter.addDiagnosis().setCondition(new Reference(new IdType(problem.getResourceType().name(), problemOutcome.getId().getIdPart())));
    encounter.addType(new CodeableConcept().addCoding(new Coding("www.elexis.info/encounter/type", "struct", "structured enconter")));
    MethodOutcome outcome = client.create().resource(encounter).execute();
    assertNotNull(outcome);
    assertTrue(outcome.getCreated());
    assertNotNull(outcome.getId());
    // add subjective to the encounter
    Observation subjective = new Observation();
    Narrative narrative = new Narrative();
    String divEncodedText = "Subjective\nTest".replaceAll("(\r\n|\r|\n)", "<br />");
    narrative.setDivAsString(divEncodedText);
    subjective.setText(narrative);
    subjective.setSubject(new Reference("Patient/" + AllTests.getTestDatabaseInitializer().getPatient().getId()));
    subjective.addCategory().addCoding(new Coding(IdentifierSystem.ELEXIS_SOAP.getSystem(), ObservationCategory.SOAP_SUBJECTIVE.getCode(), ObservationCategory.SOAP_SUBJECTIVE.getLocalized()));
    subjective.setEncounter(new Reference(new IdType(encounter.getResourceType().name(), encounter.getId())));
    MethodOutcome subjectiveOutcome = client.create().resource(subjective).execute();
    assertTrue(subjectiveOutcome.getCreated());
    Encounter readEncounter = client.read().resource(Encounter.class).withId(outcome.getId()).execute();
    assertNotNull(readEncounter);
    assertEquals(outcome.getId().getIdPart(), readEncounter.getIdElement().getIdPart());
    assertEquals(encounter.getPeriod().getStart(), readEncounter.getPeriod().getStart());
}
Also used : Condition(org.hl7.fhir.r4.model.Condition) EncounterParticipantComponent(org.hl7.fhir.r4.model.Encounter.EncounterParticipantComponent) Coding(org.hl7.fhir.r4.model.Coding) Narrative(org.hl7.fhir.r4.model.Narrative) Reference(org.hl7.fhir.r4.model.Reference) Observation(org.hl7.fhir.r4.model.Observation) Encounter(org.hl7.fhir.r4.model.Encounter) Period(org.hl7.fhir.r4.model.Period) MethodOutcome(ca.uhn.fhir.rest.api.MethodOutcome) CodeableConcept(org.hl7.fhir.r4.model.CodeableConcept) IdType(org.hl7.fhir.r4.model.IdType) Test(org.junit.Test)

Example 65 with Observation

use of org.hl7.fhir.r5.model.Observation in project elexis-server by elexis.

the class ObservationTest method laboratoryObservations.

@Test
public void laboratoryObservations() throws FHIRException {
    // search by patient and category
    Bundle results = client.search().forResource(Observation.class).where(Observation.SUBJECT.hasId(AllTests.getTestDatabaseInitializer().getPatient().getId())).and(Condition.CATEGORY.exactly().code("laboratory")).returnBundle(Bundle.class).execute();
    assertNotNull(results);
    assertFalse(results.getEntry().isEmpty());
    @SuppressWarnings("unchecked") List<Observation> observations = (List<Observation>) ((List<?>) results.getEntry().parallelStream().map(be -> be.getResource()).collect(Collectors.toList()));
    for (Observation observation : observations) {
        assertTrue(observation.hasEffectiveDateTimeType());
        assertTrue(observation.hasValue());
        assertNotNull(observation.getCode());
        List<Coding> coding = observation.getCode().getCoding();
        assertFalse(coding.isEmpty());
        for (Coding code : coding) {
            if (code.getCode().contains("NUMERIC")) {
                if (observation.hasValueQuantity()) {
                    Quantity quantityValue = observation.getValueQuantity();
                    assertNotNull(quantityValue);
                } else if (observation.hasValueStringType()) {
                    StringType stringValue = observation.getValueStringType();
                    assertNotNull(stringValue);
                    assertTrue(Character.isDigit(stringValue.toString().charAt(0)));
                } else {
                    fail("Unexpected vaue type" + observation.getValue());
                }
                List<ObservationReferenceRangeComponent> refs = observation.getReferenceRange();
                assertFalse(refs.isEmpty());
            } else if (code.getCode().contains("TEXT")) {
                StringType stringValue = observation.getValueStringType();
                assertNotNull(stringValue);
            }
        }
    }
}
Also used : TransientCoding(ch.elexis.core.findings.util.model.TransientCoding) Coding(org.hl7.fhir.r4.model.Coding) StringType(org.hl7.fhir.r4.model.StringType) Bundle(org.hl7.fhir.r4.model.Bundle) ObservationReferenceRangeComponent(org.hl7.fhir.r4.model.Observation.ObservationReferenceRangeComponent) Observation(org.hl7.fhir.r4.model.Observation) IObservation(ch.elexis.core.findings.IObservation) Quantity(org.hl7.fhir.r4.model.Quantity) ArrayList(java.util.ArrayList) List(java.util.List) 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