-
Notifications
You must be signed in to change notification settings - Fork 112
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Reapply "FM2-646: Practitioner: support limiting search to users or p… #551
Changes from all commits
f85e457
6eaa03a
d43f85a
59ca983
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,7 +11,11 @@ | |
|
||
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; | ||
|
@@ -21,6 +25,7 @@ | |
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; | ||
|
@@ -30,7 +35,6 @@ | |
import org.openmrs.module.fhir2.api.search.SearchQueryInclude; | ||
import org.openmrs.module.fhir2.api.search.TwoSearchQueryBundleProvider; | ||
import org.openmrs.module.fhir2.api.search.param.PractitionerSearchParams; | ||
import org.openmrs.module.fhir2.api.search.param.SearchParameterMap; | ||
import org.openmrs.module.fhir2.api.translators.PractitionerTranslator; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.stereotype.Component; | ||
|
@@ -92,17 +96,35 @@ 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); | ||
|
||
if (!providerBundle.isEmpty() && !userBundle.isEmpty()) { | ||
IBundleProvider providerBundle = null; | ||
IBundleProvider userBundle = null; | ||
|
||
if (shouldSearchExplicitlyFor(practitionerSearchParams.getTag(), "provider")) { | ||
providerBundle = searchQuery.getQueryResults(practitionerSearchParams.toSearchParameterMap(), dao, translator, | ||
searchQueryInclude); | ||
} | ||
|
||
if (shouldSearchExplicitlyFor(practitionerSearchParams.getTag(), "user")) { | ||
userBundle = userService.searchForUsers(practitionerSearchParams.toSearchParameterMap()); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Note that formerly the search parameters were not passed into the search for users method, which seemed incorrect, but these parameters may not currently be used in a user context? |
||
} | ||
|
||
if (providerBundle != null && userBundle != null) { | ||
return new TwoSearchQueryBundleProvider(providerBundle, userBundle, globalPropertyService); | ||
} else if (providerBundle.isEmpty() && !userBundle.isEmpty()) { | ||
} else if (providerBundle == null && userBundle != null) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not sure if I should still test for "isEmpty()" here, but the Encounter search example I am following didn't. |
||
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)))); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. So I copied this method bring much verbatim from a similar method in the encounter service, but, honestly, I don't exactly understand what the this internal coding and this new constant I defined does... we don't include this coding in our actual request, but it still seems to match like it should. @ibacher ? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The thing you copied and pasted from was intended to support this:
So, in this case:
If this works, it's kind of by mistake or at least for reasons I don't fully understand... (FHIR Tags are coded elements so ideally they'd have both a system and a code). |
||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -42,10 +42,13 @@ 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, DateRangeParam lastUpdated, HashSet<Include> revIncludes) { | ||
StringAndListParam country, TokenAndListParam id, TokenAndListParam tag, DateRangeParam lastUpdated, | ||
HashSet<Include> revIncludes) { | ||
|
||
super(id, lastUpdated, null, null, revIncludes); | ||
|
||
|
@@ -57,6 +60,7 @@ public PractitionerSearchParams(TokenAndListParam identifier, StringAndListParam | |
this.state = state; | ||
this.postalCode = postalCode; | ||
this.country = country; | ||
this.tag = tag; | ||
} | ||
|
||
@Override | ||
|
@@ -68,6 +72,7 @@ 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.COUNTRY_SEARCH_HANDLER, getCountry()) | ||
.addParameter(FhirConstants.TAG_SEARCH_HANDLER, getTag()); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Another "I'm not quite sure what this does" addition here that it would be good to add clarification on. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. By itself, I think this is meaningless or maybe a vestige of a previous version that passed the tag down the the DAO layer? In any case, it's harmless because there's nothing in the DAO layer that does anything with this. |
||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm opening to discussion about this, as I don't really understand what this does (see below)