Exemple #1
0
    def _doTestNoPillbox(self, bundle):
        submit_xform(self.submit_url, self.domain.name, bundle['xml'])
        submitted = XFormInstance.get(bundle['xform_id'])
        self.assertTrue(hasattr(submitted, PACT_DOTS_DATA_PROPERTY))
        observations = query_observations(CASE_ID, bundle['start_date'],
                                          bundle['end_date'])
        observed_dates = set()
        #assume to be five - 3,2 same as the regimen count, we are refilling empties
        self.assertEqual(
            5,
            len(observations),
            msg="Observations do not match regimen count: %d != %d" %
            (5, len(observations)))
        art_nonart = set()
        for obs in observations:
            observed_dates.add(obs.observed_date)
            self.assertEquals(
                obs.day_note, "No check, from form"
            )  #magic string from the view to indicate a generated DOT observation from form data.
            art_nonart.add(obs.is_art)
            self.assertEquals(obs.doc_id, bundle['xform_id'])

        art = filter(lambda x: x.is_art, observations)
        self.assertEquals(2, len(art))
        art_answered = filter(lambda x: x.adherence != "unchecked", art)
        self.assertEquals(1, len(art_answered))

        nonart = filter(lambda x: not x.is_art, observations)
        self.assertEquals(3, len(nonart))
        nonart_answered = filter(lambda x: x.adherence != "unchecked", nonart)
        self.assertEquals(1, len(nonart_answered))

        #this only does SINGLE observations for art and non art
        self.assertEquals(len(observed_dates), 1)
        self.assertEquals(len(art_nonart), 2)
        # inspect the regenerated submission and ensure the built xml block is correctly filled.

        case_json = get_dots_case_json(PactPatientCase.get(CASE_ID),
                                       anchor_date=bundle['anchor_date'])
        enddate = bundle['anchor_date']  # anchor date of this submission
        #encounter_date = datetime.strptime(submitted.form['encounter_date'], '%Y-%m-%d')
        encounter_date = submitted.form['encounter_date']

        for day_delta in range(DOT_DAYS_INTERVAL):
            obs_date = enddate - timedelta(days=day_delta)
            ret_index = DOT_DAYS_INTERVAL - day_delta - 1

            day_arr = case_json['days'][ret_index]
            nonart_day_data = day_arr[0]
            art_day_data = day_arr[1]

            self.assertEquals(len(nonart_day_data), 3)
            self.assertEquals(len(art_day_data), 2)
Exemple #2
0
def recompute_dots_casedata(casedoc, couch_user, submit_date=None, sync_token=None):
    """
    On a DOT submission, recompute the DOT block and submit a casedoc update xform
    Recompute and reset the ART regimen and NONART regimen to whatever the server says it is, in the casedoc where there's an idiosyncracy with how the phone has it set.

    This only updates the patient's casexml block with new dots data, and has no bearing on website display - whatever is pulled from the dots view is real.
    """
    if getattr(casedoc, 'dot_status', None) in ['DOT5', 'DOT3', 'DOT1']:
        update_dict = {}
        dots_data = get_dots_case_json(casedoc)

        update_dict['dots'] = json.dumps(dots_data)
        submit_case_update_form(casedoc, update_dict, couch_user, submit_date=submit_date, xmlns=XMLNS_PATIENT_UPDATE_DOT, sync_token=sync_token)
