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