Пример #1
0
 def callback(doc):
     try:
         # only post-process forms that aren't duplicates
         new_form_workflow(doc,SENDER_PHONE)
         
         # find out how many forms they have submitted
         def forms_submitted_count(user):
             forms_submitted = get_db().view("centralreports/chw_submission_counts", 
                                             startkey=["ud", user], 
                                             endkey=["ud", user, {}]).one()
             return forms_submitted["value"] if forms_submitted else "at least 1"
         
         def forms_submitted_today_count(user):
             today = datetime.today()
             key = ["ud", user, today.year, today.month - 1, today.day]
             forms_submitted_today = get_db().view("centralreports/chw_submission_counts", 
                                                   key=key).one()
             return forms_submitted_today["value"] if forms_submitted_today else "at least 1"
             
         if doc.metadata and doc.metadata.user_id:
             return HttpResponse(xml.get_response(doc, 
                                                  forms_submitted_today_count(doc.metadata.user_id), 
                                                  forms_submitted_count(doc.metadata.user_id)))
         else:
             return HttpResponse(xml.get_response(doc))
     except Exception, e:
         logging.exception("problem post processing phone submission")
         return HttpResponse(xml.get_response(doc))
Пример #2
0
 def testUnmatchedPatient(self):
     folder_name = os.path.join(os.path.dirname(__file__), "data", "chw")
     with open(os.path.join(folder_name, "non_life_threatening_referral.xml"), "r") as f:
         formbody = f.read()
     formdoc = post_xform_to_couch(formbody)
     new_form_workflow(formdoc, SENDER_PHONE, None)
     self.assertFalse("#patient_guid" in formdoc)
Пример #3
0
 def testMissingPatientId(self):
     folder_name = os.path.join(os.path.dirname(__file__), "data", "chw")
     with open(os.path.join(folder_name, "referral_no_pat_id.xml"), "r") as f:
         formbody = f.read()
     formdoc = post_xform_to_couch(formbody)
     new_form_workflow(formdoc, SENDER_PHONE, None)
     self.assertFalse("#patient_guid" in formdoc)
Пример #4
0
def add_form_to_patient(patient_id, form):
    """
    From a handle to a patient and xform instance xml, 
    add that form to the patient.
    Returns the updated patient and newly created form.
    This will OVERRIDE any existing form with the same ID.
    """
    formdoc = post_xform_to_couch(form)
    new_form_workflow(formdoc, SENDER_EXPORT, patient_id)
    pat =  CPatient.get(patient_id) if patient_id is not None else None
    return pat, formdoc
Пример #5
0
 def testRegeneratePatient(self):
     folder_name = os.path.join(os.path.dirname(__file__), "data", "chw")
     patient = export.import_patient_json_file(os.path.join(folder_name, "patient.json"))
     self.assertEqual(0, len(patient.encounters))
     with open(os.path.join(folder_name, "non_life_threatening_referral.xml"), "r") as f:
         formbody = f.read()
     formdoc = post_xform_to_couch(formbody)
     new_form_workflow(formdoc, SENDER_PHONE, None)
     patient = CPatient.get(patient.get_id)
     self.assertEqual(1, len(patient.encounters))
     self.assertTrue(reprocess(patient.get_id))
     patient = CPatient.get(patient.get_id)
     self.assertEqual(1, len(patient.encounters))
Пример #6
0
def post_and_process_xform(filename, patient):
    doc = post_xform(filename, patient.get_id)
    new_form_workflow(doc, "unit_tests", patient.get_id)
    return doc
Пример #7
0
 def testFollowNoPatient(self):
     # no assertions necessary, this should just not throw an exception
     with open(os.path.join(os.path.dirname(__file__), "data", "bhoma", "chw_followup_nopatient.xml"), "r") as f:
         formdoc = post_xform_to_couch(f.read())
         new_form_workflow(formdoc, None, None)
Пример #8
0
 def callback(xform, doc):
     if doc:
         new_form_workflow(doc, SENDER_CLINIC, patient_id)
     return HttpResponseRedirect(reverse("single_patient", args=(patient_id,)))