Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion mhs/common/Pipfile
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ tornado = "~=6.4.1"
defusedxml = "~=0.7.1"
aioboto3 = "~=11.3.1"
isodate = "~=0.6.1"
marshmallow = "~=3.21.3"
marshmallow = ">=3.26.2"
integration-adaptors-common = {editable = true, path = "./../../common"}
aiohttp = "==3.12.14"

Expand Down
339 changes: 177 additions & 162 deletions mhs/common/Pipfile.lock

Large diffs are not rendered by default.

103 changes: 67 additions & 36 deletions mhs/common/mhs_common/request/request_body_schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,21 +37,34 @@ class Attachment:

class AttachmentSchema(marshmallow.Schema):
"""Schema for an attachment in the request body that MHS accepts"""
is_base64 = marshmallow.fields.Bool(required=True,
description='Whether the attachment payload is base64-encoded or not. This is '
'only required for binary attachments eg images.',
truthy={True}, falsy={False})
content_type = marshmallow.fields.Str(required=True, description='Content type of the attachment',
validate=marshmallow.validate.OneOf(_ATTACHMENT_ALLOWED_CONTENT_TYPES))
payload = marshmallow.fields.Str(required=True,
description='The attachment, possibly base64-encoded as per is_base64.',
# Max length of payload is 5MB ie 5 000 000 characters. This requirement is from
# EIS section 2.5.4.2
validate=marshmallow.validate.Length(min=1, max=5_000_000))
description = marshmallow.fields.Str(required=True, description='Description of the attachment',
validate=marshmallow.validate.Length(min=1))
document_id = marshmallow.fields.Str(required=False,
description='The document id of the attachment.')
is_base64 = marshmallow.fields.Bool(
required=True,
truthy={True},
falsy={False},
metadata={
"description": 'Whether the attachment payload is base64-encoded or not. This is '
'only required for binary attachments eg images.',
})

content_type = marshmallow.fields.Str(
required=True,
validate=marshmallow.validate.OneOf(_ATTACHMENT_ALLOWED_CONTENT_TYPES),
metadata={"description": 'Content type of the attachment.'})

# Max length of payload is 5MB ie 5 000 000 characters. This requirement is from EIS section 2.5.4.2
payload = marshmallow.fields.Str(
required=True,
validate=marshmallow.validate.Length(min=1, max=5_000_000),
metadata={"description": 'The attachment, possibly base64-encoded as per is_base64.'})

description = marshmallow.fields.Str(
required=True,
validate=marshmallow.validate.Length(min=1),
metadata={"description": 'Description of the attachment.'})

document_id = marshmallow.fields.Str(
required=False,
metadata={"description": 'The document id of the attachment.'})

@marshmallow.post_load
def make_attachment(self, data, **kwargs):
Expand All @@ -76,11 +89,17 @@ class ExternalAttachment:

class ExternalAttachmentSchema(marshmallow.Schema):
"""Schema for an external attachment in the request body that MHS accepts"""
document_id = marshmallow.fields.Str(required=False,
description='The document id of the attachment.')
message_id = marshmallow.fields.Str(required=True,
description='Attachment message id.')
description = marshmallow.fields.Str(required=True, description='Description of the attachment')
document_id = marshmallow.fields.Str(
required=False,
metadata={"description": 'The document id of the attachment.'})

message_id = marshmallow.fields.Str(
required=True,
metadata={"description": 'Attachment message id.'})

description = marshmallow.fields.Str(
required=True,
metadata={"description": 'Description of the attachment'})

@marshmallow.post_load
def make_external_attachment(self, data, **kwargs):
Expand All @@ -98,25 +117,37 @@ class RequestBody:

class RequestBodySchema(marshmallow.Schema):
"""Schema for the request body that MHS accepts"""

# No explicit documentation was found in the EIS as to the max size of this
# HL7 payload, but additional attachments have a max size of 5MB so just set to
# this. Note that the whole request body sent to Spine gets checked later to make
# sure it isn't too large.
payload = marshmallow.fields.Str(
required=True, description='HL7 Payload to send to Spine',
# No explicit documentation was found in the EIS as to the max size of this
# HL7 payload, but additional attachments have a max size of 5MB so just set to
# this. Note that the whole request body sent to Spine gets checked later to make
# sure it isn't too large.
validate=marshmallow.validate.Length(min=1, max=5_000_000))
required=True,
validate=marshmallow.validate.Length(min=1, max=5_000_000),
metadata={"description": 'HL7 Payload to send to Spine'})

# EIS 2.5.4.2 says that the max number of attachments is 100, including
# the ebXML MIME part. And there is also the HL7 payload, so 100 - 2 = 98
attachments = marshmallow.fields.Nested(
AttachmentSchema, many=True, missing=[],
description='Optional attachments to send with the payload. Only for use '
'for interactions that support sending attachments.',
# EIS 2.5.4.2 says that the max number of attachments is 100, including
# the ebXML MIME part. And there is also the HL7 payload, so 100 - 2 = 98
validate=marshmallow.validate.Length(max=98))
AttachmentSchema,
many=True,
load_default=[],
validate=marshmallow.validate.Length(max=98),
metadata={
"description": 'Optional attachments to send with the payload. Only for use '
'for interactions that support sending attachments.'
})

external_attachments = marshmallow.fields.Nested(
ExternalAttachmentSchema, many=True, missing=[],
description='Optional external attachments to include in the Manifest '
'that will be sent in separate messages. Only for use '
'for interactions that support sending attachments.')
ExternalAttachmentSchema,
many=True,
load_default=[],
metadata={
"description": 'Optional external attachments to include in the Manifest '
'that will be sent in separate messages. Only for use '
'for interactions that support sending attachments.'
})

@marshmallow.post_load
def make_request_body(self, data, **kwargs):
Expand Down
1 change: 1 addition & 0 deletions mhs/outbound/Pipfile
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ tornado = "~=6.0"
defusedxml = "~=0.6"
mhs-common = {editable = true,path = "./../common"}
isodate = "~=0.6"
marshmallow = ">=3.26.2"
integration-adaptors-common = {editable = true, path = "./../../common"}
pycurl = "~=7.43"
aiohttp = "==3.12.14"
Expand Down
Loading