copy nurse

conv_bal
watcha.h@almacom.co.th 2015-01-22 14:20:04 +07:00
parent f184eb6799
commit 0a3357826a
12 changed files with 160 additions and 101 deletions

View File

@ -1,16 +1,17 @@
<form model="clinic.cycle.item.copy" title="Load Nurses"> <form model="clinic.cycle.item.copy" title="Copy Nurses">
<group form_layout="stacked"> <group form_layout="stacked">
<field name="choice" onchange="onchange_choice" span="4"/> <field name="choice" onchange="onchange_choice" span="4"/>
<field name="item_copy_id" onchange="onchange_item" span="4"/> <field name="item_copy_id" onchange="onchange_item" attrs='{"required":[["choice","=","item"]]}' span="4"/>
<field name="schd_copy_id" onchange="onchange_schd" span="4"/> <field name="schd_copy_id" onchange="onchange_item" attrs='{"required":[["choice","=","schd"]]}' span="4"/>
<field name="cycle_item_id" span="2" invisible="1"/> <field name="cycle_item_id" span="2" invisible="1"/>
</group> </group>
<field name="lines" nolabel="1"> <field name="lines" nolabel="1">
<list noadd="1"> <list noadd="1">
<field name="nurse_id"/> <field name="nurse_id"/>
<field name="department_id"/>
</list> </list>
</field> </field>
<foot> <foot>
<button string="Load" type="success" method="load"/> <button string="OK" type="success" method="load"/>
</foot> </foot>
</form> </form>

View File

@ -3,8 +3,8 @@
<field name="state"/> <field name="state"/>
<button string="Options" dropdown="1"> <button string="Options" dropdown="1">
<!--<item string="Load Nurses" method="load_nurse_from_schedule" states='draft'/>--> <!--<item string="Load Nurses" method="load_nurse_from_schedule" states='draft'/>-->
<item string="Load Nurses" method="cycle_item_copy" states='draft'/> <item string="Copy Nurses" method="cycle_item_copy" states='draft'/>
<item string="Load HDCase" method="update_hdcase" states="draft" /> <item string="Recheck HD Case" method="update_hdcase" states="draft" />
<item string="View Schedule" method="view_schedule"/> <item string="View Schedule" method="view_schedule"/>
<item string="To Draft" method="to_draft" states="validated" /> <item string="To Draft" method="to_draft" states="validated" />
</button> </button>
@ -22,6 +22,7 @@
<list> <list>
<field name="nurse_id" domain='[["type","=","nurse"]]' onchange="onchange_nurse"/> <field name="nurse_id" domain='[["type","=","nurse"]]' onchange="onchange_nurse"/>
<field name="level_id"/> <field name="level_id"/>
<field name="state"/>
</list> </list>
</field> </field>
</tab> </tab>

View File

@ -4,7 +4,7 @@
<button string="Options" dropdown="1"> <button string="Options" dropdown="1">
<item string="Copy" action="clinic_schedule_copy"/> <item string="Copy" action="clinic_schedule_copy"/>
<item string="Get Nurse" action="clinic_load_nurses" states="draft"/> <item string="Get Nurse" action="clinic_load_nurses" states="draft"/>
<item string="Reset Item" method="clear" confirm="Are you sure to remove all item?" states="draft"/> <item string="Reset Nurse" method="clear" confirm="Are you sure to remove all item?" states="draft"/>
<item string="To Draft" method="to_draft" states="confirmed"/> <item string="To Draft" method="to_draft" states="confirmed"/>
</button> </button>
</head> </head>
@ -12,12 +12,12 @@
<tab string="General"> <tab string="General">
<group form_layout="stacked"> <group form_layout="stacked">
<field name="date" span="3" onchange="onchange_date"/> <field name="date" span="3" onchange="onchange_date"/>
<field name="department_id" span="3"/> <field name="branch_id" span="3" onchange="onchange_branch"/>
<field name="branch_id" span="3"/> <field name="department_id" domain='[["branch_id","=",branch_id]]' span="3"/>
<field name="lines" nolabel="1"> <field name="lines" nolabel="1">
<list> <list>
<field name="cycle_id"/> <field name="cycle_id"/>
<field name="nurse_id" onchange="onchange_nurse"/> <field name="nurse_id" onchange="onchange_nurse" domain='[["department_id","=",parent.department_id]]'/>
<field name="level_id"/> <field name="level_id"/>
<field name="note"/> <field name="note"/>
<field name="cycle_item_id" readonly="1"/> <field name="cycle_item_id" readonly="1"/>

