Skip to content

Commit

Permalink
fix medication request integration test
Browse files Browse the repository at this point in the history
  • Loading branch information
mherman22 committed Sep 27, 2023
1 parent 6d39c58 commit 1c13866
Show file tree
Hide file tree
Showing 21 changed files with 1,796 additions and 2,843 deletions.
Original file line number Diff line number Diff line change
@@ -1,147 +1,145 @@
/*
* This Source Code Form is subject to the terms of the Mozilla Public License,
* v. 2.0. If a copy of the MPL was not distributed with this file, You can
* obtain one at http://mozilla.org/MPL/2.0/. OpenMRS is also distributed under
* the terms of the Healthcare Disclaimer located at http://openmrs.org/license.
*
* Copyright (C) OpenMRS Inc. OpenMRS is a registered trademark and the OpenMRS
* graphic logo is a trademark of OpenMRS Inc.
*/
package org.openmrs.module.fhir2.api.dao.impl;

import static org.hibernate.criterion.Projections.property;
import static org.hibernate.criterion.Restrictions.eq;
import static org.hl7.fhir.r4.model.Encounter.SP_DATE;
import static org.openmrs.module.fhir2.api.util.LastnOperationUtils.getTopNRankedIds;

import javax.annotation.Nonnull;

import java.util.List;
import java.util.Optional;
import java.util.stream.Collectors;

import ca.uhn.fhir.rest.param.DateRangeParam;
import ca.uhn.fhir.rest.param.NumberParam;
import ca.uhn.fhir.rest.param.ReferenceAndListParam;
import ca.uhn.fhir.rest.param.TokenAndListParam;
import lombok.AccessLevel;
import lombok.Setter;
import org.apache.commons.lang3.StringUtils;
import org.hibernate.Criteria;
import org.hibernate.criterion.Criterion;
import org.hibernate.criterion.Projections;
import org.hibernate.criterion.Restrictions;
import org.openmrs.Encounter;
import org.openmrs.Order;
import org.openmrs.annotation.OpenmrsProfile;
import org.openmrs.module.fhir2.FhirConstants;
import org.openmrs.module.fhir2.api.dao.FhirEncounterDao;
import org.openmrs.module.fhir2.api.search.param.SearchParameterMap;
import org.openmrs.module.fhir2.api.util.LastnResult;
import org.springframework.stereotype.Component;

@Component
@Setter(AccessLevel.PACKAGE)
public class FhirEncounterDaoImpl extends BaseEncounterDao<Encounter> implements FhirEncounterDao {

@Override
public boolean hasDistinctResults() {
return false;
}

@Override
public List<String> getSearchResultUuids(@Nonnull SearchParameterMap theParams) {
if (!theParams.getParameters(FhirConstants.LASTN_ENCOUNTERS_SEARCH_HANDLER).isEmpty()) {
Criteria criteria = getSessionFactory().getCurrentSession().createCriteria(Encounter.class);

setupSearchParams(criteria, theParams);

criteria.setProjection(Projections.projectionList().add(property("uuid")).add(property("encounterDatetime")));

@SuppressWarnings("unchecked")
List<LastnResult<String>> results = ((List<Object[]>) criteria.list()).stream()
.map(array -> new LastnResult<String>(array)).collect(Collectors.toList());

return getTopNRankedIds(results, getMaxParameter(theParams));
}

Criteria criteria = getSessionFactory().getCurrentSession().createCriteria(Encounter.class);

handleVoidable(criteria);

setupSearchParams(criteria, theParams);
handleSort(criteria, theParams.getSortSpec());

criteria.setProjection(Projections.property("uuid"));

@SuppressWarnings("unchecked")
List<String> results = criteria.list();

return results.stream().distinct().collect(Collectors.toList());
}

private int getMaxParameter(SearchParameterMap theParams) {
return ((NumberParam) theParams.getParameters(FhirConstants.MAX_SEARCH_HANDLER).get(0).getParam()).getValue()
.intValue();
}

@Override
protected void handleDate(Criteria criteria, DateRangeParam dateRangeParam) {
handleDateRange("encounterDatetime", dateRangeParam).ifPresent(criteria::add);
}

@Override
protected void handleEncounterType(Criteria criteria, TokenAndListParam tokenAndListParam) {
handleAndListParam(tokenAndListParam, t -> Optional.of(eq("et.uuid", t.getValue())))
.ifPresent(t -> criteria.createAlias("encounterType", "et").add(t));
}

@Override
protected void handleParticipant(Criteria criteria, ReferenceAndListParam referenceAndListParam) {
criteria.createAlias("encounterProviders", "ep");
handleParticipantReference(criteria, referenceAndListParam);
}

@Override
protected String paramToProp(@Nonnull String param) {
switch (param) {
case SP_DATE:
return "encounterDatetime";
default:
return null;
}
}


@Override
protected Criterion generateNotCompletedOrderQuery(String path) {
if (StringUtils.isNotBlank(path)) {
path = path + ".";
}

return Restrictions.or(Restrictions.isNull(path + "fulfillerStatus"),
Restrictions.ne(path + "fulfillerStatus", org.openmrs.Order.FulfillerStatus.COMPLETED));

}

@Override
protected Criterion generateFulfillerStatusRestriction(String path, String fulfillerStatus) {

if (StringUtils.isNotBlank(path)) {
path = path + ".";
}

return Restrictions.eq(path + "fulfillerStatus", Order.FulfillerStatus.valueOf(fulfillerStatus.toUpperCase()));
}

@Override
protected Criterion generateNotFulfillerStatusRestriction(String path, String fulfillerStatus) {

if (StringUtils.isNotBlank(path)) {
path = path + ".";
}

return Restrictions.or(Restrictions.isNull(path + "fulfillerStatus"),
Restrictions.ne(path + "fulfillerStatus", Order.FulfillerStatus.valueOf(fulfillerStatus.toUpperCase())));
}
}
/*
* This Source Code Form is subject to the terms of the Mozilla Public License,
* v. 2.0. If a copy of the MPL was not distributed with this file, You can
* obtain one at http://mozilla.org/MPL/2.0/. OpenMRS is also distributed under
* the terms of the Healthcare Disclaimer located at http://openmrs.org/license.
*
* Copyright (C) OpenMRS Inc. OpenMRS is a registered trademark and the OpenMRS
* graphic logo is a trademark of OpenMRS Inc.
*/
package org.openmrs.module.fhir2.api.dao.impl;

