Skip to content
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

PDMO-65: fix bug to enable retrieving soft deleted observations. #310

Merged
merged 1 commit into from
Oct 24, 2017

Conversation

Ewanjiru
Copy link
Contributor

@Ewanjiru Ewanjiru commented Oct 23, 2017

JIRA TICKET NAME:

RESTWS-683: [Enable retrieving soft deleted observations](https://issues.openmrs.org/browse/RESTWS-683

SUMMARY:

Fix bug in the webservice to enable retrieving soft deleted observations.

@@ -479,13 +481,19 @@ protected PageableResult doSearch(RequestContext context) {
}

String encounterUuid = context.getRequest().getParameter("encounter");
boolean includeVoided = Boolean.parseBoolean(context.getRequest().getParameter("includeAll"));
Copy link
Contributor

Choose a reason for hiding this comment

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

can you try context.getIncludeAll()

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This has been corrected

if (encounterUuid != null) {
Encounter enc = ((EncounterResource1_8) Context.getService(RestService.class).getResourceBySupportedClass(
Encounter.class)).getByUniqueId(encounterUuid);
if (enc == null)
return new EmptySearchResult();
List<Obs> obs = new ArrayList<Obs>(enc.getAllObs());
return new NeedsPaging<Obs>(obs, context);
if (includeVoided) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you refactor this, in way you may not need to use the if since you have already acquired the value of includeVoided

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This has been corrected

@coveralls
Copy link

Coverage Status

Coverage decreased (-0.01%) to 40.322% when pulling 4b8d86e on Ewanjiru:PDMO-65 into 191e0b6 on openmrs:master.

@@ -48,6 +48,8 @@
import org.openmrs.module.webservices.rest.web.response.IllegalRequestException;
import org.openmrs.module.webservices.rest.web.response.ObjectNotFoundException;
import org.openmrs.module.webservices.rest.web.response.ResponseException;
import org.openmrs.module.webservices.rest.web.v1_0.resource.openmrs1_8.EncounterResource1_8;
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we really need this?

@@ -48,6 +48,8 @@
import org.openmrs.module.webservices.rest.web.response.IllegalRequestException;
import org.openmrs.module.webservices.rest.web.response.ObjectNotFoundException;
import org.openmrs.module.webservices.rest.web.response.ResponseException;
import org.openmrs.module.webservices.rest.web.v1_0.resource.openmrs1_8.EncounterResource1_8;
import org.openmrs.module.webservices.rest.web.v1_0.resource.openmrs1_8.PatientResource1_8;
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we need this?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

These were mistakenly imported and have been removed.

@Ewanjiru Ewanjiru force-pushed the PDMO-65 branch 2 times, most recently from 43b945b to d9c493f Compare October 23, 2017 14:32
@adamsdenniskariuki
Copy link

Good work @Ewanjiru

MockHttpServletResponse allObsIncludingVoidedResponse = handle(getAllObsIncludingVoidedRequest);
List<Object> allObsIncludingVoidedList = deserialize(allObsIncludingVoidedResponse).get("results");

assertEquals(allObsIncludingVoidedList.size(), 6);
Copy link
Contributor

Choose a reason for hiding this comment

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

The test does not assert that voided obs were retrieved, because AllNonVoidedObsList has the same size with allObsIncludingVoidedList. Can you fix that?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

By this I was confirming that the length is the same since before the fix it would only retrieve the non-voided observations hence length would be less but with above test it confirms that even after the delete request the length is still the same.

Copy link
Contributor

Choose a reason for hiding this comment

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

Ok, just assert that AllNonVoidedObsList is now 5.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oh, well noted

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@adamsdenniskariuki , @andela-cuchendu I have added the assert.
Thanks for the review.

@coveralls
Copy link

Coverage Status

Coverage decreased (-0.003%) to 40.333% when pulling d9c493f on Ewanjiru:PDMO-65 into 191e0b6 on openmrs:master.

@coveralls
Copy link

Coverage Status

Coverage decreased (-0.003%) to 40.333% when pulling acebb94 on Ewanjiru:PDMO-65 into 191e0b6 on openmrs:master.

@@ -479,12 +479,14 @@ protected PageableResult doSearch(RequestContext context) {
}

String encounterUuid = context.getRequest().getParameter("encounter");
boolean includeVoided = context.getIncludeAll();
Copy link
Member

Choose a reason for hiding this comment

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

Do you really need the above local variable?


MockHttpServletRequest getAllNonVoidedObsRequest2 = newGetRequest(getURI());
getAllNonVoidedObsRequest2.addParameter("encounter", "62967e68-96bb-11e0-8d6b-9b9415a91465");
MockHttpServletResponse AllNonVoidedObsResponse2 = handle(getAllNonVoidedObsRequest2);
Copy link
Member

@dkayiwa dkayiwa Oct 23, 2017

Choose a reason for hiding this comment

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

Did you look at our conventions for variable names? https://wiki.openmrs.org/display/docs/Java+Conventions#JavaConventions-NamingConventions
The same applies to the above.


assertEquals(allObsIncludingVoidedList.size(), 6);

MockHttpServletRequest getAllNonVoidedObsRequest2 = newGetRequest(getURI());
Copy link
Member

@dkayiwa dkayiwa Oct 23, 2017

Choose a reason for hiding this comment

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

Is getAllNonVoidedObsRequest2 a function or variable?


executeDataSet("encounterWithObsGroup1_9.xml");

MockHttpServletRequest getAllNonVoidedObsRequest = newGetRequest(getURI());
Copy link
Member

Choose a reason for hiding this comment

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

Is getAllNonVoidedObsRequest a function or variable?
The same applies to the others.

@Ewanjiru Ewanjiru force-pushed the PDMO-65 branch 2 times, most recently from d882b3a to bb5b947 Compare October 24, 2017 06:00
@Ewanjiru
Copy link
Contributor Author

@dkayiwa
Feedback has been implemented. Thanks.

@coveralls
Copy link

Coverage Status

Coverage decreased (-0.003%) to 40.333% when pulling bb5b947 on Ewanjiru:PDMO-65 into 191e0b6 on openmrs:master.

@coveralls
Copy link

Coverage Status

Coverage remained the same at 40.336% when pulling bb5b947 on Ewanjiru:PDMO-65 into 191e0b6 on openmrs:master.

@@ -84,6 +87,38 @@ public void shouldGetAll() throws Exception {
}

@Test
public void shouldGetallIncludingVoidedObs() 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.

The test method name does not clearly state what you are testing. Can you look at this for an example? 191e0b6

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@dkayiwa
Working on it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This has been corrected.

handle(deleteRequest);

MockHttpServletRequest allObsIncludingVoidedRequest = newGetRequest(getURI());
allObsIncludingVoidedRequest.addParameter("encounter", "62967e68-96bb-11e0-8d6b-9b9415a91465");
Copy link
Member

Choose a reason for hiding this comment

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

Can you avoid using this uuid from more than one place 62967e68-96bb-11e0-8d6b-9b9415a91465?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@dkayiwa
I am not sure I follow what you mean since the uuids above are different;
62967e68-96bb-11e0-8d6b-9b9415a91465 is the encounter uuid
11de743c-96cd-11e0-8d6b-9b9415a91465 is the observation uuid

Copy link
Member

Choose a reason for hiding this comment

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

Let me put it this way, are you aware of the fact that you are using 62967e68-96bb-11e0-8d6b-9b9415a91465 in more than one place?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This has been corrected by assigning the uuid to a variable.

@coveralls
Copy link

Coverage Status

Coverage remained the same at 40.336% when pulling 00bd3b1 on Ewanjiru:PDMO-65 into 191e0b6 on openmrs:master.


executeDataSet("encounterWithObsGroup1_9.xml");

String encounterUuid = "62967e68-96bb-11e0-8d6b-9b9415a91465";
Copy link
Member

Choose a reason for hiding this comment

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

Have you looked at our naming conventions in regards to the above line? https://wiki.openmrs.org/display/docs/Java+Conventions#JavaConventions-NamingConventions

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@dkayiwa
This has been fixed.

Copy link
Member

Choose a reason for hiding this comment

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

How have you fixed it?

@Ewanjiru Ewanjiru force-pushed the PDMO-65 branch 2 times, most recently from 16a798b to c978e25 Compare October 24, 2017 11:03
@coveralls
Copy link

Coverage Status

Coverage remained the same at 40.336% when pulling c978e25 on Ewanjiru:PDMO-65 into 191e0b6 on openmrs:master.

@coveralls
Copy link

Coverage Status

Coverage remained the same at 40.336% when pulling c978e25 on Ewanjiru:PDMO-65 into 191e0b6 on openmrs:master.

@Ewanjiru
Copy link
Contributor Author

@dkayiwa
I made some commit mishaps.
I have fixed by having the string as a constant.

@coveralls
Copy link

Coverage Status

Coverage remained the same at 40.336% when pulling 9ff22e7 on Ewanjiru:PDMO-65 into 191e0b6 on openmrs:master.

@dkayiwa dkayiwa merged commit cf06f31 into openmrs:master Oct 24, 2017
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.

5 participants