forked from iRaySpace/erpnext-scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
medical_codes.py
33 lines (24 loc) · 833 Bytes
/
medical_codes.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
import frappe
import csv
def load_db():
with open('./medical_codes.csv') as file:
data = csv.DictReader(file)
rows = list(data)
max_length = len(rows)
duplicates = []
for i, row in enumerate(rows):
print 'Loading {0}/{1} Medical Code.'.format(i + 1, max_length)
medical_code = frappe.get_doc({
'doctype': 'Medical Code',
'medical_code_standard': 'ICD-10',
'code': row['medical_code'],
'description': row['description']
})
try:
medical_code.save()
except:
duplicates.append(row)
print 'The following are the duplicates:'
print duplicates
def clear_db():
frappe.db.sql("""DELETE FROM `tabMedical Code`""")