From 7683bc889d1af8d9454c2c0150779f7a3cceebe7 Mon Sep 17 00:00:00 2001 From: bmugwe Date: Fri, 21 Jun 2024 13:03:29 +0300 Subject: [PATCH] added columns in home approval --- cpovc_mobile/urls.py | 7 +- cpovc_mobile/views.py | 219 ++++++++++++++++++++++++------ templates/mobile/home.html | 2 +- templates/mobile/preview_csr.html | 165 ++++++++++++---------- 4 files changed, 278 insertions(+), 115 deletions(-) diff --git a/cpovc_mobile/urls.py b/cpovc_mobile/urls.py index f76f7640..1d8a0c90 100644 --- a/cpovc_mobile/urls.py +++ b/cpovc_mobile/urls.py @@ -14,8 +14,13 @@ # Approval urls UI path("mobile-approval/", views.mobile_app_home, name="mobile_app_home"), re_path( - r"^crs/view/(?P\w+)/$", + r"^crs/view/(?P[0-9a-f]{8}-[0-9a-f]{4}-1[0-9a-f]{3}-[0-9a-f]{4}-[0-9a-f]{12})/$", views.view_mobile_case_record_sheet, name="view_mobile_case_record_sheet", ), +# re_path( +# r"^crs/view/(?P\w+)/$", +# views.view_mobile_case_record_sheet, +# name="view_mobile_case_record_sheet", +# ), ] diff --git a/cpovc_mobile/views.py b/cpovc_mobile/views.py index a5a0230c..6d76856f 100644 --- a/cpovc_mobile/views.py +++ b/cpovc_mobile/views.py @@ -1,13 +1,23 @@ from rest_framework.decorators import api_view from rest_framework.response import Response +from django.urls import reverse +from django.http import HttpResponseRedirect, HttpResponse, JsonResponse +from django.contrib import messages from rest_framework import viewsets, generics, status from cpovc_forms.models import OVCCaseRecord, OVCCaseGeo from cpovc_mobile.serializers import CaseRecordSerializer from django.shortcuts import render, redirect +from cpovc_forms.views import forms_registry from django.contrib.auth.decorators import login_required +from cpovc_registry.models import (AppUser, RegPerson, RegPersonsSiblings, RegPersonsGuardians, ) +from cpovc_forms.models import (OVCEconomicStatus, OVCFamilyStatus, OVCFriends, OVCHobbies,OVCMedical, OVCCaseCategory, + OVCNeeds, OVCReferral, OVCMedicalSubconditions, OVCCaseSubCategory,OVCCaseLocation, OvcCasePersons,) + +from cpovc_main.functions import (get_dict, translate) + @api_view(["POST", "GET"]) def ovc_mobile_home(request): @@ -106,42 +116,173 @@ def mobile_app_home(request): def view_mobile_case_record_sheet(request, id): - csr_id = id - print(f"CSR-ID: {csr_id}") - context = { - "cases": [ - { - "id": "749fc18f2cbf11efb24922a3499bfe31", - "care_id": "2323", - "case": "CCO/47/287/5/29/4423/2024", - "first_name": "Boniface", - "case_date": "2024-01-01", - "case_level": "8", - }, - { - "id": "749fc18f2cbf11efb24922a3499bfe32", - "care_id": "2323", - "case": "CCO/47/287/5/29/4425/2024", - "first_name": "John", - "case_date": "2024-01-01", - "case_level": "8", - }, - { - "id": "749fc18f2cbf11efb24922a3499bfe33", - "care_id": "2323", - "case": "CCO/47/287/5/29/4426/2024", - "first_name": "Jane", - "case_date": "2024-01-01", - "case_level": "8", - }, - { - "id": "749fc18f2cbf11efb24922a3499bfe33", - "care_id": "2323", - "case": "CCO/47/287/5/29/4427/2024", - "first_name": "Jude", - "case_date": "2024-01-01", - "case_level": "8", - }, - ] - } - return render(request, "mobile/preview_csr.html", context=context) + # csr_id = id + # print(f"CSR-ID: {csr_id}") + # context = { + + # } + # return render(request, "mobile/preview_csr.html", context=context) + try: + """Get Initial Data""" + # f = FormsLog.objects.get(form_id=id, is_void=False) + ovccr = OVCCaseRecord.objects.get(case_id=id, is_void=False) + person_id = int(ovccr.person_id) + # init_data = RegPerson.objects.filter(pk=person_id) + appuser = AppUser.objects.filter(pk=ovccr.created_by).first() + f = {'form_id': id} + + # Get Siblings + init_data = RegPerson.objects.filter(pk=person_id) + reg_personsiblings = [] + + regpersonsiblings = RegPersonsSiblings.objects.filter( + child_person_id=person_id) + for regpersonsibling in regpersonsiblings: + reg_personsiblings.append(regpersonsibling.sibling_person) + init_data.siblingpersons = reg_personsiblings + + reg_caregivers = [] + caregivers = RegPersonsGuardians.objects.filter( + child_person_id=person_id) + for caregiver in caregivers: + caregiver_details = caregiver.guardian_person + setattr(caregiver_details, 'relation', caregiver.relationship) + reg_caregivers.append(caregiver_details) + init_data.caregivers = reg_caregivers + + check_fields = ['sex_id', + 'family_status_id', + 'household_economics', + 'mental_condition_id', + 'mental_subcondition_id', + 'physical_condition_id', + 'physical_subcondition_id', + 'other_condition_id', + 'other_subcondition_id', + 'case_reporter_id', + 'perpetrator_status_id', + 'relationship_type_id', + 'perpetrator_id', 'risk_level_id', + 'referral_destination_id', + 'intervention_id', + 'case_category_id', 'core_item_id', + 'yesno_id', 'relationship_type_id', + 'case_reporter_relationship_to_child', + 'long_term_support_id', + 'immediate_need_id'] + + vals = get_dict(field_name=check_fields) + + ovcd = OVCEconomicStatus.objects.get(case_id=id, is_void=False) + ovcfam = OVCFamilyStatus.objects.filter(case_id=id, is_void=False) + ovccr = OVCCaseRecord.objects.get(case_id=id, is_void=False) + ovcgeo = OVCCaseGeo.objects.get(case_id=id, is_void=False) + ovcfrnds = OVCFriends.objects.filter(case_id=id, is_void=False) + ovchobs = OVCHobbies.objects.filter(case_id=id, is_void=False) + ovcmed = OVCMedical.objects.get(case_id=id, is_void=False) + ovcccats = OVCCaseCategory.objects.filter(case_id=id, is_void=False) + ovcneeds = OVCNeeds.objects.filter(case_id=id, is_void=False) + ovcrefa = OVCReferral.objects.filter(case_id=id, is_void=False) + perpetrators = OvcCasePersons.objects.filter( + case_id=id, person_type='PERP') + ovclocs = OVCCaseLocation.objects.filter(case_id=id, is_void=False) + + # Retrieve Medical Subconditions + medical_id = ovcmed.medical_id + ovcphymeds = OVCMedicalSubconditions.objects.filter( + medical_id=medical_id, medical_condition='Physical', is_void=False) + ovcmentmeds = OVCMedicalSubconditions.objects.filter( + medical_id=medical_id, medical_condition='Mental', is_void=False) + ovcothermeds = OVCMedicalSubconditions.objects.filter( + medical_id=medical_id, medical_condition='Other', is_void=False) + + # Get OVCCaseCategory + case_grouping_ids = [] + jsonCategorysData = [] + jsonSubCategorysData = [] + str_jsonsubcategorydata = '' + resultsets = [] + ovcccats = OVCCaseCategory.objects.filter( + case_id=id, is_void=False) + """ Get case_grouping_ids[] """ + for ovcccat in ovcccats: + case_grouping_id = str(ovcccat.case_grouping_id) + if not case_grouping_id in case_grouping_ids: + case_grouping_ids.append(str(case_grouping_id)) + + """ Get Case Categories """ + ovcccats2 = None + for case_grouping_id in case_grouping_ids: + ovcccats2 = OVCCaseCategory.objects.filter( + case_grouping_id=case_grouping_id) + + for ovcccat in ovcccats2: + # OVCCaseSubCategory + ovccasesubcategorys = OVCCaseSubCategory.objects.filter( + case_grouping_id=case_grouping_id) + for ovccasesubcategory in ovccasesubcategorys: + jsonSubCategorysData.append( + translate(str(ovccasesubcategory.sub_category_id))) + str_jsonsubcategorydata = ','.join(jsonSubCategorysData) + + jsonCategorysData.append({'case_category': ovcccat.case_category, + 'case_subcategorys': str_jsonsubcategorydata, + 'date_of_event': (ovcccat.date_of_event).strftime('%d-%b-%Y'), + 'place_of_event': ovcccat.place_of_event, + 'case_nature': ovcccat.case_nature, + 'case_grouping_id': str(ovcccat.case_grouping_id) + }) + jsonSubCategorysData = [] + + """ Create resultsets """ + resultsets.append(jsonCategorysData) + + # Get OVCReferral + jsonData2 = [] + resultsets2 = [] + referral_grouping_ids = [] + """ Get referral_grouping_ids[] """ + for reffs in ovcrefa: + referral_grouping_id = str(reffs.referral_grouping_id) + if not referral_grouping_id in referral_grouping_ids: + referral_grouping_ids.append(str(referral_grouping_id)) + """ Get Referral Actors """ + ovcrefa2 = None + for referral_grouping_id in referral_grouping_ids: + ovcrefa2 = OVCReferral.objects.filter( + referral_grouping_id=referral_grouping_id) + for ra in ovcrefa2: + jsonData2.append({'refferal_actor_type': translate(ra.refferal_actor_type), + 'refferal_actor_specify': ra.refferal_actor_specify, + 'refferal_to': translate(ra.refferal_to), + 'referral_grouping_id': str(ra.referral_grouping_id) + }) + resultsets2.append(jsonData2) + + return render(request, + 'mobile/preview_csr.html', + {'init_data': init_data, + 'vals': vals, 'result': f, + 'ovcd': ovcd, + 'ovccr': ovccr, + 'ovcgeo': ovcgeo, + 'ovcfrnds': ovcfrnds, + 'ovchobs': ovchobs, + 'ovcmed': ovcmed, + 'ovcphymeds': ovcphymeds, + 'ovcmentmeds': ovcmentmeds, + 'ovcothermeds': ovcothermeds, + 'ovcneeds': ovcneeds, + 'perpetrators': perpetrators, + 'ovcfam': ovcfam, + 'resultsets': resultsets, + 'resultsets2': resultsets2, + 'ovclocs': ovclocs.first(), + 'app_user': appuser + }) + except Exception as e: + msg = 'An error occured trying to view OVCCaseRecord - %s' % (str(e)) + messages.add_message(request, messages.ERROR, msg) + redirect_url = reverse(forms_registry) + return HttpResponseRedirect(forms_registry) + # return render(request, "mobile/home.html", {}) diff --git a/templates/mobile/home.html b/templates/mobile/home.html index 221bae31..c0e15a4f 100644 --- a/templates/mobile/home.html +++ b/templates/mobile/home.html @@ -168,7 +168,7 @@

