Skip to content

Commit

Permalink
EM-1575 add blockreplace script for spec
Browse files Browse the repository at this point in the history
  • Loading branch information
jimasp committed Dec 10, 2024
1 parent 0df4270 commit 166e34e
Show file tree
Hide file tree
Showing 5 changed files with 189 additions and 153 deletions.
7 changes: 6 additions & 1 deletion .redocly.lint-ignore.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# This file instructs Redocly's linter to ignore the rules contained for specific parts of your API.
# See https://redoc.ly/docs/cli/ for more information.
# See https://redocly.com/docs/cli/ for more information.
specification/multicast-notification-service.yaml:
info-license:
- '#/info'
specification/requestBody/create-or-update-subscription-body.yaml:
struct:
- '#/content/blockReplace/action'
- '#/content/blockReplace/actioning'
- '#/content/blockReplace/actioned'
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"description": "OAS (Swagger v3) API Definition for Template API",
"scripts": {
"lint": "redocly lint specification/multicast-notification-service.yaml",
"publish": "mkdir -p build && redocly bundle specification/multicast-notification-service.yaml --dereferenced --remove-unused-components --ext json | poetry run python scripts/set_version.py > build/multicast-notification-service.json",
"publish": "mkdir -p build && redocly bundle specification/multicast-notification-service.yaml --dereferenced --remove-unused-components --ext json | poetry run python scripts/apply_block_replacements.py | poetry run python scripts/set_version.py > build/multicast-notification-service.json",
"serve": "redocly preview-docs -p 5000 build/multicast-notification-service.json",
"check-licenses": "node_modules/.bin/license-checker --failOn GPL --failOn LGPL"
},
Expand Down
28 changes: 28 additions & 0 deletions scripts/apply_block_replacements.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import sys
import json


def apply_nested_replacements(data, replacements=None):
if isinstance(data, dict):
if "blockReplace" in data:
replacements = data["blockReplace"]
del data["blockReplace"]

for key, value in data.items():
if isinstance(value, str) and replacements:
for placeholder, replacement in replacements.items():
value = value.replace(f"[[{placeholder}]]", replacement)
data[key] = value
else:
apply_nested_replacements(value, replacements) # recurse

elif isinstance(data, list):
for index, item in enumerate(data):
apply_nested_replacements(item, replacements) # recurse


