fix report
parent
42e31b16d5
commit
9f7ed34999
|
@ -1,3 +1,5 @@
|
||||||
<form model="clinic.report.hd.case.summary">
|
<form model="clinic.report.hd.case.summary">
|
||||||
<field name="date" mode="month" span="2"/>
|
<field name="date" span="3" mode="month" onchange="onchange_date"/>
|
||||||
|
<!--<field name="date_from" span="3"/>-->
|
||||||
|
<!--<field name="date_to" span="3"/>-->
|
||||||
</form>
|
</form>
|
||||||
|
|
|
@ -60,6 +60,7 @@ from . import load_nurse_line
|
||||||
from . import report_clinic
|
from . import report_clinic
|
||||||
from . import report_visit
|
from . import report_visit
|
||||||
from . import report_hd_case_summary
|
from . import report_hd_case_summary
|
||||||
|
#from . import report_hd_case_detail
|
||||||
from . import report_medical_summary
|
from . import report_medical_summary
|
||||||
from . import report_recent_patient
|
from . import report_recent_patient
|
||||||
from . import report_discontinue_patient
|
from . import report_discontinue_patient
|
||||||
|
|
|
@ -0,0 +1,223 @@
|
||||||
|
import time
|
||||||
|
import urllib.parse as urllib
|
||||||
|
|
||||||
|
from datetime import datetime
|
||||||
|
from calendar import monthrange
|
||||||
|
from netforce.model import Model, fields, get_model
|
||||||
|
from netforce.access import get_active_company
|
||||||
|
|
||||||
|
from . import utils
|
||||||
|
|
||||||
|
class ReportHDCaseDetail(Model):
|
||||||
|
_name="clinic.report.hd.case.detail"
|
||||||
|
_string="Hemodialysis Report Detail"
|
||||||
|
_transient=True
|
||||||
|
|
||||||
|
_fields={
|
||||||
|
"date": fields.Date("Month", required=True),
|
||||||
|
"date_from": fields.Date("From", required=True),
|
||||||
|
"date_to": fields.Date("To", required=True),
|
||||||
|
}
|
||||||
|
|
||||||
|
def _get_date_from(self,context={}):
|
||||||
|
year,month=time.strftime("%Y-%m").split("-")
|
||||||
|
return '%s-%s-01'%(year,month)
|
||||||
|
|
||||||
|
def _get_date_to(self,context={}):
|
||||||
|
year,month,day=time.strftime("%Y-%m-%d").split("-")
|
||||||
|
weekday, total_day=monthrange(int(year), int(month))
|
||||||
|
return "%s-%s-%s"%(year,month,total_day)
|
||||||
|
|
||||||
|
_defaults={
|
||||||
|
'date': lambda *a: time.strftime("%Y-%m-%d"),
|
||||||
|
'date_from': _get_date_from,
|
||||||
|
'date_to': _get_date_to,
|
||||||
|
}
|
||||||
|
|
||||||
|
def get_report_data(self,ids,context={}):
|
||||||
|
company_id=get_active_company()
|
||||||
|
company=get_model("company").browse(company_id)
|
||||||
|
|
||||||
|
date=datetime.now().strftime("%Y-%m-%d")
|
||||||
|
year=int(date[0:4])
|
||||||
|
crr_month=int(date[5:7])
|
||||||
|
weekday, crr_total_day=monthrange(year, crr_month)
|
||||||
|
|
||||||
|
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)
|
||||||
|
if ids:
|
||||||
|
obj=self.browse(ids)[0]
|
||||||
|
date=obj.date
|
||||||
|
time_start='%s 00:00:00'%obj.date_from
|
||||||
|
time_stop='%s 23:59:59'%obj.date_to
|
||||||
|
year=int(date[0:4])
|
||||||
|
|
||||||
|
prev_year=year
|
||||||
|
next_year=year
|
||||||
|
prev_month=crr_month-1
|
||||||
|
next_month=crr_month+1
|
||||||
|
if crr_month==1:
|
||||||
|
prev_month=12
|
||||||
|
prev_year-=1
|
||||||
|
if crr_month==12:
|
||||||
|
next_month=1
|
||||||
|
next_year+=1
|
||||||
|
|
||||||
|
month_str=utils.MONTHS['th_TH'][crr_month]
|
||||||
|
next_month_str=utils.MONTHS['th_TH'][next_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("'","\"")
|
||||||
|
|
||||||
|
count=1
|
||||||
|
# number of hd case of this month
|
||||||
|
dom=[]
|
||||||
|
dom.append(["time_start",">=",time_start])
|
||||||
|
dom.append(["time_stop","<=",time_stop])
|
||||||
|
dom.append(["state","in",["completed","waiting_payment","paid"]])
|
||||||
|
crr_total=len(get_model("clinic.hd.case").search(dom))
|
||||||
|
items={}
|
||||||
|
items['topic%s'%count]={
|
||||||
|
'month': month_str,
|
||||||
|
'qty': crr_total or 0,
|
||||||
|
'action': 'clinic_hd_case',
|
||||||
|
'action_options': 'mode=list&search_domain=%s&tab_no=0'%replace_quote('%s'%dom),
|
||||||
|
}
|
||||||
|
count+=1
|
||||||
|
|
||||||
|
# number of patient from previous
|
||||||
|
dom=[]
|
||||||
|
weekday, prev_total_day=monthrange(prev_year, prev_month)
|
||||||
|
time_stop='%s-%s-%s'%(prev_year,str(prev_month).zfill(2),prev_total_day)
|
||||||
|
dom.append(['reg_date','<=',time_stop])
|
||||||
|
npatient=len(get_model("clinic.patient").search(dom))
|
||||||
|
dom=replace_quote('%s'%dom)
|
||||||
|
items['topic%s'%count]={
|
||||||
|
'month': prev_month_str,
|
||||||
|
'qty': npatient or 0,
|
||||||
|
'action': 'clinic_patient',
|
||||||
|
'action_options': 'mode=list&search_domain=%s'%dom,
|
||||||
|
}
|
||||||
|
count+=1
|
||||||
|
|
||||||
|
# new patient of this month
|
||||||
|
dom=[]
|
||||||
|
weekday, crr_total_day=monthrange(prev_year, crr_month)
|
||||||
|
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])
|
||||||
|
new_patients=get_model('clinic.patient').search_browse(dom)
|
||||||
|
dom=replace_quote('%s'%dom)
|
||||||
|
items['topic%s'%count]={
|
||||||
|
'month': month_str,
|
||||||
|
'qty': len(new_patients) or 0,
|
||||||
|
'action': 'clinic_patient',
|
||||||
|
'action_options': 'mode=list&search_domain=%s'%dom,
|
||||||
|
}
|
||||||
|
count+=1
|
||||||
|
|
||||||
|
# number for patient who resign for this 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(['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['topic%s'%count]={
|
||||||
|
'month': month_str,
|
||||||
|
'qty': len(resign_patients) or 0,
|
||||||
|
'action': 'clinic_patient',
|
||||||
|
'action_options': 'mode=list&search_domain=%s&tab_no=1'%dom,
|
||||||
|
}
|
||||||
|
count+=1
|
||||||
|
|
||||||
|
# all patient who are in hospital on select month
|
||||||
|
dom=[]
|
||||||
|
weekday, crr_total_day=monthrange(year, crr_month)
|
||||||
|
time_stop='%s-%s-%s'%(year,str(crr_month).zfill(2),crr_total_day)
|
||||||
|
dom.append(['reg_date','<=',time_stop])
|
||||||
|
total_patient=get_model('clinic.patient').search_browse(dom)
|
||||||
|
dom=replace_quote('%s'%dom)
|
||||||
|
items['topic%s'%count]={
|
||||||
|
'month': next_month_str,
|
||||||
|
'qty': len(total_patient) or 0,
|
||||||
|
'action': 'clinic_patient',
|
||||||
|
'action_options': 'mode=list&search_domain=%s'%dom,
|
||||||
|
}
|
||||||
|
count+=1
|
||||||
|
|
||||||
|
topics=utils.TOPICS
|
||||||
|
for ptype in get_model("clinic.patient.type").search_read([[]],['name']):
|
||||||
|
tkey='topic%s'%count
|
||||||
|
topics.update({
|
||||||
|
tkey:{
|
||||||
|
'name': ptype['name'],
|
||||||
|
'unit': 'คน',
|
||||||
|
}
|
||||||
|
})
|
||||||
|
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_id','=',ptype['id']])
|
||||||
|
npatients=get_model("clinic.patient").search(dom)
|
||||||
|
dom=replace_quote('%s'%dom)
|
||||||
|
items[tkey]={
|
||||||
|
'month': '',
|
||||||
|
'qty': len(npatients),
|
||||||
|
'action': 'clinic_patient',
|
||||||
|
'action_options': 'mode=list&search_domain=%s'%dom,
|
||||||
|
}
|
||||||
|
count+=1
|
||||||
|
|
||||||
|
lines=[]
|
||||||
|
index=1
|
||||||
|
for item in items:
|
||||||
|
topic='topic%s'%index
|
||||||
|
name=utils.TOPICS[topic]['name']
|
||||||
|
unit=utils.TOPICS[topic]['unit']
|
||||||
|
line=items[topic]
|
||||||
|
line['topic']=name
|
||||||
|
line['unit']=unit
|
||||||
|
lines.append(line)
|
||||||
|
index+=1
|
||||||
|
|
||||||
|
context['defaults']={'date': date}
|
||||||
|
|
||||||
|
medicals=get_model("clinic.report.medical.summary").get_report_data(ids=[],context=context)
|
||||||
|
year=year+543
|
||||||
|
data={
|
||||||
|
'date': date,
|
||||||
|
'month': month_str,
|
||||||
|
'year': year,
|
||||||
|
'lines': lines,
|
||||||
|
'recent_patients': get_model("clinic.report.recent.patient").get_report_data(ids=[],context=context)['lines'],
|
||||||
|
'resign_patients': get_model("clinic.report.discontinue.patient").get_report_data(ids=[],context=context)['lines'],
|
||||||
|
'medicals': medicals['lines'],
|
||||||
|
'titles': medicals['titles'],
|
||||||
|
'company_name': company.name or "",
|
||||||
|
'parent_company_name': company.parent_id.name or "",
|
||||||
|
}
|
||||||
|
return data
|
||||||
|
|
||||||
|
def onchange_date(self,context={}):
|
||||||
|
data=context['data']
|
||||||
|
date=data['date']
|
||||||
|
year,month,day=date.split("-")
|
||||||
|
weekday, total_day=monthrange(int(year), int(month))
|
||||||
|
data['date_from']="%s-%s-01"%(year,month)
|
||||||
|
data['date_to']="%s-%s-%s"%(year,month,total_day)
|
||||||
|
return data
|
||||||
|
|
||||||
|
ReportHDCaseDetail.register()
|
|
@ -15,10 +15,23 @@ class ReportHDCaseSummary(Model):
|
||||||
|
|
||||||
_fields={
|
_fields={
|
||||||
"date": fields.Date("Month", required=True),
|
"date": fields.Date("Month", required=True),
|
||||||
|
"date_from": fields.Date("From", required=True),
|
||||||
|
"date_to": fields.Date("To", required=True),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
def _get_date_from(self,context={}):
|
||||||
|
year,month=time.strftime("%Y-%m").split("-")
|
||||||
|
return '%s-%s-01'%(year,month)
|
||||||
|
|
||||||
|
def _get_date_to(self,context={}):
|
||||||
|
year,month,day=time.strftime("%Y-%m-%d").split("-")
|
||||||
|
weekday, total_day=monthrange(int(year), int(month))
|
||||||
|
return "%s-%s-%s"%(year,month,total_day)
|
||||||
|
|
||||||
_defaults={
|
_defaults={
|
||||||
'date': lambda *a: time.strftime("%Y-%m-%d"),
|
'date': lambda *a: time.strftime("%Y-%m-%d"),
|
||||||
|
'date_from': _get_date_from,
|
||||||
|
'date_to': _get_date_to,
|
||||||
}
|
}
|
||||||
|
|
||||||
def get_report_data(self,ids,context={}):
|
def get_report_data(self,ids,context={}):
|
||||||
|
@ -26,14 +39,21 @@ class ReportHDCaseSummary(Model):
|
||||||
company=get_model("company").browse(company_id)
|
company=get_model("company").browse(company_id)
|
||||||
|
|
||||||
date=datetime.now().strftime("%Y-%m-%d")
|
date=datetime.now().strftime("%Y-%m-%d")
|
||||||
|
year=int(date[0:4])
|
||||||
|
crr_month=int(date[5:7])
|
||||||
|
weekday, crr_total_day=monthrange(year, crr_month)
|
||||||
|
|
||||||
|
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)
|
||||||
if ids:
|
if ids:
|
||||||
obj=self.browse(ids)[0]
|
obj=self.browse(ids)[0]
|
||||||
date=obj.date
|
date=obj.date
|
||||||
|
time_start='%s 00:00:00'%obj.date_from
|
||||||
|
time_stop='%s 23:59:59'%obj.date_to
|
||||||
year=int(date[0:4])
|
year=int(date[0:4])
|
||||||
|
|
||||||
prev_year=year
|
prev_year=year
|
||||||
next_year=year
|
next_year=year
|
||||||
crr_month=int(date[5:7])
|
|
||||||
print('crr_month ', crr_month)
|
|
||||||
prev_month=crr_month-1
|
prev_month=crr_month-1
|
||||||
next_month=crr_month+1
|
next_month=crr_month+1
|
||||||
if crr_month==1:
|
if crr_month==1:
|
||||||
|
@ -58,9 +78,6 @@ class ReportHDCaseSummary(Model):
|
||||||
count=1
|
count=1
|
||||||
# number of hd case of this month
|
# number of hd case of this month
|
||||||
dom=[]
|
dom=[]
|
||||||
weekday, crr_total_day=monthrange(year, crr_month)
|
|
||||||
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)
|
|
||||||
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","in",["completed","waiting_payment","paid"]])
|
dom.append(["state","in",["completed","waiting_payment","paid"]])
|
||||||
|
@ -194,4 +211,13 @@ class ReportHDCaseSummary(Model):
|
||||||
}
|
}
|
||||||
return data
|
return data
|
||||||
|
|
||||||
|
def onchange_date(self,context={}):
|
||||||
|
data=context['data']
|
||||||
|
date=data['date']
|
||||||
|
year,month,day=date.split("-")
|
||||||
|
weekday, total_day=monthrange(int(year), int(month))
|
||||||
|
data['date_from']="%s-%s-01"%(year,month)
|
||||||
|
data['date_to']="%s-%s-%s"%(year,month,total_day)
|
||||||
|
return data
|
||||||
|
|
||||||
ReportHDCaseSummary.register()
|
ReportHDCaseSummary.register()
|
||||||
|
|
|
@ -58,12 +58,13 @@ class ReportMedicalSummary(Model):
|
||||||
patient_types={t['id']: t['name'] for t in get_model('clinic.patient.type').search_read([[]],['name'],order="name")}
|
patient_types={t['id']: t['name'] for t in get_model('clinic.patient.type').search_read([[]],['name'],order="name")}
|
||||||
print(patient_types)
|
print(patient_types)
|
||||||
for prod in get_model("product").search_browse([['type','=','stock']]):
|
for prod in get_model("product").search_browse([['type','=','stock']]):
|
||||||
products[prod.code]={}
|
prod_code=prod.code or ""
|
||||||
|
products[prod_code]={}
|
||||||
for patient_type_id,type_name in patient_types.items():
|
for patient_type_id,type_name in patient_types.items():
|
||||||
products[prod.code][patient_type_id]={
|
products[prod_code][patient_type_id]={
|
||||||
'qty': 0,
|
'qty': 0,
|
||||||
'name': prod.name,
|
'name': prod.name,
|
||||||
'code': prod.code,
|
'code': prod_code or "",
|
||||||
'prod_id': prod.id,
|
'prod_id': prod.id,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -71,9 +72,13 @@ class ReportMedicalSummary(Model):
|
||||||
patient_type_id=hd_case.patient_id.type_id.id
|
patient_type_id=hd_case.patient_id.type_id.id
|
||||||
for line in hd_case.lines:
|
for line in hd_case.lines:
|
||||||
prod=line.product_id
|
prod=line.product_id
|
||||||
|
prod_code=prod.code or ""
|
||||||
|
#XXX
|
||||||
|
if not prod_code or not prod.active:
|
||||||
|
continue
|
||||||
if line.type=='fee' or prod.type=='service':
|
if line.type=='fee' or prod.type=='service':
|
||||||
continue
|
continue
|
||||||
products[prod.code][patient_type_id]['qty']+=line.qty
|
products[prod_code][patient_type_id]['qty']+=line.qty
|
||||||
|
|
||||||
lines=[]
|
lines=[]
|
||||||
limit=25
|
limit=25
|
||||||
|
|
Loading…
Reference in New Issue