Skip to content
Draft
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 59 additions & 3 deletions backend/python/app/rest/child_routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,63 @@


@blueprint.route("/", methods=["POST"], strict_slashes=False)
@require_authorization_by_role({"Admin"})
@validate_request("ChildDTO")
# @require_authorization_by_role({"Admin"})
# @validate_request("ChildDTO")
def create_child():
pass
undos = []

def run_undos():
for undo in undos:
service, fn, arg = undo
service.__dict__[fn](arg)
print(request.json)
child_obj = {
"intake_id": request.json["intake_id"],
"first_name": request.json["child"]["childInfo"]["first_name"],
"last_name": request.json["child"]["childInfo"]["last_name"],
"date_of_birth": request.json["child"]["childInfo"]["dateOfBirth"],
"cpin_number": request.json["child"]["childInfo"]["cpinFileNumber"],
"service_worker": request.json["child"]["childInfo"]["serviceWorker"],
"daytime_contact_id": request.json["daytimeContact_response"]["id"],
"special_needs": request.json["child"]["childInfo"]["specialNeeds"],
}
try:
child_response = child_service.add_new_child(
CreateChildDTO(**child_obj))
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("/", methods=["PUT"], strict_slashes=False)
# @require_authorization_by_role({"Admin"})
# @validate_request("ChildDTO")
def edit_child():
undos = []

def run_undos():
for undo in undos:
service, fn, arg = undo
service.__dict__[fn](arg)
child_obj = {
"intake_id": request.json["intake_id"],
"first_name": request.json["child"]["childInfo"]["first_name"],
"last_name": request.json["child"]["childInfo"]["last_name"],
"date_of_birth": request.json["child"]["childInfo"]["dateOfBirth"],
"cpin_number": request.json["child"]["childInfo"]["cpinFileNumber"],
"service_worker": request.json["child"]["childInfo"]["serviceWorker"],
"daytime_contact_id": request.json["daytimeContact_response"]["id"],
"special_needs": request.json["child"]["childInfo"]["specialNeeds"],
}
try:
child_response = child_service.edit_child(
child_obj, request.json["child_id"])
# undos.append((child_service, "delete_child", child_response.id))
except Exception as error:
# run_undos()
return jsonify(error), 400

return jsonify(child_response.__dict__), 200
21 changes: 14 additions & 7 deletions backend/python/app/rest/intake_routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@

intake_service = IntakeService(current_app.logger)
caregiver_service = CaregiverService(current_app.logger)
permittedIndividual_service = OtherPermittedIndividualService(current_app.logger)
permittedIndividual_service = OtherPermittedIndividualService(
current_app.logger)
familialConcern_service = FamilialConcernService(current_app.logger)
goal_service = GoalService(current_app.logger)
daytimeContact_service = DaytimeContactService(current_app.logger)
Expand Down Expand Up @@ -123,7 +124,8 @@ def run_undos():
caregiver = CreateCaregiverDTO(**caregiver)
try:
caregiver_response = caregiver_service.create_caregiver(caregiver)
undos.append((caregiver_service, "delete_caregiver", caregiver_response.id))
undos.append(
(caregiver_service, "delete_caregiver", caregiver_response.id))
except Exception as error:
run_undos()
return jsonify(error), 400
Expand Down Expand Up @@ -187,8 +189,10 @@ def run_undos():
"goal": shortTermGoal,
}
try:
shortTermGoal_response = goal_service.add_new_goal(**newShortTermGoal)
undos.append((goal_service, "delete_goal", shortTermGoal_response.id))
shortTermGoal_response = goal_service.add_new_goal(
**newShortTermGoal)
undos.append((goal_service, "delete_goal",
shortTermGoal_response.id))
except Exception as error:
run_undos()
return jsonify(error), 400
Expand All @@ -201,8 +205,10 @@ def run_undos():
"goal": longTermGoal,
}
try:
longTermGoal_response = goal_service.add_new_goal(**newLongTermGoal)
undos.append((goal_service, "delete_goal", longTermGoal_response.id))
longTermGoal_response = goal_service.add_new_goal(
**newLongTermGoal)
undos.append((goal_service, "delete_goal",
longTermGoal_response.id))
except Exception as error:
run_undos()
return jsonify(error), 400
Expand Down Expand Up @@ -244,7 +250,8 @@ def run_undos():
"special_needs": child["childInfo"]["specialNeeds"],
}
try:
child_response = child_service.add_new_child(CreateChildDTO(**child_obj))
child_response = child_service.add_new_child(
CreateChildDTO(**child_obj))
undos.append((child_service, "delete_child", child_response.id))
except Exception as error:
run_undos()
Expand Down
1 change: 1 addition & 0 deletions backend/python/app/rest/testbad.html
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)"
73 changes: 73 additions & 0 deletions backend/python/app/rest/testbad.json
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"
}
]
}
}
1 change: 1 addition & 0 deletions backend/python/app/rest/testbad.sh
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
22 changes: 22 additions & 0 deletions backend/python/app/rest/testgood.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
}
77 changes: 77 additions & 0 deletions backend/python/app/rest/testgood.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
{
"userId": 1,
"caseReferral": {
"referringWorker": "Referring Worker",
"referringWorkerContact": "unused",
"cpinFileNumber": "1234321",
"cpinFileType": "INVESTIGATION",
"familyName": "Family Name",
"referralDate": "2019-01-01"
},
"courtInformation": {
"courtStatus": "INTERIM_CARE",
"orderReferral": "file binary",
"firstNationHeritage": "FIRST_NATION_REGISTERED",
"firstNationBand": "first nation band"
},
"children": [
{
"childInfo": {
"first_name": "Child",
"last_name": "Child",
"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",
"email": "[email protected]",
"address": "address",
"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",
"email": "[email protected]",
"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"
}
]
}
}
1 change: 1 addition & 0 deletions backend/python/app/rest/testgood.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
curl -X POST -H "Content-Type: application/json" -d @testgood.json http://localhost:5000/intake > testgood.html
23 changes: 22 additions & 1 deletion backend/python/app/services/implementations/child_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ def get_all_children(self):
def add_new_child(self, child: CreateChildDTO):
try:
if not child:
raise Exception("Empty child DTO/None passed to add_new_child function")
raise Exception(
"Empty child DTO/None passed to add_new_child function")
if not isinstance(child, CreateChildDTO):
raise Exception("Child passed is not of CreateChildDTO type")
error_list = child.validate()
Expand All @@ -50,3 +51,23 @@ def delete_child(self, child_id):
except Exception as error:
db.session.rollback()
raise error

def edit_child(self, child_data, child_id):
try:
child = Child.query.filter_by(id=child_id).first()
if not child:
raise Exception("Child with id {} not found".format(child_id))
child.intake_id = child_data["intake_id"]
child.first_name = child_data["first_name"]
child.last_name = child_data["last_name"]
child.date_of_birth = child_data["date_of_birth"]
child.cpin_number = child_data["cpin_number"]
child.service_worker = child_data["service_worker"]
child.daytime_contact_id = child_data["daytime_contact_id"]
child.special_needs = child_data["special_needs"]
db.session.merge(child)
db.session.commit()
return ChildDTO(**child.to_dict())
except Exception as error:
db.session.rollback()
raise error
14 changes: 12 additions & 2 deletions frontend/src/components/intake/child-information/AddChildPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ type AddChildProps = {
childrens: Children;
setChildren: React.Dispatch<React.SetStateAction<Children>>;
selectedIndexChild: number;
referrer: string;
};

export type ChildrenDetails = {
Expand All @@ -38,6 +39,7 @@ const AddChild = ({
childrens,
setChildren,
selectedIndexChild,
referrer,
}: AddChildProps): React.ReactElement => {
const [activeFormIndex, setActiveFormIndex] = useState(0);

Expand Down Expand Up @@ -78,7 +80,11 @@ const AddChild = ({
}

setChildren([...childrens]);
setStep(IntakeSteps.INDIVIDUAL_DETAILS);
if (referrer === "intake") {
setStep(IntakeSteps.INDIVIDUAL_DETAILS)
} else {
console.log("back")
}
};

useEffect(() => {
Expand Down Expand Up @@ -135,7 +141,11 @@ const AddChild = ({
<Button
leftIcon={<ArrowLeft />}
onClick={() => {
setStep(IntakeSteps.INDIVIDUAL_DETAILS);
if (referrer === "intake") {
setStep(IntakeSteps.INDIVIDUAL_DETAILS)
} else {
console.log("back")
}
}}
variant="tertiary"
>
Expand Down
1 change: 1 addition & 0 deletions frontend/src/components/pages/IntakePage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,7 @@ const Intake = (): React.ReactElement => {
childrens={children}
setChildren={setChildren}
selectedIndexChild={selectedIndexChild}
referrer="intake"
/>
) : (
<>
Expand Down