fhirbug.server¶
Request Parsing¶
-
class
fhirbug.server.requestparser.
FhirRequestQuery
(resource, resourceId=None, operation=None, operationId=None, modifiers={}, search_params={}, body=None, request=None)[source]¶ Represents parsed parameters from requests.
-
modifiers
= None¶ Dictionary. Keys are modifier names and values are the provided values. Holds search parameters that start with an underscore. For example
Patient/123?_format=json
would have a modifiers value of{'_format': 'json'}
-
operationId
= None¶ Extra parameters passed after the operation. For example if
Patient/123/_history/2
was requested,operation
would be_history
andoperationId
would be2
-
resource
= None¶ A string containing the name of the requested Resource. eg:
'Procedure'
-
resourceId
= None¶ The id of the requested resource if a specific resource was requested else
None
-
search_params
= None¶ Dictionary. Keys are parameter names and values are the provided values. Holds search parameters that are not modifiers For example
Patient/123?_format=json
would have a modifiers value of{'_format': 'json'}
-
-
fhirbug.server.requestparser.
generate_query_string
(query)[source]¶ Convert a
FhirRequestQuery
back to a query string.
-
fhirbug.server.requestparser.
parse_url
(url)[source]¶ Parse an http request string and produce an option dict.
>>> p = parse_url('Patient/123/$validate?_format=json') >>> p.resource 'Patient' >>> p.resourceId '123' >>> p.operation '$validate' >>> p.modifiers {'_format': ['json']} >>> p.search_params {}
Parameters: url – a string containing the path of the request. It should not contain the server path. For example: Patients/123?name:contains=Jo Returns: A FhirRequestQuery
object
-
fhirbug.server.requestparser.
split_join
(lst)[source]¶ Accepts a list of comma separated strings, splits them and joins them in a new list
>>> split_join(['a,b,c', 'd', 'e,f']) ['a', 'b', 'c', 'd', 'e', 'f']
-
fhirbug.server.requestparser.
validate_params
(params)[source]¶ Validate a parameter dictionary. If the parameters are invalid, raise a QueryValidationError with the details.
Parameters: params – Parameter dictionary produced by parse_url Returns: Raises: fhirbug.exceptions.QueryValidationError
Request Handling¶
-
class
fhirbug.server.requesthandlers.
AbstractRequestHandler
[source]¶ Base class for request handlers
-
log_request
(url, query, status, method, resource=None, OperationOutcome=None, request_body=None, time=datetime.datetime(2020, 1, 4, 11, 45, 33, 238946))[source]¶ Create an AuditEvent resource that contains details about the request.
Parameters: - url (string) – The initial url that was requested
- query (FhirRequestQuery) – The FhirRequestQuery that was generated
- status (int) – The status code that was returned
- method (string) – The request method
- resource (FhirResource) – A Fhir resource, possibly a bundle, of the resources that were accessed or modified during the request
- OperationOutcome (OperationOutcome) – An OperationOutcome related to the requset
- request_body – The body of the request
- time (datetime) – The time the request occured
-
-
class
fhirbug.server.requesthandlers.
DeleteRequestHandler
[source]¶ Receive a request url and the request body of a DELETE request and handle it. This includes parsing the string into a
fhirbug.server.requestparser.FhirRequestQuery
, finding the model for the requested resource and deleting it. It returns a tuple (response json, status code). If an error occurs during the process, an OperationOutcome is returned.Parameters: url (string) – a string containing the path of the request. It should not contain the server path. For example: Patients/123?name:contains=Jo Returns: A tuple (response_json, status code)
, where response_json may be the requested resource, a Bundle or an OperationOutcome in case of an error.Return type: tuple -
log_request
(url, query, status, method, resource=None, OperationOutcome=None, request_body=None, time=datetime.datetime(2020, 1, 4, 11, 45, 33, 238946))¶ Create an AuditEvent resource that contains details about the request.
Parameters: - url (string) – The initial url that was requested
- query (FhirRequestQuery) – The FhirRequestQuery that was generated
- status (int) – The status code that was returned
- method (string) – The request method
- resource (FhirResource) – A Fhir resource, possibly a bundle, of the resources that were accessed or modified during the request
- OperationOutcome (OperationOutcome) – An OperationOutcome related to the requset
- request_body – The body of the request
- time (datetime) – The time the request occured
-
-
class
fhirbug.server.requesthandlers.
GetRequestHandler
[source]¶ Receive a request url as a string and handle it. This includes parsing the string into a
fhirbug.server.requestparser.FhirRequestQuery
, finding the model for the requested resource and calling Resource.get on it. It returns a tuple (response json, status code). If an error occurs during the process, an OperationOutcome is returned.Parameters: url – a string containing the path of the request. It should not contain the server path. For example: Patients/123?name:contains=Jo Returns: A tuple (response json, status code)
where response_json may be the requested resource, a Bundle or an OperationOutcome in case of an error.Return type: tuple -
log_request
(url, query, status, method, resource=None, OperationOutcome=None, request_body=None, time=datetime.datetime(2020, 1, 4, 11, 45, 33, 238946))¶ Create an AuditEvent resource that contains details about the request.
Parameters: - url (string) – The initial url that was requested
- query (FhirRequestQuery) – The FhirRequestQuery that was generated
- status (int) – The status code that was returned
- method (string) – The request method
- resource (FhirResource) – A Fhir resource, possibly a bundle, of the resources that were accessed or modified during the request
- OperationOutcome (OperationOutcome) – An OperationOutcome related to the requset
- request_body – The body of the request
- time (datetime) – The time the request occured
-
-
class
fhirbug.server.requesthandlers.
PostRequestHandler
[source]¶ Receive a request url and the request body of a POST request and handle it. This includes parsing the string into a
fhirbug.server.requestparser.FhirRequestQuery
, finding the model for the requested resource and creating a new instance. It returns a tuple (response json, status code). If an error occurs during the process, an OperationOutcome is returned.Parameters: - url (string) – a string containing the path of the request. It should not contain the server path. For example: Patients/123?name:contains=Jo
- body (dict) – a dictionary containing all data that was sent with the request
Returns: A tuple
(response_json, status code)
, where response_json may be the requested resource, a Bundle or an OperationOutcome in case of an error.Return type: tuple
-
log_request
(url, query, status, method, resource=None, OperationOutcome=None, request_body=None, time=datetime.datetime(2020, 1, 4, 11, 45, 33, 238946))¶ Create an AuditEvent resource that contains details about the request.
Parameters: - url (string) – The initial url that was requested
- query (FhirRequestQuery) – The FhirRequestQuery that was generated
- status (int) – The status code that was returned
- method (string) – The request method
- resource (FhirResource) – A Fhir resource, possibly a bundle, of the resources that were accessed or modified during the request
- OperationOutcome (OperationOutcome) – An OperationOutcome related to the requset
- request_body – The body of the request
- time (datetime) – The time the request occured
-
class
fhirbug.server.requesthandlers.
PutRequestHandler
[source]¶ Receive a request url and the request body of a POST request and handle it. This includes parsing the string into a
fhirbug.server.requestparser.FhirRequestQuery
, finding the model for the requested resource and creating a new instance. It returns a tuple (response json, status code). If an error occurs during the process, an OperationOutcome is returned.Parameters: - url (string) – a string containing the path of the request. It should not contain the server path. For example: Patients/123?name:contains=Jo
- body (dict) – a dictionary containing all data that was sent with the request
Returns: A tuple
(response_json, status code)
, where response_json may be the requested resource, a Bundle or an OperationOutcome in case of an error.Return type: tuple
-
log_request
(url, query, status, method, resource=None, OperationOutcome=None, request_body=None, time=datetime.datetime(2020, 1, 4, 11, 45, 33, 238946))¶ Create an AuditEvent resource that contains details about the request.
Parameters: - url (string) – The initial url that was requested
- query (FhirRequestQuery) – The FhirRequestQuery that was generated
- status (int) – The status code that was returned
- method (string) – The request method
- resource (FhirResource) – A Fhir resource, possibly a bundle, of the resources that were accessed or modified during the request
- OperationOutcome (OperationOutcome) – An OperationOutcome related to the requset
- request_body – The body of the request
- time (datetime) – The time the request occured