Skip to content

Instantly share code, notes, and snippets.

@dkapitan
Created June 14, 2024 19:00
Show Gist options
  • Save dkapitan/67ba9a473231ef0d86e99c70066de4ac to your computer and use it in GitHub Desktop.
Save dkapitan/67ba9a473231ef0d86e99c70066de4ac to your computer and use it in GitHub Desktop.
Simple redacting of FHIR patient resource in ndjson
import ndjson
def redact(patient: dict) -> dict:
for key in ["name", "telecom"]:
patient.pop(key, None)
return patient
with open("patient.ndjson") as f:
patients = ndjson.load(f)
redacted_patient = [redact(patient) for patient in patients]
with open("patient_redacted.ndjon", "w") as f:
writer = ndjson.writer(f, ensure_ascii=False)
for patient in redacted_patient:
writer.writerow(patient)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment