Search in sources :

Example 1 with IQuery

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;
}
Also used : IdParam(ca.uhn.fhir.rest.annotation.IdParam) IFhirTransformerRegistry(ch.elexis.core.findings.util.fhir.IFhirTransformerRegistry) IFhirTransformer(ch.elexis.core.findings.util.fhir.IFhirTransformer) LoggerFactory(org.slf4j.LoggerFactory) MethodOutcome(ca.uhn.fhir.rest.api.MethodOutcome) Update(ca.uhn.fhir.rest.annotation.Update) 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) Delete(ca.uhn.fhir.rest.annotation.Delete) Activate(org.osgi.service.component.annotations.Activate) Person(org.hl7.fhir.r4.model.Person) ResourceNotFoundException(ca.uhn.fhir.rest.server.exceptions.ResourceNotFoundException) Read(ca.uhn.fhir.rest.annotation.Read) Logger(org.slf4j.Logger) Create(ca.uhn.fhir.rest.annotation.Create) IPerson(ch.elexis.core.model.IPerson) Collectors(java.util.stream.Collectors) IdType(org.hl7.fhir.r4.model.IdType) IQuery(ch.elexis.core.services.IQuery) List(java.util.List) ResourceParam(ca.uhn.fhir.rest.annotation.ResourceParam) QueryUtil(es.fhir.rest.core.resources.util.QueryUtil) 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) IPerson(ch.elexis.core.model.IPerson) Optional(java.util.Optional) IContactSearchFilterQueryAdapter(es.fhir.rest.core.resources.util.IContactSearchFilterQueryAdapter) Person(org.hl7.fhir.r4.model.Person) IPerson(ch.elexis.core.model.IPerson) Search(ca.uhn.fhir.rest.annotation.Search)

Example 2 with IQuery

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;
}
Also used : Practitioner(org.hl7.fhir.r4.model.Practitioner) IMandator(ch.elexis.core.model.IMandator) IFhirTransformerRegistry(ch.elexis.core.findings.util.fhir.IFhirTransformerRegistry) IFhirTransformer(ch.elexis.core.findings.util.fhir.IFhirTransformer) Collectors(java.util.stream.Collectors) StringAndListParam(ca.uhn.fhir.rest.param.StringAndListParam) IModelService(ch.elexis.core.services.IModelService) IQuery(ch.elexis.core.services.IQuery) List(java.util.List) Component(org.osgi.service.component.annotations.Component) IUserService(ch.elexis.core.services.IUserService) IBaseResource(org.hl7.fhir.instance.model.api.IBaseResource) Search(ca.uhn.fhir.rest.annotation.Search) IContactSearchFilterQueryAdapter(es.fhir.rest.core.resources.util.IContactSearchFilterQueryAdapter) QueryUtil(es.fhir.rest.core.resources.util.QueryUtil) StringParam(ca.uhn.fhir.rest.param.StringParam) Optional(java.util.Optional) Activate(org.osgi.service.component.annotations.Activate) OptionalParam(ca.uhn.fhir.rest.annotation.OptionalParam) Reference(org.osgi.service.component.annotations.Reference) Practitioner(org.hl7.fhir.r4.model.Practitioner) Optional(java.util.Optional) IMandator(ch.elexis.core.model.IMandator) IContactSearchFilterQueryAdapter(es.fhir.rest.core.resources.util.IContactSearchFilterQueryAdapter) Search(ca.uhn.fhir.rest.annotation.Search)