View File

@ -1,12 +1,12 @@
<form model="clinic.visit.board"> <form model="clinic.visit.board">
<field name="date" span="2" mode="month" onchange="onchange_date"/> <field name="date" span="2" mode="month" onchange="onchange_date"/>
<field name="date_from" span="2"/> <field name="date_from" onchange="onchange_datefrom" span="2"/>
<field name="date_to" span="2"/> <field name="date_to" span="2"/>
<field name="cycle_id" span="2"/> <field name="cycle_id" span="2"/>
<field name="patient_id" span="2"/> <field name="patient_id" span="2"/>
<field name="doctor_id" span="2"/> <field name="doctor_id" span="2"/>
<field name="department_id" span="2"/> <field name="branch_id" onchange="onchange_branch" span="2"/>
<field name="branch_id" span="2"/> <field name="department_id" domain='[["branch_id","=",branch_id]]' span="2"/>
<button string='Confirm Visits' method="confirm" type="success" icon="arrow-right"/> <button string='Confirm Visits' method="confirm" type="success" icon="arrow-right"/>
<separator string="Note: Please Click 'Run Report' Before Confirm Visits"/> <separator string="Note: Please Click 'Run Report' Before Confirm Visits"/>
</form> </form>

View File

@ -23,16 +23,87 @@ class CycleItemCopy(Model):
'choice': 'item', 'choice': 'item',
} }
def update_line(self,context={}):
data=context['data']
lines=[]
if data['choice']=='item':
item=get_model("clinic.cycle.item").browse(data['item_copy_id'])
for line in item.lines:
nr=line.nurse_id
dpt=nr.department_id
lines.append({
'nurse_id':nr.id,
'department_id': dpt.id,
})
elif data['choice']=='schd':
item=get_model("clinic.cycle.item").browse(data['cycle_item_id'])
schd=get_model("clinic.schedule").browse(data['schd_copy_id'])
cycle=item.cycle_id
for line in schd.lines:
nr=line.nurse_id
dpt=nr.department_id
if cycle.id==line.cycle_id.id:
lines.append({
'nurse_id':nr.id,
'department_id': dpt.id,
})
else:
pass
return lines
def onchange_choice(self,context={}): def onchange_choice(self,context={}):
data=context['data'] data=context['data']
if data['choice']:
data['lines']=self.update_line(context=context)
return data return data
def onchange_item(self,context={}): def onchange_item(self,context={}):
data=context['data'] data=context['data']
data['lines']=self.update_line(context=context)
return data return data
def onchange_schd(self,context={}): def load(self,ids,context={}):
data=context['data'] obj=self.browse(ids)[0]
return data item=obj.cycle_item_id
for line in item.lines:
line.delete()
lines=[]
if obj.choice=='item':
for line in obj.item_copy_id.lines:
nr=line.nurse_id
lines.append(('create', {
'nurse_id': nr.id,
'level_id': nr.level_id.id,
'state': nr.state,
}))
elif obj.choice=='schd':
for line in obj.schd_copy_id.lines:
nr=line.nurse_id
cycle=line.cycle_id
if item.cycle_id.id==cycle.id:
lines.append(('create', {
'nurse_id': nr.id,
'level_id': nr.level_id.id,
'state': nr.state,
}))
else:
for line in obj.lines:
nr=line.nurse_id
lines.append(('create', {
'nurse_id': nr.id,
'level_id': nr.level_id.id,
'state': nr.state,
}))
item.write({
'lines': lines,
})
return {
'next': {
'name': 'clinic_cycle_item',
'mode': 'form',
'active_id': item.id,
},
'flash': 'Load Nurse Complete!',
}
CycleItemCopy.register() CycleItemCopy.register()

View File

