67 lines
3.2 KiB
Python
67 lines
3.2 KiB
Python
|
import time
|
||
|
|
||
|
from netforce.model import get_model
|
||
|
from netforce import migration
|
||
|
from netforce.access import set_active_user, get_active_user, set_active_company, get_active_company
|
||
|
from netforce.database import get_connection
|
||
|
|
||
|
class Migration(migration.Migration):
|
||
|
_name="clinic.patient.move"
|
||
|
_version="2.12.7"
|
||
|
|
||
|
def migrate(self):
|
||
|
set_active_company(1)
|
||
|
set_active_user(1)
|
||
|
user_id=get_active_user()
|
||
|
company_id=get_active_company()
|
||
|
count_out=0
|
||
|
count_in=0
|
||
|
db=get_connection()
|
||
|
vals=[]
|
||
|
for patient in get_model("clinic.patient").search_browse([]):
|
||
|
count_out=0
|
||
|
count_in=0
|
||
|
date_str=""
|
||
|
time_tuple=""
|
||
|
if patient.dispose==True:
|
||
|
if not patient.resign_date:
|
||
|
#time_tuple=lambda *a: time.strftime("%Y-%m-%d %H:%M:%S")
|
||
|
time_tuple = lambda *a: time.strftime("%Y-%m-%d")
|
||
|
else:
|
||
|
date_str = patient.resign_date
|
||
|
time_tuple = lambda *a: time.strptime(date_str, "%Y-%m-%d")
|
||
|
line_vals={
|
||
|
"patient_id": patient.id,
|
||
|
"patient_name": "%s %s"% (patient.first_name or "",patient.last_name or ""),
|
||
|
"patient_type": patient.type_id.name,
|
||
|
"type": "out",
|
||
|
"type_id": patient.type_id.id,
|
||
|
"date": date_str,
|
||
|
#"location_from_id": obj.location,
|
||
|
#"location_to_id": obj.location,
|
||
|
}
|
||
|
db.execute("""
|
||
|
insert INTO clinic_patient_move (patient_id,patient_name,patient_type,type_id,type,date,create_time,create_uid) VALUES (%d,'%s','%s',%d,'%s','%s',CURRENT_DATE,%d);
|
||
|
"""%(line_vals.get('patient_id'),line_vals.get('patient_name'),line_vals.get('patient_type'),line_vals.get('type_id'),line_vals.get('type'),line_vals.get('date'),user_id))
|
||
|
print("insert INTO clinic.patient.move ('OUT'): %s , %s , %s"%(line_vals.get('patient_name'),line_vals.get('type'),line_vals.get('date')))
|
||
|
date_str = patient.reg_date
|
||
|
time_tuple = lambda *a: time.strptime(date_str, "%Y-%m-%d")
|
||
|
line_vals={
|
||
|
"patient_id": patient.id,
|
||
|
"patient_name": "%s %s"% (patient.first_name or "",patient.last_name or ""),
|
||
|
"patient_type": patient.type_id.name,
|
||
|
"type": "in",
|
||
|
"type_id": patient.type_id.id,
|
||
|
"date": date_str,
|
||
|
#"location_from_id": obj.location,
|
||
|
#"location_to_id": obj.location,
|
||
|
}
|
||
|
db.execute("""
|
||
|
insert INTO clinic_patient_move (patient_id,patient_name,patient_type,type_id,type,date,create_time,create_uid) VALUES (%d,'%s','%s',%d,'%s','%s',CURRENT_DATE,%d);
|
||
|
"""%(line_vals.get('patient_id'),line_vals.get('patient_name'),line_vals.get('patient_type'),line_vals.get('type_id'),line_vals.get('type'),line_vals.get('date'),user_id))
|
||
|
print("insert INTO clinic.patient.move ('IN'): %s , %s , %s"%(line_vals.get('patient_name'),line_vals.get('type'),line_vals.get('date')))
|
||
|
#set_active_user(user_id)
|
||
|
return True
|
||
|
|
||
|
Migration.register()
|