<commit_before>from datetime import datetime, timedelta
import uuid
from casexml.apps.case.models import CommCareCase
from corehq.apps.api.es import ReportCaseES, ReportXFormES
from corehq.apps.reports.filters.base import BaseSingleOptionFilter
from corehq.apps.reports.generic import GenericTabularReport
from corehq.apps.reports.standard import CustomProjectReport, ProjectReportParametersMixin, DatespanMixin

from pact.enums import PACT_DOMAIN, PACT_CASE_TYPE, XMLNS_DOTS_FORM
from pact.models import PactPatientCase, DOTSubmission, CObservation
from pact.reports.dot_calendar import DOTCalendarReporter


class PactDOTPatientField(BaseSingleOptionFilter):
    slug = "dot_patient"
    label = "DOT Patient"
    default_option = "Select DOT Patient"

    @property
    def options(self):
        patient_cases = self.get_pact_cases()
        case_type = self.request.GET.get(self.slug, '')

        self.selected = case_type
        self.options = [
            dict(val=case['_id'], text="(%s) - %s" % (case.get('pactid.#value', '[none]'), case['name']))
            for case in patient_cases]

    @classmethod
    def get_pact_cases(cls):
        #query couch to get reduce count of all PACT cases
        case_es = ReportCaseES(PACT_DOMAIN)
        total_count = CommCareCase.get_db().view('hqcase/types_by_domain',
                                                 key=["pact", PACT_CASE_TYPE]).first().get('value', 100)
        fields = ['_id', 'name', 'pactid.#value']
        query = case_es.base_query(terms={'type': PACT_CASE_TYPE},
                                   fields=fields,
                                   start=0,
                                   size=total_count)
        query['filter']['and'].append({"prefix": {"dot_status.#value": "dot"}})

        results = case_es.run_query(query)
        for res in results['hits']['hits']:
            yield res['fields']


class PactDOTReport(GenericTabularReport, CustomProjectReport, ProjectReportParametersMixin,
                    DatespanMixin):
    label = "DOT Patient List"
    slug = "dots"

    report_template_path = "pact/dots/dots_report.html"<commit_msg>fix pact DOT admin report<commit_after>from datetime import datetime, timedelta
import uuid
from casexml.apps.case.models import CommCareCase
from corehq.apps.api.es import ReportCaseES, ReportXFormES
from corehq.apps.reports.filters.base import BaseSingleOptionFilter
from corehq.apps.reports.generic import GenericTabularReport
from corehq.apps.reports.standard import CustomProjectReport, ProjectReportParametersMixin, DatespanMixin
from dimagi.utils.decorators.memoized import memoized

from pact.enums import PACT_DOMAIN, PACT_CASE_TYPE, XMLNS_DOTS_FORM
from pact.models import PactPatientCase, DOTSubmission, CObservation
from pact.reports.dot_calendar import DOTCalendarReporter


class PactDOTPatientField(BaseSingleOptionFilter):
    slug = "dot_patient"
    label = "DOT Patient"
    default_option = "Select DOT Patient"

    @property
    @memoized
    def options(self):
        return [
            dict(val=case['_id'], text="(%s) - %s" % (case.get('pactid.#value', '[none]'), case['name']))
            for case in self.get_pact_cases()
        ]

    @property
    def selected(self):
        return self.request.GET.get(self.slug, '')

    @classmethod
    def get_pact_cases(cls):
        # query couch to get reduce count of all PACT cases
        case_es = ReportCaseES(PACT_DOMAIN)
        total_count = CommCareCase.get_db().view('hqcase/types_by_domain',
                                                 key=["pact", PACT_CASE_TYPE]).first().get('value', 100)
        fields = ['_id', 'name', 'pactid.#value']
        query = case_es.base_query(terms={'type': PACT_CASE_TYPE},
                                   fields=fields,
                                   start=0,
                                   size=total_count)
        query['filter']['and'].append({"prefix": {"dot_status.#value": "dot"}})

        results = case_es.run_query(query)
        for res in results['hits']['hits']:
            yield res['fields']


class PactDOTReport(GenericTabularReport, CustomProjectReport, ProjectReportParametersMixin,
                    DatespanMixin):
    label = "DOT Patient List"
    slug = "dots"

    report_template_path = "pact/dots/dots_report.html"
{'fraction_non_alphanumeric': 0.10497109826589596, 'fraction_numerical': 0.0018497109826589595, 'mean_word_length': 2.904332129963899, 'pattern_counts': {'":': 4, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 2}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 10, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7130253', 'n_tokens_mistral': 1314, 'n_tokens_neox': 1263, 'n_words': 269}