import static org.hibernate.criterion.Projections.property;
import static org.hibernate.criterion.Restrictions.eq;
import static org.hl7.fhir.r4.model.Encounter.SP_DATE;
import static org.openmrs.module.fhir2.api.util.LastnOperationUtils.getTopNRankedIds;

import javax.annotation.Nonnull;

import java.util.List;
import java.util.Optional;
import java.util.stream.Collectors;

import ca.uhn.fhir.rest.param.DateRangeParam;
import ca.uhn.fhir.rest.param.NumberParam;
import ca.uhn.fhir.rest.param.ReferenceAndListParam;
import ca.uhn.fhir.rest.param.TokenAndListParam;
import lombok.AccessLevel;
import lombok.Setter;
import org.apache.commons.lang3.StringUtils;
import org.hibernate.Criteria;
import org.hibernate.criterion.Criterion;
import org.hibernate.criterion.Projections;
import org.hibernate.criterion.Restrictions;
import org.openmrs.Encounter;
import org.openmrs.Order;
import org.openmrs.module.fhir2.FhirConstants;
import org.openmrs.module.fhir2.api.dao.FhirEncounterDao;
import org.openmrs.module.fhir2.api.search.param.SearchParameterMap;
import org.openmrs.module.fhir2.api.util.LastnResult;
import org.springframework.stereotype.Component;

