planing visit

conv_bal
watcha.h 2014-10-05 15:29:21 +07:00
parent 5fb4bef0b9
commit 12a365c2d6
10 changed files with 212 additions and 26 deletions

View File

@ -2,7 +2,7 @@
<head>
<field name="state"/>
<button string="Options" dropdown="1">
<item string="Journal Report" method="journal_report"/>
<item string="New Visit" method="new_visit"/>
</button>
</head>
<group span="6" columns="1">
@ -35,6 +35,17 @@
</list>
</field>
</tab>
<tab string="New Visit">
<separator string="Click Options-> New Visit"/>
<field name="planes" nolabel="1" domain="[['state','=','open']]">
<list>
<field name="date" onchange="onchange_dateplane"/>
<field name="time_start"/>
<field name="time_stop"/>
<field name="state"/>
</list>
</field>
</tab>
<tab string="Notes">
<field name="wh_start"/>
<field name="wh_stop"/>
@ -50,7 +61,7 @@
</tab>
</tabs>
<separator string="Other Expenses"/>
<field name="lines" count="4" nolabel="1">
<field name="lines" count="3" nolabel="1">
<list>
<field name="product_id" onchange="onchange_product"/>
<field name="description"/>

View File

@ -1,4 +1,4 @@
<!--<calendar model="clinic.visit" states='waiting_treatment' date_field="visit_date" colors='{"#090":[["cycle","=",1]],"#2400ff":[["cycle","=",2]],"#ebff00":[["cycle","=",3]],"#f20000":[["cycle","=",4]]}'>-->
<!--<calendar model="clinic.visit" states='waiting_treatment' date_field="date_visit" colors='{"#090":[["cycle","=",1]],"#2400ff":[["cycle","=",2]],"#ebff00":[["cycle","=",3]],"#f20000":[["cycle","=",4]]}'>-->
<calendar model="clinic.visit" states='waiting_treatment' start_field="time_start" end_field="time_stop" colors='{"#090":[["cycle","=",1]],"#2400ff":[["cycle","=",2]],"#ebff00":[["cycle","=",3]],"#f20000":[["cycle","=",4]]}'>
<field name="patient_id"/>
<field name="cycle"/>

View File

@ -10,21 +10,29 @@
<tab string="General">
<group span="6" columns="1">
<field name="number"/>
<field name="visit_date"/>
<field name="date_visit" onchange="onchange_date_visit"/>
<field name="cycle"/>
</group>
<group span="6" columns="1">
<field name="patient_id" onchange="onchange_patient"/>
<field name="doctor_id"/>
<field name="nurse_id"/>
<field name="doctor_id" attrs='{"required":[["state","=","waiting_treatment"]]}'/>
<field name="nurse_id" attrs='{"required":[["state","=","waiting_treatment"]]}'/>
<field name="department_id"/>
</group>
</tab>
<tab string="Planing">
<field name="time_start"/>
<field name="time_stop"/>
<field name="time_start" attrs='{"required":[["state","=","waiting_treatment"]]}'/>
<field name="time_stop" attrs='{"required":[["state","=","waiting_treatment"]]}'/>
<field name="time_use" onchange="onchange_timeuse"/>
<separator string="Apply to"/>
<separator string="Next Visit"/>
<field name="planes" nolabel="1">
<list>
<field name="date" onchange="onchange_dateplane"/>
<field name="time_start"/>
<field name="time_stop"/>
<field name="state"/>
</list>
</field>
</tab>
</tabs>
<group attrs='{"invisible": [["state","not in",["waiting_treatment"]]]}'>

View File

@ -1,7 +1,7 @@
<list model="clinic.visit" colors='{"#EF4D4D":[["late_visit","=",1]]}'>
<field name="late_visit" invisible="1"/>
<field name="number"/>
<field name="visit_date"/>
<field name="date_visit"/>
<field name="cycle"/>
<field name="patient_id"/>
<field name="doctor_id"/>

View File

@ -8,7 +8,6 @@ from . import doctor
from . import nurse
from . import visit
from . import hd_case
#from . import hd_case_dialyzer
from . import hd_case_line
from . import dialyzer
from . import dialyzer_line
@ -24,3 +23,4 @@ from . import input_line
from . import file_sheet
from . import payment
from . import import_payment
from . import visit_plan

View File