Mobile Approval - Workflow

"ovc_sex": val.ovc_sex, "siblings": val.case_id, "sibling_date_linked": "Hello", - "sibling_date_delinked": htmlAction(val.ovc_cpims_id) + "sibling_date_delinked": htmlAction(val.case_id) }; }); diff --git a/templates/mobile/preview_csr.html b/templates/mobile/preview_csr.html index 1d49e53c..884c77dc 100644 --- a/templates/mobile/preview_csr.html +++ b/templates/mobile/preview_csr.html @@ -46,16 +46,16 @@

Case Record Sheet - Approval {% for data in init_data %} - {% comment %} {{ data.first_name }} {% endcomment %} + {{ data.first_name }} - {% comment %} {{ data.surname }} {% endcomment %} + {{ data.surname }} | - {% comment %} {{ data.sex_id|gen_value:vals }} {% endcomment %} + {{ data.sex_id|gen_value:vals }} | {% if data.date_of_birth|gen_age == 0 %} UNDER 1 YEAR {% else %} - {% comment %} {{ data.date_of_birth|gen_age }} {% endcomment %} + {{ data.date_of_birth|gen_age }} YRS {% endif %}

{% endfor %} @@ -69,16 +69,16 @@

Case Record Sheet - Approval Active {% else %} {% endif %} - {% comment %} Edit + Edit Export CRS to PDF Print Summary - Follow-up     {% endcomment %} + Follow-up     SERIAL NO. - {% comment %} {{ ovccr.case_serial }} {% endcomment %} + {{ ovccr.case_serial }}
@@ -95,7 +95,7 @@

