clinic/netforce_clinic/migrations/add_missing_dlz.py

46 lines
1.5 KiB
Python
Raw Permalink Normal View History

2016-11-29 16:30:11 +00:00
import csv
import xlrd
from netforce.model import get_model
from netforce import migration
from netforce.access import set_active_user, set_active_company
from netforce.database import get_connection
class Migration(migration.Migration):
_name="clinic.add.missing.dlz"
_version="2.12.4"
def migrate(self):
set_active_company(1)
set_active_user(1)
cond=[
['date','>=','2016-11-10'],
['date','<=','2016-11-15'],
['patient_id','=',16907], # test
]
for hdcase in get_model("clinic.hd.case").search_browse(cond):
if not hdcase.dialyzers:
patient=hdcase.patient_id
dialyzer=patient.dialyzers[0] #active
print('hdcase.number : ', hdcase.number)
print("//"*30)
dlzs=get_model("clinic.hd.case.dialyzer").search_browse([['dialyzer_id','=',dialyzer.id]])
if dlzs:
dlz=dlzs[0]
next_usetime=dlz.use_time+1
vals={
"description": dialyzer.name,
'use_time': next_usetime,
'max_use_time': dialyzer.max_use_time,
'dialyzer_type': dialyzer.type,
'dlz_id': dialyzer.id,
'hd_case_id': hdcase.id,
}
print(patient.id, patient.name, dialyzer.id, dlz.use_time)
print("//"*30)
break
Migration.register()