コード例 #1
0
    def testStringToLabelValues(self):
        """
        From the string representation of the selected regimen, create the case properties representing this


        Note, hacky form right now assumes all these properties are resolved as strings - if changes come to the xforms that submit these values as ints, then
        equality will need to be changed.
        """

        qid = 'morning,noon,evening,bedtime' #0,1,2,3
        tid_shift = 'noon,evening,bedtime' #1,2,3
        bd_extremes = 'morning,bedtime' #0,3
        qd_eve = 'evening' #2

        qid_ret = regimen_dict_from_choice(DOT_ART, qid)
        self.assertEquals(qid_ret, {'dot_a_one': '0', 'dot_a_four': '3', 'dot_a_two': '1', 'artregimen': '4', 'dot_a_three': '2'})

        tid_ret = regimen_dict_from_choice(DOT_ART, tid_shift)
        self.assertEquals(tid_ret, {'dot_a_one': '1', 'dot_a_four': '', 'dot_a_two': '2', 'artregimen': '3', 'dot_a_three': '3'})

        bd_ret = regimen_dict_from_choice(DOT_ART, bd_extremes)
        self.assertEquals(bd_ret, {'dot_a_one': '0', 'dot_a_four': '', 'dot_a_two': '3', 'artregimen': '2', 'dot_a_three': ''})

        qd_ret = regimen_dict_from_choice(DOT_ART, qd_eve)
        self.assertEquals(qd_ret, {'dot_a_one': '2', 'dot_a_four': '', 'dot_a_two': '', 'artregimen': '1', 'dot_a_three': ''})
コード例 #2
0
    def testStringToLabelValues(self):
        """
        From the string representation of the selected regimen, create the case properties representing this


        Note, hacky form right now assumes all these properties are resolved as strings - if changes come to the xforms that submit these values as ints, then
        equality will need to be changed.
        """

        qid = 'morning,noon,evening,bedtime' #0,1,2,3
        tid_shift = 'noon,evening,bedtime' #1,2,3
        bd_extremes = 'morning,bedtime' #0,3
        qd_eve = 'evening' #2

        qid_ret = regimen_dict_from_choice(DOT_ART, qid)
        self.assertEqual(qid_ret, {'dot_a_one': '0', 'dot_a_four': '3', 'dot_a_two': '1', 'artregimen': '4', 'dot_a_three': '2'})

        tid_ret = regimen_dict_from_choice(DOT_ART, tid_shift)
        self.assertEqual(tid_ret, {'dot_a_one': '1', 'dot_a_four': '', 'dot_a_two': '2', 'artregimen': '3', 'dot_a_three': '3'})

        bd_ret = regimen_dict_from_choice(DOT_ART, bd_extremes)
        self.assertEqual(bd_ret, {'dot_a_one': '0', 'dot_a_four': '', 'dot_a_two': '3', 'artregimen': '2', 'dot_a_three': ''})

        qd_ret = regimen_dict_from_choice(DOT_ART, qd_eve)
        self.assertEqual(qd_ret, {'dot_a_one': '2', 'dot_a_four': '', 'dot_a_two': '', 'artregimen': '1', 'dot_a_three': ''})
