change visit

conv_bal
watcha.h@almacom.co.th 2015-05-12 14:51:27 +07:00
parent afca84692b
commit 685f477675
12 changed files with 183 additions and 24 deletions

View File

@ -0,0 +1,6 @@
<action>
<field name="string">Change Visit</field>
<field name="view_cls">form_popup</field>
<field name="model">clinic.change.visit</field>
<field name="target">_popup</field>
</action>

View File

@ -0,0 +1,14 @@
<form model="clinic.change.visit">
<field name="visit_date" onchange="onchange_date"/>
<field name="cycle_id" onchange="onchange_cycle" required="1"/>
<field name="department_id" onchange="onchange_department"/>
<field name="branch_id" invisible="1"/>
<field name="patient_id" onchange="onchange_patient"/>
<field name="doctor_id"/>
<field name="time_start" onchange="onchange_datefrom" invisible="1"/>
<field name="time_stop" invisible="1"/>
<field name="visit_id" invisible="1"/>
<foot>
<button string="Change" type="primary" method="do_change"/>
</foot>
</form>

View File

@ -5,4 +5,7 @@
<field name="hdcase_type" required="1" span="2"/> <field name="hdcase_type" required="1" span="2"/>
<field name="branch_id" onchange="onchange_branch" span="2"/> <field name="branch_id" onchange="onchange_branch" span="2"/>
<field name="department_id" domain='[["branch_id","=",branch_id]]' span="2"/> <field name="department_id" domain='[["branch_id","=",branch_id]]' span="2"/>
<foot>
<button string="Export PDF" method="export_pdf"/>
</foot>
</form> </form>

View File

@ -7,6 +7,7 @@
<field name="doctor_id" span="2"/> <field name="doctor_id" span="2"/>
<field name="branch_id" onchange="onchange_branch" span="2"/> <field name="branch_id" onchange="onchange_branch" span="2"/>
<field name="department_id" domain='[["branch_id","=",branch_id]]' span="2"/> <field name="department_id" domain='[["branch_id","=",branch_id]]' span="2"/>
<field name="state" span="2"/>
<button string='Confirm Visits' method="confirm" type="success" icon="arrow-right"/> <button string='Confirm Visits' method="confirm" type="success" icon="arrow-right"/>
<group span="6" columns="1"> <group span="6" columns="1">
<template> <template>

View File

@ -36,6 +36,7 @@
<button string="Pending" perm="clinic_visit_pending" type="default" method="pending" states="draft" /> <button string="Pending" perm="clinic_visit_pending" type="default" method="pending" states="draft" />
<button string="Confirm" perm="clinic_visit_confirm" type="success" method="confirm" states="pending" /> <button string="Confirm" perm="clinic_visit_confirm" type="success" method="confirm" states="pending" />
<button string="Discard" perm="clinic_visit_discard" type="danger" method="cancel" states="pending" /> <button string="Discard" perm="clinic_visit_discard" type="danger" method="cancel" states="pending" />
<button string="Change Visit" type="default" action="clinic_change_visit" states="pending" />
</foot> </foot>
<related> <related>
<field name="hd_cases" readonly="1"/> <field name="hd_cases" readonly="1"/>

View File

@ -134,5 +134,6 @@ from . import account_tax_component
from . import report_thai_wht_certif from . import report_thai_wht_certif
from . import num2word from . import num2word
from . import province from . import province
from . import change_visit
#from . import district #from . import district
#from . import subdistrict #from . import subdistrict

View File

@ -0,0 +1,139 @@
from netforce.model import Model, fields, get_model
class ChangeVisit(Model):
_name="clinic.change.visit"
_transient=True
_fields={
"visit_id": fields.Many2One("clinic.visit","Visit",required=True,on_delete="cascade"),
"time_start": fields.DateTime("Start Time",required=True),
"time_stop": fields.DateTime("End Time",required=True),
"patient_id": fields.Many2One("clinic.patient","Patient",required=True,search=True,domain=[['state','=','admit']]),
"doctor_id": fields.Many2One("clinic.staff","Doctor", domain=[['type','=','doctor']],search=True),
"department_id": fields.Many2One("clinic.department", "Department",search=True),
'branch_id': fields.Many2One("clinic.branch","Branch"),
"cycle_id": fields.Many2One("clinic.cycle","Cycle"),
'visit_date': fields.Date('Date'),
'note': fields.Text('Note'),
}
def default_get(self,field_names=None,context={},**kw):
print("clinic.change.visit.default")
#defaults=context.get("defaults",{})
refer_id=context.get("refer_id")
res={}
if refer_id:
refer_id=int(refer_id)
obj=get_model("clinic.visit").browse(refer_id)
res={
'visit_id': refer_id,
'patient_id': obj.patient_id.id,
'doctor_id': obj.doctor_id.id,
'department_id': obj.department_id.id,
'branch_id': obj.department_id.branch_id.id,
'cycle_id': obj.cycle_id.id,
'time_start': obj.time_start,
'time_stop': obj.time_stop,
'visit_date': obj.visit_date,
}
print(res)
return res
def do_change(self,ids,context):
obj=self.browse(ids)[0]
dom=[
['visit_date','=',obj.visit_date],
['patient_id','=',obj.patient_id.id],
['cycle_id','=',obj.cycle_id.id], #XXX
['department_id','=',obj.department_id.id],
]
res=get_model("clinic.visit").search(dom)
if res:
raise Exception("This visit already exist in the system!")
new_id=get_model("clinic.visit").create({
'patient_id': obj.patient_id.id,
'doctor_id': obj.doctor_id.id,
'department_id': obj.department_id.id,
'branch_id': obj.department_id.branch_id.id,
'cycle_id': obj.cycle_id.id,
'time_start': obj.time_start,
'time_stop': obj.time_stop,
'visit_date': obj.visit_date,
'state': 'pending',
})
obj.visit_id.to_draft()
obj.visit_id.cancel()
visit=get_model("clinic.visit").browse(new_id)
return {
'next': {
'name': 'clinic_visit',
'mode': 'form',
'active_id': new_id,
},
'flash': 'Copy visit %s to %s has been successfully'%(obj.visit_id.visit_date, visit.visit_date)
}
def onchange_date(self,context={}):
data=context['data']
date=data['visit_date']
time_start=data['time_start'][11:]
time_stop=data['time_stop'][11:]
data['time_start']='%s %s'%(date,time_start)
data['time_stop']='%s %s'%(date,time_stop)
return data
def onchange_department(self,context={}):
data=context['data']
dpt_id=data['department_id']
if dpt_id:
dpt=get_model("clinic.department").browse(dpt_id)
data['branch_id']=dpt.branch_id.id
return data
def onchange_cycle(self,context={}):
data=context['data']
cycle_id=data['cycle_id']
date=data['visit_date']
if not date:
date=data['time_start'][0:10]
if cycle_id:
cycle=get_model('clinic.cycle').browse(cycle_id)
data['time_start']=date+' %s:00'%cycle.time_start
data['time_stop']=date+' %s:00'%cycle.time_stop
return data
def onchange_datefrom(self,context={}):
data=context['data']
data['visit_date']=data['time_start'][0:10]
return data
def onchange_patient(self,context={}):
data=context['data']
patient_id=data['patient_id']
patient=get_model("clinic.patient").browse(patient_id)
doctor=patient.doctor_id
visits=self.search_browse([['patient_id','=',patient_id]],order="number desc")
if visits:
visit=visits[0]
department_id=None
if visit.department_id:
department_id=visit.department_id.id
elif patient.department_id:
department_id=patient.department_id.id
branch_id=None
if visit.branch_id:
branch_id=visit.branch_id.id
elif patient.branch_id:
branch_id=patient.branch_id.id
data['department_id']=department_id
data['branch_id']=branch_id
else:
department=patient.department_id
branch=patient.branch_id
data['department_id']=department.id
data['branch_id']=branch.id
data['doctor_id']=doctor.id
return data
ChangeVisit.register()

View File

@ -79,11 +79,6 @@ class HDCasePrint(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=""): def replace_quote(dom=""):
return dom.replace("'","\"") return dom.replace("'","\"")

View File

@ -302,4 +302,8 @@ class ReportHDCaseSummary(Model):
} }
} }
def export_pdf(self,ids,context={}):
raise Exception("TODO")
return
ReportHDCaseSummary.register() ReportHDCaseSummary.register()

View File

@ -359,6 +359,7 @@ class Visit(Model):
'doctor_id': obj.doctor_id.id, 'doctor_id': obj.doctor_id.id,
'nurse_id': obj.nurse_id.id, 'nurse_id': obj.nurse_id.id,
'department_id': obj.department_id.id, 'department_id': obj.department_id.id,
'branch_id': obj.department_id.branch_id.id,
'cycle_id': obj.cycle_id.id, 'cycle_id': obj.cycle_id.id,
'time_start': obj.time_start, 'time_start': obj.time_start,
'time_stop': obj.time_stop, 'time_stop': obj.time_stop,

View File

