Changes between Version 1 and Version 2 of Views


Ignore:
Timestamp:
08/24/25 20:01:08 (9 days ago)
Author:
221007
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • Views

    v1 v2  
    44
    55=== 1. !MedicalReport View
    6 //todo
     6
     7{{{
     8CREATE OR REPLACE VIEW medical_report_view AS
     9select
     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
     31from report r join person p on p.person_id = r.person_id
     32join medicalreport mr on mr.report_id = r.report_id
     33join medicalreport_diagnosis mrd on mr.report_id = mrd.report_id
     34join diagnosis d on mrd.diagnosis_id = d.diagnosis_id
     35join doctor doc on doc.doctor_id = mr.doctor_id;
     36}}}
    737=== 2. !EmploymentReport View
    8 //todo
     38
     39{{{
     40CREATE OR REPLACE VIEW employment_report_view AS
     41SELECT
     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
     57FROM report r
     58JOIN person p ON p.person_id = r.person_id
     59JOIN employmentreport er ON er.report_id = r.report_id;
     60}}}
    961=== 3. !AcademicReport View
    10 //todo
     62{{{
     63CREATE OR REPLACE VIEW academic_report_view AS
     64select
     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
     83from report r
     84join person p on p.person_id = r.person_id
     85join academicreport ar on ar.report_id = r.report_id
     86join institution i on ar.institution_id = i.institution_id;
     87}}}
    1188=== 4. !CriminalReport View
    12 //todo
     89
     90{{{
     91CREATE OR REPLACE VIEW criminal_report_view AS
     92select
     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
     117from report r
     118join person p on p.person_id = r.person_id
     119join criminalreport cr on cr.report_id = r.report_id
     120join crimetype ct on ct.crime_type_id = cr.crime_type_id
     121join punishment punish on r.report_id = punish.report_id;
     122}}}