コード例 #3
0
    def setUp(self):
        for doc in XFormInstance.get_db().view('hqadmin/forms_over_time',
                                               reduce=False,
                                               include_docs=True).all():
            #purge all xforms prior to start
            if doc['doc']['xmlns'] in [
                    XMLNS_DOTS_FORM, XMLNS_PATIENT_UPDATE_DOT
            ]:
                XFormInstance.get_db().delete_doc(doc['doc'])

        two_weeks = timedelta(days=14)
        self.domain = Domain()
        self.domain.name = PACT_DOMAIN
        self.domain.is_active = True
        self.domain.date_created = datetime.utcnow() - two_weeks
        self.domain.save()

        self.submit_url = '/a/%s/receiver' % self.domain.name

        self.user = CommCareUser.create(self.domain.name,
                                        'ctsims',
                                        'mockmock',
                                        uuid=CTSIMS_ID)

        nonart_case_regimens = regimen_dict_from_choice(
            DOT_NONART, "morning,evening,bedtime")
        art_case_regimens = regimen_dict_from_choice(DOT_ART, "morning,noon")
        props = {
            '_id': CASE_ID,
            'dot_status': 'DOT1',
            'domain': self.domain.name
        }
        props.update(nonart_case_regimens)
        props.update(art_case_regimens)

        case = CommCareCase(**props)
        case.save()

        #generate CaseDoc

        self.pillbox_form = ""
        with open(
                os.path.join(os.path.abspath(os.path.dirname(__file__)),
                             'dots_data', '01_pillbox.xml')) as fin:
            self.pillbox_form = fin.read()

        self.no_pillbox_form = ""
        with open(
                os.path.join(os.path.abspath(os.path.dirname(__file__)),
                             'dots_data', '02_no_pillbox.xml')) as fin:
            self.no_pillbox_form = fin.read()
        self.no_pillbox_form2 = ""
        with open(
                os.path.join(os.path.abspath(os.path.dirname(__file__)),
                             'dots_data', '03_no_pillbox.xml')) as fin:
            self.no_pillbox_form2 = fin.read()
コード例 #4
0
    def setUp(self):
        for doc in get_all_forms_in_all_domains():
            # purge all xforms prior to start
            if doc.xmlns in [XMLNS_DOTS_FORM, XMLNS_PATIENT_UPDATE_DOT]:
                doc.delete()

        two_weeks = timedelta(days=14)
        self.domain = Domain()
        self.domain.name = PACT_DOMAIN
        self.domain.is_active = True
        self.domain.date_created = datetime.utcnow() - two_weeks
        self.domain.save()

        self.submit_url = '/a/%s/receiver' % self.domain.name

        self.user = CommCareUser.create(self.domain.name,
                                        'ctsims',
                                        'mockmock',
                                        None,
                                        None,
                                        uuid=CTSIMS_ID)

        nonart_case_regimens = regimen_dict_from_choice(
            DOT_NONART, "morning,evening,bedtime")
        art_case_regimens = regimen_dict_from_choice(DOT_ART, "morning,noon")
        props = {
            '_id': CASE_ID,
            'dot_status': 'DOT1',
            'domain': self.domain.name
        }
        props.update(nonart_case_regimens)
        props.update(art_case_regimens)

        case = CommCareCase(**props)
        case.save()

        #generate CaseDoc

        self.pillbox_form = ""
        with open(os.path.join(os.path.abspath(os.path.dirname(__file__)),
                               'dots_data', '01_pillbox.xml'),
                  encoding='utf-8') as fin:
            self.pillbox_form = fin.read()

        self.no_pillbox_form = ""
        with open(os.path.join(os.path.abspath(os.path.dirname(__file__)),
                               'dots_data', '02_no_pillbox.xml'),
                  encoding='utf-8') as fin:
            self.no_pillbox_form = fin.read()
        self.no_pillbox_form2 = ""
        with open(os.path.join(os.path.abspath(os.path.dirname(__file__)),
                               'dots_data', '03_no_pillbox.xml'),
                  encoding='utf-8') as fin:
            self.no_pillbox_form2 = fin.read()