@ -18,7 +18,6 @@ HD_STATE={
"discountinued":"Discountinued", "discountinued":"Discountinued",
"cancelled":"Cancelled" "cancelled":"Cancelled"
} }
DAYS={ DAYS={
'mon': 0, 'mon': 0,
'tue': 1, 'tue': 1,
@ -44,6 +43,7 @@ class VisitBoard(Model):
'doctor_id': fields.Many2One("clinic.staff","Doctor",domain=[["type","=","doctor"]]), 'doctor_id': fields.Many2One("clinic.staff","Doctor",domain=[["type","=","doctor"]]),
'department_id': fields.Many2One("clinic.department","Department"), 'department_id': fields.Many2One("clinic.department","Department"),
'branch_id': fields.Many2One("clinic.branch","Branch"), 'branch_id': fields.Many2One("clinic.branch","Branch"),
"state": fields.Selection([["draft","Draft"],['pending','Pending'],["confirmed","Confirmed"],["cancelled","Cancelled"]],"Status",required=True),
} }
def default_get(self,field_names=None,context={},**kw): def default_get(self,field_names=None,context={},**kw):
@ -70,7 +70,9 @@ class VisitBoard(Model):
'date_to': date_to, 'date_to': date_to,
'branch_id': branch_id, 'branch_id': branch_id,
'department_id': department_id, 'department_id': department_id,
'state': 'pending',
} }
print('clinic.visit.board.defaults ', defaults)
return res return res
def get_report_data(self,ids,context={}): def get_report_data(self,ids,context={}):
@ -84,7 +86,7 @@ class VisitBoard(Model):
defaults=self.default_get(context=context) defaults=self.default_get(context=context)
department_id=defaults.get("department_id",None) department_id=defaults.get("department_id",None)
branch_id=defaults.get("branch_id",None) branch_id=defaults.get("branch_id",None)
print('defaults ', defaults) state=defaults.get("state",'pending')
if ids: if ids:
obj=self.browse(ids)[0] obj=self.browse(ids)[0]
date_from=obj.date_from date_from=obj.date_from
@ -94,9 +96,10 @@ class VisitBoard(Model):
doctor_id=obj.doctor_id.id doctor_id=obj.doctor_id.id
department_id=obj.department_id.id department_id=obj.department_id.id
branch_id=obj.branch_id.id branch_id=obj.branch_id.id
state=obj.state
# auto generate visit day to day
def auto_gen_visit(dom=[]): def auto_gen_visit(dom=[]):
dom.append(['dispose','=',False]) dom.append(['dispose','=',False])
#dom.append(['walkin','=','no']) #XXX
def daterange(start_date, end_date): def daterange(start_date, end_date):
for n in range(int ((end_date - start_date).days)): for n in range(int ((end_date - start_date).days)):
yield start_date + timedelta(n) yield start_date + timedelta(n)
@ -107,7 +110,6 @@ class VisitBoard(Model):
return datetime.strptime(date_txt,"%Y-%m-%d") return datetime.strptime(date_txt,"%Y-%m-%d")
except: except:
raise Exception("Wrong Format Date") raise Exception("Wrong Format Date")
# IMPROVE
# check day of week of this day # check day of week of this day
for date in daterange(convert_date(date_from),convert_date(date_to)+timedelta(days=1)): for date in daterange(convert_date(date_from),convert_date(date_to)+timedelta(days=1)):
weekday=date.weekday() weekday=date.weekday()
@ -205,7 +207,14 @@ class VisitBoard(Model):
no=1 no=1
dpt={} dpt={}
brch={} brch={}
if state=='pending':
dom+=[['state', 'in',[state,'confirmed']]]
else:
dom+=[['state', 'in',[state]]]
print('dom ', dom)
for visit in get_model("clinic.visit").search_browse(dom): for visit in get_model("clinic.visit").search_browse(dom):
if visit.patient_id.id==1282:
print("OK ", visit.patient_id.name)
if visit.state in ('draft','pending'): if visit.state in ('draft','pending'):
total_wait+=1 total_wait+=1
elif visit.state in ('confirmed'): elif visit.state in ('confirmed'):

View File

@ -1,18 +1,3 @@
<center>
<!--
<h2>ตารางนัดผู้ป่วย</h2>
<h3>
{{parent_company_name}}&nbsp;{{company_name}}<br/>
</h3>
<h4>
{{#if has_duration}}
ระหว่างวันที่ {{date_from}} ถึง {{date_to}}
{{else}}
{{date}}
{{/if}}
</h4>
-->
</center>
<table class="table table-condensed table-striped"> <table class="table table-condensed table-striped">
<thead class="scroll-header"> <thead class="scroll-header">
<th>#</th> <th>#</th>