Last active
May 25, 2020 13:11
-
-
Save inglesp/1611c0708b509f537b543cb13e02989f to your computer and use it in GitHub Desktop.
Update opensafely/chemotherapy-or-radiotherapy
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
cl = Codelist.objects.get(slug="chemotherapy-or-radiotherapy") | |
headers, *rows = cl.table | |
f = open("chemotherapy-or-radiotherapy-updated.csv", "w") | |
writer = csv.writer(f) | |
writer.writerow(headers) | |
for row in rows: | |
code = row[0] | |
if len(code) == 5: | |
writer.writerow(row) | |
continue | |
# codes are case-sensitive | |
concepts = Concept.objects.filter(read_code__startswith=code) | |
concepts = [c for c in concepts if c.read_code.startswith(code)] | |
assert len(concepts) == 1 | |
concept = concepts[0] | |
writer.writerow([concept.read_code] + row[1:]) | |
f.close() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment