matching hd case

conv_bal
watcha.h 2015-02-10 19:01:46 +07:00
parent c438771dea
commit 6897215ab2
11 changed files with 242 additions and 7 deletions

View File

@ -2,7 +2,8 @@
<field name="string">Dialyzers</field>
<field name="view_cls">multi_view</field>
<field name="model">clinic.dialyzer</field>
<field name="tabs">[["All",[]],["New",[["state","=","new"]]],["Active",[["state","=","active"]]],["Drop",[["state","=","drop"]]],["Expire",[["state","=","expire"]]],["Cancelled",[["state","=","cancelled"]]]]</field>
<field name="tabs">[["All",[]],["New",[["state","=","new"]]],["Active",[["state","=","active"]]],["Drop",[["state","=","drop"]]],["Expire",[["state","=","expire"]]]]</field>
<field name="modes">list,page,form</field>
<field name="menu">clinic_menu</field>
<field name="limit">25</field>
</action>

View File

@ -0,0 +1,8 @@
<action>
<field name="string">Matching HDCase</field>
<field name="view_cls">report</field>
<field name="model">clinic.matching.hdcase</field>
<field name="report_template">matching_hdcase</field>
<field name="report_template_xls">matching_hdcase</field>
<field name="menu">clinic_menu</field>
</action>

View File

@ -29,7 +29,6 @@
<template>
<div><b>Note:</b> 'Use time' will count automatic after finish HD Case.</div>
</template>
<!--<separator string="Note: 'Use time' will count automatic after finish HD Case."/>-->
</group>
<foot>
<button string="Validate" type="success" states="new" method="validate"/>

View File

@ -0,0 +1,4 @@
<form model="clinic.matching.hdcase">
<field name="date" span="2"/>
<field name="file" span="3"/>
</form>

View File

@ -48,7 +48,7 @@
<item string="Sickbed" action="clinic_sickbed"/>
<divider/>
<header string="OTHERS"/>
<item string="Matching HD Case" action="clinic_matching_hd_case"/>
<item string="Matching HD Case" action="clinic_matching_hdcase"/>
</item>
<item string="Reporting" perm="clinic_report">
<item string="Visit Summary" action="clinic_report_visit"/>

View File

@ -99,6 +99,7 @@ from . import product_categ
from . import make_apt
from . import make_apt_line
from . import matching_payment
from . import matching_hdcase
from . import shop
from . import shop_line
from . import sale_order

View File

@ -0,0 +1,183 @@
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"
_transient=True
_fields={
"date": fields.Date("Date", required=True),
'file': fields.File("File"),
}
def _get_date(self,context={}):
return time.strftime("%Y-%m-%d")
_defaults={
'date': _get_date,
}
def get_rows(self,fpath=None):
if not fpath:
raise Exception("File not found")
try:
# or codecs.open on Python 2
filedata = open(fpath, encoding='UTF-8').read()
except:
filedata = open(fpath, encoding='TIS-620').read()
lines=filedata.split("\n")
count=0
rows=[]
for line in lines:
#open
if '***' in line and count==0:
count+=1
#end
elif '***' in line and count==1:
count=0
#table content
if count==1:
line=line.replace("*","")
line=line.replace("|","")
i=0
vals={}
for l in line.split(","):
if l:
vals[i]=l
i+=1
# only right data
if vals:
if len(vals)>1:
rows.append(vals)
return rows
def get_report_data(self,ids,context={}):
lines=[]
hdcases={}
if ids:
obj=self.browse(ids)[0]
if obj.file:
fpath=get_file_path(obj.file)
rows=self.get_rows(fpath)
if not rows:
raise Exception("No Data")
#{0: ' A 01',
#1: ' 6',
#2: ' 11686',
#3: ' 91312851',
#4: ' 450124497',
#5: ' 27/01/2558 06:05:00',
#6: ' C',
#7: ' O',
#8: ' U ',
#9: ' N',
#10: ' Espogen',
#11: ' 4000',
#12: ' 30',
#13: ' 1',
#14: ' 0',
#15: ' 1500',
#16: ' 1500',
#17: ' 0',
#18: ' 1500',
#19: ' S',
#20: ' U '}
patients={}
for pt in get_model("clinic.patient").search_read([],['name','hn_no']):
hn=pt['hn_no']
patients[hn]={
'id': pt['id'],
'name': pt['name'] or '',
}
products={}
for prod in get_model("product").search_read([],['name']):
name=(prod['name'] or "").replace(" ", "")
name=name.upper()
products[name]=prod['id']
dom=[]
dom.append(['date',">=",obj.date])
dom.append(['date',"<=",obj.date])
dom.append(['state','!=','cancelled'])
hdcases={}
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
for line in hdcase.lines:
prod=line.product_id
categ=prod.categ_id
prod_line=[]
if categ:
if categ.code=='EPO':
prod_line.append(prod.name)
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]={
'id': hdcase.id,
'number': hdcase.number or ''
}
for row in rows:
vals=list(row.values())
date,time=(vals[5] or "").split()
if len(date)<3:
raise Exception("Wrong format date")
d,m,y=date.split("/")
y=int(y)-543
date='%s-%s-%s'%(y,m,d)
hn=vals[3]
hn=''.join(x for x in (hn or "") if x.isdigit())
pt=patients.get(hn)
pt_name=''
pt_id=None
if pt:
pt_name=pt['name']
pt_id=pt['id']
hct=vals[12] or 0
fee_amt=float(vals[15] or "0")
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={
'hn': hn,
'date': date,
'patient_name': pt_name,
'patient_id': pt_id,
'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,
}
lines.append(vals)
no=1
lines2=[]
for line in sorted(lines,key=lambda x: x['hn']):
line['no']=no
lines2.append(line)
no+=1
lines=lines2
data={
'lines': lines,
}
return data
MatchingHDCase.register()

View File

@ -108,10 +108,10 @@ class ClinicSetting(Model):
if user_id !=1:
print("Only admin!!")
return
for hdi in get_model("clinic.hd.case.dialyzer").search_browse([]):
dlz=hdi.dialyzer_id
hdi.write({
'membrane_type': dlz.membrane_type,
for pt in get_model("clinic.patient").search_browse([]):
hn=''.join(x for x in (pt.number or "") if x.isdigit())
pt.write({
'hn_no': hn,
})
print("Done! ")

Binary file not shown.

View File

@ -98,6 +98,9 @@
<div>
<a href="#name=clinic_sickbed">{{t "Sickbed"}}</a>
</div>
<div>
<a href="#name=clinic_matching_hdcase">{{t "Matching HD Cases"}}</a>
</div>
</div>
</div>
</div>

View File

@ -0,0 +1,36 @@
<table class="table table-condensed table-striped">
<thead>
<th>#</th>
<th>Date</th>
<th>HN</th>
<th>Patient</th>
<th>HCT</th>
<th>Product</th>
<th>Fee Amount</th>
<th>HD Case</th>
</thead>
<tbody>
{{#each lines }}
<tr>
<td>{{no}}</td>
<td>{{date}}</td>
<td>{{hn}}</td>
<td>{{patient_name}}</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>
{{else}}
<td>{{hd_case_number}}</td>
{{/if}}
</tr>
{{/each}}
</tbody>
<tfoot>
</tfoot>
</table>