def case_submits_facet_dict(self, limit): query = query_per_case_submissions_facet(self.request.domain, limit=limit) results = self.xform_es.run_query(query) case_id_count_map = {} for f in results['facets']['case_submissions']['terms']: case_id_count_map[f['term']] = f['count'] return case_id_count_map
def get(self, *args, **kwargs): """ Download prior progress note submissions for local access """ db = XFormInstance.get_db() couch_user = CouchUser.from_django_user(self.request.user) username = couch_user.raw_username if hasattr(localsettings, 'debug_pact_user'): username = getattr(localsettings, 'debug_pact_user')(username) offset =0 limit_count=200 total_count = 0 query = { "query": { "filtered": { "filter": { "and": [ {"term": {"domain.exact": "pact"}}, {"term": {"form.#type": "progress_note"}}, {"term": {"form.meta.username": username}} ] }, "query": {"match_all": {}} } }, "sort": {"received_on": "asc"}, "size": limit_count, "fields": ['_id', 'external_blobs'] } query['script_fields'] = {} query['script_fields'].update(pact_script_fields()) query['script_fields'].update(case_script_field()) res = self.xform_es.run_query(query) my_patients_ever_submitted_query = query_per_case_submissions_facet(PACT_DOMAIN, username) patients_res = self.xform_es.run_query(my_patients_ever_submitted_query) #filter by active/discharged? #get all the forms #get all the patients #get all patients to determine which to filter. active_patients = [] for pt in []: #if pt.hp_status == "Discharged": #continue case_id = pt['script_case_id'] active_patients.append(case_id) def return_iterator(): yield "<restoredata>" for result in res['hits']['hits']: data_row = result['fields'] # if data_row['script_case_id'] not in active_patients: # continue try: xml_str = (BlobHelper(data_row, db, CODES.form_xml) .fetch_attachment('form.xml').decode('utf-8') .replace("<?xml version=\'1.0\' ?>", '') .replace("<?xml version='1.0' encoding='UTF-8' ?>", '')) yield xml_str except Exception as ex: logging.error("for downloader: error fetching attachment: %s" % ex) yield "</restoredata>" response = HttpResponse(return_iterator(), content_type='text/xml') return response
def get(self, *args, **kwargs): """ Download prior progress note submissions for local access """ db = XFormInstance.get_db() couch_user = CouchUser.from_django_user(self.request.user) username = couch_user.raw_username if hasattr(localsettings, 'debug_pact_user'): username = getattr(localsettings, 'debug_pact_user')(username) offset =0 limit_count=200 total_count = 0 query = { "query": { "filtered": { "filter": { "and": [ {"term": {"domain.exact": "pact"}}, {"term": {"form.#type": "progress_note"}}, {"term": {"form.meta.username": username}} ] }, "query": {"match_all": {}} } }, "sort": {"received_on": "asc"}, "size": limit_count, "fields": ['_id'] } query['script_fields'] = {} query['script_fields'].update(pact_script_fields()) query['script_fields'].update(case_script_field()) res = self.xform_es.run_query(query) my_patients_ever_submitted_query = query_per_case_submissions_facet(PACT_DOMAIN, username) patients_res = self.xform_es.run_query(my_patients_ever_submitted_query) #filter by active/discharged? #get all the forms #get all the patients #get all patients to determine which to filter. active_patients = [] for pt in []: #if pt.hp_status == "Discharged": #continue case_id = pt['script_case_id'] active_patients.append(case_id) def return_iterator(): yield "<restoredata>" for result in res['hits']['hits']: data_row = result['fields'] # if data_row['script_case_id'] not in active_patients: # continue try: xml_str = db.fetch_attachment(data_row['_id'], 'form.xml').replace("<?xml version=\'1.0\' ?>", '').replace("<?xml version='1.0' encoding='UTF-8' ?>", '') yield xml_str except Exception, ex: logging.error("for downloader: error fetching attachment: %s" % ex) yield "</restoredata>"