Exemplo n.º 1
0
 def test_query_single(self):
     """
     This function test whether the "querySingle" function extract correct row and attributes.
     """
     data_extract = query_single(DF, 'subject_id', 61, ["subject_id"],
                                 ["insurance", "age"], "subject_id")
     incorrect_data_extract = query_single(DF, 'subject_id', 300, ["subject_id"],
                                           ["insurance"], "subject_id")
     self.assertEqual(data_extract.shape, (1, 3))
     self.assertEqual(incorrect_data_extract.shape, (0, 2))
     self.assertTrue(len(data_extract['insurance'][0]) == len(data_extract['age'][0]))
Exemplo n.º 2
0
 def test_filter(self):
     """
     This function test "filter" function, to see if it can successfully filter the data
     from extracted data by "querySingle" function.
     """
     data_extract = query_single(DF, 'subject_id', 61, ["subject_id"], \
                                ["insurance", "age"], "subject_id")
     filtered_data = f(data_extract, 'subject_id', 66, '>')
     self.assertTrue(filtered_data.shape[0] == 0)
     filtered_data = f(data_extract, 'subject_id', 66, '<')
     self.assertTrue(filtered_data.shape[0] == data_extract.shape[0])
Exemplo n.º 3
0
    def get_report(self, subject_id, birth_year):
        '''main report generator program'''
        df1 = database_build.main()
        # df1 = pd.read_csv('../Data/test_file.csv')
        list_tolist = reversed([
            'hadm_id', 'Code', 'Descriptor', 'icd9_code', 'long_title',
            'admission_type', 'diagnosis', 'insurance', 'language', 'religion',
            'marital_status', 'ethnicity', 'gender', 'expire_flag', 'age',
            'age_death', 'age_group', 'admit_year', 'admit_new', 'disch_new',
            'description', 'drug_type', 'drug', 'formulary_drug_cd'
        ])

        table = qu.query_single(df1, 'subject_id', int(subject_id),
                                ["subject_id"], list_tolist, ["subject_id"])

        ages = table['age'].tolist()
        patient_age = int(ages[0][0])
        year = birth_year + patient_age

        if patient_age <= 4:
            age = '0-4'
        elif patient_age <= 9:
            age = '5-9'
        elif patient_age <= 19:
            age = '10-19'
        elif patient_age <= 29:
            age = '20-29'
        elif patient_age <= 39:
            age = '30-39'
        elif patient_age <= 49:
            age = '40-49'
        elif patient_age <= 59:
            age = '50-59'
        elif patient_age <= 69:
            age = '60-69'
        elif patient_age <= 79:
            age = '70-79'
        elif patient_age >= 80:
            age = '80+'

        for column in list_tolist:
            if column not in list(table.columns.values):
                table[column] = 'Nah'
        narms = qu.narms_query("../Data/narms_processed.csv", year, age)

        data_row = table.iloc[0]
        list_content = (data_row.tolist())

        list_name = [
            'subject_id', 'hadm_id', 'Code', 'Descriptor', 'icd9_code',
            'long_title', 'admission_type', 'diagnosis', 'insurance',
            'language', 'religion', 'marital_status', 'ethnicity', 'gender',
            'expire_flag', 'age', 'age_death', 'age_group', 'admit_year',
            'admit_new', 'disch_new', 'description', 'drug_type', 'drug',
            'formulary_drug_cd'
        ]

        list_narms = [
            'Data_Year', 'Age_Group', 'Specimen_ID', 'Resistance_Pattern',
            'AMI_Concl', 'AMP_Concl', 'ATM_Concl', 'AUG_Concl', 'AXO_Concl',
            'AZM_Concl', 'CAZ_Concl', 'CCV_Concl', 'CEP_Concl', 'CEQ_Concl',
            'CHL_Concl', 'CIP_Concl', 'CLI_Concl', 'COT_Concl', 'CTC_Concl',
            'CTX_Concl', 'ERY_Concl', 'FEP_Concl', 'FFN_Concl', 'FIS_Concl',
            'FOX_Concl', 'GEN_Concl', 'IMI_Concl', 'KAN_Concl', 'NAL_Concl',
            'PTZ_Concl', 'SMX_Concl', 'STR_Concl', 'TEL_Concl', 'TET_Concl',
            'TIO_Concl'
        ]

        variable = {}
        table_narms = OrderedDict()

        for count in range(0, len(list_name)):
            cell = list_content[count]
            if isinstance(cell, list):
                if len(cell) > 1 and list_name[count] != 'drug':
                    list_content[count] = list_content[count][:1]
                elif list_name[count] == 'drug':
                    list_content[count] = list_content[count][:50]
            list_content[count] = str(list_content[count])
            variable[list_name[count]] = list_content[count]

        for count in range(0, len(list_narms)):
            table_narms[list_narms[count]] = str(narms.iloc[0][count])

        for item in variable.keys():
            values_tem = variable[item]
            if (values_tem[0] == '[' and values_tem[1] == "'"
                    and values_tem[len(values_tem) - 2] == "'"
                    and values_tem[len(values_tem) - 1] == ']'):
                variable[item] = values_tem[2:(len(variable[item]) - 2)]
            elif (values_tem[0] == '['
                  and values_tem[len(values_tem) - 1] == ']'):
                variable[item] = values_tem[1:(len(variable[item]) - 1)]
        variable['drug'] = variable['drug'].replace("'", " ")
        variable['age'] = int(float(variable['age']))
        variable['age'] = str(variable['age'])

        if variable['age_death'] != 'nan':
            variable['age_death'] = int(float(variable['age_death']))
            variable['age_death'] = str(variable['age_death'])
        if variable['expire_flag'] == '1':
            variable['expire_flag'] = 'Death'
        else:
            variable['expire_flag'] = 'Live'

        return variable, table_narms