Case Record Sheet - Approval - {% comment %} {{ ovccr.case_reporter|gen_value:vals }} {% endcomment %} + {{ ovccr.case_reporter|gen_value:vals }} {% if ovccr.court_name %} @@ -106,11 +106,11 @@

Case Record Sheet - Approval - {% comment %} {{ ovccr.court_name }} {% endcomment %} + {{ ovccr.court_name }} Court / File Number - {% comment %} {{ ovccr.court_number }} {% endcomment %} + {{ ovccr.court_number }} {% endif %} @@ -122,11 +122,11 @@

Case Record Sheet - Approval - {% comment %} {{ ovccr.police_station }} {% endcomment %} + {{ ovccr.police_station }} OB Number - {% comment %} {{ ovccr.ob_number }} {% endcomment %} + {{ ovccr.ob_number }} {% endif %} @@ -138,13 +138,13 @@

Case Record Sheet - Approval - {% comment %} {{ ovccr.case_reporter_first_name }} {% endcomment %} + {{ ovccr.case_reporter_first_name }} - {% comment %} {{ ovccr.case_reporter_surname }} {% endcomment %} + {{ ovccr.case_reporter_surname }} {% if ovccr.case_reporter_other_names %} - {% comment %} {{ ovccr.case_reporter_other_names }} {% endcomment %} + {{ ovccr.case_reporter_other_names }} {% endif %} @@ -160,11 +160,11 @@

