Beispiel #1
0
def get_chemo_label_object(wards, ord_start_date, ord_end_date, start_dt,
                           end_dt):
    from recordlib import RecordParser, read_excel
    drugs_recs = read_excel(DRUG_DB_PATH)
    odr = OrderSelectApiRequest(ord_start_date, ord_end_date, wards)
    odr.api_calls()
    records = odr.get_records()
    ord_recs = RecordParser(records=records,
                            drop_if=lambda row: row.get('rcpt_dt', "") == "")

    # if real
    ord_recs.select('*', where=lambda row: start_dt <= row['rcpt_dt'] < end_dt)

    ord_recs.vlookup(drugs_recs, 'ord_cd',
                     '약품코드', [('항암제구분', '0'), ('함량1', 0.0), ('함량단위1', ''),
                              ('함량2', 0.0), ('함량단위2', '')])
    ord_recs.format([('ord_qty', 0.0), ('함량1', 0.0), ('함량2', 0.0)])
    ord_recs.add_column([('amt_vol', lambda row: row['ord_qty'] * row['함량1']),
                         ('amt_wgt', lambda row: row['ord_qty'] * row['함량2'])])

    chemo_index = ord_recs.select(['ord_ymd', 'rcpt_seq', 'medi_no', 'ord_no'],
                                  where=lambda row: row['항암제구분'] == '1',
                                  inplace=False).to2darry(headers=False)
    ord_recs.select('*',
                    where=lambda r: [
                        r['ord_ymd'], r['rcpt_seq'], r['medi_no'], r['ord_no']
                    ] in chemo_index)
    detail = ord_recs.records.copy()
    f, l = ord_recs.min('rcpt_dt'), ord_recs.max('rcpt_dt')
    ord_recs.group_by(columns=['ord_ymd', 'rcpt_seq', 'medi_no', 'ord_cd'],
                      aggset=[('amt_vol', sum, 'amt_vol_sum'),
                              ('amt_wgt', sum, 'amt_wgt_sum'),
                              ('ord_qty', sum, 'ord_qty_sum'),
                              ('drug_nm', len, 'drug_nm_count')],
                      selects=[
                          'ord_cd', 'drug_nm', 'ord_unit_nm', 'amt_vol_sum',
                          'amt_wgt_sum', 'ord_qty_sum', '함량단위1', '함량단위2',
                          'drug_nm_count'
                      ],
                      inplace=True)
    ord_recs.add_column([('rcpt_dt_min', lambda x: f),
                         ('rcpt_dt_max', lambda x: l)])
    return ord_recs.records, detail


# path  = 'C:\\Users\\user\\Desktop\\집계표.xlsx'
# ret = get_label_object(['P', 'S'], ['51', '52', '61', '71', '81', '92', 'IC'], '2017-04-09','2017-04-10', '2017-04-08 00:00:00', '2017-04-08 23:23:00')
# ret.to_excel(path)
# os.startfile(path)

# get_label_object_test(['P', 'S'], ['51', '52', '61', '71', '81', '92', 'IC'], '2017-04-09','2017-04-10', '2017-04-08 00:00:00', '2017-04-08 23:23:00')
Beispiel #2
0
def get_inj_object(types,
                   wards,
                   ord_start_date,
                   ord_end_date,
                   start_dt,
                   end_dt,
                   test=False):
    from recordlib import RecordParser, read_excel
    drug_db_recs = read_excel(
        DRUG_DB_PATH,
        drop_if=lambda row: row['투여경로'] != '3' or row['효능코드명'] in
        ['혈액대용제', '당류제'] or row['항암제구분'] == '1' or row['약품법적구분'] in ['1', '2'])
    pk_set = drug_db_recs.unique('약품코드')
    odr = OrderSelectApiRequest(ord_start_date, ord_end_date, wards)

    if test:
        odr.set_test_response('response_samples/ordSelect51.sample.rsp')
    else:
        odr.api_calls()

    ord_recs = RecordParser(
        records=odr.get_records(),
        drop_if=lambda row: row.get('ord_cd') not in pk_set or row.get(
            'rcpt_dt', "") == "" or row.get('rcpt_ord_tp_nm') not in types)
    ord_recs.format([('ord_qty', 0.0), ('ord_frq', 0), ('ord_day', 0)])
    if not test:
        ord_recs.select('*',
                        where=lambda row: start_dt <= row['rcpt_dt'] < end_dt)

    ord_recs.add_column([
        ('once_amt', lambda row: round(row['ord_qty'] / row['ord_frq'], 2)),
        ('total_amt', lambda row: row['ord_qty'] * row['ord_day'])
    ])

    detail = ord_recs.records.copy()
    f, l = ord_recs.min('rcpt_dt'), ord_recs.max('rcpt_dt')
    ord_recs.group_by(columns=['ord_cd'],
                      aggset=[('ord_qty', sum, 'ord_qty_sum'),
                              ('drug_nm', len, 'drug_nm_count'),
                              ('total_amt', sum, 'total_amt_sum')],
                      selects=[
                          'ord_cd', 'drug_nm', 'ord_qty_sum', 'ord_unit_nm',
                          'drug_nm_count', 'total_amt_sum'
                      ])
    ord_recs.add_column([('rcpt_dt_min', lambda x: f),
                         ('rcpt_dt_max', lambda x: l)])
    return ord_recs.records, detail
