88import requests
99
1010from itk_dev_shared_components .kmd_nova .authentication import NovaAccess
11- from itk_dev_shared_components .kmd_nova .nova_objects import NovaCase , CaseParty , JournalNote
11+ from itk_dev_shared_components .kmd_nova .nova_objects import NovaCase , CaseParty , JournalNote , Caseworker , Department
1212from itk_dev_shared_components .kmd_nova .util import datetime_from_iso_string
1313
1414
@@ -83,7 +83,30 @@ def get_cases(nova_access: NovaAccess, cpr: str = None, case_number: str = None,
8383 },
8484 "sensitivity" : {
8585 "sensitivity" : True
86- }
86+ },
87+ "caseworker" : {
88+ "kspIdentity" : {
89+ "novaUserId" : True ,
90+ "fullName" : True ,
91+ "racfId" : True
92+ }
93+ },
94+ "responsibleDepartment" : {
95+ "losIdentity" : {
96+ "novaUnitId" : True ,
97+ "administrativeUnitId" : True ,
98+ "fullName" : True ,
99+ "userKey" : True
100+ }
101+ },
102+ "securityUnit" : {
103+ "losIdentity" : {
104+ "novaUnitId" : True ,
105+ "administrativeUnitId" : True ,
106+ "fullName" : True ,
107+ "userKey" : True
108+ }
109+ },
87110 }
88111 }
89112
@@ -98,6 +121,7 @@ def get_cases(nova_access: NovaAccess, cpr: str = None, case_number: str = None,
98121 # Convert json to NovaCase objects
99122 cases = []
100123 for case_dict in response .json ()['cases' ]:
124+ security_unit , responsible_department = _extract_departments (case_dict )
101125 case = NovaCase (
102126 uuid = case_dict ['common' ]['uuid' ],
103127 title = case_dict ['caseAttributes' ]['title' ],
@@ -110,14 +134,60 @@ def get_cases(nova_access: NovaAccess, cpr: str = None, case_number: str = None,
110134 note_count = case_dict ['numberOfJournalNotes' ],
111135 kle_number = case_dict ['caseClassification' ]['kleNumber' ]['code' ],
112136 proceeding_facet = case_dict ['caseClassification' ]['proceedingFacet' ]['code' ],
113- sensitivity = case_dict ["sensitivity" ]["sensitivity" ]
137+ sensitivity = case_dict ["sensitivity" ]["sensitivity" ],
138+ caseworker = _extract_case_worker (case_dict ),
139+ security_unit = security_unit ,
140+ responsible_department = responsible_department
114141 )
115142
116143 cases .append (case )
117144
118145 return cases
119146
120147
148+ def _extract_departments (case_dict : dict ) -> tuple [Department , Department ]:
149+ """Extract the departments from a HTTP request response.
150+
151+ Args:
152+ case_dict: The dictionary describing the case.
153+
154+ Returns:
155+ The security unit and the responsible department.
156+ """
157+ security_unit = Department (
158+ id = case_dict ['securityUnit' ]['losIdentity' ]['administrativeUnitId' ],
159+ name = case_dict ['securityUnit' ]['losIdentity' ]['fullName' ],
160+ user_key = case_dict ['securityUnit' ]['losIdentity' ]['userKey' ]
161+ )
162+
163+ responsible_department = Department (
164+ id = case_dict ['responsibleDepartment' ]['losIdentity' ]['administrativeUnitId' ],
165+ name = case_dict ['responsibleDepartment' ]['losIdentity' ]['fullName' ],
166+ user_key = case_dict ['responsibleDepartment' ]['losIdentity' ]['userKey' ]
167+ )
168+
169+ return security_unit , responsible_department
170+
171+
172+ def _extract_case_worker (case_dict : dict ) -> Caseworker | None :
173+ """Extract the case worker from a HTTP request response.
174+
175+ Args:
176+ case_dict: The dictionary describing the case.
177+
178+ Returns:
179+ A case worker object describing the case worker if any.
180+ """
181+ if 'caseworker' in case_dict :
182+ return Caseworker (
183+ uuid = case_dict ['caseworker' ]['kspIdentity' ]['novaUserId' ],
184+ name = case_dict ['caseworker' ]['kspIdentity' ]['fullName' ],
185+ ident = case_dict ['caseworker' ]['kspIdentity' ]['racfId' ]
186+ )
187+
188+ return None
189+
190+
121191def _extract_case_parties (case_dict : dict ) -> list [CaseParty ]:
122192 """Extract the case parties from a HTTP request response.
123193
@@ -164,7 +234,7 @@ def _extract_journal_notes(case_dict: dict) -> list:
164234 return notes
165235
166236
167- def add_case (case : NovaCase , nova_access : NovaAccess , security_unit_id : int = 818485 , security_unit_name : str = "Borgerservice" ):
237+ def add_case (case : NovaCase , nova_access : NovaAccess ):
168238 """Add a case to KMD Nova. The case will be created as 'Active'.
169239
170240 Args:
@@ -208,8 +278,16 @@ def add_case(case: NovaCase, nova_access: NovaAccess, security_unit_id: int = 81
208278 ],
209279 "securityUnit" : {
210280 "losIdentity" : {
211- "administrativeUnitId" : security_unit_id ,
212- "fullName" : security_unit_name ,
281+ "administrativeUnitId" : case .security_unit .id ,
282+ "fullName" : case .security_unit .name ,
283+ "userKey" : case .security_unit .user_key
284+ }
285+ },
286+ "responsibleDepartment" : {
287+ "losIdentity" : {
288+ "administrativeUnitId" : case .responsible_department .id ,
289+ "fullName" : case .responsible_department .name ,
290+ "userKey" : case .responsible_department .user_key
213291 }
214292 },
215293 "SensitivityCtrlBy" : "Bruger" ,
@@ -222,6 +300,14 @@ def add_case(case: NovaCase, nova_access: NovaAccess, security_unit_id: int = 81
222300 "AvailabilityCtrlBy" : "Regler"
223301 }
224302
303+ if case .caseworker :
304+ payload ['caseworker' ] = {
305+ "kspIdentity" : {
306+ "racfId" : case .caseworker .ident ,
307+ "fullName" : case .caseworker .name
308+ }
309+ }
310+
225311 headers = {'Content-Type' : 'application/json' , 'Authorization' : f"Bearer { nova_access .get_bearer_token ()} " }
226312
227313 response = requests .post (url , params = params , headers = headers , json = payload , timeout = 60 )
0 commit comments