Exemple #3
0
def recompute_dots_casedata(casedoc, couch_user, submit_date=None, sync_token=None):
    """
    On a DOT submission, recompute the DOT block and submit a casedoc update xform
    Recompute and reset the ART regimen and NONART regimen to whatever the server says it is, in the casedoc where there's an idiosyncracy with how the phone has it set.

    This only updates the patient's casexml block with new dots data, and has no bearing on website display - whatever is pulled from the dots view is real.
    """
    if getattr(casedoc, 'dot_status', None) in ['DOT5', 'DOT3', 'DOT1']:
        update_dict = {}
        dots_data = get_dots_case_json(casedoc)

        update_dict['dots'] = json.dumps(dots_data)
        submit_case_update_form(casedoc, update_dict, couch_user, submit_date=submit_date, xmlns=XMLNS_PATIENT_UPDATE_DOT, sync_token=sync_token)
    def _doTestNoPillbox(self, bundle):
        submit_xform(self.submit_url, self.domain.name, bundle['xml'])
        submitted = XFormInstance.get(bundle['xform_id'])
        self.assertTrue(hasattr(submitted, PACT_DOTS_DATA_PROPERTY))
        observations = query_observations(CASE_ID, bundle['start_date'], bundle['end_date'])
        observed_dates = set()
        #assume to be five - 3,2 same as the regimen count, we are refilling empties
        self.assertEqual(5, len(observations), msg="Observations do not match regimen count: %d != %d" % ( 5, len(observations)))
        art_nonart = set()
        for obs in observations:
            observed_dates.add(obs.observed_date)
            self.assertEquals(obs.day_note, "No check, from form") #magic string from the view to indicate a generated DOT observation from form data.
            art_nonart.add(obs.is_art)
            self.assertEquals(obs.doc_id, bundle['xform_id'])

        art = filter(lambda x: x.is_art, observations)
        self.assertEquals(2, len(art))
        art_answered = filter(lambda x: x.adherence != "unchecked", art)
        self.assertEquals(1, len(art_answered))

        nonart = filter(lambda x: not x.is_art, observations)
        self.assertEquals(3, len(nonart))
        nonart_answered = filter(lambda x: x.adherence != "unchecked", nonart)
        self.assertEquals(1, len(nonart_answered))

        #this only does SINGLE observations for art and non art
        self.assertEquals(len(observed_dates), 1)
        self.assertEquals(len(art_nonart), 2)
        # inspect the regenerated submission and ensure the built xml block is correctly filled.

        case_json = get_dots_case_json(PactPatientCase.get(CASE_ID), anchor_date=bundle['anchor_date'])
        enddate = bundle['anchor_date'] # anchor date of this submission
        #encounter_date = datetime.strptime(submitted.form['encounter_date'], '%Y-%m-%d')
        encounter_date = submitted.form['encounter_date']

        for day_delta in range(DOT_DAYS_INTERVAL):
            obs_date = enddate - timedelta(days=day_delta)
            ret_index = DOT_DAYS_INTERVAL - day_delta -1


            day_arr = case_json['days'][ret_index]
            nonart_day_data = day_arr[0]
            art_day_data = day_arr[1]

            self.assertEquals(len(nonart_day_data), 3)
            self.assertEquals(len(art_day_data), 2)
