matching hdcase

conv_bal
watcha.h 2015-02-10 23:08:38 +07:00
parent 6897215ab2
commit 7a979d17bd
3 changed files with 65 additions and 32 deletions

View File

@ -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

View File

@ -4,10 +4,12 @@
<th>Date</th>
<th>HN</th>
<th>Patient</th>
<th>Type</th>
<th>HCT</th>
<th>Product</th>
<th>EPO</th>
<th>Fee Amount</th>
<th>HD Case</th>
<th>Note (fmt: date,hn,hct,epo,fee)</th>
</thead>
<tbody>
{{#each lines }}
@ -15,19 +17,29 @@
<td>{{no}}</td>
<td>{{date}}</td>
<td>{{hn}}</td>
<td>{{patient_name}}</td>
{{#if patient_id}}
<td style="width:15%;">{{view "link" string=patient_name action="clinic_patient" action_options="mode=form" active_id=patient_id}}</td>
{{else}}
<td style="width: 15%">{{patient_name}}</td>
{{/if}}
<td>{{patient_type}}</td>
<td>{{hct}}</td>
{{#if prod_id}}
<td>{{view "link" string=prod_name action="product" action_options="mode=form" active_id=prod_id}}</td>
{{else}}
<td>{{prod_name}}</td>
{{/if}}
<td>{{fee_amt}}</td>
{{#if hd_case_id}}
<td style="background-color;#4daa35;color:white">{{view "link" string=hd_case_number action="clinic_hd_case" action_options="mode=form" active_id=hd_case_id}}</td>
<td>{{currency fee_amt zero=""}}</td>
{{#if is_match}}
<td style="background-color:#4daa35;width:8%;">
<a style="color:white" href="/ui#name=clinic_hd_case&mode=form&active_id={{hd_case_id}}">{{hd_case_number}}</a>
</td>
{{else}}
<td>{{hd_case_number}}</td>
<td style="background-color:#b9b9b7;width:8%;">
<a style="color:white" href="/ui#name=clinic_hd_case&mode=form&active_id={{hd_case_id}}">{{hd_case_number}}</a>
</td>
{{/if}}
<td>{{note}}</td>
</tr>
{{/each}}
</tbody>