def testPostCreatesLock(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_id, errors = post_from_settings(xml_data) xform = CXFormInstance.get(doc_id) self.assertTrue(xform.is_locked())
def testClosed(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_id, errors = post_from_settings(xml_data) xform = CXFormInstance.get(doc_id) self.assertNotEqual(None, xform.metadata) self.assertEqual("5020280", xform.metadata.clinic_id) self.assertEqual(date(2010,07,22), xform.metadata.time_start.date()) self.assertEqual(date(2010,07,23), xform.metadata.time_end.date()) self.assertEqual("admin", xform.metadata.username) self.assertEqual("f7f0c79e-8b79-11df-b7de-005056c00008", xform.metadata.user_id)
def bhoma_case_from_xml(test_class, filename, pat_id_override=None, referral_id_override=None): file_path = os.path.join(os.path.dirname(__file__), "data", filename) with open(file_path, "rb") as f: xml_data = f.read() doc_id, uid, case_id, ref_id = replace_ids_and_post(xml_data, case_id_override=pat_id_override, referral_id_override=referral_id_override) doc = CXFormInstance.get(doc_id) encounter = Encounter.from_xform(doc) case = get_or_update_bhoma_case(doc, encounter) test_class.assertNotEqual(None, case) return case
def bootstrap_case_from_xml(test_class, filename, case_id_override=None, referral_id_override=None): file_path = os.path.join(os.path.dirname(__file__), "data", filename) with open(file_path, "rb") as f: xml_data = f.read() doc_id, uid, case_id, ref_id = replace_ids_and_post(xml_data, case_id_override=case_id_override, referral_id_override=referral_id_override) cases_touched = get_or_update_cases(CXFormInstance.get(doc_id)) test_class.assertEqual(1, len(cases_touched)) case = cases_touched[case_id] test_class.assertEqual(case_id, case.case_id) return case
def get_xform(self, invalidate_cache=False): """ Get the xform that created this encounter. Will return a cached copy if one is available, unless invalidate_cache is specified and True. """ if self._xform == None or invalidate_cache: try: self._xform = CXFormInstance.get(self.xform_id) except ResourceNotFound: logging.exception( "No form with id %s found in encounter %s, could be due to partial couch sync" % (self.xform_id, self.get_id) ) return None return self._xform
def followup_made(case_id): """ For a given case id, return if a followup was made against it """ # NOTE: Due to the way the system works the only time a case has more # than one form submitted against it is when a CHW makes a follow up. # Clinic forms _only_ create new case or _manually close_ existing cases # (not with a form). Therefore a proxy for this logic is that the case # has 2 or more forms submitted against it. rows = get_db().view("case/xform_case", key=case_id, reduce=False).all() casedoc = CommCareCase.get_by_id(case_id) if not casedoc: logging.warning(("Couldn't find commcare case with id %s. " "This may mean the patient was deleted.") % case_id) return False for row in rows: # get the forms and if the namespace is a followup, then a followup # was made form = CXFormInstance.get(row["value"]) if form.namespace == config.CHW_FOLLOWUP_NAMESPACE: return True return False
def xform_data(request, instance_id): instance = CXFormInstance.get(instance_id) return render_to_response(request, "xforms/single_instance_raw.html", {"instance": instance})
def sorted_xforms(self): # TODO: cache. efficiency. forms = [] for form_id in self.form_ids: forms.append(CXFormInstance.get(form_id)) return sorted(forms, key=lambda form: Encounter.get_visit_date(form))