@ -7,6 +7,7 @@ class CycleItemCopyLine(Model):
_fields={ _fields={
"item_copy_id": fields.Many2One("clinic.cycle.item.copy","Copy Item",required=True,on_delete="cascade"), "item_copy_id": fields.Many2One("clinic.cycle.item.copy","Copy Item",required=True,on_delete="cascade"),
'nurse_id': fields.Many2One("clinic.staff","Nurse",domain=[['type','=','nurse']]), 'nurse_id': fields.Many2One("clinic.staff","Nurse",domain=[['type','=','nurse']]),
'department_id': fields.Many2One("clinic.department","Department"),
} }

View File

@ -9,6 +9,7 @@ class CycleItemLine(Model):
'level_id': fields.Many2One("clinic.staff.level", "Level",), 'level_id': fields.Many2One("clinic.staff.level", "Level",),
'nurse_id': fields.Many2One("clinic.staff",'Nurse',domain=[['type','=','nurse']]), 'nurse_id': fields.Many2One("clinic.staff",'Nurse',domain=[['type','=','nurse']]),
'department_id': fields.Many2One("clinic.department","Department"), 'department_id': fields.Many2One("clinic.department","Department"),
"state": fields.Selection([["part_time","Part Time"],["full_time","Full Time"]],"Working Status",search=True),
} }
CycleItemLine.register() CycleItemLine.register()

View File

@ -7,38 +7,20 @@ from netforce.utils import get_data_path
class Schedule(Model): class Schedule(Model):
_name="clinic.schedule" _name="clinic.schedule"
_string="Schedule" _string="Schedule"
_field_name="date" _name_field="name"
_key=['name'] _key=['name']
def _get_name(self,ids,context={}): def _get_name(self,ids,context={}):
res={} res={}
for obj in self.browse(ids): for obj in self.browse(ids):
st="\n" # XXX count=len(obj.lines)
count=0 dpt=obj.department_id
for line in obj.lines: name='%s %s'%(obj.date, dpt.name or '')
nurse=line.nurse_id res[obj.id]='%s'%(name if count else 'Waiting planing')
level=line.level_id
cycle=line.cycle_id
st+='#%s %s %s\n'%(cycle.sequence,nurse.name,level.name or "")
count+=1
res[obj.id]='%s'%(st if count else 'No nurse')
return res
def _get_item(self,ids,context={}):
res={}
for obj in self.browse(ids):
cycle_id=None
if obj.cycle_id:
cycle_id=obj.cycle_id.id
item_ids=get_model("clinic.cycle.item").search([['cycle_id','=',cycle_id],['date','=',obj.time_start[0:10]]])
item_id=None
if item_ids:
item_id=item_ids[0]
res[obj.id]=item_id
return res return res
_fields={ _fields={
'name': fields.Char("Name", function="_get_name"), 'name': fields.Char("Name", function="_get_name",store=True),
"time_start": fields.DateTime("Time Start",required=True), "time_start": fields.DateTime("Time Start",required=True),
"time_stop": fields.DateTime("Time Stop",required=True), "time_stop": fields.DateTime("Time Stop",required=True),
'date': fields.Date("Date",required=True,search=True), 'date': fields.Date("Date",required=True,search=True),
@ -245,5 +227,18 @@ class Schedule(Model):
line['level_id']=nurse.level_id.id line['level_id']=nurse.level_id.id
return data return data
def create(self,vals,**kw):
id=super().create(vals,**kw)
self.function_store([id])
def write(self,ids,vals,**kw):
super().write(ids,vals,**kw)
self.function_store(ids)
def onchange_branch(self,context={}):
data=context['data']
data['department_id']=None
return data
Schedule.register() Schedule.register()

View File

@ -91,56 +91,12 @@ class ClinicSetting(Model):
return True return True
def run_script(self,ids,context={}): def run_script(self,ids,context={}):
db=get_connection() for item in get_model("clinic.cycle.item").search_browse([]):
db.execute(""" for line in item.lines:
update clinic_branch set active=True; nr=line.nurse_id
update clinic_department set active=True; line.write({
""") 'state': nr.state,
print("Done!")
return
obj=self.browse(ids)[0]
################ update sickbed #############
#sickbed: update department
for sb in get_model('clinic.sickbed').search_browse([]):
hdcs=sorted(sb.hd_cases, key=lambda a: a.id)
if hdcs:
hdc=hdcs[0]
#patient=hdc.patient_id
sb.write({
'department_id': hdc.department_id.id,
}) })
#print("Done!")
#return
#############################################
############### cycle item
for lc in get_model('clinic.labor.cost').search_browse([]):
lc.delete()
db=get_connection()
res=db.query("""
select cycle_item_id, nurse_id, level_id from clinic_cycle_item_nurse
""")
for rs in res:
item_id=rs['cycle_item_id']
nid=rs['nurse_id']
lid=rs['level_id']
if item_id:
item=get_model('clinic.cycle.item').browse(item_id)
item.write({
'lines': [('create',{'nurse_id': nid, 'level_id': lid})],
})
print('update ', item.name)
item.validate()
if item.department_id:
print("update department for nurse", nid)
get_model("clinic.staff").browse(nid).write({
'department_id': item.department_id.id,
})
#return
#############################################
print("Done!") print("Done!")
def reset_last_import(self,ids,context={}): def reset_last_import(self,ids,context={}):