Beispiel #3
0
def get_chemo_label_object_test(wards, ord_start_date, ord_end_date, start_dt,
                                end_dt):
    from recordlib import RecordParser, read_excel
    drugs_recs = read_excel(DRUG_DB_PATH)
    odr = OrderSelectApiRequest(ord_start_date, ord_end_date, wards)
    odr.set_test_response('response_samples/ordSelect51.sample.rsp')
    records = odr.get_records()
    ord_recs = RecordParser(records=records,
                            drop_if=lambda row: row.get('rcpt_dt', "") == "")

    # if real
    # ord_recs.select('*', where= lambda row: start_dt <= row['rcpt_dt'] < end_dt)

    ord_recs.vlookup(drugs_recs, 'ord_cd',
                     '약품코드', [('항암제구분', '0'), ('함량1', 0.0), ('함량단위1', ''),
                              ('함량2', 0.0), ('함량단위2', '')])
    ord_recs.format([('ord_qty', 0.0), ('함량1', 0.0), ('함량2', 0.0)])
    ord_recs.add_column([('amt_vol', lambda row: row['ord_qty'] * row['함량1']),
                         ('amt_wgt', lambda row: row['ord_qty'] * row['함량2'])])

    chemo_index = ord_recs.select(['ord_ymd', 'rcpt_seq', 'medi_no', 'ord_no'],
                                  where=lambda row: row['항암제구분'] == '1',
                                  inplace=False).to2darry(headers=False)
    ord_recs.select('*',
                    where=lambda r: [
                        r['ord_ymd'], r['rcpt_seq'], r['medi_no'], r['ord_no']
                    ] in chemo_index)
    detail = ord_recs.records.copy()
    f, l = ord_recs.min('rcpt_dt'), ord_recs.max('rcpt_dt')
    ord_recs.group_by(columns=['ord_ymd', 'rcpt_seq', 'medi_no', 'ord_cd'],
                      aggset=[('amt_vol', sum, 'amt_vol_sum'),
                              ('amt_wgt', sum, 'amt_wgt_sum'),
                              ('ord_qty', sum, 'ord_qty_sum'),
                              ('drug_nm', len, 'drug_nm_count')],
                      selects=[
                          'ord_cd', 'drug_nm', 'ord_unit_nm', 'amt_vol_sum',
                          'amt_wgt_sum', 'ord_qty_sum', '함량단위1', '함량단위2',
                          'drug_nm_count'
                      ],
                      inplace=True)
    ord_recs.add_column([('rcpt_dt_min', lambda x: f),
                         ('rcpt_dt_max', lambda x: l)])
    return ord_recs.records, detail
Beispiel #4
0
def get_label_object(kinds, types, wards, ord_start_date, ord_end_date,
                     start_dt, end_dt):
    from recordlib import RecordParser, read_excel
    try:
        drug_db_recs = get_label_list()
        drug_db_recs = RecordParser(
            drug_db_recs, drop_if=lambda row: row['단일포장구분'] not in ['S', 'P'])
    except:
        drug_db_recs = read_excel(
            DRUG_DB_PATH, drop_if=lambda row: row['단일포장구분'] not in ['S', 'P'])

    pk_set = drug_db_recs.unique('약품코드')
    odr = OrderSelectApiRequest(ord_start_date, ord_end_date, wards)
    odr.api_calls()
    records = odr.get_records()
    ord_recs = RecordParser(
        records=records,
        drop_if=lambda row: row.get('ord_cd') not in pk_set or row.get(
            'rcpt_dt', "") == "" or row.get('rcpt_ord_tp_nm') not in types)

    ord_recs.vlookup(drug_db_recs, 'ord_cd', '약품코드', [('단일포장구분', 'S')])
    ord_recs.format([('ord_qty', 0.0), ('ord_frq', 0), ('ord_day', 0)])

    ord_recs.select('*', where=lambda row: start_dt <= row['rcpt_dt'] < end_dt)
    ord_recs.add_column([
        ('once_amt', lambda row: round(row['ord_qty'] / row['ord_frq'], 2)),
        ('total_amt', lambda row: row['ord_qty'] * row['ord_day'])
    ])
    detail = ord_recs.records.copy()
    f, l = ord_recs.min('rcpt_dt'), ord_recs.max('rcpt_dt')

    ord_recs.group_by(columns=['단일포장구분', 'drug_nm'],
                      aggset=[('ord_qty', sum, 'ord_qty_sum'),
                              ('drug_nm', len, 'drug_nm_count'),
                              ('total_amt', sum, 'total_amt_sum')],
                      selects=[
                          '단일포장구분', 'ord_cd', 'drug_nm', 'ord_qty_sum',
                          'ord_unit_nm', 'drug_nm_count', 'total_amt_sum'
                      ])
    ord_recs.add_column([('rcpt_dt_min', lambda x: f),
                         ('rcpt_dt_max', lambda x: l)])
    ord_recs.value_map([('단일포장구분', {'S': '작은라벨', 'P': '큰라벨'}, '')])
    return ord_recs.records, detail
