Skip to content

Commit

Permalink
reset migrations, move site to patient model, scope patient list to l…
Browse files Browse the repository at this point in the history
…ogged in users organisation, scope patient creation to users organisation, patient update to record in site model
  • Loading branch information
eatyourpeas committed Jun 2, 2024
1 parent 5016306 commit 8e5f5f5
Show file tree
Hide file tree
Showing 14 changed files with 295 additions and 1,188 deletions.
40 changes: 20 additions & 20 deletions project/npda/general_functions/csv_upload.py
Original file line number Diff line number Diff line change
Expand Up @@ -781,12 +781,32 @@ def save_row(row):
site_errors,
) = validate_row(row)

try:
# save site
site, created = Site.objects.get_or_create(
date_leaving_service=(
row["Date of leaving service"]
if not pd.isnull(row["Date of leaving service"])
else None
),
reason_leaving_service=(
row["Reason for leaving service"]
if not pd.isnull(row["Reason for leaving service"])
else None
),
paediatric_diabetes_unit_pz_code=pdu_pz_code,
organisation_ods_code=organisation_ods_code,
)
except Exception as error:
raise Exception(f"Could not save site: {error}")

nhs_number = row["NHS Number"].replace(" ", "")

try:
patient, created = Patient.objects.update_or_create(
nhs_number=nhs_number,
defaults={
"site": site,
"date_of_birth": row["Date of Birth"],
"postcode": row["Postcode of usual address"],
"sex": row["Stated gender"],
Expand All @@ -804,26 +824,6 @@ def save_row(row):
except Exception as error:
raise Exception(f"Could not save patient: {error}")

try:
# save site
Site.objects.get_or_create(
date_leaving_service=(
row["Date of leaving service"]
if not pd.isnull(row["Date of leaving service"])
else None
),
reason_leaving_service=(
row["Reason for leaving service"]
if not pd.isnull(row["Reason for leaving service"])
else None
),
paediatric_diabetes_unit_pz_code=pdu_pz_code,
organisation_ods_code=organisation_ods_code,
patient=patient,
)
except Exception as error:
raise Exception(f"Could not save site: {error}")

try:
obj = {
"patient": patient,
Expand Down
Loading

0 comments on commit 8e5f5f5

Please sign in to comment.