diff --git a/netforce_clinic/actions/clinic_gen_visit.xml b/netforce_clinic/actions/clinic_gen_visit.xml
new file mode 100644
index 0000000..5d26d99
--- /dev/null
+++ b/netforce_clinic/actions/clinic_gen_visit.xml
@@ -0,0 +1,6 @@
+
+ Generate Visit
+ form_popup
+ clinic.gen.visit
+ _popup
+
diff --git a/netforce_clinic/actions/view_hdcase.xml b/netforce_clinic/actions/view_hdcase.xml
deleted file mode 100644
index 46799de..0000000
--- a/netforce_clinic/actions/view_hdcase.xml
+++ /dev/null
@@ -1,5 +0,0 @@
-
- method
- clinic.hd.case
- view_hdcase
-
diff --git a/netforce_clinic/layouts/clinic_gen_visit_form.xml b/netforce_clinic/layouts/clinic_gen_visit_form.xml
new file mode 100644
index 0000000..797a0a8
--- /dev/null
+++ b/netforce_clinic/layouts/clinic_gen_visit_form.xml
@@ -0,0 +1,22 @@
+
diff --git a/netforce_clinic/layouts/clinic_patient_form.xml b/netforce_clinic/layouts/clinic_patient_form.xml
index af25ed4..391ea12 100644
--- a/netforce_clinic/layouts/clinic_patient_form.xml
+++ b/netforce_clinic/layouts/clinic_patient_form.xml
@@ -2,7 +2,7 @@
@@ -82,9 +82,6 @@
-
-
-
diff --git a/netforce_clinic/layouts/clinic_patient_list.xml b/netforce_clinic/layouts/clinic_patient_list.xml
index b723099..bbf504a 100644
--- a/netforce_clinic/layouts/clinic_patient_list.xml
+++ b/netforce_clinic/layouts/clinic_patient_list.xml
@@ -1,4 +1,7 @@
+
+
+
diff --git a/netforce_clinic/models/__init__.py b/netforce_clinic/models/__init__.py
index 0e6df59..a5fb461 100644
--- a/netforce_clinic/models/__init__.py
+++ b/netforce_clinic/models/__init__.py
@@ -29,3 +29,5 @@ from . import dialyzer_line
from . import import_payment
from . import file_sheet
from . import cycle
+from . import gen_visit
+from . import gen_visit_line
diff --git a/netforce_clinic/models/__init__.py~ b/netforce_clinic/models/__init__.py~
deleted file mode 100644
index b97e624..0000000
--- a/netforce_clinic/models/__init__.py~
+++ /dev/null
@@ -1,36 +0,0 @@
-from . import comorbidity
-from . import morbidity
-from . import education
-from . import setting
-from . import graduation
-from . import nation
-from . import race
-from . import cycle
-from . import cause_chronic
-from . import schedule
-from . import patient
-from . import patient_schedule
-from . import patient_cause_line
-from . import patient_comorbidity_line
-from . import patient_morbidity_line
-from . import department
-from . import doctor
-from . import nurse
-from . import visit
-from . import visit_plan
-from . import report_hd
-from . import hd_case
-from . import hd_case_line
-from . import hd_case_discont
-from . import dialyzer
-from . import report_dialyzer_drop
-from . import department
-from . import education
-from . import setting
-from . import graduation
-from . import nation
-from . import race
-from . import cause_chronic
-from . import dialyzer_line
-from . import import_payment
-from . import file_sheet
diff --git a/netforce_clinic/models/gen_visit.py b/netforce_clinic/models/gen_visit.py
new file mode 100644
index 0000000..e4180fc
--- /dev/null
+++ b/netforce_clinic/models/gen_visit.py
@@ -0,0 +1,133 @@
+from datetime import datetime, timedelta
+
+from netforce.access import get_active_user
+from netforce.model import Model, fields, get_model
+
+FMT_DATE="%Y-%m-%d"
+FMT_DATETIME="%Y-%m-%d %H:%M:%S"
+
+class GenVisit(Model):
+ _name="clinic.gen.visit"
+ _transient=True
+
+ def _get_duration(self,ids,context={}):
+ res={}
+ for obj in self.browse(ids):
+ duration=datetime.strptime(obj.date_to,FMT_DATETIME)-datetime.strptime(obj.date_from,FMT_DATETIME)
+ res[obj.id]=duration.days
+ return res
+
+ _fields={
+ 'date_from': fields.DateTime("From", required=True),
+ 'date_to': fields.DateTime("To", required=True),
+ 'cycle_id': fields.Many2One("clinic.cycle","Cycle", required=True),
+ 'lines': fields.One2Many("clinic.gen.visit.line","gen_id","Lines"),
+ 'monday': fields.Boolean("Monday"),
+ 'tuesday': fields.Boolean("Tuesdays"),
+ 'wednesday': fields.Boolean("Wednesdays"),
+ 'thursday': fields.Boolean("Thursdays"),
+ 'friday': fields.Boolean("Fridays"),
+ 'doctor_id': fields.Many2One("clinic.doctor","Doctor"),
+ 'nurse_id': fields.Many2One("clinic.nurse","Nurse"),
+ 'duration': fields.Integer("Duration", function="_get_duration"),
+ }
+
+ def _get_lines(self,context={}):
+ ids=context.get("ids")
+ lines=[{'patient_id': id} for id in ids]
+ return lines
+
+ def _get_nurse(self,context={}):
+ user_id=get_active_user()
+ print("user_id ",user_id)
+ nurse_ids=get_model("clinic.nurse").search([['user_id','=',user_id]])
+ if nurse_ids:
+ return nurse_ids[0]
+ return None
+
+ _defaults={
+ 'lines': _get_lines,
+ 'date_from': lambda *a: datetime.now().strftime(FMT_DATETIME),
+ 'date_to': lambda *a: datetime.now().strftime(FMT_DATETIME),
+ 'nurse_id': _get_nurse,
+ 'duration': 1,
+ }
+
+ def onchange_time(self,context={}):
+ data=context['data']
+ cycle_id=data['cycle_id']
+ duration=1
+ if cycle_id:
+ cycle=get_model('clinic.cycle').browse(cycle_id)
+ duration=cycle.duration or 0
+ seconds=duration*3600
+ date_from=data['date_from']
+ date_to=(datetime.strptime(date_from,FMT_DATETIME)+timedelta(seconds=seconds)).strftime(FMT_DATETIME)
+ data['date_to']='%s %s'%(data['date_to'][0:10],date_to[11:])
+ data['duration']=(datetime.strptime(data['date_to'],FMT_DATETIME)-datetime.strptime(data['date_from'],FMT_DATETIME)).days+1
+ return data
+
+ def onchange_dateto(self,context={}):
+ data=context['data']
+ data['duration']=(datetime.strptime(data['date_to'],FMT_DATETIME)-datetime.strptime(data['date_from'],FMT_DATETIME)).days+1
+ return data
+
+ def gen_visit(self,ids,context):
+ obj=self.browse(ids)[0]
+ time_stop=obj.date_to[11:]
+ days=[
+ obj.monday and 1 or 0,
+ obj.tuesday and 2 or 0,
+ obj.wednesday and 3 or 0,
+ obj.thursday and 4 or 0,
+ obj.friday and 5 or 0,
+ ]
+ days=[day for day in days if day]
+ print("days ", days)
+ if not days:
+ raise Exception("Please select Day")
+ duration=datetime.strptime(obj.date_to,FMT_DATETIME)-datetime.strptime(obj.date_from,FMT_DATETIME)
+ for day in range(duration.days+1):
+ date_from=(datetime.strptime(obj.date_from,FMT_DATETIME)+timedelta(days=day)).strftime(FMT_DATETIME)
+ date_to="%s %s" % (obj.date_from[0:10],time_stop)
+ # loop patient
+ visit_vals=[]
+ for line in obj.lines:
+ # loop days in weekend
+ for day in days:
+ vals={
+ 'patient_id': line.patient_id.id,
+ 'doctor_id': obj.doctor_id.id,
+ 'nurse_id': obj.nurse_id.id,
+ 'cycle_id': obj.cycle_id.id,
+ 'time_start': date_from,
+ 'time_stop': date_to,
+ 'state': 'draft',
+ }
+ visit_vals.append(vals)
+ if visit_vals:
+ dom=[]
+ dom.append(['time_start','>=','%s %s'%(obj.date_from[0:10],' 00:00:00')])
+ dom.append(['time_stop','<=','%s %s'%(obj.date_to[0:10],' 23:59:59')])
+ # search patient
+ dom.append(['state','=','draft'])
+ patient_ids=[visit['patient_id'] for visit in visit_vals]
+ dom.append(['patient_id', 'in', tuple(patient_ids)])
+ print("dom ", dom)
+ visit_obj=get_model('clinic.visit')
+ visit_ids=visit_obj.search(dom)
+ # delete old visit (same duration)
+ visit_obj.delete(visit_ids)
+ for vas in visit_vals:
+ visit_obj.create(vals)
+
+ return {
+ 'next': {
+ 'name': 'clinic_patient',
+ 'mode': 'list',
+ },
+ 'flash': 'Generate OK',
+ }
+
+GenVisit.register()
+
diff --git a/netforce_clinic/models/gen_visit_line.py b/netforce_clinic/models/gen_visit_line.py
new file mode 100644
index 0000000..e9bfd01
--- /dev/null
+++ b/netforce_clinic/models/gen_visit_line.py
@@ -0,0 +1,13 @@
+from netforce.model import Model, fields, get_model
+
+class GenVisitLine(Model):
+ _name="clinic.gen.visit.line"
+ _transient=True
+
+ _fields={
+ 'gen_id': fields.Many2One("clinic.gen.visit","gen_id","Gen Visit"),
+ 'patient_id': fields.Many2One("clinic.patient","Patient"),
+ }
+
+GenVisitLine.register()
+
diff --git a/netforce_clinic/models/hd_case.py b/netforce_clinic/models/hd_case.py
index 04a74f4..c2940d0 100644
--- a/netforce_clinic/models/hd_case.py
+++ b/netforce_clinic/models/hd_case.py
@@ -424,14 +424,6 @@ class HDcase(Model):
"fee_amount": amt,
}
return vals
-
- def view_hdcase(self,ids,context={}):
- return {
- 'name': 'clinic_hd_case',
- 'mode': 'form',
- 'form_view_xml': 'clinic_hd_case_form',
- 'active_id': ids[0],
- }
def delete(self,ids,context={}):
for obj in self.browse(ids):
diff --git a/netforce_clinic/models/patient.py b/netforce_clinic/models/patient.py
index 6ee521e..b34b69a 100644
--- a/netforce_clinic/models/patient.py
+++ b/netforce_clinic/models/patient.py
@@ -76,7 +76,6 @@ class Patient(Model):
"hd_cases": fields.One2Many("clinic.hd.case","patient_id","HD Cases"),
"partner_id": fields.Many2One("partner","Contact"),
"dialyzers": fields.One2Many("clinic.dialyzer","patient_id","Dialyzers"),
- 'schedules': fields.Many2Many("clinic.schedule","Schedule"),
}
def _get_number(self,context={}):
diff --git a/netforce_clinic/models/visit.py b/netforce_clinic/models/visit.py
index 127062e..4953a64 100644
--- a/netforce_clinic/models/visit.py
+++ b/netforce_clinic/models/visit.py
@@ -26,8 +26,8 @@ class Visit(Model):
_fields={
"number": fields.Char("Number",required=True,search=True),
- "time_start": fields.DateTime("Time Start"),
- "time_stop": fields.DateTime("Time Stop"),
+ "time_start": fields.DateTime("Time Start",required=True),
+ "time_stop": fields.DateTime("Time Stop",required=True),
"patient_id": fields.Many2One("clinic.patient","Patient",required=True,search=True),
"doctor_id": fields.Many2One("clinic.doctor","Doctor",search=True),
"nurse_id": fields.Many2One("clinic.nurse","Nurse",search=True),