示例#1
0
def parse_narc_content(content, n=0, to_queryset=False):
    soup = BeautifulSoup(content, 'html.parser')
    recs = RecordParser(records=[
        OrderedDict((child.name, child.text) for child in table.children)
        for table in soup.find_all('table1')
    ],
                        drop_if=lambda row: not row.get('narct_owarh_ymd') or
                        row['drug_cd'] not in drugDB or not row.get('ptnt_no'))

    recs.select([
        'narct_owarh_ymd', 'ward', 'ori_ord_ymd', 'ord_no', 'ptnt_no',
        'ptnt_nm', 'drug_cd', 'drug_nm', 'ord_qty_std', 'tot_qty',
        'get_dept_nm'
    ],
                where=lambda row: row['ret_gb'] not in ['D/C', '반납', '수납취소'])
    recs.vlookup(drugDB.values(), 'drug_cd', 'code', [('amount', 0),
                                                      ('amount_unit', ''),
                                                      ('name', ""),
                                                      ('std_unit', "")])
    recs.format([('tot_qty', 0.0), ('ord_qty_std', 0.0)])
    recs.add_column([('잔량', lambda row: row['tot_qty'] - row['ord_qty_std']),
                     ('폐기량', lambda row: row['잔량'] * row['amount'])])
    recs.update([('잔량', lambda row: round(row['잔량'], 2)),
                 ('폐기량', lambda row: round(row['폐기량'], 2))])

    recs.select('*', where=lambda row: row['잔량'] > 0).order_by(
        ['name', 'narct_owarh_ymd', 'ward'])
    if len(recs.records) == 0:
        return [], []
    recs.rename([('narct_owarh_ymd', '불출일자'), ('ori_ord_ymd', '원처방일자'),
                 ('ord_no', '처방번호[묶음]'), ('tot_qty', '집계량'), ('name', '폐기약품명'),
                 ('drug_cd', '약품코드'), ('amount', '집계량'),
                 ('ord_qty_std', '처방량(규격단위)'), ('drug_nm', '약품명'),
                 ('amount_unit', '폐기단위'), ('ptnt_nm', '환자명'),
                 ('ptnt_no', '환자번호'), ('std_unit', '규격단위'), ('ward', '병동')])
    table = recs.select([
        '불출일자', '병동', '환자번호', '환자명', '폐기약품명', '약품코드', '처방량(규격단위)', '잔량',
        '규격단위', '폐기량', '폐기단위', 'get_dept_nm'
    ])
    table.add_column([('ord_amt', lambda row: row['처방량(규격단위)'])])
    if to_queryset == False:
        table = table.to2darry()

    grp = recs.group_by(
        columns=['폐기약품명'],
        aggset=[('폐기량', sum, '폐기량__sum'), ('폐기약품명', len, '폐기약품명__len')],
        selects=['폐기약품명', '폐기약품명__len', '규격단위', '폐기량__sum', '폐기단위', '약품코드'],
        inplace=False)
    # grp = map(lambda row: round(row['폐기량__sum'], 2), grp)
    for row in grp:
        row['폐기량__sum'] = round(row['폐기량__sum'], 2)

    return table[n:], grp
示例#2
0
def parse_opstock_content(content, drop_if=lambda row: False):
	soup = BeautifulSoup(content, 'html.parser')
	recs = RecordParser(
		records = [OrderedDict((child.name, child.text) for child in table.children) for table in soup.find_all('table1')],
		drop_if = drop_if
	)
	recs.format([('stock_qty', 0.0)])
	recs.update([('drug_nm', get_std_name), ('drug_cd', code_with_count)])
	recs.group_by(
		columns = ['drug_nm'], 
		aggset = [('stock_qty', sum, 'stock')], 
		selects = ['drug_cd', 'drug_nm', 'stock', 'stock_unit']
	)
	recs.update([('stock', lambda row: row['stock'] if int(row['stock'])!=row['stock'] else int(row['stock']) )])
	return recs.records