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

Mob 36 #4

Open
wants to merge 13 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Revised Location and provider identification and saving approach
kwatuha committed Mar 14, 2013
commit 1f2601dabeab37014d65d6b0eff8854f974010f5
Original file line number Diff line number Diff line change
@@ -89,7 +89,7 @@ public class MobileFormEntryConstants {
/** The survey nodes prefix. */
public final static String SURVEY_PREFIX = "/form/survey";

/** The household nodes prefix. */
/** The household nodes prefix. */
public final static String HOUSEHOLD_PREFIX = "/form/household";

/** The economics nodes prefix. */
Original file line number Diff line number Diff line change
@@ -15,7 +15,7 @@ public class MobileFormEntryError extends BaseOpenmrsObject implements Auditable

private Integer mobileFormEntryErrorId;
private String providerId;
private Integer locationId;
private String locationId;
private String formName;
private String error;
private String errorDetails;
@@ -118,15 +118,15 @@ public void setProviderId(String providerId) {
/**
* @return Returns the Location Id
*/
public Integer getLocationId() {
public String getLocationId() {
return locationId;
}

/**
* @param Location Id
* The formData to set.
*/
public void setLocationId(Integer locationId) {
public void setLocationId(String locationId) {
this.locationId = locationId;
}
/**
Original file line number Diff line number Diff line change
@@ -58,7 +58,7 @@ public MobileFormHouseholdLinksProcessor() {
private void processPendingLinkForm(String filePath, MobileFormQueue queue) throws APIException {
log.debug("Linking Patient to household");
String providerId=null;
Integer locationId=0;
String locationId=null;
try {
String formData = queue.getFormData();
docBuilder = docBuilderFactory.newDocumentBuilder();
@@ -71,10 +71,14 @@ private void processPendingLinkForm(String filePath, MobileFormQueue queue) thro
String householdId = xp.evaluate(MobileFormEntryConstants.PATIENT_HOUSEHOLD_IDENTIFIER, curNode);
providerId = Integer.toString(MobileFormEntryUtil.getProviderId(xp.evaluate(MobileFormEntryConstants.ENCOUNTER_PROVIDER, curNode)));
String householdLocation = xp.evaluate(MobileFormEntryConstants.PATIENT_CATCHMENT_AREA, curNode);
locationId = locationId = Integer.parseInt(householdLocation);

//find provider Id from the document
Node surveyNode = (Node) xp.evaluate(MobileFormEntryConstants.SURVEY_PREFIX, doc, XPathConstants.NODE);
providerId = Integer.toString(MobileFormEntryUtil.getProviderId(xp.evaluate(MobileFormEntryConstants.SURVEY_PROVIDER_ID, surveyNode)));

//Clean location id by removing decimal points
locationId=MobileFormEntryUtil.cleanLocationEntry(householdLocation) ;

//String providerId=Integer.toString(intProviderId);
// First Ensure there is at least a patient identifier in the form
if (!StringUtils.hasText(MobileFormEntryUtil.getPatientIdentifier(doc))) {
// form has no patient identifier : move to error
Original file line number Diff line number Diff line change
@@ -59,7 +59,7 @@ private void processMobileForm(MobileFormQueue queue) throws APIException {
String householdGps = null;
MobileFormEntryService mfes = (MobileFormEntryService) Context.getService(MobileFormEntryService.class);
String providerId=null;
Integer locationId=0;
String locationId=null;

try {
docBuilder = docBuilderFactory.newDocumentBuilder();
@@ -70,8 +70,11 @@ private void processMobileForm(MobileFormQueue queue) throws APIException {
householdIdentifier = xp.evaluate(MobileFormEntryConstants.HOUSEHOLD_META_HOUSEHOLD_ID, curNode);
householdGps = xp.evaluate(MobileFormEntryConstants.HOUSEHOLD_META_GPS_LOCATION, curNode);
String householdLocation = xp.evaluate(MobileFormEntryConstants.PATIENT_CATCHMENT_AREA, curNode);
locationId= Integer.parseInt(householdLocation);
providerId = Integer.toString(MobileFormEntryUtil.getProviderId(xp.evaluate(MobileFormEntryConstants.ENCOUNTER_PROVIDER, curNode)));

Node surveyNode = (Node) xp.evaluate(MobileFormEntryConstants.SURVEY_PREFIX, doc, XPathConstants.NODE);
locationId=MobileFormEntryUtil.cleanLocationEntry(householdLocation) ;

providerId = Integer.toString(MobileFormEntryUtil.getProviderId(xp.evaluate(MobileFormEntryConstants.SURVEY_PROVIDER_ID, surveyNode)));
// check household identifier and gps were entered correctly
if (StringUtils.isBlank(householdIdentifier) || StringUtils.isBlank(householdGps)) {
log.debug("Null household identifier or GPS");
Original file line number Diff line number Diff line change
@@ -52,7 +52,7 @@ public MobileFormSplitProcessor(){
private boolean splitMobileForm(MobileFormQueue queue) throws APIException {
String formData = queue.getFormData();
String providerId=null;
Integer locationId=0;
String locationId=null;
try {
docBuilder = docBuilderFactory.newDocumentBuilder();
Document doc = docBuilder.parse(IOUtils.toInputStream(formData));
Original file line number Diff line number Diff line change
@@ -62,7 +62,7 @@ public MobileFormUploadProcessor() {
private void processSplitForm(String filePath, MobileFormQueue queue) throws APIException {
log.debug("Sending splitted mobile forms to the xform module");
String providerId=null;
Integer locationId =0;
String locationId =null;
try {
String formData = queue.getFormData();
docBuilder = docBuilderFactory.newDocumentBuilder();
@@ -78,11 +78,19 @@ private void processSplitForm(String filePath, MobileFormQueue queue) throws API
String givenName = xp.evaluate(MobileFormEntryConstants.PATIENT_GIVENNAME, curNode);
String middleName = xp.evaluate(MobileFormEntryConstants.PATIENT_MIDDLENAME, curNode);

curNode = (Node) xp.evaluate(MobileFormEntryConstants.ENCOUNTER_NODE, doc, XPathConstants.NODE);
/* curNode = (Node) xp.evaluate(MobileFormEntryConstants.ENCOUNTER_NODE, doc, XPathConstants.NODE);
Integer intProvider = MobileFormEntryUtil.getProviderId(xp.evaluate(MobileFormEntryConstants.ENCOUNTER_PROVIDER, curNode));
providerId=intProvider.toString();
providerId=intProvider.toString();*/
String householdLocation = xp.evaluate(MobileFormEntryConstants.PATIENT_CATCHMENT_AREA, curNode);
locationId = Integer.parseInt(householdLocation);

//Clean location id by removing decimal points
locationId=MobileFormEntryUtil.cleanLocationEntry(householdLocation) ;

//find provider Id from the document
Node surveyNode = (Node) xp.evaluate(MobileFormEntryConstants.SURVEY_PREFIX, doc, XPathConstants.NODE);
providerId = Integer.toString(MobileFormEntryUtil.getProviderId(xp.evaluate(MobileFormEntryConstants.SURVEY_PROVIDER_ID, surveyNode)));


//Ensure there is a patient identifier in the form and
// if without names just delete the form
if (MobileFormEntryUtil.getPatientIdentifier(doc) == null || MobileFormEntryUtil.getPatientIdentifier(doc).trim() == "") {
Original file line number Diff line number Diff line change
@@ -276,15 +276,30 @@ public static boolean isNewLink(Integer patientId) {
return false;
}

public static MobileFormEntryError createError(String formName, String error, String errorDetails,String providerId, Integer locationId) {
public static MobileFormEntryError createError(String formName, String error, String errorDetails,String providerId, String locationId) {
MobileFormEntryError mobileFormEntryError = new MobileFormEntryError();
mobileFormEntryError.setProviderId(providerId);
mobileFormEntryError.setFormName(formName);
mobileFormEntryError.setError(error);
mobileFormEntryError.setErrorDetails(errorDetails);
mobileFormEntryError.setProviderId(providerId);
mobileFormEntryError.setLocationId(locationId);
return mobileFormEntryError;
}

public static String cleanLocationEntry(String householdLocation) {
householdLocation=householdLocation.trim();
String locationId=null;
if(householdLocation.length()>0) {

String lastDec=householdLocation.substring(householdLocation.length()-2);
if (lastDec.equals(".0")) {
locationId=householdLocation.substring(0,householdLocation.length()-2);
} else {
locationId= householdLocation;
}
}

return locationId;
}
public static MobileFormHousehold getHousehold(MobileFormHousehold household, Document doc, XPath xp) throws XPathExpressionException {
Node householdMetaNode = (Node) xp.evaluate(MobileFormEntryConstants.HOUSEHOLD_PREFIX + MobileFormEntryConstants.HOUSEHOLD_META_PREFIX, doc, XPathConstants.NODE);
if (household == null) {