@@ -12,8 +12,8 @@ class Severity(str, Enum):
1212class Code (str , Enum ):
1313 forbidden = "forbidden"
1414 not_found = "not-found"
15- invalid = "invalid or missing access token "
16- server_error = "internal server error "
15+ invalid = "invalid"
16+ server_error = "exception "
1717 invariant = "invariant"
1818 incomplete = "parameter-incomplete"
1919 not_supported = "not-supported"
@@ -43,12 +43,6 @@ def to_operation_outcome() -> dict:
4343
4444@dataclass
4545class UnauthorizedVaxError (RuntimeError ):
46- response : dict | str
47- message : str
48-
49- def __str__ (self ):
50- return f"{ self .message } \n { self .response } "
51-
5246 @staticmethod
5347 def to_operation_outcome () -> dict :
5448 msg = "Unauthorized request for vaccine type"
@@ -62,12 +56,6 @@ def to_operation_outcome() -> dict:
6256
6357@dataclass
6458class UnauthorizedVaxOnRecordError (RuntimeError ):
65- response : dict | str
66- message : str
67-
68- def __str__ (self ):
69- return f"{ self .message } \n { self .response } "
70-
7159 @staticmethod
7260 def to_operation_outcome () -> dict :
7361 msg = "Unauthorized request for vaccine type present in the stored immunization resource"
@@ -121,7 +109,7 @@ def to_operation_outcome() -> dict:
121109class ResourceNotFoundError (RuntimeError ):
122110 """Return this error when the requested FHIR resource does not exist"""
123111
124- resource_type : str | None
112+ resource_type : str
125113 resource_id : str
126114
127115 def __str__ (self ):
@@ -296,6 +284,30 @@ def to_operation_outcome(self) -> dict:
296284 )
297285
298286
287+ def create_operation_outcome (resource_id : str , severity : Severity , code : Code , diagnostics : str ) -> dict :
288+ """Create an OperationOutcome object. Do not use `fhir.resource` library since it adds unnecessary validations"""
289+ return {
290+ "resourceType" : "OperationOutcome" ,
291+ "id" : resource_id ,
292+ "meta" : {"profile" : ["https://simplifier.net/guide/UKCoreDevelopment2/ProfileUKCore-OperationOutcome" ]},
293+ "issue" : [
294+ {
295+ "severity" : severity ,
296+ "code" : code ,
297+ "details" : {
298+ "coding" : [
299+ {
300+ "system" : "https://fhir.nhs.uk/Codesystem/http-error-codes" ,
301+ "code" : code .upper (),
302+ }
303+ ]
304+ },
305+ "diagnostics" : diagnostics ,
306+ }
307+ ],
308+ }
309+
310+
299311@dataclass
300312class ParameterException (RuntimeError ):
301313 message : str
@@ -335,29 +347,5 @@ class RecordProcessorError(Exception):
335347 and is stored as an attribute.
336348 """
337349
338-
339- def create_operation_outcome (resource_id : str , severity : Severity , code : Code , diagnostics : str ) -> dict :
340- """Create an OperationOutcome object. Do not use `fhir.resource` library since it adds unnecessary validations"""
341- return {
342- "resourceType" : "OperationOutcome" ,
343- "id" : resource_id ,
344- "meta" : {"profile" : ["https://simplifier.net/guide/UKCoreDevelopment2/ProfileUKCore-OperationOutcome" ]},
345- "issue" : [
346- {
347- "severity" : severity ,
348- "code" : code ,
349- "details" : {
350- "coding" : [
351- {
352- "system" : "https://fhir.nhs.uk/Codesystem/http-error-codes" ,
353- "code" : code .upper (),
354- }
355- ]
356- },
357- "diagnostics" : diagnostics ,
358- }
359- ],
360- }
361-
362350 def __init__ (self , diagnostics_dictionary : dict ):
363351 self .diagnostics_dictionary = diagnostics_dictionary
0 commit comments