diff --git a/netforce_clinic/actions/clinic_change_visit.xml b/netforce_clinic/actions/clinic_change_visit.xml
new file mode 100644
index 0000000..79be8ad
--- /dev/null
+++ b/netforce_clinic/actions/clinic_change_visit.xml
@@ -0,0 +1,6 @@
+
+ Change Visit
+ form_popup
+ clinic.change.visit
+ _popup
+
diff --git a/netforce_clinic/layouts/clinic_change_visit.xml b/netforce_clinic/layouts/clinic_change_visit.xml
new file mode 100644
index 0000000..885d014
--- /dev/null
+++ b/netforce_clinic/layouts/clinic_change_visit.xml
@@ -0,0 +1,14 @@
+
diff --git a/netforce_clinic/layouts/clinic_report_hd_case_summary.xml b/netforce_clinic/layouts/clinic_report_hd_case_summary.xml
index da9f5e0..7fe0860 100644
--- a/netforce_clinic/layouts/clinic_report_hd_case_summary.xml
+++ b/netforce_clinic/layouts/clinic_report_hd_case_summary.xml
@@ -5,4 +5,7 @@
+
+
+
diff --git a/netforce_clinic/layouts/clinic_visit_board.xml b/netforce_clinic/layouts/clinic_visit_board.xml
index 801b0b1..83549c4 100644
--- a/netforce_clinic/layouts/clinic_visit_board.xml
+++ b/netforce_clinic/layouts/clinic_visit_board.xml
@@ -7,6 +7,7 @@
+
diff --git a/netforce_clinic/layouts/clinic_visit_form.xml b/netforce_clinic/layouts/clinic_visit_form.xml
index 0294756..47181fe 100644
--- a/netforce_clinic/layouts/clinic_visit_form.xml
+++ b/netforce_clinic/layouts/clinic_visit_form.xml
@@ -36,6 +36,7 @@
+
diff --git a/netforce_clinic/models/__init__.py b/netforce_clinic/models/__init__.py
index 69ecfcf..a3c962e 100644
--- a/netforce_clinic/models/__init__.py
+++ b/netforce_clinic/models/__init__.py
@@ -134,5 +134,6 @@ from . import account_tax_component
from . import report_thai_wht_certif
from . import num2word
from . import province
+from . import change_visit
#from . import district
#from . import subdistrict
diff --git a/netforce_clinic/models/change_visit.py b/netforce_clinic/models/change_visit.py
new file mode 100644
index 0000000..3bfc8c0
--- /dev/null
+++ b/netforce_clinic/models/change_visit.py
@@ -0,0 +1,139 @@
+from netforce.model import Model, fields, get_model
+
+class ChangeVisit(Model):
+ _name="clinic.change.visit"
+ _transient=True
+
+ _fields={
+ "visit_id": fields.Many2One("clinic.visit","Visit",required=True,on_delete="cascade"),
+ "time_start": fields.DateTime("Start Time",required=True),
+ "time_stop": fields.DateTime("End Time",required=True),
+ "patient_id": fields.Many2One("clinic.patient","Patient",required=True,search=True,domain=[['state','=','admit']]),
+ "doctor_id": fields.Many2One("clinic.staff","Doctor", domain=[['type','=','doctor']],search=True),
+ "department_id": fields.Many2One("clinic.department", "Department",search=True),
+ 'branch_id': fields.Many2One("clinic.branch","Branch"),
+ "cycle_id": fields.Many2One("clinic.cycle","Cycle"),
+ 'visit_date': fields.Date('Date'),
+ 'note': fields.Text('Note'),
+ }
+
+ def default_get(self,field_names=None,context={},**kw):
+ print("clinic.change.visit.default")
+ #defaults=context.get("defaults",{})
+ refer_id=context.get("refer_id")
+ res={}
+ if refer_id:
+ refer_id=int(refer_id)
+ obj=get_model("clinic.visit").browse(refer_id)
+ res={
+ 'visit_id': refer_id,
+ 'patient_id': obj.patient_id.id,
+ 'doctor_id': obj.doctor_id.id,
+ 'department_id': obj.department_id.id,
+ 'branch_id': obj.department_id.branch_id.id,
+ 'cycle_id': obj.cycle_id.id,
+ 'time_start': obj.time_start,
+ 'time_stop': obj.time_stop,
+ 'visit_date': obj.visit_date,
+ }
+ print(res)
+ return res
+
+ def do_change(self,ids,context):
+ obj=self.browse(ids)[0]
+ dom=[
+ ['visit_date','=',obj.visit_date],
+ ['patient_id','=',obj.patient_id.id],
+ ['cycle_id','=',obj.cycle_id.id], #XXX
+ ['department_id','=',obj.department_id.id],
+ ]
+ res=get_model("clinic.visit").search(dom)
+ if res:
+ raise Exception("This visit already exist in the system!")
+ new_id=get_model("clinic.visit").create({
+ 'patient_id': obj.patient_id.id,
+ 'doctor_id': obj.doctor_id.id,
+ 'department_id': obj.department_id.id,
+ 'branch_id': obj.department_id.branch_id.id,
+ 'cycle_id': obj.cycle_id.id,
+ 'time_start': obj.time_start,
+ 'time_stop': obj.time_stop,
+ 'visit_date': obj.visit_date,
+ 'state': 'pending',
+ })
+ obj.visit_id.to_draft()
+ obj.visit_id.cancel()
+ visit=get_model("clinic.visit").browse(new_id)
+ return {
+ 'next': {
+ 'name': 'clinic_visit',
+ 'mode': 'form',
+ 'active_id': new_id,
+ },
+ 'flash': 'Copy visit %s to %s has been successfully'%(obj.visit_id.visit_date, visit.visit_date)
+ }
+
+ def onchange_date(self,context={}):
+ data=context['data']
+ date=data['visit_date']
+ time_start=data['time_start'][11:]
+ time_stop=data['time_stop'][11:]
+ data['time_start']='%s %s'%(date,time_start)
+ data['time_stop']='%s %s'%(date,time_stop)
+ return data
+
+ def onchange_department(self,context={}):
+ data=context['data']
+ dpt_id=data['department_id']
+ if dpt_id:
+ dpt=get_model("clinic.department").browse(dpt_id)
+ data['branch_id']=dpt.branch_id.id
+ return data
+
+ def onchange_cycle(self,context={}):
+ data=context['data']
+ cycle_id=data['cycle_id']
+ date=data['visit_date']
+ if not date:
+ date=data['time_start'][0:10]
+ if cycle_id:
+ cycle=get_model('clinic.cycle').browse(cycle_id)
+ data['time_start']=date+' %s:00'%cycle.time_start
+ data['time_stop']=date+' %s:00'%cycle.time_stop
+ return data
+
+ def onchange_datefrom(self,context={}):
+ data=context['data']
+ data['visit_date']=data['time_start'][0:10]
+ return data
+
+ def onchange_patient(self,context={}):
+ data=context['data']
+ patient_id=data['patient_id']
+ patient=get_model("clinic.patient").browse(patient_id)
+ doctor=patient.doctor_id
+ visits=self.search_browse([['patient_id','=',patient_id]],order="number desc")
+ if visits:
+ visit=visits[0]
+ department_id=None
+ if visit.department_id:
+ department_id=visit.department_id.id
+ elif patient.department_id:
+ department_id=patient.department_id.id
+ branch_id=None
+ if visit.branch_id:
+ branch_id=visit.branch_id.id
+ elif patient.branch_id:
+ branch_id=patient.branch_id.id
+ data['department_id']=department_id
+ data['branch_id']=branch_id
+ else:
+ department=patient.department_id
+ branch=patient.branch_id
+ data['department_id']=department.id
+ data['branch_id']=branch.id
+ data['doctor_id']=doctor.id
+ return data
+
+ChangeVisit.register()
+
diff --git a/netforce_clinic/models/hd_case_print.py b/netforce_clinic/models/hd_case_print.py
index bbe5e19..05e52cd 100644
--- a/netforce_clinic/models/hd_case_print.py
+++ b/netforce_clinic/models/hd_case_print.py
@@ -79,11 +79,6 @@ class HDCasePrint(Model):
next_month_str=utils.MONTHS['th_TH'][next_month]
prev_month_str=utils.MONTHS['th_TH'][prev_month]
- def encode_url(dom):
- dom='%s'%dom
- dom=urllib.quote(dom.encode('utf-8'))
- return dom
-
def replace_quote(dom=""):
return dom.replace("'","\"")
diff --git a/netforce_clinic/models/report_hd_case_summary.py b/netforce_clinic/models/report_hd_case_summary.py
index b5586bc..3c08699 100644
--- a/netforce_clinic/models/report_hd_case_summary.py
+++ b/netforce_clinic/models/report_hd_case_summary.py
@@ -302,4 +302,8 @@ class ReportHDCaseSummary(Model):
}
}
+ def export_pdf(self,ids,context={}):
+ raise Exception("TODO")
+ return
+
ReportHDCaseSummary.register()
diff --git a/netforce_clinic/models/visit.py b/netforce_clinic/models/visit.py
index 33443a5..15fe2ce 100644
--- a/netforce_clinic/models/visit.py
+++ b/netforce_clinic/models/visit.py
@@ -359,6 +359,7 @@ class Visit(Model):
'doctor_id': obj.doctor_id.id,
'nurse_id': obj.nurse_id.id,
'department_id': obj.department_id.id,
+ 'branch_id': obj.department_id.branch_id.id,
'cycle_id': obj.cycle_id.id,
'time_start': obj.time_start,
'time_stop': obj.time_stop,
diff --git a/netforce_clinic/models/visit_board.py b/netforce_clinic/models/visit_board.py
index b29dd00..e1f886e 100644
--- a/netforce_clinic/models/visit_board.py
+++ b/netforce_clinic/models/visit_board.py
@@ -18,7 +18,6 @@ HD_STATE={
"discountinued":"Discountinued",
"cancelled":"Cancelled"
}
-
DAYS={
'mon': 0,
'tue': 1,
@@ -44,6 +43,7 @@ class VisitBoard(Model):
'doctor_id': fields.Many2One("clinic.staff","Doctor",domain=[["type","=","doctor"]]),
'department_id': fields.Many2One("clinic.department","Department"),
'branch_id': fields.Many2One("clinic.branch","Branch"),
+ "state": fields.Selection([["draft","Draft"],['pending','Pending'],["confirmed","Confirmed"],["cancelled","Cancelled"]],"Status",required=True),
}
def default_get(self,field_names=None,context={},**kw):
@@ -70,7 +70,9 @@ class VisitBoard(Model):
'date_to': date_to,
'branch_id': branch_id,
'department_id': department_id,
+ 'state': 'pending',
}
+ print('clinic.visit.board.defaults ', defaults)
return res
def get_report_data(self,ids,context={}):
@@ -84,7 +86,7 @@ class VisitBoard(Model):
defaults=self.default_get(context=context)
department_id=defaults.get("department_id",None)
branch_id=defaults.get("branch_id",None)
- print('defaults ', defaults)
+ state=defaults.get("state",'pending')
if ids:
obj=self.browse(ids)[0]
date_from=obj.date_from
@@ -94,9 +96,10 @@ class VisitBoard(Model):
doctor_id=obj.doctor_id.id
department_id=obj.department_id.id
branch_id=obj.branch_id.id
+ state=obj.state
+ # auto generate visit day to day
def auto_gen_visit(dom=[]):
dom.append(['dispose','=',False])
- #dom.append(['walkin','=','no']) #XXX
def daterange(start_date, end_date):
for n in range(int ((end_date - start_date).days)):
yield start_date + timedelta(n)
@@ -107,7 +110,6 @@ class VisitBoard(Model):
return datetime.strptime(date_txt,"%Y-%m-%d")
except:
raise Exception("Wrong Format Date")
- # IMPROVE
# check day of week of this day
for date in daterange(convert_date(date_from),convert_date(date_to)+timedelta(days=1)):
weekday=date.weekday()
@@ -205,7 +207,14 @@ class VisitBoard(Model):
no=1
dpt={}
brch={}
+ if state=='pending':
+ dom+=[['state', 'in',[state,'confirmed']]]
+ else:
+ dom+=[['state', 'in',[state]]]
+ print('dom ', dom)
for visit in get_model("clinic.visit").search_browse(dom):
+ if visit.patient_id.id==1282:
+ print("OK ", visit.patient_id.name)
if visit.state in ('draft','pending'):
total_wait+=1
elif visit.state in ('confirmed'):
diff --git a/netforce_clinic/templates/report_visit.hbs b/netforce_clinic/templates/report_visit.hbs
index 83d20a2..1cbad8c 100644
--- a/netforce_clinic/templates/report_visit.hbs
+++ b/netforce_clinic/templates/report_visit.hbs
@@ -1,18 +1,3 @@
-
-
-