RestWS-950-Encounter Search Handler should support a visits parameter#616
RestWS-950-Encounter Search Handler should support a visits parameter#616mogoodrich merged 1 commit intoopenmrs:masterfrom
Conversation
mogoodrich
left a comment
There was a problem hiding this comment.
Thanks @sadamhussain-m , generally looks good, but see my comments... there seem to be changes from other recent commits in your PR, and there is one place where I believe we need a null chek.
| delegate.getPatient().addIdentifier(delegate); | ||
| } | ||
|
|
||
| service().savePatientIdentifier(delegate); |
There was a problem hiding this comment.
This looks unrelated, I think you are modifying another recent commit unintentionally?
There was a problem hiding this comment.
I don't know how other commits are tagged up on this issue branch.Before I'm raising the PR,I tried to skip the other unrelated commits.But I can't find a way for it.Could you help me on this?.
| private List<CustomDatatypeRepresentation> getAllCustomDatatypes() { | ||
| if(!Context.isAuthenticated()) { | ||
| throw new APIAuthenticationException("User must be authenticated!"); | ||
| } |
There was a problem hiding this comment.
Same here, this looks unrelated, I think you are modifying another recent commit unintentionally?
| } | ||
|
|
||
| @Test | ||
| public void shouldNotAddIdentifierInUseByAnotherPatient() throws Exception { |
There was a problem hiding this comment.
Same here as well, this looks unrelated, I think you are modifying another recent commit unintentionally?
| import java.util.Collections; | ||
| import java.util.Date; | ||
| import java.util.List; | ||
| import java.util.*; |
There was a problem hiding this comment.
As a convention, we don't use wildcard imports. You made need to configure your IDE not to automatically substitute with wildcard imports?
There was a problem hiding this comment.
I'll rectify this.
| String patientUuid = context.getRequest().getParameter("patient"); | ||
| String encounterTypeUuid = context.getRequest().getParameter("encounterType"); | ||
|
|
||
| String[] visitsUuid=context.getRequest().getParameter("visits").split(","); |
There was a problem hiding this comment.
We will need to do a null check here, as visits is not a required parameter.
There was a problem hiding this comment.
sure,I'll add it up.
| } | ||
|
|
||
| service().savePatientIdentifier(delegate); | ||
|
|
There was a problem hiding this comment.
This seems unrelated to this ticket, was this done to support a different issue?
There was a problem hiding this comment.
I don't know how the unrelated commits are tagged up on this issue branch.
| private List<CustomDatatypeRepresentation> getAllCustomDatatypes() { | ||
| if(!Context.isAuthenticated()) { | ||
| throw new APIAuthenticationException("User must be authenticated!"); | ||
| } |
There was a problem hiding this comment.
This seems unrelated to this ticket, was this done to support a different issue?
|
|
||
| assertNotNull(PropertyUtils.getProperty(result, "auditInfo")); | ||
| } | ||
|
|
There was a problem hiding this comment.
This seems unrelated to this ticket, was this done to support a different issue?
| String patientUuid = context.getRequest().getParameter("patient"); | ||
| String encounterTypeUuid = context.getRequest().getParameter("encounterType"); | ||
|
|
||
| String[] visitsUuid=context.getRequest().getParameter("visits").split(","); |
There was a problem hiding this comment.
The name of this parameter should be singular visit, not plural visits.
There was a problem hiding this comment.
Sorry, @sadamhussain-m my bad, I think I said to use "visits", but let's go with "visit"
There was a problem hiding this comment.
okay fine,I'll modify it.
| String patientUuid = context.getRequest().getParameter("patient"); | ||
| String encounterTypeUuid = context.getRequest().getParameter("encounterType"); | ||
|
|
||
| String[] visitsUuid=context.getRequest().getParameter("visits").split(","); |
There was a problem hiding this comment.
Better to use existing method: String[] visitUuids = context.getRequest().getParameterValues("visit");
There was a problem hiding this comment.
okay,I'll use this.
|
|
||
| if (!visits.isEmpty()){ | ||
| encounterSearchCriteriaBuilder.setVisits(visits); | ||
| } |
There was a problem hiding this comment.
if (visitUuids != null && visitUuids.length > 0) {
List<Visit> visits = new ArrayList<>();
for (String visitUuid : visitUuids) {
visits.add(Context.getVisitService().getVisitByUuid(visitUuid));
}
encounterSearchCriteriaBuilder.setVisits(visits);
}
| Visit visit = ((VisitResource1_9) Context.getService(RestService.class).getResourceBySupportedClass(Visit.class)).getByUniqueId(uuid); | ||
| visits.add(visit); | ||
| } | ||
| } |
There was a problem hiding this comment.
Might as well wait to do all this once you are actually doing the query below, rather than pre-emptively, since patient is current required. If we want to make patient no longer required, and query on visit only, then we need to make sure the patient null check does not wrap everything. See suggested code below.
There was a problem hiding this comment.
Okay.I'll add up those validations for visits before the query itself.
| assertEquals(patientIdentifierUuidThatShouldNotChange, uuid); | ||
| assertEquals(patientIdentifierNewValue, identifierValue); | ||
| assertEquals(patientIdentifierNewValue, patientIdentifier.getIdentifier()); | ||
| } |
There was a problem hiding this comment.
We do need to add a unit test for this feature, which should be placed in the `EncounterController2_0Test.java" class, which is where the existing tests of the Encounter 2.0 search functionality live.
There was a problem hiding this comment.
can you give me a test data for the visits as input and the expected output for the encounters for a patient to check for it?
| String patientUuid = context.getRequest().getParameter("patient"); | ||
| String encounterTypeUuid = context.getRequest().getParameter("encounterType"); | ||
|
|
||
| String[] visitsUuid=context.getRequest().getParameter("visits").split(","); |
There was a problem hiding this comment.
Sorry, @sadamhussain-m my bad, I think I said to use "visits", but let's go with "visit"
|
@sadamhussain-m thanks so much for working on this! I'm actually going to go ahead and merge this in, as we have need for it right now for a feature we are building. I will handle the changes @mseaton and I suggested and tag you on them, thanks! |
Description of what I changed
Issue I worked on
see https://issues.openmrs.org/browse/RESTWS-
Checklist: I completed these to help reviewers :)
My IDE is configured to follow the code style of this project.
No? Unsure? -> configure your IDE, format the code and add the changes with
git add . && git commit --amendI have added tests to cover my changes. (If you refactored
existing code that was well tested you do not have to add tests)
No? -> write tests and add them to this commit
git add . && git commit --amendI ran
mvn clean packageright before creating this pull request andadded all formatting changes to my commit.
No? -> execute above command
All new and existing tests passed.
No? -> figure out why and add the fix to your commit. It is your responsibility to make sure your code works.
My pull request is based on the latest changes of the master branch.
No? Unsure? -> execute command
git pull --rebase upstream master