def create_patients(count, clinic_id): from bhoma.utils.data import random_person, random_clinic_id from bhoma.apps.patient.models import CPatient if clinic_id is None: print "no clinic specified, will randomly assign ids" CPatient.get_db() for i in range(count): p = random_person() this_clinic_id = clinic_id if clinic_id else random_clinic_id() p.clinic_ids = [this_clinic_id,] p.save() print "successfully generated %s new patients" % count
def _patient_wrapper(row): """ The wrapper bolts the patient object onto the case, if we find it, otherwise does what the view would have done in the first place and adds an empty patient property """ from bhoma.apps.patient.models import CPatient data = row.get('value') docid = row.get('id') doc = row.get('doc') if not data or data is None: return row if not isinstance(data, dict) or not docid: return row else: if 'rev' in data: data['_rev'] = data.pop('rev') case = cls.wrap(data) case.patient = None if doc == None: # there's (I think) a bug in couchdb causing these to come back empty try: doc = CPatient.get_db().get(docid) except Exception, e: pass if doc and doc.get("doc_type") == "CPatient": case.patient = CPatient.wrap(doc) return case