generate visit
parent
2f663da539
commit
04529f2669
|
@ -2,7 +2,7 @@
|
|||
<field name="string">Visits</field>
|
||||
<field name="view_cls">multi_view</field>
|
||||
<field name="model">clinic.visit</field>
|
||||
<field name="tabs">[["All",[]],["Draft",[["state","=","draft"]]],["Waiting Treatment",[["state","=","waiting_treatment"]]],["Treatment",[["state","=","treatment"]]],["Cancelled",[["state","=","cancelled"]]]]</field>
|
||||
<field name="tabs">[["All",[]],["Draft",[["state","=","draft"]]],["Confirmed",[["state","=","confirmed"]]],["Cancelled",[["state","=","cancelled"]]]]</field>
|
||||
<field name="modes">list,calendar,form</field>
|
||||
<field name="menu">clinic_menu</field>
|
||||
</action>
|
||||
|
|
|
@ -1,34 +1,32 @@
|
|||
<form model="clinic.visit" attrs='{"readonly":[["state","in",["treatment"]]]}' show_company="1">
|
||||
<form model="clinic.visit" attrs='{"readonly":[["state","in",["confirmed"]]]}' show_company="1">
|
||||
<head>
|
||||
<field name="state"/>
|
||||
<button string="Print" icon="print" action="report_visit_form"/>
|
||||
<button string="Options" dropdown="1">
|
||||
<item string="Copy" method="copy"/>
|
||||
<item string="Create Dialyzer" method="create_dialyzer"/>
|
||||
<item string="Generate Cycle" method="generate_cycle"/>
|
||||
<!--<item string="Create Dialyzer" method="create_dialyzer"/>-->
|
||||
<!--<item string="Generate Cycle" method="generate_cycle"/>-->
|
||||
</button>
|
||||
</head>
|
||||
<tabs>
|
||||
<tab string="General">
|
||||
<group span="6" columns="1">
|
||||
<field name="number"/>
|
||||
<field name="time_start" onchange="onchange_time" attrs='{"required":[["state","=","waiting_treatment"]]}'/>
|
||||
<field name="time_start" onchange="onchange_time"/>
|
||||
<field name="department_id"/>
|
||||
<field name="cycle_id" onchange="onchange_time" required="1"/>
|
||||
</group>
|
||||
<group span="6" columns="1">
|
||||
<field name="patient_id" onchange="onchange_patient"/>
|
||||
<field name="time_stop" attrs='{"required":[["state","=","waiting_treatment"]]}'/>
|
||||
<field name="time_stop"/>
|
||||
<field name="doctor_id"/>
|
||||
<field name="nurse_id" attrs='{"required":[["state","=","waiting_treatment"]]}'/>
|
||||
<field name="nurse_id"/>
|
||||
</group>
|
||||
</tab>
|
||||
</tabs>
|
||||
<foot>
|
||||
<button string="Confirm" type="success" method="confirm" states="draft" />
|
||||
<button string="Do Treatment" type="success" method="do_treatment" icon="arrow-right" states="waiting_treatment" />
|
||||
<button string="Dicard" type="warning" icon="trash" method="discard" states="waiting_treatment" confirm="Are you sure to cancel HD case?"/>
|
||||
<button string="Re Visit" type="default" attrs='{"invisible":[["state","=","treatment"]]}' icon="repeat" method="reopen" states="cancelled" />
|
||||
<button string="To Draft" type="default" icon="refresh" method="to_draft" states="confirmed" />
|
||||
</foot>
|
||||
<related>
|
||||
<field name="hd_cases" readonly="1"/>
|
||||
|
|
|
@ -29,11 +29,13 @@ class GenVisit(Model):
|
|||
'friday': fields.Boolean("Fridays"),
|
||||
'doctor_id': fields.Many2One("clinic.doctor","Doctor"),
|
||||
'nurse_id': fields.Many2One("clinic.nurse","Nurse"),
|
||||
'duration': fields.Integer("Duration", function="_get_duration"),
|
||||
'duration': fields.Integer("Duration (hrs)", function="_get_duration"),
|
||||
}
|
||||
|
||||
def _get_lines(self,context={}):
|
||||
ids=context.get("ids")
|
||||
if not ids:
|
||||
ids=[context.get("refer_id")]
|
||||
lines=[{'patient_id': id} for id in ids]
|
||||
return lines
|
||||
|
||||
|
@ -45,12 +47,20 @@ class GenVisit(Model):
|
|||
return nurse_ids[0]
|
||||
return None
|
||||
|
||||
def _get_cycle(self,context={}):
|
||||
cycle_ids=get_model('clinic.cycle').search([],order="sequence")
|
||||
if cycle_ids:
|
||||
cycle_id=cycle_ids[0]
|
||||
return cycle_id or None
|
||||
|
||||
_defaults={
|
||||
'lines': _get_lines,
|
||||
'date_from': lambda *a: datetime.now().strftime(FMT_DATETIME),
|
||||
'date_to': lambda *a: datetime.now().strftime(FMT_DATETIME),
|
||||
'nurse_id': _get_nurse,
|
||||
'duration': 1,
|
||||
'cycle_id': _get_cycle,
|
||||
'monday': True,
|
||||
}
|
||||
|
||||
def onchange_time(self,context={}):
|
||||
|
@ -64,17 +74,18 @@ class GenVisit(Model):
|
|||
date_from=data['date_from']
|
||||
date_to=(datetime.strptime(date_from,FMT_DATETIME)+timedelta(seconds=seconds)).strftime(FMT_DATETIME)
|
||||
data['date_to']='%s %s'%(data['date_to'][0:10],date_to[11:])
|
||||
data['duration']=(datetime.strptime(data['date_to'],FMT_DATETIME)-datetime.strptime(data['date_from'],FMT_DATETIME)).days+1
|
||||
duration=(datetime.strptime(data['date_to'],FMT_DATETIME)-datetime.strptime(data['date_from'],FMT_DATETIME)).seconds/3600
|
||||
data['duration']=duration
|
||||
return data
|
||||
|
||||
def onchange_dateto(self,context={}):
|
||||
data=context['data']
|
||||
data['duration']=(datetime.strptime(data['date_to'],FMT_DATETIME)-datetime.strptime(data['date_from'],FMT_DATETIME)).days+1
|
||||
data['duration']=(datetime.strptime(data['date_to'],FMT_DATETIME)-datetime.strptime(data['date_from'],FMT_DATETIME)).seconds/3600
|
||||
return data
|
||||
|
||||
def gen_visit(self,ids,context):
|
||||
obj=self.browse(ids)[0]
|
||||
time_stop=obj.date_to[11:]
|
||||
#time_stop=obj.date_to[11:]
|
||||
days=[
|
||||
obj.monday and 1 or 0,
|
||||
obj.tuesday and 2 or 0,
|
||||
|
@ -86,29 +97,46 @@ class GenVisit(Model):
|
|||
print("days ", days)
|
||||
if not days:
|
||||
raise Exception("Please select Day")
|
||||
duration=datetime.strptime(obj.date_to,FMT_DATETIME)-datetime.strptime(obj.date_from,FMT_DATETIME)
|
||||
for day in range(duration.days+1):
|
||||
date_from=(datetime.strptime(obj.date_from,FMT_DATETIME)+timedelta(days=day)).strftime(FMT_DATETIME)
|
||||
date_to="%s %s" % (obj.date_from[0:10],time_stop)
|
||||
#duration=datetime.strptime(obj.date_to,FMT_DATETIME)-datetime.strptime(obj.date_from,FMT_DATETIME)
|
||||
# loop patient
|
||||
visit_vals=[]
|
||||
date_from=datetime.strptime(obj.date_from,FMT_DATETIME)
|
||||
date_to=datetime.strptime(obj.date_to,FMT_DATETIME)
|
||||
#total_days=(date_to-date_from).days
|
||||
for line in obj.lines:
|
||||
# loop days in weekend
|
||||
for day in days:
|
||||
ntoday=1
|
||||
day_total=(date_to-date_from).days+ntoday
|
||||
for weekday in days:
|
||||
wd=date_from.weekday()
|
||||
start_date=date_from
|
||||
while wd != weekday-1:
|
||||
start_date+=timedelta(days=1)
|
||||
wd=start_date.weekday()
|
||||
|
||||
#XXX should gen only in scoop
|
||||
if start_date.strftime(FMT_DATE) > date_to.strftime(FMT_DATE):
|
||||
continue
|
||||
count=0
|
||||
while count < day_total:
|
||||
tmp=start_date+timedelta(days=count)
|
||||
vals={
|
||||
'patient_id': line.patient_id.id,
|
||||
'doctor_id': obj.doctor_id.id,
|
||||
'nurse_id': obj.nurse_id.id,
|
||||
'cycle_id': obj.cycle_id.id,
|
||||
'time_start': date_from,
|
||||
'time_stop': date_to,
|
||||
'time_start': "%s %s" % (tmp.strftime(FMT_DATE),date_from.strftime(FMT_DATETIME)[11:]),
|
||||
'time_stop': "%s %s" % (tmp.strftime(FMT_DATE),date_to.strftime(FMT_DATETIME)[11:]),
|
||||
'state': 'draft',
|
||||
}
|
||||
visit_vals.append(vals)
|
||||
count+=7
|
||||
start_date=tmp
|
||||
|
||||
if visit_vals:
|
||||
dom=[]
|
||||
dom.append(['time_start','>=','%s %s'%(obj.date_from[0:10],' 00:00:00')])
|
||||
dom.append(['time_stop','<=','%s %s'%(obj.date_to[0:10],' 23:59:59')])
|
||||
dom.append(['time_start','>=','%s %s'%(date_from.strftime(FMT_DATE)[0:10],' 00:00:00')])
|
||||
dom.append(['time_stop','<=','%s %s'%(start_date.strftime(FMT_DATE)[0:10],' 23:59:59')])
|
||||
# search patient
|
||||
dom.append(['state','=','draft'])
|
||||
patient_ids=[visit['patient_id'] for visit in visit_vals]
|
||||
|
@ -118,7 +146,7 @@ class GenVisit(Model):
|
|||
visit_ids=visit_obj.search(dom)
|
||||
# delete old visit (same duration)
|
||||
visit_obj.delete(visit_ids)
|
||||
for vas in visit_vals:
|
||||
for vals in visit_vals:
|
||||
visit_obj.create(vals)
|
||||
|
||||
return {
|
||||
|
|
|
@ -1,119 +0,0 @@
|
|||
import time
|
||||
|
||||
from netforce.model import Model, fields, get_model
|
||||
|
||||
class HDReport(Model):
|
||||
_name="clinic.hd.report"
|
||||
_string="HD Report"
|
||||
_transient=True
|
||||
|
||||
_fields={
|
||||
"date": fields.Date("Start-Date"),
|
||||
#"time_start": fields.DateTime("Time start",required=False,search=True),
|
||||
#"time_stop": fields.DateTime("Time stop",required=False,search=True),
|
||||
"cycle_id": fields.Many2One("clinic.cycle","Cycle"),
|
||||
}
|
||||
|
||||
_defaults={
|
||||
'date': lambda *a: time.strftime("%Y-%m-%d"),
|
||||
#'time_start': lambda *a: time.strftime("%Y-%m-%d"),
|
||||
#'time_stop': lambda *a: time.strftime("%Y-%m-%d"),
|
||||
}
|
||||
|
||||
_order="cycle_id desc"
|
||||
|
||||
|
||||
def get_report_data(self,ids,context={}):
|
||||
PATIENT_TYPE={
|
||||
"mg":"Medical Government",
|
||||
"sc":"Social Security",
|
||||
"nhso":"NHSO (30฿)",
|
||||
"personal": "Personal",
|
||||
"others": "Others",
|
||||
}
|
||||
#time_start=time.strftime("%Y-%m-%d")
|
||||
#time_stop=time.strftime("%Y-%m-%d")
|
||||
date=time.strftime("%Y-%m-%d")
|
||||
dom=[]
|
||||
dom.append(['state','=','completed'])
|
||||
if ids:
|
||||
obj=self.browse(ids)[0]
|
||||
if obj.date:
|
||||
date=obj.date
|
||||
if obj.cycle_id:
|
||||
dom.append([
|
||||
'cycle_id','=',obj.cycle_id.id,
|
||||
])
|
||||
dom.append(['time_start', ">=", obj.date+"00:00:00"])
|
||||
dom.append(['time_stop', "<=", obj.date+"23:59:59"])
|
||||
print("dom ", dom)
|
||||
lines=[]
|
||||
cycles=[]
|
||||
index=0
|
||||
no_patient=0
|
||||
for hd_case in get_model("clinic.hd.case").search_browse(dom,order="cycle_id.sequence"):
|
||||
patient_type=hd_case.patient_id.type
|
||||
patient_type=PATIENT_TYPE.get(patient_type)
|
||||
dialyzer_name=hd_case.dialyzers.id
|
||||
dialyzer_name=DIALYZER_NAME.get(dialyzer_name)
|
||||
cycle_name=hd_case.cycle_id.name or ""
|
||||
show_cycle=False
|
||||
if not cycle_name in cycles:
|
||||
cycles.append(cycle_name)
|
||||
show_cycle=True
|
||||
if index > 1:
|
||||
vals={
|
||||
'color': 'success',
|
||||
'show_cycle': False,
|
||||
'cycle' : "",
|
||||
'patient': "",
|
||||
'no_patient': no_patient,
|
||||
'patient_type' : "",
|
||||
'doctor' : "",
|
||||
'total' : "",
|
||||
'rc_no' : "",
|
||||
'dialyzer_name' : "",
|
||||
'nurse' : "",
|
||||
}
|
||||
lines.append(vals)
|
||||
no_patient=1
|
||||
else:
|
||||
no_patient+=1
|
||||
index+=1
|
||||
vals={
|
||||
'show_cycle': show_cycle,
|
||||
'cycle' : cycle_name,
|
||||
'patient': hd_case.patient_id.name,
|
||||
'patient_type' : patient_type,
|
||||
'no_patient': 0,
|
||||
'doctor' : hd_case.doctor_id.name,
|
||||
'total' : hd_case.fee,
|
||||
'rc_no' : hd_case.number,
|
||||
'dialyzer' : dialyzer_name,
|
||||
'nurse' : hd_case.nurse_id.name,
|
||||
}
|
||||
lines.append(vals)
|
||||
|
||||
# XXX
|
||||
if lines:
|
||||
vals={
|
||||
'color': 'success',
|
||||
'show_cycle': False,
|
||||
'cycle' : "",
|
||||
'patient': "",
|
||||
'no_patient': no_patient,
|
||||
'patient_type' : "",
|
||||
'doctor' : "",
|
||||
'total' : "",
|
||||
'rc_no' : "",
|
||||
'dialyzer_name' : "",
|
||||
'nurse' : "",
|
||||
}
|
||||
lines.append(vals)
|
||||
|
||||
data={
|
||||
'lines': lines,
|
||||
}
|
||||
return data
|
||||
|
||||
HDReport.register()
|
|
@ -14,16 +14,6 @@ class Visit(Model):
|
|||
_name_field="number"
|
||||
_multi_company=True
|
||||
|
||||
def _get_visit_late(self,ids,context={}):
|
||||
res={}
|
||||
datenow=time.strftime("%Y-%m-%d")
|
||||
for obj in self.browse(ids):
|
||||
late=0
|
||||
if datenow > (obj.date_visit or '') and obj.state=='waiting_treatment':
|
||||
late=1
|
||||
res[obj.id]=late
|
||||
return res
|
||||
|
||||
_fields={
|
||||
"number": fields.Char("Number",required=True,search=True),
|
||||
"time_start": fields.DateTime("Time Start",required=True),
|
||||
|
@ -32,12 +22,11 @@ class Visit(Model):
|
|||
"doctor_id": fields.Many2One("clinic.doctor","Doctor",search=True),
|
||||
"nurse_id": fields.Many2One("clinic.nurse","Nurse",search=True),
|
||||
"department_id": fields.Many2One("clinic.department", "Department",search=True),
|
||||
"state": fields.Selection([("draft","Draft"),("waiting_treatment","Waiting Treatment"),('treatment','Treatment'),("cancelled","Cancelled")],"Status",required=True),
|
||||
"comments": fields.One2Many("message","related_id","Comments"),
|
||||
"company_id": fields.Many2One("company","Company"),
|
||||
'hd_cases': fields.One2Many('clinic.hd.case','visit_id',"HD Cases",readonly=True),
|
||||
"cycle_id": fields.Many2One("clinic.cycle","Cycle"),
|
||||
"state": fields.Selection([("draft","Draft"),("waiting_treatment","Waiting Treatment"),('treatment','Treatment'),("cancelled","Cancelled")],"Status",required=True),
|
||||
"state": fields.Selection([["draft","Draft"],["confirmed","Confirmed"],["cancelled","Cancelled"]],"Status",required=True),
|
||||
"comments": fields.One2Many("message","related_id","Comments"),
|
||||
}
|
||||
|
||||
|
@ -97,21 +86,18 @@ class Visit(Model):
|
|||
number=self._get_number(context)
|
||||
vals={
|
||||
'number': number,
|
||||
'state': 'waiting_treatment',
|
||||
'state': 'confirmed',
|
||||
}
|
||||
obj.write(vals)
|
||||
|
||||
def do_treatment(self,ids,context={}):
|
||||
hd_case_obj=get_model("clinic.hd.case")
|
||||
dt=datetime
|
||||
datenow=dt.now().strftime("%Y-%m-%d")
|
||||
#dt=datetime
|
||||
#datenow=dt.now().strftime("%Y-%m-%d")
|
||||
obj=self.browse(ids)[0]
|
||||
date_visit=obj.time_start[0:10]
|
||||
#date_visit=obj.time_start[0:10]
|
||||
# cannot treatment if current date is not same visit date
|
||||
if date_visit!=datenow:
|
||||
raise Exception("Today is not treament date!")
|
||||
#if date_visit!=datenow:
|
||||
#raise Exception("Today is not treament date!")
|
||||
|
||||
#include_fee=obj.patient_id.type in ('mg','sc','nhso') and True or False
|
||||
vals={
|
||||
'patient_id': obj.patient_id.id,
|
||||
'doctor_id': obj.doctor_id.id,
|
||||
|
@ -122,12 +108,22 @@ class Visit(Model):
|
|||
'cycle_id' : obj.cycle_id.id,
|
||||
'visit_id': obj.id,
|
||||
'cycle_id': obj.cycle_id.id,
|
||||
#'fee': include_fee and 1500.00 or 0.0,
|
||||
'fee_type': obj.patient_id.type,
|
||||
'lines':[],
|
||||
'gm_lines':[],
|
||||
'dialyzers': [],
|
||||
'state': 'in_progress',
|
||||
}
|
||||
products=get_model("product").search_browse([['code','=','FEE']])
|
||||
for product in products:
|
||||
vals['gm_lines'].append(('create',{
|
||||
'product_id': product.id,
|
||||
'description': product.name or "",
|
||||
'qty': 1,
|
||||
'price': product.sale_price or 0.0,
|
||||
'amount': product.sale_price or 0.0,
|
||||
'uom_id': product.uom_id.id,
|
||||
}))
|
||||
|
||||
patient_type={
|
||||
"mg":"Medical Government",
|
||||
|
@ -150,7 +146,6 @@ class Visit(Model):
|
|||
break
|
||||
|
||||
hd_case_id=hd_case_obj.create(vals)
|
||||
obj.write({"state":"treatment"})
|
||||
return {
|
||||
'next': {
|
||||
'name': 'clinic_hd_case',
|
||||
|
@ -240,4 +235,16 @@ class Visit(Model):
|
|||
data['time_stop']=(datetime.strptime(time_start,FMT_DATE)+timedelta(seconds=seconds)).strftime(FMT_DATE)
|
||||
return data
|
||||
|
||||
def to_draft(self,ids,context={}):
|
||||
obj=self.browse(ids)[0]
|
||||
for hd_case in obj.hd_cases:
|
||||
# XXX
|
||||
hd_case.write({
|
||||
'state': 'draft',
|
||||
})
|
||||
hd_case.delete()
|
||||
obj.write({
|
||||
'state': 'draft',
|
||||
})
|
||||
|
||||
Visit.register()
|
||||
|
|
Loading…
Reference in New Issue