71 lines
2.4 KiB
Python
71 lines
2.4 KiB
Python
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
|
|
import collections
|
|
|
|
class Migration(migration.Migration):
|
|
_name="check.patient"
|
|
_version="2.12.8"
|
|
|
|
def migrate(salf):
|
|
set_active_company(1)
|
|
set_active_user(1)
|
|
totals={}
|
|
context={
|
|
'active_test': False,
|
|
}
|
|
for pt in get_model('clinic.patient').search_browse([], context=context):
|
|
key=(pt.number, pt.card_no, pt.walkin)
|
|
#key=(pt.hn_no)
|
|
totals.setdefault(key,{
|
|
'count': 0,
|
|
'pid': pt.id,
|
|
'pname': pt.name,
|
|
})
|
|
totals[key]['count']+=1
|
|
|
|
for k in sorted(totals.keys()):
|
|
hn_no, card_no, walkin = k
|
|
pt=totals[k]
|
|
if pt['count'] > 1:
|
|
#hn_no, card_no, walkin = k
|
|
print(k, pt)
|
|
return
|
|
|
|
user_id=get_active_user()
|
|
company_id=get_active_company()
|
|
count=0
|
|
lines_hn=[]
|
|
lines_pid=[]
|
|
lines_h=[]
|
|
lines_p=[]
|
|
print('start check patients.')
|
|
for pat in get_model('clinic.patient').search_browse([]):
|
|
lines_hn.append(pat.hn_no)
|
|
lines_pid.append(pat.card_no)
|
|
count+=1
|
|
print('count : %d'%(count))
|
|
total_hn = [item for item, count in collections.Counter(lines_hn).items() if count > 1]
|
|
total_pid = [item for item, count in collections.Counter(lines_pid).items() if count > 1]
|
|
count=0
|
|
for total in total_hn:
|
|
for line in get_model('clinic.patient').search_browse(['hn_no','=',total]):
|
|
data = '%d : %s'%(line.id,line.hn_no)
|
|
lines_h.append(data)
|
|
count+=1
|
|
print('#%d : id=%d, name=%s %s, hn_no=%s'%(count,line.id,line.first_name,line.last_name,line.hn_no))
|
|
print("")
|
|
print("*"*100)
|
|
print("")
|
|
count=0
|
|
for total in total_pid:
|
|
for line in get_model('clinic.patient').search_browse(['card_no','=',total]):
|
|
data = '%d : %s'%(line.id,line.card_no)
|
|
lines_p.append(data)
|
|
count+=1
|
|
print('#%d : id=%d, name=%s %s, pid=%s'%(count,line.id,line.first_name,line.last_name,line.card_no))
|
|
print('check patients : Done!')
|
|
return True
|
|
|
|
Migration.register()
|