Skip to content

RestWS-950-Encounter Search Handler should support a visits parameter#616

Merged
mogoodrich merged 1 commit intoopenmrs:masterfrom
sadamhussain-m:master
Aug 8, 2024
Merged

RestWS-950-Encounter Search Handler should support a visits parameter#616
mogoodrich merged 1 commit intoopenmrs:masterfrom
sadamhussain-m:master

Conversation

@sadamhussain-m
Copy link
Contributor

@sadamhussain-m sadamhussain-m commented Aug 2, 2024

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 --amend

  • I 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 --amend

  • I ran mvn clean package right before creating this pull request and
    added 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

Copy link
Member

@mogoodrich mogoodrich left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks unrelated, I think you are modifying another recent commit unintentionally?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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!");
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here, this looks unrelated, I think you are modifying another recent commit unintentionally?

}

@Test
public void shouldNotAddIdentifierInUseByAnotherPatient() throws Exception {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.*;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As a convention, we don't use wildcard imports. You made need to configure your IDE not to automatically substitute with wildcard imports?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll rectify this.

String patientUuid = context.getRequest().getParameter("patient");
String encounterTypeUuid = context.getRequest().getParameter("encounterType");

String[] visitsUuid=context.getRequest().getParameter("visits").split(",");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We will need to do a null check here, as visits is not a required parameter.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sure,I'll add it up.

}

service().savePatientIdentifier(delegate);

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems unrelated to this ticket, was this done to support a different issue?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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!");
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems unrelated to this ticket, was this done to support a different issue?


assertNotNull(PropertyUtils.getProperty(result, "auditInfo"));
}

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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(",");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The name of this parameter should be singular visit, not plural visits.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, @sadamhussain-m my bad, I think I said to use "visits", but let's go with "visit"

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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(",");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Better to use existing method: String[] visitUuids = context.getRequest().getParameterValues("visit");

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

okay,I'll use this.


if (!visits.isEmpty()){
encounterSearchCriteriaBuilder.setVisits(visits);
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

			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);
}
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay.I'll add up those validations for visits before the query itself.

assertEquals(patientIdentifierUuidThatShouldNotChange, uuid);
assertEquals(patientIdentifierNewValue, identifierValue);
assertEquals(patientIdentifierNewValue, patientIdentifier.getIdentifier());
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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?

@ibacher ibacher changed the base branch from RESTWS-950-Encounter-Search-Handler-should-support-a-visits-parameter to master August 5, 2024 17:54
Copy link
Member

@mogoodrich mogoodrich left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like you were merging against the wrong branch, Sadam, but @ibacher was able fix it, thanks @ibacher ... I am no longer seeing the changes to the other files. If you can address the comments @mseaton and I made we should be good to merge, thanks!

String patientUuid = context.getRequest().getParameter("patient");
String encounterTypeUuid = context.getRequest().getParameter("encounterType");

String[] visitsUuid=context.getRequest().getParameter("visits").split(",");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, @sadamhussain-m my bad, I think I said to use "visits", but let's go with "visit"

@mogoodrich
Copy link
Member

@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!

@mogoodrich mogoodrich merged commit a0c09b2 into openmrs:master Aug 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants