1
1
import json
2
2
import sys
3
+
3
4
from flask import Blueprint , current_app , jsonify , request
4
5
5
6
from ..middlewares .auth import require_authorization_by_role
6
7
from ..middlewares .validate import validate_request
7
- from ..resources .daytime_contact_dto import DaytimeContactDTO , CreateDaytimeContactDTO
8
8
from ..resources .child_dto import ChildDTO , CreateChildDTO
9
+ from ..resources .daytime_contact_dto import CreateDaytimeContactDTO , DaytimeContactDTO
9
10
from ..services .implementations .child_service import ChildService
10
- from ..services .implementations .provider_service import ProviderService
11
11
from ..services .implementations .daytime_contact_service import DaytimeContactService
12
+ from ..services .implementations .provider_service import ProviderService
12
13
13
14
child_service = ChildService (current_app .logger )
14
15
provider_service = ProviderService (current_app .logger )
15
16
daytimeContact_service = DaytimeContactService (current_app .logger )
16
17
17
18
blueprint = Blueprint ("child" , __name__ , url_prefix = "/children" )
18
19
20
+
19
21
@blueprint .route ("/" , methods = ["GET" ], strict_slashes = False )
20
22
# @require_authorization_by_role({"Admin"})
21
23
def get_child ():
@@ -33,12 +35,12 @@ def get_child():
33
35
"workerName" : child .service_worker ,
34
36
"specialNeeds" : child .special_needs ,
35
37
"concerns" : [],
36
- "childId" : child .id
38
+ "childId" : child .id ,
37
39
}
38
40
39
- #need to get by child_id instead
40
- daytime_contact = (
41
- daytimeContact_service . get_daytime_contact_by_intake_id ( intake_id )
41
+ # need to get by child_id instead
42
+ daytime_contact = daytimeContact_service . get_daytime_contact_by_intake_id (
43
+ intake_id
42
44
)
43
45
44
46
provider_list = []
@@ -53,23 +55,23 @@ def get_child():
53
55
"address" : provider .address ,
54
56
"relationship" : provider .relationship_to_child ,
55
57
"contactNotes" : provider .additional_contact_notes ,
56
- "status" : "previous"
58
+ "status" : "previous" ,
57
59
}
58
60
)
59
-
61
+
60
62
new_child = {
61
63
"childDetails" : child_info ,
62
64
"schoolDetails" : daytime_contact ,
63
65
"providers" : provider_list ,
64
66
}
65
67
66
68
new_children .append (new_child )
67
-
69
+
68
70
return jsonify (list (new_children )), 200
69
71
70
72
except Exception as error :
71
73
return jsonify (error ), 400
72
-
74
+
73
75
74
76
@blueprint .route ("/<int:intake_id>" , methods = ["POST" ], strict_slashes = False )
75
77
# @require_authorization_by_role({"Admin"})
@@ -94,13 +96,15 @@ def run_undos():
94
96
}
95
97
96
98
try :
97
- daytime_response = daytimeContact_service .create_new_daytime_contact (CreateDaytimeContactDTO (** daytimeContact_obj ))
99
+ daytime_response = daytimeContact_service .create_new_daytime_contact (
100
+ CreateDaytimeContactDTO (** daytimeContact_obj )
101
+ )
98
102
print (daytime_response , file = sys .stderr )
99
- undos .append ((daytime_response ,"delete_daytime_contact" , daytime_response .id ))
103
+ undos .append ((daytime_response , "delete_daytime_contact" , daytime_response .id ))
100
104
except Exception as error :
101
105
run_undos ()
102
106
return jsonify (error ), 400
103
-
107
+
104
108
child_obj = {
105
109
"first_name" : child_details ["child_name" ],
106
110
"last_name" : "." ,
@@ -109,7 +113,7 @@ def run_undos():
109
113
"cpin_number" : child_details ["cpin_file_number" ],
110
114
"service_worker" : child_details ["worker_name" ],
111
115
"special_needs" : child_details ["special_needs" ],
112
- "daytime_contact_id" : daytime_response .id
116
+ "daytime_contact_id" : daytime_response .id ,
113
117
}
114
118
115
119
try :
@@ -118,8 +122,8 @@ def run_undos():
118
122
undos .append ((child_service , "delete_child" , child_response .id ))
119
123
except Exception as error :
120
124
run_undos ()
121
- return jsonify (error ), 400
122
-
125
+ return jsonify (error ), 400
126
+
123
127
return jsonify (child_response .__dict__ ), 201
124
128
125
129
@@ -133,40 +137,39 @@ def run_undos():
133
137
for undo in undos :
134
138
service , fn , arg = undo
135
139
service .__dict__ [fn ](arg )
136
-
140
+
137
141
child_details = request .json ["child_details" ]
138
- daytimeContact_details = request .json ["school_details" ]
142
+ daytimeContact_details = request .json ["school_details" ]
139
143
providers = request .json ["providers" ]
140
144
141
145
child_obj = {
142
146
"first_name" : child_details ["child_name" ],
143
147
"last_name" : "." ,
144
148
"date_of_birth" : child_details ["date_of_birth" ],
145
- "cpin_number" : child_details ["cpin_file_number" ],
149
+ "cpin_number" : child_details ["cpin_file_number" ],
146
150
"service_worker" : child_details ["worker_name" ],
147
151
"special_needs" : child_details ["special_needs" ],
148
152
}
149
153
150
154
try :
151
155
child_response = child_service .edit_child (child_obj , child_details ["child_id" ])
152
- #print(child_response, file=sys.stderr)
156
+ # print(child_response, file=sys.stderr)
153
157
# undos.append((child_service, "delete_child", child_response.id))
154
158
except Exception as error :
155
159
# run_undos()
156
- return jsonify (error ),400
157
-
160
+ return jsonify (error ), 400
161
+
158
162
# daytimeContact_obj ={
159
163
# "name": daytimeContact_details["school_name"],
160
164
# "contact_information": daytimeContact_details["school_phone_no"],
161
165
# "address": daytimeContact_details["school_address"],
162
166
# "dismissal_time": daytimeContact_details["dismissal_time"],
163
167
# }
164
168
165
- # try:
169
+ # try:
166
170
# daytime_response = daytimeContact_service.edit_daytime_contact(daytimeContact_obj, daytimeContact_details["school_id"])
167
171
# except Exception as error:
168
172
# # run_undos()
169
173
# return jsonify(error),400
170
174
171
-
172
175
return jsonify (child_response .__dict__ ), 200
0 commit comments