report hd case summary (revise) 2

art
saharat.i@netforce.co.th 2017-11-28 15:48:52 +07:00
parent 59b0427b6a
commit 392e04f932
10 changed files with 206 additions and 123 deletions

View File

@ -1,6 +1,7 @@
<form model="clinic.patient.move"> <form model="clinic.patient.move">
<field name="date"/> <field name="date"/>
<field name="patient_id"/> <field name="patient_id"/>
<field name="type_id"/>
<field name="type"/> <field name="type"/>
<field name="patient_name"/> <field name="patient_name"/>
<field name="patient_type"/> <field name="patient_type"/>

View File

@ -16,3 +16,4 @@ from . import clinic_setting
#from . import add_missing_dlz # pending #from . import add_missing_dlz # pending
#from . import validate_cycle_item #from . import validate_cycle_item
from . import update_line_amount from . import update_line_amount
from . import add_patient_moves

View File

@ -0,0 +1,66 @@
import time
from netforce.model import get_model
from netforce import migration
from netforce.access import set_active_user, get_active_user, set_active_company, get_active_company
from netforce.database import get_connection
class Migration(migration.Migration):
_name="clinic.patient.move"
_version="2.12.7"
def migrate(self):
set_active_company(1)
set_active_user(1)
user_id=get_active_user()
company_id=get_active_company()
count_out=0
count_in=0
db=get_connection()
vals=[]
for patient in get_model("clinic.patient").search_browse([]):
count_out=0
count_in=0
date_str=""
time_tuple=""
if patient.dispose==True:
if not patient.resign_date:
#time_tuple=lambda *a: time.strftime("%Y-%m-%d %H:%M:%S")
time_tuple = lambda *a: time.strftime("%Y-%m-%d")
else:
date_str = patient.resign_date
time_tuple = lambda *a: time.strptime(date_str, "%Y-%m-%d")
line_vals={
"patient_id": patient.id,
"patient_name": "%s %s"% (patient.first_name or "",patient.last_name or ""),
"patient_type": patient.type_id.name,
"type": "out",
"type_id": patient.type_id.id,
"date": date_str,
#"location_from_id": obj.location,
#"location_to_id": obj.location,
}
db.execute("""
insert INTO clinic_patient_move (patient_id,patient_name,patient_type,type_id,type,date,create_time,create_uid) VALUES (%d,'%s','%s',%d,'%s','%s',CURRENT_DATE,%d);
"""%(line_vals.get('patient_id'),line_vals.get('patient_name'),line_vals.get('patient_type'),line_vals.get('type_id'),line_vals.get('type'),line_vals.get('date'),user_id))
print("insert INTO clinic.patient.move ('OUT'): %s , %s , %s"%(line_vals.get('patient_name'),line_vals.get('type'),line_vals.get('date')))
date_str = patient.reg_date
time_tuple = lambda *a: time.strptime(date_str, "%Y-%m-%d")
line_vals={
"patient_id": patient.id,
"patient_name": "%s %s"% (patient.first_name or "",patient.last_name or ""),
"patient_type": patient.type_id.name,
"type": "in",
"type_id": patient.type_id.id,
"date": date_str,
#"location_from_id": obj.location,
#"location_to_id": obj.location,
}
db.execute("""
insert INTO clinic_patient_move (patient_id,patient_name,patient_type,type_id,type,date,create_time,create_uid) VALUES (%d,'%s','%s',%d,'%s','%s',CURRENT_DATE,%d);
"""%(line_vals.get('patient_id'),line_vals.get('patient_name'),line_vals.get('patient_type'),line_vals.get('type_id'),line_vals.get('type'),line_vals.get('date'),user_id))
print("insert INTO clinic.patient.move ('IN'): %s , %s , %s"%(line_vals.get('patient_name'),line_vals.get('type'),line_vals.get('date')))
#set_active_user(user_id)
return True
Migration.register()

View File

