-
Notifications
You must be signed in to change notification settings - Fork 143
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
EA-198: Add support for configuring (and fetching) Mother Child relat… #239
Changes from 1 commit
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 |
---|---|---|
|
@@ -47,7 +47,9 @@ public List<MotherAndChild> getMothersAndChildren(MothersAndChildrenSearchCriter | |
|
||
Map<String, Object> parameters = new HashMap<>(); | ||
parameters.put("motherUuids", criteria.getMotherUuids()); | ||
parameters.put("restrictByMothers", criteria.getMotherUuids() != 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. see below |
||
parameters.put("childUuids", criteria.getChildUuids()); | ||
parameters.put("restrictByChildren", criteria.getChildUuids() != null); | ||
parameters.put("motherChildRelationshipType", motherChildRelationshipType); | ||
parameters.put("motherRequiredToHaveActiveVisit", criteria.isMotherRequiredToHaveActiveVisit()); | ||
parameters.put("childRequiredToHaveActiveVisit", criteria.isChildRequiredToHaveActiveVisit()); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,8 +6,8 @@ from | |
inner join motherChildRelationship.personA as mother | ||
inner join motherChildRelationship.personB as child | ||
where | ||
((:motherUuids) is null or mother.uuid in (:motherUuids)) | ||
and ((:childUuids) is null or child.uuid in (:childUuids)) | ||
(:restrictByMothers = false or mother.uuid in (:motherUuids)) | ||
and (:restrictByChildren = false or child.uuid in (:childUuids)) | ||
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. Was stumped by this for a while... the "(:motherUuids) is null" was throwing an error when motherUuids was an array, which in-and-of-itself isn't necessarily surprising, but it was working in the tests, it was only failing when trying to use it for "real". No idea what the difference was. I figured I was inadvertently passing in a slightly different datatype, but debugging they looked the same. 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. Yeah, I ran into the same thing. I assume you saw how I ended up handling this in the other hql queries, but if not we arrived at the same solution :) 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. Oops, I guess I missed that |
||
and motherChildRelationship.relationshipType = :motherChildRelationshipType | ||
and (:motherRequiredToHaveActiveVisit = false or (select count(motherVisit) from Visit as motherVisit where motherVisit.patient = mother and motherVisit.stopDatetime is null and motherVisit.voided = false) > 0) | ||
and (:childRequiredToHaveActiveVisit = false or (select count(childVisit) from Visit as childVisit where childVisit.patient = child and childVisit.stopDatetime is null and childVisit.voided = false) > 0) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
package org.openmrs.module.emrapi.web.controller; | ||
|
||
import javax.servlet.http.HttpServletRequest; | ||
import javax.servlet.http.HttpServletResponse; | ||
|
||
import java.util.Arrays; | ||
import java.util.List; | ||
|
||
import org.apache.commons.lang.StringUtils; | ||
import org.openmrs.module.emrapi.maternal.MaternalService; | ||
import org.openmrs.module.emrapi.maternal.MotherAndChild; | ||
import org.openmrs.module.emrapi.maternal.MothersAndChildrenSearchCriteria; | ||
import org.openmrs.module.emrapi.rest.converter.SimpleBeanConverter; | ||
import org.openmrs.module.webservices.rest.SimpleObject; | ||
import org.openmrs.module.webservices.rest.web.RequestContext; | ||
import org.openmrs.module.webservices.rest.web.RestUtil; | ||
import org.openmrs.module.webservices.rest.web.representation.Representation; | ||
import org.openmrs.module.webservices.rest.web.resource.impl.NeedsPaging; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.stereotype.Controller; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.RequestMethod; | ||
import org.springframework.web.bind.annotation.RequestParam; | ||
import org.springframework.web.bind.annotation.ResponseBody; | ||
|
||
@Controller | ||
public class MothersAndChildrenController { | ||
|
||
@Autowired | ||
private MaternalService maternalService; | ||
|
||
@RequestMapping(method = RequestMethod.GET, value = "/rest/**/emrapi/maternal/mothersAndChildren") | ||
@ResponseBody | ||
public SimpleObject getMothersAndChildren( | ||
HttpServletRequest request, | ||
HttpServletResponse response, | ||
@RequestParam(required = false, value = "motherUuids") String motherUuids, | ||
@RequestParam(required = false, value = "childUuids") String childUuids, | ||
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. Maybe call these properties 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. If best practice is not to use the comments, I would change this probably to "mother" and "child" like to specified below, let me fiddle around with this. |
||
@RequestParam(required = false, value = "requireMotherHasActiveVisit") boolean requireMotherHasActiveVisit, | ||
@RequestParam(required = false, value = "requireChildHasActiveVisit") boolean requireChildHasActiveVisit, | ||
@RequestParam(required = false, value = "requireChildBornDuringMothersActiveVisit") boolean requireChildBornDuringMothersActiveVisit | ||
) { | ||
RequestContext context = RestUtil.getRequestContext(request, response, Representation.DEFAULT); | ||
MothersAndChildrenSearchCriteria criteria = new MothersAndChildrenSearchCriteria(); | ||
criteria.setMotherUuids(StringUtils.isNotBlank(motherUuids) ? Arrays.asList(motherUuids.split(",")) : null); | ||
criteria.setChildUuids(StringUtils.isNotBlank(childUuids) ? Arrays.asList(childUuids.split(",")) : 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 there is a built-in way to map a parameter to an array, but the few ways I tried didn't seem to work. 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. If it isn't supported out of the box, I'd assume it isn't considered best practice. The way to accomplish this is typically to just pass in the request parameter multiple times. This is one of the reasons I was thinking the singular tense maybe: 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. Ah right, makes sense 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. Updated to use:
|
||
criteria.setMotherRequiredToHaveActiveVisit(requireMotherHasActiveVisit); | ||
criteria.setChildRequiredToHaveActiveVisit(requireChildHasActiveVisit); | ||
criteria.setChildRequiredToBeBornDuringMothersActiveVisit(requireChildBornDuringMothersActiveVisit); | ||
List<MotherAndChild> motherAndChildList = maternalService.getMothersAndChildren(criteria); | ||
return new NeedsPaging<>(motherAndChildList, context).toSimpleObject(new SimpleBeanConverter<MotherAndChild>()); | ||
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 started to create a custom converter, but at the end-of-the-day the buildt in converter seemed to give reps with reasonable defaults. I tested full, default, rep, and a custom rep. |
||
} | ||
|
||
} |
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.
All the other EMR API properties started with "emr", so I renamed this for consistency.