@ -1,5 +1,5 @@
import time
from datetime import datetime
from datetime import datetime, timedelta
from netforce.model import Model, fields, get_model
from netforce.utils import get_data_path
@ -55,6 +55,7 @@ class HDcase(Model):
"time_start": fields.DateTime("Time start",required=True,search=True),
"time_stop": fields.DateTime("Time stop",required=True,search=True),
"date": fields.Date("Date Treatment",required=True),
'planes': fields.One2Many("clinic.visit.plane","hd_case_id","Planning"),
}
def _get_number(self,context={}):
@ -163,7 +164,7 @@ class HDcase(Model):
if not uom:
raise Exception("Unit not found in uom")
obj=self.browse(ids[0])
due_date=obj.date_start[0:10]
due_date=obj.date[0:10]
# XXX
context['type']='out'
context['inv_type']='invoice'
@ -368,5 +369,105 @@ class HDcase(Model):
else:
data['fee']=0.0
return data
def new_visit(self,ids,context={}):
obj=self.browse(ids[0])
skip_plan_id=0
for plane in obj.planes:
if plane.state=='close':
continue
break
# XXX
if not plane or plane.state=='close':
raise Exception("No Planing")
print("found plane ",plane)
vals={
'date_visit': plane.date,
'time_start': plane.time_start,
'time_stop': plane.time_stop,
'patient_id': obj.patient_id.id,
'doctor_id': obj.doctor_id.id,
'nurse_id': obj.nurse_id.id,
'department_id': obj.department_id.id,
'planes': [],
'dialyzers': [],
#'state': 'waiting_treatment',
'state': 'draft', # XXX need to gen new doc
}
plane.write({
'state': 'close',
})
visit_id=get_model("clinic.visit").create(vals)
visit=get_model('clinic.visit').browse(visit_id)
skip_plan_id=plane.id
# copy remaining plane to new visit
new_planes=[]
for pl in obj.planes:
# XXX
if skip_plan_id==pl.id:
continue
if pl.state=='close':
continue
print("pl state ", pl.state)
line={
'date': pl.date,
'time_start': pl.time_start,
'time_stop': pl.time_stop,
'visit_id': visit_id,
}
new_planes.append(('create',line))
new_dialyzers=[]
for dlz in obj.dialyzers:
if dlz.use_time > dlz.dialyzer_id.max_use_time:
continue
use_time=(dlz.use_time or 0)+1
line={
"visit_id": visit_id,
"dialyzer_id": dlz.dialyzer_id.id,
"description": dlz.description,
"use_time": use_time,
"max_use_time": dlz.max_use_time,
"member_type": dlz.member_type,
"dialyzer_type": dlz.dialyzer_type,
"bid_flow_rate": dlz.bid_flow_rate,
"ultrafittration": dlz.ultrafittration,
}
new_dialyzers.append(('create',line))
vals={
'planes': new_planes,
'dialyzers': new_dialyzers,
}
visit.write(vals)
return {
'next': {
'name': "clinic_visit",
'mode': 'form',
'active_id': visit_id,
},
'flash': "New visit is created",
}
def onchange_dateplane(self,context={}):
data=context["data"]
path=context["path"]
line=get_data_path(data,path,parent=True)
start_date=line.get("date")
if not start_date:
return {}
timenow=time.strftime("%H:%M:%S")
timevisit=timenow
# XXX
timevisit=data['time_start'][11:20]
fmt_date="%Y-%m-%d %H:%M:%S"
fix_hrs=data['total_time'] or 0 # XXX
time_start=datetime.strptime("%s %s"%(start_date,timevisit),fmt_date)
seconds=fix_hrs*3600
time_stop=time_start+timedelta(seconds=seconds)
line['time_start']=time_start.strftime(fmt_date)
line['time_stop']=time_stop.strftime(fmt_date)
if not line.get('state'):
line['state']='open'
return data
HDcase.register()

View File

