Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --
- -- Name: mv_connected_assocs_disease_progresses; Type: MATERIALIZED VIEW; Schema: public; Owner: -
- --
- CREATE MATERIALIZED VIEW public.mv_connected_assocs_disease_progresses
- WITH (autovacuum_enabled=off) AS
- SELECT combined_data.id,
- combined_data.patient_id,
- combined_data.service_code,
- combined_data.performed_date,
- combined_data.assoc_type
- FROM (((( SELECT ehr_direction_service_requests.id,
- ehr_direction_service_requests.patient_id,
- ehr_ehealth_services.code AS service_code,
- ehr_direction_service_requests.ehealth_inserted_at AS performed_date,
- 0 AS assoc_type
- FROM (public.ehr_direction_service_requests
- JOIN public.ehr_ehealth_services ON (((ehr_ehealth_services.id = ehr_direction_service_requests.service_requestable_id) AND ((ehr_direction_service_requests.service_requestable_type)::text = 'Ehr::Ehealth::Service'::text) AND ((ehr_direction_service_requests.status)::text = ANY ((ARRAY['active'::character varying, 'completed'::character varying])::text[])))))
- UNION
- SELECT ehr_diagnostic_reports.id,
- ehr_diagnostic_reports.patient_id,
- ehr_ehealth_services.code AS service_code,
- ehr_diagnostic_reports.issued AS perfomed_date,
- 1 AS assoc_type
- FROM (public.ehr_diagnostic_reports
- JOIN public.ehr_ehealth_services ON (((ehr_diagnostic_reports.service_id = ehr_ehealth_services.id) AND (ehr_diagnostic_reports.ehealth_status = 1))))
- UNION
- SELECT ehr_observations.id,
- ehr_observations.patient_id,
- NULL::character varying AS service_code,
- ehr_observations.issued AS performed_date,
- 2 AS assoc_type
- FROM (public.ehr_observations
- JOIN public.classification_fhir_observation_codes ON (((classification_fhir_observation_codes.id = ehr_observations.codeable_id) AND ((classification_fhir_observation_codes.code)::text = '14743-9'::text))))) combined_data
- JOIN public.user_patients ON ((user_patients.id = combined_data.patient_id)))
- JOIN public.personalities ON (((personalities.id = user_patients.personality_id) AND ((personalities.type)::text = 'Patient::Person'::text))))
- JOIN public.declarations ON (((declarations.personality_id = personalities.id) AND (declarations.declaration_status_id = ( SELECT declaration_statuses.id
- FROM public.declaration_statuses
- WHERE ((declaration_statuses.code)::text = 'ACTIVE'::text))))))
- WITH NO DATA;
- --
- -- Name: idx_k4_mv_connected_assocs_disease_progresses_patient_id; Type: INDEX; Schema: public; Owner: -
- --
- CREATE INDEX idx_k4_mv_connected_assocs_disease_progresses_patient_id ON public.mv_connected_assocs_disease_progresses USING btree (patient_id);
- --
- -- Name: mv_encounter_disease_progresses; Type: MATERIALIZED VIEW; Schema: public; Owner: -
- --
- CREATE MATERIALIZED VIEW public.mv_encounter_disease_progresses
- WITH (autovacuum_enabled=off) AS
- SELECT receptions.id,
- receptions.patient_id,
- receptions.onset_date,
- CASE
- WHEN ((EXISTS ( SELECT 1
- FROM (public.ehr_reasons
- JOIN public.classification_icpc2_items ON (((ehr_reasons.encounter_id = receptions.id) AND (ehr_reasons.icpc2_reason_id = classification_icpc2_items.id) AND ((classification_icpc2_items.code)::text = 'A98'::text)))))) AND (EXISTS ( SELECT 1
- FROM (public.ehr_observations
- JOIN public.classification_fhir_observation_codes ON (((ehr_observations.encounter_id = receptions.id) AND (classification_fhir_observation_codes.id = ehr_observations.codeable_id) AND ((classification_fhir_observation_codes.code)::text = ANY ((ARRAY['39156-5'::character varying, '14743-9'::character varying, '8462-4'::character varying, '8480-6'::character varying])::text[])))))))) THEN true
- ELSE false
- END AS prof_check
- FROM (((public.receptions
- JOIN public.user_patients ON ((user_patients.id = receptions.patient_id)))
- JOIN public.personalities ON (((personalities.id = user_patients.personality_id) AND ((personalities.type)::text = 'Patient::Person'::text))))
- JOIN public.declarations ON (((declarations.personality_id = personalities.id) AND (declarations.declaration_status_id = ( SELECT declaration_statuses.id
- FROM public.declaration_statuses
- WHERE ((declaration_statuses.code)::text = 'ACTIVE'::text))))))
- WHERE (receptions.ehealth_status = 1)
- WITH NO DATA;
- --
- -- Name: idx_k4_mv_encounter_disease_progresses_patient_id; Type: INDEX; Schema: public; Owner: -
- --
- CREATE INDEX idx_k4_mv_encounter_disease_progresses_patient_id ON public.mv_encounter_disease_progresses USING btree (patient_id);
- --
- -- Name: mv_stat_calendar_events_service_requests; Type: MATERIALIZED VIEW; Schema: public; Owner: -
- --
- CREATE MATERIALIZED VIEW public.mv_stat_calendar_events_service_requests
- WITH (autovacuum_enabled=off) AS
- SELECT calendar_events.id,
- calendar_events.legal_entity_id,
- calendar_events.service_request_id,
- calendar_events.created_at,
- ehr_direction_service_requests.service_requestable_id,
- ehr_direction_service_requests.program_processing_status
- FROM ((public.calendar_events
- JOIN public.ehr_direction_service_requests ON ((ehr_direction_service_requests.id = calendar_events.service_request_id)))
- JOIN public.ehr_ehealth_services ON ((ehr_ehealth_services.id = ehr_direction_service_requests.service_requestable_id)))
- WHERE (((calendar_events.state)::text = 'approved'::text) AND ((ehr_direction_service_requests.status)::text = ANY (ARRAY[('completed'::character varying)::text, ('active'::character varying)::text])))
- WITH NO DATA;
- --
- -- Name: idx_k4_mv_stat_calendar_events_service_requests_legal_service; Type: INDEX; Schema: public; Owner: -
- --
- CREATE INDEX idx_k4_mv_stat_calendar_events_service_requests_legal_service ON public.mv_stat_calendar_events_service_requests USING btree (legal_entity_id, service_requestable_id);
- --
- -- Name: mv_stat_conditions; Type: MATERIALIZED VIEW; Schema: public; Owner: -
- --
- CREATE MATERIALIZED VIEW public.mv_stat_conditions
- WITH (autovacuum_enabled=off) AS
- SELECT ehr_conditions.encounter_id,
- ehr_conditions.patient_id,
- ehr_conditions.employee_id,
- classification_icpc2_items.code,
- (classification_icpc2_items.title_translations OPERATOR(public.->) 'uk'::text) AS label,
- receptions.asserted_date
- FROM ((public.ehr_conditions
- JOIN public.receptions ON (((receptions.id = ehr_conditions.encounter_id) AND (receptions.ehealth_status = 1))))
- JOIN public.classification_icpc2_items ON ((((classification_icpc2_items.type)::text = 'Classification::Icpc2::Condition'::text) AND (classification_icpc2_items.id = ehr_conditions.icpc2_code_id))))
- WHERE ((ehr_conditions.employee_id IS NOT NULL) AND (((classification_icpc2_items.code)::text = ANY (ARRAY[('T90'::character varying)::text, ('K85'::character varying)::text, ('K86'::character varying)::text, ('K87'::character varying)::text, ('R96'::character varying)::text])) OR ((classification_icpc2_items.code)::text ~~ 'P%'::text)))
- WITH NO DATA;
- --
- -- Name: idx_k4_mv_stat_condition_code; Type: INDEX; Schema: public; Owner: -
- --
- CREATE INDEX idx_k4_mv_stat_condition_code ON public.mv_stat_conditions USING btree (code);
- --
- -- Name: idx_k4_mv_stat_condition_code_asserted_date; Type: INDEX; Schema: public; Owner: -
- --
- CREATE INDEX idx_k4_mv_stat_condition_code_asserted_date ON public.mv_stat_conditions USING btree (code, asserted_date);
- --
- -- Name: idx_k4_mv_stat_condition_employee_patient; Type: INDEX; Schema: public; Owner: -
- --
- CREATE INDEX idx_k4_mv_stat_condition_employee_patient ON public.mv_stat_conditions USING btree (employee_id, patient_id);
- --
- -- Name: mv_stat_declarations; Type: MATERIALIZED VIEW; Schema: public; Owner: -
- --
- CREATE MATERIALIZED VIEW public.mv_stat_declarations
- WITH (autovacuum_enabled=off) AS
- SELECT DISTINCT ON (declarations.id) declarations.id,
- declarations.employee_id,
- declarations.personality_id,
- declarations.division_id,
- declarations.start_date,
- declarations.end_date,
- "Parties"."LegalEntityId" AS legal_entity_id,
- user_patients.id AS patient_id,
- personalities.birth_date,
- declaration_statuses.code AS declaration_status_code,
- receptions.asserted_date
- FROM ((((((public.declarations
- JOIN dbo."Employees" ON (("Employees"."Id" = declarations.employee_id)))
- JOIN public.declaration_statuses ON ((declaration_statuses.id = declarations.declaration_status_id)))
- JOIN dbo."Parties" ON (("Parties"."Id" = "Employees"."PartyId")))
- JOIN public.personalities ON (((personalities.id = declarations.personality_id) AND ((personalities.type)::text = 'Patient::Person'::text))))
- JOIN public.user_patients ON ((user_patients.personality_id = personalities.id)))
- LEFT JOIN public.receptions ON (((receptions.patient_id = user_patients.id) AND (receptions.ehealth_status = 1))))
- WHERE ((declaration_statuses.code)::text = ANY (ARRAY[('ACTIVE'::character varying)::text, ('COMPLETED'::character varying)::text]))
- ORDER BY declarations.id, receptions.asserted_date DESC
- WITH NO DATA;
- --
- -- Name: idx_k4_mv_stat_declarations_by_date; Type: INDEX; Schema: public; Owner: -
- --
- CREATE INDEX idx_k4_mv_stat_declarations_by_date ON public.mv_stat_declarations USING btree (legal_entity_id, start_date);
- --
- -- Name: idx_k4_mv_stat_declarations_by_division; Type: INDEX; Schema: public; Owner: -
- --
- CREATE INDEX idx_k4_mv_stat_declarations_by_division ON public.mv_stat_declarations USING btree (legal_entity_id, division_id);
- --
- -- Name: idx_k4_mv_stat_declarations_by_employee; Type: INDEX; Schema: public; Owner: -
- --
- CREATE INDEX idx_k4_mv_stat_declarations_by_employee ON public.mv_stat_declarations USING btree (legal_entity_id, employee_id);
- --
- -- Name: idx_k4_mv_stat_declarations_emp_pers; Type: INDEX; Schema: public; Owner: -
- --
- CREATE INDEX idx_k4_mv_stat_declarations_emp_pers ON public.mv_stat_declarations USING btree (legal_entity_id, personality_id);
- --
- -- Name: idx_k4_mv_stat_declarations_legal; Type: INDEX; Schema: public; Owner: -
- --
- CREATE INDEX idx_k4_mv_stat_declarations_legal ON public.mv_stat_declarations USING btree (legal_entity_id, id);
- --
- -- Name: idx_k4_mv_stat_declarations_status; Type: INDEX; Schema: public; Owner: -
- --
- CREATE INDEX idx_k4_mv_stat_declarations_status ON public.mv_stat_declarations USING btree (legal_entity_id, declaration_status_code);
- --
- -- Name: mv_stat_ehr_ehealth_service_groups; Type: MATERIALIZED VIEW; Schema: public; Owner: -
- --
- CREATE MATERIALIZED VIEW public.mv_stat_ehr_ehealth_service_groups
- WITH (autovacuum_enabled=off) AS
- SELECT ehr_ehealth_services.id,
- ehr_ehealth_service_groups.ehr_ehealth_group_id
- FROM (public.ehr_ehealth_services
- JOIN public.ehr_ehealth_service_groups ON ((ehr_ehealth_services.id = ehr_ehealth_service_groups.ehr_ehealth_service_id)))
- WITH NO DATA;
- --
- -- Name: idx_k4_mv_stat_ehr_ehealth_service_groups; Type: INDEX; Schema: public; Owner: -
- --
- CREATE INDEX idx_k4_mv_stat_ehr_ehealth_service_groups ON public.mv_stat_ehr_ehealth_service_groups USING btree (ehr_ehealth_group_id);
- --
- -- Name: mv_stat_employees_parties; Type: MATERIALIZED VIEW; Schema: public; Owner: -
- --
- CREATE MATERIALIZED VIEW public.mv_stat_employees_parties
- WITH (autovacuum_enabled=off) AS
- SELECT "Employees"."Id",
- "Employees"."PartyId",
- "Parties"."LegalEntityId",
- "Employees"."EmployeeTypeRefValue",
- "Employees"."EmployeeStatusRefValue",
- "Employees"."PositionRefId",
- "PositionRefs"."Value" AS "PositionRefValue",
- "PositionRefs"."_Name" AS "PositionName",
- "Parties"."FirstName",
- "Parties"."LastName",
- "Parties"."SecondName",
- "Employees"."DivisionId",
- concat_ws(' '::text, "Parties"."LastName", "Parties"."FirstName") AS "FullName"
- FROM ((dbo."Employees"
- JOIN dbo."Parties" ON (("Employees"."PartyId" = "Parties"."Id")))
- JOIN dbo."PositionRefs" ON (("PositionRefs"."Id" = "Employees"."PositionRefId")))
- WITH NO DATA;
- --
- -- Name: idx_k4_mv_stat_employees_parties; Type: INDEX; Schema: public; Owner: -
- --
- CREATE INDEX idx_k4_mv_stat_employees_parties ON public.mv_stat_employees_parties USING btree ("LegalEntityId", "EmployeeTypeRefValue", "EmployeeStatusRefValue") INCLUDE ("Id");
- --
- -- Name: idx_uq_k4_mv_stat_employees_le_id_division; Type: INDEX; Schema: public; Owner: -
- --
- CREATE INDEX idx_uq_k4_mv_stat_employees_le_id_division ON public.mv_stat_employees_parties USING btree ("LegalEntityId", "Id", "DivisionId");
- --
- -- Name: idx_uq_k4_mv_stat_employees_parties_id_legal; Type: INDEX; Schema: public; Owner: -
- --
- CREATE INDEX idx_uq_k4_mv_stat_employees_parties_id_legal ON public.mv_stat_employees_parties USING btree ("LegalEntityId", "Id");
- --
- -- Name: idx_uq_k4_mv_stat_employess_parties_id_full_position; Type: INDEX; Schema: public; Owner: -
- --
- CREATE INDEX idx_uq_k4_mv_stat_employess_parties_id_full_position ON public.mv_stat_employees_parties USING btree ("LegalEntityId", "Id", "PositionRefId", "FullName") INCLUDE ("PositionRefValue") WHERE ((("EmployeeTypeRefValue")::text = 'DOCTOR'::text) AND (("EmployeeStatusRefValue")::text = 'APPROVED'::text));
- --
- -- Name: mv_stat_imt_diseases; Type: MATERIALIZED VIEW; Schema: public; Owner: -
- --
- CREATE MATERIALIZED VIEW public.mv_stat_imt_diseases
- WITH (autovacuum_enabled=off) AS
- SELECT DISTINCT ON (ehr_observations.id, ehr_observations.patient_id, classification_fhir_observation_codes.code) 'ІМТ'::text AS label,
- ehr_observations.encounter_id,
- ehr_observations.employee_id,
- ehr_observations.patient_id,
- classification_fhir_observation_codes.code,
- receptions.asserted_date,
- CASE
- WHEN ((classification_fhir_observation_codes.code)::text = '39156-5'::text) THEN (NULLIF(regexp_replace((ehr_observations.surveillance_value ->> 'value'::text), '[^0-9.]+'::text, ''::text, 'g'::text), ''::text))::double precision
- ELSE (COALESCE((NULLIF(regexp_replace((ehr_observations.surveillance_value ->> 'value'::text), '[^0-9.]+'::text, ''::text, 'g'::text), ''::text))::double precision, (1)::double precision) / power(((COALESCE((NULLIF(regexp_replace(imt_table.observation_value, '[^0-9.]+'::text, ''::text, 'g'::text), ''::text))::numeric, (1)::numeric))::double precision * (0.01)::double precision), (2)::double precision))
- END AS imt_index
- FROM ((((public.ehr_observations
- JOIN public.classification_fhir_observation_codes ON (((classification_fhir_observation_codes.id = ehr_observations.codeable_id) AND ((classification_fhir_observation_codes.code)::text = ANY (ARRAY[('39156-5'::character varying)::text, ('29463-7'::character varying)::text])))))
- JOIN public.classification_fhir_items ON (((classification_fhir_items.id = classification_fhir_observation_codes.quantity_unit_id) AND ((classification_fhir_items.type)::text = 'Classification::Fhir::ValueSet::UcumUnit'::text))))
- JOIN public.receptions ON (((receptions.id = ehr_observations.encounter_id) AND (receptions.ehealth_status = 1))))
- LEFT JOIN ( SELECT ehr_observations_1.id,
- ehr_observations_1.patient_id,
- (classification_fhir_observation_codes_1.title_translations OPERATOR(public.->) 'uk'::text) AS observation_title,
- (ehr_observations_1.surveillance_value ->> 'value'::text) AS observation_value,
- classification_fhir_items_1.code AS unit_code
- FROM ((public.ehr_observations ehr_observations_1
- JOIN public.classification_fhir_observation_codes classification_fhir_observation_codes_1 ON (((classification_fhir_observation_codes_1.id = ehr_observations_1.codeable_id) AND ((classification_fhir_observation_codes_1.code)::text = '8302-2'::text))))
- JOIN public.classification_fhir_items classification_fhir_items_1 ON (((classification_fhir_items_1.id = classification_fhir_observation_codes_1.quantity_unit_id) AND ((classification_fhir_items_1.type)::text = 'Classification::Fhir::ValueSet::UcumUnit'::text))))
- ORDER BY ehr_observations_1.id DESC) imt_table ON (((imt_table.patient_id = ehr_observations.patient_id) AND ((classification_fhir_observation_codes.code)::text = '29463-7'::text))))
- WHERE ((ehr_observations.id IS NOT NULL) AND (ehr_observations.employee_id IS NOT NULL) AND (NULLIF(TRIM(BOTH FROM (ehr_observations.surveillance_value ->> 'value'::text)), ''::text) IS NOT NULL) AND ((((classification_fhir_observation_codes.code)::text = '39156-5'::text) AND ((COALESCE((NULLIF(regexp_replace((ehr_observations.surveillance_value ->> 'value'::text), '[^0-9.]+'::text, ''::text, 'g'::text), ''::text))::numeric, (1)::numeric))::double precision > (25)::double precision)) OR (((classification_fhir_observation_codes.code)::text = '29463-7'::text) AND (imt_table.patient_id IS NOT NULL) AND (COALESCE((NULLIF(regexp_replace(imt_table.observation_value, '[^0-9.]+'::text, ''::text, 'g'::text), ''::text))::numeric, (0)::numeric) > (0)::numeric) AND ((COALESCE((NULLIF(regexp_replace((ehr_observations.surveillance_value ->> 'value'::text), '[^0-9.]+'::text, ''::text, 'g'::text), ''::text))::double precision, (1)::double precision) / power(((COALESCE((NULLIF(regexp_replace(imt_table.observation_value, '[^0-9.]+'::text, ''::text, 'g'::text), ''::text))::numeric, (1)::numeric))::double precision * (0.01)::double precision), (2)::double precision)) > (25)::double precision))))
- WITH NO DATA;
- --
- -- Name: idx_k4_mv_stat_imt_diseases_asserted_date; Type: INDEX; Schema: public; Owner: -
- --
- CREATE INDEX idx_k4_mv_stat_imt_diseases_asserted_date ON public.mv_stat_imt_diseases USING btree (asserted_date);
- --
- -- Name: idx_k4_mv_stat_imt_diseases_employee; Type: INDEX; Schema: public; Owner: -
- --
- CREATE INDEX idx_k4_mv_stat_imt_diseases_employee ON public.mv_stat_imt_diseases USING btree (employee_id);
- --
- -- Name: idx_k4_mv_stat_imt_diseases_patient; Type: INDEX; Schema: public; Owner: -
- --
- CREATE INDEX idx_k4_mv_stat_imt_diseases_patient ON public.mv_stat_imt_diseases USING btree (patient_id);
- --
- -- Name: mv_stat_legal_entity_total_completed_service_requests; Type: MATERIALIZED VIEW; Schema: public; Owner: -
- --
- CREATE MATERIALIZED VIEW public.mv_stat_legal_entity_total_completed_service_requests
- WITH (autovacuum_enabled=off) AS
- SELECT ehr_direction_service_requests.legal_entity_id,
- count(ehr_direction_service_requests.id) AS counter
- FROM public.ehr_direction_service_requests
- WHERE (((ehr_direction_service_requests.status)::text = 'completed'::text) AND ((ehr_direction_service_requests.category_code)::text = 'counselling'::text))
- GROUP BY ehr_direction_service_requests.legal_entity_id
- WITH NO DATA;
- --
- -- Name: idx_uq_k4_mv_stat_mv_stat_legal_entity_completed_requests; Type: INDEX; Schema: public; Owner: -
- --
- CREATE INDEX idx_uq_k4_mv_stat_mv_stat_legal_entity_completed_requests ON public.mv_stat_legal_entity_total_completed_service_requests USING btree (legal_entity_id);
- --
- -- Name: mv_stat_legal_entity_total_reception_conditions; Type: MATERIALIZED VIEW; Schema: public; Owner: -
- --
- CREATE MATERIALIZED VIEW public.mv_stat_legal_entity_total_reception_conditions
- WITH (autovacuum_enabled=off) AS
- SELECT receptions.legal_entity_id,
- count(DISTINCT receptions.patient_id) AS counter
- FROM ((public.receptions
- JOIN public.ehr_conditions ON ((ehr_conditions.encounter_id = receptions.id)))
- JOIN public.classification_icpc2_items ON (((classification_icpc2_items.id = ehr_conditions.icpc2_code_id) AND ((classification_icpc2_items.type)::text = 'Classification::Icpc2::Condition'::text) AND (((classification_icpc2_items.code)::text >= 'K29'::text) AND ((classification_icpc2_items.code)::text <= 'K99'::text)))))
- WHERE (receptions.ehealth_status = 1)
- GROUP BY receptions.legal_entity_id
- WITH NO DATA;
- --
- -- Name: idx_uq_k4_mv_stat_mv_stat_legal_entity_reception_conditions; Type: INDEX; Schema: public; Owner: -
- --
- CREATE INDEX idx_uq_k4_mv_stat_mv_stat_legal_entity_reception_conditions ON public.mv_stat_legal_entity_total_reception_conditions USING btree (legal_entity_id);
- --
- -- Name: mv_stat_legal_entity_total_receptions; Type: MATERIALIZED VIEW; Schema: public; Owner: -
- --
- CREATE MATERIALIZED VIEW public.mv_stat_legal_entity_total_receptions
- WITH (autovacuum_enabled=off) AS
- SELECT receptions.legal_entity_id,
- count(receptions.id) AS counter
- FROM public.receptions
- WHERE (receptions.ehealth_status = 1)
- GROUP BY receptions.legal_entity_id
- WITH NO DATA;
- --
- -- Name: idx_uq_k4_mv_stat_mv_stat_legal_entity_id_total_receptions; Type: INDEX; Schema: public; Owner: -
- --
- CREATE INDEX idx_uq_k4_mv_stat_mv_stat_legal_entity_id_total_receptions ON public.mv_stat_legal_entity_total_receptions USING btree (legal_entity_id);
- --
- -- Name: mv_stat_legal_entity_total_service_requests; Type: MATERIALIZED VIEW; Schema: public; Owner: -
- --
- CREATE MATERIALIZED VIEW public.mv_stat_legal_entity_total_service_requests
- WITH (autovacuum_enabled=off) AS
- SELECT ehr_direction_service_requests.legal_entity_id,
- count(ehr_direction_service_requests.id) AS counter
- FROM public.ehr_direction_service_requests
- WHERE (((ehr_direction_service_requests.status)::text = ANY (ARRAY[('completed'::character varying)::text, ('active'::character varying)::text])) AND ((ehr_direction_service_requests.category_code)::text = 'counselling'::text))
- GROUP BY ehr_direction_service_requests.legal_entity_id
- WITH NO DATA;
- --
- -- Name: idx_uq_k4_mv_stat_mv_stat_legal_entity_id_service_requests; Type: INDEX; Schema: public; Owner: -
- --
- CREATE INDEX idx_uq_k4_mv_stat_mv_stat_legal_entity_id_service_requests ON public.mv_stat_legal_entity_total_service_requests USING btree (legal_entity_id);
- --
- -- Name: mv_stat_patient_personalities; Type: MATERIALIZED VIEW; Schema: public; Owner: -
- --
- CREATE MATERIALIZED VIEW public.mv_stat_patient_personalities
- WITH (autovacuum_enabled=off) AS
- SELECT user_patients.id,
- personalities.id AS personalities_id,
- declarations.id AS declaration_id,
- declarations.employee_id,
- personalities.gender,
- user_patients.is_smoking,
- personalities.birth_date,
- EXTRACT(year FROM age((personalities.birth_date)::timestamp with time zone)) AS age,
- concat_ws(' '::text, personalities.last_name, personalities.first_name) AS original_name,
- concat_ws(' '::text, personalities.last_name, personalities.first_name, personalities.second_name) AS full_name
- FROM (((public.user_patients
- JOIN public.personalities ON ((user_patients.personality_id = personalities.id)))
- JOIN public.declarations ON ((declarations.personality_id = personalities.id)))
- JOIN public.declaration_statuses ON ((declaration_statuses.id = declarations.declaration_status_id)))
- WHERE (((declaration_statuses.code)::text = 'ACTIVE'::text) AND ((personalities.type)::text = 'Patient::Person'::text))
- WITH NO DATA;
- --
- -- Name: idx_k4_mv_stat_patient_personalities_age; Type: INDEX; Schema: public; Owner: -
- --
- CREATE INDEX idx_k4_mv_stat_patient_personalities_age ON public.mv_stat_patient_personalities USING btree (age);
- --
- -- Name: idx_k4_mv_stat_patient_personalities_age_is_smoking; Type: INDEX; Schema: public; Owner: -
- --
- CREATE INDEX idx_k4_mv_stat_patient_personalities_age_is_smoking ON public.mv_stat_patient_personalities USING btree (age, is_smoking);
- --
- -- Name: idx_k4_mv_stat_patient_personalities_employee; Type: INDEX; Schema: public; Owner: -
- --
- CREATE INDEX idx_k4_mv_stat_patient_personalities_employee ON public.mv_stat_patient_personalities USING btree (id, employee_id);
- --
- -- Name: mv_stat_receptions_conditions; Type: MATERIALIZED VIEW; Schema: public; Owner: -
- --
- CREATE MATERIALIZED VIEW public.mv_stat_receptions_conditions
- WITH (autovacuum_enabled=off) AS
- SELECT receptions.id,
- receptions.legal_entity_id,
- receptions.patient_id,
- medication_prescriptions.ehealth_status AS medication_prescriptions_ehealth_status,
- medication_prescriptions.program_id AS prescription_program_id,
- classification_icpc2_items.id AS icpc2_code_id
- FROM (((public.receptions
- JOIN public.ehr_conditions ON ((ehr_conditions.encounter_id = receptions.id)))
- LEFT JOIN public.medication_prescriptions ON (((medication_prescriptions.encounter_id = receptions.id) AND (medication_prescriptions.ehealth_status = ANY (ARRAY[0, 1])))))
- JOIN public.classification_icpc2_items ON (((classification_icpc2_items.id = ehr_conditions.icpc2_code_id) AND ((classification_icpc2_items.type)::text = 'Classification::Icpc2::Condition'::text) AND (((classification_icpc2_items.code)::text >= 'K29'::text) AND ((classification_icpc2_items.code)::text <= 'K99'::text)))))
- WHERE (receptions.ehealth_status = 1)
- WITH NO DATA;
- --
- -- Name: idx_k4_mv_stat_receptions_conditions_legal_patient_id; Type: INDEX; Schema: public; Owner: -
- --
- CREATE INDEX idx_k4_mv_stat_receptions_conditions_legal_patient_id ON public.mv_stat_receptions_conditions USING btree (legal_entity_id, medication_prescriptions_ehealth_status, patient_id, prescription_program_id, icpc2_code_id, id);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement