use of ch.elexis.core.services.IQuery in project elexis-server by elexis.
the class PersonResourceProvider method search.
@Search
public List<Person> search(@OptionalParam(name = Person.SP_NAME) StringParam name, @OptionalParam(name = ca.uhn.fhir.rest.api.Constants.PARAM_FILTER) StringAndListParam theFtFilter) {
IQuery<IPerson> query = modelService.getQuery(IPerson.class);
if (name != null) {
QueryUtil.andContactNameCriterion(query, name);
}
if (theFtFilter != null) {
new IContactSearchFilterQueryAdapter().adapt(query, theFtFilter);
}
List<IPerson> persons = query.execute();
List<Person> _persons = persons.parallelStream().map(org -> getTransformer().getFhirObject(org)).filter(Optional::isPresent).map(Optional::get).collect(Collectors.toList());
return _persons;
}
use of ch.elexis.core.services.IQuery in project elexis-server by elexis.
the class PractitionerResourceProvider method search.
@Search
public List<Practitioner> search(@OptionalParam(name = Practitioner.SP_NAME) StringParam name, @OptionalParam(name = ca.uhn.fhir.rest.api.Constants.PARAM_FILTER) StringAndListParam theFtFilter) {
IQuery<IMandator> query = coreModelService.getQuery(IMandator.class);
if (name != null) {
QueryUtil.andContactNameCriterion(query, name);
}
if (theFtFilter != null) {
new IContactSearchFilterQueryAdapter().adapt(query, theFtFilter);
}
List<IMandator> practitioners = query.execute();
List<Practitioner> _practitioners = practitioners.parallelStream().map(org -> getTransformer().getFhirObject(org)).filter(Optional::isPresent).map(Optional::get).collect(Collectors.toList());
return _practitioners;
}
use of ch.elexis.core.services.IQuery 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();
}
use of ch.elexis.core.services.IQuery in project elexis-server by elexis.
the class OrganizationResourceProvider method search.
@Search
public List<Organization> search(@OptionalParam(name = Organization.SP_NAME) StringParam name, @OptionalParam(name = ca.uhn.fhir.rest.api.Constants.PARAM_FILTER) StringAndListParam theFtFilter) {
IQuery<IOrganization> query = coreModelService.getQuery(IOrganization.class);
if (name != null) {
QueryUtil.andContactNameCriterion(query, name);
}
if (theFtFilter != null) {
new IContactSearchFilterQueryAdapter().adapt(query, theFtFilter);
}
// TODO default limit result number
List<IOrganization> organizations = query.execute();
List<Organization> _organizations = organizations.parallelStream().map(org -> getTransformer().getFhirObject(org)).filter(Optional::isPresent).map(Optional::get).collect(Collectors.toList());
return _organizations;
}
use of ch.elexis.core.services.IQuery in project elexis-server by elexis.
the class PatientResourceProvider method search.
@Search
public List<Patient> search(@OptionalParam(name = Patient.SP_IDENTIFIER) TokenParam identifier, @OptionalParam(name = Patient.SP_NAME) StringParam theName, @OptionalParam(name = Patient.SP_BIRTHDATE) DateParam theBirthDate, @OptionalParam(name = Patient.SP_ACTIVE) StringParam isActive, @OptionalParam(name = ca.uhn.fhir.rest.api.Constants.PARAM_FILTER) StringAndListParam theFtFilter, @Sort SortSpec theSort, SummaryEnum theSummary) {
boolean includeDeleted = (isActive != null) ? Boolean.valueOf(isActive.getValue()) : false;
IQuery<IPatient> query = coreModelService.getQuery(IPatient.class, includeDeleted);
if (identifier != null && Objects.equals(IdentifierSystem.ELEXIS_PATNR.getSystem(), identifier.getSystem())) {
query.and(ModelPackage.Literals.ICONTACT__CODE, COMPARATOR.EQUALS, identifier.getValue());
}
if (theName != null) {
QueryUtil.andContactNameCriterion(query, theName);
}
if (theBirthDate != null) {
LocalDate localDate = Instant.ofEpochMilli(theBirthDate.getValue().getTime()).atZone(ZoneId.systemDefault()).toLocalDate();
query.and(ModelPackage.Literals.IPERSON__DATE_OF_BIRTH, COMPARATOR.EQUALS, localDate);
}
if (theFtFilter != null) {
new IContactSearchFilterQueryAdapter().adapt(query, theFtFilter);
}
if (theSort != null) {
String param = theSort.getParamName();
SortOrderEnum order = theSort.getOrder();
switch(param) {
case Patient.SP_FAMILY:
query.orderBy(ModelPackage.Literals.ICONTACT__DESCRIPTION1, QueryUtil.sortOrderEnumToLocal(order));
break;
case Patient.SP_GIVEN:
query.orderBy(ModelPackage.Literals.ICONTACT__DESCRIPTION2, QueryUtil.sortOrderEnumToLocal(order));
break;
default:
log.info("sortParamName [{}] not supported.", param);
break;
}
}
List<IPatient> patients = query.execute();
List<Patient> _patients = patients.parallelStream().map(org -> getTransformer().getFhirObject(org, theSummary, Collections.emptySet())).filter(Optional::isPresent).map(Optional::get).collect(Collectors.toList());
return _patients;
}
Aggregations