File size: 1,718 Bytes
a71b937
fba9ff3
 
 
 
 
 
 
 
 
 
 
a71b937
 
 
fba9ff3
 
 
 
 
 
a71b937
fba9ff3
a71b937
fba9ff3
 
 
 
 
f0a794c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
def date_dict(df, pif_key):
    date = df.loc[df['pif_key'].astype(str) == str(pif_key), 'encounter_date'].values[0]
    date_insert_dict = {
        'attribute_name': 'report_date',
        'attribute_method': 'cv',
        'attribute_normalized_prediction': '',
        'attribute_prediction': str(date),
        'attribute_version': 'v2_090523',
        'attribute_vocab': '',
        'attribute_code': '',
        'date_of_service': ''
    }
    return date_insert_dict

def report_date_check(dict_list, df):
    col_names = {col['attribute_name'] for col in dict_list}
    if 'report_date' not in col_names:
        pif_key = next((col['attribute_prediction'] for col in dict_list if col['attribute_name'] == 'pif_key'), None)
        if pif_key is not None:
            date_insert_dict = date_dict(df, pif_key)
            dict_list.append(date_insert_dict)
    return dict_list

def json_report_date_insertion(json_data, df):
    for biomarker_detail in json_data['patient_level']['biomarkers']['details']:
        for attribute in biomarker_detail['attribute']:
            attribute_details = attribute['attribute_details']
            attribute['attribute_details'] = report_date_check(attribute_details, df)
    return json_data

def dicts_to_dataframe(list_of_dicts):
    # Initialize an empty DataFrame
    df = pd.DataFrame()

    # Iterate through each dictionary in the list
    for d in list_of_dicts:
        # Convert each dictionary into a DataFrame
        temp_df = pd.DataFrame([d])

        # Concatenate the temporary DataFrame with the main DataFrame
        df = pd.concat([df, temp_df], ignore_index=True)

    # Fill missing values with empty strings
    df = df.fillna('')

    return df