@ -19,7 +19,7 @@ class Visit(Model):
datenow=time.strftime("%Y-%m-%d")
for obj in self.browse(ids):
late=0
if datenow > obj.visit_date and obj.state=='waiting_treatment':
if datenow > obj.date_visit and obj.state=='waiting_treatment':
late=1
res[obj.id]=late
return res
@ -35,12 +35,13 @@ class Visit(Model):
"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"),
'time_use': fields.Integer("Fix Hr"),
'time_use': fields.Integer("Fix Hour"),
'late_visit': fields.Integer("Late Vist",function="_get_visit_late"),
"dialyzers": fields.One2Many("clinic.dialyzer.line","visit_id","Dialyzers"),
"visit_date": fields.Date("Visit Date",required=True,search=True),
"date_visit": fields.Date("Visit Date",required=True,search=True),
"time_start": fields.DateTime("Time Start"),
"time_stop": fields.DateTime("Time Stop"),
'planes': fields.One2Many("clinic.visit.plane","visit_id","Planning"),
}
def _get_number(self,context={}):
@ -79,7 +80,7 @@ class Visit(Model):
_defaults={
"state": "draft",
"cycle": "1",
'visit_date': lambda *a: time.strftime("%Y-%m-%d"),
'date_visit': lambda *a: time.strftime("%Y-%m-%d"),
'time_start': _get_time_start,
'time_stop': _get_time_stop,
"number": "/",
@ -110,7 +111,7 @@ class Visit(Model):
obj=self.browse(ids)[0]
# cannot treatment if current date is not same visit date
if obj.visit_date!=datenow:
if obj.date_visit!=datenow:
raise Exception("Today is not treament date!")
if not obj.dialyzers:
raise Exception("Please select dialyzer!")
@ -163,6 +164,11 @@ class Visit(Model):
dlz.write({
'hd_case_id': hd_case_id,
})
for plan in obj.planes:
plan.write({
'hd_case_id': hd_case_id,
})
obj.write({"state":"treatment"})
return {
'next': {
@ -186,7 +192,7 @@ class Visit(Model):
patient_id=data['patient_id']
visits=self.search_browse([['patient_id','=',patient_id]],order="number desc")
if visits:
#print([(v.id, v.visit_date,v.cycle) for v in visits])
#print([(v.id, v.date_visit,v.cycle) for v in visits])
visit=visits[0]
data['doctor_id']=visit.doctor_id.id
data['department_id']=visit.department_id.id
@ -242,7 +248,7 @@ class Visit(Model):
cycle_list={'1': 'One','2': 'Two','3': 'Tree','4': 'Four'}
data={
'number': obj.number,
'visit_date': obj.visit_date,
'date_visit': obj.date_visit,
'department_name': obj.department_id.name or "",
'patient_name': obj.patient_id.name or "",
'doctor_name': obj.doctor_id.name or "",
@ -283,4 +289,39 @@ class Visit(Model):
data['time_stop']=time_stop.strftime(fmt_date)
return data
def onchange_date_visit(self,context={}):
data=context["data"]
timenow=time.strftime("%Y-%m-%d")
date_visit=data['date_visit']
fmt_date="%Y-%m-%d %H:%M:%S"
time_start=datetime.datetime.strptime("%s %s"%(date_visit,timenow),fmt_date)
time_use=data['time_use']
seconds=(time_use or 1)*3600
time_stop=time_start+datetime.timedelta(seconds=seconds)
data['time_stop']=time_stop.strftime(fmt_date)
return data
def onchange_dateplane(self,context={}):
data=context["data"]
path=context["path"]
line=get_data_path(data,path,parent=True)
start_date=line.get("date")
if not start_date:
return {}
timenow=time.strftime("%H:%M:%S")
timevisit=timenow
# XXX
timevisit=data['time_start'][11:20]
fmt_date="%Y-%m-%d %H:%M:%S"
fix_hrs=data['time_use'] or 0
time_start=datetime.datetime.strptime("%s %s"%(start_date,timevisit),fmt_date)
seconds=fix_hrs*3600
time_stop=time_start+datetime.timedelta(seconds=seconds)
line['time_start']=time_start.strftime(fmt_date)
line['time_stop']=time_stop.strftime(fmt_date)
if not line.get('state'):
line['state']='open'
return data
Visit.register()

View File

@ -0,0 +1,22 @@
from netforce.model import Model, fields
class VisitPlane(Model):
_name="clinic.visit.plane"
_string="Visit Plan"
_fieldname="visit_id"
_fields={
'visit_id': fields.Many2One("clinic.visit","Visit"),
'hd_case_id': fields.Many2One("clinic.hd.case","HD Case"),
"date": fields.Date("Date"),
"time_start": fields.DateTime("Time Start"),
"time_stop": fields.DateTime("Time Stop"),
"state": fields.Selection([("open","Open"),("close","Close")],"Status"),
'active': fields.Boolean("Active"), # to hide
}
_defaults={
'state': 'open',
'active': True,
}
VisitPlane.register()

Binary file not shown.

View File

@ -12,7 +12,7 @@
- load default data
- one2many
- visit
-> split date and time
-> split date and time ->ok
-> state
- draft
- confirmed
@ -26,17 +26,20 @@
- print visit -> ok
- treament
-
- visit planing
- find visit of patient which state is close
- print invoice
- time start/stop
- pay for normal person
-> how ???
- make payment
- time start/stop -> ok
- only time
- date treament
- date treament ->ok
- color (check state)
- if fail -> red
- cancelled
- make next appointment
- make payment
- make next appointment -> ok
- state
- ready to treatment
- paid -> no because not realte to accounting