diff --git a/netforce_clinic/models/matching_hdcase.py b/netforce_clinic/models/matching_hdcase.py index 97574b2..de91247 100644 --- a/netforce_clinic/models/matching_hdcase.py +++ b/netforce_clinic/models/matching_hdcase.py @@ -1,9 +1,7 @@ import time -from calendar import monthrange from netforce.model import Model, fields, get_model from netforce.utils import get_file_path -from . import utils class MatchingHDCase(Model): _name="clinic.matching.hdcase" @@ -57,10 +55,11 @@ class MatchingHDCase(Model): return rows def get_report_data(self,ids,context={}): - lines=[] hdcases={} + date=time.strftime("%Y-%m-%d") if ids: obj=self.browse(ids)[0] + date=obj.date if obj.file: fpath=get_file_path(obj.file) rows=self.get_rows(fpath) @@ -89,11 +88,12 @@ class MatchingHDCase(Model): #20: ' U '} patients={} - for pt in get_model("clinic.patient").search_read([],['name','hn_no']): + for pt in get_model("clinic.patient").search_read([],['name','hn_no','type_id']): hn=pt['hn_no'] patients[hn]={ 'id': pt['id'], 'name': pt['name'] or '', + 'type': pt['type_id'][1], } products={} for prod in get_model("product").search_read([],['name']): @@ -105,28 +105,40 @@ class MatchingHDCase(Model): dom.append(['date',"<=",obj.date]) dom.append(['state','!=','cancelled']) hdcases={} + hdcases2={} for hdcase in get_model("clinic.hd.case").search_browse(dom): date=hdcase.date hn=hdcase.patient_id.hn_no or 0 fee_amt=0 + hct=hdcase.hct or "0" + hct=round(float(hct),2) + prod_line=[] for line in hdcase.lines: prod=line.product_id categ=prod.categ_id - prod_line=[] - if categ: + if categ and line.reimbursable=='yes': if categ.code=='EPO': - prod_line.append(prod.name) + prod_line.append((prod.name or "").upper()) elif categ.code=='FEE': fee_amt=line.amount or 0 prod_name=','.join(prod_line) - key='%s-%s-%s-%s'%(date,hn,prod_name,fee_amt) - hdcases[key]={ + key1='%s-%s-%s-%s-%s'%(date,hn,hct,prod_name,fee_amt) + hdcases[key1]={ 'id': hdcase.id, - 'number': hdcase.number or '' + 'number': hdcase.number or '', + 'note': '', } + key2='%s-%s'%(date,hn) + hdcases2[key2]={ + 'id': hdcase.id, + 'number': hdcase.number or '', + 'note': '%s, %s, %s, %s, %s'%(date,hn,hct,prod_name,fee_amt), + } + + lines=[] for row in rows: vals=list(row.values()) - date,time=(vals[5] or "").split() + date,_time=(vals[5] or "").split() if len(date)<3: raise Exception("Wrong format date") d,m,y=date.split("/") @@ -135,39 +147,47 @@ class MatchingHDCase(Model): hn=vals[3] hn=''.join(x for x in (hn or "") if x.isdigit()) pt=patients.get(hn) + pt_type='' pt_name='' pt_id=None if pt: pt_name=pt['name'] pt_id=pt['id'] - hct=vals[12] or 0 + pt_type=pt['type'] + hct=float(vals[12] or "0") + hct=round(hct,2) fee_amt=float(vals[15] or "0") + fee_amt=round(fee_amt,2) prod_name=vals[10] or '' prod_name=prod_name.replace(" ", "") prod_id=products.get(prod_name.upper(),None) - hd_case_id=None - hd_case_number="" - key='%s-%s-%s-%s'%(date,hn,prod_name,fee_amt) - if hn=='10073353': - print('key ', key) - #import pdb; pdb.set_trace() - hdcase=hdcases.get(key) - if hdcase: - hd_case_id=hdcase['id'] - hd_case_number=hdcase['number'] - vals={ + key1='%s-%s-%s-%s-%s'%(date,hn,hct,prod_name.upper(),fee_amt) + hdcase=hdcases.get(key1) + line_vals={ 'hn': hn, 'date': date, 'patient_name': pt_name, 'patient_id': pt_id, + 'patient_type': pt_type, 'hct': hct, 'prod_name': prod_name, 'prod_id': prod_id, 'fee_amt': fee_amt, - 'hd_case_id': hd_case_id, - 'hd_case_number': hd_case_number, + 'note': '', } - lines.append(vals) + if hdcase: + line_vals['is_match']=True + line_vals['hd_case_id']=hdcase['id'] + line_vals['hd_case_number']=hdcase['number'] + else: + key2='%s-%s'%(date,hn) + hdcase2=hdcases2.get(key2) + if hdcase2: + line_vals['is_match']=False + line_vals['hd_case_id']=hdcase2['id'] + line_vals['hd_case_number']=hdcase2['number'] + line_vals['note']=hdcase2['note'] + lines.append(line_vals) no=1 lines2=[] for line in sorted(lines,key=lambda x: x['hn']): @@ -177,6 +197,7 @@ class MatchingHDCase(Model): lines=lines2 data={ 'lines': lines, + 'date': date, } return data diff --git a/netforce_clinic/reports/matching_hdcase.xlsx b/netforce_clinic/reports/matching_hdcase.xlsx index e09487c..33e8a9a 100644 Binary files a/netforce_clinic/reports/matching_hdcase.xlsx and b/netforce_clinic/reports/matching_hdcase.xlsx differ diff --git a/netforce_clinic/templates/matching_hdcase.hbs b/netforce_clinic/templates/matching_hdcase.hbs index 733b325..7b13dff 100644 --- a/netforce_clinic/templates/matching_hdcase.hbs +++ b/netforce_clinic/templates/matching_hdcase.hbs @@ -4,10 +4,12 @@ Date HN Patient + Type HCT - Product + EPO Fee Amount HD Case + Note (fmt: date,hn,hct,epo,fee) {{#each lines }} @@ -15,19 +17,29 @@ {{no}} {{date}} {{hn}} - {{patient_name}} + {{#if patient_id}} + {{view "link" string=patient_name action="clinic_patient" action_options="mode=form" active_id=patient_id}} + {{else}} + {{patient_name}} + {{/if}} + {{patient_type}} {{hct}} {{#if prod_id}} {{view "link" string=prod_name action="product" action_options="mode=form" active_id=prod_id}} {{else}} {{prod_name}} {{/if}} - {{fee_amt}} - {{#if hd_case_id}} - {{view "link" string=hd_case_number action="clinic_hd_case" action_options="mode=form" active_id=hd_case_id}} + {{currency fee_amt zero=""}} + {{#if is_match}} + + {{hd_case_number}} + {{else}} - {{hd_case_number}} + + {{hd_case_number}} + {{/if}} + {{note}} {{/each}}