Build the facility_levels_of_care upsert rows referenced by stays. A stay contributes a row
only when it carries both a level_of_care_external_id and a level_of_care_name. Identity is the
LOC NAME ((facility_id, name), matching facility_programs): the EMR's LOC external id churns
across syncs, so it is NOT stored here (external_id: null) — persisting it made the same name
reappear under a new external id violate the (facility_id, name) unique. Rows are deduped by
trimmed name; synced LOCs are type: "clinical" (UR-derived LOCs are sourced elsewhere).
Build the
facility_levels_of_careupsert rows referenced bystays. A stay contributes a row only when it carries both alevel_of_care_external_idand alevel_of_care_name. Identity is the LOC NAME ((facility_id, name), matchingfacility_programs): the EMR's LOC external id churns across syncs, so it is NOT stored here (external_id: null) — persisting it made the same name reappear under a new external id violate the(facility_id, name)unique. Rows are deduped by trimmed name; synced LOCs aretype: "clinical"(UR-derived LOCs are sourced elsewhere).