Exemplo n.º 4
0
    def test1(self):
        '''
        test1 is to test if the html is the same as we expect
        '''
        df1 = pd.read_csv('../Data/test_file.csv')
        list_tolist = reversed([
            'hadm_id', 'Code', 'Descriptor', 'icd9_code', 'long_title',
            'admission_type', 'diagnosis', 'insurance', 'language', 'religion',
            'marital_status', 'ethnicity', 'gender', 'expire_flag', 'age',
            'age_death', 'age_group', 'admit_year', 'admit_new', 'disch_new',
            'description', 'drug_type', 'drug', 'formulary_drug_cd'
        ])
        table = qu.query_single(df1, 'subject_id', 61, ["subject_id"],
                                list_tolist, ["subject_id"])

        for column in list_tolist:
            if column not in list(table.columns.values):
                table[column] = 'Nah'
        table_narms = qu.narms_query("../Data/narms_processed.csv", 1996,
                                     '0-4')
        data_row = table.iloc[0]
        list_tem = (data_row.tolist())
        html = op.html_maker(list_tem, table_narms)

        f = open('tem_out.csv', 'w')
        f.write(html)
        html_template = '''
    <hr>
    <h1 align="center">Patient Case Report Form</h1>
    <hr>

    <div class="bordered" style="float: left; width: 48%;">
    <h3>Patient Information</h3>
    <p>
    <b>Subject ID:</b> 61<br>
    <b>Hospital Visit ID:</b> 189535<br>
    <b>Age:</b> 55<br>
    <b>Deceased:</b>  Death<br>
    &nbsp;&nbsp;&nbsp;&nbsp;<b>Age at Death:</b> 55<br>
    <b>Gender:</b> M<br>
    <b>Ethnicity:</b> WHITE<br>
    <b>Primary Language:</b> nan<br>
    <b>Marital Status:</b> MARRIED<br>
    <b>Religion:</b> CATHOLIC<br>
    <b>Insurance:</b> Private<br>
    </p>
    </div>
    <div class="bordered" style="float: right; width: 50%;">
    <p>
    <h3>Disease Information</h3>
    <b>Condition Diagnosis Code:</b> 99591<br>
    &nbsp;&nbsp;&nbsp;&nbsp;<b>Descriptor:</b> Salmonella sepsis<br>
    <b>All Diagnoses:</b> Acidosis<br>
    <b>Hospital Admission Type:</b>EMERGENCY <br>
    <b>Admission Date:</b> 2002-01-04<br>
    <b>Discharge Date:</b> 2002-02-03<br>
    <h3>Prescription Information</h3>
    <b>Medications:</b> Amino Acids 4.25% W/ Dextrose 5% ,  Calcium Gluconate ,  Digoxin ,  Potassium Chloride ,  Potassium Chloride ,  Multivitamin IV ,  Heparin Flush PICC (100 units/ml) ,  Digoxin ,  Digoxin ,  Insulin ,  Hydrocortisone Na Succ. ,  Syringe ,  Insulin ,  Insulin ,  NS ,  Hydrocortisone Na Succ. ,  Digoxin ,  Neutra-Phos ,  Vial ,  Vial ,  Sodium Phosphate ,  Potassium Chloride ,  Hydrocortisone Na Succ. ,  Potassium Chloride ,  Daptomycin ,  NS ,  Levofloxacin ,  Potassium Chloride ,  SW ,  Potassium Chloride ,  Potassium Chloride ,  NS ,  Hydrocortisone Na Succ. ,  Vial ,  Diltiazem ,  NS ,  Potassium Chloride ,  Potassium Chloride ,  Potassium Chloride ,  Potassium Phosphate ,  SW ,  SW ,  SW ,  Spironolactone ,  Vial ,  Filgrastim ,  Potassium Chloride ,  Potassium Chloride ,  Hydrocortisone Na Succ. ,  Caspofungin<br>
    </div>
    <br>
    <div class="bordered2" style="float: left; width: 100%;">
    <p>
    <h3>NARMS Data</h3>
    <br>
    <b>List</b><br>
    AMI	Amikacin : 0<br>
    AMP Ampicillin : 2<br>
    ATM	Aztreonam : 0<br>
    AUG	Amoxicillin-clavulanic acid: 0<br>
    AXO	Ceftriaxone: 0<br>
    AZM	Azithromycin: 0<br>
    CAZ	Ceftazidime: 0<br>
    CCV	Ceftazidime-clavulanic acid: 0<br>
    CEP	Cephalothin: 0<br>
    CEQ	Cefquinome: 0<br>
    CHL	Chloramphenicol: 2<br>
    CIP	Ciprofloxacin: 0<br>
    CLI	Clindamycin: 0<br>
    COT	Trimethoprim-sulfamethoxazole: 0<br>
    CTC	Cefotaxime-clavulanic acid: 0<br>
    CTX	Cefotaxime: 0<br>
    ERY	Erythromycin: 0<br>
    FEP	Cefepime: 0<br>
    FFN	Florfenicol: 0<br>
    FIS	Sulfisoxazole: 0<br>
    FOX	Cefoxitin: 0<br>
    GEN	Gentamicin: 0<br>
    IMI	Imipenem: 0<br>
    KAN	Kanamycin: 0<br>
    NAL	Naladixic acid: 0<br>
    PTZ	Piperacillin-tazobactam: 0<br>
    SMX	Sulfamethoxazole: 2<br>
    STR	Streptomycin: 2<br>
    TEL	Telithromycin: 0<br>
    TIO	Ceftiofur: 0<br>
    TET	Tetracycline: 3<br>

    </p>
    </div>
    <img src="eCRx_logo_small.png" alt="eCRx Logo" style="float:left;width:10px;height:8.3px;">
   
    '''
        self.assertEqual(len(html), len(html_template))
Exemplo n.º 5
0
''' update: stu_id is optional
# do login (need stu_id from args)
if args.stu_id:
    stu_id = args.stu_id
    load_from_cookies(stu_id)
else:
    print ('You must provide a student ID for login!')
    #exit(0)
'''

if args.mode == 'query':
    if args.search and args.begin and args.end:
        print('please do not provide them at the same time!')
        exit(0)

    if args.search or (args.begin and args.end):
        import query
        if args.search:
            query.query_single(args.search)
        else:
            query.query_multiple(args.begin, args.end)
    else:
        print('please provide --search or (--begin AND --end)!')
        exit(0)

    if args.export:
        from parse import parse
        if args.export == 'csv':
            parse('csv')
        elif args.export == 'jpg':
            parse()