コード例 #5
0
ファイル: dot_ordering.py プロジェクト: caktus/commcare-hq
    def setUp(self):

        for doc in get_all_forms_in_all_domains():
            # purge all xforms prior to start
            if doc.xmlns in [XMLNS_DOTS_FORM, XMLNS_PATIENT_UPDATE_DOT]:
                doc.delete()

        two_weeks = timedelta(days=14)
        self.domain = create_domain(PACT_DOMAIN)
        self.domain.date_created = datetime.utcnow() - two_weeks
        self.domain.save()

        self.submit_url = '/a/%s/receiver' % self.domain.name

        self.user = CommCareUser.create(self.domain.name,
                                        'ctsims',
                                        'mockmock',
                                        None,
                                        None,
                                        uuid=CTSIMS_ID)

        nonart_case_regimens = regimen_dict_from_choice(
            DOT_NONART, "morning,bedtime")
        art_case_regimens = regimen_dict_from_choice(DOT_ART,
                                                     "morning,bedtime")
        props = {
            '_id': CASE_ID,
            'dot_status': 'DOT1',
            'domain': self.domain.name
        }
        props.update(nonart_case_regimens)
        props.update(art_case_regimens)

        self.case = CommCareCase(**props)
        self.case.save()

        self.form_a = ""
        with open(os.path.join(os.path.abspath(os.path.dirname(__file__)),
                               'dots_data', '05_uncheck_a.xml'),
                  encoding='utf-8') as fin:
            self.form_a = fin.read() % {
                'encounter_date': ANCHOR_DATE_A.strftime('%Y-%m-%d'),
                'anchor_date': ANCHOR_DATE_A.strftime("%d %b %Y")
            }

        self.form_b = ""
        with open(os.path.join(os.path.abspath(os.path.dirname(__file__)),
                               'dots_data', '06_uncheck_b.xml'),
                  encoding='utf-8') as fin:
            self.form_b = fin.read() % {
                'encounter_date': ANCHOR_DATE_B.strftime('%Y-%m-%d'),
                'anchor_date': ANCHOR_DATE_B.strftime("%d %b %Y")
            }
コード例 #6
0
    def setUp(self):
        for doc in get_all_forms_in_all_domains():
            # purge all xforms prior to start
            if doc.xmlns in [XMLNS_DOTS_FORM, XMLNS_PATIENT_UPDATE_DOT]:
                doc.delete()

        two_weeks = timedelta(days=14)
        self.domain = Domain()
        self.domain.name = PACT_DOMAIN
        self.domain.is_active = True
        self.domain.date_created = datetime.utcnow() - two_weeks
        self.domain.save()

        self.submit_url = '/a/%s/receiver' % self.domain.name

        self.user = CommCareUser.create(self.domain.name, 'ctsims', 'mockmock', uuid=CTSIMS_ID)

        nonart_case_regimens = regimen_dict_from_choice(DOT_NONART, "morning,evening,bedtime")
        art_case_regimens = regimen_dict_from_choice(DOT_ART, "morning,noon")
        props= {'_id': CASE_ID, 'dot_status': 'DOT1', 'domain': self.domain.name}
        props.update(nonart_case_regimens)
        props.update(art_case_regimens)

        case = CommCareCase(**props)
        case.save()

        #generate CaseDoc

        self.pillbox_form = ""
        with open(os.path.join(os.path.abspath(os.path.dirname(__file__)), 'dots_data',
                               '01_pillbox.xml')) as fin:
            self.pillbox_form = fin.read()

        self.no_pillbox_form = ""
        with open(os.path.join(os.path.abspath(os.path.dirname(__file__)), 'dots_data',
                               '02_no_pillbox.xml')) as fin:
            self.no_pillbox_form = fin.read()
        self.no_pillbox_form2 = ""
        with open(os.path.join(os.path.abspath(os.path.dirname(__file__)), 'dots_data',
                               '03_no_pillbox.xml')) as fin:
            self.no_pillbox_form2 = fin.read()
