Skip to content

Commit

Permalink
Merge pull request #6406 from espoon-voltti/use-application-primary-p…
Browse files Browse the repository at this point in the history
…referred-unit

Käytetään hakemusten generoitua saraketta SQL-kyselyissä
  • Loading branch information
akheron authored Feb 19, 2025
2 parents 8cdf5c0 + 8eaf856 commit 4b9ee0c
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -466,7 +466,7 @@ fun Database.Read.fetchApplicationSummaries(
JOIN person child ON child.id = a.child_id
LEFT JOIN placement_plan pp ON pp.application_id = a.id
LEFT JOIN evaka_user e ON e.id = a.status_modified_by
JOIN daycare d ON COALESCE(pp.unit_id, (a.document -> 'apply' -> 'preferredUnits' ->> 0)::uuid) = d.id
JOIN daycare d ON COALESCE(pp.unit_id, a.primary_preferred_unit) = d.id
JOIN care_area ca ON d.care_area_id = ca.id
JOIN (
SELECT l.id, EXISTS(
Expand Down Expand Up @@ -497,7 +497,7 @@ fun Database.Read.fetchApplicationSummaries(
WHERE
p.child_id = a.child_id AND
${bind(today)} BETWEEN p.start_date AND p.end_date AND
p.unit_id = (a.document -> 'apply' -> 'preferredUnits' ->> 0)::uuid
p.unit_id = a.primary_preferred_unit
) AS continuation
) continuation_status ON true
LEFT JOIN LATERAL (
Expand Down Expand Up @@ -695,11 +695,7 @@ SELECT
a.type,
a.child_id,
(a.document -> 'child' ->> 'lastName') || ' ' || (a.document -> 'child' ->> 'firstName') AS child_name,
(
SELECT name
FROM daycare d
WHERE d.id = (a.document -> 'apply' -> 'preferredUnits' ->> 0)::uuid
) AS preferred_unit_name,
(SELECT name FROM daycare d WHERE d.id = a.primary_preferred_unit) AS preferred_unit_name,
COALESCE((
SELECT array_agg(d.name)
FROM jsonb_array_elements_text(a.document -> 'apply' -> 'preferredUnits') pu
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -690,10 +690,7 @@ LEFT JOIN application a ON p.id IS NULL AND a.child_id IN (
fc_spouse.child_id
)
LEFT JOIN daycare d ON d.id IN (
p.unit_id,
(a.document -> 'apply' -> 'preferredUnits' ->> 0)::uuid
)
LEFT JOIN daycare d ON d.id IN (p.unit_id, a.primary_preferred_unit)
LEFT JOIN care_area ca ON ca.id = d.care_area_id
WHERE
i.status = 'SENT'::income_statement_status AND
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ SELECT
person.date_of_birth AS child_date_of_birth,
EXISTS (SELECT FROM daycare_assistance WHERE child_id = person.id AND valid_during @> ${bind(today)}) AS is_daycare_assistance_need
FROM application
JOIN daycare application_unit ON (application.document -> 'apply' -> 'preferredUnits' ->> 0)::uuid = application_unit.id
JOIN daycare application_unit ON application.primary_preferred_unit = application_unit.id
JOIN person on application.child_id = person.id
LEFT JOIN placement ON person.id = placement.child_id AND ${bind(today)} BETWEEN placement.start_date AND placement.end_date
LEFT JOIN daycare current_unit ON placement.unit_id = current_unit.id
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ SELECT
placement_plan.start_date,
(appl.document ->> 'preferredStartDate')::DATE
) AS startDate,
appl.document -> 'apply' -> 'preferredUnits' ->> 0 AS preferredUnit,
appl.primary_preferred_unit AS preferredUnit,
(
SELECT array_agg(e::UUID)
FROM jsonb_array_elements_text(appl.document -> 'apply' -> 'preferredUnits') e
Expand Down

0 comments on commit 4b9ee0c

Please sign in to comment.