Skip to content
This repository has been archived by the owner on Jan 28, 2024. It is now read-only.

Commit

Permalink
refactor(routes): use fluent json schema for other objects
Browse files Browse the repository at this point in the history
  • Loading branch information
Frazer Smith committed Jan 5, 2021
1 parent a3c7953 commit 9c55e94
Show file tree
Hide file tree
Showing 2 changed files with 182 additions and 232 deletions.
295 changes: 129 additions & 166 deletions src/routes/documents/schema.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,191 +15,154 @@ const headerSchema = S.object().prop(
const registerGetSchema = {
description: "Retrieve document metadata from register",
headers: headerSchema,
querystring: {
type: "object",
properties: {
lastModified: {
description: "Last modified datetime of document",
examples: [

querystring: S.object()
.prop(
"lastModified",
S.string()
.description("Last modified datetime of document")
.examples([
"2021-01-01",
"ge2021-01-01T00:00:01",
"ge2021-01-01",
"2021-01-01T00:00:01",
],
type: "string",
pattern:
"^(?:eq|ne|ge|le|gt|lt|sa|eb|ap|)\\d{4}-\\d{2}-\\d{2}(?:T\\d{2}\\:\\d{2}\\:\\d{2}|)$",
},
page: {
description: "Page to retrieve",
default: "1",
examples: ["1", "10"],
type: "string",
pattern: "^\\d{1,}$",
},
perPage: {
description: "Number of documents to return per page",
default: "1",
examples: ["1", "10"],
type: "string",
pattern: "^\\d{1,}$",
},
},
required: ["lastModified"],
},
])
.pattern(
"^(?:eq|ne|ge|le|gt|lt|sa|eb|ap|)\\d{4}-\\d{2}-\\d{2}(?:T\\d{2}\\:\\d{2}\\:\\d{2}|)$"
)
.required()
)
.prop(
"page",
S.number()
.description("Page to retrieve")
.default(1)
.examples([1, 10])
)
.prop(
"perPage",
S.number()
.description("Number of documents to return per page")
.default(1)
.examples([1, 10])
),
response: {
200: {
type: "object",
properties: {
data: {
type: "array",
items: {
type: "object",
properties: {
GUID: {
examples: ["EXAMPLE-GUID"],
type: "string",
},
fhir_id: {
examples: ["99999"],
type: "number",
},
Title: {
examples: [
"99999 DUCK 11 July 2015 11 27.pdf",
],
type: "string",
},
Clinic: {
examples: ["CLO/BIA"],
type: "string",
},
Document_Type: {
examples: ["Clinic Letter"],
type: "string",
},
Filesname: {
examples: [
"99999 DUCK 11 July 2015 11 27.pdf",
],
type: "string",
},
URL: {
examples: [
200: S.object()
.prop(
"data",
S.array().items(
S.object()
.prop("guid", S.string().examples(["EXAMPLE-GUID"]))
.prop("fhir_id", S.number().examples(["99999"]))
.prop(
"title",
S.string().examples([
"99999 DUCK 11 July 2015 11 27.pdf",
])
)
.prop(
"specialty",
S.string().examples(["General Surgery"])
)
.prop("clinic", S.string().examples(["CLO/BIA"]))
.prop(
"document_type",
S.string().examples(['"Clinic Letter"'])
)
.prop(
"file_name",
S.string().examples([
"99999 DUCK 11 July 2015 11 27.pdf",
])
)
.prop(
"url",
S.string()
.examples([
"https://notreal.ydh.nhs.uk/sites/MedicalRecords1/_layouts/15/DocIdRedir.aspx?ID=EXAMPLE-GUID",
],
type: "string",
},
CreatedDate: {
examples: ["2015-09-30T05:40:14.000Z"],
format: "date-time",
type: "string",
},
Modified: {
examples: ["2020-08-10T03:51:54.000Z"],
format: "date-time",
type: "string",
},
Specialty: {
examples: ["General Surgery"],
type: "string",
},
},
},
},

meta: {
type: "object",
properties: {
pagination: {
type: "object",
properties: {
total: {
examples: [0, 1, 10],
type: "number",
},
per_page: {
default: 1,
examples: [1, 10],
type: "number",
},
current_page: {
default: 1,
examples: [1, 10],
type: "number",
},
total_pages: {
examples: [1, 10],
type: "number",
},
},
},
},
},
},
},
])
.format("uri")
)
.prop(
"created_date",
S.string()
.examples(["2015-09-30T05:40:14.000Z"])
.format("date-time")
)
.prop(
"modified",
S.string()
.examples(["2020-08-10T03:51:54.000Z"])
.format("date-time")
)
)
)
.prop(
"meta",
S.object().prop(
"pagination",
S.object()
.prop("total", S.number().examples([0, 1, 10]))
.prop(
"per_page",
S.number().default(1).examples([1, 10])
)
.prop(
"current_page",
S.number().default(1).examples([1, 10])
)
.prop("total_pages", S.number().examples([1, 10]))
)
),
},
};

// TODO: Add 200 and 300 response schema
const receiptDeleteSchema = {
description: "Delete document read receipt",
headers: headerSchema,
params: {
type: "object",
properties: {
id: {
description: "Logical id of the artifact",
examples: ["EXAMPLE-GUID"],
type: "string",
},
},
required: ["id"],
},
querystring: {
type: "object",
properties: {
patientId: {
description: "Unique patient identifier",
examples: [9999999999],
type: "number",
},
},
required: ["patientId"],
},
params: S.object().prop(
"id",
S.string()
.description("Logical id of the artifact")
.examples(["EXAMPLE-GUID"])
.required()
),
querystring: S.object().prop(
"patientId",
S.number()
.description("Unique patient identifier")
.examples([9999999999])
.required()
),
};

// TODO: Add 200 and 300 response schema
const receiptPutSchema = {
description: "Create document read receipt",
headers: headerSchema,
params: {
type: "object",
properties: {
id: {
description: "Logical id of the artifact",
examples: ["EXAMPLE-GUID"],
type: "string",
},
},
required: ["id"],
},
querystring: {
type: "object",
properties: {
patientId: {
description: "Unique patient identifier",
examples: [9999999999],
type: "number",
},
timestamp: {
description: "Read time of document",
format: "date-time",
type: "string",
},
},
required: ["patientId", "timestamp"],
},
params: S.object().prop(
"id",
S.string()
.description("Logical id of the artifact")
.examples(["EXAMPLE-GUID"])
.required()
),
querystring: S.object()
.prop(
"patientId",
S.number()
.description("Unique patient identifier")
.examples([9999999999])
.required()
)
.prop(
"timestamp",
S.string()
.description("Read time of document")
.format("date-time")
.required()
),
};

module.exports = { registerGetSchema, receiptDeleteSchema, receiptPutSchema };
Loading

0 comments on commit 9c55e94

Please sign in to comment.