@ -330,11 +330,13 @@ class Patient(Model):
}) })
#TODO create patient.move #TODO create patient.move
if obj.walkin=="no":
patient_move={ patient_move={
"patient_id": obj.id, "patient_id": obj.id,
"patient_name": "%s %s"% (obj.first_name or "",obj.last_name or ""), "patient_name": "%s %s"% (obj.first_name or "",obj.last_name or ""),
"patient_type": obj.type_id.name, "patient_type": obj.type_id.name,
"type": "in", "type": "in",
"type_id": obj.type_id.id,
#"location_from_id": obj.location, #"location_from_id": obj.location,
#"location_to_id": obj.location, #"location_to_id": obj.location,
} }
@ -385,11 +387,13 @@ class Patient(Model):
vals['resign_date']=time.strftime("%Y-%m-%d") vals['resign_date']=time.strftime("%Y-%m-%d")
vals['rm_remain_visit']=True vals['rm_remain_visit']=True
obj=self.browse(ids)[0] obj=self.browse(ids)[0]
if obj.walkin=='no':
patient_move={ patient_move={
"patient_id": obj.id, "patient_id": obj.id,
"patient_name": "%s %s"% (obj.first_name or "",obj.last_name or ""), "patient_name": "%s %s"% (obj.first_name or "",obj.last_name or ""),
"patient_type": obj.type_id.name, "patient_type": obj.type_id.name,
"type": "out", "type": "out",
"type_id": obj.type_id.id,
#"location_from_id": obj.location, #"location_from_id": obj.location,
#"location_to_id": obj.location, #"location_to_id": obj.location,
} }
@ -398,6 +402,18 @@ class Patient(Model):
vals['state']='admit' vals['state']='admit'
vals['rm_remain_visit']=False vals['rm_remain_visit']=False
vals['resign_date']=None vals['resign_date']=None
obj=self.browse(ids)[0]
if obj.walkin=='no':
patient_move={
"patient_id": obj.id,
"patient_name": "%s %s"% (obj.first_name or "",obj.last_name or ""),
"patient_type": obj.type_id.name,
"type": "in",
"type_id": obj.type_id.id,
#"location_from_id": obj.location,
#"location_to_id": obj.location,
}
get_model("clinic.patient.move").create(patient_move)
ctx={} ctx={}
if 'active' in vals.keys(): if 'active' in vals.keys():
if not vals['active']: if not vals['active']:

View File

