Search in sources :

Example 1 with ILabResult

use of ch.elexis.core.model.ILabResult in project elexis-server by elexis.

the class ObservationTest method getObservation.

@Test
public void getObservation() {
    List<ILabResult> labResults = TestDatabaseInitializer.getLabResults();
    Observation readObservation = client.read().resource(Observation.class).withId(labResults.get(0).getId()).execute();
    assertNotNull(readObservation);
    // 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);
    List<BundleEntryComponent> entries = results.getEntry();
    assertFalse(entries.isEmpty());
    Observation observation = (Observation) entries.get(0).getResource();
    List<String> idList = entries.stream().map(p -> p.getResource().getId()).collect(Collectors.toList());
    assertTrue(idList.contains(observation.getId()));
    results = client.search().forResource(Observation.class).where(Observation.SUBJECT.hasId(AllTests.getTestDatabaseInitializer().getPatient().getId())).and(Condition.CATEGORY.exactly().code("abc")).returnBundle(Bundle.class).execute();
    assertNotNull(results);
    entries = results.getEntry();
    assertTrue(entries.isEmpty());
    // search with date parameter
    results = client.search().forResource(Observation.class).where(Observation.SUBJECT.hasId(AllTests.getTestDatabaseInitializer().getPatient().getId())).and(Observation.DATE.exactly().day(AllTests.getDate(LocalDateTime.of(2016, Month.DECEMBER, 14, 17, 44, 25)))).returnBundle(Bundle.class).execute();
    assertNotNull(results);
    entries = results.getEntry();
    assertFalse(entries.isEmpty());
    results = client.search().forResource(Observation.class).where(Observation.SUBJECT.hasId(AllTests.getTestDatabaseInitializer().getPatient().getId())).and(Observation.DATE.exactly().day(AllTests.getDate(LocalDateTime.of(2016, Month.DECEMBER, 1, 0, 0, 0)))).returnBundle(Bundle.class).execute();
    assertNotNull(results);
    entries = results.getEntry();
    assertTrue(entries.isEmpty());
    // search with date parameter and code
    results = client.search().forResource(Observation.class).where(Observation.SUBJECT.hasId(AllTests.getTestDatabaseInitializer().getPatient().getId())).and(Observation.CODE.exactly().systemAndCode(CodingSystem.ELEXIS_LOCAL_LABORATORY_VITOLABKEY.getSystem(), "2")).returnBundle(Bundle.class).execute();
    assertNotNull(results);
    entries = results.getEntry();
    assertFalse(entries.isEmpty());
    // search for pers anamnesis
    results = client.search().forResource(Observation.class).where(Observation.SUBJECT.hasId(AllTests.getTestDatabaseInitializer().getPatient().getId())).and(Observation.CODE.exactly().systemAndCode(ObservationCode.ANAM_PERSONAL.getIdentifierSystem().getSystem(), ObservationCode.ANAM_PERSONAL.getCode())).and(Observation.CATEGORY.exactly().code(ObservationCategory.SOCIALHISTORY.getCode())).returnBundle(Bundle.class).execute();
    assertNotNull(results);
    entries = results.getEntry();
    assertFalse(entries.isEmpty());
    assertTrue(((Observation) entries.get(0).getResource()).getText().getDivAsString().contains("Pers Anamnese 1"));
    // search for risk factors
    results = client.search().forResource(Observation.class).where(Observation.SUBJECT.hasId(AllTests.getTestDatabaseInitializer().getPatient().getId())).and(Observation.CODE.exactly().systemAndCode(ObservationCode.ANAM_RISK.getIdentifierSystem().getSystem(), ObservationCode.ANAM_RISK.getCode())).and(Observation.CATEGORY.exactly().code(ObservationCategory.SOCIALHISTORY.getCode())).returnBundle(Bundle.class).execute();
    assertNotNull(results);
    entries = results.getEntry();
    assertFalse(entries.isEmpty());
    assertTrue(((Observation) entries.get(0).getResource()).getText().getDivAsString().contains("Risiken 1"));
    // search for vital signs
    results = client.search().forResource(Observation.class).where(Observation.SUBJECT.hasId(AllTests.getTestDatabaseInitializer().getPatient().getId())).and(Observation.CATEGORY.exactly().code(ObservationCategory.VITALSIGNS.getCode())).returnBundle(Bundle.class).execute();
    assertNotNull(results);
    entries = results.getEntry();
    assertFalse(entries.isEmpty());
    assertTrue(((Observation) entries.get(0).getResource()).getText().getDivAsString().contains("display test"));
    // search for encounter
    results = client.search().forResource(Observation.class).where(Observation.SUBJECT.hasId(AllTests.getTestDatabaseInitializer().getPatient().getId())).and(Observation.ENCOUNTER.hasId(findingsCreated.get(2).getId())).returnBundle(Bundle.class).execute();
    assertNotNull(results);
    entries = results.getEntry();
    assertFalse(entries.isEmpty());
}
Also used : BeforeClass(org.junit.BeforeClass) ILabResult(ch.elexis.core.model.ILabResult) LocalDateTime(java.time.LocalDateTime) Condition(org.hl7.fhir.r4.model.Condition) ArrayList(java.util.ArrayList) BigDecimal(java.math.BigDecimal) IFinding(ch.elexis.core.findings.IFinding) SQLException(java.sql.SQLException) TestDatabaseInitializer(ch.elexis.core.test.initializer.TestDatabaseInitializer) ObservationComponent(ch.elexis.core.findings.ObservationComponent) StringType(org.hl7.fhir.r4.model.StringType) BundleEntryComponent(org.hl7.fhir.r4.model.Bundle.BundleEntryComponent) ObservationCategory(ch.elexis.core.findings.IObservation.ObservationCategory) Assert.fail(org.junit.Assert.fail) Quantity(org.hl7.fhir.r4.model.Quantity) IGenericClient(ca.uhn.fhir.rest.client.api.IGenericClient) Observation(org.hl7.fhir.r4.model.Observation) ObservationReferenceRangeComponent(org.hl7.fhir.r4.model.Observation.ObservationReferenceRangeComponent) IEncounter(ch.elexis.core.findings.IEncounter) AfterClass(org.junit.AfterClass) AllTests(info.elexis.server.fhir.rest.core.test.AllTests) Month(java.time.Month) ObservationType(ch.elexis.core.findings.IObservation.ObservationType) Assert.assertNotNull(org.junit.Assert.assertNotNull) ObservationCode(ch.elexis.core.findings.IObservation.ObservationCode) Assert.assertTrue(org.junit.Assert.assertTrue) IOException(java.io.IOException) Test(org.junit.Test) UpdateFindingTextCommand(ch.elexis.core.findings.util.commands.UpdateFindingTextCommand) TransientCoding(ch.elexis.core.findings.util.model.TransientCoding) Collectors(java.util.stream.Collectors) CodingSystem(ch.elexis.core.findings.codes.CodingSystem) ElexisException(ch.elexis.core.exceptions.ElexisException) IObservation(ch.elexis.core.findings.IObservation) List(java.util.List) Assert.assertFalse(org.junit.Assert.assertFalse) Coding(org.hl7.fhir.r4.model.Coding) FHIRException(org.hl7.fhir.exceptions.FHIRException) Bundle(org.hl7.fhir.r4.model.Bundle) Collections(java.util.Collections) FhirUtil(info.elexis.server.fhir.rest.core.test.FhirUtil) BundleEntryComponent(org.hl7.fhir.r4.model.Bundle.BundleEntryComponent) Bundle(org.hl7.fhir.r4.model.Bundle) ILabResult(ch.elexis.core.model.ILabResult) Observation(org.hl7.fhir.r4.model.Observation) IObservation(ch.elexis.core.findings.IObservation) Test(org.junit.Test)

