Search in sources :

Example 1 with LastnResult

use of org.openmrs.module.fhir2.api.util.LastnResult in project openmrs-module-fhir2 by openmrs.

the class FhirObservationDaoImpl method getSearchResultUuids.

@Override
public List<String> getSearchResultUuids(@Nonnull SearchParameterMap theParams) {
    if (!theParams.getParameters(FhirConstants.LASTN_OBSERVATION_SEARCH_HANDLER).isEmpty()) {
        Criteria criteria = getSessionFactory().getCurrentSession().createCriteria(typeToken.getRawType());
        setupSearchParams(criteria, theParams);
        criteria.setProjection(Projections.projectionList().add(property("uuid")).add(property("concept")).add(property("obsDatetime")));
        @SuppressWarnings("unchecked") List<LastnResult> results = ((List<Object[]>) criteria.list()).stream().map(objects -> {
            Map<String, Object> attributes = new HashMap<>();
            attributes.put("concept", objects[1]);
            return new LastnResult(objects[0], objects[2], attributes);
        }).collect(Collectors.toList());
        return getLastnUuids(handleGrouping(results), getMaxParameter(theParams)).stream().distinct().collect(Collectors.toList());
    }
    if (!theParams.getParameters(FhirConstants.LASTN_ENCOUNTERS_SEARCH_HANDLER).isEmpty()) {
        ReferenceAndListParam encountersReferences = new ReferenceAndListParam();
        ReferenceOrListParam referenceOrListParam = new ReferenceOrListParam();
        List<String> encounters = encounterDao.getSearchResultUuids(theParams);
        encounters.forEach(encounter -> referenceOrListParam.addOr(new ReferenceParam().setValue(encounter)));
        encountersReferences.addAnd(referenceOrListParam);
        theParams.addParameter(FhirConstants.ENCOUNTER_REFERENCE_SEARCH_HANDLER, encountersReferences);
    }
    return super.getSearchResultUuids(theParams);
}
Also used : Criteria(org.hibernate.Criteria) QuantityAndListParam(ca.uhn.fhir.rest.param.QuantityAndListParam) Projections.property(org.hibernate.criterion.Projections.property) Autowired(org.springframework.beans.factory.annotation.Autowired) HashMap(java.util.HashMap) StringUtils(org.apache.commons.lang3.StringUtils) ArrayList(java.util.ArrayList) StringAndListParam(ca.uhn.fhir.rest.param.StringAndListParam) DateRangeParam(ca.uhn.fhir.rest.param.DateRangeParam) FhirObservationDao(org.openmrs.module.fhir2.api.dao.FhirObservationDao) Map(java.util.Map) ReferenceParam(ca.uhn.fhir.rest.param.ReferenceParam) FhirConstants(org.openmrs.module.fhir2.FhirConstants) Obs(org.openmrs.Obs) Nonnull(javax.annotation.Nonnull) Observation(org.hl7.fhir.r4.model.Observation) ReferenceOrListParam(ca.uhn.fhir.rest.param.ReferenceOrListParam) Criterion(org.hibernate.criterion.Criterion) SearchParameterMap(org.openmrs.module.fhir2.api.search.param.SearchParameterMap) LastnResult(org.openmrs.module.fhir2.api.util.LastnResult) ObservationCategoryMap(org.openmrs.module.fhir2.api.mappings.ObservationCategoryMap) LastnOperationUtils.getTopNRankedUuids(org.openmrs.module.fhir2.api.util.LastnOperationUtils.getTopNRankedUuids) ReferenceAndListParam(ca.uhn.fhir.rest.param.ReferenceAndListParam) Projections(org.hibernate.criterion.Projections) Collectors(java.util.stream.Collectors) TokenParam(ca.uhn.fhir.rest.param.TokenParam) Restrictions.eq(org.hibernate.criterion.Restrictions.eq) List(java.util.List) Component(org.springframework.stereotype.Component) Concept(org.openmrs.Concept) Optional(java.util.Optional) FhirEncounterDao(org.openmrs.module.fhir2.api.dao.FhirEncounterDao) NumberParam(ca.uhn.fhir.rest.param.NumberParam) TokenAndListParam(ca.uhn.fhir.rest.param.TokenAndListParam) Subqueries(org.hibernate.criterion.Subqueries) ReferenceParam(ca.uhn.fhir.rest.param.ReferenceParam) LastnResult(org.openmrs.module.fhir2.api.util.LastnResult) ReferenceAndListParam(ca.uhn.fhir.rest.param.ReferenceAndListParam) Criteria(org.hibernate.Criteria) ReferenceOrListParam(ca.uhn.fhir.rest.param.ReferenceOrListParam) ArrayList(java.util.ArrayList) List(java.util.List) HashMap(java.util.HashMap) Map(java.util.Map) SearchParameterMap(org.openmrs.module.fhir2.api.search.param.SearchParameterMap) ObservationCategoryMap(org.openmrs.module.fhir2.api.mappings.ObservationCategoryMap)

Example 2 with LastnResult

use of org.openmrs.module.fhir2.api.util.LastnResult in project openmrs-module-fhir2 by openmrs.

the class FhirEncounterDaoImpl method getSearchResultUuids.

@Override
public List<String> getSearchResultUuids(@Nonnull SearchParameterMap theParams) {
    if (!theParams.getParameters(FhirConstants.LASTN_ENCOUNTERS_SEARCH_HANDLER).isEmpty()) {
        Criteria criteria = getSessionFactory().getCurrentSession().createCriteria(typeToken.getRawType());
        setupSearchParams(criteria, theParams);
        criteria.setProjection(Projections.projectionList().add(property("uuid")).add(property("encounterDatetime")));
        @SuppressWarnings("unchecked") List<LastnResult> results = ((List<Object[]>) criteria.list()).stream().map(LastnResult::new).collect(Collectors.toList());
        return getTopNRankedUuids(results, getMaxParameter(theParams));
    }
    return super.getSearchResultUuids(theParams);
}
Also used : LastnResult(org.openmrs.module.fhir2.api.util.LastnResult) List(java.util.List) Criteria(org.hibernate.Criteria)

Aggregations

List (java.util.List)2 Criteria (org.hibernate.Criteria)2 LastnResult (org.openmrs.module.fhir2.api.util.LastnResult)2 DateRangeParam (ca.uhn.fhir.rest.param.DateRangeParam)1 NumberParam (ca.uhn.fhir.rest.param.NumberParam)1 QuantityAndListParam (ca.uhn.fhir.rest.param.QuantityAndListParam)1 ReferenceAndListParam (ca.uhn.fhir.rest.param.ReferenceAndListParam)1 ReferenceOrListParam (ca.uhn.fhir.rest.param.ReferenceOrListParam)1 ReferenceParam (ca.uhn.fhir.rest.param.ReferenceParam)1 StringAndListParam (ca.uhn.fhir.rest.param.StringAndListParam)1 TokenAndListParam (ca.uhn.fhir.rest.param.TokenAndListParam)1 TokenParam (ca.uhn.fhir.rest.param.TokenParam)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 Optional (java.util.Optional)1 Collectors (java.util.stream.Collectors)1 Nonnull (javax.annotation.Nonnull)1 StringUtils (org.apache.commons.lang3.StringUtils)1 Criterion (org.hibernate.criterion.Criterion)1