Search in sources :

Example 1 with IObservation

use of ch.elexis.core.findings.IObservation 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 2 with IObservation

use of ch.elexis.core.findings.IObservation in project elexis-server by elexis.

the class ObservationTest method setupClass.

@BeforeClass
public static void setupClass() throws IOException, SQLException, ElexisException {
    AllTests.getTestDatabaseInitializer().initializeLabResult();
    AllTests.getTestDatabaseInitializer().initializeBehandlung();
    AllTests.getTestDatabaseInitializer().initializeMandant();
    client = FhirUtil.getGenericClient("http://localhost:8380/fhir");
    assertNotNull(client);
    IObservation persAnam = AllTests.getFindingsService().create(IObservation.class);
    persAnam.setCategory(ObservationCategory.SOCIALHISTORY);
    persAnam.setCoding(Collections.singletonList(new TransientCoding(ObservationCode.ANAM_PERSONAL)));
    persAnam.setText("Pers Anamnese 1");
    persAnam.setPatientId(AllTests.getTestDatabaseInitializer().getPatient().getId());
    IObservation risk = AllTests.getFindingsService().create(IObservation.class);
    risk.setCategory(ObservationCategory.SOCIALHISTORY);
    risk.setCoding(Collections.singletonList(new TransientCoding(ObservationCode.ANAM_RISK)));
    risk.setText("Risiken 1");
    risk.setPatientId(AllTests.getTestDatabaseInitializer().getPatient().getId());
    IEncounter encounter = AllTests.getFindingsService().create(IEncounter.class);
    encounter.setConsultationId(TestDatabaseInitializer.getBehandlung().getId());
    encounter.setPatientId(AllTests.getTestDatabaseInitializer().getPatient().getId());
    IObservation iObservation = AllTests.getFindingsService().create(IObservation.class);
    iObservation.setCategory(ObservationCategory.SOAP_SUBJECTIVE);
    iObservation.setText("Encounter test 1");
    iObservation.setPatientId(AllTests.getTestDatabaseInitializer().getPatient().getId());
    iObservation.setEncounter(encounter);
    IObservation vitalSign = AllTests.getFindingsService().create(IObservation.class);
    vitalSign.setObservationType(ObservationType.COMP);
    vitalSign.setCategory(ObservationCategory.VITALSIGNS);
    vitalSign.setCoding(Collections.singletonList(new TransientCoding(CodingSystem.ELEXIS_LOCAL_CODESYSTEM.getSystem(), "test", "display test")));
    ObservationComponent componentA = new ObservationComponent("componentA");
    componentA.setNumericValue(new BigDecimal("122"));
    componentA.setNumericValueUnit("mmHg");
    vitalSign.addComponent(componentA);
    ObservationComponent componentB = new ObservationComponent("componentB");
    componentB.setNumericValue(new BigDecimal("78"));
    componentB.setNumericValueUnit("mmHg");
    vitalSign.addComponent(componentB);
    vitalSign.setPatientId(AllTests.getTestDatabaseInitializer().getPatient().getId());
    vitalSign.setEncounter(encounter);
    new UpdateFindingTextCommand(vitalSign).execute();
    AllTests.getFindingsService().saveFinding(persAnam);
    AllTests.getFindingsService().saveFinding(risk);
    AllTests.getFindingsService().saveFinding(encounter);
    AllTests.getFindingsService().saveFinding(iObservation);
    AllTests.getFindingsService().saveFinding(vitalSign);
    findingsCreated.add(persAnam);
    findingsCreated.add(risk);
    findingsCreated.add(encounter);
    findingsCreated.add(iObservation);
    findingsCreated.add(vitalSign);
}
Also used : IEncounter(ch.elexis.core.findings.IEncounter) TransientCoding(ch.elexis.core.findings.util.model.TransientCoding) UpdateFindingTextCommand(ch.elexis.core.findings.util.commands.UpdateFindingTextCommand) BigDecimal(java.math.BigDecimal) IObservation(ch.elexis.core.findings.IObservation) ObservationComponent(ch.elexis.core.findings.ObservationComponent) BeforeClass(org.junit.BeforeClass)

Example 3 with IObservation

use of ch.elexis.core.findings.IObservation 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)3 Create (ca.uhn.fhir.rest.annotation.Create)2 MethodOutcome (ca.uhn.fhir.rest.api.MethodOutcome)2 InternalErrorException (ca.uhn.fhir.rest.server.exceptions.InternalErrorException)2 IdType (org.hl7.fhir.r4.model.IdType)2 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 DateRangeParam (ca.uhn.fhir.rest.param.DateRangeParam)1 IEncounter (ch.elexis.core.findings.IEncounter)1 IFindingsService (ch.elexis.core.findings.IFindingsService)1 ObservationCategory (ch.elexis.core.findings.IObservation.ObservationCategory)1 ObservationComponent (ch.elexis.core.findings.ObservationComponent)1 CodingSystem (ch.elexis.core.findings.codes.CodingSystem)1 CodeTypeUtil (ch.elexis.core.findings.util.CodeTypeUtil)1 DateRangeParamUtil (ch.elexis.core.findings.util.DateRangeParamUtil)1 UpdateFindingTextCommand (ch.elexis.core.findings.util.commands.UpdateFindingTextCommand)1