コード例 #7
0
    def setUp(self):
        settings.TIME_ZONE = 'UTC'
        for doc in XFormInstance.get_db().view('hqadmin/forms_over_time', reduce=False,
                                               include_docs=True).all():
            # purge all xforms prior to start
            if doc['doc']['xmlns'] in [XMLNS_DOTS_FORM, XMLNS_PATIENT_UPDATE_DOT]:
                XFormInstance.get_db().delete_doc(doc['doc'])

        two_weeks = timedelta(days=14)
        self.domain = create_domain(PACT_DOMAIN)
        self.domain.date_created = datetime.utcnow() - two_weeks
        self.domain.save()

        self.submit_url = '/a/%s/receiver' % self.domain.name

        self.user = CommCareUser.create(self.domain.name, 'ctsims', 'mockmock', uuid=CTSIMS_ID)

        nonart_case_regimens = regimen_dict_from_choice(DOT_NONART, "morning,bedtime")
        art_case_regimens = regimen_dict_from_choice(DOT_ART, "morning,bedtime")
        props = {'_id': CASE_ID, 'dot_status': 'DOT1', 'domain': self.domain.name}
        props.update(nonart_case_regimens)
        props.update(art_case_regimens)

        self.case = CommCareCase(**props)
        self.case.save()

        self.form_a = ""
        with open(os.path.join(os.path.abspath(os.path.dirname(__file__)), 'dots_data',
                               '05_uncheck_a.xml')) as fin:
            self.form_a = fin.read() % {
                'encounter_date': ANCHOR_DATE_A.strftime('%Y-%m-%d'),
                'anchor_date': ANCHOR_DATE_A.strftime("%d %b %Y")
            }

        self.form_b = ""
        with open(os.path.join(os.path.abspath(os.path.dirname(__file__)), 'dots_data',
                               '06_uncheck_b.xml')) as fin:
            self.form_b = fin.read() % {
                'encounter_date': ANCHOR_DATE_B.strftime('%Y-%m-%d'),
                'anchor_date': ANCHOR_DATE_B.strftime("%d %b %Y")
            }
コード例 #8
0
ファイル: dot_ordering.py プロジェクト: kkrampa/commcare-hq
    def setUp(self):

        for doc in get_all_forms_in_all_domains():
            # purge all xforms prior to start
            if doc.xmlns in [XMLNS_DOTS_FORM, XMLNS_PATIENT_UPDATE_DOT]:
                doc.delete()

        two_weeks = timedelta(days=14)
        self.domain = create_domain(PACT_DOMAIN)
        self.domain.date_created = datetime.utcnow() - two_weeks
        self.domain.save()

        self.submit_url = '/a/%s/receiver' % self.domain.name

        self.user = CommCareUser.create(self.domain.name, 'ctsims', 'mockmock', uuid=CTSIMS_ID)

        nonart_case_regimens = regimen_dict_from_choice(DOT_NONART, "morning,bedtime")
        art_case_regimens = regimen_dict_from_choice(DOT_ART, "morning,bedtime")
        props = {'_id': CASE_ID, 'dot_status': 'DOT1', 'domain': self.domain.name}
        props.update(nonart_case_regimens)
        props.update(art_case_regimens)

        self.case = CommCareCase(**props)
        self.case.save()

        self.form_a = ""
        with open(os.path.join(os.path.abspath(os.path.dirname(__file__)), 'dots_data',
                               '05_uncheck_a.xml'), encoding='utf-8') as fin:
            self.form_a = fin.read() % {
                'encounter_date': ANCHOR_DATE_A.strftime('%Y-%m-%d'),
                'anchor_date': ANCHOR_DATE_A.strftime("%d %b %Y")
            }

        self.form_b = ""
        with open(os.path.join(os.path.abspath(os.path.dirname(__file__)), 'dots_data',
                               '06_uncheck_b.xml'), encoding='utf-8') as fin:
            self.form_b = fin.read() % {
                'encounter_date': ANCHOR_DATE_B.strftime('%Y-%m-%d'),
                'anchor_date': ANCHOR_DATE_B.strftime("%d %b %Y")
            }