Exemple #5
0
    def testDOTFormatConversion(self):
        """
        When a DOT submission comes in, it gets sliced into the CObservations
        and put into the DOTDay format.

        On resubmit/recompute, it's transmitted back into the packed json format and sent back to the phone and resubmitted with new data.
        This test confirms that the conversion process works.
        """
        self.testSignal()

        submitted = XFormInstance.get(PILLBOX_ID)
        orig_data = getattr(submitted, PACT_DOTS_DATA_PROPERTY)['dots']
        orig_anchor = orig_data['anchor']
        del orig_data['anchor']  # can't reproduce gmt offset

        observations = query_observations(CASE_ID, START_DATE, END_DATE)

        #hack, bootstrap the labels manually
        nonart_idx = [0, 2, 3]
        art_idx = [0, 1]
        casedoc = PactPatientCase.get(CASE_ID)
        casedoc.nonartregimen = 3
        casedoc.dot_n_one = 0
        casedoc.dot_n_two = 2
        casedoc.dot_n_three = 3
        casedoc.dot_n_four = None

        casedoc.artregimen = 2
        casedoc.dot_a_one = 0
        casedoc.dot_a_two = 1
        casedoc.dot_a_three = ''
        casedoc.dot_a_four = None

        computed_json = simplejson.loads(
            simplejson.dumps(
                get_dots_case_json(casedoc, anchor_date=ANCHOR_DATE)))
        computed_anchor = computed_json['anchor']
        del computed_json['anchor']

        for k in orig_data.keys():
            if k != 'days':
                self.assertEquals(orig_data[k], computed_json[k])

        self.assertEquals(simplejson.dumps(orig_data),
                          simplejson.dumps(computed_json))
    def _submitAndVerifyBundle(self, bundle, verify=True):
        start_nums = len(self.case.xform_ids)
        submit_xform(self.submit_url, self.domain.name, bundle['xml'])
        time.sleep(1)
        submitted = XFormInstance.get(bundle['xform_id'])
        self.assertTrue(hasattr(submitted, PACT_DOTS_DATA_PROPERTY))

        submitted_dots = getattr(submitted, PACT_DOTS_DATA_PROPERTY)
        updated_case = PactPatientCase.get(CASE_ID)
        case_dots = get_dots_case_json(updated_case)
        days = case_dots['days']

        if verify:
            nonart_submissions = bundle['nonart']
            art_submissions = bundle['art']
            examine_day = days[bundle['check_idx']]

            self._verify_dot_cells(nonart_submissions, art_submissions, examine_day)
Exemple #7
0
    def _submitAndVerifyBundle(self, bundle, verify=True):
        start_nums = len(self.case.xform_ids)
        submit_xform(self.submit_url, self.domain.name, bundle['xml'])
        time.sleep(1)
        submitted = XFormInstance.get(bundle['xform_id'])
        self.assertTrue(hasattr(submitted, PACT_DOTS_DATA_PROPERTY))

        submitted_dots = getattr(submitted, PACT_DOTS_DATA_PROPERTY)
        updated_case = PactPatientCase.get(CASE_ID)
        case_dots = get_dots_case_json(updated_case)
        days = case_dots['days']

        if verify:
            nonart_submissions = bundle['nonart']
            art_submissions = bundle['art']
            examine_day = days[bundle['check_idx']]

            self._verify_dot_cells(nonart_submissions, art_submissions, examine_day)
    def testDOTFormatConversion(self):
        """
        When a DOT submission comes in, it gets sliced into the CObservations
        and put into the DOTDay format.

        On resubmit/recompute, it's transmitted back into the packed json format and sent back to the phone and resubmitted with new data.
        This test confirms that the conversion process works.
        """
        self.testSignal()

        submitted = XFormInstance.get(PILLBOX_ID)
        orig_data = getattr(submitted, PACT_DOTS_DATA_PROPERTY)['dots']
        orig_anchor = orig_data['anchor']
        del orig_data['anchor'] # can't reproduce gmt offset

        observations = query_observations(CASE_ID, START_DATE, END_DATE)

        #hack, bootstrap the labels manually
        nonart_idx = [0, 2, 3]
        art_idx = [0, 1]
        casedoc = PactPatientCase.get(CASE_ID)
        casedoc.nonartregimen = 3
        casedoc.dot_n_one = 0
        casedoc.dot_n_two = 2
        casedoc.dot_n_three = 3
        casedoc.dot_n_four = None

        casedoc.artregimen = 2
        casedoc.dot_a_one = 0
        casedoc.dot_a_two = 1
        casedoc.dot_a_three = ''
        casedoc.dot_a_four = None

        computed_json = simplejson.loads(
            simplejson.dumps(get_dots_case_json(casedoc, anchor_date=ANCHOR_DATE)))
        computed_anchor = computed_json['anchor']
        del computed_json['anchor']

        for k in orig_data.keys():
            if k != 'days':
                self.assertEquals(orig_data[k], computed_json[k])

        self.assertEquals(simplejson.dumps(orig_data), simplejson.dumps(computed_json))