Exemplo n.º 1
0
 def es_results(self):
     user = self.get_user()
     fields = [
         "_id", "form.#type", "received_on", "form.meta.timeStart",
         "form.meta.timeEnd"
     ]
     query = get_base_form_es_query(self.pagination.start,
                                    self.pagination.count)
     query = (query.filter(
         filters.term('form.meta.username',
                      user.raw_username)).source(fields).raw_query)
     query['script_fields'] = {}
     query['script_fields'].update(pact_script_fields())
     query['script_fields'].update(case_script_field())
     query['sort'] = self.get_sorting_block()
     return self.xform_es.run_query(query)
Exemplo n.º 2
0
 def es_results(self):
     user = self.get_user()
     fields = [
         "_id", "form.#type", "received_on", "form.meta.timeStart",
         "form.meta.timeEnd"
     ]
     query = self.xform_es.base_query(
         terms={'form.meta.username': user.raw_username},
         fields=fields,
         start=self.pagination.start,
         size=self.pagination.count)
     query['script_fields'] = {}
     query['script_fields'].update(pact_script_fields())
     query['script_fields'].update(case_script_field())
     query['sort'] = self.get_sorting_block()
     return self.xform_es.run_query(query)
Exemplo n.º 3
0
 def es_results(self):
     user = self.get_user()
     fields = [
         "_id",
         "form.#type",
         "received_on",
         "form.meta.timeStart",
         "form.meta.timeEnd"
     ]
     query = self.xform_es.base_query(terms={'form.meta.username': user.raw_username},
                                      fields=fields, start=self.pagination.start,
                                      size=self.pagination.count)
     query['script_fields'] = {}
     query['script_fields'].update(pact_script_fields())
     query['script_fields'].update(case_script_field())
     query['sort'] = self.get_sorting_block()
     return self.xform_es.run_query(query)
Exemplo n.º 4
0
    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
Exemplo n.º 5
0
    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>"