Case Record Sheet - Approval - {% comment %} {{ ovccr.case_reporter_contacts }} {% endcomment %} + {{ ovccr.case_reporter_contacts }} Date of Reporting - {% comment %} {{ ovccr.date_case_opened }} {% endcomment %} + {{ ovccr.date_case_opened }} {% endif %} @@ -180,11 +180,11 @@

Case Record Sheet - Approval Sub County
- {% comment %} {{ ovcgeo.occurence_subcounty.area_id|gen_areaname }} {% endcomment %} + {{ ovcgeo.occurence_subcounty.area_id|gen_areaname }} Ward {% if ovcgeo.occurence_ward %} - {% comment %} {{ ovcgeo.occurence_ward|gen_areaname }} {% endcomment %} + {{ ovcgeo.occurence_ward|gen_areaname }} {% else %}N/A{% endif %} @@ -193,7 +193,7 @@

Case Record Sheet - Approval Village/Estate
{% if ovcgeo.occurence_village %} - {% comment %} {{ ovcgeo.occurence_village }} {% endcomment %} + {{ ovcgeo.occurence_village }} {% else %}N/A{% endif %} Landmark N/A @@ -211,7 +211,7 @@

Case Record Sheet - Approval - {% comment %} {{ ovcgeo.report_subcounty.area_id|gen_areaname }} {% endcomment %} + {{ ovcgeo.report_subcounty.area_id|gen_areaname }} @@ -219,7 +219,7 @@

Case Record Sheet - Approval Place of Reporting - {% comment %} {{ ovcgeo.report_orgunit }} {% endcomment %} + {{ ovcgeo.report_orgunit }} @@ -239,25 +239,25 @@

Case Record Sheet - Approval Child Names - {% comment %} {{ data.first_name }} {% endcomment %} + {{ data.first_name }} - {% comment %} {{ data.surname }} {% endcomment %} + {{ data.surname }} Date of Birth - {% comment %} {{ data.date_of_birth }} {% endcomment %} + {{ data.date_of_birth }} Sex - {% comment %} {{ data.sex_id|gen_value:vals }} {% endcomment %} + {{ data.sex_id|gen_value:vals }} Age {% if data.date_of_birth|gen_age == 0 %} UNDER 1 YEAR {% else %} - {% comment %} {{ data.date_of_birth|gen_age }} {% endcomment %} + {{ data.date_of_birth|gen_age }} YRS {% endif %} @@ -281,19 +281,19 @@