View File

@ -218,6 +218,10 @@ class Visit(Model):
def get_schedule(date): def get_schedule(date):
dom=[] dom=[]
dom.append(['date','=',date]) dom.append(['date','=',date])
if branch:
dom.append(['branch_id','=',branch.id])
if department:
dom.append(['department_id','=',department.id])
schedule=None schedule=None
schedules=get_model("clinic.schedule").search_browse(dom) schedules=get_model("clinic.schedule").search_browse(dom)
if schedules: if schedules:
@ -239,14 +243,10 @@ class Visit(Model):
# clear old nurse in cycle item # clear old nurse in cycle item
item_id=item_ids[0] item_id=item_ids[0]
item=item_obj.browse(item_id) item=item_obj.browse(item_id)
if item.state!='draft':
# reset nurse
for nurse in item.lines:
nurse.delete()
# copy nurse from schedule # copy nurse from schedule(only draft)
item=item_obj.browse(item_id) item=item_obj.browse(item_id)
if item.state!='draft': if not item.lines and item.state=='draft':
schedule=get_schedule(date) schedule=get_schedule(date)
if schedule: if schedule:
for line in schedule.lines: for line in schedule.lines:
@ -255,9 +255,32 @@ class Visit(Model):
item_vals['lines'].append(('create',{ item_vals['lines'].append(('create',{
'nurse_id': nurse.id, 'nurse_id': nurse.id,
'level_id': nurse.level_id.id, 'level_id': nurse.level_id.id,
'state': nurse.state,
})) }))
item.write(item_vals) item.write(item_vals)
# copy nurse from previous cycle item
if not item.lines:
dom=[
['branch_id','=',branch.id],
['department_id','=',department.id],
]
for item2 in get_model("clinic.cycle.item").search_browse([]):
lines=[]
for line in item2.lines:
nr=line.nurse_id
lines.append(('create', {
'nurse_id': nr.id,
'level_id': nr.level_id.id,
'state': nr.state,
}))
if lines:
print("copy nurse from %s to %s"%(item2.name, item.name))
item.write({
'lines': lines,
})
break
obj.write({ obj.write({
'cycle_item_id': item_id, 'cycle_item_id': item_id,
}) })

View File

@ -319,6 +319,16 @@ class VisitBoard(Model):
data['date_to']="%s-%s-%s"%(year,month,total_day) data['date_to']="%s-%s-%s"%(year,month,total_day)
return data return data
def onchange_datefrom(self,context={}):
data=context['data']
data['date_to']=data['date_from']
return data
def onchange_branch(self,context={}):
data=context['data']
data['department_id']=None
return data
def confirm(self,ids,context={}): def confirm(self,ids,context={}):
obj=self.browse(ids)[0] obj=self.browse(ids)[0]
return { return {

View File

@ -5,7 +5,7 @@ todo:
- popup messagging -> Ask DJ - popup messagging -> Ask DJ
- modify message of log -> Ask DJ - modify message of log -> Ask DJ
- show image of staff - show image of staff
- copy old nurse from previous cycle item - copy old nurse from previous cycle item -> fixing
- multi confirm on visit board **** -> ok - multi confirm on visit board **** -> ok
======= =======
generate visit ใหม่ -> ok generate visit ใหม่ -> ok