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;
}
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);
}
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();
}
Aggregations