Skip to content

Commit

Permalink
Add Mi scope report
Browse files Browse the repository at this point in the history
  • Loading branch information
said-moj committed Sep 3, 2024
1 parent f971cea commit cfc2191
Show file tree
Hide file tree
Showing 4 changed files with 101 additions and 0 deletions.
32 changes: 32 additions & 0 deletions cla_backend/apps/reports/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -1008,6 +1008,38 @@ def get_headers(self):
]


class MIScopeReport(SQLFileDateRangeReport):
QUERY_FILE = "MIScopeReport.sql"

def get_sql_params(self):
from_date, to_date = self.date_range
return {"from_date": from_date, "to_date": to_date}

def get_headers(self):
return [
"Person ID",
"Case ID",
"Created",
"Modified",
"Case source",
"CHS scope state",
"Web scope state",
"Means eligibility state",
"Workflow status",
"CHS case outcome code",
"Provider Notes",
"Operator Notes",
"Client notes",
"Category code",
"Category name",
"Matter Type 1 code",
"Matter Type 1 description",
"Matter Type 2 code",
"Matter Type 2 description",
"Web diagnosis categories",
]


class CallbackTimeSlotReport(DateRangeReportForm):
def get_queryset(self):
from_date, to_date = self.date_range
Expand Down
61 changes: 61 additions & 0 deletions cla_backend/apps/reports/sql/MiScopeReport.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
WITH log_changed_category as (
SELECT log_created.case_id, (log_changed_category.patch #>> '{}')::json#>>'{backwards,0,value}' as "diagnosis_category"
FROM cla_eventlog_log as log_created
JOIN cla_eventlog_log as log_changed_category ON log_created.case_id=log_changed_category.case_id
AND log_created.notes = 'Case created digitally' AND log_changed_category.notes LIKE 'Changed category to%%'
),
log_mi_oos_outcome_code as (
SELECT case_id, code
FROM cla_eventlog_log
WHERE code = 'MIS-OOS'
GROUP BY case_id, code
)

SELECT
c.personal_details_id as "Person ID"
,c.reference as "Case Id"
,to_char(c.created, 'YYYY-MM-DD') as "Created"
,to_char(c.modified, 'YYYY-MM-DD') as "Modified"
,c.source as "Case source"
,CASE diagnosis.state
when 'INSCOPE' then 'yes'
else NULL
END as "CHS scope state"
,COALESCE(log_changed_category.diagnosis_category, category.code) as "Web scope state"
,CASE ec.state
when 'yes' then 'yes'
when 'no' then 'no'
else 'unknown'
END AS "Means eligibility state"
,CASE
WHEN ec.state NOT IN('yes', 'no') THEN 'Pending'
WHEN ec.state IS NOT NULL AND provider_assigned_at IS NULL THEN 'Operator'
WHEN c.provider_viewed IS NOT NULL AND log_mi_oos_outcome_code.code IS NULL THEN 'Read and approved by SP'
WHEN c.provider_viewed IS NOT NULL AND log_mi_oos_outcome_code.code IS NOT NULL THEN 'Read and NOT approved by SP'
ELSE 'Provider has not viewed'
END as "Workflow status"
,c.outcome_code as "CHS case outcome code"
,c.provider_notes as "Provider Notes"
,c.notes as "Operator Notes"
,ec.notes as "Client notes"
,category.code as "Category code"
,category.name as "Category name"
,mt1.code as "Matter Type 1 code"
,mt1.description as "Matter Type 1 description"
,mt2.code as "Matter Type 2 code"
,mt2.description as "Matter Type 2 description"
,ec.notes as "Web diagnosis categories"


FROM legalaid_case as c
LEFT OUTER JOIN legalaid_eligibilitycheck as ec on c.eligibility_check_id = ec.id
LEFT OUTER JOIN legalaid_category as category on ec.category_id = category.id
LEFT OUTER JOIN legalaid_adaptationdetails as adapt on c.adaptation_details_id = adapt.id
LEFT OUTER JOIN log_changed_category ON log_changed_category.case_id = c.id
LEFT OUTER JOIN legalaid_mattertype as mt1 on mt1.id = c.matter_type1_id
LEFT OUTER JOIN legalaid_mattertype as mt2 on mt2.id = c.matter_type2_id
LEFT OUTER JOIN diagnosis_diagnosistraversal as diagnosis on c.diagnosis_id = diagnosis.id
LEFT OUTER JOIN log_mi_oos_outcome_code ON log_mi_oos_outcome_code.case_id = c.id
WHERE source IN ('WEB')
AND c.modified >= %(from_date)s AND c.modified < %(to_date)s
ORDER BY c.modified DESC
1 change: 1 addition & 0 deletions cla_backend/apps/reports/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
url(r"^mi-comlpaints/$", views.mi_complaints, name="mi_complaints"),
url(r"^mi-obiee-extract/$", views.mi_obiee_extract, name="mi_obiee_extract"),
url(r"^mi-problem-categorisation/$", views.mi_problem_categorisation, name="mi_problem_categorisation"),
url(r"^mi-scope-report/$", views.mi_scope_report, name="mi_scope_report"),
url(r"^metrics-report/$", views.metrics_report, name="metrics_report"),
url(r"^all-knowledgebase-articles/$", views.all_knowledgebase_articles, name="all_knowledgebase_articles"),
url(r"^reasons-for-contacting/$", views.reasons_for_contacting, name="reasons_for_contacting"),
Expand Down
7 changes: 7 additions & 0 deletions cla_backend/apps/reports/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
ReasonsForContactingReport,
ReasonsForContactingDisaggregated,
MIProblemCategorisation,
MIScopeReport,
MIDemographicReport,
CallbackTimeSlotReport,
)
Expand Down Expand Up @@ -271,6 +272,12 @@ def mi_problem_categorisation(request):
return report_view(request, MIProblemCategorisation, "MI Problem Categorisation")


@staff_member_required
@permission_required("legalaid.run_reports")
def mi_scope_report(request):
return report_view(request, MIScopeReport, "MI Scope report")


@staff_member_required
@permission_required("legalaid.run_reports")
def callback_time_slot_report(request):
Expand Down

0 comments on commit cfc2191

Please sign in to comment.