@Component
@Setter(AccessLevel.PACKAGE)
public class FhirEncounterDaoImpl extends BaseEncounterDao<Encounter> implements FhirEncounterDao {

@Override
public boolean hasDistinctResults() {
return false;
}

@Override
public List<String> getSearchResultUuids(@Nonnull SearchParameterMap theParams) {
if (!theParams.getParameters(FhirConstants.LASTN_ENCOUNTERS_SEARCH_HANDLER).isEmpty()) {
Criteria criteria = getSessionFactory().getCurrentSession().createCriteria(Encounter.class);

setupSearchParams(criteria, theParams);

criteria.setProjection(Projections.projectionList().add(property("uuid")).add(property("encounterDatetime")));

@SuppressWarnings("unchecked")
List<LastnResult<String>> results = ((List<Object[]>) criteria.list()).stream()
.map(array -> new LastnResult<String>(array)).collect(Collectors.toList());

return getTopNRankedIds(results, getMaxParameter(theParams));
}

Criteria criteria = getSessionFactory().getCurrentSession().createCriteria(Encounter.class);

handleVoidable(criteria);

setupSearchParams(criteria, theParams);
handleSort(criteria, theParams.getSortSpec());

criteria.setProjection(Projections.property("uuid"));

@SuppressWarnings("unchecked")
List<String> results = criteria.list();

return results.stream().distinct().collect(Collectors.toList());
}

private int getMaxParameter(SearchParameterMap theParams) {
return ((NumberParam) theParams.getParameters(FhirConstants.MAX_SEARCH_HANDLER).get(0).getParam()).getValue()
.intValue();
}

@Override
protected void handleDate(Criteria criteria, DateRangeParam dateRangeParam) {
handleDateRange("encounterDatetime", dateRangeParam).ifPresent(criteria::add);
}

@Override
protected void handleEncounterType(Criteria criteria, TokenAndListParam tokenAndListParam) {
handleAndListParam(tokenAndListParam, t -> Optional.of(eq("et.uuid", t.getValue())))
.ifPresent(t -> criteria.createAlias("encounterType", "et").add(t));
}

@Override
protected void handleParticipant(Criteria criteria, ReferenceAndListParam referenceAndListParam) {
criteria.createAlias("encounterProviders", "ep");
handleParticipantReference(criteria, referenceAndListParam);
}

@Override
protected String paramToProp(@Nonnull String param) {
switch (param) {
case SP_DATE:
return "encounterDatetime";
default:
return null;
}
}

@Override
protected Criterion generateNotCompletedOrderQuery(String path) {
if (StringUtils.isNotBlank(path)) {
path = path + ".";
}

return Restrictions.or(Restrictions.isNull(path + "fulfillerStatus"),
Restrictions.ne(path + "fulfillerStatus", org.openmrs.Order.FulfillerStatus.COMPLETED));

}

@Override
protected Criterion generateFulfillerStatusRestriction(String path, String fulfillerStatus) {

if (StringUtils.isNotBlank(path)) {
path = path + ".";
}

return Restrictions.eq(path + "fulfillerStatus", Order.FulfillerStatus.valueOf(fulfillerStatus.toUpperCase()));
}

@Override
protected Criterion generateNotFulfillerStatusRestriction(String path, String fulfillerStatus) {

if (StringUtils.isNotBlank(path)) {
path = path + ".";
}

return Restrictions.or(Restrictions.isNull(path + "fulfillerStatus"),
Restrictions.ne(path + "fulfillerStatus", Order.FulfillerStatus.valueOf(fulfillerStatus.toUpperCase())));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ protected void setupSearchParams(Criteria criteria, SearchParameterMap theParams
switch (entry.getKey()) {
case FhirConstants.FULFILLER_STATUS_SEARCH_HANDLER:
entry.getValue().forEach(
param -> handleFulfillerStatus((TokenAndListParam) param.getParam()).ifPresent(criteria::add));
param -> handleFulfillerStatus((TokenAndListParam) param.getParam()).ifPresent(criteria::add));
break;
case FhirConstants.ENCOUNTER_REFERENCE_SEARCH_HANDLER:
entry.getValue()
Expand Down Expand Up @@ -132,7 +132,7 @@ private Optional<Criterion> handleFulfillerStatus(TokenAndListParam tokenAndList
return handleAndListParam(tokenAndListParam, token -> {
if (token.getValue() != null) {
return Optional.of(
generateFulfillerStatusRestriction(Order.FulfillerStatus.valueOf(token.getValue().toUpperCase())));
generateFulfillerStatusRestriction(Order.FulfillerStatus.valueOf(token.getValue().toUpperCase())));
}
return Optional.empty();
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,6 @@ public class FhirConditionServiceImpl extends BaseFhirService<Condition, org.ope

@Override
public IBundleProvider searchConditions(ConditionSearchParams conditionSearchParams) {
conditionSearchParams.toSearchParameterMap().addParameter(FhirConstants.DATE_RANGE_SEARCH_HANDLER, "onsetDate",
conditionSearchParams.getOnsetDate());

return searchQuery.getQueryResults(conditionSearchParams.toSearchParameterMap(), dao, translator,
searchQueryInclude);
return searchQuery.getQueryResults(conditionSearchParams.toSearchParameterMap(), dao, translator, searchQueryInclude);
}
}
Original file line number Diff line number Diff line change
@@ -1,28 +1,27 @@
/*
* This Source Code Form is subject to the terms of the Mozilla Public License,
* v. 2.0. If a copy of the MPL was not distributed with this file, You can
* obtain one at http://mozilla.org/MPL/2.0/. OpenMRS is also distributed under
* the terms of the Healthcare Disclaimer located at http://openmrs.org/license.
*
* Copyright (C) OpenMRS Inc. OpenMRS is a registered trademark and the OpenMRS
* graphic logo is a trademark of OpenMRS Inc.
*/
package org.openmrs.module.fhir2.api.impl;

import javax.annotation.Nonnull;

import ca.uhn.fhir.rest.api.server.IBundleProvider;
import org.openmrs.annotation.OpenmrsProfile;
import org.openmrs.module.fhir2.api.FhirGroupMemberService;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;

@Component
@Transactional
public class FhirGroupMemberServiceImpl implements FhirGroupMemberService {

@Override
public IBundleProvider getGroupMembers(@Nonnull String groupUuid) {
throw new UnsupportedOperationException("Not supported in this openmrs platform version");
}
}
/*
* This Source Code Form is subject to the terms of the Mozilla Public License,
* v. 2.0. If a copy of the MPL was not distributed with this file, You can
* obtain one at http://mozilla.org/MPL/2.0/. OpenMRS is also distributed under
* the terms of the Healthcare Disclaimer located at http://openmrs.org/license.
*
* Copyright (C) OpenMRS Inc. OpenMRS is a registered trademark and the OpenMRS
* graphic logo is a trademark of OpenMRS Inc.
*/
package org.openmrs.module.fhir2.api.impl;

import javax.annotation.Nonnull;

import ca.uhn.fhir.rest.api.server.IBundleProvider;
import org.openmrs.module.fhir2.api.FhirGroupMemberService;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;

@Component
@Transactional
public class FhirGroupMemberServiceImpl implements FhirGroupMemberService {

@Override
public IBundleProvider getGroupMembers(@Nonnull String groupUuid) {
throw new UnsupportedOperationException("Not supported in this openmrs platform version");
}
}
Loading

0 comments on commit 1c13866

Please sign in to comment.