Case Record Sheet - Approval - {% comment %} {{ forloop.counter }} {% endcomment %} + {{ forloop.counter }} - {% comment %} {{ result.id }} {% endcomment %} + {{ result.id }} - {% comment %} {{ result.first_name }} {% endcomment %} + {{ result.first_name }} - {% comment %} {{ result.surname }} {% endcomment %} + {{ result.surname }} - {% comment %} {{ result.sex_id|gen_value:vals }} {% endcomment %} + {{ result.sex_id|gen_value:vals }} {% endfor %} @@ -312,7 +312,7 @@

Case Record Sheet - Approval House Economic Status
- {% comment %} {{ ovcd.household_economic_status|gen_value:vals }} {% endcomment %} + {{ ovcd.household_economic_status|gen_value:vals }} Family Status
@@ -320,7 +320,7 @@

Case Record Sheet - Approval {% for ovcf in ovcfam %} - {% comment %} {{ ovcf.family_status|gen_value:vals }} {% endcomment %} + {{ ovcf.family_status|gen_value:vals }}
{% endfor %} @@ -334,13 +334,13 @@

Case Record Sheet - Approval Case Record Sheet - Approval {% for ovchob in ovchobs %} - {% comment %} {{ovchob.hobby}} {% endcomment %} + {{ovchob.hobby}} ;   {% endfor %} @@ -365,12 +365,12 @@

Case Record Sheet - Approval Mental Condition
- {% comment %} {{ ovcmed.mental_condition|gen_value:vals }} {% endcomment %} + {{ ovcmed.mental_condition|gen_value:vals }} {% for ovcmentmed in ovcmentmeds %} - {% comment %} {{ovcmentmed.medical_subcondition|gen_value:vals}} {% endcomment %} + {{ovcmentmed.medical_subcondition|gen_value:vals}} ;   {% endfor %} @@ -381,12 +381,12 @@

Case Record Sheet - Approval Physical Condition
- {% comment %} {{ ovcmed.physical_condition|gen_value:vals }} {% endcomment %} + {{ ovcmed.physical_condition|gen_value:vals }} {% for ovcphymed in ovcphymeds %} - {% comment %} {{ovcphymed.medical_subcondition|gen_value:vals}} {% endcomment %} + {{ovcphymed.medical_subcondition|gen_value:vals}} ;   {% endfor %} @@ -397,12 +397,12 @@

Case Record Sheet - Approval Other Conditions
- {% comment %} {{ ovcmed.other_condition|gen_value:vals }} {% endcomment %} + {{ ovcmed.other_condition|gen_value:vals }} {% for ovcothermed in ovcothermeds %} - {% comment %} {{ovcothermed.medical_subcondition|gen_value:vals}} {% endcomment %} + {{ovcothermed.medical_subcondition|gen_value:vals}} ;   {% endfor %} @@ -426,7 +426,7 @@

Case Record Sheet - Approval Case Serial
- {% comment %} {{ ovccr.case_serial }} {% endcomment %} + {{ ovccr.case_serial }} Alleged Perpetrator / Offender Name(s)
@@ -435,28 +435,28 @@

Case Record Sheet - Approval - {% comment %} {{ ovccr.perpetrator_first_name }} {% endcomment %} + {{ ovccr.perpetrator_first_name }} - {% comment %} {{ ovccr.perpetrator_surname }} {% endcomment %} + {{ ovccr.perpetrator_surname }} {% if ovccr.perpetrator_other_names %} - {% comment %} {{ ovccr.perpetrator_other_names }} {% endcomment %} + {{ ovccr.perpetrator_other_names }} {% endif %} - - {% comment %} {{ ovccr.perpetrator_relationship_type|gen_value:vals }} {% endcomment %} + {{ ovccr.perpetrator_relationship_type|gen_value:vals }}
{% for perpetrator in perpetrators %} - {% comment %} {{ perpetrator.person_first_name }} {% endcomment %} + {{ perpetrator.person_first_name }} - {% comment %} {{ perpetrator.person_surname }} {% endcomment %} + {{ perpetrator.person_surname }} {% if perpetrator.person_other_names %} - {% comment %} {{ perpetrator.person_other_names }} {% endcomment %} + {{ perpetrator.person_other_names }} {% endif %} - - {% comment %} {{ perpetrator.person_relation|gen_value:vals }} {% endcomment %} + {{ perpetrator.person_relation|gen_value:vals }}
{% endfor %} @@ -481,19 +481,19 @@

