-
Notifications
You must be signed in to change notification settings - Fork 1
Case overview children component #195
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from 14 commits
14d3805
4ad7e9e
fb9ff06
586a54b
6a380a8
ea40aa1
1564e46
ad5aae3
536c2c7
9c947d5
5f76384
f6920e0
169f244
4e64eb6
ef83b1e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,19 +1,172 @@ | ||
| import json | ||
|
|
||
| import sys | ||
| from flask import Blueprint, current_app, jsonify, request | ||
|
|
||
| from ..middlewares.auth import require_authorization_by_role | ||
| from ..middlewares.validate import validate_request | ||
| from ..resources.daytime_contact_dto import DaytimeContactDTO, CreateDaytimeContactDTO | ||
| from ..resources.child_dto import ChildDTO, CreateChildDTO | ||
| from ..services.implementations.child_service import ChildService | ||
| from ..services.implementations.provider_service import ProviderService | ||
| from ..services.implementations.daytime_contact_service import DaytimeContactService | ||
|
|
||
| child_service = ChildService(current_app.logger) | ||
| provider_service = ProviderService(current_app.logger) | ||
| daytimeContact_service = DaytimeContactService(current_app.logger) | ||
|
|
||
| blueprint = Blueprint("child", __name__, url_prefix="/children") | ||
|
|
||
| @blueprint.route("/", methods=["GET"], strict_slashes=False) | ||
| # @require_authorization_by_role({"Admin"}) | ||
| def get_child(): | ||
| try: | ||
| args = request.args | ||
| intake_id = args.get("intake_id") | ||
| just_children = child_service.get_children_by_intake_id(intake_id) | ||
| new_children = [] | ||
| for child in just_children: | ||
| providers = provider_service.get_providers_by_child_id(child.id) | ||
| child_info = { | ||
| "childName": child.first_name, | ||
| "dateOfBirth": child.date_of_birth, | ||
| "cpinFileNumber": child.cpin_number, | ||
| "workerName": child.service_worker, | ||
| "specialNeeds": child.special_needs, | ||
| "concerns": [], | ||
| "childId": child.id | ||
| } | ||
|
|
||
| #need to get by child_id instead | ||
| daytime_contact = ( | ||
| daytimeContact_service.get_daytime_contact_by_intake_id(intake_id) | ||
| ) | ||
|
|
||
| provider_list = [] | ||
| for provider in providers: | ||
| provider_list.append( | ||
| { | ||
| "providerName": provider.name, | ||
| "providerFileNo": provider.file_number, | ||
| "primaryPhoneNo": provider.primary_phone_number, | ||
| "secondaryPhoneNo": provider.secondary_phone_number, | ||
| "email": provider.email, | ||
| "address": provider.address, | ||
| "relationship": provider.relationship_to_child, | ||
| "contactNotes": provider.additional_contact_notes, | ||
| "status": "previous" | ||
| } | ||
| ) | ||
|
|
||
| new_child = { | ||
| "childDetails": child_info, | ||
| "schoolDetails": daytime_contact, | ||
| "providers": provider_list, | ||
| } | ||
|
|
||
| new_children.append(new_child) | ||
|
|
||
| return jsonify(list(new_children)), 200 | ||
|
|
||
| except Exception as error: | ||
| return jsonify(error), 400 | ||
Check warningCode scanning / CodeQL Information exposure through an exception
[Stack trace information](1) flows to this location and may be exposed to an external user.
|
||
|
|
||
|
|
||
| @blueprint.route("/<int:intake_id>", methods=["POST"], strict_slashes=False) | ||
| # @require_authorization_by_role({"Admin"}) | ||
| # @validate_request("ChildDTO") | ||
| def create_child(intake_id): | ||
| undos = [] | ||
|
|
||
| def run_undos(): | ||
| for undo in undos: | ||
| service, fn, arg = undo | ||
| service.__dict__[fn](arg) | ||
|
|
||
| child_details = request.json["child_details"] | ||
| daytimeContact_details = request.json["school_details"] | ||
| providers = request.json["providers"] | ||
|
|
||
| daytimeContact_obj = { | ||
| "name": daytimeContact_details["school_name"], | ||
| "address": daytimeContact_details["school_address"], | ||
| "contact_information": daytimeContact_details["school_phone_no"], | ||
| "dismissal_time": daytimeContact_details["dismissal_time"], | ||
| } | ||
|
|
||
| try: | ||
| daytime_response = daytimeContact_service.create_new_daytime_contact(CreateDaytimeContactDTO(**daytimeContact_obj)) | ||
| print(daytime_response, file=sys.stderr) | ||
| undos.append((daytime_response,"delete_daytime_contact", daytime_response.id)) | ||
| except Exception as error: | ||
| run_undos() | ||
| return jsonify(error), 400 | ||
|
||
|
|
||
| child_obj = { | ||
| "first_name": child_details["child_name"], | ||
| "last_name": ".", | ||
| "intake_id": intake_id, | ||
| "date_of_birth": child_details["date_of_birth"], | ||
| "cpin_number": child_details["cpin_file_number"], | ||
| "service_worker": child_details["worker_name"], | ||
| "special_needs": child_details["special_needs"], | ||
| "daytime_contact_id": daytime_response.id | ||
| } | ||
|
|
||
| try: | ||
| child_response = child_service.add_new_child(CreateChildDTO(**child_obj)) | ||
| print(child_response, file=sys.stderr) | ||
| undos.append((child_service, "delete_child", child_response.id)) | ||
| except Exception as error: | ||
| run_undos() | ||
| return jsonify(error), 400 | ||
|
||
|
|
||
| return jsonify(child_response.__dict__), 201 | ||
|
|
||
|
|
||
| @blueprint.route("/<int:intake_id>", methods=["PUT"], strict_slashes=False) | ||
| # @require_authorization_by_role({"Admin"}) | ||
| # @validate_request("ChildDTO") | ||
| def edit_child(intake_id): | ||
| undos = [] | ||
|
|
||
| def run_undos(): | ||
| for undo in undos: | ||
| service, fn, arg = undo | ||
| service.__dict__[fn](arg) | ||
|
|
||
| child_details = request.json["child_details"] | ||
| daytimeContact_details = request.json["school_details"] | ||
| providers = request.json["providers"] | ||
|
|
||
| child_obj = { | ||
| "first_name": child_details["child_name"], | ||
| "last_name": ".", | ||
| "date_of_birth": child_details["date_of_birth"], | ||
| "cpin_number": child_details["cpin_file_number"], | ||
| "service_worker": child_details["worker_name"], | ||
| "special_needs": child_details["special_needs"], | ||
| } | ||
|
|
||
| try: | ||
| child_response = child_service.edit_child(child_obj, child_details["child_id"]) | ||
| #print(child_response, file=sys.stderr) | ||
| # undos.append((child_service, "delete_child", child_response.id)) | ||
| except Exception as error: | ||
| # run_undos() | ||
| return jsonify(error),400 | ||
|
||
|
|
||
| # daytimeContact_obj ={ | ||
| # "name": daytimeContact_details["school_name"], | ||
| # "contact_information": daytimeContact_details["school_phone_no"], | ||
| # "address": daytimeContact_details["school_address"], | ||
| # "dismissal_time": daytimeContact_details["dismissal_time"], | ||
| # } | ||
|
|
||
| # try: | ||
| # daytime_response = daytimeContact_service.edit_daytime_contact(daytimeContact_obj, daytimeContact_details["school_id"]) | ||
| # except Exception as error: | ||
| # # run_undos() | ||
| # return jsonify(error),400 | ||
|
|
||
|
|
||
| @blueprint.route("/", methods=["POST"], strict_slashes=False) | ||
| @require_authorization_by_role({"Admin"}) | ||
| @validate_request("ChildDTO") | ||
| def create_child(): | ||
| pass | ||
| return jsonify(child_response.__dict__), 200 | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| "(psycopg2.errors.InvalidTextRepresentation) invalid input value for enum intakes_court_status: \"i am not a valid court status\"\nLINE 1: ...1-01', 'Family Name', '1234321', 'INVESTIGATION', 'i am not ...\n ^\n\n[SQL: INSERT INTO intakes (user_id, intake_status, referring_worker_name, referring_worker_contact, referral_date, family_name, cpin_number, cpin_file_type, court_status, court_order_file, first_nation_heritage, first_nation_band, transportation_requirements, scheduling_requirements, suggested_start_date, date_accepted, access_location, lead_access_worker_id, denial_reason) VALUES (%(user_id)s, %(intake_status)s, %(referring_worker_name)s, %(referring_worker_contact)s, %(referral_date)s, %(family_name)s, %(cpin_number)s, %(cpin_file_type)s, %(court_status)s, %(court_order_file)s, %(first_nation_heritage)s, %(first_nation_band)s, %(transportation_requirements)s, %(scheduling_requirements)s, %(suggested_start_date)s, %(date_accepted)s, %(access_location)s, %(lead_access_worker_id)s, %(denial_reason)s) RETURNING intakes.id]\n[parameters: {'user_id': 1, 'intake_status': 'SUBMITTED', 'referring_worker_name': 'Referring Worker', 'referring_worker_contact': 'unused', 'referral_date': '2019-01-01', 'family_name': 'Family Name', 'cpin_number': '1234321', 'cpin_file_type': 'INVESTIGATION', 'court_status': 'i am not a valid court status', 'court_order_file': 'file binary', 'first_nation_heritage': 'i am also invalid', 'first_nation_band': 'first nation band', 'transportation_requirements': 'transport requirements', 'scheduling_requirements': 'scheduling requirements', 'suggested_start_date': '2019-01-01', 'date_accepted': None, 'access_location': None, 'lead_access_worker_id': None, 'denial_reason': None}]\n(Background on this error at: http://sqlalche.me/e/13/9h9h)" |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,73 @@ | ||
| { | ||
| "userId": 1, | ||
| "caseReferral": { | ||
| "referringWorker": "Referring Worker", | ||
| "referringWorkerContact": "unused", | ||
| "cpinFileNumber": "1234321", | ||
| "cpinFileType": "INVESTIGATION", | ||
| "familyName": "Family Name", | ||
| "referralDate": "2019-01-01" | ||
| }, | ||
| "courtInformation": { | ||
| "courtStatus": "i am not a valid court status", | ||
| "orderReferral": "file binary", | ||
| "firstNationHeritage": "i am also invalid", | ||
| "firstNationBand": "first nation band" | ||
| }, | ||
| "children": [ | ||
| { | ||
| "childInfo": { | ||
| "name": "Child Name", | ||
| "dateOfBirth": "2019-01-01", | ||
| "cpinFileNumber": "1234321", | ||
| "serviceWorker": "Service Worker", | ||
| "specialNeeds": "special needs", | ||
| "concerns": ["concern1", "concern2"] | ||
| }, | ||
| "daytimeContact": { | ||
| "name": "Daytime Contact", | ||
| "contactInfo": "contact info", | ||
| "address": "address", | ||
| "dismissalTime": "dismissal time" | ||
| }, | ||
| "provider": [ | ||
| { | ||
| "name": "Provider Name", | ||
| "fileNumber": "1234321", | ||
| "primaryPhoneNumber": "primary phone number", | ||
| "secondaryPhoneNumber": "secondary phone number", | ||
| "additionalContactNotes": "additional contact notes", | ||
| "relationshipToChild": "FOSTER_CAREGIVER" | ||
| } | ||
| ] | ||
| } | ||
| ], | ||
| "caregivers": [ | ||
| { | ||
| "name": "Caregiver Name", | ||
| "dateOfBirth": "2019-01-01", | ||
| "primaryPhoneNumber": "primary phone number", | ||
| "secondaryPhoneNumber": "secondary phone number", | ||
| "additionalContactNotes": "additional contact notes", | ||
| "address": "address", | ||
| "relationshipToChild": "FOSTER_CAREGIVER", | ||
| "individualConsiderations": "individual considerations" | ||
| } | ||
| ], | ||
| "programDetails": { | ||
| "transportRequirements": "transport requirements", | ||
| "schedulingRequirements": "scheduling requirements", | ||
| "suggestedStartDate": "2019-01-01", | ||
| "shortTermGoals": ["goal1", "goal2"], | ||
| "longTermGoals": ["goal3", "goal4"], | ||
| "familialConcerns": ["concern1", "concern2"], | ||
| "permittedIndividuals": [ | ||
| { | ||
| "name": "Permitted Individual Name", | ||
| "phoneNumber": "phone number", | ||
| "relationshipToChildren": "relationship to children", | ||
| "additionalNotes": "additional notes" | ||
| } | ||
| ] | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| curl -X POST -H "Content-Type: application/json" -d @testbad.json http://localhost:5000/intake > testbad.html |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| { | ||
| "access_location": null, | ||
| "court_order_file": "file binary", | ||
| "court_status": "INTERIM_CARE", | ||
| "cpin_file_type": "INVESTIGATION", | ||
| "cpin_number": "1234321", | ||
| "date_accepted": null, | ||
| "denial_reason": null, | ||
| "family_name": "Family Name", | ||
| "first_nation_band": "first nation band", | ||
| "first_nation_heritage": "FIRST_NATION_REGISTERED", | ||
| "id": 8, | ||
| "intake_status": "SUBMITTED", | ||
| "lead_access_worker_id": null, | ||
| "referral_date": "Tue, 01 Jan 2019 00:00:00 GMT", | ||
| "referring_worker_contact": "unused", | ||
| "referring_worker_name": "Referring Worker", | ||
| "scheduling_requirements": "scheduling requirements", | ||
| "suggested_start_date": "Tue, 01 Jan 2019 00:00:00 GMT", | ||
| "transportation_requirements": "transport requirements", | ||
| "user_id": 1 | ||
| } |
Check warning
Code scanning / CodeQL
Information exposure through an exception