report hd summary

conv_bal
watcha.h 2014-11-10 12:10:39 +07:00
parent 0613851962
commit c933fb1280
9 changed files with 130 additions and 59 deletions

View File

@ -1,5 +1,5 @@
<action> <action>
<field name="string">HD Report Summary</field> <field name="string">HD Case Report Summary</field>
<field name="view_cls">report</field> <field name="view_cls">report</field>
<field name="model">clinic.report.hd.case.summary</field> <field name="model">clinic.report.hd.case.summary</field>
<field name="report_template">report_hd_case_summary</field> <field name="report_template">report_hd_case_summary</field>

View File

@ -4,4 +4,5 @@
<field name="time_stop"/> <field name="time_stop"/>
<field name="patient_id"/> <field name="patient_id"/>
<field name="cycle_id"/> <field name="cycle_id"/>
<field name="state"/>
</search> </search>

View File

@ -88,6 +88,7 @@
<tab string="Note"> <tab string="Note">
<field name="note" nolabel="1"/> <field name="note" nolabel="1"/>
<field name="active"/> <field name="active"/>
<field name="resign_date" readonly="1"/>
</tab> </tab>
</tabs> </tabs>
<related> <related>

View File

@ -6,6 +6,7 @@
<field name="hn"/> <field name="hn"/>
<field name="name"/> <field name="name"/>
<field name="reg_date"/> <field name="reg_date"/>
<field name="resign_date"/>
<field name="categ_id"/> <field name="categ_id"/>
<field name="type"/> <field name="type"/>
</list> </list>

View File

@ -1,5 +1,3 @@
<form model="clinic.report.medical.summary"> <form model="clinic.report.medical.summary">
<group> <field name="date" mode="month" span="3"/>
<field name="date" span="3"/>
</group>
</form> </form>

View File

@ -76,11 +76,12 @@ class Patient(Model):
"hd_cases": fields.One2Many("clinic.hd.case","patient_id","HD Cases"), "hd_cases": fields.One2Many("clinic.hd.case","patient_id","HD Cases"),
"partner_id": fields.Many2One("partner","Contact"), "partner_id": fields.Many2One("partner","Contact"),
"dialyzers": fields.One2Many("clinic.dialyzer","patient_id","Dialyzers"), "dialyzers": fields.One2Many("clinic.dialyzer","patient_id","Dialyzers"),
"active":fields.Boolean("Mark as discountinue"), "active":fields.Boolean("Uncheck as discountinue", search=True),
'note': fields.Text("Note"), 'note': fields.Text("Note"),
'categ_id': fields.Many2One("clinic.patient.categ","Category"), 'categ_id': fields.Many2One("clinic.patient.categ","Category"),
'doctor_id': fields.Many2One("clinic.personal","Doctor",domain=[['type','=','doctor']]), 'doctor_id': fields.Many2One("clinic.personal","Doctor",domain=[['type','=','doctor']]),
"documents": fields.One2Many("document","related_id","Documents"), "documents": fields.One2Many("document","related_id","Documents"),
'resign_date': fields.Date("Resign Date"),
} }
def _get_number(self,context={}): def _get_number(self,context={}):
@ -197,6 +198,9 @@ class Patient(Model):
super().delete(ids) super().delete(ids)
def write(self,ids,vals,**kw): def write(self,ids,vals,**kw):
if 'active' in vals.keys():
if not vals['active']:
vals['resign_date']=time.strftime("%Y-%m-%d")
for obj in self.browse(ids): for obj in self.browse(ids):
partner_id=obj.partner_id partner_id=obj.partner_id
if not partner_id: if not partner_id:

View File