@ -6,7 +6,8 @@ class PatientMove(Model):
_name='clinic.patient.move' _name='clinic.patient.move'
_fields={ _fields={
'patient_id': fields.Many2One("clinic.patient", "Patient", required=True, on_delete="cascade"), "patient_id": fields.Many2One("clinic.patient", "Patient", required=True, on_delete="cascade"),
"type_id": fields.Many2One("clinic.patient.type","Type",search=True,required=True),
"date": fields.DateTime("Date"), "date": fields.DateTime("Date"),
"patient_name": fields.Char("Patient Name"), "patient_name": fields.Char("Patient Name"),
"patient_type": fields.Char("Patient Type"), #ปกส. .... "patient_type": fields.Char("Patient Type"), #ปกส. ....

View File

@ -51,7 +51,7 @@ class ReportDiscontinuePatient(Model):
} }
return res return res
def get_report_data_revise(self,ids,context={}): def get_report_data(self,ids,context={}):
company_id=get_active_company() company_id=get_active_company()
company=get_model('company').browse(company_id) company=get_model('company').browse(company_id)
year, month=time.strftime("%Y-%m").split("-") year, month=time.strftime("%Y-%m").split("-")
@ -90,6 +90,8 @@ class ReportDiscontinuePatient(Model):
continue continue
if record.patient_id.department_id.id!=department_id: if record.patient_id.department_id.id!=department_id:
continue continue
if record.patient_id.walkin!='no':
continue
lines.append({ lines.append({
'no': no, 'no': no,
'name': record.patient_name or '', 'name': record.patient_name or '',
@ -121,7 +123,7 @@ class ReportDiscontinuePatient(Model):
} }
return data return data
def get_report_data(self,ids,context={}): def get_report_data_bak(self,ids,context={}):
company_id=get_active_company() company_id=get_active_company()
company=get_model('company').browse(company_id) company=get_model('company').browse(company_id)
year, month=time.strftime("%Y-%m").split("-") year, month=time.strftime("%Y-%m").split("-")

View File

@ -77,295 +77,6 @@ class ReportHDCaseDetail(Model):
#print('report.hd.case.detail.defaults ', res) #print('report.hd.case.detail.defaults ', res)
return res return res
def get_report_data_revise(self,ids,context={}):
user_id=get_active_user()
set_active_user(1)
company_id=get_active_company()
company=get_model("company").browse(company_id)
defaults=self.default_get(context=context)
date=defaults.get('date',time.strftime("%Y-%m-%d"))
year=int(date[0:4])
crr_month=int(date[5:7])
weekday, crr_total_day=monthrange(year, crr_month)
date_from=defaults.get('date_from',date)
date_to=defaults.get('date_to',date)
branch_id=defaults.get("branch_id",None)
department_id=defaults.get("department_id",None)
hdcase_type=defaults.get('hdcase_type')
report_type=defaults.get('report_type','topic1')
patient_type_id=defaults.get('patient_type_id')
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)
titles=dict(self._fields['report_type'].selection)
title=titles.get(report_type,'no title')
if ids:
obj=self.browse(ids)[0]
branch_id=obj.branch_id.id
department_id=obj.department_id.id
date=obj.date
crr_month=int(date[5:7])
time_start=obj.date_from
time_stop=obj.date_to
year=int(date[0:4])
date_from=obj.date_from
date_to=obj.date_to
report_type=obj.report_type or 'topic1'
hdcase_type=obj.hdcase_type or 'completed'
patient_type_id=obj.patient_type_id.id
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 replace_quote(dom=""):
dom=dom.replace("False","false")
dom=dom.replace("True","true")
return dom.replace("'","\"")
dom=[]
lines=[]
total=0
# current hd case
if report_type=='topic1':
title=titles.get(report_type,'no title')
dom=[]
dom.append(["date",">=",date_from])
dom.append(["date","<=",date_to])
if hdcase_type=='completed':
dom.append(["state","in",["waiting_payment","paid"]])
else:
dom.append(["state","not in",["waiting_payment","paid"]])
if branch_id:
dom.append(['branch_id','=',branch_id])
if department_id:
dom.append(['department_id','=',department_id])
total=0
for hdcase in get_model("clinic.hd.case").search_browse(dom,order="number"):
patient=hdcase.patient_id
lines.append({
'number': hdcase.number,
'date': hdcase.date,
'name': patient.name,
'note': hdcase.note,
})
total+=1
# number of patient from previous month
elif report_type=='topic2':
title=titles.get(report_type,'no title')
title+=' '+prev_month_str
prev_weekday, prev_total_day=monthrange(prev_year, prev_month)
reg_date='%s-%s-%s'%(prev_year,str(prev_month).zfill(2),str(prev_total_day).zfill(2))
print('topic2 ', reg_date)
dom=[]
dom.append(['reg_date','<=',reg_date])
dom.append(['walkin','=',"no"])
#dom.append(['dispose','=',False])
if branch_id:
dom.append(['branch_id','=',branch_id])
if department_id:
dom.append(['department_id','=',department_id])
total=0
for patient in get_model("clinic.patient").search_browse(dom):
if patient.dispose and patient.resign_date:
if patient.resign_date < date_from:
print('continue >>> ', patient.name, patient.resign_date, date_from, date_to)
continue
elif patient.resign_date > date_to:
pass
elif not patient.resign_date > date_to:
print('pass >>> ', patient.name, patient.resign_date, date_from, date_to)
elif not (patient.resign_date>=date_from and patient.resign_date<=date_to):
print('continue >>> ', patient.name, patient.resign_date, date_from, date_to)
continue
print('pass >>> ', patient.name, patient.resign_date, date_from, date_to)
lines.append({
'number': patient.hn_no,
'pid': patient.id,
'name': patient.name,
'note': patient.note,
'date': patient.reg_date,
})
total+=1
# new patient of this month
#TODO should include move_history
elif report_type=='topic3':
title=titles.get(report_type,'no title')
title+=' '+month_str
dom=[]
dom.append(['date','>=',time_start])
dom.append(['date','<=',time_stop])
dom.append(['type','=',"in"])
#dom.append(['reg_date','>=',time_start])
#dom.append(['reg_date','<=',time_stop])
#dom.append(['walkin','=',"no"])
#dom.append(['dispose','=',False])
#if branch_id:
#dom.append(['branch_id','=',branch_id])
#if department_id:
#dom.append(['department_id','=',department_id])
total=0
for moves in get_model('clinic.patient.move').search_browse(dom):
if moves.patient_id.branch_id.id!=branch_id:
continue
if moves.patient_id.department_id.id!=department_id:
continue
lines.append({
#'number': patient.hn_no,
#'pid': patient.id,
#'name': patient.name,
#'note': patient.note,
#'date': patient.reg_date,
'number': moves.patient_id.hn_no,
'pid': moves.patient_id.id,
'name': moves.patient_id.name,
'note': moves.patient_id.note,
'date': moves.date[:10],
})
total+=1
# number for patient who resign for this month
#TODO should include move_history
elif report_type=='topic4':
title=titles.get(report_type,'no title')
title+=' '+month_str
dom=[]
#dom.append(['resign_date','>=',time_start])
#dom.append(['resign_date','<=',time_stop])
dom.append(['date','>=',time_start])
dom.append(['date','<=',time_stop])
dom.append(['type','=',"out"])
#dom.append(['walkin','=',"no"])
#dom.append(['dispose','=',True])
#if branch_id:
#dom.append(['branch_id','=',branch_id])
#if department_id:
#dom.append(['department_id','=',department_id])
total=0
for moves in get_model('clinic.patient.move').search_browse(dom):
if moves.patient_id.branch_id.id!=branch_id:
continue
if moves.patient_id.department_id.id!=department_id:
continue
lines.append({
'number': moves.patient_id.hn_no,
'pid': moves.patient_id.id,
'name': moves.patient_id.name,
'note': moves.patient_id.note,
'date': moves.date[:10],
})
total+=1
# all patient who are in hospital on select month
elif report_type=='topic5':
print('topic5 ', time_stop)
title=titles.get(report_type,'no title')
title+=' '+next_month_str
dom=[]
dom.append(['reg_date','<=',time_stop])
if branch_id:
dom.append(['branch_id','=',branch_id])
if department_id:
dom.append(['department_id','=',department_id])
dom.append(['walkin','=',"no"])
total=0
for patient in get_model('clinic.patient').search_browse(dom,order="reg_date"):
if patient.dispose and patient.resign_date:
if patient.resign_date < date_from:
print('1. continue >>> ', patient.name, patient.resign_date, date_from, date_to)
continue
elif patient.resign_date > date_to:
pass
elif patient.resign_date > date_to:
print('2. pass >>> ', patient.name, patient.resign_date, date_from, date_to)
elif (patient.resign_date>=date_from and patient.resign_date<=date_to):
print('3. continue >>> ', patient.name, patient.resign_date, date_from, date_to)
continue
print('4. pass >>> ', patient.name, patient.resign_date, date_from, date_to)
lines.append({
'number': patient.hn_no,
'pid': patient.id,
'name': patient.name,
'note': patient.note,
'date': patient.reg_date,
'dispose': patient.dispose and 'yes' or 'no',
})
total+=1
# find patient movement
elif report_type=='topic6':
print('topic6')
ptype=None
if patient_type_id:
ptype=get_model('clinic.patient.type').browse(patient_type_id)
if not ptype:
return {'total': 0}
title=ptype.name or ''
dom=[]
dom.append(['reg_date','<=',time_stop])
dom.append(['type_id','=',ptype['id']])
dom.append(['walkin','=',"no"])
dom.append(['type_id','=',ptype.id])
if branch_id:
dom.append(['branch_id','=',branch_id])
if department_id:
dom.append(['department_id','=',department_id])
total=0
for patient in get_model("clinic.patient").search_browse(dom):
if patient.resign_date:
if patient.dispose and patient.resign_date < date_from:
print('1. continue >>> ', patient.name, patient.resign_date, date_from, date_to)
continue
elif patient.resign_date > date_to:
pass
elif patient.resign_date > date_to:
print('2. pass >>> ', patient.name, patient.resign_date, date_from, date_to)
elif (patient.resign_date>=date_from and patient.resign_date<=date_to):
print('3. continue >>> ', patient.name, patient.resign_date, date_from, date_to)
continue
print('4. pass >>> ', patient.name, patient.resign_date, date_from, date_to)
lines.append({
'pid': patient.id,
'number': patient.hn_no,
'name': patient.name or '',
'date': patient.reg_date,
})
total+=1
sub_name=''
if department_id:
dpt=get_model("clinic.department").browse(department_id)
sub_name="(%s)" % dpt.name or ""
elif branch_id:
branch=get_model("clinic.branch").browse(branch_id)
sub_name="(%s)" % branch.name or ""
no=1
for line in lines:
line['no']="{0:,.0f}".format(no)
no+=1
data={
'total_txt': "{0:,.0f}".format(total),
'total': total,
'title': title,
'report_type': report_type,
'date': date,
'date_from': date_from,
'date_to': date_to,
'month': month_str,
'year': year,
'branch_id': branch_id,
'department_id': department_id,
'lines': lines,
'company_name': '%s %s'% (company.name or "", sub_name),
'parent_company_name': company.parent_id.name or "",
}
set_active_user(user_id)
return data
def get_report_data(self,ids,context={}): def get_report_data(self,ids,context={}):
user_id=get_active_user() user_id=get_active_user()
set_active_user(1) set_active_user(1)
@ -416,6 +127,289 @@ class ReportHDCaseDetail(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 replace_quote(dom=""):
dom=dom.replace("False","false")
dom=dom.replace("True","true")
return dom.replace("'","\"")
dom=[]
lines=[]
total=0
# current hd case
if report_type=='topic1':
title=titles.get(report_type,'no title')
dom=[]
dom.append(["date",">=",date_from])
dom.append(["date","<=",date_to])
if hdcase_type=='completed':
dom.append(["state","in",["waiting_payment","paid"]])
else:
dom.append(["state","not in",["waiting_payment","paid"]])
if branch_id:
dom.append(['branch_id','=',branch_id])
if department_id:
dom.append(['department_id','=',department_id])
total=0
for hdcase in get_model("clinic.hd.case").search_browse(dom,order="number"):
patient=hdcase.patient_id
lines.append({
'number': hdcase.number,
'date': hdcase.date,
'name': patient.name,
'note': hdcase.note,
})
total+=1
# number of patient from previous month
elif report_type=='topic2':
title=titles.get(report_type,'no title')
title+=' '+prev_month_str
prev_weekday, prev_total_day=monthrange(prev_year, prev_month)
reg_date='%s-%s-%s'%(prev_year,str(prev_month).zfill(2),str(prev_total_day).zfill(2))
print('topic2 ', reg_date)
dom=[]
dom.append(['walkin','=',"no"])
if branch_id:
dom.append(['branch_id','=',branch_id])
if department_id:
dom.append(['department_id','=',department_id])
total=0
for patient in get_model("clinic.patient").search_browse(dom):
if len(get_model('clinic.patient.move').search_browse([['patient_id','=',patient.id],['type','=','in'],['date','<=',reg_date]],order="date desc"))==0:
continue
if len(get_model('clinic.patient.move').search_browse([['patient_id','=',patient.id],['type','=','out'],['date','<=',reg_date]],order="date desc"))==0:
moves_in=get_model('clinic.patient.move').search_browse([['patient_id','=',patient.id],['type','=','in'],['date','<=',reg_date]],order="date desc")[0]
data={
'number': moves_in.patient_id.hn_no,
'pid': moves_in.patient_id.id,
'name': moves_in.patient_name,
'note': moves_in.patient_id.note,
'date': moves_in.patient_id.reg_date,
}
else:
moves_in=get_model('clinic.patient.move').search_browse([['patient_id','=',patient.id],['type','=','in'],['date','<=',reg_date]],order="date desc")[0]
moves_out=get_model('clinic.patient.move').search_browse([['patient_id','=',patient.id],['type','=','out'],['date','<=',reg_date]],order="date desc")[0]
if moves_out.date > moves_in.date:
continue
data={
'number': moves_in.patient_id.hn_no,
'pid': moves_in.patient_id.id,
'name': moves_in.patient_name,
'note': moves_in.patient_id.note,
'date': moves_in.patient_id.reg_date,
}
lines.append(data)
total+=1
# new patient of this month
#TODO should include move_history
elif report_type=='topic3':
title=titles.get(report_type,'no title')
title+=' '+month_str
dom=[]
dom.append(['date','>=',time_start])
dom.append(['date','<=',time_stop])
dom.append(['type','=',"in"])
total=0
for moves in get_model('clinic.patient.move').search_browse(dom):
if moves.patient_id.branch_id.id!=branch_id:
continue
if moves.patient_id.department_id.id!=department_id:
continue
if moves.patient_id.walkin!='no':
continue
lines.append({
'number': moves.patient_id.hn_no,
'pid': moves.patient_id.id,
'name': moves.patient_name,
'note': moves.patient_id.note,
'date': moves.date[:10],
})
total+=1
# number for patient who resign for this month
#TODO should include move_history
elif report_type=='topic4':
title=titles.get(report_type,'no title')
title+=' '+month_str
dom=[]
dom.append(['date','>=',time_start])
dom.append(['date','<=',time_stop])
dom.append(['type','=',"out"])
total=0
for moves in get_model('clinic.patient.move').search_browse(dom):
if moves.patient_id.branch_id.id!=branch_id:
continue
if moves.patient_id.department_id.id!=department_id:
continue
if moves.patient_id.walkin!='no':
continue
lines.append({
'number': moves.patient_id.hn_no,
'pid': moves.id,
'name': moves.patient_name,
'note': moves.patient_id.note,
'date': moves.date[:10],
})
total+=1
# all patient who are in hospital on select month
elif report_type=='topic5':
print('topic5 ', time_stop)
title=titles.get(report_type,'no title')
title+=' '+next_month_str
dom=[]
if branch_id:
dom.append(['branch_id','=',branch_id])
if department_id:
dom.append(['department_id','=',department_id])
dom.append(['walkin','=',"no"])
total=0
count=0
data_check={}
for patient in get_model('clinic.patient').search_browse(dom):
if len(get_model('clinic.patient.move').search_browse([['patient_id','=',patient.id],['type','=','in'],['date','<=',time_stop]],order="date desc"))==0:
continue
if len(get_model('clinic.patient.move').search_browse([['patient_id','=',patient.id],['type','=','out'],['date','<=',time_stop]],order="date desc"))==0:
moves_in=get_model('clinic.patient.move').search_browse([['patient_id','=',patient.id],['type','=','in'],['date','<=',time_stop]],order="date desc")[0]
data={
'number': moves_in.patient_id.hn_no,
'pid': moves_in.patient_id.id,
'name': moves_in.patient_name,
'note': moves_in.patient_id.note,
'date': moves_in.patient_id.reg_date,
}
else:
moves_in=get_model('clinic.patient.move').search_browse([['patient_id','=',patient.id],['type','=','in'],['date','<=',time_stop]],order="date desc")[0]
moves_out=get_model('clinic.patient.move').search_browse([['patient_id','=',patient.id],['type','=','out'],['date','<=',time_stop]],order="date desc")[0]
if moves_out.date > moves_in.date:
continue
data={
'number': moves_in.patient_id.hn_no,
'pid': moves_in.patient_id.id,
'name': moves_in.patient_name,
'note': moves_in.patient_id.note,
'date': moves_in.patient_id.reg_date,
}
lines.append(data)
total+=1
# find patient movement
elif report_type=='topic6':
print('topic6')
ptype=None
if patient_type_id:
ptype=get_model('clinic.patient.type').browse(patient_type_id)
if not ptype:
return {'total': 0}
title=ptype.name or ''
dom=[]
dom.append(['type_id','=',ptype['id']])
dom.append(['walkin','=',"no"])
dom.append(['type_id','=',ptype.id])
if branch_id:
dom.append(['branch_id','=',branch_id])
if department_id:
dom.append(['department_id','=',department_id])
total=0
for patient in get_model('clinic.patient').search_browse(dom):
if len(get_model('clinic.patient.move').search_browse([['patient_id','=',patient.id],['type','=','in'],['date','<=',time_stop]],order="date desc"))==0:
continue
if len(get_model('clinic.patient.move').search_browse([['patient_id','=',patient.id],['type','=','out'],['date','<=',time_stop]],order="date desc"))==0:
moves_in=get_model('clinic.patient.move').search_browse([['patient_id','=',patient.id],['type','=','in'],['date','<=',time_stop]],order="date desc")[0]
data={
'number': moves_in.patient_id.hn_no,
'pid': moves_in.patient_id.id,
'name': moves_in.patient_name,
'date': moves_in.patient_id.reg_date,
}
else:
moves_in=get_model('clinic.patient.move').search_browse([['patient_id','=',patient.id],['type','=','in'],['date','<=',time_stop]],order="date desc")[0]
moves_out=get_model('clinic.patient.move').search_browse([['patient_id','=',patient.id],['type','=','out'],['date','<=',time_stop]],order="date desc")[0]
if moves_out.date > moves_in.date:
continue
data={
'number': moves_in.patient_id.hn_no,
'pid': moves_in.patient_id.id,
'name': moves_in.patient_name,
'date': moves_in.patient_id.reg_date,
}
lines.append(data)
total+=1
sub_name=''
if department_id:
dpt=get_model("clinic.department").browse(department_id)
sub_name="(%s)" % dpt.name or ""
elif branch_id:
branch=get_model("clinic.branch").browse(branch_id)
sub_name="(%s)" % branch.name or ""
no=1
for line in lines:
line['no']="{0:,.0f}".format(no)
no+=1
data={
'total_txt': "{0:,.0f}".format(total),
'total': total,
'title': title,
'report_type': report_type,
'date': date,
'date_from': date_from,
'date_to': date_to,
'month': month_str,
'year': year,
'branch_id': branch_id,
'department_id': department_id,
'lines': lines,
'company_name': '%s %s'% (company.name or "", sub_name),
'parent_company_name': company.parent_id.name or "",
}
set_active_user(user_id)
return data
def get_report_data_bak(self,ids,context={}):
user_id=get_active_user()
set_active_user(1)
company_id=get_active_company()
company=get_model("company").browse(company_id)
defaults=self.default_get(context=context)
date=defaults.get('date',time.strftime("%Y-%m-%d"))
year=int(date[0:4])
crr_month=int(date[5:7])
weekday, crr_total_day=monthrange(year, crr_month)
date_from=defaults.get('date_from',date)
date_to=defaults.get('date_to',date)
branch_id=defaults.get("branch_id",None)
department_id=defaults.get("department_id",None)
hdcase_type=defaults.get('hdcase_type')
report_type=defaults.get('report_type','topic1')
patient_type_id=defaults.get('patient_type_id')
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)
titles=dict(self._fields['report_type'].selection)
title=titles.get(report_type,'no title')
if ids:
obj=self.browse(ids)[0]
branch_id=obj.branch_id.id
department_id=obj.department_id.id
date=obj.date
crr_month=int(date[5:7])
time_start=obj.date_from
time_stop=obj.date_to
year=int(date[0:4])
date_from=obj.date_from
date_to=obj.date_to
report_type=obj.report_type or 'topic1'
hdcase_type=obj.hdcase_type or 'completed'
patient_type_id=obj.patient_type_id.id
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 replace_quote(dom=""): def replace_quote(dom=""):
dom=dom.replace("False","false") dom=dom.replace("False","false")
dom=dom.replace("True","true") dom=dom.replace("True","true")
@ -482,6 +476,7 @@ class ReportHDCaseDetail(Model):
'name': patient.name, 'name': patient.name,
'note': patient.note, 'note': patient.note,
'date': patient.reg_date, 'date': patient.reg_date,
'dispose': patient.dispose and 'yes' or 'no',
}) })
total+=1 total+=1
# new patient of this month # new patient of this month
@ -604,6 +599,7 @@ class ReportHDCaseDetail(Model):
'number': patient.hn_no, 'number': patient.hn_no,
'name': patient.name or '', 'name': patient.name or '',
'date': patient.reg_date, 'date': patient.reg_date,
'dispose': patient.dispose and 'yes' or 'no',
}) })
total+=1 total+=1
sub_name='' sub_name=''

