View difference between Paste ID: Cc9eTzPq and HcZ4NhMn
SHOW: | | - or go back to the newest paste.
1-
-- http://localhost:4000/api/v1/chronic_diseases/patients
1+
-- http://localhost:4000/api/v1/chronic_diseases/employees
2
3-
SELECT DISTINCT "mv_stat_declarations".* FROM "mv_stat_declarations" WHERE ("mv_stat_declarations"."legal_entity_id" = 3228) AND "mv_stat_declarations"."declaration_status_code" = $1  [["declaration_status_code", "ACTIVE"]]
3+
MainApplication::Dbo::LegalEntity Load (1.8ms)
4
SELECT "dbo"."LegalEntities".* FROM "dbo"."LegalEntities" WHERE "dbo"."LegalEntities"."Id" = $1 LIMIT $2  [["Id", 3228], ["LIMIT", 1]]
5-
 SELECT "mv_stat_patient_personalities".* FROM "mv_stat_patient_personalities" WHERE "mv_stat_patient_personalities"."id" IN ($1, $2, $3, $4, $5)  [["id", 11395822], ["id", 11395824], ["id", 11464974], ["id", 11464976], ["id", 11464994]]
5+
6
View::MvStatistic::Level0::Employee Load (7.4ms)
7-
SELECT "mv_stat_employees_parties".* FROM "mv_stat_employees_parties" WHERE "mv_stat_employees_parties"."Id" IN ($1, $2)  [["Id", 180499], ["Id", 181286]]
7+
SELECT mv_stat_lvl_0_employees.id,
8
mv_stat_lvl_0_employees.full_name,
9-
SELECT MAX(receptions.patient_id) as patient_id, COUNT(DISTINCT receptions.patient_id) as counter FROM "receptions" WHERE ("receptions"."ehealth_status" = 1) AND "receptions"."asserted_date" BETWEEN $1 AND $2 AND "receptions"."patient_id" IN ($3, $4, $5, $6, $7) GROUP BY date(asserted_date), patient_id  [["asserted_date", "2024-01-01 00:00:00"], ["asserted_date", "2024-02-02 23:59:59.999999"], ["patient_id", 11395822], ["patient_id", 11395824], ["patient_id", 11464974], ["patient_id", 11464976], ["patient_id", 11464994]
9+
COUNT(DISTINCT mv_stat_lvl_0_declarations.patient_id) AS total_counter,
10
COUNT(DISTINCT mv_stat_lvl_1_patients.id) filter (WHERE mv_stat_lvl_1_patients.is_smoking = true AND mv_stat_lvl_1_patients.age BETWEEN 18 AND 69) AS smoking_counter,
11-
SELECT "mv_stat_imt_diseases".* FROM "mv_stat_imt_diseases" WHERE "mv_stat_imt_diseases"."asserted_date" BETWEEN $1 AND $2 AND "mv_stat_imt_diseases"."patient_id" IN ($3, $4, $5, $6, $7)  [["asserted_date", "2024-01-01 00:00:00"], ["asserted_date", "2024-02-02 23:59:59.999999"], ["patient_id", 11395822], ["patient_id", 11395824], ["patient_id", 11464974], ["patient_id", 11464976], ["patient_id", 11464994]]
11+
COUNT(DISTINCT mv_stat_lvl_2_imt_indices.patient_id) filter (WHERE mv_stat_lvl_1_patients.age BETWEEN 18 AND 69 AND mv_stat_lvl_2_imt_indices.imt_index > 25 AND mv_stat_lvl_2_imt_indices.asserted_date BETWEEN '2024-01-01 00:00:00' AND '2024-02-12 23:59:59.999999' ) AS overweight_counter,
12
COUNT(DISTINCT mv_stat_lvl_1_ehr_conditions.patient_id) filter (WHERE mv_stat_lvl_1_ehr_conditions.code IN ('K85', 'K86', 'K87') AND mv_stat_lvl_1_ehr_conditions.asserted_date BETWEEN '2024-01-01 00:00:00' AND '2024-02-12 23:59:59.999999' ) AS hypertension_counter,
13-
SELECT "mv_stat_conditions".* FROM "mv_stat_conditions" WHERE "mv_stat_conditions"."asserted_date" BETWEEN $1 AND $2 AND "mv_stat_conditions"."patient_id" IN ($3, $4, $5, $6, $7)  [["asserted_date", "2024-01-01 00:00:00"], ["asserted_date", "2024-02-02 23:59:59.999999"], ["patient_id", 11395822], ["patient_id", 11395824], ["patient_id", 11464974], ["patient_id", 11464976], ["patient_id", 11464994]]
13+
COUNT(DISTINCT mv_stat_lvl_1_ehr_conditions.patient_id) filter (WHERE mv_stat_lvl_1_ehr_conditions.code IN ('T90') AND mv_stat_lvl_1_ehr_conditions.asserted_date BETWEEN '2024-01-01 00:00:00' AND '2024-02-12 23:59:59.999999') AS diabetes_counter,
14
COUNT(DISTINCT mv_stat_lvl_1_ehr_conditions.patient_id) filter (WHERE mv_stat_lvl_1_ehr_conditions.code IN ('R96') AND mv_stat_lvl_1_ehr_conditions.asserted_date BETWEEN '2024-01-01 00:00:00' AND '2024-02-12 23:59:59.999999') AS asthma_counter,
15
COUNT(DISTINCT mv_stat_lvl_1_ehr_conditions.patient_id) filter (WHERE mv_stat_lvl_1_ehr_conditions.code LIKE 'P%' AND mv_stat_lvl_1_ehr_conditions.asserted_date BETWEEN '2024-01-01 00:00:00' AND '2024-02-12 23:59:59.999999') AS derangement_counter,
16
COUNT(DISTINCT mv_stat_lvl_0_receptions.patient_id) filter (WHERE mv_stat_lvl_0_receptions.asserted_date BETWEEN '2024-01-01 00:00:00' AND '2024-02-12 23:59:59.999999') AS reception_counter FROM "mv_stat_lvl_0_employees" LEFT OUTER JOIN "mv_stat_lvl_0_receptions" ON "mv_stat_lvl_0_receptions"."employee_id" = "mv_stat_lvl_0_employees"."id" LEFT OUTER JOIN "mv_stat_lvl_0_declarations" ON "mv_stat_lvl_0_declarations"."employee_id" = "mv_stat_lvl_0_employees"."id" LEFT OUTER JOIN "mv_stat_lvl_2_imt_indices" ON "mv_stat_lvl_2_imt_indices"."patient_id" = "mv_stat_lvl_0_declarations"."patient_id" LEFT OUTER JOIN "mv_stat_lvl_1_ehr_conditions" ON "mv_stat_lvl_1_ehr_conditions"."patient_id" = "mv_stat_lvl_0_declarations"."patient_id" LEFT OUTER JOIN "mv_stat_lvl_1_patients" ON "mv_stat_lvl_1_patients"."id" = "mv_stat_lvl_0_declarations"."patient_id" WHERE "mv_stat_lvl_0_employees"."legal_entity_id" = $1 AND "mv_stat_lvl_0_employees"."employee_type_ref_value" = $2 GROUP BY mv_stat_lvl_0_employees.id, mv_stat_lvl_0_employees.full_name  [["legal_entity_id", 3228], ["employee_type_ref_value", "DOCTOR"]]
17
18
View::MvStatistic::Level0::Declaration Count (1.0ms)
19
SELECT COUNT(DISTINCT mv_stat_lvl_2_imt_indices.patient_id) FROM "mv_stat_lvl_0_declarations" INNER JOIN "mv_stat_lvl_1_patients" ON "mv_stat_lvl_1_patients"."id" = "mv_stat_lvl_0_declarations"."patient_id" INNER JOIN "mv_stat_lvl_2_imt_indices" ON "mv_stat_lvl_2_imt_indices"."patient_id" = "mv_stat_lvl_0_declarations"."patient_id" WHERE "mv_stat_lvl_0_declarations"."legal_entity_id" = $1 AND "mv_stat_lvl_1_patients"."age" BETWEEN $2 AND $3 AND "mv_stat_lvl_2_imt_indices"."asserted_date" BETWEEN $4 AND $5  [["legal_entity_id", 3228], ["age", "18.0"], ["age", "69.0"], ["asserted_date", "2024-01-01 00:00:00"], ["asserted_date", "2024-02-12 23:59:59.999999"]]
20
21
View::MvStatistic::Level0::Declaration Count (0.5ms)  
22
SELECT COUNT("mv_stat_lvl_0_declarations"."id") FROM "mv_stat_lvl_0_declarations" INNER JOIN "mv_stat_lvl_1_patients" ON "mv_stat_lvl_1_patients"."id" = "mv_stat_lvl_0_declarations"."patient_id" WHERE "mv_stat_lvl_0_declarations"."legal_entity_id" = $1  [["legal_entity_id", 3228]]
23
24
25
View::MvStatistic::Level0::Employee Count (0.3ms)  
26
SELECT COUNT("mv_stat_lvl_0_employees"."id") FROM "mv_stat_lvl_0_employees" WHERE "mv_stat_lvl_0_employees"."legal_entity_id" = $1 AND "mv_stat_lvl_0_employees"."employee_type_ref_value" = $2  [["legal_entity_id", 3228], ["employee_type_ref_value", "DOCTOR"]]
27
28
 View::MvStatistic::Level0::Declaration Count (0.5ms)
29
 SELECT COUNT("mv_stat_lvl_1_patients"."id") FROM "mv_stat_lvl_0_declarations" INNER JOIN "mv_stat_lvl_1_patients" ON "mv_stat_lvl_1_patients"."id" = "mv_stat_lvl_0_declarations"."patient_id" WHERE "mv_stat_lvl_0_declarations"."legal_entity_id" = $1 AND "mv_stat_lvl_1_patients"."age" BETWEEN $2 AND $3 AND "mv_stat_lvl_1_patients"."is_smoking" = $4  [["legal_entity_id", 3228], ["age", "18.0"], ["age", "69.0"], ["is_smoking", true]]
30
31
View::MvStatistic::Level0::Declaration Count (0.7ms)  
32
SELECT COUNT(DISTINCT mv_stat_lvl_1_ehr_conditions.patient_id) FROM "mv_stat_lvl_0_declarations" INNER JOIN "mv_stat_lvl_1_patients" ON "mv_stat_lvl_1_patients"."id" = "mv_stat_lvl_0_declarations"."patient_id" INNER JOIN "mv_stat_lvl_1_ehr_conditions" ON "mv_stat_lvl_1_ehr_conditions"."patient_id" = "mv_stat_lvl_0_declarations"."patient_id" WHERE "mv_stat_lvl_0_declarations"."legal_entity_id" = $1 AND "mv_stat_lvl_1_ehr_conditions"."code" IN ($2, $3, $4) AND "mv_stat_lvl_1_ehr_conditions"."asserted_date" BETWEEN $5 AND $6  [["legal_entity_id", 3228], ["code", "K85"], ["code", "K86"], ["code", "K87"], ["asserted_date", "2024-01-01 00:00:00"], ["asserted_date", "2024-02-12 23:59:59.999999"]]
33
34
View::MvStatistic::Level0::Declaration Count (0.6ms)  
35
SELECT COUNT(DISTINCT mv_stat_lvl_1_ehr_conditions.patient_id) FROM "mv_stat_lvl_0_declarations" INNER JOIN "mv_stat_lvl_1_patients" ON "mv_stat_lvl_1_patients"."id" = "mv_stat_lvl_0_declarations"."patient_id" INNER JOIN "mv_stat_lvl_1_ehr_conditions" ON "mv_stat_lvl_1_ehr_conditions"."patient_id" = "mv_stat_lvl_0_declarations"."patient_id" WHERE "mv_stat_lvl_0_declarations"."legal_entity_id" = $1 AND "mv_stat_lvl_1_ehr_conditions"."code" = $2 AND "mv_stat_lvl_1_ehr_conditions"."asserted_date" BETWEEN $3 AND $4  [["legal_entity_id", 3228], ["code", "T90"], ["asserted_date", "2024-01-01 00:00:00"], ["asserted_date", "2024-02-12 23:59:59.999999"]]
36
37
38
View::MvStatistic::Level0::Declaration Count (0.6ms)
39
SELECT COUNT(DISTINCT mv_stat_lvl_1_ehr_conditions.patient_id) FROM "mv_stat_lvl_0_declarations" INNER JOIN "mv_stat_lvl_1_patients" ON "mv_stat_lvl_1_patients"."id" = "mv_stat_lvl_0_declarations"."patient_id" INNER JOIN "mv_stat_lvl_1_ehr_conditions" ON "mv_stat_lvl_1_ehr_conditions"."patient_id" = "mv_stat_lvl_0_declarations"."patient_id" WHERE "mv_stat_lvl_0_declarations"."legal_entity_id" = $1 AND "mv_stat_lvl_1_ehr_conditions"."code" = $2 AND "mv_stat_lvl_1_ehr_conditions"."asserted_date" BETWEEN $3 AND $4  [["legal_entity_id", 3228], ["code", "R96"], ["asserted_date", "2024-01-01 00:00:00"], ["asserted_date", "2024-02-12 23:59:59.999999"]]
40
41
View::MvStatistic::Level0::Declaration Count (0.6ms)  
42
SELECT COUNT(DISTINCT mv_stat_lvl_1_ehr_conditions.patient_id) FROM "mv_stat_lvl_0_declarations" INNER JOIN "mv_stat_lvl_1_patients" ON "mv_stat_lvl_1_patients"."id" = "mv_stat_lvl_0_declarations"."patient_id" INNER JOIN "mv_stat_lvl_1_ehr_conditions" ON "mv_stat_lvl_1_ehr_conditions"."patient_id" = "mv_stat_lvl_0_declarations"."patient_id" WHERE "mv_stat_lvl_0_declarations"."legal_entity_id" = $1 AND (mv_stat_lvl_1_ehr_conditions.code LIKE 'P%') AND "mv_stat_lvl_1_ehr_conditions"."asserted_date" BETWEEN $2 AND $3  [["legal_entity_id", 3228], ["asserted_date", "2024-01-01 00:00:00"], ["asserted_date", "2024-02-12 23:59:59.999999"]]
43
  ↳ app/services/calculators/chronic_diseases/general_count_service.rb:77:in `derangement_counter'
44
  CACHE View::MvStatistic::Level0::Declaration Count (0.0ms)  SELECT COUNT("mv_stat_lvl_0_declarations"."id") FROM "mv_stat_lvl_0_declarations" INNER JOIN "mv_stat_lvl_1_patients" ON "mv_stat_lvl_1_patients"."id" = "mv_stat_lvl_0_declarations"."patient_id" WHERE "mv_stat_lvl_0_declarations"."legal_entity_id" = $1  [["legal_entity_id", 3228]]
45
46
View::MvStatistic::Level0::Employee Load (2.2ms)
47
SELECT mv_stat_lvl_0_employees.id,
48
mv_stat_lvl_0_employees.full_name,
49
COUNT(DISTINCT mv_stat_lvl_0_declarations.patient_id) AS total_counter,
50
COUNT(DISTINCT mv_stat_lvl_1_patients.id) filter (WHERE mv_stat_lvl_1_patients.is_smoking = true AND mv_stat_lvl_1_patients.age BETWEEN 18 AND 69) AS smoking_counter,
51
COUNT(DISTINCT mv_stat_lvl_2_imt_indices.patient_id) filter (WHERE mv_stat_lvl_1_patients.age BETWEEN 18 AND 69 AND mv_stat_lvl_2_imt_indices.imt_index > 25 AND mv_stat_lvl_2_imt_indices.asserted_date BETWEEN '2024-01-01 00:00:00' AND '2024-02-12 23:59:59.999999' ) AS overweight_counter,
52
COUNT(DISTINCT mv_stat_lvl_1_ehr_conditions.patient_id) filter (WHERE mv_stat_lvl_1_ehr_conditions.code IN ('K85', 'K86', 'K87') AND mv_stat_lvl_1_ehr_conditions.asserted_date BETWEEN '2024-01-01 00:00:00' AND '2024-02-12 23:59:59.999999' ) AS hypertension_counter,
53
COUNT(DISTINCT mv_stat_lvl_1_ehr_conditions.patient_id) filter (WHERE mv_stat_lvl_1_ehr_conditions.code IN ('T90') AND mv_stat_lvl_1_ehr_conditions.asserted_date BETWEEN '2024-01-01 00:00:00' AND '2024-02-12 23:59:59.999999') AS diabetes_counter,
54
COUNT(DISTINCT mv_stat_lvl_1_ehr_conditions.patient_id) filter (WHERE mv_stat_lvl_1_ehr_conditions.code IN ('R96') AND mv_stat_lvl_1_ehr_conditions.asserted_date BETWEEN '2024-01-01 00:00:00' AND '2024-02-12 23:59:59.999999') AS asthma_counter,
55
COUNT(DISTINCT mv_stat_lvl_1_ehr_conditions.patient_id) filter (WHERE mv_stat_lvl_1_ehr_conditions.code LIKE 'P%' AND mv_stat_lvl_1_ehr_conditions.asserted_date BETWEEN '2024-01-01 00:00:00' AND '2024-02-12 23:59:59.999999') AS derangement_counter,
56
COUNT(DISTINCT mv_stat_lvl_0_receptions.patient_id) filter (WHERE mv_stat_lvl_0_receptions.asserted_date BETWEEN '2024-01-01 00:00:00' AND '2024-02-12 23:59:59.999999') AS reception_counter FROM "mv_stat_lvl_0_employees" LEFT OUTER JOIN "mv_stat_lvl_0_receptions" ON "mv_stat_lvl_0_receptions"."employee_id" = "mv_stat_lvl_0_employees"."id" LEFT OUTER JOIN "mv_stat_lvl_0_declarations" ON "mv_stat_lvl_0_declarations"."employee_id" = "mv_stat_lvl_0_employees"."id" LEFT OUTER JOIN "mv_stat_lvl_2_imt_indices" ON "mv_stat_lvl_2_imt_indices"."patient_id" = "mv_stat_lvl_0_declarations"."patient_id" LEFT OUTER JOIN "mv_stat_lvl_1_ehr_conditions" ON "mv_stat_lvl_1_ehr_conditions"."patient_id" = "mv_stat_lvl_0_declarations"."patient_id" LEFT OUTER JOIN "mv_stat_lvl_1_patients" ON "mv_stat_lvl_1_patients"."id" = "mv_stat_lvl_0_declarations"."patient_id" WHERE "mv_stat_lvl_0_employees"."legal_entity_id" = $1 AND "mv_stat_lvl_0_employees"."employee_type_ref_value" = $2 GROUP BY mv_stat_lvl_0_employees.id, mv_stat_lvl_0_employees.full_name LIMIT $3 OFFSET $4  [["legal_entity_id", 3228], ["employee_type_ref_value", "DOCTOR"], ["LIMIT", 15], ["OFFSET", 0]]
57
58
Completed 200 OK in 88ms (Views: 0.4ms | ActiveRecord: 21.5ms | Allocations: 41999)
59