clinic/netforce_clinic/models/clinic_visit.py

55 lines
1.9 KiB
Python

from netforce.model import Model, fields, get_model
from netforce.utils import get_data_path
import time
from netforce.access import get_active_user
from netforce.access import get_active_company
class Visit(Model):
_name="clinic.visit"
_string="Visit"
_audit_log=True
_name_field="number"
_multi_company=True
_fields={
"number": fields.Char("Number",required=True,search=True),
"patient_id": fields.Many2One("clinic.patient","Patients",required=True,search=True),
"doctor_id": fields.Many2One("clinic.doctor","Doctor",search=True),
"nurse_id": fields.Many2One("clinic.nurse","Nurse",search=True),
"date": fields.Date("Visit Date",required=True,search=True),
"department": fields.Char("Department",required=False,search=True),
"cycle": fields.Selection([("1","One"),("2","Two"),("3","Tree"),("4","Four")],"Cycle",required=True),
"state": fields.Selection([("pending","Pending"),("confirmed","Confirmed"),("canceled","Canceled")],"Status",required=True),
"comments": fields.One2Many("message","related_id","Comments"),
"company_id": fields.Many2One("company","Company"),
}
def _get_number(self,context={}):
while 1:
num=get_model("sequence").get_number("sale_order")
if not num:
return None
res=self.search([["number","=",num]])
if not res:
return num
get_model("sequence").increment("sale_order")
_defaults={
"state": "pending",
"number": _get_number,
"company_id": lambda *a: get_active_company(),
}
_order="date asc,cycle asc"
def confirmed(self,ids,context={}):
obj=self.browse(ids)[0]
obj.write({"state":"confirmed"})
def canceled(self,ids,context={}):
obj=self.browse(ids)[0]
obj.write({"state":"canceled"})
Visit.register()