@ -1,4 +1,5 @@
import time import time
import urllib.parse as urllib
from datetime import datetime from datetime import datetime
from calendar import monthrange from calendar import monthrange
@ -47,103 +48,140 @@ class ReportHDCaseSummary(Model):
next_month_str=utils.MONTHS['th_TH'][next_month] next_month_str=utils.MONTHS['th_TH'][next_month]
prev_month_str=utils.MONTHS['th_TH'][prev_month] prev_month_str=utils.MONTHS['th_TH'][prev_month]
def encode_url(dom):
dom='%s'%dom
dom=urllib.quote(dom.encode('utf-8'))
return dom
def replace_quote(dom=""):
return dom.replace("'","\"")
# number of hd case of this month # number of hd case of this month
dom=[] dom=[]
weekday, crr_total_day=monthrange(year, crr_month) weekday, crr_total_day=monthrange(year, crr_month)
time_start='%s-%s-01 00:00:00'%(year,str(crr_month).zfill(2)) time_start='%s-%s-01 00:00:00'%(year,str(crr_month).zfill(2))
time_stop='%s-%s-%s 23:59:59'%(year,str(crr_month).zfill(2),crr_total_day) time_stop='%s-%s-%s 23:59:59'%(year,str(crr_month).zfill(2),crr_total_day)
dom.append(['time_start','>=', time_start]) dom.append(["time_start",">=",time_start])
dom.append(['time_stop','<=',time_stop]) dom.append(["time_stop","<=",time_stop])
dom.append(['state','=','completed']) dom.append(["state","=","completed"])
crr_total=len(get_model("clinic.hd.case").search(dom)) crr_total=len(get_model("clinic.hd.case").search(dom))
items={} items={}
items['topic1']={ items['topic1']={
'month': month_str, 'month': month_str,
'amount': crr_total, 'qty': crr_total or 0,
'date_from': time_start[0:10], 'action': 'clinic_hd_case',
'date_to': time_stop[0:10], 'action_options': 'mode=list&search_domain=%s'%replace_quote('%s'%dom),
'link': True,
} }
# number patient from previous month # number of patient from previous
dom=[] dom=[]
weekday, prev_total_day=monthrange(prev_year, prev_month) weekday, prev_total_day=monthrange(prev_year, prev_month)
#time_start='%s-%s-01'%(prev_year,str(prev_month).zfill(2))
time_stop='%s-%s-%s'%(prev_year,str(prev_month).zfill(2),prev_total_day) time_stop='%s-%s-%s'%(prev_year,str(prev_month).zfill(2),prev_total_day)
#dom.append(['reg_date','>=', time_start])
dom.append(['reg_date','<=',time_stop]) dom.append(['reg_date','<=',time_stop])
npatient=len(get_model("clinic.patient").search(dom)) npatient=len(get_model("clinic.patient").search(dom))
dom=replace_quote('%s'%dom)
items['topic2']={ items['topic2']={
'month': prev_month_str, 'month': prev_month_str,
'amount': npatient or 0.0, 'qty': npatient or 0,
'date_from': '', 'action': 'clinic_patient',
'date_to': '', 'action_options': 'mode=list&search_domain=%s'%dom,
'link': False,
} }
# new patient of this month # new patient of this month
dom=[] dom=[]
weekday, crr_total_day=monthrange(prev_year, crr_month) weekday, crr_total_day=monthrange(prev_year, crr_month)
time_start='%s-%s-01 00:00:00'%(year,str(crr_month).zfill(2)) time_start='%s-%s-01'%(year,str(crr_month).zfill(2))
time_stop='%s-%s-%s 23:59:59'%(year,str(crr_month).zfill(2),crr_total_day) time_stop='%s-%s-%s'%(year,str(crr_month).zfill(2),crr_total_day)
new_patients=db.query("select id, name, note from clinic_patient where active=true and create_time >=%s and create_time <=%s and company_id=%s",time_start,time_stop,company_id) dom.append(['reg_date','>=',time_start])
dom.append(['reg_date','<=',time_stop])
new_patients=get_model('clinic.patient').search_browse(dom)
dom=replace_quote('%s'%dom)
items['topic3']={ items['topic3']={
'month': month_str, 'month': month_str,
'amount': len(new_patients) or 0.0, 'qty': len(new_patients) or 0,
'date_from': '', 'action': 'clinic_patient',
'date_to': '', 'action_options': 'mode=list&search_domain=%s'%dom,
'link': False,
} }
# number for patient who resign for this month # number for patient who resign for this month
time_start='%s-%s-01 00:00:00'%(year,str(crr_month).zfill(2)) dom=[]
time_stop='%s-%s-%s 23:59:59'%(year,str(crr_month).zfill(2),crr_total_day) time_start='%s-%s-01'%(year,str(crr_month).zfill(2))
resign_patients=db.query("select id, name, note from clinic_patient where active=false and write_time >=%s and write_time <=%s and company_id=%s",time_start,time_stop,company_id) time_stop='%s-%s-%s'%(year,str(crr_month).zfill(2),crr_total_day)
dom.append(['resign_date','>=',time_start])
dom.append(['resign_date','<=',time_stop])
dom.append(['active','=',False])
resign_patients=get_model('clinic.patient').search_browse(dom)
del dom[-1]
dom=replace_quote('%s'%dom)
items['topic4']={ items['topic4']={
'month': month_str, 'month': month_str,
'amount': len(resign_patients) or 0.0, 'qty': len(resign_patients) or 0,
'date_from': '', 'action': 'clinic_patient',
'date_to': '', 'action_options': 'mode=list&search_domain=%s&tab_no=1'%dom,
'link': False,
} }
# all patient who are in hospital now
# all patient who are in hospital on select month
dom=[] dom=[]
weekday, crr_total_day=monthrange(year, crr_month) weekday, crr_total_day=monthrange(year, crr_month)
time_stop='%s-%s-%s'%(year,str(crr_month).zfill(2),crr_total_day) time_stop='%s-%s-%s'%(year,str(crr_month).zfill(2),crr_total_day)
npatients=db.query("select id, name, note from clinic_patient where active=true and reg_date <=%s and company_id=%s",time_stop,company_id) dom.append(['reg_date','<=',time_stop])
total_patient=get_model('clinic.patient').search_browse(dom)
dom=replace_quote('%s'%dom)
items['topic5']={ items['topic5']={
'month': next_month_str, 'month': next_month_str,
'amount': len(npatients), 'qty': len(total_patient) or 0,
'date_from': '', 'action': 'clinic_patient',
'date_to': '', 'action_options': 'mode=list&search_domain=%s'%dom,
'link': False,
} }
npatients=get_model("clinic.patient").search([['type','=','sc']]) # all patient who are sc in hospital on select month
dom=[]
time_start='%s-%s-01'%(year,str(crr_month).zfill(2))
time_stop='%s-%s-%s'%(year,str(crr_month).zfill(2),crr_total_day)
dom.append(['reg_date','>=',time_start])
dom.append(['reg_date','<=',time_stop])
dom.append(['type','=','sc'])
npatients=get_model("clinic.patient").search(dom)
dom=replace_quote('%s'%dom)
items['topic6']={ items['topic6']={
'month': '', 'month': '',
'amount': len(npatients), 'qty': len(npatients),
'date_from': '', 'action': 'clinic_patient',
'date_to': '', 'action_options': 'mode=list&search_domain=%s&tab_no=2'%dom,
'link': False,
} }
npatients=get_model("clinic.patient").search([['type','=','nhso']])
# all patient who are nhso in hospital on select month
dom=[]
time_start='%s-%s-01'%(year,str(crr_month).zfill(2))
time_stop='%s-%s-%s'%(year,str(crr_month).zfill(2),crr_total_day)
dom.append(['reg_date','>=',time_start])
dom.append(['reg_date','<=',time_stop])
dom.append(['type','=','nhso'])
npatients=get_model("clinic.patient").search(dom)
dom=replace_quote('%s'%dom)
items['topic7']={ items['topic7']={
'month':'', 'month':'',
'amount': len(npatients), 'qty': len(npatients),
'date_from': '', 'action': 'clinic_patient',
'date_to': '', 'action_options': 'mode=list&search_domain=%s&tab_no=3'%dom,
'link': False,
} }
npatients=get_model("clinic.patient").search([['type','in',['personal','others']]])
# all patient who are other in hospital on select month
dom=[]
time_start='%s-%s-01'%(year,str(crr_month).zfill(2))
time_stop='%s-%s-%s'%(year,str(crr_month).zfill(2),crr_total_day)
dom.append(['reg_date','>=',time_start])
dom.append(['reg_date','<=',time_stop])
dom.append(['type','=','personal'])
npatients=get_model("clinic.patient").search(dom)
dom=replace_quote('%s'%dom)
items['topic8']={ items['topic8']={
'month': '', 'month': '',
'amount': len(npatients), 'qty': len(npatients),
'date_from': '', 'action': 'clinic_patient',
'date_to': '', 'action_options': 'mode=list&search_domain=%s&tab_no=4'%dom,
'link': False,
} }
lines=[] lines=[]
index=1 index=1
for item in items: for item in items:

