diff --git a/netforce_clinic/migrations/__init__.py b/netforce_clinic/migrations/__init__.py index dd73eb7..87b7a4d 100644 --- a/netforce_clinic/migrations/__init__.py +++ b/netforce_clinic/migrations/__init__.py @@ -19,4 +19,5 @@ from . import clinic_setting #from . import revise #from . import add_patient_moves #XXX do not run it again!!! #from . import check_patient -from . import update_patient_name +#from . import update_patient_name +from . import del_dbl_visit diff --git a/netforce_clinic/migrations/del_dbl_visit.py b/netforce_clinic/migrations/del_dbl_visit.py new file mode 100644 index 0000000..618a1fa --- /dev/null +++ b/netforce_clinic/migrations/del_dbl_visit.py @@ -0,0 +1,39 @@ +import time +from netforce.migration import Migration +from netforce.model import Model, fields, get_model + + +class UpdatePatientName(Migration): + _name='del.dbl.visit' + _version="2.12.9" + + def migrate(self): + cond=[ + ['visit_date','>=','2018-03-06'], + ['visit_date','<=', '2018-03-06'], + ['department_id','=', 4], + ['state','!=', 'confirmed'], + ] + patients={} + add_count=0 + del_count=0 + for index, visit in enumerate(get_model("clinic.visit").search_browse(cond)): + patient_id=visit.patient_id.id + cycle_id=visit.cycle_id.id + key=(patient_id, cycle_id) + if key in patients.keys(): + print("del ", visit.id) + try: + visit.delete() + except Exception as e: + print("ERROR ", e) + print("visit ", visit.id, visit.number) + del_count+=1 + else: + print("add ", visit.id) + add_count+=1 + patients.setdefault(key) + print('total ', add_count, del_count) + + +UpdatePatientName.register() diff --git a/netforce_clinic/migrations/update_patient_name.py b/netforce_clinic/migrations/update_patient_name.py index f9a926c..8614ddf 100644 --- a/netforce_clinic/migrations/update_patient_name.py +++ b/netforce_clinic/migrations/update_patient_name.py @@ -13,18 +13,22 @@ class UpdatePatientName(Migration): for f, model in [('date', 'clinic.hd.case'),('visit_date','clinic.visit')]: cond=[ - [f,'>=','%s-01-01'%(y)], + #[f,'>=','%s-01-01'%(y)], + [f,'>=','2014-01-01'], [f,'<=',datenow], ['patient_name','=',None], ] print("update %s ... "%model) + context={ + 'migration': True, + } objs=get_model(model).search_browse(cond) for index, obj in enumerate(objs): patient=obj.patient_id vals={ 'patient_name': patient.name_get()[-1][1] } - obj.write(vals) + obj.write(vals,context=context) #print("%s/%s"%(index+1, len(hdcases))) UpdatePatientName.register() diff --git a/netforce_clinic/models/hd_case.py b/netforce_clinic/models/hd_case.py index a086b87..3696a2d 100644 --- a/netforce_clinic/models/hd_case.py +++ b/netforce_clinic/models/hd_case.py @@ -1109,7 +1109,7 @@ class HDCase(Model): # update sickbed if obj.sickbed_id: obj.sickbed_id.write({ - 'available': False, + 'available': True, #reset to available, => please recheck art }) obj.recompute_labor_cost() return { @@ -1618,7 +1618,8 @@ class HDCase(Model): }) sb=get_model("clinic.sickbed").browse(vals['sickbed_id']) sb.write({ - 'state': 'not_available', + 'available': False, + 'state': 'not_available', #XXX Check state. }) set_active_user(user_id) if 'lines' in vals.keys(): diff --git a/netforce_clinic/models/patient.py b/netforce_clinic/models/patient.py index 5d9da9c..2d7eb8f 100644 --- a/netforce_clinic/models/patient.py +++ b/netforce_clinic/models/patient.py @@ -112,8 +112,8 @@ class Patient(Model): "hn_no": fields.Char("HN",function="_get_hn_no",store=True), "hn": fields.Char("REF/HN",search=False), 'title_id': fields.Many2One("clinic.name.title","Title"), - "first_name": fields.Char("First Name"), - "last_name": fields.Char("Last Name"), + "first_name": fields.Char("First Name", search=True), + "last_name": fields.Char("Last Name", search=True), "name": fields.Char("Name",function="_get_name",function_multi=True,store=True,search=True), "name_check": fields.Char("Name",function="_get_name",function_multi=True,store=True), # prevent duplicate 'type_id': fields.Many2One("clinic.patient.type","Type",search=True,required=True), @@ -389,6 +389,7 @@ class Patient(Model): obj=self.browse(ids)[0] if obj.walkin=='no': patient_move={ + 'date': obj.resign_date, #XXX "patient_id": obj.id, "patient_name": "%s %s"% (obj.first_name or "",obj.last_name or ""), "patient_type": obj.type_id.name, diff --git a/netforce_clinic/models/report_labor_cost.py b/netforce_clinic/models/report_labor_cost.py index 57bff51..71a53e7 100644 --- a/netforce_clinic/models/report_labor_cost.py +++ b/netforce_clinic/models/report_labor_cost.py @@ -51,10 +51,13 @@ class ReportLaborCost(Model): date_to=line.date_stop break if defaults.get('report_type_wizard'): - per = get_model('clinic.period.line').browse(int(defaults.get('period_id'))) - period_id=per.id - date_from=per.date_start - date_to=per.date_stop + date_from=defaults.get('date_from') + date_to=defaults.get('date_to') + if defaults.get('period_id') != 'None': + per = get_model('clinic.period.line').browse(int(defaults.get('period_id'))) + period_id=per.id + date_from=per.date_start + date_to=per.date_stop res={ 'period_id': period_id, 'date': time.strftime("%Y-%m-%d"), diff --git a/netforce_clinic/models/visit_board.py b/netforce_clinic/models/visit_board.py index ee5d2de..dce6383 100644 --- a/netforce_clinic/models/visit_board.py +++ b/netforce_clinic/models/visit_board.py @@ -400,6 +400,7 @@ class VisitBoard(Model): 'date_from': utils.date2thai(date_from,format='%(d)s %(Tm)s %(By)s',lang="th_TH2"), 'date_to': utils.date2thai(date_to,format='%(d)s %(Tm)s %(By)s',lang="th_TH2"), } + # TODO Delete the data if duplicate (date, patient, deparment) return data def onchange_date(self,context={}): diff --git a/netforce_clinic/reports/report_wizard_labor_cost_details.odt b/netforce_clinic/reports/report_wizard_labor_cost_details.odt index 1b8ceb1..3665f3c 100644 Binary files a/netforce_clinic/reports/report_wizard_labor_cost_details.odt and b/netforce_clinic/reports/report_wizard_labor_cost_details.odt differ diff --git a/netforce_clinic/reports/report_wizard_labor_cost_sub_details.odt b/netforce_clinic/reports/report_wizard_labor_cost_sub_details.odt index eed32db..3f7c964 100644 Binary files a/netforce_clinic/reports/report_wizard_labor_cost_sub_details.odt and b/netforce_clinic/reports/report_wizard_labor_cost_sub_details.odt differ