2017-06-11 17:35:26 +00:00
|
|
|
import time
|
2017-06-09 20:07:54 +00:00
|
|
|
from netforce.model import Model, fields, get_model
|
2017-06-11 17:35:26 +00:00
|
|
|
from netforce.access import get_active_user, set_active_user
|
|
|
|
'''
|
|
|
|
lines:
|
|
|
|
patient, location -> text
|
|
|
|
patient:
|
|
|
|
share location
|
|
|
|
'''
|
2017-06-09 20:07:54 +00:00
|
|
|
|
|
|
|
class NewPatient(Model):
|
|
|
|
_name="new.patient"
|
|
|
|
_transient=True
|
|
|
|
|
|
|
|
_fields={
|
|
|
|
'name': fields.Char("Patient Name", required=True),
|
2017-06-11 17:35:26 +00:00
|
|
|
'date': fields.Date("Date"),
|
2017-06-09 20:07:54 +00:00
|
|
|
'lines': fields.One2Many("new.patient.line","new_id","Lines"),
|
|
|
|
'state': fields.Selection([['step1','Step1'],['step2','Step2']], 'State'),
|
2017-06-11 17:35:26 +00:00
|
|
|
|
|
|
|
'location_from_id': fields.Many2One("clinic.department","From Location"),
|
|
|
|
'location_to_id': fields.Many2One("clinic.department","To Location"),
|
2017-06-09 20:07:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
_defaults={
|
|
|
|
'state': 'step1',
|
2017-06-11 17:35:26 +00:00
|
|
|
'date': lambda *a: time.strftime("%Y-%m-%d")
|
2017-06-09 20:07:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
def find_patient(self, ids, context={}):
|
2017-06-11 17:35:26 +00:00
|
|
|
user_id=get_active_user()
|
|
|
|
set_active_user(1)
|
|
|
|
|
2017-06-09 20:07:54 +00:00
|
|
|
obj=self.browse(ids)[0]
|
|
|
|
get_model("new.patient.line").delete([l.id for l in obj.lines])
|
|
|
|
lines=[]
|
|
|
|
cond=[
|
|
|
|
['name','ilike',obj.name],
|
|
|
|
]
|
2017-06-11 17:35:26 +00:00
|
|
|
for patient in get_model("clinic.patient").search_browse(cond+[["dispose","=",True]]):
|
2017-06-09 20:07:54 +00:00
|
|
|
vals={
|
2017-06-11 17:35:26 +00:00
|
|
|
'patient_id': patient.id,
|
|
|
|
'department_id': patient.department_id.id,
|
|
|
|
'patient_name': patient.name,
|
|
|
|
'department_name': patient.department_id.name,
|
2017-06-09 20:07:54 +00:00
|
|
|
}
|
|
|
|
lines.append(('create',vals))
|
|
|
|
if not lines:
|
|
|
|
for patient_id in get_model("clinic.patient").search(cond):
|
|
|
|
return {
|
|
|
|
'next': {
|
|
|
|
'name': "clinic_patient",
|
|
|
|
"mode": "form",
|
|
|
|
"active_id": patient_id,
|
|
|
|
},
|
|
|
|
'flash': "ผู้ป่วยนี้มีอยู่แล้วในระบบ",
|
|
|
|
}
|
2017-06-11 17:35:26 +00:00
|
|
|
|
|
|
|
if len(lines)==1:
|
|
|
|
lines[0][1]['choose']=True
|
2017-06-09 20:07:54 +00:00
|
|
|
obj.write({
|
|
|
|
'lines': lines,
|
|
|
|
})
|
|
|
|
|
2017-06-11 17:35:26 +00:00
|
|
|
set_active_user(user_id)
|
2017-06-09 20:07:54 +00:00
|
|
|
|
|
|
|
def step1(self, ids, context={}):
|
|
|
|
obj=self.browse(ids)[0]
|
|
|
|
res=obj.find_patient()
|
|
|
|
if res:
|
|
|
|
return res
|
|
|
|
obj.write({
|
|
|
|
'state': 'step2',
|
|
|
|
})
|
|
|
|
|
|
|
|
def back_step1(self, ids, context={}):
|
|
|
|
obj=self.browse(ids)[0]
|
|
|
|
obj.write({
|
|
|
|
'state': 'step1',
|
|
|
|
})
|
|
|
|
print("back step1")
|
|
|
|
|
|
|
|
def step2(self, ids, context={}):
|
|
|
|
print("step2")
|
2017-06-11 17:35:26 +00:00
|
|
|
location_to_id=get_model("clinic.patient")._get_department(context)
|
|
|
|
user_id=get_active_user()
|
|
|
|
set_active_user(1)
|
|
|
|
|
2017-06-09 20:07:54 +00:00
|
|
|
obj=self.browse(ids)[0]
|
|
|
|
if not obj.lines:
|
|
|
|
res=obj.name.split(" ")
|
|
|
|
fname=''
|
|
|
|
lname=''
|
|
|
|
if len(res)>1:
|
|
|
|
fname=res[0]
|
|
|
|
lname=res[1]
|
|
|
|
else:
|
|
|
|
fname=obj.name
|
|
|
|
return {
|
|
|
|
'next': {
|
|
|
|
'name': 'clinic_patient',
|
|
|
|
'mode': 'form',
|
|
|
|
'defaults': {
|
|
|
|
'first_name': fname,
|
|
|
|
'last_name': lname,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else:
|
|
|
|
select_lines=[]
|
|
|
|
for line in obj.lines:
|
|
|
|
if line.choose:
|
|
|
|
select_lines.append(line)
|
|
|
|
if not select_lines:
|
|
|
|
raise Exception("Please choose patient!")
|
|
|
|
if len(select_lines)>1:
|
|
|
|
raise Exception("Can not select patient more than 1!")
|
2017-06-11 17:35:26 +00:00
|
|
|
|
|
|
|
line=[line for line in obj.lines if line.choose][0]
|
|
|
|
patient=line.patient_id
|
|
|
|
patient_id=patient.id
|
|
|
|
|
|
|
|
#default location from
|
|
|
|
#1. find in patient profile
|
|
|
|
location_code=patient.location.split(",")[-1]
|
|
|
|
location_from_id=None
|
|
|
|
for location_id in get_model("clinic.department").search([['code','=',location_code]]):
|
|
|
|
location_from_id=location_id
|
2017-06-09 20:07:54 +00:00
|
|
|
obj.write({
|
|
|
|
'state': 'step3',
|
2017-06-11 17:35:26 +00:00
|
|
|
'location_from_id': location_from_id,
|
|
|
|
'location_to_id': location_to_id,
|
2017-06-09 20:07:54 +00:00
|
|
|
})
|
2017-06-11 17:35:26 +00:00
|
|
|
set_active_user(user_id)
|
2017-06-09 20:07:54 +00:00
|
|
|
|
|
|
|
def back_step2(self, ids, context={}):
|
|
|
|
obj=self.browse(ids)[0]
|
|
|
|
obj.write({
|
|
|
|
'state': 'step2',
|
|
|
|
})
|
|
|
|
print("back step2")
|
|
|
|
|
2017-06-11 17:35:26 +00:00
|
|
|
def confirm(self, ids, context={}):
|
|
|
|
user_id=get_active_user()
|
|
|
|
set_active_user(1)
|
|
|
|
|
2017-06-09 20:07:54 +00:00
|
|
|
obj=self.browse(ids)[0]
|
|
|
|
line=[line for line in obj.lines if line.choose][0]
|
|
|
|
patient=line.patient_id
|
2017-06-11 17:35:26 +00:00
|
|
|
|
|
|
|
#share location here
|
|
|
|
|
|
|
|
location=patient.location.split(",")+[obj.location_to_id.code or '']
|
|
|
|
sloc=list(set(location))
|
|
|
|
location=','.join([loc for loc in sloc if loc])
|
|
|
|
patient.write({
|
|
|
|
'location': location,
|
|
|
|
})
|
|
|
|
|
|
|
|
set_active_user(user_id)
|
|
|
|
|
2017-06-09 20:07:54 +00:00
|
|
|
patient_id=patient.id
|
2017-06-11 17:35:26 +00:00
|
|
|
|
|
|
|
vals={
|
|
|
|
'patient_id': patient_id,
|
2017-06-12 17:51:25 +00:00
|
|
|
'patient_type_id': patient.type_id.id,
|
2017-06-11 17:35:26 +00:00
|
|
|
'location_from_id': obj.location_from_id.id,
|
|
|
|
'location_to_id': obj.location_to_id.id,
|
|
|
|
'state': 'new',
|
|
|
|
'date': obj.date,
|
|
|
|
}
|
|
|
|
|
|
|
|
get_model("clinic.patient.move").create(vals)
|
|
|
|
|
|
|
|
patient.write({
|
|
|
|
'dispose': False,
|
|
|
|
})
|
|
|
|
|
2017-06-09 20:07:54 +00:00
|
|
|
return {
|
|
|
|
'next': {
|
2017-06-11 17:35:26 +00:00
|
|
|
'name': 'clinic_patient',
|
2017-06-09 20:07:54 +00:00
|
|
|
'mode': 'form',
|
2017-06-11 17:35:26 +00:00
|
|
|
'active_id': patient.id,
|
|
|
|
},
|
|
|
|
'flash': "New patient successful!",
|
2017-06-09 20:07:54 +00:00
|
|
|
}
|
|
|
|
|
2017-06-11 17:35:26 +00:00
|
|
|
|
2017-06-09 20:07:54 +00:00
|
|
|
NewPatient.register()
|