Skip to content

Commit

Permalink
fix: get patients missed prefetch of relations
Browse files Browse the repository at this point in the history
  • Loading branch information
TanookiVerde committed Jan 4, 2024
1 parent 7d40ae5 commit f8609d0
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 7 deletions.
12 changes: 6 additions & 6 deletions api/app/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,23 +110,23 @@ class Patient(Model):


class PatientRecord(Model):
patient = fields.ForeignKeyField("app.Patient", related_name="records")
data_source = fields.ForeignKeyField("app.DataSource", related_name="patients")
patient = fields.ForeignKeyField("app.Patient", related_name="patient")
data_source = fields.ForeignKeyField("app.DataSource", related_name="data_source")

active = fields.BooleanField(default=True)
birth_city = fields.ForeignKeyField("app.City", related_name="birth_patients", null=True)
birth_date = fields.DateField()
deceased = fields.BooleanField(default=False)
deceased_date = fields.DateField(null=True)
ethnicity = fields.ForeignKeyField("app.Ethnicity", related_name="patients", null=True)
ethnicity = fields.ForeignKeyField("app.Ethnicity", related_name="ethnicity", null=True)
father_name = fields.CharField(max_length=512, null=True)
gender = fields.ForeignKeyField("app.Gender", related_name="patients", null=True)
gender = fields.ForeignKeyField("app.Gender", related_name="gender", null=True)
mother_name = fields.CharField(max_length=512, null=True)
name = fields.CharField(max_length=512)
nationality = fields.ForeignKeyField("app.Nationality", related_name="patients", null=True)
nationality = fields.ForeignKeyField("app.Nationality", related_name="nationality", null=True)
naturalization = fields.CharField(max_length=512, null=True)
protected_person = fields.BooleanField(null=True)
race = fields.ForeignKeyField("app.Race", related_name="patients", null=True)
race = fields.ForeignKeyField("app.Race", related_name="race", null=True)

class Meta:
unique_together = (("patient", "data_source"),)
Expand Down
5 changes: 4 additions & 1 deletion api/app/routers/patients.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,10 @@ async def get_patients(
detail="User does not have a data source associated with it.",
)
else:
patients = await PatientRecord.filter(data_source__name=current_user.data_source.name)
data_source = await current_user.data_source
patients = await PatientRecord.filter(data_source__name=data_source.name).prefetch_related(
'patient','data_source', 'ethnicity','race','gender','nationality','birth_city'
)
return [await patient.to_pydantic_model() for patient in patients]


Expand Down

0 comments on commit f8609d0

Please sign in to comment.