Example 2 with ILabResult

use of ch.elexis.core.model.ILabResult in project elexis-server by elexis.

the class ObservationResourceProvider method findObservation.

@Search()
public List<Observation> findObservation(@RequiredParam(name = Observation.SP_SUBJECT) IdType theSubjectId, @OptionalParam(name = Observation.SP_CATEGORY) CodeType categoryCode, @OptionalParam(name = Observation.SP_CODE) CodeType code, @OptionalParam(name = Observation.SP_DATE) DateRangeParam dates, @OptionalParam(name = Observation.SP_ENCOUNTER) IdType contextId) {
    if (theSubjectId != null && !theSubjectId.isEmpty()) {
        Optional<IPatient> patient = modelService.load(theSubjectId.getIdPart(), IPatient.class);
        if (patient.isPresent()) {
            if (patient.get().isPatient()) {
                List<Observation> ret = new ArrayList<Observation>();
                // laboratory
                if (categoryCode == null || ObservationCategory.LABORATORY.name().equalsIgnoreCase(CodeTypeUtil.getCode(categoryCode).orElse(""))) {
                    List<Observation> intermediateRet = new ArrayList<>();
                    IQuery<ILabResult> resultQuery = modelService.getQuery(ILabResult.class);
                    resultQuery.and(ModelPackage.Literals.ILAB_RESULT__PATIENT, COMPARATOR.EQUALS, patient.get());
                    List<ILabResult> result = resultQuery.execute();
                    result.parallelStream().forEach(r -> getLabTransformer().getFhirObject(r).ifPresent(t -> intermediateRet.add(t)));
                    ret = sortLaboratory(intermediateRet);
                }
                // all other observations
                List<IObservation> findings = findingsService.getPatientsFindings(theSubjectId.getIdPart(), IObservation.class);
                if (findings != null && !findings.isEmpty()) {
                    for (IObservation iFinding : findings) {
                        if (categoryCode != null && !isObservationCategory(iFinding, categoryCode)) {
                            continue;
                        }
                        Optional<Observation> fhirObservation = getTransformer().getFhirObject(iFinding);
                        if (fhirObservation.isPresent()) {
                            ret.add(fhirObservation.get());
                        }
                    }
                }
                if (dates != null) {
                    ret = filterDates(ret, dates);
                }
                if (code != null) {
                    ret = filterCode(ret, code);
                }
                if (contextId != null) {
                    ret = filterContext(ret, contextId);
                }
                return ret;
            }
        }
    }
    return Collections.emptyList();
}
Also used : IdParam(ca.uhn.fhir.rest.annotation.IdParam) IFindingsService(ch.elexis.core.findings.IFindingsService) ModelPackage(ch.elexis.core.model.ModelPackage) IFhirTransformerRegistry(ch.elexis.core.findings.util.fhir.IFhirTransformerRegistry) ILabResult(ch.elexis.core.model.ILabResult) IFhirTransformer(ch.elexis.core.findings.util.fhir.IFhirTransformer) COMPARATOR(ch.elexis.core.services.IQuery.COMPARATOR) MethodOutcome(ca.uhn.fhir.rest.api.MethodOutcome) ArrayList(java.util.ArrayList) RequiredParam(ca.uhn.fhir.rest.annotation.RequiredParam) CodeTypeUtil(ch.elexis.core.findings.util.CodeTypeUtil) IModelService(ch.elexis.core.services.IModelService) Component(org.osgi.service.component.annotations.Component) DateRangeParam(ca.uhn.fhir.rest.param.DateRangeParam) IBaseResource(org.hl7.fhir.instance.model.api.IBaseResource) Search(ca.uhn.fhir.rest.annotation.Search) ObservationCategory(ch.elexis.core.findings.IObservation.ObservationCategory) Observation(org.hl7.fhir.r4.model.Observation) Read(ca.uhn.fhir.rest.annotation.Read) IPatient(ch.elexis.core.model.IPatient) DateRangeParamUtil(ch.elexis.core.findings.util.DateRangeParamUtil) Create(ca.uhn.fhir.rest.annotation.Create) Collectors(java.util.stream.Collectors) InternalErrorException(ca.uhn.fhir.rest.server.exceptions.InternalErrorException) IdType(org.hl7.fhir.r4.model.IdType) CodingSystem(ch.elexis.core.findings.codes.CodingSystem) IObservation(ch.elexis.core.findings.IObservation) IQuery(ch.elexis.core.services.IQuery) List(java.util.List) ResourceParam(ca.uhn.fhir.rest.annotation.ResourceParam) Coding(org.hl7.fhir.r4.model.Coding) Optional(java.util.Optional) FHIRException(org.hl7.fhir.exceptions.FHIRException) CodeType(org.hl7.fhir.r4.model.CodeType) OptionalParam(ca.uhn.fhir.rest.annotation.OptionalParam) Comparator(java.util.Comparator) Reference(org.osgi.service.component.annotations.Reference) Collections(java.util.Collections) Observation(org.hl7.fhir.r4.model.Observation) IObservation(ch.elexis.core.findings.IObservation) ArrayList(java.util.ArrayList) ILabResult(ch.elexis.core.model.ILabResult) IPatient(ch.elexis.core.model.IPatient) IObservation(ch.elexis.core.findings.IObservation) Search(ca.uhn.fhir.rest.annotation.Search)

