use of ch.elexis.core.model.IAppointment 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);
}
Aggregations