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 37 #5

Open
wants to merge 16 commits into
base: master
Choose a base branch
from
Open
Changes from 9 commits
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
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
@@ -14,6 +14,8 @@
public class MobileFormEntryError extends BaseOpenmrsObject implements Auditable{

private Integer mobileFormEntryErrorId;
private String providerId;
private String locationId;
private String formName;
private String error;
private String errorDetails;
@@ -98,6 +100,35 @@ public void setFormName(String formName) {
this.formName = formName;
}

/**
* @return Returns the Provider Id
*/
public String getProviderId() {
return providerId;
}

/**
* @param Provider Id
* The formData to set.
*/
public void setProviderId(String providerId) {
this.providerId = providerId;
}

/**
* @return Returns the Location Id
*/
public String getLocationId() {
return locationId;
}

/**
* @param Location Id
* The formData to set.
*/
public void setLocationId(String locationId) {
this.locationId = locationId;
}
/**
* @return Returns the mobileFormEntryErrorId.
*/
Original file line number Diff line number Diff line change
@@ -25,15 +25,9 @@ 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
//encounter.provider_id
private String location = "";
private String providerId = "";
private String encounterDate = "";
private String formModelName = "";
private String formId = "";
@@ -67,7 +61,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));
@@ -91,13 +85,7 @@ 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");

setProviderId(xp.evaluate("/form/encounter/encounter.provider_id",formDataDoc));
}

setFormModelName(xp.evaluate("/form/@name", formDataDoc));
setFormId(xp.evaluate("/form/@version", formDataDoc));

@@ -197,14 +185,12 @@ 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
*/
@@ -227,48 +213,6 @@ 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 providerId
*/
public String getProviderId() {
return providerId;
}

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

/**
* @return the errorType
Original file line number Diff line number Diff line change
@@ -12,6 +12,7 @@
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.openmrs.Patient;
import org.openmrs.Location;
import org.openmrs.api.APIException;
import org.openmrs.api.context.Context;
import org.openmrs.module.amrsmobileforms.util.MobileFormEntryUtil;
@@ -56,30 +57,42 @@ public MobileFormHouseholdLinksProcessor() {
*/
private void processPendingLinkForm(String filePath, MobileFormQueue queue) throws APIException {
log.debug("Linking Patient to household");
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));

// 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"));
return;
}

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;
}

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"));
"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);
@@ -100,7 +113,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()));
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
@@ -2,7 +2,6 @@

import java.io.File;
import java.util.Iterator;

import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.xpath.XPath;
Original file line number Diff line number Diff line change
@@ -17,6 +17,7 @@
import org.springframework.transaction.annotation.Transactional;
import org.w3c.dom.Document;
import org.w3c.dom.Node;
import org.openmrs.Location;
import org.xml.sax.SAXParseException;

/**
@@ -57,6 +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;

try {
docBuilder = docBuilderFactory.newDocumentBuilder();
@@ -66,14 +69,22 @@ 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) ;

// providerId = Integer.toString(MobileFormEntryUtil.getProviderId(xp.evaluate(MobileFormEntryConstants.SURVEY_PROVIDER_ID, surveyNode)));

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"));
"This household has no identifier or GPS specified", providerId,locationId ));
return;
}

@@ -87,7 +98,7 @@ private void processMobileForm(MobileFormQueue queue) throws APIException {
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 + ")"));
"A duplicate household different from this one exists with the same identifier (" + householdIdentifier + ")", providerId,locationId ));
} else {

// get or create household
@@ -121,7 +132,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()));
createError(getFormName(queue.getFileSystemUrl()), "Error Parsing household form", t.getMessage(), providerId,locationId ));
}
}

Original file line number Diff line number Diff line change
@@ -35,7 +35,6 @@ public class MobileFormSplitProcessor {
private static final DocumentBuilderFactory docBuilderFactory = DocumentBuilderFactory.newInstance();
private DocumentBuilder docBuilder;
private MobileFormEntryService mobileService;

public MobileFormSplitProcessor(){
try{
docBuilder = docBuilderFactory.newDocumentBuilder();
@@ -52,6 +51,8 @@ public MobileFormSplitProcessor(){
*/
private boolean splitMobileForm(MobileFormQueue queue) throws APIException {
String formData = queue.getFormData();
String providerId=null;
String locationId=null;
try {
docBuilder = docBuilderFactory.newDocumentBuilder();
Document doc = docBuilder.parse(IOUtils.toInputStream(formData));
@@ -63,7 +64,7 @@ private boolean splitMobileForm(MobileFormQueue queue) throws APIException {
//Move form to error queue
saveFormInError(queue.getFileSystemUrl());
mobileService.saveErrorInDatabase(MobileFormEntryUtil.
createError(getFormName(queue.getFileSystemUrl()), "Error splitting document", t.getMessage()));
createError(getFormName(queue.getFileSystemUrl()), "Error splitting document", t.getMessage(),providerId,locationId));
return false;
}
return true;
Loading