-
Notifications
You must be signed in to change notification settings - Fork 30
HAI-736: Display the patient enrollment site during the search #586
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
base: master
Are you sure you want to change the base?
Changes from all commits
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 |
|---|---|---|
| @@ -0,0 +1,100 @@ | ||
| package org.openmrs.module.pihcore.rest; | ||
|
|
||
| import org.apache.commons.lang.StringUtils; | ||
| import org.apache.commons.logging.Log; | ||
| import org.apache.commons.logging.LogFactory; | ||
| import org.openmrs.Patient; | ||
| import org.openmrs.api.PatientService; | ||
| import org.openmrs.api.context.Context; | ||
| import org.openmrs.module.webservices.rest.web.RequestContext; | ||
| import org.openmrs.module.webservices.rest.web.resource.api.PageableResult; | ||
| import org.openmrs.module.webservices.rest.web.resource.api.SearchConfig; | ||
| import org.openmrs.module.webservices.rest.web.resource.impl.EmptySearchResult; | ||
| import org.openmrs.module.webservices.rest.web.resource.impl.NeedsPaging; | ||
| import org.openmrs.module.webservices.rest.web.response.ResponseException; | ||
| import org.openmrs.module.webservices.rest.web.v1_0.search.openmrs1_8.PatientByIdentifierSearchHandler1_8; | ||
| import org.springframework.beans.factory.annotation.Autowired; | ||
| import org.springframework.stereotype.Component; | ||
| import org.openmrs.PatientProgram; | ||
| import org.openmrs.Program; | ||
| import org.openmrs.api.ProgramWorkflowService; | ||
| import org.openmrs.module.pihcore.PihEmrConfigConstants; | ||
| import org.openmrs.PatientIdentifier; | ||
|
|
||
|
|
||
| import java.util.List; | ||
|
|
||
| @Component | ||
| public class PihPatientSearchHandler extends PatientByIdentifierSearchHandler1_8 { | ||
|
|
||
| protected final Log log = LogFactory.getLog(getClass()); | ||
|
|
||
| public static final String SEARCH_ID = "pihPatientSearch"; | ||
|
|
||
| private final PatientService patientService; | ||
|
|
||
| private final ProgramWorkflowService programWorkflowService; | ||
|
|
||
| public PihPatientSearchHandler(@Autowired PatientService patientService,ProgramWorkflowService programWorkflowService) { | ||
| this.patientService = patientService; | ||
| this.programWorkflowService = programWorkflowService; | ||
| } | ||
|
|
||
| /** | ||
| * If multiple search handlers are found for a particular resource and the same supported parameters, the REST | ||
| * module will return the one whose id = "default". We configure that here to ensure this search handler is used. | ||
|
Member
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. This comment no longer appears correct, please remove / change it. |
||
| */ | ||
| @Override | ||
| public SearchConfig getSearchConfig() { | ||
| SearchConfig p = super.getSearchConfig(); | ||
| return new SearchConfig(SEARCH_ID, p.getSupportedResource(), p.getSupportedOpenmrsVersions(), p.getSearchQueries()); | ||
| } | ||
|
|
||
| /** | ||
| * This has the same logic as the superclass, with the addition of searching by insurance number and phone number | ||
| * There are 2 possible parameters that will be passed to this: | ||
| * - identifier = search with no white-space | ||
| * - q = search with white-space | ||
| * This handles both the same way currently | ||
|
Member
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. This comment is not correct for this, it was simply copied from Rwanda. Please update this to reflect the actual behavior |
||
| */ | ||
| @Override | ||
| public PageableResult search(RequestContext context) throws ResponseException { | ||
| String searchString = context.getRequest().getParameter("identifier"); | ||
| if (StringUtils.isBlank(searchString)) { | ||
| searchString = context.getRequest().getParameter("q"); | ||
| } | ||
| if (StringUtils.isNotBlank(searchString)) { | ||
| log.trace("Searching patients by: " + searchString); | ||
|
|
||
| // The core patient search matches on identifier, name, and attributes based on core configuration(s) | ||
| List<Patient> patients = patientService.getPatients(null, searchString, null, true); | ||
| log.trace("Found " + patients.size() + " patients from core patient search"); | ||
|
|
||
| // Retrieve the HIV program from the ProgramWorkflowService | ||
| Program hivProgram = programWorkflowService.getProgramByUuid(PihEmrConfigConstants.PROGRAM_HIV_UUID); | ||
| for(Patient patient : patients){ | ||
| // Ensure that the patient object is not null and the HIV program exists | ||
| if (patient !=null && hivProgram !=null) { | ||
| // Retrieve all patient programs for this patient that are linked to the HIV program | ||
| List<PatientProgram> patientPrograms = programWorkflowService.getPatientPrograms(patient, hivProgram, null, null, null, null, false); | ||
| if (patientPrograms != null) { | ||
| for (PatientProgram pp : patientPrograms) { | ||
| for (PatientIdentifier pid : patient.getIdentifiers()) { | ||
| // Set the location of the identifier to match the program enrollment's location | ||
| pid.setLocation(pp.getLocation()); | ||
|
Member
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. I am a little concerned about this approach, looking at it, for a few reasons:
Member
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. To @mseaton 's points:
I'm also concerned that we are using the Rwanda logic for patient search instead of what is provided in the core PatientByIdentifierSearchHandler1_8: https://github.com/openmrs/openmrs-module-webservices.rest/blob/master/omod-2.4/src/main/java/org/openmrs/module/webservices/rest/web/v1_0/search/openmrs1_8/PatientByIdentifierSearchHandler1_8.java#L50 This is definitely a complicated one and I've been staring at it for a while now @louidorjp , thanks for all this work and sorry this is so difficult! I wll comment more on the ticket. |
||
| } | ||
| } | ||
| } | ||
| } | ||
| } | ||
|
|
||
| if (!patients.isEmpty()) { | ||
| return new NeedsPaging<>(patients, context); | ||
| } | ||
| } | ||
|
|
||
| log.trace("No patients found that match the search criteria"); | ||
| return new EmptySearchResult(); | ||
| } | ||
|
|
||
| } | ||
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.
Both arguments need to be autowired