Case Record Sheet - Approval - {% comment %} {{ forloop.counter }} {% endcomment %} + {{ forloop.counter }} {% for item in case_grouping_id.list %} - {% comment %} {{ item.case_category|gen_value2 }} {% endcomment %} + {{ item.case_category|gen_value2 }}
{% endfor %} {% for item in case_grouping_id.list %} - {% comment %} {{ item.case_subcategorys }} {% endcomment %} + {{ item.case_subcategorys }}
{% endfor %} @@ -501,14 +501,14 @@

Case Record Sheet - Approval - {% comment %} {{ case_grouping_id.list|gen_date_of_event }} {% endcomment %} + {{ case_grouping_id.list|gen_date_of_event }} {% for item in case_grouping_id.list %} - {% comment %} {{ item.place_of_event|gen_value2 }} {% endcomment %} + {{ item.place_of_event|gen_value2 }}
{% endfor %} @@ -517,7 +517,7 @@

Case Record Sheet - Approval {% for item in case_grouping_id.list %} - {% comment %} {{ item.case_nature|gen_value2 }} {% endcomment %} + {{ item.case_nature|gen_value2 }}
{% endfor %} @@ -533,7 +533,7 @@

Case Record Sheet - Approval - {% comment %} {{ ovccr.risk_level|gen_value:vals }} {% endcomment %} + {{ ovccr.risk_level|gen_value:vals }} @@ -546,7 +546,7 @@

Case Record Sheet - Approval - {% comment %} {{ ovcneed.need_description|gen_value:vals }} {% endcomment %} + {{ ovcneed.need_description|gen_value:vals }}
{% endif %} {% endfor %} @@ -559,7 +559,7 @@

Case Record Sheet - Approval - {% comment %} {{ ovcneed.need_description|gen_value:vals }} {% endcomment %} + {{ ovcneed.need_description|gen_value:vals }}
{% endif %} {% endfor %} @@ -586,14 +586,14 @@

Case Record Sheet - Approval - {% comment %} {{ forloop.counter }} {% endcomment %} + {{ forloop.counter }} {% for item in referral_grouping_id.list %} - {% comment %} {{ item.refferal_actor_type|gen_value2 }} {% endcomment %} + {{ item.refferal_actor_type|gen_value2 }}
{% endfor %} @@ -601,7 +601,7 @@

Case Record Sheet - Approval {% for item in referral_grouping_id.list %} - {% comment %} {{ item.refferal_actor_specify }} {% endcomment %} + {{ item.refferal_actor_specify }} {% endfor %} @@ -609,7 +609,7 @@

Case Record Sheet - Approval {% for item in referral_grouping_id.list %} - {% comment %} {{ item.refferal_to|gen_value2 }} {% endcomment %} + {{ item.refferal_to|gen_value2 }}
{% endfor %} @@ -632,7 +632,7 @@

Case Record Sheet - Approval {% if ovccr.date_of_summon %} - {% comment %} {{ ovccr.date_of_summon }} {% endcomment %} + {{ ovccr.date_of_summon }} {% else %} No Summons Issued @@ -655,7 +655,7 @@

Case Record Sheet - Approval Case Remarks - {% comment %} {{ ovccr.case_remarks }} {% endcomment %} + {{ ovccr.case_remarks }} @@ -669,13 +669,13 @@

Case Record Sheet - Approval

Case ID: - {% comment %} {{ ovccr.case_id }} {% endcomment %} + {{ ovccr.case_id }} ; Case Created by: - {% comment %} {{ app_user.reg_person.first_name }} {% endcomment %} + {{ app_user.reg_person.first_name }} - {% comment %} {{ app_user.reg_person.surname }} {% endcomment %} + {{ app_user.reg_person.surname }} ; Date and Time: - {% comment %} {{ ovccr.timestamp_created }} {% endcomment %} + {{ ovccr.timestamp_created }}

@@ -720,6 +720,23 @@

Case Record Sheet - Approval { console.log({type}) - } + var approResp = apiCall("csr", "POST").then(data =>{ + + }) + .catch(error => { + console.error('Error fetching initial data:', error); + }); } + + const apiCall = async (url, pMethod) => { + var settings = { + url: window.location.origin + '/api/mobile/' + url, + method: pMethod, + timeout: 0, + headers: {}, + }; + return $.ajax(settings).done(function (response) { + return response; + }); + }; {% endblock %}