input_data = sys.stdin.read()
json_data = json.loads(input_data)
apply_nested_replacements(json_data)
# send to stdout
print(json.dumps(json_data, indent=2))
152 changes: 1 addition & 151 deletions specification/multicast-notification-service.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -453,157 +453,7 @@ paths:
- $ref: "parameters/headers/authorization.yaml"
- $ref: "parameters/headers/x-correlation-id.yaml"
requestBody:
required: true
content:
application/fhir+json:
schema:
type: "object"
required:
- "resourceType"
- "status"
- "reason"
- "criteria"
- "channel"
properties:
resourceType:
type: "string"
description: "The subscription FHIR Resource: https://hl7.org/fhir/R4/subscription.html"
status:
type: "string"
description: "The status of the subscription. When creating a subscription, the value must be `requested`."
end:
type: "string"
format: "date-time"
description: |
Optional expiry date/time for the subscription. As per the [FHIR R4 instant data type](https://hl7.org/fhir/R4/datatypes.html#instant) time shall be specified to at least the second and include a time zone.
For example: YYYY-MM-DDThh:mm:ss.sss+zz:zz (e.g. 2015-02-07T13:28:17.239+02:00 or 2017-01-01T00:00:00Z)
reason:
type: "string"
description: "A description of why this subscription is required. You may provide an empty string."
criteria:
type: "string"
description: |
Criteria for the subscription. Provide your criteria with each condition separated by `&;`. If you are requesting a generic subscription to all signals of a certain type the separator is not required. For example, `eventType=gpreg-change-gp-req-1&;generalpractitioner=XY11`
or `eventType=gpreg-change-gp-req-1`. A valid criteria must contain a permitted value for `eventType`. Additional criteria depends on the event and are documentated on our [Signal Catalogue page](https://digital.nhs.uk/developer/api-catalogue?query=mns+event+publish-subscribe).
channel:
type: "object"
required:
- "type"
- "endpoint"
- "payload"
description: "The channel on which to report matches to the criteria. SQS Endpoints must be unique per event type; attempts to add a subscription with an endpoint which is already in-use will fail with a HTTP 409 (Conflict)"
properties:
type:
type: "string"
description: "The type of channel to send notifications on. Of the options within [FHIR](https://hl7.org/fhir/R4/valueset-subscription-channel-type.html), MNS currently only supports `message`."
endpoint:
type: "string"
description: "The endpoint which signals will be delivered to. MNS currently only supports delivery to [MESH](https://digital.nhs.uk/services/message-exchange-for-social-care-and-health-mesh) mailboxes and [AWS SQS](https://aws.amazon.com/sqs/) endpoints. Note: for MESH delivery you must provide the full mailbox ID and for SQS delivery you must provide the full SQS ARN of your desired queue."
payload:
type: "string"
description: "The mime type to send the payload in. MNS supports `application/json` and `application/fhir+json` (FHIR R4 Bundle)."
hydration:
type: "object"
required:
- "enabled"
description: "Optional block to configure hydration properties - hydration is disabled by default."
properties:
enabled:
type: "boolean"
description: "A flag to enable (true) or disable (false) signal hydration."
headers:
type: object
description: "An optional dictionary of HTTP headers that will be sent in the request to the API endpoint specified in the signal."
additionalProperties:
type: string
description: "HTTP header that will be sent in the request to the API endpoint specified in the signal."
examples:
pdsChangeofGPSubscription:
description: "Create a pds change of GP subscription"
value:
resourceType: "Subscription"
status: "requested"
end: "2022-04-05T17:31:00.000Z"
reason: "A description of why this subscription should be created."
criteria: "eventType=pds-change-of-gp-1"
channel:
type: "message"
endpoint: "arn:aws:sqs:eu-west-2:123456789012:queue1"
payload: "application/json"
pdsChangeofGPSubscriptionMeshDelivery:
description: "Create a pds change of GP subscription with MESH delivery"
value:
resourceType: "Subscription"
status: "requested"
end: "2022-04-05T17:31:00.000Z"
reason: "A description of why this subscription should be created."
criteria: "eventType=pds-change-of-gp-1"
channel:
type: "message"
endpoint: "mesh://MYMAILBOXOT101?workflow_id=myWorkflow101"
payload: "application/json"
nhsNumberChangeSubscription:
description: "Create an NHS number change subscription"
value:
resourceType: "Subscription"
status: "requested"
end: "2022-04-05T17:31:00.000Z"
reason: "A description of why this subscription should be created."
criteria: "eventType=nhs-number-change-1"
channel:
type: "message"
endpoint: "arn:aws:sqs:eu-west-2:123456789012:queue2"
payload: "application/json"
pdsDeathNotificationSubscription:
description: "Create a pds death notification subscription"
value:
resourceType: "Subscription"
status: "requested"
end: "2022-04-05T17:31:00.000Z"
reason: "A description of why this subscription should be created."
criteria: "eventType=pds-death-notification-1"
channel:
type: "message"
endpoint: "arn:aws:sqs:eu-west-2:123456789012:queue2"
payload: "application/fhir+json"
immunisationVaccinationSubscription:
description: "Create an immunisation vaccination subscription"
value:
resourceType: "Subscription"
status: "requested"
end: "2022-04-05T17:31:00.000Z"
reason: "A description of why this subscription should be created."
criteria: "eventType=imms-vaccinations-1"
channel:
type: "message"
endpoint: "arn:aws:sqs:eu-west-2:123456789012:queue2"
payload: "application/json"
validatedGPRegistrationRequestSubscription:
description: "Create a validated GP registration request event subscription"
value:
resourceType: "Subscription"
status: "requested"
end: "2022-04-05T17:31:00.000Z"
reason: "A description of why this subscription should be created."
criteria: "eventType=gpreg-change-gp-req-1&;supplierNACS=Y12345&;registrationencountercode=3"
channel:
type: "message"
endpoint: "arn:aws:sqs:eu-west-2:123456789012:queue2"
payload: "application/fhir+json"
patientflagsChangeSubscription:
description: "Create a Patient Flags Change subscription"
value:
resourceType: "Subscription"
status: "requested"
end: "2022-04-05T17:31:00.000Z"
reason: "A description of why this subscription should be created."
criteria: "eventType=patientflags-change-1&;flagtype=NRAF&;generalpractitioner=XY11"
channel:
type: "message"
endpoint: "arn:aws:sqs:eu-west-2:123456789012:queue2"
payload: "application/fhir+json"


$ref: "requestBody/create-or-update-subscription-body.yaml"
responses:
201:
description: Created - the subscription has been successfully created
Expand Down
153 changes: 153 additions & 0 deletions specification/requestBody/create-or-update-subscription-body.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,153 @@
required: true
content:
blockReplace:
action: "Create"
actioning: "creating"
actioned: "created"
application/fhir+json:
schema:
type: "object"
required:
- "resourceType"
- "status"
- "reason"
- "criteria"
- "channel"
properties:
resourceType:
type: "string"
description: "The subscription FHIR Resource: https://hl7.org/fhir/R4/subscription.html"
status:
type: "string"
description: "The status of the subscription. When [[actioning]] a subscription, the value must be `requested`."
end:
type: "string"
format: "date-time"
description: |
Optional expiry date/time for the subscription. As per the [FHIR R4 instant data type](https://hl7.org/fhir/R4/datatypes.html#instant) time shall be specified to at least the second and include a time zone.
For example: YYYY-MM-DDThh:mm:ss.sss+zz:zz (e.g. 2015-02-07T13:28:17.239+02:00 or 2017-01-01T00:00:00Z)
reason:
type: "string"
description: "A description of why this subscription is required. You may provide an empty string."
criteria:
type: "string"
description: |
Criteria for the subscription. Provide your criteria with each condition separated by `&;`. If you are requesting a generic subscription to all signals of a certain type the separator is not required. For example, `eventType=gpreg-change-gp-req-1&;generalpractitioner=XY11`
or `eventType=gpreg-change-gp-req-1`. A valid criteria must contain a permitted value for `eventType`. Additional criteria depends on the event and are documentated on our [Signal Catalogue page](https://digital.nhs.uk/developer/api-catalogue?query=mns+event+publish-subscribe).
channel:
type: "object"
required:
- "type"
- "endpoint"
- "payload"
description: "The channel on which to report matches to the criteria. SQS Endpoints must be unique per event type; attempts to add a subscription with an endpoint which is already in-use will fail with a HTTP 409 (Conflict)"
properties:
type:
type: "string"
description: "The type of channel to send notifications on. Of the options within [FHIR](https://hl7.org/fhir/R4/valueset-subscription-channel-type.html), MNS currently only supports `message`."
endpoint:
type: "string"
description: "The endpoint which signals will be delivered to. MNS currently only supports delivery to [MESH](https://digital.nhs.uk/services/message-exchange-for-social-care-and-health-mesh) mailboxes and [AWS SQS](https://aws.amazon.com/sqs/) endpoints. Note: for MESH delivery you must provide the full mailbox ID and for SQS delivery you must provide the full SQS ARN of your desired queue."
payload:
type: "string"
description: "The mime type to send the payload in. MNS supports `application/json` and `application/fhir+json` (FHIR R4 Bundle)."
hydration:
type: "object"
required:
- "enabled"
description: "Optional block to configure hydration properties - hydration is disabled by default."
properties:
enabled:
type: "boolean"
description: "A flag to enable (true) or disable (false) signal hydration."
headers:
type: object
description: "An optional dictionary of HTTP headers that will be sent in the request to the API endpoint specified in the signal."
additionalProperties:
type: string
description: "HTTP header that will be sent in the request to the API endpoint specified in the signal."
examples:
pdsChangeofGPSubscription:
description: "[[action]] a pds change of GP subscription"
value:
resourceType: "Subscription"
status: "requested"
end: "2022-04-05T17:31:00.000Z"
reason: "A description of why this subscription should be [[actioned]]."
criteria: "eventType=pds-change-of-gp-1"
channel:
type: "message"
endpoint: "arn:aws:sqs:eu-west-2:123456789012:queue1"
payload: "application/json"
pdsChangeofGPSubscriptionMeshDelivery:
description: "[[action]] a pds change of GP subscription with MESH delivery"
value:
resourceType: "Subscription"
status: "requested"
end: "2022-04-05T17:31:00.000Z"
reason: "A description of why this subscription should be [[actioned]]."
criteria: "eventType=pds-change-of-gp-1"
channel:
type: "message"
endpoint: "mesh://MYMAILBOXOT101?workflow_id=myWorkflow101"
payload: "application/json"
nhsNumberChangeSubscription:
description: "[[action]] an NHS number change subscription"
value:
resourceType: "Subscription"
status: "requested"
end: "2022-04-05T17:31:00.000Z"
reason: "A description of why this subscription should be [[actioned]]."
criteria: "eventType=nhs-number-change-1"
channel:
type: "message"
endpoint: "arn:aws:sqs:eu-west-2:123456789012:queue2"
payload: "application/json"
pdsDeathNotificationSubscription:
description: "[[action]] a pds death notification subscription"
value:
resourceType: "Subscription"
status: "requested"
end: "2022-04-05T17:31:00.000Z"
reason: "A description of why this subscription should be [[actioned]]."
criteria: "eventType=pds-death-notification-1"
channel:
type: "message"
endpoint: "arn:aws:sqs:eu-west-2:123456789012:queue2"
payload: "application/fhir+json"
immunisationVaccinationSubscription:
description: "[[action]] an immunisation vaccination subscription"
value:
resourceType: "Subscription"
status: "requested"
end: "2022-04-05T17:31:00.000Z"
reason: "A description of why this subscription should be [[actioned]]."
criteria: "eventType=imms-vaccinations-1"
channel:
type: "message"
endpoint: "arn:aws:sqs:eu-west-2:123456789012:queue2"
payload: "application/json"
validatedGPRegistrationRequestSubscription:
description: "[[action]] a validated GP registration request event subscription"
value:
resourceType: "Subscription"
status: "requested"
end: "2022-04-05T17:31:00.000Z"
reason: "A description of why this subscription should be [[actioned]]."
criteria: "eventType=gpreg-change-gp-req-1&;supplierNACS=Y12345&;registrationencountercode=3"
channel:
type: "message"
endpoint: "arn:aws:sqs:eu-west-2:123456789012:queue2"
payload: "application/fhir+json"
patientflagsChangeSubscription:
description: "[[action]] a Patient Flags Change subscription"
value:
resourceType: "Subscription"
status: "requested"
end: "2022-04-05T17:31:00.000Z"
reason: "A description of why this subscription should be [[actioned]]."
criteria: "eventType=patientflags-change-1&;flagtype=NRAF&;generalpractitioner=XY11"
channel:
type: "message"
endpoint: "arn:aws:sqs:eu-west-2:123456789012:queue2"
payload: "application/fhir+json"

0 comments on commit 166e34e

Please sign in to comment.