Search in sources :

Example 1 with SortOrderEnum

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);
}
Also used : IAppointment(ch.elexis.core.model.IAppointment) DateConverter(ch.elexis.core.time.DateConverter) SortOrderEnum(ca.uhn.fhir.rest.api.SortOrderEnum) COMPARATOR(ch.elexis.core.services.IQuery.COMPARATOR) LocalDate(java.time.LocalDate) SortSpec(ca.uhn.fhir.rest.api.SortSpec) Search(ca.uhn.fhir.rest.annotation.Search)

Example 2 with SortOrderEnum

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;
}
Also used : ModelPackage(ch.elexis.core.model.ModelPackage) IdentifierSystem(ch.elexis.core.findings.IdentifierSystem) IFhirTransformerRegistry(ch.elexis.core.findings.util.fhir.IFhirTransformerRegistry) IFhirTransformer(ch.elexis.core.findings.util.fhir.IFhirTransformer) COMPARATOR(ch.elexis.core.services.IQuery.COMPARATOR) SummaryEnum(ca.uhn.fhir.rest.api.SummaryEnum) StringAndListParam(ca.uhn.fhir.rest.param.StringAndListParam) IModelService(ch.elexis.core.services.IModelService) Component(org.osgi.service.component.annotations.Component) IBaseResource(org.hl7.fhir.instance.model.api.IBaseResource) Search(ca.uhn.fhir.rest.annotation.Search) IContactSearchFilterQueryAdapter(es.fhir.rest.core.resources.util.IContactSearchFilterQueryAdapter) Activate(org.osgi.service.component.annotations.Activate) Patient(org.hl7.fhir.r4.model.Patient) SortOrderEnum(ca.uhn.fhir.rest.api.SortOrderEnum) IPatient(ch.elexis.core.model.IPatient) Sort(ca.uhn.fhir.rest.annotation.Sort) Instant(java.time.Instant) Collectors(java.util.stream.Collectors) ZoneId(java.time.ZoneId) TokenParam(ca.uhn.fhir.rest.param.TokenParam) Objects(java.util.Objects) IQuery(ch.elexis.core.services.IQuery) List(java.util.List) SortSpec(ca.uhn.fhir.rest.api.SortSpec) QueryUtil(es.fhir.rest.core.resources.util.QueryUtil) LocalDate(java.time.LocalDate) StringParam(ca.uhn.fhir.rest.param.StringParam) Optional(java.util.Optional) OptionalParam(ca.uhn.fhir.rest.annotation.OptionalParam) Reference(org.osgi.service.component.annotations.Reference) Collections(java.util.Collections) DateParam(ca.uhn.fhir.rest.param.DateParam) SortOrderEnum(ca.uhn.fhir.rest.api.SortOrderEnum) Optional(java.util.Optional) IContactSearchFilterQueryAdapter(es.fhir.rest.core.resources.util.IContactSearchFilterQueryAdapter) Patient(org.hl7.fhir.r4.model.Patient) IPatient(ch.elexis.core.model.IPatient) LocalDate(java.time.LocalDate) IPatient(ch.elexis.core.model.IPatient) Search(ca.uhn.fhir.rest.annotation.Search)

Aggregations

Search (ca.uhn.fhir.rest.annotation.Search)2 SortOrderEnum (ca.uhn.fhir.rest.api.SortOrderEnum)2 SortSpec (ca.uhn.fhir.rest.api.SortSpec)2 COMPARATOR (ch.elexis.core.services.IQuery.COMPARATOR)2 LocalDate (java.time.LocalDate)2 OptionalParam (ca.uhn.fhir.rest.annotation.OptionalParam)1 Sort (ca.uhn.fhir.rest.annotation.Sort)1 SummaryEnum (ca.uhn.fhir.rest.api.SummaryEnum)1 DateParam (ca.uhn.fhir.rest.param.DateParam)1 StringAndListParam (ca.uhn.fhir.rest.param.StringAndListParam)1 StringParam (ca.uhn.fhir.rest.param.StringParam)1 TokenParam (ca.uhn.fhir.rest.param.TokenParam)1 IdentifierSystem (ch.elexis.core.findings.IdentifierSystem)1 IFhirTransformer (ch.elexis.core.findings.util.fhir.IFhirTransformer)1 IFhirTransformerRegistry (ch.elexis.core.findings.util.fhir.IFhirTransformerRegistry)1 IAppointment (ch.elexis.core.model.IAppointment)1 IPatient (ch.elexis.core.model.IPatient)1 ModelPackage (ch.elexis.core.model.ModelPackage)1 IModelService (ch.elexis.core.services.IModelService)1 IQuery (ch.elexis.core.services.IQuery)1