| 6 | | //todo |
| | 6 | |
| | 7 | {{{ |
| | 8 | CREATE OR REPLACE VIEW medical_report_view AS |
| | 9 | select |
| | 10 | r.report_id AS report_id, |
| | 11 | summary, |
| | 12 | r.created_at AS report_created_at, |
| | 13 | p.embg AS embg_of_person, |
| | 14 | (p.name || ' ' || p.surname) AS person_fullname, |
| | 15 | p.gender, |
| | 16 | p.date_of_birth, |
| | 17 | p.date_of_death, |
| | 18 | p.address AS address_of_living, |
| | 19 | p.contact_phone, |
| | 20 | r.report_type AS type_of_report, |
| | 21 | added_on as diagnosis_creation_date, |
| | 22 | short_description as diagnosis_description, |
| | 23 | is_chronic, |
| | 24 | severity, |
| | 25 | therapy as therapy_for_diagnosis, |
| | 26 | next_control_date, |
| | 27 | ('Dr. ' || doc.name || ' ' || doc.surname) AS doctor_fullname, |
| | 28 | specialization as doctor_specialization, |
| | 29 | is_active as is_doctor_still_active, |
| | 30 | years_of_experience |
| | 31 | from report r join person p on p.person_id = r.person_id |
| | 32 | join medicalreport mr on mr.report_id = r.report_id |
| | 33 | join medicalreport_diagnosis mrd on mr.report_id = mrd.report_id |
| | 34 | join diagnosis d on mrd.diagnosis_id = d.diagnosis_id |
| | 35 | join doctor doc on doc.doctor_id = mr.doctor_id; |
| | 36 | }}} |
| 8 | | //todo |
| | 38 | |
| | 39 | {{{ |
| | 40 | CREATE OR REPLACE VIEW employment_report_view AS |
| | 41 | SELECT |
| | 42 | r.report_id AS report_id, |
| | 43 | r.summary, |
| | 44 | r.created_at AS report_created_at, |
| | 45 | p.embg AS embg_of_person, |
| | 46 | (p.name || ' ' || p.surname) AS person_fullname, |
| | 47 | p.gender, |
| | 48 | p.date_of_birth, |
| | 49 | p.date_of_death, |
| | 50 | p.address AS address_of_living, |
| | 51 | p.contact_phone, |
| | 52 | r.report_type AS type_of_report, |
| | 53 | er.start_date AS started_working_date, |
| | 54 | er.end_date AS ended_working_date, |
| | 55 | er.job_role, |
| | 56 | er.income_per_month AS income_per_month_in_euros |
| | 57 | FROM report r |
| | 58 | JOIN person p ON p.person_id = r.person_id |
| | 59 | JOIN employmentreport er ON er.report_id = r.report_id; |
| | 60 | }}} |
| 10 | | //todo |
| | 62 | {{{ |
| | 63 | CREATE OR REPLACE VIEW academic_report_view AS |
| | 64 | select |
| | 65 | r.report_id AS report_id, |
| | 66 | summary, |
| | 67 | r.created_at AS report_created_at, |
| | 68 | p.embg AS embg_of_person, |
| | 69 | (p.name || ' ' || p.surname) AS person_fullname, |
| | 70 | p.gender, |
| | 71 | p.date_of_birth, |
| | 72 | p.date_of_death, |
| | 73 | p.address AS address_of_living, |
| | 74 | p.contact_phone, |
| | 75 | r.report_type AS type_of_report, |
| | 76 | academic_field, |
| | 77 | description_of_report as academic_report_description, |
| | 78 | i.name as institution_name, |
| | 79 | i.address as institution_address, |
| | 80 | year_established as institution_year_of_establishing, |
| | 81 | city as city_where_educating, |
| | 82 | type as type_of_education |
| | 83 | from report r |
| | 84 | join person p on p.person_id = r.person_id |
| | 85 | join academicreport ar on ar.report_id = r.report_id |
| | 86 | join institution i on ar.institution_id = i.institution_id; |
| | 87 | }}} |
| 12 | | //todo |
| | 89 | |
| | 90 | {{{ |
| | 91 | CREATE OR REPLACE VIEW criminal_report_view AS |
| | 92 | select |
| | 93 | r.report_id AS report_id, |
| | 94 | summary, |
| | 95 | r.created_at AS report_created_at, |
| | 96 | p.embg AS embg_of_person, |
| | 97 | (p.name || ' ' || p.surname) AS person_fullname, |
| | 98 | p.gender, |
| | 99 | p.date_of_birth, |
| | 100 | p.date_of_death, |
| | 101 | p.address AS address_of_living, |
| | 102 | p.contact_phone, |
| | 103 | r.report_type AS type_of_report, |
| | 104 | label as type_of_criminal, |
| | 105 | location as where_criminal_is_reported, |
| | 106 | resolved as is_resolved, |
| | 107 | descriptive_punishment, |
| | 108 | severity_level, |
| | 109 | CASE |
| | 110 | WHEN punishment_type = 'fine' AND value_unit = 'euros' THEN |
| | 111 | 'Fine: ' || fine_to_pay || ' €' |
| | 112 | WHEN punishment_type = 'prison' AND value_unit = 'years' THEN |
| | 113 | 'Release Date: ' || COALESCE(TO_CHAR(release_date, 'YYYY-MM-DD'), 'N/A') |
| | 114 | ELSE |
| | 115 | 'Unknown Punishment' |
| | 116 | END AS punishment |
| | 117 | from report r |
| | 118 | join person p on p.person_id = r.person_id |
| | 119 | join criminalreport cr on cr.report_id = r.report_id |
| | 120 | join crimetype ct on ct.crime_type_id = cr.crime_type_id |
| | 121 | join punishment punish on r.report_id = punish.report_id; |
| | 122 | }}} |