Skip to content

Commit

Permalink
Fixed condition for facilities comparision
Browse files Browse the repository at this point in the history
  • Loading branch information
dborowiecki committed Jun 24, 2024
1 parent ee2bc6a commit 6581f1a
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions sigeca_data_import_microservice/app/domain/resources.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,13 @@ def get_all(self):

class FacilityResourceRepository(BaseResourceRepository):
def get_all(self):
query = """(SELECT f.*, jsonb_object_agg(p.code, p.id) AS supported_programs
query = """(SELECT f.*,
(case when count(p.code)= 0 then '{}'::jsonb
else jsonb_object_agg(coalesce(p.code, 'undefined'), p.id)
end) as supported_programs
FROM referencedata.facilities f
JOIN referencedata.supported_programs sp ON sp.facilityid = f.id
JOIN referencedata.programs p ON sp.programid = p.id
LEFT JOIN referencedata.supported_programs sp ON sp.facilityid = f.id
LEFT JOIN referencedata.programs p ON sp.programid = p.id
GROUP BY f.id
) AS facilities"""
return self.jdbc_reader.read_data(query)
Expand Down

0 comments on commit 6581f1a

Please sign in to comment.