コード例 #9
0
    def testStringToDictRegimensNum(self):
        #assure that all frequencies line up ok
        for freq in range(1, 5):
            regimens = PACT_REGIMEN_CHOICES[freq][1]
            for drug_type in art_nonart:
                for regimen_tuple in regimens:
                    ret = regimen_dict_from_choice(drug_type, regimen_tuple[0])

                    if drug_type == DOT_ART:
                        key_type_string = CASE_ART_REGIMEN_PROP
                    elif drug_type == DOT_NONART:
                        key_type_string = CASE_NONART_REGIMEN_PROP
                    self.assertEqual(ret[key_type_string], str(freq))
コード例 #10
0
    def testStringToDictRegimensNum(self):
        #assure that all frequencies line up ok
        for freq in range(1,5):
            regimens = PACT_REGIMEN_CHOICES[freq][1]
            for drug_type in art_nonart:
                for regimen_tuple in regimens:
                    ret = regimen_dict_from_choice(drug_type, regimen_tuple[0])

                    if drug_type == DOT_ART:
                        key_type_string = CASE_ART_REGIMEN_PROP
                    elif drug_type == DOT_NONART:
                        key_type_string = CASE_NONART_REGIMEN_PROP
                    self.assertEquals(ret[key_type_string], str(freq))
コード例 #11
0
ファイル: patient_form.py プロジェクト: solleks/commcare-hq
    def clean_changed_data(self):
        #to be called after validation
        ret = {}
        for name, value in self.cleaned_data.items():
            #to verify that the regimens changed calculate the dict of the freq+label ids.
            if name == CASE_ART_REGIMEN_PROP:
                art_props = regimen_dict_from_choice(DOT_ART, value)
                if art_props != self.casedoc.art_properties():
                    ret.update(art_props)
            elif name == CASE_NONART_REGIMEN_PROP:
                nonart_props = regimen_dict_from_choice(DOT_NONART, value)
                if nonart_props != self.casedoc.nonart_properties():
                    ret.update(nonart_props)
            else:
                if getattr(self.casedoc, name, '') != value:
                    ret[name] = value

        # hack, if any of the names, change remake the name and initials
        name_changed = False
        if 'first_name' in list(ret.keys()):
            name_changed = True
            first_name = ret['first_name']
        else:
            first_name = self.casedoc.first_name

        if 'last_name' in list(ret.keys()):
            name_changed = True
            last_name = ret['last_name']
        else:
            last_name = self.casedoc.last_name

        if name_changed:
            ret['name'] = '%s %s' % (first_name, last_name)
            ret['initials'] = '%s%s' % (
                first_name[0] if len(first_name) > 1 else '',
                last_name[0] if len(last_name) > 0 else '')

        return ret
コード例 #12
0
    def clean_changed_data(self):
        #to be called after validation
        ret = {}
        for name, value in self.cleaned_data.items():
            #to verify that the regimens changed calculate the dict of the freq+label ids.
            if name == CASE_ART_REGIMEN_PROP:
                art_props = regimen_dict_from_choice(DOT_ART, value)
                if art_props != self.casedoc.art_properties():
                    ret.update(art_props)
            elif name == CASE_NONART_REGIMEN_PROP:
                nonart_props = regimen_dict_from_choice(DOT_NONART, value)
                if nonart_props != self.casedoc.nonart_properties():
                    ret.update(nonart_props)
            else:
                if getattr(self.casedoc, name, '') != value:
                    ret[name] = value


        # hack, if any of the names, change remake the name and initials
        name_changed = False
        if 'first_name' in ret.keys():
            name_changed = True
            first_name = ret['first_name']
        else:
            first_name = self.casedoc.first_name

        if 'last_name' in ret.keys():
            name_changed = True
            last_name = ret['last_name']
        else:
            last_name = self.casedoc.last_name

        if name_changed:
            ret['name'] = '%s %s' % (first_name, last_name)
            ret['initials'] = '%s%s' % (first_name[0] if len(first_name) > 1 else '', last_name[0] if len(last_name) > 0 else '')

        return ret