use of ca.uhn.fhir.rest.api.SortOrderEnum in project elexis-server by elexis.
the class AppointmentResourceProvider method search.
@Search
public List<Appointment> search(@OptionalParam(name = Appointment.SP_DATE) DateRangeParam dateParam, @OptionalParam(name = Appointment.SP_SERVICE_CATEGORY) TokenParam serviceCategoryParam, @OptionalParam(name = Appointment.SP_PATIENT) StringParam patientParam, @Sort SortSpec theSort, @Count Integer theCount) {
// TODO default limit, offset, paging
IQuery<IAppointment> query = coreModelService.getQuery(IAppointment.class);
// TODO configurable
query.and(ModelPackage.Literals.IAPPOINTMENT__TYPE, COMPARATOR.NOT_EQUALS, "gesperrt");
if (serviceCategoryParam != null && StringUtils.equalsIgnoreCase(CodingSystem.ELEXIS_AGENDA_AREA_ID.getSystem(), serviceCategoryParam.getSystem())) {
query.and(ModelPackage.Literals.IAPPOINTMENT__SCHEDULE, COMPARATOR.EQUALS, serviceCategoryParam.getValue());
}
if (dateParam != null) {
DateConverter dateConverter = new DateConverter();
if (dateParam.getLowerBound() != null) {
LocalDate dayParam = dateConverter.convertToLocalDate(dateParam.getLowerBound().getValue());
COMPARATOR compare = QueryUtil.prefixParamToToQueryParam(dateParam.getLowerBound().getPrefix());
query.and("tag", compare, dayParam);
}
if (dateParam.getUpperBound() != null) {
LocalDate dayParam2 = dateConverter.convertToLocalDate(dateParam.getUpperBound().getValue());
COMPARATOR compare2 = QueryUtil.prefixParamToToQueryParam(dateParam.getUpperBound().getPrefix());
query.and("tag", compare2, dayParam2);
}
}
if (patientParam != null) {
String patientId = patientParam.getValue();
query.and(ModelPackage.Literals.IAPPOINTMENT__SUBJECT_OR_PATIENT, COMPARATOR.EQUALS, patientId);
}
if (theSort == null) {
theSort = new SortSpec(Appointment.SP_DATE, SortOrderEnum.ASC);
}
if (theSort != null) {
String param = theSort.getParamName();
SortOrderEnum order = theSort.getOrder();
switch(param) {
case Appointment.SP_DATE:
query.orderBy("Tag", QueryUtil.sortOrderEnumToLocal(order));
query.orderBy("Beginn", QueryUtil.sortOrderEnumToLocal(order));
break;
default:
log.info("sortParamName [{}] not supported.", param);
break;
}
}
if (theCount != null) {
// TODO only valid with theSort set, somehow combine?
query.limit(theCount.intValue());
}
return super.handleExecute(query);
}
use of ca.uhn.fhir.rest.api.SortOrderEnum 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