Skip to content

Commit

Permalink
Revert "FM2-646: Practitioner: support limiting search to users or pr…
Browse files Browse the repository at this point in the history
…oviders"

This reverts commit a304967.
  • Loading branch information
mogoodrich committed Sep 26, 2024
1 parent a304967 commit 1bad7e3
Show file tree
Hide file tree
Showing 9 changed files with 139 additions and 246 deletions.
2 changes: 0 additions & 2 deletions api/src/main/java/org/openmrs/module/fhir2/FhirConstants.java
Original file line number Diff line number Diff line change
Expand Up @@ -109,8 +109,6 @@ private FhirConstants() {

public static final String OPENMRS_FHIR_EXT_ENCOUNTER_TAG = OPENMRS_FHIR_EXT_PREFIX + "/encounter-tag";

public static final String OPENMRS_FHIR_EXT_PRACTITIONER_TAG = OPENMRS_FHIR_EXT_PREFIX + "/practitioner-tag";

public static final String OPENMRS_FHIR_EXT_OBSERVATION_REFERENCE_RANGE = OPENMRS_FHIR_EXT_PREFIX
+ "/obs/reference-range";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,7 @@

import javax.annotation.Nonnull;

import java.util.Collections;

import ca.uhn.fhir.rest.api.server.IBundleProvider;
import ca.uhn.fhir.rest.param.InternalCodingDt;
import ca.uhn.fhir.rest.param.TokenAndListParam;
import ca.uhn.fhir.rest.server.exceptions.InvalidRequestException;
import ca.uhn.fhir.rest.server.exceptions.ResourceNotFoundException;
import ca.uhn.fhir.rest.server.exceptions.UnprocessableEntityException;
Expand All @@ -25,7 +21,6 @@
import org.hl7.fhir.r4.model.Practitioner;
import org.openmrs.Provider;
import org.openmrs.User;
import org.openmrs.module.fhir2.FhirConstants;
import org.openmrs.module.fhir2.api.FhirGlobalPropertyService;
import org.openmrs.module.fhir2.api.FhirPractitionerService;
import org.openmrs.module.fhir2.api.FhirUserService;
Expand Down Expand Up @@ -97,36 +92,17 @@ public Practitioner create(@Nonnull Practitioner newResource) {
@Override
@Transactional(readOnly = true)
public IBundleProvider searchForPractitioners(PractitionerSearchParams practitionerSearchParams) {
IBundleProvider providerBundle = searchQuery.getQueryResults(practitionerSearchParams.toSearchParameterMap(), dao,
translator, searchQueryInclude);
SearchParameterMap theParams = new SearchParameterMap();
IBundleProvider userBundle = userService.searchForUsers(theParams);

IBundleProvider providerBundle = null;
IBundleProvider userBundle = null;

if (shouldSearchExplicitlyFor(practitionerSearchParams.getTag(), "provider")) {
providerBundle = searchQuery.getQueryResults(practitionerSearchParams.toSearchParameterMap(), dao, translator,
searchQueryInclude);
}

if (shouldSearchExplicitlyFor(practitionerSearchParams.getTag(), "user")) {
SearchParameterMap theParams = new SearchParameterMap();
userBundle = userService.searchForUsers(theParams);
}

if (providerBundle != null && userBundle != null) {
if (!providerBundle.isEmpty() && !userBundle.isEmpty()) {
return new TwoSearchQueryBundleProvider(providerBundle, userBundle, globalPropertyService);
} else if (providerBundle == null && userBundle != null) {
} else if (providerBundle.isEmpty() && !userBundle.isEmpty()) {
return userBundle;
}

return providerBundle;
}

protected boolean shouldSearchExplicitlyFor(TokenAndListParam tokenAndListParam, @Nonnull String valueToCheck) {
if (tokenAndListParam == null || tokenAndListParam.size() == 0 || valueToCheck.isEmpty()) {
return true;
}

return tokenAndListParam.getValuesAsQueryTokens().stream().anyMatch(
tokenOrListParam -> tokenOrListParam.doesCodingListMatch(Collections
.singletonList(new InternalCodingDt(FhirConstants.OPENMRS_FHIR_EXT_PRACTITIONER_TAG, valueToCheck))));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,10 @@ public class PractitionerSearchParams extends BaseResourceSearchParams {

private StringAndListParam country;

private TokenAndListParam tag;

@Builder
public PractitionerSearchParams(TokenAndListParam identifier, StringAndListParam name, StringAndListParam given,
StringAndListParam family, StringAndListParam city, StringAndListParam state, StringAndListParam postalCode,
StringAndListParam country, TokenAndListParam id, TokenAndListParam tag, DateRangeParam lastUpdated,
HashSet<Include> revIncludes) {
StringAndListParam country, TokenAndListParam id, DateRangeParam lastUpdated, HashSet<Include> revIncludes) {

super(id, lastUpdated, null, null, revIncludes);

Expand All @@ -60,7 +57,6 @@ public PractitionerSearchParams(TokenAndListParam identifier, StringAndListParam
this.state = state;
this.postalCode = postalCode;
this.country = country;
this.tag = tag;
}

@Override
Expand All @@ -72,7 +68,6 @@ public SearchParameterMap toSearchParameterMap() {
.addParameter(FhirConstants.CITY_SEARCH_HANDLER, getCity())
.addParameter(FhirConstants.STATE_SEARCH_HANDLER, getState())
.addParameter(FhirConstants.POSTALCODE_SEARCH_HANDLER, getPostalCode())
.addParameter(FhirConstants.COUNTRY_SEARCH_HANDLER, getCountry())
.addParameter(FhirConstants.TAG_SEARCH_HANDLER, getTag());
.addParameter(FhirConstants.COUNTRY_SEARCH_HANDLER, getCountry());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,6 @@ public IBundleProvider searchForPractitioners(@OptionalParam(name = Practitioner
@OptionalParam(name = Practitioner.SP_ADDRESS_POSTALCODE) StringAndListParam postalCode,
@OptionalParam(name = Practitioner.SP_ADDRESS_COUNTRY) StringAndListParam country,
@OptionalParam(name = Practitioner.SP_RES_ID) TokenAndListParam id,
@OptionalParam(name = "_tag") TokenAndListParam tag,
@OptionalParam(name = "_lastUpdated") DateRangeParam lastUpdated,
@IncludeParam(reverse = true, allow = { "Encounter:" + Encounter.SP_PARTICIPANT,
"MedicationRequest:" + MedicationRequest.SP_REQUESTER,
Expand All @@ -125,7 +124,7 @@ public IBundleProvider searchForPractitioners(@OptionalParam(name = Practitioner

return new SearchQueryBundleProviderR3Wrapper(
practitionerService.searchForPractitioners(new PractitionerSearchParams(identifier, name, given, family,
city, state, postalCode, country, id, tag, lastUpdated, revIncludes)));
city, state, postalCode, country, id, lastUpdated, revIncludes)));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,6 @@ public IBundleProvider searchForPractitioners(@OptionalParam(name = Practitioner
@OptionalParam(name = Practitioner.SP_ADDRESS_POSTALCODE) StringAndListParam postalCode,
@OptionalParam(name = Practitioner.SP_ADDRESS_COUNTRY) StringAndListParam country,
@OptionalParam(name = Practitioner.SP_RES_ID) TokenAndListParam id,
@OptionalParam(name = "_tag") TokenAndListParam tag,
@OptionalParam(name = "_lastUpdated") DateRangeParam lastUpdated,
@IncludeParam(reverse = true, allow = { "Encounter:" + Encounter.SP_PARTICIPANT,
"MedicationRequest:" + MedicationRequest.SP_REQUESTER, "ServiceRequest:" + ServiceRequest.SP_REQUESTER,
Expand All @@ -132,6 +131,6 @@ public IBundleProvider searchForPractitioners(@OptionalParam(name = Practitioner
}

return practitionerService.searchForPractitioners(new PractitionerSearchParams(identifier, name, given, family, city,
state, postalCode, country, id, tag, lastUpdated, revIncludes));
state, postalCode, country, id, lastUpdated, revIncludes));
}
}
Loading

0 comments on commit 1bad7e3

Please sign in to comment.