View File

@ -1,7 +1,9 @@
import time import time
from calendar import monthrange
from netforce.model import Model,fields,get_model from netforce.model import Model,fields,get_model
from netforce.access import get_active_company from netforce.access import get_active_company
from . import utils
class ReportMedicalSummary(Model): class ReportMedicalSummary(Model):
_name="clinic.report.medical.summary" _name="clinic.report.medical.summary"
@ -17,7 +19,29 @@ class ReportMedicalSummary(Model):
} }
def get_report_data(self,ids,context={}): def get_report_data(self,ids,context={}):
obj=self.browse(ids)[0] date=time.strftime("%Y-%m-%d")
defaults=context.get('defaults')
if defaults:
date=defaults['date']
year=int(date[0:4])
month=int(date[5:7])
weekday, total_day=monthrange(year, month)
dom=[]
dom.append([['state','=','completed']])
dom.append([['time_start','>=','%s-%s-01 00:00:00'%(year,month)]])
dom.append([['time_stop','<=','%s-%s-%s 23:59:59'%(year,month,total_day)]])
print("dom ", dom)
products=[]
for hd_case in get_model('clinic.hd.case').search_browse(dom):
print("="*30)
for line in hd_case.lines:
prod=line.product_id
if line.type=='fee':
continue
if prod.type=='service':
continue
company_id=get_active_company() company_id=get_active_company()
company=get_model('company').browse(company_id) company=get_model('company').browse(company_id)

View File

@ -23,10 +23,14 @@
<td>{{topic}}</td> <td>{{topic}}</td>
<td>{{month}}</td> <td>{{month}}</td>
<td>เท่ากับ</td> <td>เท่ากับ</td>
{{#if link}} {{#if qty}}
<td><a style="text-decoration: underline" href="ui#name=clinic_report_hd_case_detail&defaults.date_from={{date_from}}&defaults.date_to={{date_to}}" >{{amount}}</a></td> <td>
{{view "link" string=qty action=action action_options=action_options}}
</td>
{{else}} {{else}}
<td>{{amount}}</td> <td>
0
</td>
{{/if}} {{/if}}
<td>{{unit}}</td> <td>{{unit}}</td>
</tr> </tr>