def post_xform(filename, patient_id): file_path = os.path.join(os.path.dirname(__file__), "data", filename) with open(file_path, "rb") as f: xml_data = f.read() xml_data = xml_data.replace("REPLACE_PATID", patient_id) doc = post_xform_to_couch(xml_data) return doc
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)
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)
def testBasicDuplicate(self): file_path = os.path.join(os.path.dirname(__file__), "data", "duplicate.xml") with open(file_path, "rb") as f: xml_data = f.read() doc = post_xform_to_couch(xml_data) self.assertEqual("7H46J37FGH3", doc.get_id) self.assertTrue(doc.contributes()) self.assertEqual("CXFormInstance", doc.doc_type) self.assertEqual("XForm", doc["#doc_type"]) doc = post_xform_to_couch(xml_data) self.assertFalse(doc.contributes()) self.assertEqual("CXFormDuplicate", doc.doc_type) self.assertEqual("XFormDuplicate", doc["#doc_type"]) self.assertFalse(doc.is_locked())
def testUtilityReleasesLock(self): file_path = os.path.join(os.path.dirname(__file__), "data", "meta.xml") with open(file_path, "rb") as f: xml_data = f.read() doc = post_xform_to_couch(xml_data) self.assertFalse(doc.is_locked())
def inner_callback(xform, instance): # post to couch doc = post_xform_to_couch(instance) # call the callback, if there, otherwise route back to the # xforms list if callback: return callback(xform, doc) else: return HttpResponseRedirect(reverse("xform_list"))
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
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))
def post(request, callback=None): """ XForms can get posted here. They will be forwarded to couch. Just like play, if you specify a callback you get called, otherwise you get a generic response. Callbacks follow a different signature as play, only passing in the document (since we don't know what xform was being posted to) """ # just forward the post request to couch # this won't currently work with ODK # post to couch instance = request.raw_post_data doc = post_xform_to_couch(instance) if callback: return callback(doc) return HttpResponse("Thanks! Your new xform id is: %s" % doc["_id"])
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)