Aggregations

IObservation (ch.elexis.core.findings.IObservation)2 ObservationCategory (ch.elexis.core.findings.IObservation.ObservationCategory)2 CodingSystem (ch.elexis.core.findings.codes.CodingSystem)2 ILabResult (ch.elexis.core.model.ILabResult)2 ArrayList (java.util.ArrayList)2 Collections (java.util.Collections)2 List (java.util.List)2 Collectors (java.util.stream.Collectors)2 FHIRException (org.hl7.fhir.exceptions.FHIRException)2 Coding (org.hl7.fhir.r4.model.Coding)2 Observation (org.hl7.fhir.r4.model.Observation)2 Create (ca.uhn.fhir.rest.annotation.Create)1 IdParam (ca.uhn.fhir.rest.annotation.IdParam)1 OptionalParam (ca.uhn.fhir.rest.annotation.OptionalParam)1 Read (ca.uhn.fhir.rest.annotation.Read)1 RequiredParam (ca.uhn.fhir.rest.annotation.RequiredParam)1 ResourceParam (ca.uhn.fhir.rest.annotation.ResourceParam)1 Search (ca.uhn.fhir.rest.annotation.Search)1 MethodOutcome (ca.uhn.fhir.rest.api.MethodOutcome)1 IGenericClient (ca.uhn.fhir.rest.client.api.IGenericClient)1