View File

@ -176,11 +176,11 @@ class ReportHDCaseSummary(Model):
dom2=dom+[['patient_type_id','=',topics[topic]['ptype_id']]] dom2=dom+[['patient_type_id','=',topics[topic]['ptype_id']]]
dom_txt=set_default(dom2,topic) dom_txt=set_default(dom2,topic)
ctx=set_ctx(dom2,topic) ctx=set_ctx(dom2,topic)
qty=get_model("clinic.report.hd.case.detail").get_report_data_revise(ids=[],context=ctx)['total'] qty=get_model("clinic.report.hd.case.detail").get_report_data(ids=[],context=ctx)['total']
else: else:
dom_txt=set_default(dom,topic) dom_txt=set_default(dom,topic)
ctx=set_ctx(dom,topic) ctx=set_ctx(dom,topic)
qty=get_model("clinic.report.hd.case.detail").get_report_data_revise(ids=[],context=ctx)['total'] qty=get_model("clinic.report.hd.case.detail").get_report_data(ids=[],context=ctx)['total']
item_vals={ item_vals={
"topic": topics[topic]['name'], "topic": topics[topic]['name'],
"unit": topics[topic]['unit'], "unit": topics[topic]['unit'],
@ -233,8 +233,8 @@ class ReportHDCaseSummary(Model):
'month': month_str, 'month': month_str,
'year': year, 'year': year,
'lines': lines, 'lines': lines,
'recent_patients': get_model("clinic.report.recent.patient").get_report_data_revise(ids=[],context=context)['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_revise(ids=[],context=context)['lines'], 'resign_patients': get_model("clinic.report.discontinue.patient").get_report_data(ids=[],context=context)['lines'],
'medicals': medical_lines, 'medicals': medical_lines,
'titles': medical_titles, 'titles': medical_titles,
'plines': plines, 'plines': plines,

View File

@ -50,7 +50,7 @@ class ReportRecentPatient(Model):
} }
return res return res
def get_report_data_revise(self,ids,context={}): def get_report_data(self,ids,context={}):
company_id=get_active_company() company_id=get_active_company()
company=get_model('company').browse(company_id) company=get_model('company').browse(company_id)
year, month=time.strftime("%Y-%m").split("-") year, month=time.strftime("%Y-%m").split("-")
@ -72,14 +72,6 @@ class ReportRecentPatient(Model):
dom.append(['date','>=',time_start]) dom.append(['date','>=',time_start])
dom.append(['date','<=',time_stop]) dom.append(['date','<=',time_stop])
dom.append(['type','=',"in"]) dom.append(['type','=',"in"])
#dom.append(['reg_date','>=',time_start])
#dom.append(['reg_date','<=',time_stop])
#dom.append(['walkin','=',"no"])
#dom.append(['dispose','=',False])
#if branch_id:
#dom.append(['branch_id','=',branch_id])
#if department_id:
#dom.append(['department_id','=',department_id])
records=get_model('clinic.patient.move').search_browse(dom) records=get_model('clinic.patient.move').search_browse(dom)
lines=[] lines=[]
no=1 no=1
@ -88,6 +80,8 @@ class ReportRecentPatient(Model):
continue continue
if record.patient_id.department_id.id!=department_id: if record.patient_id.department_id.id!=department_id:
continue continue
if record.patient_id.walkin!='no':
continue
lines.append({ lines.append({
'no': no, 'no': no,
'name': record.patient_name or '', 'name': record.patient_name or '',
@ -120,7 +114,7 @@ class ReportRecentPatient(Model):
} }
return data return data
def get_report_data(self,ids,context={}): def get_report_data_bak(self,ids,context={}):
company_id=get_active_company() company_id=get_active_company()
company=get_model('company').browse(company_id) company=get_model('company').browse(company_id)
year, month=time.strftime("%Y-%m").split("-") year, month=time.strftime("%Y-%m").split("-")

View File

@ -70,8 +70,11 @@
<td> <td>
{{view "link" string=name action="clinic_patient_move" action_options="mode=form" active_id=pid}} {{view "link" string=name action="clinic_patient_move" action_options="mode=form" active_id=pid}}
</td> </td>
<!--button delete ##TODO-->
<td> <td>
<button type="button" class="btn btn-danger btn-xs">Del</button> <button type="button" class="btn btn-danger btn-xs">
<span class="glyphicon glyphicon-remove"></span>
</button>
</td> </td>
</tr> </tr>
{{/each}} {{/each}}
@ -103,8 +106,11 @@
<td> <td>
{{view "link" string=name action="clinic_patient_move" action_options="mode=form" active_id=pid}} {{view "link" string=name action="clinic_patient_move" action_options="mode=form" active_id=pid}}
</td> </td>
<!--button delete ##TODO-->
<td> <td>
<button type="button" class="btn btn-danger btn-xs">Del</button> <button type="button" class="btn btn-danger btn-xs">
<span class="glyphicon glyphicon-remove"></span>
</button>
</td> </td>
</tr> </tr>
{{/each}} {{/each}}