xxxxxx
parent
13d03040a4
commit
49aa5d555d
|
@ -6,7 +6,7 @@
|
||||||
</button>
|
</button>
|
||||||
</head>
|
</head>
|
||||||
<field name="number"/>
|
<field name="number"/>
|
||||||
<field name="type"/>
|
<field name="type" onchange="onchange_type"/>
|
||||||
<field name="name"/>
|
<field name="name"/>
|
||||||
<field name="reg_date"/>
|
<field name="reg_date"/>
|
||||||
<field name="job"/>
|
<field name="job"/>
|
||||||
|
|
|
@ -3,6 +3,14 @@ import time
|
||||||
from netforce.model import Model, fields, get_model
|
from netforce.model import Model, fields, get_model
|
||||||
from netforce.access import get_active_company, get_active_user, set_active_user
|
from netforce.access import get_active_company, get_active_user, set_active_user
|
||||||
|
|
||||||
|
PATIENT_TYPE={
|
||||||
|
"mg":"Medical Government",
|
||||||
|
"sc":"Social Security",
|
||||||
|
"nhso":"NHSO (30฿)",
|
||||||
|
"personal": "Personal",
|
||||||
|
"others": "Others",
|
||||||
|
}
|
||||||
|
|
||||||
class Patient(Model):
|
class Patient(Model):
|
||||||
_name="clinic.patient"
|
_name="clinic.patient"
|
||||||
_string="Patient"
|
_string="Patient"
|
||||||
|
@ -21,7 +29,7 @@ class Patient(Model):
|
||||||
return res # -> {1: 30, 2: 45,.....}
|
return res # -> {1: 30, 2: 45,.....}
|
||||||
|
|
||||||
_fields={
|
_fields={
|
||||||
"type": fields.Selection([("mg","Medical Govement"),("sc","Social Security"),("nhso","NHSO (30฿)"),("personal","Personal"),("others","Others")],"Patient Type",required=False),
|
"type": fields.Selection([("mg","Medical Government"),("sc","Social Security"),("nhso","NHSO (30฿)"),("personal","Personal"),("others","Others")],"Patient Type",required=True),
|
||||||
"number": fields.Char("Patient No.",required=True,search=True),
|
"number": fields.Char("Patient No.",required=True,search=True),
|
||||||
"name": fields.Char("Name",required=True,search=True),
|
"name": fields.Char("Name",required=True,search=True),
|
||||||
"reg_date": fields.Date("Register Date",required=False,search=True),
|
"reg_date": fields.Date("Register Date",required=False,search=True),
|
||||||
|
@ -94,22 +102,65 @@ class Patient(Model):
|
||||||
obj=self.browse(ids)[0]
|
obj=self.browse(ids)[0]
|
||||||
obj.write({"state":"voided"})
|
obj.write({"state":"voided"})
|
||||||
|
|
||||||
|
def get_partner_id(self,patient_type,data):
|
||||||
|
partner_obj=get_model("partner")
|
||||||
|
categ_name=PATIENT_TYPE.get(patient_type)
|
||||||
|
categ_ids=get_model("partner.categ").search([['name','=',categ_name]])
|
||||||
|
if not categ_ids:
|
||||||
|
raise Exception("Category: %s not found"%categ_name)
|
||||||
|
partner_id=None
|
||||||
|
if patient_type in ("mg","sc","nhso"):
|
||||||
|
partner_obj=get_model("partner")
|
||||||
|
for partner in partner_obj.search_browse([]):
|
||||||
|
if partner.categ_id.id in categ_ids:
|
||||||
|
partner_id=partner.id
|
||||||
|
print("Found partner ", partner.name, " ", partner.id)
|
||||||
|
break
|
||||||
|
if not partner_id:
|
||||||
|
name=data.get("name","")
|
||||||
|
partner_ids=partner_obj.search([['name','=',name]])
|
||||||
|
if not partner_ids:
|
||||||
|
partner_id=partner_obj.create({
|
||||||
|
'name': name,
|
||||||
|
'last_name': name,
|
||||||
|
'type': 'person'
|
||||||
|
})
|
||||||
|
print("create new partner ", name)
|
||||||
|
else:
|
||||||
|
partner_id=partner_ids[0]
|
||||||
|
return partner_id
|
||||||
|
|
||||||
|
def onchange_type(self,context={}):
|
||||||
|
data=context['data']
|
||||||
|
patient_type=data['type']
|
||||||
|
partner_id=None
|
||||||
|
if patient_type:
|
||||||
|
partner_id=self.get_partner_id(patient_type,data)
|
||||||
|
data['partner_id']=partner_id
|
||||||
|
return data
|
||||||
|
|
||||||
def create(self,vals,**kw):
|
def create(self,vals,**kw):
|
||||||
obj_id=super(Patient,self).create(vals,**kw)
|
obj_id=super(Patient,self).create(vals,**kw)
|
||||||
obj=self.browse(obj_id)
|
obj=self.browse(obj_id)
|
||||||
partner_id=get_model("partner").create({
|
partner_id=self.get_partner_id(patient_type=obj.type,data={'name': obj.name})
|
||||||
'name': obj.name,
|
|
||||||
'last_name': obj.name,
|
|
||||||
'type': 'person'
|
|
||||||
})
|
|
||||||
obj.write({
|
obj.write({
|
||||||
'partner_id': partner_id,
|
'partner_id': partner_id,
|
||||||
})
|
})
|
||||||
return obj_id
|
return obj_id
|
||||||
|
|
||||||
def delete(self,ids,context={}):
|
def delete(self,ids,context={}):
|
||||||
partner_ids=[obj.partner_id.id for obj in self.browse(ids)]
|
partner_ids=[]
|
||||||
|
for obj in self.browse(ids):
|
||||||
|
if obj.type not in ("mg","nhso","sc"):
|
||||||
|
partner_ids.append(obj.partner_id.id)
|
||||||
get_model("partner").delete(partner_ids)
|
get_model("partner").delete(partner_ids)
|
||||||
super().delete(ids)
|
super().delete(ids)
|
||||||
|
|
||||||
|
def write(self,ids,vals,**kw):
|
||||||
|
partner_id=vals.get('partner_id')
|
||||||
|
if not partner_id:
|
||||||
|
obj=self.browse(ids[0])
|
||||||
|
vals['partner_id']=self.get_partner_id(patient_type=obj.type,data={'name': obj.name})
|
||||||
|
super().write(ids,vals,**kw)
|
||||||
|
|
||||||
Patient.register()
|
Patient.register()
|
||||||
|
|
Loading…
Reference in New Issue