clinic/netforce_clinic/migrations/del_dbl_visit.py

40 lines
1.2 KiB
Python
Raw Normal View History

2018-05-28 03:35:22 +00:00
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()