Skip to content

Commit 60410cd

Browse files
committed
[NRL-1051] Add transaction API to APIGW. Fix TF response state issue
1 parent 1733a36 commit 60410cd

File tree

4 files changed

+56
-12
lines changed

4 files changed

+56
-12
lines changed

api/producer/processTransaction/process_transaction_bundle.py

Lines changed: 26 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -265,16 +265,26 @@ def create_document_reference(
265265
return NRLResponse.RESOURCE_CREATED(resource_id=result.resource.id)
266266

267267

268+
def _convert_document_reference(
269+
document_reference: DocumentReference, requested_profile: str
270+
) -> DocumentReference:
271+
"""
272+
Convert the DocumentReference to the requested profile
273+
"""
274+
# TODO - Implement conversion logic from MHDS profile to NRLF FHIR profile
275+
return document_reference
276+
277+
268278
@request_handler(body=Bundle)
269279
def handler(
270280
metadata: ConnectionMetadata,
271281
repository: DocumentPointerRepository,
272282
body: Bundle,
273283
) -> Response:
274284
"""
275-
Handles an MHDS transaction bundle request.
285+
Handles an FHIR transaction bundle request.
276286
277-
Currently limited to register requests only.
287+
Currently limited to create requests only and only supports either the MHDS profile or the NRLF profile.
278288
279289
Args:
280290
metadata (ConnectionMetadata): The connection metadata.
@@ -285,17 +295,17 @@ def handler(
285295
Response: The response indicating the result of the operation.
286296
"""
287297
# TODO - Add logging
288-
# TODO - Add profile for NRLF too
289-
if (
290-
body.meta
291-
and body.meta.profile
292-
and not body.meta.profile[0].endswith(
293-
"profiles.ihe.net/ITI/MHD/StructureDefinition/IHE.MHD.UnContained.Comprehensive.ProvideBundle"
294-
)
298+
requested_profile = (
299+
body.meta.profile[0].root if body.meta and body.meta.profile else None
300+
)
301+
302+
# TODO - Add profile for NRLF too (assume NRLF profile if not provided)
303+
if requested_profile and not requested_profile.endswith(
304+
"profiles.ihe.net/ITI/MHD/StructureDefinition/IHE.MHD.UnContained.Comprehensive.ProvideBundle"
295305
):
296306
return SpineErrorResponse.BAD_REQUEST(
297307
diagnostics="Only IHE.MHD.UnContained.Comprehensive.ProvideBundle profiles are supported",
298-
expression="meta.profile",
308+
expression="meta.profile[0]",
299309
)
300310

301311
if body.type != "transaction":
@@ -305,7 +315,7 @@ def handler(
305315
)
306316

307317
if body.entry is None:
308-
# TODO - Log that there was not entry
318+
# TODO - Log that there was no entry
309319
return Response.from_resource(
310320
resource=Bundle(resourceType="Bundle", type="transaction-response")
311321
)
@@ -345,6 +355,11 @@ def handler(
345355
responses: list[Response] = []
346356
for document_reference in document_references:
347357
try:
358+
if requested_profile:
359+
document_reference = _convert_document_reference(
360+
document_reference, requested_profile
361+
)
362+
348363
create_response = create_document_reference(
349364
metadata, repository, document_reference
350365
)

api/producer/swagger.yaml

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,33 @@ servers:
237237
description: Production environment.
238238
tags:
239239
paths:
240+
/:
241+
post:
242+
tags:
243+
summary: Process a FHIR transaction
244+
operationId: processTransaction
245+
responses:
246+
"200":
247+
description: Transaction successful response
248+
$ref: "#/components/responses/Success"
249+
content:
250+
application/fhir+json:
251+
example: {} # TODO - Add example response for processTransaction
252+
requestBody:
253+
$ref: "#/components/schemas/Bundle"
254+
parameters: {}
255+
x-amazon-apigateway-integration:
256+
type: aws_proxy
257+
httpMethod: POST
258+
uri: ${method_processTransaction}
259+
responses:
260+
default:
261+
statusCode: "200"
262+
passthroughBehavior: when_no_match
263+
contentHandling: CONVERT_TO_TEXT
264+
description: |
265+
TODO - Add description for processTransaction
266+
240267
/DocumentReference:
241268
post:
242269
tags:

terraform/infrastructure/api_gateway.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ module "producer__gateway" {
3434
method_upsertDocumentReference = "arn:aws:apigateway:eu-west-2:lambda:path/2015-03-31/functions/arn:aws:lambda:eu-west-2:${local.aws_account_id}:function:${substr("${local.prefix}--api--producer--upsertDocumentReference", 0, 64)}/invocations"
3535
method_deleteDocumentReference = "arn:aws:apigateway:eu-west-2:lambda:path/2015-03-31/functions/arn:aws:lambda:eu-west-2:${local.aws_account_id}:function:${substr("${local.prefix}--api--producer--deleteDocumentReference", 0, 64)}/invocations"
3636
method_status = "arn:aws:apigateway:eu-west-2:lambda:path/2015-03-31/functions/arn:aws:lambda:eu-west-2:${local.aws_account_id}:function:${substr("${local.prefix}--api--producer--status", 0, 64)}/invocations"
37-
method_processTransation = "arn:aws:apigateway:eu-west-2:lambda:path/2015-03-31/functions/arn:aws:lambda:eu-west-2:${local.aws_account_id}:function:${substr("${local.prefix}--api--producer--processTransaction", 0, 64)}/invocations"
37+
method_processTransaction = "arn:aws:apigateway:eu-west-2:lambda:path/2015-03-31/functions/arn:aws:lambda:eu-west-2:${local.aws_account_id}:function:${substr("${local.prefix}--api--producer--processTransaction", 0, 64)}/invocations"
3838
}
3939

4040
kms_key_id = module.kms__cloudwatch.kms_arn

terraform/infrastructure/modules/api_gateway/api_gateway.tf

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,8 @@ resource "aws_api_gateway_method_settings" "api_gateway_method_settings" {
113113
resource "aws_api_gateway_gateway_response" "api_access_denied" {
114114
rest_api_id = aws_api_gateway_rest_api.api_gateway_rest_api.id
115115
response_type = "ACCESS_DENIED"
116+
status_code = "403"
117+
116118
response_templates = {
117119
"application/json" = jsonencode({
118120
resourceType : "OperationOutcome",

0 commit comments

Comments
 (0)