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
MOB-29 - cleaning up code, integrating with other branches
jlkeiper committed May 14, 2013
commit 03f55a810de2206a078d84df1ace3316688c5838
Original file line number Diff line number Diff line change
@@ -25,6 +25,10 @@ public class MobileFormEntryErrorModel extends MobileFormEntryError {
private String birthdate = "";
private String gender = "";
private String identifier = "";

//data from household meta-data section
private String totalHousehold = "";
private String totalEligible = "";

// data from the formData encounter section
private String location = "";
@@ -50,6 +54,8 @@ public MobileFormEntryErrorModel(MobileFormEntryError error, String errorType) {
setError(error.getError());
setErrorDetails(error.getErrorDetails());
setDateCreated(error.getDateCreated());
setProviderId(error.getProviderId());
setLocationId(error.getLocationId());

//For resolve form
setComment(error.getComment());
@@ -61,7 +67,7 @@ public MobileFormEntryErrorModel(MobileFormEntryError error, String errorType) {
Document formDataDoc = getDocumentForErrorQueueItem(getFormName());
XPath xp = getXPathFactory().newXPath();

if ("household".equals(errorType)) {
if ("household".equals(errorType)) {
setName("Household");
setBirthdate("N/A");
setIdentifier(xp.evaluate("/form/household/meta_data/household_id", formDataDoc));
@@ -71,7 +77,10 @@ public MobileFormEntryErrorModel(MobileFormEntryError error, String errorType) {

setTotalHousehold(xp.evaluate("/form/household/meta_data/total_household", formDataDoc));
setTotalEligible(xp.evaluate("/form/household/meta_data/total_eligible", formDataDoc));
setProviderId(xp.evaluate("/form/encounter/encounter.provider_id",formDataDoc));

if (getProviderId() == null)
setProviderId(xp.evaluate("/form/survey/provider_id", formDataDoc));

} else {
setName(xp.evaluate("/form/patient/patient.given_name", formDataDoc) + " " +
xp.evaluate("/form/patient/patient.middle_name", formDataDoc) + " " +
@@ -85,7 +94,15 @@ public MobileFormEntryErrorModel(MobileFormEntryError error, String errorType) {
String location = xp.evaluate("/form/encounter/encounter.location_id", formDataDoc);
setLocation(location.substring(location.indexOf("^") + 1));
setEncounterDate(xp.evaluate("/form/encounter/encounter.encounter_datetime", formDataDoc));

setTotalHousehold("N/A");
setTotalEligible("N/A");

if (getProviderId() == null)
setProviderId(xp.evaluate("/form/encounter/encounter.provider_id", formDataDoc));
}

// common properties for both household and individual
setFormModelName(xp.evaluate("/form/@name", formDataDoc));
setFormId(xp.evaluate("/form/@version", formDataDoc));

@@ -185,12 +202,14 @@ public void setLocation(String location) {
public String getFormModelName() {
return formModelName;
}

/**
* @param formModelName the formModelName to set
*/
public void setFormModelName(String formModelName) {
this.formModelName = formModelName;
}

/**
* @return the formId
*/
@@ -213,7 +232,35 @@ public void setFormPath(String formPath) {
this.formPath = formPath;
}

/**
* @return the totalHousehold
*/
public String getTotalHousehold() {
return totalHousehold;
}

/**
* @param totalHousehold the totalHousehold to set
*/
public void setTotalHousehold(String totalHousehold) {
this.totalHousehold = totalHousehold;
}


/**
* @return the totalEligible
*/
public String getTotalEligible() {
return totalEligible;
}

/**
* @param totalEligible the totalEligible to set
*/
public void setTotalEligible(String totalEligible) {
this.totalEligible = totalEligible;
}

/**
* @return the errorType
*/
Original file line number Diff line number Diff line change
@@ -34,7 +34,7 @@ public class MobileFormHouseholdLinksProcessor {
private DocumentBuilder docBuilder;
private XPathFactory xPathFactory;
private MobileFormEntryService mobileService;

// allow only one running instance
private static Boolean isRunning = false;

@@ -57,42 +57,41 @@ public MobileFormHouseholdLinksProcessor() {
*/
private void processPendingLinkForm(String filePath, MobileFormQueue queue) throws APIException {
log.debug("Linking Patient to household");
String providerId=null;
String locationId=null;
String providerId = null;
String locationId = null;
try {
String formData = queue.getFormData();
docBuilder = docBuilderFactory.newDocumentBuilder();
XPathFactory xpf = getXPathFactory();
XPath xp = xpf.newXPath();
Document doc = docBuilder.parse(IOUtils.toInputStream(formData));

Node curNode = (Node) xp.evaluate("/form/patient", doc, XPathConstants.NODE);
Node curNode = (Node) xp.evaluate("/form/patient", doc, XPathConstants.NODE);
String patientIdentifier = xp.evaluate(MobileFormEntryConstants.PATIENT_IDENTIFIER, curNode);
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);

//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)));
providerId = xp.evaluate(MobileFormEntryConstants.SURVEY_PROVIDER_ID, surveyNode);
providerId=providerId.trim();
//Clean location id by removing decimal points
locationId=MobileFormEntryUtil.cleanLocationEntry(householdLocation) ;

// 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
saveFormInError(filePath);
mobileService.saveErrorInDatabase(MobileFormEntryUtil.createError(getFormName(filePath), "Error linking patient",
"Patient has no identifier, or the identifier provided is invalid",providerId, locationId));
return;
}
String householdLocation = xp.evaluate(MobileFormEntryConstants.PATIENT_CATCHMENT_AREA, curNode);

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

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

// 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
saveFormInError(filePath);
mobileService.saveErrorInDatabase(MobileFormEntryUtil.createError(getFormName(filePath), "Error linking patient",
"Patient has no identifier, or the identifier provided is invalid", providerId, locationId));
return;
}

if (!StringUtils.hasText(householdId) || MobileFormEntryUtil.isNewHousehold(householdId)) {
saveFormInError(filePath);
mobileService.saveErrorInDatabase(MobileFormEntryUtil.createError(getFormName(filePath), "Error linking patient",
"Patient is not linked to household or household Id provided is invalid",providerId, locationId));
"Patient is not linked to household or household Id provided is invalid", providerId, locationId));
} else {
Patient pat = MobileFormEntryUtil.getPatient(patientIdentifier);
MobileFormHousehold household = mobileService.getHousehold(householdId);
@@ -113,7 +112,7 @@ private void processPendingLinkForm(String filePath, MobileFormQueue queue) thro
log.error("Error while linking patient to household", t);
//put file in error queue
saveFormInError(filePath);
mobileService.saveErrorInDatabase(MobileFormEntryUtil.createError(getFormName(filePath), "Error while linking patient to house hold", t.getMessage(),providerId, locationId));
mobileService.saveErrorInDatabase(MobileFormEntryUtil.createError(getFormName(filePath), "Error while linking patient to house hold", t.getMessage(), providerId, locationId));
}
}

Original file line number Diff line number Diff line change
@@ -6,6 +6,7 @@
import javax.xml.xpath.XPath;
import javax.xml.xpath.XPathConstants;
import javax.xml.xpath.XPathFactory;

import org.apache.commons.io.IOUtils;
import org.apache.commons.lang.StringUtils;
import org.apache.commons.logging.Log;
@@ -22,12 +23,11 @@

/**
* Processes Mobile forms Queue entries.
*
* <p/>
* When the processing is successful, For unsuccessful processing, the queue
* entry is put in the Mobile forms error folder.
*
* @author Samuel Mbugua
*
*/
@Transactional
public class MobileFormQueueProcessor {
@@ -58,8 +58,8 @@ private void processMobileForm(MobileFormQueue queue) throws APIException {
String householdIdentifier = null;
String householdGps = null;
MobileFormEntryService mfes = (MobileFormEntryService) Context.getService(MobileFormEntryService.class);
String providerId=null;
String locationId=null;
String providerId = null;
String locationId = null;

try {
docBuilder = docBuilderFactory.newDocumentBuilder();
@@ -69,36 +69,33 @@ private void processMobileForm(MobileFormQueue queue) throws APIException {
Node curNode = (Node) xp.evaluate(MobileFormEntryConstants.HOUSEHOLD_PREFIX + MobileFormEntryConstants.HOUSEHOLD_META_PREFIX, doc, XPathConstants.NODE);
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);

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

// providerId = Integer.toString(MobileFormEntryUtil.getProviderId(xp.evaluate(MobileFormEntryConstants.SURVEY_PROVIDER_ID, surveyNode)));
Node surveyNode = (Node) xp.evaluate(MobileFormEntryConstants.SURVEY_PREFIX, doc, XPathConstants.NODE);
locationId = MobileFormEntryUtil.cleanLocationEntry(householdLocation);
providerId = xp.evaluate(MobileFormEntryConstants.SURVEY_PROVIDER_ID, surveyNode).trim();

providerId = xp.evaluate(MobileFormEntryConstants.SURVEY_PROVIDER_ID, surveyNode);
providerId=providerId.trim();
// check household identifier and gps were entered correctly
if (StringUtils.isBlank(householdIdentifier) || StringUtils.isBlank(householdGps)) {
log.debug("Null household identifier or GPS");
saveFormInError(queue.getFileSystemUrl());
mfes.saveErrorInDatabase(MobileFormEntryUtil.
createError(getFormName(queue.getFileSystemUrl()), "Error processing household",
"This household has no identifier or GPS specified", providerId,locationId ));
createError(getFormName(queue.getFileSystemUrl()), "Error processing household",
"This household has no identifier or GPS specified", providerId, locationId));
return;
}

//pull out household data: includes meta, survey, economic, household_meta

//Search for the identifier in the household database
if (!MobileFormEntryUtil.isNewHousehold(householdIdentifier)
&& !MobileFormEntryUtil.isSameHousehold(householdIdentifier, householdGps)) {
&& !MobileFormEntryUtil.isSameHousehold(householdIdentifier, householdGps)) {

log.error("household with identifier " + householdIdentifier + " has conflicting GPS coordinates: " + householdGps);
saveFormInError(queue.getFileSystemUrl());
mfes.saveErrorInDatabase(MobileFormEntryUtil.
createError(getFormName(queue.getFileSystemUrl()), "Error processing household",
"A duplicate household different from this one exists with the same identifier (" + householdIdentifier + ")", providerId,locationId ));
createError(getFormName(queue.getFileSystemUrl()), "Error processing household",
"A duplicate household different from this one exists with the same identifier (" + householdIdentifier + ")", providerId, locationId));
} else {

// get or create household
@@ -132,7 +129,7 @@ private void processMobileForm(MobileFormQueue queue) throws APIException {
//put file in error table and move it to error directory
saveFormInError(queue.getFileSystemUrl());
mfes.saveErrorInDatabase(MobileFormEntryUtil.
createError(getFormName(queue.getFileSystemUrl()), "Error Parsing household form", t.getMessage(), providerId,locationId ));
createError(getFormName(queue.getFileSystemUrl()), "Error Parsing household form", t.getMessage(), providerId, locationId));
}
}

@@ -222,7 +219,7 @@ private String getFormName(String formPath) {

/**
* @return XPathFactory to be used for obtaining data from the parsed
* XML
* XML
*/
private XPathFactory getXPathFactory() {
if (xPathFactory == null) {
Loading