Skip to content

Commit

Permalink
fix: listing address and telecom in endpoint output
Browse files Browse the repository at this point in the history
  • Loading branch information
TanookiVerde committed Jan 3, 2024
1 parent dad730e commit bfd4a90
Showing 1 changed file with 24 additions and 12 deletions.
36 changes: 24 additions & 12 deletions api/app/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@ async def to_pydantic_model(self) -> PatientModel:
# one.
cnss = []
try:
cnss_instances = await Cns.filter(patient=self)
cnss_instances = await self.cnss.all()
for cns in cnss_instances:
if cns.is_main:
cnss.insert(0, cns.value)
Expand All @@ -303,20 +303,28 @@ async def to_pydantic_model(self) -> PatientModel:
# Iterate over the patient's addresses.
addresses = []
try:
for address_patient_period in self.address_patient_periods:
address = address_patient_period.address
address_patient_periods_instances = await self.address_patient_periods.all()
for address_patient_period in address_patient_periods_instances:
# TODO: Refactor this part
address = await address_patient_period.address
type = await address.type
use = await address.use
city = await address.city
state = await city.state
country = await state.country

period = PeriodModel(
start=address_patient_period.period_start,
end=address_patient_period.period_end,
)
addresses.append(
AddressModel(
use=address.use.name if address.use else None,
type=address.type.name if address.type else None,
use=use.name if use else None,
type=type.name if type else None,
line=address.line,
city=address.city.name,
state=address.city.state.name,
country=address.city.state.country.name,
city=city.name,
state=state.name,
country=country.name,
postal_code=address.postal_code,
period=period,
)
Expand All @@ -326,16 +334,20 @@ async def to_pydantic_model(self) -> PatientModel:
# Iterate over the patient's telecoms.
telecoms = []
try:
for telecom_patient_period in self.telecom_patient_periods:
telecom = telecom_patient_period.telecom
telecom_patient_period_instances = await self.telecom_patient_periods.all()
for telecom_patient_period in telecom_patient_period_instances:
telecom = await telecom_patient_period.telecom
use = await telecom.use
system = await telecom.system

period = PeriodModel(
start=telecom_patient_period.period_start,
end=telecom_patient_period.period_end,
)
telecoms.append(
TelecomModel(
system=telecom.system.name if telecom.system else None,
use=telecom.use.name if telecom.use else None,
system=system.name if system else None,
use=use.name if use else None,
value=telecom.value,
rank=telecom.rank,
period=period,
Expand Down

0 comments on commit bfd4a90

Please sign in to comment.