patient.move

fix_hdcase_sum
watcha.h 2017-09-19 19:10:32 +07:00
parent aa2448888d
commit b977b8ad48
8 changed files with 139 additions and 21 deletions

View File

@ -0,0 +1,13 @@
<action>
<field name="string">Patient Moves</field>
<field name="view_cls">multi_view</field>
<field name="model">clinic.patient.move</field>
<field name="tabs">[
["All",[]],
["New",[["state","=","new"]]],
["Move",[["state","=","move"]]],
["Dispose",[["state","=","dispose"]]]
]</field>
<field name="modes">list,form</field>
<field name="menu">clinic_menu</field>
</action>

View File

@ -12,6 +12,7 @@
</item>
<item string="Patients" perm="clinic_patient">
<item string="Patients" action="clinic_patient"/>
<item string="Patient Moves" action="clinic_patient_move"/>
<item string="Dialyzers" action="clinic_dialyzer"/>
<divider/>
<header string="SETTINGS"/>

View File

@ -2,7 +2,8 @@
<head>
<field name="type_id"/>
<button string="Options" dropdown="1">
<item string="Share" action="clinic_share_location"/>
<item string="Share" action="clinic_share_location" states="admit"/>
<item string="Dispose" method="dispose" confirm="Are you sure?" states="admit"/>
</button>
</head>
<field name="number"/>
@ -113,16 +114,16 @@
<tab string="Accounting" perm="clinic_patient_account">
<field name="partner_id" domain='[["is_patient","=","true"]]'/>
</tab>
<tab string="Dispose Info">
<tab string="Disposing">
<group>
<field name="dispose"/>
<!--<field name="dispose"/>-->
<field name="resign_date" attrs='{"required":[["dispose","=","true"]]}'/>
<field name="note" attrs='{"required":[["dispose","=","true"]]}'/>
<field name="state" invisible="1"/>
<field name="hn_no" invisible="1"/>
</group>
</tab>
<tab string="Log">
<tab string="Other info">
<group>
<field name="c_time"/>
<field name="w_time"/>
@ -173,4 +174,7 @@
<field name="documents"/>
<field name="comments"/>
</related>
<foot>
<button string="Active" method="do_active" type="success" attrs='{"invisible":[["state","!=","dispose"]]}'/>
</foot>
</form>

View File

@ -0,0 +1,8 @@
<form model="clinic.patient.move">
<field name="date"/>
<field name="state"/>
<field name="patient_id" onchange="onchange_patient"/>
<field name="patient_type_id"/>
<field name="location_from_id"/>
<field name="location_to_id"/>
</form>

View File

@ -0,0 +1,8 @@
<list model="clinic.patient.move">
<field name="date"/>
<field name="patient_id"/>
<field name="patient_type_id"/>
<field name="location_from_id"/>
<field name="location_to_id"/>
<field name="state"/>
</list>

View File

