Class: Renalware::Events::AlertableEventsQuery
- Inherits:
-
Object
- Object
- Renalware::Events::AlertableEventsQuery
- Defined in:
- app/models/renalware/events/alertable_events_query.rb
Overview
Query object that returns, for a patient, the most recent matching event (if any) for each event_type_alert_trigger row in the databse. The results are used to display alerts in the UI. For example given a vaccination Event::Type and an EventTypeAlertTrigger which is configured to find any vaccination event with the word “covid” in anywhere in the document, this query will return the most matching event. It is possible to have mltiple triggers rows for the same event type, so for eample one could display triggers for the most recent covid vaccination, and the most recent HBV vaccination.
Class Method Summary collapse
Class Method Details
.call(patient:) ⇒ Object
17 18 19 20 21 22 23 24 |
# File 'app/models/renalware/events/alertable_events_query.rb', line 17 def self.call(patient:) Event .for_patient(patient) .joins(event_type: :alert_triggers) .select("DISTINCT ON (events.patient_id, event_type_alert_triggers.id) events.*") .where("(events.document::text ilike '%' || when_event_document_contains || '%') or (events.description ilike '%' || when_event_description_contains || '%')") .order("events.patient_id, event_type_alert_triggers.id, events.created_at desc") end |