Beispiel #5
0
def get_records(types,
                wards,
                ord_start_date,
                ord_end_date,
                start_dt,
                end_dt,
                test,
                shape='po'):
    # print(ord_start_date, ord_end_date, wards)
    ord_request = OrderSelectApiRequest(ord_start_date, ord_end_date, wards)
    if test:
        ord_request.set_test_response('response_samples/orderselect')
        drug_lst = listorm.read_excel(DRUG_DB_PATH)
        ord_lst = listorm.Listorm(ord_request.get_records())
    else:
        ord_request.api_calls()
        ord_lst = listorm.Listorm(ord_request.get_records())
        try:
            if shape == 'inj':
                drug_lst = get_inj_list()
            else:
                drug_lst = get_label_list()
        except:
            drug_lst = read_excel(DRUG_DB_PATH)
        else:
            ord_lst = ord_lst.filter(where=lambda row: row.rcpt_dt and start_dt
                                     <= row['rcpt_dt'] < end_dt)

    drug_lst = drug_lst.select('약품코드', '단일포장구분', '효능코드(보건복지부)')
    pk_set = drug_lst.unique('약품코드')

    ord_lst = ord_lst.filter(
        where=lambda row: row.get('ord_cd') in pk_set and row.get(
            'rcpt_dt') and row.get('rcpt_ord_tp_nm') in types)
    ord_lst = ord_lst.join(drug_lst, left_on='ord_cd', right_on='약품코드')
    ord_lst = ord_lst.set_number_type(ord_qty=0.0, ord_frq=0, ord_day=0)

    rcpt_dt_list = ord_lst.column_values('rcpt_dt')
    if rcpt_dt_list:
        f, l = min(rcpt_dt_list), max(rcpt_dt_list)
        ord_lst = ord_lst.add_columns(rcpt_dt_min=lambda x: f,
                                      rcpt_dt_max=lambda x: l)
    return ord_lst
Beispiel #6
0
    def save_drug_list(self,
                       page_start,
                       page_end,
                       categorys,
                       market_status,
                       excel=None,
                       csv=None,
                       append=False,
                       set_detail=False):
        '''	present_code = {'Y':'급여', 'N': '비급여'}
			categorys = {'E': '전문', 'O': '일반', 'Q': '의약외품'}
			market_status = {'AS': '유통/생산 중', 'AE': '유통/생산 미확인', 'AD': '유통/생산 중단'}
		'''
        if append:
            recs = read_excel(excel) if excel else read_csv(csv,
                                                            encoding='cp949')
        else:
            recs = RecordParser()

        for ctg in categorys:
            for mks in market_status:
                for npage in range(page_start, page_end):
                    try:
                        record = RecordParser(
                            self.get_all(category=ctg,
                                         market_status=mks,
                                         page=npage,
                                         set_detail=set_detail))
                    except Exception as e:
                        print("Except on", ctg, mks, npage, e)
                        break
                    if not record:
                        break
                    recs += record
                    print('{}-{}-{}'.format(ctg, mks, npage))

        recs.distinct(['drug_id'])
        if excel:
            recs.to_excel(excel)
        elif csv:
            recs.to_csv(csv)
Beispiel #7
0
from recordlib import RecordParser, read_excel

path1 = r'C:\Users\HS\Desktop\향정잔량.xls'
path2 = "C:\\Users\\HS\\Desktop\\향정잔량2.xls"
path3 = "C:\\Users\\HS\\Desktop\\약품정보.xls"
path4 = "C:\\Users\\HS\\Desktop\\약품정보2.xls"

# recs = read_excel(path1, drop_if=lambda row: row['불출일자'] == '')
# recs2 = read_excel(path2, drop_if=lambda row: row['불출일자'] == '')
recs3 = read_excel(path3)
recs4 = read_excel(path4)
# recs.round_float_fields([('총량', 0), ('처방량(규격단위)', 2), ('불출량', 2)])

# for row in recs[:1]:
# 	print(row['처방량(규격단위)'])

# # print(recs.nsmallest_rows(3, ['병동', '총량']))
info = recs3.get_changes(recs4, '약품코드')
print(info.updated[0].where)
# info = recs.get_changes(recs2, ['불출일자', '병동', '약품코드'])
# recs3._put_changes(info)
# recs3.set_pk(['투여경로', '제약회사명'])
# recs.set_pk(['접수일련번호', '접수처방일련번호'])
# for row in recs:
# 	print(row['pk'])