def regimen_dict_from_choice(key_type, regimen_string): """ Given a regimen string, "morning,noon,evening" return a dict of the appropriate update values of the casedoc of this representation key_type is ART or NONART so if art will return 'artregimen': <int>, "dot_a_one": 0, "dot_a_two": "1", etc if nonartregimen it'll be 'nonartregimen' and dot_n_one, etc. """ assert key_type in list(type_keys.keys()), 'the key_type must be ART or NONART' #ensure regimen_string is in PACT_REGIMEN_CHOICES_DICT #get integer day slot from DAY_SLOTS_BY_TIME[str] if len(regimen_string) > 0: regimen_split = regimen_string.split(',') regimen_freq = len(regimen_split) else: regimen_freq = 0 regimen_split = [] day_key_prefix = type_keys[key_type] if key_type == DOT_ART: key_type_string = CASE_ART_REGIMEN_PROP elif key_type == DOT_NONART: key_type_string = CASE_NONART_REGIMEN_PROP ret = { key_type_string: str(regimen_freq) } for x in range(0, 4): if x < regimen_freq: ret[day_key_prefix % digit_strings[x]] = str(DAY_SLOTS_BY_TIME.get(regimen_split[x], None)) else: ret[day_key_prefix % digit_strings[x]] = "" return ret
def regimen_dict_from_choice(key_type, regimen_string): """ Given a regimen string, "morning,noon,evening" return a dict of the appropriate update values of the casedoc of this representation key_type is ART or NONART so if art will return 'artregimen': <int>, "dot_a_one": 0, "dot_a_two": "1", etc if nonartregimen it'll be 'nonartregimen' and dot_n_one, etc. """ assert key_type in type_keys.keys(), 'the key_type must be ART or NONART' #ensure regimen_string is in PACT_REGIMEN_CHOICES_DICT #get integer day slot from DAY_SLOTS_BY_TIME[str] if len(regimen_string) > 0: regimen_split = regimen_string.split(',') regimen_freq = len(regimen_split) else: regimen_freq = 0 regimen_split = [] day_key_prefix = type_keys[key_type] if key_type == DOT_ART: key_type_string = CASE_ART_REGIMEN_PROP elif key_type == DOT_NONART: key_type_string = CASE_NONART_REGIMEN_PROP ret = { key_type_string: str(regimen_freq) } for x in range(0, 4): if x < regimen_freq: ret[day_key_prefix % digit_strings[x]] = str(DAY_SLOTS_BY_TIME.get(regimen_split[x], None)) else: ret[day_key_prefix % digit_strings[x]] = "" return ret
def get_regimen_code_arr(str_regimen): """ Helper function to decode regimens for both the old style regimens (in REGIMEN_CHOICES) as well as the new style regimens as required in the technical specs above. should return an array of day slot indices. """ if str_regimen is None or str_regimen == '' or str_regimen == 'None': return [] #legacy handling if str_regimen.lower() == 'qd': return [0] elif str_regimen.lower() == 'qd-am': return [0] elif str_regimen.lower() == 'qd-pm': return [2] elif str_regimen.lower() == 'bid': return [0, 2] elif str_regimen.lower() == 'qid': return [0, 1, 2, 3] elif str_regimen.lower() == 'tid': return [0, 1, 2] elif str_regimen.lower() == '': return [] #newer handling, a split string splits = str_regimen.split(',') ret = [] for x in splits: if x in DAY_SLOTS_BY_TIME.keys(): ret.append(DAY_SLOTS_BY_TIME[x]) else: logging.error( "value error, the regimen string is incorrect for the given patient, returning blank" ) ret = [] return ret
def get_regimen_code_arr(str_regimen): """ Helper function to decode regimens for both the old style regimens (in REGIMEN_CHOICES) as well as the new style regimens as required in the technical specs above. should return an array of day slot indices. """ if str_regimen is None or str_regimen == '' or str_regimen == 'None': return [] #legacy handling if str_regimen.lower() == 'qd': return [0] elif str_regimen.lower() == 'qd-am': return [0] elif str_regimen.lower() == 'qd-pm': return [2] elif str_regimen.lower() == 'bid': return [0, 2] elif str_regimen.lower() == 'qid': return [0, 1, 2, 3] elif str_regimen.lower() == 'tid': return [0, 1, 2] elif str_regimen.lower() == '': return [] #newer handling, a split string splits = str_regimen.split(',') ret = [] for x in splits: if x in DAY_SLOTS_BY_TIME.keys(): ret.append(DAY_SLOTS_BY_TIME[x]) else: logging.error("value error, the regimen string is incorrect for the given patient, returning blank") ret = [] return ret