Example 3 with IQuery

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();
}
Also used : IdParam(ca.uhn.fhir.rest.annotation.IdParam) IFindingsService(ch.elexis.core.findings.IFindingsService) ModelPackage(ch.elexis.core.model.ModelPackage) IFhirTransformerRegistry(ch.elexis.core.findings.util.fhir.IFhirTransformerRegistry) ILabResult(ch.elexis.core.model.ILabResult) IFhirTransformer(ch.elexis.core.findings.util.fhir.IFhirTransformer) COMPARATOR(ch.elexis.core.services.IQuery.COMPARATOR) MethodOutcome(ca.uhn.fhir.rest.api.MethodOutcome) ArrayList(java.util.ArrayList) RequiredParam(ca.uhn.fhir.rest.annotation.RequiredParam) CodeTypeUtil(ch.elexis.core.findings.util.CodeTypeUtil) IModelService(ch.elexis.core.services.IModelService) Component(org.osgi.service.component.annotations.Component) DateRangeParam(ca.uhn.fhir.rest.param.DateRangeParam) IBaseResource(org.hl7.fhir.instance.model.api.IBaseResource) Search(ca.uhn.fhir.rest.annotation.Search) ObservationCategory(ch.elexis.core.findings.IObservation.ObservationCategory) Observation(org.hl7.fhir.r4.model.Observation) Read(ca.uhn.fhir.rest.annotation.Read) IPatient(ch.elexis.core.model.IPatient) DateRangeParamUtil(ch.elexis.core.findings.util.DateRangeParamUtil) Create(ca.uhn.fhir.rest.annotation.Create) Collectors(java.util.stream.Collectors) InternalErrorException(ca.uhn.fhir.rest.server.exceptions.InternalErrorException) IdType(org.hl7.fhir.r4.model.IdType) CodingSystem(ch.elexis.core.findings.codes.CodingSystem) IObservation(ch.elexis.core.findings.IObservation) IQuery(ch.elexis.core.services.IQuery) List(java.util.List) ResourceParam(ca.uhn.fhir.rest.annotation.ResourceParam) Coding(org.hl7.fhir.r4.model.Coding) Optional(java.util.Optional) FHIRException(org.hl7.fhir.exceptions.FHIRException) CodeType(org.hl7.fhir.r4.model.CodeType) OptionalParam(ca.uhn.fhir.rest.annotation.OptionalParam) Comparator(java.util.Comparator) Reference(org.osgi.service.component.annotations.Reference) Collections(java.util.Collections) Observation(org.hl7.fhir.r4.model.Observation) IObservation(ch.elexis.core.findings.IObservation) ArrayList(java.util.ArrayList) ILabResult(ch.elexis.core.model.ILabResult) IPatient(ch.elexis.core.model.IPatient) IObservation(ch.elexis.core.findings.IObservation) Search(ca.uhn.fhir.rest.annotation.Search)

Example 4 with IQuery

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;
}
Also used : IFhirTransformerRegistry(ch.elexis.core.findings.util.fhir.IFhirTransformerRegistry) IFhirTransformer(ch.elexis.core.findings.util.fhir.IFhirTransformer) Collectors(java.util.stream.Collectors) StringAndListParam(ca.uhn.fhir.rest.param.StringAndListParam) IOrganization(ch.elexis.core.model.IOrganization) Organization(org.hl7.fhir.r4.model.Organization) IModelService(ch.elexis.core.services.IModelService) IQuery(ch.elexis.core.services.IQuery) List(java.util.List) 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) QueryUtil(es.fhir.rest.core.resources.util.QueryUtil) StringParam(ca.uhn.fhir.rest.param.StringParam) Optional(java.util.Optional) Activate(org.osgi.service.component.annotations.Activate) OptionalParam(ca.uhn.fhir.rest.annotation.OptionalParam) Reference(org.osgi.service.component.annotations.Reference) IOrganization(ch.elexis.core.model.IOrganization) IOrganization(ch.elexis.core.model.IOrganization) Organization(org.hl7.fhir.r4.model.Organization) Optional(java.util.Optional) IContactSearchFilterQueryAdapter(es.fhir.rest.core.resources.util.IContactSearchFilterQueryAdapter) Search(ca.uhn.fhir.rest.annotation.Search)

Example 5 with IQuery

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;
}
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

OptionalParam (ca.uhn.fhir.rest.annotation.OptionalParam)5 Search (ca.uhn.fhir.rest.annotation.Search)5 IFhirTransformer (ch.elexis.core.findings.util.fhir.IFhirTransformer)5 IFhirTransformerRegistry (ch.elexis.core.findings.util.fhir.IFhirTransformerRegistry)5 IModelService (ch.elexis.core.services.IModelService)5 IQuery (ch.elexis.core.services.IQuery)5 List (java.util.List)5 Optional (java.util.Optional)5 Collectors (java.util.stream.Collectors)5 IBaseResource (org.hl7.fhir.instance.model.api.IBaseResource)5 Component (org.osgi.service.component.annotations.Component)5 Reference (org.osgi.service.component.annotations.Reference)5 StringAndListParam (ca.uhn.fhir.rest.param.StringAndListParam)4 StringParam (ca.uhn.fhir.rest.param.StringParam)4 IContactSearchFilterQueryAdapter (es.fhir.rest.core.resources.util.IContactSearchFilterQueryAdapter)4 QueryUtil (es.fhir.rest.core.resources.util.QueryUtil)4 Activate (org.osgi.service.component.annotations.Activate)4 Create (ca.uhn.fhir.rest.annotation.Create)2 IdParam (ca.uhn.fhir.rest.annotation.IdParam)2 Read (ca.uhn.fhir.rest.annotation.Read)2