diff --git a/netforce_clinic/actions/clinic_patient_move.xml b/netforce_clinic/actions/clinic_patient_move.xml
new file mode 100644
index 0000000..da016fd
--- /dev/null
+++ b/netforce_clinic/actions/clinic_patient_move.xml
@@ -0,0 +1,13 @@
+
+ Patient Moves
+ multi_view
+ clinic.patient.move
+ [
+ ["All",[]],
+ ["New",[["state","=","new"]]],
+ ["Move",[["state","=","move"]]],
+ ["Dispose",[["state","=","dispose"]]]
+ ]
+ list,form
+ clinic_menu
+
diff --git a/netforce_clinic/layouts/clinic_menu.xml b/netforce_clinic/layouts/clinic_menu.xml
index 875bc87..8b660ae 100644
--- a/netforce_clinic/layouts/clinic_menu.xml
+++ b/netforce_clinic/layouts/clinic_menu.xml
@@ -12,6 +12,7 @@
-
+
diff --git a/netforce_clinic/layouts/clinic_patient_form.xml b/netforce_clinic/layouts/clinic_patient_form.xml
index 8a6a94d..3b7c342 100644
--- a/netforce_clinic/layouts/clinic_patient_form.xml
+++ b/netforce_clinic/layouts/clinic_patient_form.xml
@@ -2,7 +2,8 @@
@@ -113,16 +114,16 @@
-
+
-
+
-
+
@@ -173,4 +174,7 @@
+
+
+
diff --git a/netforce_clinic/layouts/clinic_patient_move_form.xml b/netforce_clinic/layouts/clinic_patient_move_form.xml
new file mode 100644
index 0000000..4b4daf4
--- /dev/null
+++ b/netforce_clinic/layouts/clinic_patient_move_form.xml
@@ -0,0 +1,8 @@
+
diff --git a/netforce_clinic/layouts/clinic_patient_move_list.xml b/netforce_clinic/layouts/clinic_patient_move_list.xml
new file mode 100644
index 0000000..8b5a134
--- /dev/null
+++ b/netforce_clinic/layouts/clinic_patient_move_list.xml
@@ -0,0 +1,8 @@
+
+
+
+
+
+
+
+
diff --git a/netforce_clinic/models/patient.py b/netforce_clinic/models/patient.py
index 239b348..41b02e2 100644
--- a/netforce_clinic/models/patient.py
+++ b/netforce_clinic/models/patient.py
@@ -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()
diff --git a/netforce_clinic/models/patient_move.py b/netforce_clinic/models/patient_move.py
index 992c736..49bfae5 100644
--- a/netforce_clinic/models/patient_move.py
+++ b/netforce_clinic/models/patient_move.py
@@ -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()
diff --git a/netforce_clinic/models/staff.py b/netforce_clinic/models/staff.py
index 4156209..346ce95 100644
--- a/netforce_clinic/models/staff.py
+++ b/netforce_clinic/models/staff.py
@@ -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):