Skip to content

Instantly share code, notes, and snippets.

@inglesp
Last active May 25, 2020 13:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save inglesp/1611c0708b509f537b543cb13e02989f to your computer and use it in GitHub Desktop.
Save inglesp/1611c0708b509f537b543cb13e02989f to your computer and use it in GitHub Desktop.
Update opensafely/chemotherapy-or-radiotherapy
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