(self, casedoc, regimen_labels)
return ret
Return the json representation of a single days nonart/art data
        that is put back into the caseblock, sent to phone,
        sent back from phone

        This is the transmitted representation
        and the phone's representation of DOT data.
Return the json representation of a single days nonart/art data
        that is put back into the caseblock, sent to phone,
        sent back from phone
Return the json representation of a single days nonart / art data that is put back into the caseblock sent to phone sent back from phone
def to_case_json(self, casedoc, regimen_labels):
        """
        Return the json representation of a single days nonart/art data
        that is put back into the caseblock, sent to phone,
        sent back from phone

        This is the transmitted representation
        and the phone's representation of DOT data.
        """

        def get_obs_for_dosenum(obs_list, dose_num, label):
            if len(obs_list) > 0:
                obs = obs_list[0]
                day_slot = label
                if obs.day_slot != '' and obs.day_slot is not None:
                    day_slot = obs.day_slot
                if (obs.day_note is not None and len(obs.day_note) > 0
                        and obs.day_note != "[AddendumEntry]"):
                    day_note = obs.day_note
                else:
                    day_note = ''

                return [obs.adherence, obs.method, day_note, day_slot]
                # one and done per array
            else:
                # return pristine unchecked
                return ['unchecked', 'pillbox', '', label]

        ret = []
        for ix, dose_data in enumerate([self.nonart, self.art]):
            drug_arr = []
            labels_arr = regimen_labels[ix]
            dose_nums = list(dose_data.dose_dict.keys())
            dose_nums.sort()

            for dose_num in dose_nums:
                if dose_num is not None:
                    # for each dose num in the observed array of the drug type,
                    # there maybe more than one observation
                    obs_list = dose_data.dose_dict[dose_num]
                    drug_arr.append(get_obs_for_dosenum(obs_list, dose_num, labels_arr[dose_num]))
                else:
                    # just to get a sense of how widespread this problem is in sentry
                    logging.error('A pact case had an empty dose number.')

            # don't fill because we're looking at what was submitted.
            if len(drug_arr) <= dose_data.total_doses:
                if dose_data.drug_class == DOT_NONART:
                    max_doses = int(getattr(casedoc, 'nonartregimen', None) or 0)
                elif dose_data.drug_class == DOT_ART:
                    max_doses = int(getattr(casedoc, 'artregimen', None) or 0)

                # hack, in cases where we have zero data, put in the current regimen delta count
                delta = max_doses - dose_data.total_doses
                for x in range(0, delta):
                    drug_arr.append(["unchecked", "pillbox", '', labels_arr[x] if x < len(labels_arr) else -1])
            ret.append(drug_arr)
        return ret
def to_case_json ( self , casedoc , regimen_labels ) : def get_obs_for_dosenum ( obs_list , dose_num , label ) : if len ( obs_list ) > 0 : obs = obs_list [ 0 ] day_slot = label if obs . day_slot != '' and obs . day_slot is not None : day_slot = obs . day_slot if ( obs . day_note is not None and len ( obs . day_note ) > 0 and obs . day_note != "[AddendumEntry]" ) : day_note = obs . day_note else : day_note = '' return [ obs . adherence , obs . method , day_note , day_slot ] # one and done per array else : # return pristine unchecked return [ 'unchecked' , 'pillbox' , '' , label ] ret = [ ] for ix , dose_data in enumerate ( [ self . nonart , self . art ] ) : drug_arr = [ ] labels_arr = regimen_labels [ ix ] dose_nums = list ( dose_data . dose_dict . keys ( ) ) dose_nums . sort ( ) for dose_num in dose_nums : if dose_num is not None : # for each dose num in the observed array of the drug type, # there maybe more than one observation obs_list = dose_data . dose_dict [ dose_num ] drug_arr . append ( get_obs_for_dosenum ( obs_list , dose_num , labels_arr [ dose_num ] ) ) else : # just to get a sense of how widespread this problem is in sentry logging . error ( 'A pact case had an empty dose number.' ) # don't fill because we're looking at what was submitted. if len ( drug_arr ) <= dose_data . total_doses : if dose_data . drug_class == DOT_NONART : max_doses = int ( getattr ( casedoc , 'nonartregimen' , None ) or 0 ) elif dose_data . drug_class == DOT_ART : max_doses = int ( getattr ( casedoc , 'artregimen' , None ) or 0 ) # hack, in cases where we have zero data, put in the current regimen delta count delta = max_doses - dose_data . total_doses for x in range ( 0 , delta ) : drug_arr . append ( [ "unchecked" , "pillbox" , '' , labels_arr [ x ] if x < len ( labels_arr ) else - 1 ] ) ret . append ( drug_arr ) return ret