2018-01-24 05:26:15 +00:00
|
|
|
import time
|
|
|
|
from netforce.migration import Migration
|
|
|
|
from netforce.model import Model, fields, get_model
|
|
|
|
|
|
|
|
|
|
|
|
class UpdatePatientName(Migration):
|
|
|
|
_name='update.petient.name'
|
|
|
|
_version="2.12.9"
|
|
|
|
|
|
|
|
def migrate(self):
|
|
|
|
datenow=time.strftime("%Y-%m-%d")
|
|
|
|
y,m,d=datenow.split("-")
|
|
|
|
|
|
|
|
for f, model in [('date', 'clinic.hd.case'),('visit_date','clinic.visit')]:
|
|
|
|
cond=[
|
2018-05-28 03:35:22 +00:00
|
|
|
#[f,'>=','%s-01-01'%(y)],
|
|
|
|
[f,'>=','2014-01-01'],
|
2018-01-24 05:26:15 +00:00
|
|
|
[f,'<=',datenow],
|
|
|
|
['patient_name','=',None],
|
|
|
|
]
|
|
|
|
print("update %s ... "%model)
|
2018-05-28 03:35:22 +00:00
|
|
|
context={
|
|
|
|
'migration': True,
|
|
|
|
}
|
2018-01-24 05:26:15 +00:00
|
|
|
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]
|
|
|
|
}
|
2018-05-28 03:35:22 +00:00
|
|
|
obj.write(vals,context=context)
|
2018-01-24 05:26:15 +00:00
|
|
|
#print("%s/%s"%(index+1, len(hdcases)))
|
|
|
|
|
|
|
|
UpdatePatientName.register()
|