def _load_encounter_data(self): """ Loads the encounters into this. """ def _clear_encounters(self): self._encounters = [] if len(self._encounters) == 0 and (self.anchor_form_id or self.other_form_ids): self._encounters = [] if self.anchor_form_id: anchor = Encounter.view("encounter/in_patient_by_form", key=self.anchor_form_id).one() # this typically means we're in reprocessing mode, just clear the encounters # and try again next time. if not anchor: return _clear_encounters(self) self._add_encounter(anchor) for form_id in self.other_form_ids: enc = Encounter.view("encounter/in_patient_by_form", key=form_id).one() # this typically means we're in reprocessing mode, just clear the encounters # and try again next time. if not enc: return _clear_encounters(self) self._add_encounter(enc)
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))
def get_last_visit_date(self): if self.sorted_encounters(): return self.sorted_encounters()[-1].visit_date return Encounter.get_visit_date(self.sorted_xforms()[-1])
def get_encounter(self): if not self._encounter: self._encounter = Encounter.view("encounter/in_patient", key=self.encounter_id).one() return self._encounter