@ -3,6 +3,7 @@ import time
from netforce.model import Model, fields, get_model
from netforce.access import get_active_company, get_active_user, set_active_user
from netforce.database import get_connection
from netforce.utils import print_color
from . import utils
@ -10,6 +11,7 @@ class Patient(Model):
_name="clinic.patient"
_string="Patient"
_audit_log=True
_key=["number","name","branch_id"]
_multi_company=True
def _get_age(self,ids,context):
@ -271,7 +273,7 @@ class Patient(Model):
'dispose': False,
}
_sql_constraints=("clinic_patient_key_uniq","unique(name_check)","name should be unique"),
#_sql_constraints=("clinic_patient_key_uniq","unique(name_check)","name should be unique"),
def check_idcard(self,card_type,idcard=''):
res=True
@ -288,14 +290,11 @@ class Patient(Model):
elif len(idcard)!=13:
res=False
if not res:
raise Exception("Wrong ID Card!")
raise Exception("Wrong ID Card! %s/%s"%(len(idcard), 13))
def create(self, vals,**kw):
if 'card_no' in vals.keys():
self.check_idcard(vals.get("card_type",""),vals['card_no'])
obj_id=super().create(vals,**kw)
self.function_store([obj_id])
obj=self.browse(obj_id)
def create_contact(self, ids, context={}):
obj=self.browse(ids)[0]
partner_id=obj.partner_id
if not partner_id:
partner_name='%s %s'%(obj.first_name or "",obj.last_name or "") # XXX
@ -327,7 +326,40 @@ class Patient(Model):
obj.write({
'partner_id': partner_id,
})
return obj_id
print_color('contact created: %s'%partner_name,"green")
return
def create_patient_move(self, ids, context={}):
obj=self.browse(ids)[0]
cond=[
['date','=', time.strftime("%Y-%m-%d")],
['patient_id','=',obj.id],
]
#XXX
move_ids=get_model("clinic.patient.move").search(cond)
if move_ids:
get_model("clinic.patient.move").delete(move_ids)
vals={
'patient_id': obj.id,
'patient_type_id': obj.type_id.id,
'location_from_id': obj.department_id.id,
'location_to_id': obj.department_id.id,
"state": context.get('state') or "new",
}
get_model('clinic.patient.move').create(vals)
print_color('patient_move created: %s'%vals,"green")
def create(self, vals,**kw):
if 'card_no' in vals.keys():
self.check_idcard(vals.get("card_type",""),vals['card_no'])
new_id=super().create(vals,**kw)
self.function_store([new_id])
obj=self.browse(new_id)
self.create_contact([new_id])
self.create_patient_move([new_id])
#return to wizard patient.move
return new_id
def delete(self,ids,context={}):
partner_ids=[]
@ -359,8 +391,8 @@ class Patient(Model):
vals['cw_time']=time.strftime("%Y-%m-%d %H:%M:%S")
vals['cw_uid']=get_active_user()
#update type patient for pending hd case
if 'type_id' in vals.keys():
#update patient in hd case which state is condition below
for obj in self.browse(ids):
for hdcase in get_model('clinic.hd.case').search_browse([['patient_id','in',ids],['state','in',['draft','waiting_treatment']]]):
hdcase.write({
@ -376,6 +408,8 @@ class Patient(Model):
vals['state']='admit'
vals['rm_remain_visit']=False
vals['resign_date']=None
#XXX reset resign date
ctx={}
if 'active' in vals.keys():
if not vals['active']:
@ -460,10 +494,12 @@ class Patient(Model):
del vals['addresses']
else:
obj.simple_address()
# clear pending visit
if obj.rm_remain_visit or vals.get('rm_remain_visit'):
visit_ids=get_model('clinic.visit').search([['patient_id','=',obj.id],['state','in',('draft','pending')]])
get_model('clinic.visit').delete(visit_ids)
print('remove visit auto %s'%visit_ids)
super().write(ids,vals,**kw)
self.function_store(ids,context=ctx)
# update name of partner
@ -574,4 +610,25 @@ class Patient(Model):
#data['doctor_id']=None
return data
def dispose(self, ids, context={}):
obj=self.browse(ids)[0]
obj.write({
'dispose': True,
})
context['state']='dispose'
obj.create_patient_move(context)
def do_active(self, ids, context={}):
obj=self.browse(ids)[0]
obj.write({
'active': True,
'dispose': False,
})
context['state']='new'
obj.create_patient_move(context)
print('do_active')
Patient.register()

View File

@ -1,17 +1,43 @@
import time
from netforce.model import Model, fields
from netforce.model import Model, fields, get_model
class PatientMove(Model):
_name="clinic.patient.move"
_fields={
'patient_id': fields.Many2One('clinic.patient','Patient'),
'date': fields.DateTime("Date"),
'location_id': fields.Many2One("clinic.department","Department"),
'create_date': fields.DateTime("Create Date", required=True),
'date': fields.Date("Date", search=True, required=True),
'patient_id': fields.Many2One('clinic.patient','Patient', search=True, required=True),
'patient_type_id': fields.Many2One('clinic.patient.type','Patient Type', search=True, required=True),
'location_from_id': fields.Many2One("clinic.department","From Department", search=True, required=True),
'location_to_id': fields.Many2One("clinic.department","To Department", search=True, required=True),
"state": fields.Selection([['new','New'],["move","Move"],['dispose','Dispose']],'State'),
}
_defaults={
'date': lambda *a: time.strftime("%Y-%m-%d %H:%M:%S"),
'create_date': lambda *a: time.strftime("%Y-%m-%d %H:%M:%S"),
'date': lambda *a: time.strftime("%Y-%m-%d"),
"state": "new",
}
_order="date desc"
PatientMove()
_constraints=["check_location_status"]
def check_location_status(self, ids, context={}):
for obj in self.browse(ids):
if obj.state=='move' and obj.location_from_id.id == obj.location_to_id.id:
raise Exception("Can not move patient the same location!!")
elif obj.state in ('new','dispose') and obj.location_from_id.id != obj.location_to_id.id:
raise Exception("New/Dispose patient should be the same location!!")
def onchange_patient(self, context={}):
data=context['data']
patient_id=data['patient_id']
patient=get_model("clinic.patient").browse(patient_id)
data['patient_type_id']=patient.type_id.id
data['location_from_id']=patient.branch_id.id
return data
PatientMove.register()

View File

@ -7,6 +7,7 @@ class Staff(Model):
_name="clinic.staff"
_string="Staff"
_audit_log=True
_key=["number","name","branch_id"]
_multi_company=True
def _get_age(self,ids,context={}):
@ -251,7 +252,7 @@ class Staff(Model):
'location': _get_default_location,
}
_sql_constraints=("clinic_staff_key_uniq","unique(name_check)","name should be unique"),
#_sql_constraints=("clinic_staff_key_uniq","unique(name_check)","name should be unique"),
_order="date desc,number desc"
def create_contact(self,code,name):