diff --git a/netforce_clinic/layouts/clinic_cycle_item_form.xml b/netforce_clinic/layouts/clinic_cycle_item_form.xml
index 431cd7b..7eab044 100644
--- a/netforce_clinic/layouts/clinic_cycle_item_form.xml
+++ b/netforce_clinic/layouts/clinic_cycle_item_form.xml
@@ -16,6 +16,20 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/netforce_clinic/layouts/clinic_cycle_item_list.xml b/netforce_clinic/layouts/clinic_cycle_item_list.xml
index d7c6422..beca47f 100644
--- a/netforce_clinic/layouts/clinic_cycle_item_list.xml
+++ b/netforce_clinic/layouts/clinic_cycle_item_list.xml
@@ -1,5 +1,5 @@
-
+
diff --git a/netforce_clinic/layouts/clinic_personal_form.xml b/netforce_clinic/layouts/clinic_personal_form.xml
index 9379ab7..e0ac19d 100644
--- a/netforce_clinic/layouts/clinic_personal_form.xml
+++ b/netforce_clinic/layouts/clinic_personal_form.xml
@@ -31,8 +31,8 @@
-
-
+
+
@@ -47,6 +47,7 @@
+
diff --git a/netforce_clinic/layouts/clinic_personal_level_form.xml b/netforce_clinic/layouts/clinic_personal_level_form.xml
index c4e7743..b8c949a 100644
--- a/netforce_clinic/layouts/clinic_personal_level_form.xml
+++ b/netforce_clinic/layouts/clinic_personal_level_form.xml
@@ -1,7 +1,11 @@
diff --git a/netforce_clinic/layouts/clinic_personal_level_list.xml b/netforce_clinic/layouts/clinic_personal_level_list.xml
index 52ac036..01fc691 100644
--- a/netforce_clinic/layouts/clinic_personal_level_list.xml
+++ b/netforce_clinic/layouts/clinic_personal_level_list.xml
@@ -1,7 +1,7 @@
-
+
diff --git a/netforce_clinic/layouts/clinic_schedule_form.xml b/netforce_clinic/layouts/clinic_schedule_form.xml
index 7714bc6..1498090 100644
--- a/netforce_clinic/layouts/clinic_schedule_form.xml
+++ b/netforce_clinic/layouts/clinic_schedule_form.xml
@@ -17,6 +17,7 @@
+
diff --git a/netforce_clinic/layouts/clinic_setting.xml b/netforce_clinic/layouts/clinic_setting.xml
index d97ef89..48ee378 100644
--- a/netforce_clinic/layouts/clinic_setting.xml
+++ b/netforce_clinic/layouts/clinic_setting.xml
@@ -1,17 +1,39 @@
diff --git a/netforce_clinic/models/__init__.py b/netforce_clinic/models/__init__.py
index d1e9d79..8cf5ac9 100644
--- a/netforce_clinic/models/__init__.py
+++ b/netforce_clinic/models/__init__.py
@@ -1,5 +1,6 @@
from . import utils
from . import setting
+from . import setting_level
from . import cause_chronic
from . import comorbidity
from . import department
diff --git a/netforce_clinic/models/cycle_dialy.py b/netforce_clinic/models/cycle_dialy.py
index a402bbf..445752d 100644
--- a/netforce_clinic/models/cycle_dialy.py
+++ b/netforce_clinic/models/cycle_dialy.py
@@ -5,7 +5,7 @@ from netforce.access import get_active_company
class CycleDialy(Model):
_name="clinic.cycle.dialy"
- _string="Cycle Diay"
+ _string="Cycle Dialy"
_fields={
"name": fields.Char("Name"),
diff --git a/netforce_clinic/models/cycle_item.py b/netforce_clinic/models/cycle_item.py
index 77e6e34..f988047 100644
--- a/netforce_clinic/models/cycle_item.py
+++ b/netforce_clinic/models/cycle_item.py
@@ -8,7 +8,7 @@ class CycleItem(Model):
_string="Cycle Item"
_name_field="name"
- def _get_all(self,ids,context):
+ def _get_all(self,ids,context={}):
res={}
for obj in self.browse(ids):
name="%s-%s"%(obj.cycle_id.name,obj.date)
@@ -16,24 +16,44 @@ class CycleItem(Model):
'name': name,
}
return res
+
+ def _get_pt(self,ids,context={}):
+ res={}
+ for obj in self.browse(ids):
+ total_case=len(obj.hd_cases)
+ res[obj.id]={
+ 'var_pt': total_case,
+ 'var_ptx': total_case*(obj.var_k or 0)
+ }
+ return res
_fields={
'name': fields.Char("Name", function="_get_all",function_multi=True),
'date': fields.Date("Date",search=True),
'cycle_id': fields.Many2One("clinic.cycle", "Cycle",search=True),
'cycle_dialy_id': fields.Many2One("clinic.cycle.dialy", "Cycle Dialy",search=True),
+ 'lines': fields.One2Many("clinic.cycle.item.line","item_id", "Lines"),
'visits': fields.One2Many("clinic.visit","cycle_item_id", "Visits"),
'hd_cases': fields.One2Many("clinic.hd.case","cycle_item_id", "HD Cases"),
'nurses': fields.One2Many("clinic.cycle.item.nurse",'cycle_item_id','Nurses'),
'sequence': fields.Char("Sequence"), # for sort item
'company_id': fields.Many2One("company", "Company"),
"state": fields.Selection([("draft","Draft"),("done","Done")],"Status",required=True),
+ 'var_k': fields.Float("K"),
+ 'var_x': fields.Float("X"),
+ 'var_pt': fields.Integer("PT", function="_get_pt",function_multi=True),
+ 'var_ptx': fields.Float("PT x K", function="_get_pt",function_multi=True),
}
+
+ def _get_vark(self,context={}):
+ st=get_model("clinic.setting").browse(1)
+ return st.var_k or 0
_defaults={
'state': 'draft',
'company_id': lambda *a: get_active_company(),
'date': lambda *a: time.strftime("%Y-%m-%d"),
+ 'var_k': _get_vark,
}
_order="sequence"
diff --git a/netforce_clinic/models/cycle_item_line.py b/netforce_clinic/models/cycle_item_line.py
index 9da5c52..c741654 100644
--- a/netforce_clinic/models/cycle_item_line.py
+++ b/netforce_clinic/models/cycle_item_line.py
@@ -9,19 +9,16 @@ class CycleItemLine(Model):
res={}
for obj in self.browse(ids):
res[obj.id]={
- 'amount': (obj.qty or 0) * (obj.rate or 0.0),
+ 'amount': (obj.qty or 0)*(obj.rate or 0.0),
}
return res
_fields={
- 'cycle_item_id': fields.Many2One("clinic.cycle.item", "Cycle Item"),
- "type": fields.Selection([("doctor","Doctor"),("nurse","Nurse")],"Personal Type",required=True),
- 'personal_categ': fields.Many2One("clinic.personal.categ", "Nurse Category",),
+ 'item_id': fields.Many2One("clinic.cycle.item", "Cycle Item"),
+ 'level_id': fields.Many2One("clinic.personal.level", "Level",domain=[['type','=','nurse']]),
'formular': fields.Char("Formular", size=100),
- 'description': fields.Char("Description"),
'qty': fields.Integer("Qty"),
'rate': fields.Float("Rate"),
- #'amount': fields.Float("Amount",function="all_amount", function_multi=True),
'amount': fields.Float("Amount"),
'company_id': fields.Many2One('company','Company'),
}
diff --git a/netforce_clinic/models/gen_visit.py b/netforce_clinic/models/gen_visit.py
index 72c8d90..ac90129 100644
--- a/netforce_clinic/models/gen_visit.py
+++ b/netforce_clinic/models/gen_visit.py
@@ -71,8 +71,23 @@ class GenVisit(Model):
'nurse_id': _get_nurse,
'duration': 1,
'cycle_id': _get_cycle,
- 'monday': True,
+ #'monday': True, # dynamic select weekday, use default_get
}
+
+ def default_get(self,field_names=None,context=None,**kw):
+ vals=super().default_get(field_names,context,**kw)
+ wd=datetime.now().weekday()
+ wds={
+ 0: 'monday',
+ 1: 'tuesday',
+ 2: 'wednesday',
+ 3: 'thursday',
+ 4: 'friday',
+ 5: 'sathurday',
+ 6: 'sunday',
+ }
+ vals[wds[wd]]=True
+ return vals
def onchange_time(self,context={}):
data=context['data']
@@ -182,7 +197,7 @@ class GenVisit(Model):
dom.append(['state','=','draft'])
vids=visit_obj.search(dom)
visit_obj.delete(vids)
- key='%s-%s'%(vals['cycle_id'], vals['time_start'])
+ key='%s/%s'%(vals['cycle_id'], vals['time_start'])
if not schedules.get(key):
schedules[key]={
'cycle_id': obj.cycle_id.id,
@@ -194,20 +209,41 @@ class GenVisit(Model):
start_date=tmp
for vals in visit_vals:
- vals['nurse_vals']=nurse_vals # XXX
visit_obj.create(vals)
- #dom=[]
- #dom.append(['time_start','>=','%s %s'%(obj.date_from[0:10],' 00:00:00')])
- #dom.append(['time_stop','<=','%s %s'%(start_date.strftime(FMT_DATE)[0:10],' 23:59:59')])
- #dom.append(['cycle_id','=',obj.cycle_id.id])
- #schedule_obj=get_model("clinic.schedule")
- #schedule_ids=schedule_obj.search(dom)
- #schedule_obj.delete(schedule_ids)
- #nurse_ids=[nurse['id'] for nurse in nurse_vals]
- #for key, vals in schedules.items():
- #vals['nurses']=[('add', nurse_ids)]
- #schedule_obj.create(vals)
-
+
+ print("create schedule")
+ print("="*50)
+ for k, v in schedules.items():
+ cycle_id,time_start=k.split("/")
+ schedule_date=time_start[0:10]
+ dom=[]
+ dom.append(['date','=',schedule_date])
+ schedules=get_model("clinic.schedule").search_browse(dom)
+ if schedules:
+ schedule=schedules[0]
+ if schedule.state=='draft':
+ for line in schedule.lines:
+ line.delete()
+ else:
+ vals={
+ 'date': time_start[0:10],
+ 'time_start': time_start,
+ 'time_stop': time_start,
+ }
+ schedule_id=get_model("clinic.schedule").create(vals)
+ schedule=get_model("clinic.schedule").browse(schedule_id)
+
+ lines=[]
+ for nv in nurse_vals:
+ nurse_id=nv['id']
+ lines.append(('create',{
+ 'nurse_id': nurse_id,
+ 'cycle_id': cycle_id,
+ }))
+ schedule.write({'lines': lines})
+
+ print("="*50)
+
return {
'next': {
'name': 'clinic_visit',
diff --git a/netforce_clinic/models/load_nurse.py b/netforce_clinic/models/load_nurse.py
index 44f825d..3540120 100644
--- a/netforce_clinic/models/load_nurse.py
+++ b/netforce_clinic/models/load_nurse.py
@@ -22,7 +22,6 @@ class LoadNurse(Model):
if cycle_ids:
cycle_id=cycle_ids[0]
lines=[]
- print("cycle_id ", cycle_id)
for nurse in get_model("clinic.personal").search_browse([['type','=','nurse']]):
in_cycle_id=None
if nurse.cycle_id.id:
diff --git a/netforce_clinic/models/personal_level.py b/netforce_clinic/models/personal_level.py
index b62a41d..0509870 100644
--- a/netforce_clinic/models/personal_level.py
+++ b/netforce_clinic/models/personal_level.py
@@ -1,4 +1,4 @@
-from netforce.model import Model, fields
+from netforce.model import Model, fields, get_model
from netforce.access import get_active_company
class PersonalLevel(Model):
@@ -8,9 +8,9 @@ class PersonalLevel(Model):
_fields={
"name": fields.Char("Name",required=True,search=True),
'formular': fields.Text("Formular"),
- 'description': fields.Text("Description"),
+ 'description': fields.Text("Description", search=True),
'sequence': fields.Integer("Sequence"),
- "type": fields.Selection([('personal','Personal'),("doctor","Doctor"),("nurse","Nurse")],"Personal Type",required=True),
+ "type": fields.Selection([('personal','Personal'),("doctor","Doctor"),("nurse","Nurse")],"Personal Type",required=True, search=True),
}
_defaults={
@@ -22,4 +22,21 @@ class PersonalLevel(Model):
_order="sequence"
+ def copy(self,ids,context={}):
+ obj=self.browse(ids)[0]
+ vals={
+ 'name': '%s (copy)'%obj.name,
+ 'description': obj.description,
+ 'type': obj.type,
+ }
+ new_id=get_model("clinic.personal.level").create(vals)
+ return {
+ 'next': {
+ 'name': 'clinic_personal_level',
+ 'mode': 'form',
+ 'active_id': new_id,
+ },
+ 'flash': 'Copy has been succcesfully',
+ }
+
PersonalLevel.register()
diff --git a/netforce_clinic/models/schedule.py b/netforce_clinic/models/schedule.py
index 3c7ffaf..41a0d36 100644
--- a/netforce_clinic/models/schedule.py
+++ b/netforce_clinic/models/schedule.py
@@ -12,10 +12,12 @@ class Schedule(Model):
res={}
for obj in self.browse(ids):
st="\n" # XXX
+ count=0
for line in obj.lines:
nurse=line.nurse_id
st+='%s %s\n'%(nurse.name, nurse.level_id.name or "")
- res[obj.id]='%s'%(st)
+ count+=1
+ res[obj.id]='%s'%(st if count else 'No nurse')
return res
def _get_item(self,ids,context={}):
diff --git a/netforce_clinic/models/schedule_copy.py b/netforce_clinic/models/schedule_copy.py
index 7a3990d..a676957 100644
--- a/netforce_clinic/models/schedule_copy.py
+++ b/netforce_clinic/models/schedule_copy.py
@@ -129,6 +129,15 @@ class ScheduleCopy(Model):
'date': date,
'lines': lines,
})
+ else:
+ # copy to exist nurse
+ schedules=get_model("clinic.schedule").search_browse([['date','=',date]])
+ print("update lines ", lines)
+ if schedules and lines:
+ schd=schedules[0]
+ for line in schd.lines:
+ line.delete()
+ schd.write({'lines': lines})
start_date=tmp
diff --git a/netforce_clinic/models/schedule_line.py b/netforce_clinic/models/schedule_line.py
index e5393ad..7ae8650 100644
--- a/netforce_clinic/models/schedule_line.py
+++ b/netforce_clinic/models/schedule_line.py
@@ -3,11 +3,17 @@ from netforce.model import Model, fields
class ScheduleLine(Model):
_name="clinic.schedule.line"
_string="Schedule Line"
-
+
+ def _get_level(self,ids,context={}):
+ res={}
+ for obj in self.browse(ids):
+ res[obj.id]=obj.nurse_id.level_id.id
+ return res
_fields={
'schedule_id': fields.Many2One("clinic.schedule","Schedule"),
'cycle_id': fields.Many2One("clinic.cycle","Cycle"),
"nurse_id": fields.Many2One("clinic.personal","Nurse",domain=[['type','=','nurse']]),
+ 'level_id': fields.Many2One("clinic.personal.level","Level",function="_get_level"),
}
ScheduleLine.register()
diff --git a/netforce_clinic/models/setting.py b/netforce_clinic/models/setting.py
index 8013d24..c3edafb 100644
--- a/netforce_clinic/models/setting.py
+++ b/netforce_clinic/models/setting.py
@@ -14,6 +14,7 @@ class ClinicSetting(Model):
_fields={
"var_k": fields.Float("K"),
'file': fields.File("File"),
+ 'levels': fields.One2Many("clinic.setting.level","setting_id","Levels"),
}
def read_excel(self,fpath=None):
diff --git a/netforce_clinic/models/setting_level.py b/netforce_clinic/models/setting_level.py
new file mode 100644
index 0000000..82af751
--- /dev/null
+++ b/netforce_clinic/models/setting_level.py
@@ -0,0 +1,22 @@
+from netforce.model import Model, fields, get_model
+
+class SettingLevel(Model):
+ _name="clinic.setting.level"
+ _string="Setting Line"
+
+ def _get_formular(self,ids,context={}):
+ res={}
+ for obj in self.browse(ids):
+ res[obj.id]=''.join(['%sx'%obj.var_a or '', obj.op or '', obj.var_b or ''])
+ return res
+
+ _fields={
+ "setting_id": fields.Many2One("clinic.setting","Setting"),
+ "level_id": fields.Many2One("clinic.personal.level","Level",domain=[['type','=','nurse']]),
+ 'var_a': fields.Char("Ax"),
+ "op": fields.Selection([["+","+"],["-","-"],["*","*"],["/","/"]],"Operation"),
+ 'var_b': fields.Char("B"),
+ 'formular': fields.Text("Formular",function="_get_formular"),
+ }
+
+SettingLevel.register()
diff --git a/netforce_clinic/models/visit.py b/netforce_clinic/models/visit.py
index a7fb332..7bc0884 100644
--- a/netforce_clinic/models/visit.py
+++ b/netforce_clinic/models/visit.py
@@ -177,6 +177,64 @@ class Visit(Model):
hd_case_id=hd_case_obj.create(vals)
if context.get("called"): #XXX call outside
return hd_case_id
+
+ print("checking cycle item")
+ date=vals['time_start'][0:10]
+ cycle=obj.cycle_id
+ dom=[]
+ dom.append(['date','=',date])
+ dom.append(['cycle_id','=',cycle.id])
+ dom.append(['state','=','draft'])
+ item_obj=get_model('clinic.cycle.item')
+ item_ids=item_obj.search(dom)
+
+ def get_schedule(date):
+ dom=[]
+ dom.append(['date','=',date])
+ schedule=None
+ schedules=get_model("clinic.schedule").search_browse(dom)
+ if schedules:
+ schedule=schedules[0]
+ return schedule
+
+ item_vals={
+ 'cycle_id': cycle.id,
+ 'date': date,
+ 'nurses': [],
+ }
+
+ item_id=None
+ if not item_ids:
+ item_id=item_obj.create(item_vals)
+ else:
+ # clear old nurse in cycle item
+ item_id=item_ids[0]
+ item=item_obj.browse(item_id)
+ for nurse in item.nurses:
+ nurse.delete()
+
+ item=item_obj.browse(item_id)
+ schedule=get_schedule(date)
+ if schedule:
+ for line in schedule.lines:
+ if line.cycle_id.id==cycle.id:
+ nurse=line.nurse_id
+ item_vals['nurses'].append(('create',{
+ 'nurse_id': nurse.id,
+ 'level_id': nurse.level_id.id,
+ }))
+
+ item.write(item_vals)
+
+ obj.write({
+ 'cycle_item_id': item_id,
+ })
+
+ hd_case=hd_case_obj.browse(hd_case_id)
+ hd_case.write({
+ 'cycle_item_id': item_id,
+ })
+
return {
'next': {
'name': 'clinic_hd_case',
@@ -296,50 +354,12 @@ class Visit(Model):
}
def create(self, vals,**kw):
- date=vals['time_start'][0:10]
cycle_id=vals['cycle_id']
cycle=get_model("clinic.cycle").browse(cycle_id)
- dom=[]
- dom.append(['date','=',date])
- dom.append(['cycle_id','=',cycle_id])
- item_obj=get_model('clinic.cycle.item')
- item_ids=item_obj.search(dom)
- item_id=None
-
- nurse_vals=[]
- if 'nurse_vals' in vals.keys():
- nurse_vals=vals['nurse_vals']
- del vals['nurse_vals']
- if not item_ids:
- item_vals={
- 'cycle_id': cycle_id,
- 'date': date,
- 'nurses': [],
- }
- for nurse_val in nurse_vals:
- item_vals['nurses'].append(('create',{
- 'nurse_id': nurse_val['id'],
- 'level_id': nurse_val['level_id'],
- }))
- item_id=item_obj.create(item_vals)
- else:
- item_id=item_ids[0]
- item_nurse_obj=get_model("clinic.cycle.item.nurse")
- item_nurse_ids=item_nurse_obj.search([['cycle_item_id','=',item_id]])
- item_nurse_obj.delete(item_nurse_ids)
- for nurse_val in nurse_vals:
- item_nurse_obj.create({
- 'cycle_item_id': item_id,
- 'nurse_id': nurse_val['id'],
- 'level_id': nurse_val['level_id'],
- })
-
- vals['cycle_item_id']=item_id
-
vals['sequence']='%s-%s'%(vals['time_start'][0:10],cycle.sequence) #date-sequence
vals['visit_date']=vals['time_start'][0:10]
- obj_id=super().create(vals,**kw)
- return obj_id
+ new_id=super().create(vals,**kw)
+ return new_id
def cancel(self,ids,context={}):
obj=self.browse(ids)[0]
diff --git a/netforce_clinic/todo.txt b/netforce_clinic/todo.txt
index 5652b11..4ef68ef 100644
--- a/netforce_clinic/todo.txt
+++ b/netforce_clinic/todo.txt
@@ -1,5 +1,14 @@
+=======
customize ui
- - attribute color for field
+ calendar -
+ - show search
+ - change color from cycle
+ - filter state from attr
+ - can print sechedule all month
+ - set attribute color for field
+
+========
+
cycle dialy
-list of cycle items
- report all compute all cost