124 lines
3.6 KiB
Python
124 lines
3.6 KiB
Python
from netforce.model import Model, fields, get_model
|
|
|
|
class NewPatient(Model):
|
|
_name="new.patient"
|
|
_transient=True
|
|
|
|
_fields={
|
|
'name': fields.Char("Patient Name", required=True),
|
|
'lines': fields.One2Many("new.patient.line","new_id","Lines"),
|
|
'state': fields.Selection([['step1','Step1'],['step2','Step2']], 'State'),
|
|
}
|
|
|
|
_defaults={
|
|
'state': 'step1',
|
|
}
|
|
|
|
def find_patient(self, ids, context={}):
|
|
obj=self.browse(ids)[0]
|
|
get_model("new.patient.line").delete([l.id for l in obj.lines])
|
|
lines=[]
|
|
cond=[
|
|
['name','ilike',obj.name],
|
|
]
|
|
for patient_id in get_model("clinic.patient").search(cond+[["dispose","=",True]]):
|
|
vals={
|
|
'patient_id': patient_id,
|
|
}
|
|
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': "ผู้ป่วยนี้มีอยู่แล้วในระบบ",
|
|
}
|
|
obj.write({
|
|
'lines': lines,
|
|
})
|
|
|
|
|
|
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")
|
|
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!")
|
|
obj.write({
|
|
'state': 'step3',
|
|
})
|
|
|
|
def back_step2(self, ids, context={}):
|
|
obj=self.browse(ids)[0]
|
|
obj.write({
|
|
'state': 'step2',
|
|
})
|
|
print("back step2")
|
|
|
|
def step3(self, ids, context={}):
|
|
obj=self.browse(ids)[0]
|
|
line=[line for line in obj.lines if line.choose][0]
|
|
patient=line.patient_id
|
|
patient_id=patient.id
|
|
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
|
|
return {
|
|
'next': {
|
|
'name': 'clinic_patient_move',
|
|
'mode': 'form',
|
|
'defaults': {
|
|
'patient_id': patient_id,
|
|
'location_from_id': location_from_id,
|
|
'state': 'new',
|
|
}
|
|
}
|
|
}
|
|
|
|
NewPatient.register()
|