dsi-icl/optimise

View on GitHub
packages/optimise-core/docs/swagger.json

Summary

Maintainability
Test Coverage
{
    "swagger": "2.0",
    "info": {
        "description": "API documentation for OPTIMISE MS",
        "version": "3.1.4",
        "title": "OPTIMISE MS API",
        "license": {
            "name": "MIT License"
        }
    },
    "securityDefinitions": {
        "Cookie": {
            "type": "apiKey",
            "name": "cookie",
            "in": "header"
        }
    },
    "basePath": "/api",
    "security": [
        {
            "Cookie": []
        }
    ],
    "paths": {
        "/whoami": {
            "get": {
                "summary": "The logged in username",
                "responses": {
                    "200": {
                        "description": "OK",
                        "schema": {
                            "type": "object",
                            "properties": {
                                "id": {
                                    "type": "integer",
                                    "example": 1
                                },
                                "username": {
                                    "type": "string",
                                    "example": "admin"
                                },
                                "realname": {
                                    "type": "string",
                                    "example": "Administrator"
                                },
                                "priv": {
                                    "type": "integer",
                                    "example": 1
                                }
                            }
                        }
                    },
                    "404": {
                        "description": "Not found",
                        "schema": {
                            "type": "object",
                            "properties": {
                                "error": {
                                    "type": "string",
                                    "enum": [
                                        "An unknown unicorn"
                                    ]
                                }
                            }
                        }
                    }
                }
            }
        },
        "/users/login": {
            "post": {
                "summary": "User login",
                "parameters": [
                    {
                        "in": "body",
                        "name": "userlogin",
                        "description": "User log-in credentials.",
                        "schema": {
                            "type": "object",
                            "required": [
                                "username",
                                "pw"
                            ],
                            "properties": {
                                "username": {
                                    "type": "string",
                                    "example": "admin"
                                },
                                "pw": {
                                    "type": "string",
                                    "example": "admin"
                                }
                            }
                        }
                    }
                ],
                "responses": {
                    "200": {
                        "description": "OK",
                        "schema": {
                            "type": "object",
                            "properties": {
                                "status": {
                                    "type": "string",
                                    "example": "OK"
                                },
                                "message": {
                                    "type": "string",
                                    "enum": [
                                        "Successfully logged in"
                                    ]
                                },
                                "account": {
                                    "type": "object",
                                    "properties": {
                                        "id": {
                                            "type": "integer"
                                        },
                                        "username": {
                                            "type": "string"
                                        },
                                        "priv": {
                                            "type": "integer"
                                        }
                                    }
                                }
                            }
                        }
                    },
                    "400": {
                        "description": "Bad request",
                        "schema": {
                            "type": "object",
                            "properties": {
                                "error": {
                                    "type": "string",
                                    "enum": [
                                        "Couldn't fetch the entry",
                                        "The password provided doesn't match this account",
                                        "The request is missing some arguments"
                                    ]
                                }
                            }
                        }
                    }
                }
            }
        },
        "/users/logout": {
            "post": {
                "summary": "User logout",
                "responses": {
                    "200": {
                        "description": "OK",
                        "schema": {
                            "type": "object",
                            "properties": {
                                "message": {
                                    "type": "string",
                                    "enum": [
                                        "Successfully logged out"
                                    ]
                                }
                            }
                        }
                    },
                    "400": {
                        "description": "Bad request",
                        "schema": {
                            "type": "object",
                            "properties": {
                                "status": {
                                    "type": "string",
                                    "enum": [
                                        "error"
                                    ]
                                },
                                "message": {
                                    "type": "string",
                                    "enum": [
                                        "Please login first"
                                    ]
                                }
                            }
                        }
                    },
                    "401": {
                        "description": "Unauthorized",
                        "schema": {
                            "type": "object",
                            "properties": {
                                "error": {
                                    "type": "string",
                                    "enum": [
                                        "Not logged in"
                                    ]
                                }
                            }
                        }
                    },
                    "500": {
                        "description": "Internal error",
                        "schema": {
                            "type": "object",
                            "properties": {
                                "error": {
                                    "type": "string",
                                    "enum": [
                                        "Cannot destroy session"
                                    ]
                                }
                            }
                        }
                    }
                }
            }
        },
        "/users": {
            "get": {
                "summary": "Get basic info about the user",
                "parameters": [
                    {
                        "in": "query",
                        "name": "username",
                        "type": "string",
                        "description": "Get the user with the given username or all users if no valid query string"
                    }
                ],
                "responses": {
                    "200": {
                        "description": "OK",
                        "schema": {
                            "type": "array",
                            "items": {
                                "$ref": "#/definitions/UserInfo"
                            }
                        }
                    },
                    "400": {
                        "description": "Bad request",
                        "schema": {
                            "type": "object",
                            "properties": {
                                "error": {
                                    "type": "string",
                                    "enum": [
                                        "Couldn't fetch the entry"
                                    ]
                                }
                            }
                        }
                    },
                    "401": {
                        "description": "Unauthorized",
                        "schema": {
                            "$ref": "#/definitions/NoRights"
                        }
                    }
                }
            },
            "post": {
                "summary": "Create a user (admin only)",
                "consumes": [
                    "application/json"
                ],
                "parameters": [
                    {
                        "in": "body",
                        "name": "user",
                        "description": "User object that needs to be added to the users",
                        "required": true,
                        "schema": {
                            "$ref": "#/definitions/User"
                        }
                    }
                ],
                "responses": {
                    "200": {
                        "description": "OK",
                        "schema": {
                            "type": "object",
                            "properties": {
                                "state": {
                                    "type": "integer",
                                    "description": "the first inserted id",
                                    "example": 3
                                }
                            }
                        }
                    },
                    "400": {
                        "description": "Bad request",
                        "schema": {
                            "type": "object",
                            "properties": {
                                "error": {
                                    "type": "string",
                                    "enum": [
                                        "Couldn't create entry",
                                        "The request is missing some arguments",
                                        "Wrong value in the given arguments"
                                    ]
                                }
                            }
                        }
                    },
                    "401": {
                        "description": "Unauthorized",
                        "schema": {
                            "$ref": "#/definitions/NoRights"
                        }
                    }
                }
            },
            "put": {
                "summary": "Change a user password (admin or self only)",
                "consumes": [
                    "application/json"
                ],
                "parameters": [
                    {
                        "in": "body",
                        "name": "userpassword",
                        "description": "New password for username",
                        "schema": {
                            "type": "object",
                            "required": [
                                "username",
                                "pw"
                            ],
                            "properties": {
                                "username": {
                                    "type": "string",
                                    "example": "testUser"
                                },
                                "pw": {
                                    "type": "string",
                                    "example": "newpassword"
                                }
                            }
                        }
                    }
                ],
                "responses": {
                    "200": {
                        "description": "OK",
                        "schema": {
                            "type": "object",
                            "properties": {
                                "state": {
                                    "type": "integer",
                                    "description": "number of updated rows (users)",
                                    "enum": [
                                        1
                                    ]
                                }
                            }
                        }
                    },
                    "400": {
                        "description": "Bad request",
                        "schema": {
                            "type": "object",
                            "properties": {
                                "error": {
                                    "type": "string",
                                    "enum": [
                                        "Couldn't update entry",
                                        "The request is missing some arguments",
                                        "Wrong value in the given arguments"
                                    ]
                                }
                            }
                        }
                    },
                    "401": {
                        "description": "Unauthorized",
                        "schema": {
                            "$ref": "#/definitions/NoRights"
                        }
                    }
                }
            },
            "patch": {
                "summary": "Update user rights (admin only)",
                "consumes": [
                    "application/json"
                ],
                "parameters": [
                    {
                        "in": "body",
                        "name": "updaterights",
                        "description": "User ID and admin priv",
                        "required": true,
                        "schema": {
                            "type": "object",
                            "properties": {
                                "id": {
                                    "type": "integer",
                                    "description": "ID of user to have rights updated"
                                },
                                "adminPriv": {
                                    "type": "integer",
                                    "description": "new admin priv- 1 for admin rights, 0 otherwise"
                                }
                            }
                        }
                    }
                ],
                "responses": {
                    "200": {
                        "description": "OK",
                        "schema": {
                            "type": "object",
                            "properties": {
                                "state": {
                                    "type": "integer",
                                    "description": "number of updated rows (users)",
                                    "enum": [
                                        1
                                    ]
                                }
                            }
                        }
                    },
                    "400": {
                        "description": "Bad request",
                        "schema": {
                            "type": "object",
                            "properties": {
                                "error": {
                                    "type": "string",
                                    "enum": [
                                        "Couldn't update entry",
                                        "The request is missing some arguments",
                                        "Wrong value in the given arguments"
                                    ]
                                }
                            }
                        }
                    },
                    "401": {
                        "description": "Unauthorized",
                        "schema": {
                            "$ref": "#/definitions/NoRights"
                        }
                    }
                }
            },
            "delete": {
                "summary": "Delete a user (admin or self only)",
                "consumes": [
                    "application/json"
                ],
                "parameters": [
                    {
                        "in": "body",
                        "name": "delpatient",
                        "description": "Username to delete",
                        "schema": {
                            "type": "object",
                            "required": [
                                "username"
                            ],
                            "properties": {
                                "username": {
                                    "type": "string",
                                    "example": "testUser",
                                    "description": "The username to be deleted"
                                }
                            }
                        }
                    }
                ],
                "responses": {
                    "200": {
                        "description": "OK",
                        "schema": {
                            "type": "object",
                            "properties": {
                                "state": {
                                    "type": "integer",
                                    "example": 1,
                                    "description": "number of updated users- 1 if user is updated, 0 otherwise"
                                }
                            }
                        }
                    },
                    "400": {
                        "description": "Bad request",
                        "schema": {
                            "$ref": "#/definitions/DeleteFail"
                        }
                    },
                    "401": {
                        "description": "Unauthorized",
                        "schema": {
                            "$ref": "#/definitions/NoRights"
                        }
                    }
                }
            }
        },
        "/export": {
            "get": {
                "summary": "Export the full database if no query string, subset of the database otherwise",
                "parameters": [
                    {
                        "in": "query",
                        "name": "field",
                        "type": "string",
                        "description": "search field",
                        "enum": [
                            "USUBJID",
                            "OPTIMISEID",
                            "SEX",
                            "EXTRT",
                            "ETHNIC",
                            "COUNTRY",
                            "DOMINANT",
                            "MHTERM"
                        ]
                    },
                    {
                        "in": "query",
                        "name": "value",
                        "type": "string",
                        "description": "search value"
                    }
                ],
                "produces": [
                    "application/zip"
                ],
                "responses": {
                    "200": {
                        "description": "OK- A ZIP of CSV and JSON files.",
                        "schema": {
                            "type": "file"
                        }
                    },
                    "400": {
                        "description": "Bad request- A ZIP file containing a file with the error message.",
                        "schema": {
                            "type": "file"
                        }
                    }
                }
            }
        },
        "/patients": {
            "get": {
                "summary": "Get patient basic info",
                "description": "If search query string 'field={field}&value={value}' is provided, then a list of the patients that satisfy the search criteria is returned. If no query string is provided, all patients are returned. If only 'value={value}' is provided, then patients with ID that contains {value} are returned.",
                "produces": [
                    "application/json"
                ],
                "parameters": [
                    {
                        "in": "query",
                        "name": "field",
                        "type": "string",
                        "description": "Search field. To search by patient id, use USUBJID or OPTIMISEID.",
                        "enum": [
                            "USUBJID",
                            "OPTIMISEID",
                            "SEX",
                            "EXTRT",
                            "ETHNIC",
                            "COUNTRY",
                            "DOMINANT",
                            "MHTERM"
                        ]
                    },
                    {
                        "in": "query",
                        "name": "value",
                        "type": "string",
                        "description": "Value for the search field."
                    }
                ],
                "responses": {
                    "200": {
                        "description": "OK. Basic information about the patient(s).",
                        "schema": {
                            "type": "array",
                            "items": {
                                "$ref": "#/definitions/PatientBasicInfo"
                            }
                        }
                    },
                    "400": {
                        "description": "Bad request",
                        "schema": {
                            "type": "object",
                            "properties": {
                                "error": {
                                    "type": "string",
                                    "enum": [
                                        "The query string should be comprised of 'value' or 'field'+'value'",
                                        "Couldn't fetch the entry"
                                    ]
                                }
                            }
                        }
                    },
                    "404": {
                        "description": "Not found",
                        "schema": {
                            "$ref": "#/definitions/EntryNotFound"
                        }
                    }
                }
            },
            "post": {
                "summary": "Create a patient",
                "consumes": [
                    "application/json"
                ],
                "parameters": [
                    {
                        "in": "body",
                        "name": "newpatient",
                        "schema": {
                            "type": "object",
                            "required": [
                                "aliasId",
                                "optimiseConsent"
                            ],
                            "properties": {
                                "aliasId": {
                                    "type": "string",
                                    "example": "OPTIMISE1"
                                },
                                "optimiseConsent": {
                                    "type": "string",
                                    "description": "ISO formatted date"
                                }
                            }
                        }
                    }
                ],
                "responses": {
                    "200": {
                        "description": "OK",
                        "schema": {
                            "type": "object",
                            "properties": {
                                "state": {
                                    "type": "integer",
                                    "description": "The inserted id.",
                                    "example": 1
                                }
                            }
                        }
                    },
                    "400": {
                        "description": "Bad request",
                        "schema": {
                            "type": "object",
                            "properties": {
                                "error": {
                                    "type": "string",
                                    "example": "Wrong value in the given arguments"
                                }
                            }
                        }
                    }
                }
            },
            "patch": {
                "summary": "Delete a patient (admin only)",
                "consumes": [
                    "application/json"
                ],
                "parameters": [
                    {
                        "in": "body",
                        "name": "deletepatient",
                        "schema": {
                            "type": "object",
                            "required": [
                                "aliasId"
                            ],
                            "properties": {
                                "aliasId": {
                                    "type": "string",
                                    "example": "OPTIMISE1"
                                }
                            }
                        }
                    }
                ],
                "responses": {
                    "200": {
                        "description": "OK",
                        "schema": {
                            "type": "object",
                            "properties": {
                                "state": {
                                    "type": "integer",
                                    "description": "Number of patients deleted- 1 if patient is deleted",
                                    "example": 1
                                }
                            }
                        }
                    },
                    "400": {
                        "description": "Bad request",
                        "schema": {
                            "type": "object",
                            "properties": {
                                "error": {
                                    "type": "string",
                                    "enum": [
                                        "Wrong value in the given arguments"
                                    ]
                                }
                            }
                        }
                    },
                    "401": {
                        "description": "Unauthorized",
                        "schema": {
                            "$ref": "#/definitions/NoRights"
                        }
                    },
                    "404": {
                        "description": "Not found",
                        "schema": {
                            "$ref": "#/definitions/Error"
                        }
                    }
                }
            },
            "put": {
                "summary": "Update patient data",
                "consumes": [
                    "application/json"
                ],
                "parameters": [
                    {
                        "in": "body",
                        "name": "newpatientdata",
                        "schema": {
                            "type": "object",
                            "required": [
                                "id"
                            ],
                            "properties": {
                                "id": {
                                    "type": "integer",
                                    "example": 1
                                },
                                "aliasId": {
                                    "type": "string",
                                    "example": "OPTIMISE3"
                                },
                                "optimiseConsent": {
                                    "type": "string",
                                    "description": "ISO formatted date"
                                }
                            }
                        }
                    }
                ],
                "responses": {
                    "200": {
                        "description": "OK",
                        "schema": {
                            "type": "object",
                            "properties": {
                                "state": {
                                    "type": "integer",
                                    "description": "1 if patient has been updated"
                                }
                            }
                        }
                    },
                    "400": {
                        "description": "Bad request",
                        "schema": {
                            "type": "object",
                            "properties": {
                                "error": {
                                    "type": "string",
                                    "enum": [
                                        "Couldn't update entry",
                                        "The request is missing some arguments"
                                    ]
                                }
                            }
                        }
                    }
                }
            },
            "delete": {
                "summary": "Erase patient (admin only)",
                "consumes": [
                    "application/json"
                ],
                "parameters": [
                    {
                        "in": "body",
                        "name": "erasepatient",
                        "schema": {
                            "type": "object",
                            "properties": {
                                "patientId": {
                                    "type": "string"
                                }
                            }
                        }
                    }
                ],
                "responses": {
                    "200": {
                        "description": "OK",
                        "schema": {
                            "type": "object",
                            "properties": {
                                "success": {
                                    "type": "boolean"
                                },
                                "message": {
                                    "type": "string"
                                }
                            }
                        }
                    },
                    "400": {
                        "description": "Bad request",
                        "schema": {
                            "type": "object",
                            "properties": {
                                "error": {
                                    "type": "string",
                                    "enum": [
                                        "Couldn't fetch the entry",
                                        "The request is missing some arguments",
                                        "Wrong value in the given arguments"
                                    ]
                                }
                            }
                        }
                    },
                    "401": {
                        "description": "Unauthorized",
                        "schema": {
                            "$ref": "#/definitions/NoRights"
                        }
                    }
                }
            }
        },
        "/patients/{patientId}": {
            "get": {
                "summary": "Get data of {patientId}",
                "description": "Get data of {patientId}. Return specified data sets if query string is provided (getOnly)",
                "produces": [
                    "application/json"
                ],
                "parameters": [
                    {
                        "in": "path",
                        "name": "patientId",
                        "type": "string",
                        "required": true
                    },
                    {
                        "in": "query",
                        "name": "getOnly",
                        "type": "array",
                        "items": {
                            "type": "string"
                        }
                    }
                ],
                "responses": {
                    "200": {
                        "description": "OK",
                        "schema": {
                            "$ref": "#/definitions/PatientProfile"
                        }
                    },
                    "400": {
                        "description": "Bad request",
                        "schema": {
                            "type": "object",
                            "properties": {
                                "error": {
                                    "type": "string",
                                    "enum": [
                                        "Wrong value in the given arguments"
                                    ]
                                }
                            }
                        }
                    },
                    "404": {
                        "description": "Not found",
                        "schema": {
                            "$ref": "#/definitions/EntryNotFound"
                        }
                    }
                }
            }
        },
        "/patientPii": {
            "get": {
                "summary": "Get Personally Identifiable Information for patient ID in query string",
                "parameters": [
                    {
                        "in": "query",
                        "name": "patient",
                        "type": "integer",
                        "required": true,
                        "description": "Patient id (integer)"
                    }
                ],
                "responses": {
                    "200": {
                        "description": "OK",
                        "schema": {
                            "type": "array",
                            "items": {
                                "$ref": "#/definitions/PII"
                            }
                        }
                    },
                    "400": {
                        "description": "Bad request",
                        "schema": {
                            "type": "object",
                            "properties": {
                                "error": {
                                    "type": "string",
                                    "enum": [
                                        "Couldn't fetch the entry",
                                        "Wrong value in the given arguments"
                                    ]
                                }
                            }
                        }
                    }
                }
            },
            "post": {
                "summary": "Create patient PII",
                "parameters": [
                    {
                        "in": "body",
                        "name": "newPII",
                        "schema": {
                            "type": "object",
                            "required": [
                                "patient",
                                "firstName",
                                "surname",
                                "fullAddress",
                                "postcode"
                            ],
                            "properties": {
                                "patient": {
                                    "type": "integer"
                                },
                                "firstName": {
                                    "type": "string"
                                },
                                "surname": {
                                    "type": "string"
                                },
                                "fullAddress": {
                                    "type": "string"
                                },
                                "postcode": {
                                    "type": "string"
                                }
                            }
                        }
                    }
                ],
                "responses": {
                    "200": {
                        "description": "OK",
                        "schema": {
                            "type": "object",
                            "properties": {
                                "state": {
                                    "type": "integer",
                                    "description": "The most recently created PII id"
                                }
                            }
                        }
                    },
                    "400": {
                        "description": "Bad request",
                        "schema": {
                            "type": "object",
                            "properties": {
                                "error": {
                                    "type": "string",
                                    "enum": [
                                        "Couldn't create entry",
                                        "The request is missing some arguments",
                                        "Wrong value in the given arguments"
                                    ]
                                }
                            }
                        }
                    }
                }
            },
            "put": {
                "summary": "Update PII",
                "parameters": [
                    {
                        "in": "body",
                        "name": "newpii",
                        "schema": {
                            "type": "object",
                            "required": [
                                "id"
                            ],
                            "properties": {
                                "id": {
                                    "type": "integer"
                                },
                                "firstName": {
                                    "type": "string"
                                },
                                "surname": {
                                    "type": "string"
                                },
                                "fullAddress": {
                                    "type": "string"
                                },
                                "postcode": {
                                    "type": "string"
                                }
                            }
                        }
                    }
                ],
                "responses": {
                    "200": {
                        "description": "OK",
                        "schema": {
                            "type": "object",
                            "properties": {
                                "state": {
                                    "type": "integer",
                                    "description": "the number of updated PII entries- should be 1 if update is successful"
                                }
                            }
                        }
                    },
                    "400": {
                        "description": "Bad request",
                        "schema": {
                            "type": "object",
                            "properties": {
                                "error": {
                                    "type": "string",
                                    "enum": [
                                        "Couldn't update entry",
                                        "The request is missing some arguments",
                                        "Wrong value in the given arguments"
                                    ]
                                }
                            }
                        }
                    }
                }
            },
            "delete": {
                "summary": "Delete PII",
                "parameters": [
                    {
                        "in": "body",
                        "name": "deletepii",
                        "schema": {
                            "type": "object",
                            "required": [
                                "id"
                            ],
                            "properties": {
                                "id": {
                                    "type": "integer"
                                }
                            }
                        }
                    }
                ],
                "responses": {
                    "200": {
                        "description": "OK",
                        "schema": {
                            "type": "object",
                            "properties": {
                                "state": {
                                    "type": "integer",
                                    "description": "1 if deletion is successful"
                                }
                            }
                        }
                    },
                    "400": {
                        "description": "Bad request",
                        "schema": {
                            "$ref": "#/definitions/DeleteFail"
                        }
                    }
                }
            }
        },
        "/patientDiagnosis": {
            "get": {
                "summary": "Get patient diagnosis",
                "description": "Returns diagnoses of all patients if no query string.",
                "parameters": [
                    {
                        "in": "query",
                        "name": "patient",
                        "type": "integer",
                        "description": "The id of the patient to get the diagnosis of"
                    }
                ],
                "responses": {
                    "200": {
                        "description": "OK",
                        "schema": {
                            "type": "array",
                            "items": {
                                "$ref": "#/definitions/Diagnosis"
                            }
                        }
                    },
                    "400": {
                        "description": "Bad request",
                        "schema": {
                            "$ref": "#/definitions/GetFail"
                        }
                    }
                }
            },
            "post": {
                "summary": "Create patient diagnosis",
                "parameters": [
                    {
                        "in": "body",
                        "name": "newpatientdiagnosis",
                        "schema": {
                            "type": "object",
                            "required": [
                                "patient",
                                "diagnosis",
                                "diagnosisDate"
                            ],
                            "properties": {
                                "patient": {
                                    "type": "integer"
                                },
                                "diagnosis": {
                                    "type": "integer"
                                },
                                "diagnosisDate": {
                                    "type": "string"
                                }
                            }
                        }
                    }
                ],
                "responses": {
                    "200": {
                        "description": "OK",
                        "schema": {
                            "type": "object",
                            "properties": {
                                "state": {
                                    "type": "integer",
                                    "description": "the last inserted patient diagnosis id"
                                }
                            }
                        }
                    },
                    "400": {
                        "description": "Bad request",
                        "schema": {
                            "type": "object",
                            "properties": {
                                "error": {
                                    "type": "string",
                                    "enum": [
                                        "Couldn't create entry",
                                        "The date provided is not valid",
                                        "The request is missing some arguments",
                                        "Wrong value in the given arguments"
                                    ]
                                }
                            }
                        }
                    }
                }
            },
            "put": {
                "summary": "Update patient diagnosis",
                "parameters": [
                    {
                        "in": "body",
                        "name": "newdiagnosis",
                        "schema": {
                            "type": "object",
                            "required": [
                                "id"
                            ],
                            "properties": {
                                "id": {
                                    "type": "integer"
                                },
                                "diagnosis": {
                                    "type": "integer"
                                },
                                "diagnosisDate": {
                                    "type": "string"
                                }
                            }
                        }
                    }
                ],
                "responses": {
                    "200": {
                        "description": "OK",
                        "schema": {
                            "type": "object",
                            "properties": {
                                "state": {
                                    "type": "integer",
                                    "description": "the last inserted id"
                                }
                            }
                        }
                    },
                    "400": {
                        "description": "Bad request",
                        "schema": {
                            "type": "object",
                            "properties": {
                                "error": {
                                    "type": "string",
                                    "enum": [
                                        "Couldn't update entry",
                                        "The date provided is not valid",
                                        "The request is missing some arguments",
                                        "Wrong value in the given arguments"
                                    ]
                                }
                            }
                        }
                    }
                }
            },
            "delete": {
                "summary": "Delete patient diagnosis",
                "parameters": [
                    {
                        "in": "body",
                        "name": "deletediagnosis",
                        "schema": {
                            "type": "object",
                            "required": [
                                "id"
                            ],
                            "properties": {
                                "id": {
                                    "type": "integer",
                                    "description": "the id of the diagnosis entry to be deleted"
                                }
                            }
                        }
                    }
                ],
                "responses": {
                    "200": {
                        "description": "OK",
                        "schema": {
                            "type": "object",
                            "properties": {
                                "id": {
                                    "type": "integer",
                                    "description": "1 if entry is successfully deleted, 0 otherwise"
                                }
                            }
                        }
                    },
                    "400": {
                        "description": "Bad request",
                        "schema": {
                            "$ref": "#/definitions/DeleteFail"
                        }
                    }
                }
            }
        },
        "/tests": {
            "post": {
                "summary": "Create a test",
                "consumes": [
                    "application/json"
                ],
                "parameters": [
                    {
                        "in": "body",
                        "name": "newtest",
                        "schema": {
                            "type": "object",
                            "required": [
                                "visitId",
                                "type",
                                "expectedOccurDate"
                            ],
                            "properties": {
                                "visitId": {
                                    "type": "integer"
                                },
                                "type": {
                                    "type": "integer"
                                },
                                "expectedOccurDate": {
                                    "type": "string"
                                },
                                "actualOccurredDate": {
                                    "type": "string"
                                }
                            }
                        }
                    }
                ],
                "responses": {
                    "200": {
                        "description": "OK",
                        "schema": {
                            "type": "object",
                            "properties": {
                                "state": {
                                    "type": "integer",
                                    "description": "the last inserted test id"
                                }
                            }
                        }
                    },
                    "400": {
                        "description": "Bad request",
                        "schema": {
                            "type": "object",
                            "properties": {
                                "error": {
                                    "type": "string",
                                    "enum": [
                                        "Couldn't create entry",
                                        "The date provided is not valid",
                                        "The request is missing some arguments",
                                        "Wrong value in the given arguments"
                                    ]
                                }
                            }
                        }
                    }
                }
            },
            "delete": {
                "summary": "Delete a test",
                "consumes": [
                    "application/json"
                ],
                "parameters": [
                    {
                        "in": "body",
                        "name": "deletetest",
                        "required": true,
                        "schema": {
                            "type": "object",
                            "required": [
                                "testId"
                            ],
                            "properties": {
                                "testId": {
                                    "type": "integer"
                                }
                            }
                        }
                    }
                ],
                "responses": {
                    "200": {
                        "description": "OK",
                        "schema": {
                            "type": "object",
                            "properties": {
                                "state": {
                                    "type": "integer",
                                    "description": "1 if test is deleted successfully, 0 otherwise"
                                }
                            }
                        }
                    },
                    "400": {
                        "description": "Bad request- Delete failed",
                        "schema": {
                            "$ref": "#/definitions/DeleteFail"
                        }
                    }
                }
            },
            "put": {
                "summary": "Update a test",
                "consumes": [
                    "application/json"
                ],
                "parameters": [
                    {
                        "in": "body",
                        "name": "test",
                        "required": true,
                        "schema": {
                            "type": "object",
                            "required": [
                                "id"
                            ],
                            "properties": {
                                "id": {
                                    "type": "integer"
                                },
                                "expectedOccurDate": {
                                    "type": "string"
                                },
                                "actualOccurredDate": {
                                    "type": "string"
                                }
                            }
                        }
                    }
                ],
                "responses": {
                    "200": {
                        "description": "OK",
                        "schema": {
                            "type": "object",
                            "properties": {
                                "state": {
                                    "type": "integer"
                                }
                            }
                        }
                    },
                    "400": {
                        "description": "Bad request",
                        "schema": {
                            "type": "object",
                            "properties": {
                                "error": {
                                    "type": "string",
                                    "enum": [
                                        "Couldn't update entry",
                                        "The date provided is not valid",
                                        "The request is missing some arguments"
                                    ]
                                }
                            }
                        }
                    }
                }
            }
        },
        "/visits": {
            "get": {
                "summary": "Get visit data for the specified patient",
                "parameters": [
                    {
                        "in": "query",
                        "name": "patientId",
                        "type": "string",
                        "description": "Patient ID (alias ID) specified at patient creation",
                        "required": true
                    }
                ],
                "responses": {
                    "200": {
                        "description": "OK",
                        "schema": {
                            "type": "array",
                            "items": {
                                "$ref": "#/definitions/VisitBasicInfo"
                            }
                        }
                    },
                    "400": {
                        "description": "Bad request",
                        "schema": {
                            "type": "object",
                            "properties": {
                                "error": {
                                    "type": "string",
                                    "enum": [
                                        "Couldn't fetch the entry",
                                        "The request is missing some arguments"
                                    ]
                                }
                            }
                        }
                    }
                }
            },
            "post": {
                "summary": "Create a visit",
                "consumes": [
                    "application/json"
                ],
                "parameters": [
                    {
                        "in": "body",
                        "name": "newvisit",
                        "schema": {
                            "type": "object",
                            "required": [
                                "patientId",
                                "visitDate"
                            ],
                            "properties": {
                                "patientId": {
                                    "type": "integer",
                                    "example": 1
                                },
                                "visitDate": {
                                    "type": "string",
                                    "example": "20100218"
                                },
                                "type": {
                                    "type": "integer",
                                    "description": "type of visit",
                                    "enum": [
                                        1,
                                        2
                                    ]
                                }
                            }
                        }
                    }
                ],
                "responses": {
                    "200": {
                        "description": "OK",
                        "schema": {
                            "type": "object",
                            "properties": {
                                "state": {
                                    "type": "integer",
                                    "description": "the last inserted visit id"
                                }
                            }
                        }
                    },
                    "400": {
                        "description": "Bad request",
                        "schema": {
                            "type": "object",
                            "properties": {
                                "error": {
                                    "type": "string",
                                    "enum": [
                                        "Couldn't create entry",
                                        "The request is missing some arguments",
                                        "The date provided is not valid"
                                    ]
                                }
                            }
                        }
                    }
                }
            },
            "put": {
                "summary": "Update visit",
                "consumes": [
                    "application/json"
                ],
                "parameters": [
                    {
                        "in": "body",
                        "name": "updatevisit",
                        "schema": {
                            "type": "object",
                            "required": [
                                "id"
                            ],
                            "properties": {
                                "id": {
                                    "type": "integer",
                                    "description": "the id of the visit to update",
                                    "example": 1
                                },
                                "visitDate": {
                                    "type": "string",
                                    "example": "20180310"
                                },
                                "type": {
                                    "type": "integer",
                                    "description": "the type of visit",
                                    "enum": [
                                        1,
                                        2
                                    ]
                                }
                            }
                        }
                    }
                ],
                "responses": {
                    "200": {
                        "description": "OK",
                        "schema": {
                            "type": "object",
                            "properties": {
                                "state": {
                                    "type": "integer",
                                    "description": "number of updated visits- 1 if update is successful, 0 otherwise"
                                }
                            }
                        }
                    },
                    "400": {
                        "description": "Bad request",
                        "schema": {
                            "type": "object",
                            "properties": {
                                "error": {
                                    "type": "string",
                                    "enum": [
                                        "Couldn't update entry",
                                        "The date provided is not valid",
                                        "The request is missing some arguments"
                                    ]
                                }
                            }
                        }
                    }
                }
            },
            "delete": {
                "summary": "Delete a visit",
                "consumes": [
                    "application/json"
                ],
                "parameters": [
                    {
                        "in": "body",
                        "name": "deletevisit",
                        "schema": {
                            "type": "object",
                            "required": [
                                "visitId"
                            ],
                            "properties": {
                                "visitId": {
                                    "type": "integer",
                                    "example": 1
                                }
                            }
                        }
                    }
                ],
                "responses": {
                    "200": {
                        "description": "OK",
                        "schema": {
                            "type": "object",
                            "properties": {
                                "state": {
                                    "type": "integer",
                                    "description": "The number of deleted visits- 1 if deletion is successful, 0 otherwise (e.g. if visitId does not exist)."
                                }
                            }
                        }
                    },
                    "400": {
                        "description": "Bad request",
                        "schema": {
                            "$ref": "#/definitions/DeleteFail"
                        }
                    }
                }
            }
        },
        "/visits/report": {
            "get": {
                "summary": "Get communication report of visit(s)",
                "parameters": [
                    {
                        "in": "query",
                        "name": "id",
                        "type": "integer",
                        "description": "the visit id"
                    }
                ],
                "responses": {
                    "200": {
                        "description": "OK",
                        "schema": {
                            "$ref": "#/definitions/CommunicationReport"
                        }
                    },
                    "400": {
                        "description": "Bad request",
                        "schema": {
                            "$ref": "#/definitions/GetFail"
                        }
                    }
                }
            },
            "post": {
                "summary": "Create a visit communication report",
                "consumes": [
                    "application/json"
                ],
                "parameters": [
                    {
                        "in": "body",
                        "name": "newvisitcommunicationreport",
                        "schema": {
                            "type": "object",
                            "properties": {
                                "visit": {
                                    "type": "integer",
                                    "example": 1
                                },
                                "report": {
                                    "type": "string"
                                }
                            }
                        }
                    }
                ],
                "responses": {
                    "200": {
                        "description": "OK",
                        "schema": {
                            "type": "object",
                            "properties": {
                                "state": {
                                    "type": "integer",
                                    "description": "the last inserted visit communication report id"
                                }
                            }
                        }
                    },
                    "400": {
                        "description": "Bad request",
                        "schema": {
                            "$ref": "#/definitions/CreateFail"
                        }
                    }
                }
            },
            "put": {
                "summary": "Update visit communication report",
                "consumes": [
                    "application/json"
                ],
                "parameters": [
                    {
                        "in": "body",
                        "name": "updatevisitcommunicationreport",
                        "schema": {
                            "type": "object",
                            "required": [
                                "id"
                            ],
                            "properties": {
                                "id": {
                                    "type": "integer",
                                    "description": "the id of the visit report to update",
                                    "example": 1
                                },
                                "report": {
                                    "type": "string"
                                }
                            }
                        }
                    }
                ],
                "responses": {
                    "200": {
                        "description": "OK",
                        "schema": {
                            "type": "object",
                            "properties": {
                                "state": {
                                    "type": "integer",
                                    "description": "number of updated reports- 1 if update is successful"
                                }
                            }
                        }
                    },
                    "400": {
                        "description": "Bad request",
                        "schema": {
                            "$ref": "#/definitions/UpdateFail"
                        }
                    }
                }
            },
            "delete": {
                "summary": "Delete a visit communication report (admin only)",
                "consumes": [
                    "application/json"
                ],
                "parameters": [
                    {
                        "in": "body",
                        "name": "deletevisitreport",
                        "schema": {
                            "type": "object",
                            "required": [
                                "id"
                            ],
                            "properties": {
                                "id": {
                                    "type": "integer",
                                    "example": 1
                                }
                            }
                        }
                    }
                ],
                "responses": {
                    "200": {
                        "description": "OK",
                        "schema": {
                            "type": "object",
                            "properties": {
                                "state": {
                                    "type": "integer",
                                    "description": "The number of deleted reports- 1 if deletion is successful"
                                }
                            }
                        }
                    },
                    "400": {
                        "description": "Bad request",
                        "schema": {
                            "$ref": "#/definitions/UpdateFail"
                        }
                    }
                }
            }
        },
        "/treatments": {
            "post": {
                "summary": "Create a treatment",
                "consumes": [
                    "application/json"
                ],
                "parameters": [
                    {
                        "in": "body",
                        "name": "newtreatment",
                        "required": true,
                        "schema": {
                            "type": "object",
                            "required": [
                                "visitId",
                                "drugId",
                                "startDate"
                            ],
                            "properties": {
                                "visitId": {
                                    "type": "integer"
                                },
                                "drugId": {
                                    "type": "integer"
                                },
                                "startDate": {
                                    "type": "string",
                                    "example": "20180310"
                                },
                                "dose": {
                                    "type": "integer"
                                },
                                "unit": {
                                    "type": "string",
                                    "enum": [
                                        "mg",
                                        "cc"
                                    ]
                                },
                                "form": {
                                    "type": "string",
                                    "enum": [
                                        "OR",
                                        "IV",
                                        "IM",
                                        "SC"
                                    ]
                                },
                                "times": {
                                    "type": "integer"
                                },
                                "intervalUnit": {
                                    "type": "string",
                                    "enum": [
                                        "hour",
                                        "day",
                                        "week",
                                        "month",
                                        "year"
                                    ]
                                },
                                "terminatedDate": {
                                    "type": "string",
                                    "example": "20180810"
                                },
                                "terminatedReason": {
                                    "type": "integer",
                                    "enum": [
                                        1,
                                        2,
                                        3,
                                        4,
                                        5,
                                        6,
                                        7,
                                        8,
                                        9
                                    ]
                                }
                            }
                        }
                    }
                ],
                "responses": {
                    "200": {
                        "description": "OK",
                        "schema": {
                            "type": "object",
                            "properties": {
                                "state": {
                                    "type": "integer",
                                    "description": "the last inserted treatment id",
                                    "example": 1
                                }
                            }
                        }
                    },
                    "400": {
                        "description": "Bad request",
                        "schema": {
                            "type": "object",
                            "properties": {
                                "error": {
                                    "type": "string",
                                    "enum": [
                                        "Couldn't create entry",
                                        "The request is missing some arguments",
                                        "Wrong value in the given arguments",
                                        "The date provided is not valid",
                                        "Frequency and Interval Unit must be both present or missing"
                                    ]
                                }
                            }
                        }
                    }
                }
            },
            "patch": {
                "summary": "Add termination date for treatment",
                "consumes": [
                    "application/json"
                ],
                "parameters": [
                    {
                        "in": "body",
                        "name": "treatmenttermination",
                        "schema": {
                            "type": "object",
                            "required": [
                                "treatmentId",
                                "terminatedDate",
                                "terminatedReason"
                            ],
                            "properties": {
                                "treatmentId": {
                                    "type": "integer",
                                    "example": 1
                                },
                                "terminationDate": {
                                    "type": "string",
                                    "example": "20100820"
                                },
                                "terminatedReason": {
                                    "type": "integer",
                                    "enum": [
                                        1,
                                        2,
                                        3,
                                        4,
                                        5,
                                        6,
                                        7,
                                        8,
                                        9
                                    ]
                                }
                            }
                        }
                    }
                ],
                "responses": {
                    "200": {
                        "description": "OK",
                        "schema": {
                            "type": "object",
                            "properties": {
                                "state": {
                                    "type": "integer",
                                    "description": "1 if termination date and reason are added"
                                }
                            }
                        }
                    },
                    "400": {
                        "description": "Bad request",
                        "schema": {
                            "$ref": "#/definitions/UpdateFailDate"
                        }
                    }
                }
            },
            "put": {
                "summary": "Edit a treatment",
                "consumes": [
                    "application/json"
                ],
                "parameters": [
                    {
                        "in": "body",
                        "name": "updatetreatment",
                        "schema": {
                            "type": "object",
                            "required": [
                                "id"
                            ],
                            "properties": {
                                "id": {
                                    "type": "integer",
                                    "description": "treatment id",
                                    "example": 1
                                },
                                "startDate": {
                                    "type": "string",
                                    "example": "20100820"
                                },
                                "terminatedDate": {
                                    "type": "string",
                                    "example": "20110820"
                                },
                                "terminatedReason": {
                                    "type": "integer"
                                },
                                "orderedDuringVisit": {
                                    "type": "integer"
                                },
                                "drug": {
                                    "type": "integer"
                                },
                                "dose": {
                                    "type": "integer"
                                },
                                "unit": {
                                    "type": "string",
                                    "enum": [
                                        "mg",
                                        "cc"
                                    ]
                                },
                                "form": {
                                    "type": "string",
                                    "enum": [
                                        "OR",
                                        "IV",
                                        "IM",
                                        "SC"
                                    ]
                                },
                                "times": {
                                    "type": "integer"
                                },
                                "intervalUnit": {
                                    "type": "string",
                                    "enum": [
                                        "hour",
                                        "day",
                                        "week",
                                        "month",
                                        "year"
                                    ]
                                }
                            }
                        }
                    }
                ],
                "responses": {
                    "200": {
                        "description": "OK",
                        "schema": {
                            "type": "object",
                            "properties": {
                                "state": {
                                    "type": "integer",
                                    "description": "1 if treatment is updated successfully"
                                }
                            }
                        }
                    },
                    "400": {
                        "description": "Bad request",
                        "schema": {
                            "$ref": "#/definitions/UpdateFailDate"
                        }
                    }
                }
            },
            "delete": {
                "summary": "Delete a treatment",
                "consumes": [
                    "application/json"
                ],
                "parameters": [
                    {
                        "in": "body",
                        "name": "deletetreatment",
                        "schema": {
                            "type": "object",
                            "required": [
                                "treatmentId"
                            ],
                            "properties": {
                                "treatmentId": {
                                    "type": "integer"
                                }
                            }
                        }
                    }
                ],
                "responses": {
                    "200": {
                        "description": "OK",
                        "schema": {
                            "type": "object",
                            "properties": {
                                "state": {
                                    "type": "integer",
                                    "description": "1 if treatment is deleted"
                                }
                            }
                        }
                    },
                    "400": {
                        "description": "Bad request",
                        "schema": {
                            "$ref": "#/definitions/DeleteFail"
                        }
                    }
                }
            }
        },
        "/treatments/interrupt": {
            "post": {
                "summary": "Add a treatment interruption",
                "consumes": [
                    "application/json"
                ],
                "parameters": [
                    {
                        "in": "body",
                        "name": "newtreatmentinterruption",
                        "schema": {
                            "type": "object",
                            "required": [
                                "treatmentId",
                                "start_date"
                            ],
                            "properties": {
                                "treatmentId": {
                                    "type": "integer"
                                },
                                "start_date": {
                                    "type": "string",
                                    "example": "20181010"
                                },
                                "meddra": {
                                    "type": "integer"
                                },
                                "end_date": {
                                    "type": "string"
                                },
                                "reason": {
                                    "type": "integer"
                                }
                            }
                        }
                    }
                ],
                "responses": {
                    "200": {
                        "description": "OK",
                        "schema": {
                            "type": "object",
                            "properties": {
                                "state": {
                                    "type": "integer"
                                }
                            }
                        }
                    },
                    "400": {
                        "description": "Bad request",
                        "schema": {
                            "$ref": "#/definitions/CreateFailDate"
                        }
                    }
                }
            },
            "put": {
                "summary": "Edit a treatment interruption",
                "consumes": [
                    "application/json"
                ],
                "parameters": [
                    {
                        "in": "body",
                        "name": "newtreatmentinterruption",
                        "schema": {
                            "type": "object",
                            "required": [
                                "treatmentId",
                                "start_date"
                            ],
                            "properties": {
                                "treatmentId": {
                                    "type": "integer"
                                },
                                "start_date": {
                                    "type": "string",
                                    "example": "20181010"
                                },
                                "meddra": {
                                    "type": "integer"
                                },
                                "end_date": {
                                    "type": "string"
                                },
                                "reason": {
                                    "type": "integer"
                                }
                            }
                        }
                    }
                ],
                "responses": {
                    "200": {
                        "description": "OK",
                        "schema": {
                            "type": "object",
                            "properties": {
                                "state": {
                                    "type": "integer",
                                    "description": "1 if treatment interruption is added"
                                }
                            }
                        }
                    },
                    "400": {
                        "description": "Bad request",
                        "schema": {
                            "$ref": "#/definitions/UpdateFailDate"
                        }
                    }
                }
            },
            "delete": {
                "summary": "Delete a treatment interruption",
                "consumes": [
                    "application/json"
                ],
                "parameters": [
                    {
                        "in": "body",
                        "name": "deletetreatmentinterruption",
                        "schema": {
                            "type": "object",
                            "required": [
                                "treatmentInterId"
                            ],
                            "properties": {
                                "treatmentInterId": {
                                    "type": "integer"
                                }
                            }
                        }
                    }
                ],
                "responses": {
                    "200": {
                        "description": "OK",
                        "schema": {
                            "type": "integer",
                            "description": "1 if treatment interruption is deleted"
                        }
                    },
                    "400": {
                        "description": "Bad request",
                        "schema": {
                            "$ref": "#/definitions/DeleteFail"
                        }
                    }
                }
            }
        },
        "/treatments/drugs": {
            "get": {
                "summary": "Get all treatments if no query string, treatments with name containing {name} otherwise",
                "parameters": [
                    {
                        "in": "query",
                        "name": "name",
                        "type": "string",
                        "description": "The name of treatment to search for"
                    }
                ],
                "responses": {
                    "200": {
                        "description": "OK",
                        "schema": {
                            "type": "array",
                            "items": {
                                "type": "object",
                                "properties": {
                                    "id": {
                                        "type": "integer",
                                        "example": 1
                                    },
                                    "name": {
                                        "type": "string"
                                    },
                                    "module": {
                                        "type": "string",
                                        "example": "Disease Modifying"
                                    }
                                }
                            }
                        }
                    },
                    "404": {
                        "description": "Not found",
                        "schema": {
                            "$ref": "#/definitions/GetFail"
                        }
                    }
                }
            }
        },
        "/treatments/reasons": {
            "get": {
                "summary": "Get all interruption reason options if no query string, reasons with property value containing {value} otherwise",
                "parameters": [
                    {
                        "in": "query",
                        "name": "name",
                        "type": "string",
                        "description": "the reason for the interruption"
                    }
                ],
                "responses": {
                    "200": {
                        "description": "OK",
                        "schema": {
                            "type": "array",
                            "items": {
                                "type": "object",
                                "properties": {
                                    "id": {
                                        "type": "integer",
                                        "example": 1
                                    },
                                    "value": {
                                        "type": "string",
                                        "example": "Death"
                                    },
                                    "module": {
                                        "type": "string",
                                        "example": "TREATMENTS"
                                    }
                                }
                            }
                        }
                    },
                    "404": {
                        "description": "Not found",
                        "schema": {
                            "$ref": "#/definitions/GetFail"
                        }
                    }
                }
            }
        },
        "/clinicalEvents": {
            "post": {
                "summary": "Create a clinical event",
                "parameters": [
                    {
                        "in": "body",
                        "name": "newclinicalevent",
                        "schema": {
                            "type": "object",
                            "description": "visitId or patient is required",
                            "required": [
                                "visitId",
                                "patient",
                                "dateStartDate",
                                "type"
                            ],
                            "properties": {
                                "visitId": {
                                    "type": "integer",
                                    "example": 1
                                },
                                "patient": {
                                    "type": "integer",
                                    "example": 1
                                },
                                "dateStartDate": {
                                    "type": "string",
                                    "example": "20160110"
                                },
                                "type": {
                                    "type": "integer",
                                    "description": "clinical event type",
                                    "enum": [
                                        0,
                                        1,
                                        2,
                                        3,
                                        4,
                                        5,
                                        6
                                    ]
                                },
                                "endDate": {
                                    "type": "string",
                                    "example": "20170110"
                                },
                                "meddra": {
                                    "type": "integer"
                                }
                            }
                        }
                    }
                ],
                "responses": {
                    "200": {
                        "description": "OK",
                        "schema": {
                            "type": "object",
                            "properties": {
                                "state": {
                                    "type": "integer",
                                    "description": "the clinical event id created last"
                                }
                            }
                        }
                    },
                    "400": {
                        "description": "Bad request",
                        "schema": {
                            "$ref": "#/definitions/CreateFailDate"
                        }
                    }
                }
            },
            "put": {
                "summary": "Update a clinical event",
                "parameters": [
                    {
                        "in": "body",
                        "name": "editclinicalevent",
                        "schema": {
                            "type": "object",
                            "required": [
                                "id"
                            ],
                            "properties": {
                                "id": {
                                    "type": "integer"
                                },
                                "dateStartDate": {
                                    "type": "string",
                                    "example": "20160110"
                                },
                                "type": {
                                    "type": "integer",
                                    "enum": [
                                        0,
                                        1,
                                        2,
                                        3,
                                        4,
                                        5,
                                        6
                                    ]
                                },
                                "endDate": {
                                    "type": "string",
                                    "example": "20170110"
                                },
                                "meddra": {
                                    "type": "integer"
                                }
                            }
                        }
                    }
                ],
                "responses": {
                    "200": {
                        "description": "OK",
                        "schema": {
                            "type": "object",
                            "properties": {
                                "state": {
                                    "type": "integer",
                                    "description": "1 if clinical event is updated"
                                }
                            }
                        }
                    },
                    "400": {
                        "description": "Bad request",
                        "schema": {
                            "$ref": "#/definitions/UpdateFailDate"
                        }
                    }
                }
            },
            "delete": {
                "summary": "Delete a clinical event",
                "parameters": [
                    {
                        "in": "body",
                        "name": "deleteclinicalevent",
                        "schema": {
                            "type": "object",
                            "required": [
                                "ceId"
                            ],
                            "properties": {
                                "ceId": {
                                    "type": "integer",
                                    "description": "the id of the clinical event to delete",
                                    "example": 1
                                }
                            }
                        }
                    }
                ],
                "responses": {
                    "200": {
                        "description": "OK",
                        "schema": {
                            "type": "object",
                            "properties": {
                                "state": {
                                    "type": "integer",
                                    "description": "1 if the clinical event is deleted"
                                }
                            }
                        }
                    },
                    "400": {
                        "description": "Bad request",
                        "schema": {
                            "$ref": "#/definitions/DeleteFail"
                        }
                    }
                }
            }
        },
        "/available/visitFields": {
            "get": {
                "summary": "Get all visit fields",
                "parameters": [
                    {
                        "in": "query",
                        "name": "module",
                        "type": "string",
                        "enum": [
                            "MS"
                        ]
                    }
                ],
                "responses": {
                    "200": {
                        "description": "OK",
                        "schema": {
                            "type": "array",
                            "items": {
                                "$ref": "#/definitions/Fields"
                            }
                        }
                    },
                    "400": {
                        "description": "Bad request",
                        "schema": {
                            "$ref": "#/definitions/GetFail"
                        }
                    }
                }
            }
        },
        "/available/visitSections": {
            "get": {
                "summary": "Get all visit sections",
                "parameters": [
                    {
                        "in": "query",
                        "name": "module",
                        "type": "string"
                    }
                ],
                "responses": {
                    "200": {
                        "description": "OK",
                        "schema": {
                            "type": "array",
                            "items": {
                                "$ref": "#/definitions/Sections"
                            }
                        }
                    },
                    "400": {
                        "description": "Bad request",
                        "schema": {
                            "$ref": "#/definitions/GetFail"
                        }
                    }
                }
            }
        },
        "/available/testFields": {
            "get": {
                "summary": "Get all test fields",
                "parameters": [
                    {
                        "in": "query",
                        "name": "module",
                        "type": "string",
                        "enum": [
                            "MS"
                        ]
                    }
                ],
                "responses": {
                    "200": {
                        "description": "OK",
                        "schema": {
                            "type": "array",
                            "items": {
                                "$ref": "#/definitions/Fields"
                            }
                        }
                    },
                    "400": {
                        "description": "Bad request",
                        "schema": {
                            "$ref": "#/definitions/GetFail"
                        }
                    }
                }
            }
        },
        "/available/ceFields": {
            "get": {
                "summary": "Get all clinical event fields",
                "parameters": [
                    {
                        "in": "query",
                        "name": "module",
                        "type": "string",
                        "enum": [
                            "MS"
                        ]
                    }
                ],
                "responses": {
                    "200": {
                        "description": "OK",
                        "schema": {
                            "type": "array",
                            "items": {
                                "$ref": "#/definitions/Fields"
                            }
                        }
                    },
                    "400": {
                        "description": "Bad request",
                        "schema": {
                            "$ref": "#/definitions/GetFail"
                        }
                    }
                }
            }
        },
        "/available/clinicalEvents": {
            "get": {
                "summary": "Get all clinical event types",
                "parameters": [
                    {
                        "in": "query",
                        "name": "module",
                        "type": "string",
                        "enum": [
                            "MS"
                        ]
                    }
                ],
                "responses": {
                    "200": {
                        "description": "OK",
                        "schema": {
                            "type": "array",
                            "items": {
                                "$ref": "#/definitions/Types"
                            }
                        }
                    },
                    "400": {
                        "description": "Bad request",
                        "schema": {
                            "$ref": "#/definitions/GetFail"
                        }
                    }
                }
            }
        },
        "/available/testTypes": {
            "get": {
                "summary": "Get all test types",
                "parameters": [
                    {
                        "in": "query",
                        "name": "module",
                        "type": "string",
                        "enum": [
                            "MS"
                        ]
                    }
                ],
                "responses": {
                    "200": {
                        "description": "OK",
                        "schema": {
                            "type": "array",
                            "items": {
                                "$ref": "#/definitions/Types"
                            }
                        }
                    },
                    "400": {
                        "description": "Bad request",
                        "schema": {
                            "$ref": "#/definitions/GetFail"
                        }
                    }
                }
            }
        },
        "/available/diagnoses": {
            "get": {
                "summary": "Get all diagnosis options",
                "responses": {
                    "200": {
                        "description": "OK",
                        "schema": {
                            "type": "array",
                            "items": {
                                "type": "object",
                                "properties": {
                                    "id": {
                                        "type": "integer"
                                    },
                                    "value": {
                                        "type": "string"
                                    }
                                }
                            }
                        }
                    },
                    "400": {
                        "description": "Bad request",
                        "schema": {
                            "$ref": "#/definitions/GetFail"
                        }
                    }
                }
            }
        },
        "/data/visit": {
            "post": {
                "summary": "Add or update visit data",
                "parameters": [
                    {
                        "in": "body",
                        "name": "addupdatevisitdata",
                        "schema": {
                            "type": "object",
                            "properties": {
                                "visitId": {
                                    "type": "integer",
                                    "example": 1
                                },
                                "add": {
                                    "type": "object",
                                    "description": "Object to add- visit field id as key and visit field value as value",
                                    "example": {
                                        "1": "BOTH",
                                        "2": 42
                                    }
                                },
                                "update": {
                                    "type": "object",
                                    "description": "Object to update- Visit field id as key and visit field value as value",
                                    "example": {
                                        "3": true
                                    }
                                }
                            }
                        }
                    }
                ],
                "responses": {
                    "200": {
                        "description": "OK",
                        "schema": {
                            "type": "object",
                            "properties": {
                                "success": {
                                    "type": "boolean"
                                },
                                "message": {
                                    "type": "string",
                                    "example": "Successfuly added entries."
                                }
                            }
                        }
                    },
                    "400": {
                        "description": "Bad request",
                        "schema": {
                            "type": "object",
                            "properties": {
                                "error": {
                                    "type": "string",
                                    "example": "Value should be a number for the field Systolic Blood Pressure"
                                }
                            }
                        }
                    },
                    "404": {
                        "description": "Not found",
                        "schema": {
                            "$ref": "#/definitions/Error"
                        }
                    }
                }
            },
            "delete": {
                "summary": "Delete visit data",
                "consumes": [
                    "application/json"
                ],
                "parameters": [
                    {
                        "in": "body",
                        "name": "deletevisitdata",
                        "schema": {
                            "type": "object",
                            "required": [
                                "visitId",
                                "delete"
                            ],
                            "properties": {
                                "visitId": {
                                    "type": "integer",
                                    "example": 1
                                },
                                "delete": {
                                    "type": "array",
                                    "items": {
                                        "type": "integer",
                                        "example": 3
                                    }
                                }
                            }
                        }
                    }
                ],
                "responses": {
                    "200": {
                        "description": "OK",
                        "schema": {
                            "type": "object",
                            "properties": {
                                "state": {
                                    "type": "integer",
                                    "description": "1 if visit data is deleted"
                                }
                            }
                        }
                    },
                    "400": {
                        "description": "Bad request",
                        "schema": {
                            "$ref": "#/definitions/Error"
                        }
                    }
                }
            }
        },
        "/data/{dataType}": {
            "get": {
                "summary": "Get all {dataType} fields",
                "parameters": [
                    {
                        "in": "path",
                        "name": "dataType",
                        "type": "string",
                        "required": true,
                        "enum": [
                            "visitFields",
                            "visitSections",
                            "testFields",
                            "ceFields",
                            "clinicalEvents",
                            "testTypes",
                            "diagnoses"
                        ]
                    }
                ],
                "responses": {
                    "200": {
                        "description": "OK",
                        "schema": {
                            "type": "array",
                            "description": "Array of fields or types. For types see",
                            "items": {
                                "$ref": "#/definitions/Fields"
                            }
                        }
                    },
                    "400": {
                        "description": "Bad request- GET fail",
                        "schema": {
                            "$ref": "#/definitions/Error"
                        }
                    }
                }
            }
        },
        "/data/diagnoses": {
            "get": {
                "summary": "Get all diagnosis options",
                "responses": {
                    "200": {
                        "description": "OK",
                        "schema": {
                            "type": "array",
                            "items": {
                                "properties": {
                                    "id": {
                                        "type": "integer"
                                    },
                                    "value": {
                                        "type": "string"
                                    }
                                }
                            }
                        }
                    },
                    "400": {
                        "description": "Bad request",
                        "schema": {
                            "$ref": "#/definitions/Error"
                        }
                    }
                }
            }
        },
        "/data/test": {
            "post": {
                "summary": "Add or update test data",
                "parameters": [
                    {
                        "in": "body",
                        "name": "addupdatetestdata",
                        "schema": {
                            "type": "object",
                            "properties": {
                                "testId": {
                                    "type": "integer",
                                    "example": 1
                                },
                                "add": {
                                    "type": "object",
                                    "description": "Object to add- test field id as key and test field value as value",
                                    "example": {
                                        "2": 42
                                    }
                                },
                                "update": {
                                    "type": "object",
                                    "description": "Object to update- test field id as key and test field value as value",
                                    "example": {
                                        "3": true
                                    }
                                }
                            }
                        }
                    }
                ],
                "responses": {
                    "200": {
                        "description": "OK",
                        "schema": {
                            "type": "object",
                            "properties": {
                                "success": {
                                    "type": "boolean"
                                },
                                "message": {
                                    "type": "string",
                                    "example": "Successfuly added entries."
                                }
                            }
                        }
                    },
                    "400": {
                        "description": "Bad request",
                        "schema": {
                            "type": "object",
                            "properties": {
                                "error": {
                                    "type": "string",
                                    "example": "Value should be a number for the field Bilirubin"
                                }
                            }
                        }
                    },
                    "404": {
                        "description": "Not found",
                        "schema": {
                            "$ref": "#/definitions/Error"
                        }
                    }
                }
            },
            "delete": {
                "summary": "Delete test data",
                "consumes": [
                    "application/json"
                ],
                "parameters": [
                    {
                        "in": "body",
                        "name": "deletetestdata",
                        "schema": {
                            "type": "object",
                            "required": [
                                "testId",
                                "delete"
                            ],
                            "properties": {
                                "testId": {
                                    "type": "integer",
                                    "example": 1
                                },
                                "delete": {
                                    "type": "array",
                                    "items": {
                                        "type": "integer",
                                        "example": 3
                                    }
                                }
                            }
                        }
                    }
                ],
                "responses": {
                    "200": {
                        "description": "OK",
                        "schema": {
                            "type": "object",
                            "properties": {
                                "state": {
                                    "type": "integer",
                                    "description": "1 if test data is deleted"
                                }
                            }
                        }
                    },
                    "400": {
                        "description": "Bad request",
                        "schema": {
                            "$ref": "#/definitions/Error"
                        }
                    }
                }
            }
        },
        "/data/clinicalEvent": {
            "post": {
                "summary": "Add or update clinical event data",
                "parameters": [
                    {
                        "in": "body",
                        "name": "addupdateclinicaleventdata",
                        "schema": {
                            "type": "object",
                            "properties": {
                                "clinicalEventId": {
                                    "type": "integer",
                                    "example": 1
                                },
                                "add": {
                                    "type": "object",
                                    "description": "Object to add- clinical event field id as key and clinical event field value as value",
                                    "example": {
                                        "60": "BOTH"
                                    }
                                },
                                "update": {
                                    "type": "object",
                                    "description": "Object to update- clinical event field id as key and clinical event field value as value",
                                    "example": {
                                        "3": true
                                    }
                                }
                            }
                        }
                    }
                ],
                "responses": {
                    "200": {
                        "description": "OK",
                        "schema": {
                            "type": "object",
                            "properties": {
                                "success": {
                                    "type": "boolean"
                                },
                                "message": {
                                    "type": "string",
                                    "example": "Successfuly added entries."
                                }
                            }
                        }
                    },
                    "400": {
                        "description": "Bad request",
                        "schema": {
                            "type": "object",
                            "properties": {
                                "error": {
                                    "type": "string",
                                    "example": "Value should be boolean for the field Impact on ADL"
                                }
                            }
                        }
                    },
                    "404": {
                        "description": "Not found",
                        "schema": {
                            "$ref": "#/definitions/Error"
                        }
                    }
                }
            },
            "delete": {
                "summary": "Delete clinical event data",
                "consumes": [
                    "application/json"
                ],
                "parameters": [
                    {
                        "in": "body",
                        "name": "deleteclinicaleventdata",
                        "schema": {
                            "type": "object",
                            "required": [
                                "clinicalEventId",
                                "delete"
                            ],
                            "properties": {
                                "clinicalEventId": {
                                    "type": "integer",
                                    "example": 1
                                },
                                "delete": {
                                    "type": "array",
                                    "items": {
                                        "type": "integer",
                                        "example": 3
                                    }
                                }
                            }
                        }
                    }
                ],
                "responses": {
                    "200": {
                        "description": "OK",
                        "schema": {
                            "type": "object",
                            "properties": {
                                "state": {
                                    "type": "integer",
                                    "description": "1 if clinical event data is deleted"
                                }
                            }
                        }
                    },
                    "400": {
                        "description": "Bad request",
                        "schema": {
                            "$ref": "#/definitions/Error"
                        }
                    }
                }
            }
        },
        "/demographics/Demographic": {
            "post": {
                "summary": "Create demographic entry",
                "parameters": [
                    {
                        "in": "body",
                        "name": "demographicentry",
                        "schema": {
                            "type": "object",
                            "required": [
                                "patient",
                                "DOB",
                                "gender",
                                "dominant_hand",
                                "ethnicity",
                                "country_of_origin",
                                "alcohol_usage",
                                "smoking_history"
                            ],
                            "properties": {
                                "patient": {
                                    "type": "integer",
                                    "example": 1
                                },
                                "DOB": {
                                    "type": "string",
                                    "example": "19901010"
                                },
                                "gender": {
                                    "type": "integer",
                                    "enum": [
                                        1,
                                        2,
                                        3,
                                        4
                                    ]
                                },
                                "dominant_hand": {
                                    "type": "integer",
                                    "enum": [
                                        1,
                                        2,
                                        3,
                                        4
                                    ]
                                },
                                "ethnicity": {
                                    "type": "integer",
                                    "enum": [
                                        1,
                                        2,
                                        3,
                                        4,
                                        5,
                                        6
                                    ]
                                },
                                "country_of_origin": {
                                    "type": "integer"
                                },
                                "alcohol_usage": {
                                    "type": "integer",
                                    "enum": [
                                        1,
                                        2,
                                        3,
                                        4
                                    ]
                                },
                                "smoking_history": {
                                    "type": "integer",
                                    "enum": [
                                        1,
                                        2,
                                        3,
                                        4
                                    ]
                                }
                            }
                        }
                    }
                ],
                "responses": {
                    "200": {
                        "description": "OK",
                        "schema": {
                            "type": "object",
                            "properties": {
                                "state": {
                                    "type": "integer",
                                    "description": "the patient demographic id inserted last"
                                }
                            }
                        }
                    },
                    "400": {
                        "description": "Bad request",
                        "schema": {
                            "$ref": "#/definitions/CreateFailDate"
                        }
                    }
                }
            },
            "put": {
                "summary": "Edit demographic data",
                "parameters": [
                    {
                        "in": "body",
                        "name": "editdemographicentry",
                        "schema": {
                            "type": "object",
                            "required": [
                                "id"
                            ],
                            "properties": {
                                "id": {
                                    "type": "integer",
                                    "example": 1,
                                    "description": "the demographic entry id"
                                },
                                "DOB": {
                                    "type": "string",
                                    "example": "19901010"
                                },
                                "gender": {
                                    "type": "integer",
                                    "enum": [
                                        1,
                                        2,
                                        3,
                                        4
                                    ]
                                },
                                "dominant_hand": {
                                    "type": "integer",
                                    "enum": [
                                        1,
                                        2,
                                        3,
                                        4
                                    ]
                                },
                                "ethnicity": {
                                    "type": "integer",
                                    "enum": [
                                        1,
                                        2,
                                        3,
                                        4,
                                        5,
                                        6
                                    ]
                                },
                                "country_of_origin": {
                                    "type": "integer"
                                },
                                "alcohol_usage": {
                                    "type": "integer",
                                    "enum": [
                                        1,
                                        2,
                                        3,
                                        4
                                    ]
                                },
                                "smoking_history": {
                                    "type": "integer",
                                    "enum": [
                                        1,
                                        2,
                                        3,
                                        4
                                    ]
                                }
                            }
                        }
                    }
                ],
                "responses": {
                    "200": {
                        "description": "OK",
                        "schema": {
                            "type": "object",
                            "properties": {
                                "state": {
                                    "type": "integer",
                                    "description": "1 if demographic entry is updated"
                                }
                            }
                        }
                    },
                    "400": {
                        "description": "Bad request",
                        "schema": {
                            "$ref": "#/definitions/UpdateFail"
                        }
                    }
                }
            },
            "delete": {
                "summary": "Delete demographic entry",
                "parameters": [
                    {
                        "in": "body",
                        "name": "deletedemographicentry",
                        "schema": {
                            "type": "object",
                            "required": [
                                "id"
                            ],
                            "properties": {
                                "id": {
                                    "type": "integer",
                                    "example": 1
                                }
                            }
                        }
                    }
                ],
                "responses": {
                    "200": {
                        "description": "OK",
                        "schema": {
                            "type": "object",
                            "properties": {
                                "state": {
                                    "type": "integer",
                                    "description": "1 if demographic entry is deleted"
                                }
                            }
                        }
                    },
                    "400": {
                        "description": "Bad request",
                        "schema": {
                            "$ref": "#/definitions/DeleteFail"
                        }
                    }
                }
            },
            "get": {
                "summary": "If no query string, get demographics of all patients. Otherwise, returns demographics for patient {patient}.",
                "parameters": [
                    {
                        "in": "query",
                        "name": "patient",
                        "type": "integer"
                    }
                ],
                "responses": {
                    "200": {
                        "description": "OK",
                        "schema": {
                            "type": "array",
                            "items": {
                                "type": "object",
                                "properties": {
                                    "id": {
                                        "type": "integer"
                                    },
                                    "patient": {
                                        "type": "integer"
                                    },
                                    "DOB": {
                                        "type": "string"
                                    },
                                    "gender": {
                                        "type": "integer"
                                    },
                                    "dominantHand": {
                                        "type": "integer"
                                    },
                                    "ethnicity": {
                                        "type": "integer"
                                    },
                                    "countryOfOrigin": {
                                        "type": "integer"
                                    },
                                    "alcoholUsage": {
                                        "type": "integer"
                                    },
                                    "smokingHistory": {
                                        "type": "integer"
                                    }
                                }
                            }
                        }
                    },
                    "400": {
                        "description": "Bad request",
                        "schema": {
                            "$ref": "#/definitions/GetFail"
                        }
                    }
                }
            }
        },
        "/demographics/Fields/Demographic": {
            "get": {
                "summary": "If no query string, returns all demographic fields",
                "parameters": [
                    {
                        "in": "query",
                        "name": "fieldName",
                        "type": "string",
                        "enum": [
                            "gender",
                            "dominant_hand",
                            "ethnicity",
                            "country",
                            "alcohol_usage",
                            "smoking_history"
                        ]
                    }
                ],
                "responses": {
                    "200": {
                        "description": "OK",
                        "schema": {
                            "$ref": "#/definitions/DemographicFields"
                        }
                    },
                    "400": {
                        "description": "Bad request",
                        "schema": {
                            "$ref": "#/definitions/Error"
                        }
                    }
                }
            }
        },
        "/demographics/Immunisation": {
            "post": {
                "summary": "Create immunisation entry",
                "parameters": [
                    {
                        "in": "body",
                        "name": "immunisationentry",
                        "schema": {
                            "type": "object",
                            "required": [
                                "patient",
                                "immunisationDate",
                                "vaccineName"
                            ],
                            "properties": {
                                "patient": {
                                    "type": "integer",
                                    "example": 1
                                },
                                "immunisationDate": {
                                    "type": "string",
                                    "example": "19901010"
                                },
                                "vaccineName": {
                                    "type": "string"
                                }
                            }
                        }
                    }
                ],
                "responses": {
                    "200": {
                        "description": "OK",
                        "schema": {
                            "type": "object",
                            "properties": {
                                "state": {
                                    "type": "integer",
                                    "description": "the immunisation id inserted last"
                                }
                            }
                        }
                    },
                    "400": {
                        "description": "Bad request",
                        "schema": {
                            "$ref": "#/definitions/CreateFailDate"
                        }
                    }
                }
            },
            "put": {
                "summary": "Edit immunisation data",
                "parameters": [
                    {
                        "in": "body",
                        "name": "editimmunisationentry",
                        "schema": {
                            "type": "object",
                            "required": [
                                "id"
                            ],
                            "properties": {
                                "id": {
                                    "type": "integer",
                                    "example": 1,
                                    "description": "the immunisation entry id"
                                },
                                "immunisationDate": {
                                    "type": "string",
                                    "example": "19901010"
                                },
                                "vaccineName": {
                                    "type": "string"
                                }
                            }
                        }
                    }
                ],
                "responses": {
                    "200": {
                        "description": "OK",
                        "schema": {
                            "type": "object",
                            "properties": {
                                "state": {
                                    "type": "integer",
                                    "description": "1 if immunisation entry is updated"
                                }
                            }
                        }
                    },
                    "400": {
                        "description": "Bad request",
                        "schema": {
                            "$ref": "#/definitions/UpdateFailDate"
                        }
                    }
                }
            },
            "delete": {
                "summary": "Delete immunisation entry",
                "parameters": [
                    {
                        "in": "body",
                        "name": "deleteimmunisationentry",
                        "schema": {
                            "type": "object",
                            "required": [
                                "id"
                            ],
                            "properties": {
                                "id": {
                                    "type": "integer",
                                    "example": 1
                                }
                            }
                        }
                    }
                ],
                "responses": {
                    "200": {
                        "description": "OK",
                        "schema": {
                            "type": "object",
                            "properties": {
                                "state": {
                                    "type": "integer",
                                    "description": "1 if immunisation entry is deleted"
                                }
                            }
                        }
                    },
                    "400": {
                        "description": "Bad request",
                        "schema": {
                            "$ref": "#/definitions/DeleteFail"
                        }
                    }
                }
            },
            "get": {
                "summary": "If no query string, get immunisations of all patients. Otherwise, returns immunisations for patient {patient}.",
                "parameters": [
                    {
                        "in": "query",
                        "name": "patient",
                        "type": "integer"
                    }
                ],
                "responses": {
                    "200": {
                        "description": "OK",
                        "schema": {
                            "type": "array",
                            "items": {
                                "type": "object",
                                "properties": {
                                    "id": {
                                        "type": "integer"
                                    },
                                    "patient": {
                                        "type": "integer"
                                    },
                                    "immunisationDate": {
                                        "type": "string"
                                    },
                                    "vaccineName": {
                                        "type": "string"
                                    }
                                }
                            }
                        }
                    },
                    "400": {
                        "description": "Bad request",
                        "schema": {
                            "$ref": "#/definitions/GetFail"
                        }
                    }
                }
            }
        },
        "/demographics/MedicalCondition": {
            "post": {
                "summary": "Create medical condition entry",
                "parameters": [
                    {
                        "in": "body",
                        "name": "newmedicalconditionentry",
                        "schema": {
                            "type": "object",
                            "required": [
                                "patient",
                                "startDate",
                                "outcome",
                                "relation",
                                "conditionName"
                            ],
                            "properties": {
                                "patient": {
                                    "type": "integer"
                                },
                                "startDate": {
                                    "type": "string",
                                    "example": "19901010"
                                },
                                "outcome": {
                                    "type": "string"
                                },
                                "relation": {
                                    "type": "integer"
                                },
                                "conditionName": {
                                    "type": "integer"
                                },
                                "resolvedYear": {
                                    "type": "integer"
                                }
                            }
                        }
                    }
                ],
                "responses": {
                    "200": {
                        "description": "OK",
                        "schema": {
                            "type": "object",
                            "properties": {
                                "state": {
                                    "type": "integer",
                                    "description": "the medical condition id inserted last"
                                }
                            }
                        }
                    },
                    "400": {
                        "description": "Bad request",
                        "schema": {
                            "$ref": "#/definitions/CreateFailDate"
                        }
                    }
                }
            },
            "put": {
                "summary": "Edit medical condition entry",
                "parameters": [
                    {
                        "in": "body",
                        "name": "editmedicalconditionentry",
                        "schema": {
                            "type": "object",
                            "required": [
                                "id"
                            ],
                            "properties": {
                                "id": {
                                    "type": "integer",
                                    "example": 1,
                                    "description": "the medical condition entry id"
                                },
                                "startDate": {
                                    "type": "string",
                                    "example": "19901010"
                                },
                                "outcome": {
                                    "type": "string"
                                },
                                "relation": {
                                    "type": "integer"
                                },
                                "conditionName": {
                                    "type": "integer"
                                },
                                "resolvedYear": {
                                    "type": "integer"
                                }
                            }
                        }
                    }
                ],
                "responses": {
                    "200": {
                        "description": "OK",
                        "schema": {
                            "type": "object",
                            "properties": {
                                "state": {
                                    "type": "integer",
                                    "description": "1 if medical condition entry is updated"
                                }
                            }
                        }
                    },
                    "400": {
                        "description": "Bad request",
                        "schema": {
                            "$ref": "#/definitions/UpdateFailDate"
                        }
                    }
                }
            },
            "delete": {
                "summary": "Delete medical condition entry",
                "parameters": [
                    {
                        "in": "body",
                        "name": "deletemedicalconditionentry",
                        "schema": {
                            "type": "object",
                            "required": [
                                "id"
                            ],
                            "properties": {
                                "id": {
                                    "type": "integer",
                                    "example": 1
                                }
                            }
                        }
                    }
                ],
                "responses": {
                    "200": {
                        "description": "OK",
                        "schema": {
                            "type": "object",
                            "properties": {
                                "state": {
                                    "type": "integer",
                                    "description": "1 if medical condition entry is deleted"
                                }
                            }
                        }
                    },
                    "400": {
                        "description": "Bad request",
                        "schema": {
                            "$ref": "#/definitions/DeleteFail"
                        }
                    }
                }
            },
            "get": {
                "summary": "If no query string, get medical conditions of all patients. Otherwise, returns medical conditions for patient {patient}.",
                "parameters": [
                    {
                        "in": "query",
                        "name": "patient",
                        "type": "integer"
                    }
                ],
                "responses": {
                    "200": {
                        "description": "OK",
                        "schema": {
                            "type": "array",
                            "items": {
                                "type": "object",
                                "properties": {
                                    "id": {
                                        "type": "integer"
                                    },
                                    "patient": {
                                        "type": "integer"
                                    },
                                    "startDate": {
                                        "type": "string",
                                        "example": "19901010"
                                    },
                                    "outcome": {
                                        "type": "string"
                                    },
                                    "relation": {
                                        "type": "integer"
                                    },
                                    "conditionName": {
                                        "type": "integer"
                                    },
                                    "resolvedYear": {
                                        "type": "integer"
                                    }
                                }
                            }
                        }
                    },
                    "400": {
                        "description": "Bad request",
                        "schema": {
                            "$ref": "#/definitions/GetFail"
                        }
                    }
                }
            }
        },
        "/demographics/Fields/MedicalCondition": {
            "get": {
                "summary": "If no query string, returns all medical condition fields",
                "parameters": [
                    {
                        "in": "query",
                        "name": "fieldName",
                        "type": "string",
                        "enum": [
                            "conditions",
                            "relations"
                        ]
                    }
                ],
                "responses": {
                    "200": {
                        "description": "OK",
                        "schema": {
                            "$ref": "#/definitions/MedicalConditionFields"
                        }
                    },
                    "400": {
                        "description": "Bad request",
                        "schema": {
                            "$ref": "#/definitions/Error"
                        }
                    }
                }
            }
        },
        "/demographics/Pregnancy": {
            "post": {
                "summary": "Create pregnancy entry",
                "parameters": [
                    {
                        "in": "body",
                        "name": "newpregnancyentry",
                        "schema": {
                            "type": "object",
                            "required": [
                                "patient",
                                "outcome",
                                "startDate"
                            ],
                            "properties": {
                                "patient": {
                                    "type": "integer"
                                },
                                "outcome": {
                                    "type": "integer"
                                },
                                "startDate": {
                                    "type": "string",
                                    "example": "19901010"
                                },
                                "outcomeDate": {
                                    "type": "string",
                                    "example": "19901010"
                                },
                                "meddra": {
                                    "type": "integer"
                                }
                            }
                        }
                    }
                ],
                "responses": {
                    "200": {
                        "description": "OK",
                        "schema": {
                            "type": "object",
                            "properties": {
                                "state": {
                                    "type": "integer",
                                    "description": "the pregnancy id inserted last"
                                }
                            }
                        }
                    },
                    "400": {
                        "description": "Bad request",
                        "schema": {
                            "$ref": "#/definitions/CreateFailDate"
                        }
                    }
                }
            },
            "put": {
                "summary": "Edit pregnancy entry",
                "parameters": [
                    {
                        "in": "body",
                        "name": "editpregnancyentry",
                        "schema": {
                            "type": "object",
                            "required": [
                                "id"
                            ],
                            "properties": {
                                "id": {
                                    "type": "integer",
                                    "example": 1,
                                    "description": "the pregnancy entry id"
                                },
                                "outcome": {
                                    "type": "integer"
                                },
                                "startDate": {
                                    "type": "string",
                                    "example": "19901010"
                                },
                                "outcomeDate": {
                                    "type": "string",
                                    "example": "19901010"
                                },
                                "meddra": {
                                    "type": "integer"
                                }
                            }
                        }
                    }
                ],
                "responses": {
                    "200": {
                        "description": "OK",
                        "schema": {
                            "type": "object",
                            "properties": {
                                "state": {
                                    "type": "integer",
                                    "description": "1 if pregnancy entry is updated"
                                }
                            }
                        }
                    },
                    "400": {
                        "description": "Bad request",
                        "schema": {
                            "$ref": "#/definitions/UpdateFailDate"
                        }
                    }
                }
            },
            "delete": {
                "summary": "Delete medical condition entry",
                "parameters": [
                    {
                        "in": "body",
                        "name": "deletepregnancyentry",
                        "schema": {
                            "type": "object",
                            "required": [
                                "id"
                            ],
                            "properties": {
                                "id": {
                                    "type": "integer",
                                    "example": 1
                                }
                            }
                        }
                    }
                ],
                "responses": {
                    "200": {
                        "description": "OK",
                        "schema": {
                            "type": "object",
                            "properties": {
                                "state": {
                                    "type": "integer",
                                    "description": "1 if pregnancy entry is deleted"
                                }
                            }
                        }
                    },
                    "400": {
                        "description": "Bad request",
                        "schema": {
                            "$ref": "#/definitions/DeleteFail"
                        }
                    }
                }
            },
            "get": {
                "summary": "If no query string, get pregnancies of all patients. Otherwise, returns pregnancies for patient {patient}.",
                "parameters": [
                    {
                        "in": "query",
                        "name": "patient",
                        "type": "integer"
                    }
                ],
                "responses": {
                    "200": {
                        "description": "OK",
                        "schema": {
                            "type": "array",
                            "items": {
                                "type": "object",
                                "properties": {
                                    "id": {
                                        "type": "integer"
                                    },
                                    "patient": {
                                        "type": "integer"
                                    },
                                    "outcome": {
                                        "type": "integer"
                                    },
                                    "startDate": {
                                        "type": "string",
                                        "example": "19901010"
                                    },
                                    "outcomeDate": {
                                        "type": "string",
                                        "example": "19901010"
                                    },
                                    "meddra": {
                                        "type": "integer"
                                    }
                                }
                            }
                        }
                    },
                    "400": {
                        "description": "Bad request",
                        "schema": {
                            "$ref": "#/definitions/GetFail"
                        }
                    }
                }
            }
        },
        "/demographics/Fields/Pregnancy": {
            "get": {
                "summary": "Get all avaialable pregnancy outcomes",
                "responses": {
                    "200": {
                        "description": "OK",
                        "schema": {
                            "type": "array",
                            "items": {
                                "type": "object",
                                "properties": {
                                    "id": {
                                        "type": "integer"
                                    },
                                    "value": {
                                        "type": "string"
                                    }
                                }
                            }
                        }
                    },
                    "400": {
                        "description": "Bad request",
                        "schema": {
                            "$ref": "#/definitions/GetFail"
                        }
                    }
                }
            }
        },
        "/logs": {
            "get": {
                "summary": "Get log of actions (admin only)",
                "produces": [
                    "application/json"
                ],
                "responses": {
                    "200": {
                        "description": "OK",
                        "schema": {
                            "type": "array",
                            "items": {
                                "$ref": "#/definitions/Log"
                            }
                        }
                    },
                    "400": {
                        "description": "Bad request",
                        "schema": {
                            "$ref": "#/definitions/GetFail"
                        }
                    },
                    "401": {
                        "description": "Unauthorized",
                        "schema": {
                            "$ref": "#/definitions/NoRights"
                        }
                    }
                }
            }
        },
        "/meddra": {
            "get": {
                "summary": "Get MedDRA",
                "description": "Get all MedDRA terms if no query string or the subset of terms containing {search} otherwise",
                "produces": [
                    "application/json"
                ],
                "parameters": [
                    {
                        "in": "query",
                        "name": "search",
                        "type": "string",
                        "description": "term to search for"
                    }
                ],
                "responses": {
                    "200": {
                        "description": "OK",
                        "schema": {
                            "type": "array",
                            "items": {
                                "type": "object",
                                "properties": {
                                    "id": {
                                        "type": "integer",
                                        "example": 1
                                    },
                                    "code": {
                                        "type": "string"
                                    },
                                    "name": {
                                        "type": "string"
                                    },
                                    "parent": {
                                        "type": "integer"
                                    },
                                    "isLeaf": {
                                        "type": "integer",
                                        "enum": [
                                            0,
                                            1
                                        ]
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
    },
    "definitions": {
        "Error": {
            "type": "object",
            "properties": {
                "error": {
                    "type": "string"
                }
            }
        },
        "UserInfo": {
            "type": "object",
            "properties": {
                "id": {
                    "type": "integer",
                    "example": 1
                },
                "username": {
                    "type": "string",
                    "example": "admin"
                },
                "realname": {
                    "type": "string",
                    "example": "Admin Administrator"
                },
                "priv": {
                    "type": "integer",
                    "example": 1
                }
            }
        },
        "User": {
            "type": "object",
            "properties": {
                "pw": {
                    "type": "string",
                    "example": "uSer3572"
                },
                "username": {
                    "type": "string",
                    "example": "testUser"
                },
                "isAdmin": {
                    "type": "integer",
                    "description": "1 is for admin users and 0 for non-admin",
                    "example": 0
                },
                "realname": {
                    "type": "string",
                    "example": "Test User"
                }
            }
        },
        "PatientBasicInfo": {
            "type": "object",
            "properties": {
                "patientId": {
                    "type": "integer",
                    "example": 1
                },
                "aliasId": {
                    "type": "string",
                    "example": "OPTIMISE1"
                },
                "optimiseConsent": {
                    "type": "string",
                    "description": "ISO formatted date"
                }
            }
        },
        "PatientProfile": {
            "type": "object",
            "properties": {
                "patientId": {
                    "type": "string"
                },
                "id": {
                    "type": "integer"
                },
                "optimiseConsent": {
                    "type": "string",
                    "description": "ISO formatted date"
                },
                "demographicData": {
                    "$ref": "#/definitions/Demographic"
                },
                "immunisations": {
                    "type": "array",
                    "items": {
                        "$ref": "#/definitions/Immunisation"
                    }
                },
                "medicalHistory": {
                    "type": "array",
                    "items": {
                        "$ref": "#/definitions/MedicalHistory"
                    }
                },
                "visits": {
                    "type": "array",
                    "items": {
                        "$ref": "#/definitions/Visit"
                    }
                },
                "tests": {
                    "type": "array",
                    "items": {
                        "$ref": "#/definitions/Test"
                    }
                },
                "treatments": {
                    "type": "array",
                    "items": {
                        "$ref": "#/definitions/Treatment"
                    }
                },
                "clinicalEvents": {
                    "type": "array",
                    "items": {
                        "$ref": "#/definitions/ClinicalEvent"
                    }
                },
                "pregnancy": {
                    "type": "array",
                    "items": {
                        "$ref": "#/definitions/Pregnancy"
                    }
                },
                "diagnosis": {
                    "type": "array",
                    "items": {
                        "$ref": "#/definitions/Diagnosis"
                    }
                }
            }
        },
        "VisitBasicInfo": {
            "type": "object",
            "properties": {
                "patientId": {
                    "type": "integer",
                    "description": "Numerical id of patient record",
                    "example": 1
                },
                "aliasId": {
                    "type": "string",
                    "description": "Patient ID given at patient creation",
                    "example": "OPTIMISE1"
                },
                "visitId": {
                    "type": "integer",
                    "description": "numerical id of visit record",
                    "example": 1
                },
                "communication": {
                    "type": "string",
                    "description": "visit communication report in text format",
                    "example": "Patient seen by Dr X today"
                },
                "visitDate": {
                    "type": "string",
                    "example": "20000924"
                },
                "type": {
                    "type": "integer",
                    "description": "type of visit",
                    "enum": [
                        1,
                        2
                    ]
                }
            }
        },
        "Demographic": {
            "type": "object",
            "properties": {
                "id": {
                    "type": "integer"
                },
                "DOB": {
                    "type": "string"
                },
                "gender": {
                    "type": "integer"
                },
                "dominantHand": {
                    "type": "integer"
                },
                "ethnicity": {
                    "type": "integer"
                },
                "countryOfOrigin": {
                    "type": "integer"
                },
                "alcoholUsage": {
                    "type": "integer"
                },
                "smokingHistory": {
                    "type": "integer"
                }
            }
        },
        "Immunisation": {
            "type": "object",
            "properties": {
                "id": {
                    "type": "integer"
                },
                "vaccineName": {
                    "type": "string"
                },
                "immunisationDate": {
                    "type": "string"
                }
            }
        },
        "MedicalHistory": {
            "type": "object",
            "properties": {
                "id": {
                    "type": "integer"
                },
                "relation": {
                    "type": "integer"
                },
                "conditionName": {
                    "type": "integer"
                },
                "startDate": {
                    "type": "string"
                },
                "outcome": {
                    "type": "string"
                },
                "resolvedYear": {
                    "type": "integer"
                }
            }
        },
        "Visit": {
            "type": "object",
            "properties": {
                "id": {
                    "type": "integer"
                },
                "visitDate": {
                    "type": "string"
                },
                "type": {
                    "type": "integer"
                },
                "communication": {
                    "type": "array",
                    "items": {
                        "$ref": "#/definitions/CommunicationReport"
                    }
                },
                "data": {
                    "type": "array",
                    "items": {
                        "$ref": "#/definitions/Data"
                    }
                }
            }
        },
        "Test": {
            "type": "object",
            "properties": {
                "id": {
                    "type": "integer"
                },
                "orderedDuringVisit": {
                    "type": "integer"
                },
                "type": {
                    "type": "integer"
                },
                "expectedOccurDate": {
                    "type": "string"
                },
                "actualOccurredDate": {
                    "type": "string"
                },
                "data": {
                    "type": "array",
                    "items": {
                        "$ref": "#/definitions/Data"
                    }
                }
            }
        },
        "Treatment": {
            "type": "object",
            "properties": {
                "id": {
                    "type": "integer"
                },
                "orderedDuringVisit": {
                    "type": "integer"
                },
                "drug": {
                    "type": "integer"
                },
                "dose": {
                    "type": "integer"
                },
                "unit": {
                    "type": "string"
                },
                "form": {
                    "type": "string"
                },
                "times": {
                    "type": "integer"
                },
                "intervalUnit": {
                    "type": "string"
                },
                "startDate": {
                    "type": "string"
                },
                "terminatedDate": {
                    "type": "string"
                },
                "terminatedReason": {
                    "type": "integer"
                },
                "visitDate": {
                    "type": "string"
                },
                "interruptions": {
                    "type": "array",
                    "items": {
                        "$ref": "#/definitions/Interruption"
                    }
                }
            }
        },
        "Interruption": {
            "type": "object",
            "properties": {
                "id": {
                    "type": "integer"
                },
                "reason": {
                    "type": "integer"
                },
                "startDate": {
                    "type": "string"
                },
                "endDate": {
                    "type": "string"
                },
                "meddra": {
                    "type": "integer"
                }
            }
        },
        "ClinicalEvent": {
            "type": "object",
            "properties": {
                "id": {
                    "type": "integer"
                },
                "recordedDuringVisit": {
                    "type": "integer"
                },
                "type": {
                    "type": "integer"
                },
                "dateStartDate": {
                    "type": "string"
                },
                "endDate": {
                    "type": "string"
                },
                "meddra": {
                    "type": "integer"
                },
                "data": {
                    "type": "array",
                    "items": {
                        "$ref": "#/definitions/Data"
                    }
                }
            }
        },
        "Pregnancy": {
            "type": "object",
            "properties": {
                "id": {
                    "type": "integer"
                },
                "patient": {
                    "type": "integer"
                },
                "startDate": {
                    "type": "string"
                },
                "outcome": {
                    "type": "integer"
                },
                "outcomeDate": {
                    "type": "string"
                },
                "meddra": {
                    "type": "integer"
                }
            }
        },
        "Diagnosis": {
            "type": "object",
            "properties": {
                "id": {
                    "type": "integer"
                },
                "patient": {
                    "type": "integer"
                },
                "diagnosis": {
                    "type": "integer"
                },
                "diagnosisDate": {
                    "type": "string",
                    "example": "YYYYMMDD"
                }
            }
        },
        "CommunicationReport": {
            "type": "object",
            "properties": {
                "id": {
                    "type": "integer",
                    "example": 1
                },
                "report": {
                    "type": "string"
                },
                "visit": {
                    "type": "integer",
                    "example": 1
                }
            }
        },
        "Data": {
            "type": "object",
            "properties": {
                "id": {
                    "type": "integer"
                },
                "field": {
                    "type": "integer"
                },
                "value": {
                    "type": "string"
                }
            }
        },
        "PII": {
            "type": "object",
            "properties": {
                "id": {
                    "type": "integer"
                },
                "patient": {
                    "type": "integer"
                },
                "firstName": {
                    "type": "string"
                },
                "surname": {
                    "type": "string"
                },
                "fullAddress": {
                    "type": "string"
                },
                "postcode": {
                    "type": "string"
                }
            }
        },
        "Fields": {
            "type": "object",
            "properties": {
                "id": {
                    "type": "integer"
                },
                "definition": {
                    "type": "string"
                },
                "idname": {
                    "type": "string"
                },
                "section": {
                    "type": "integer",
                    "enum": [
                        1,
                        2,
                        3,
                        4
                    ]
                },
                "subsection": {
                    "type": "string"
                },
                "type": {
                    "type": "integer",
                    "enum": [
                        1,
                        2,
                        3,
                        4,
                        5,
                        6,
                        7
                    ]
                },
                "unit": {
                    "type": "string"
                },
                "module": {
                    "type": "string"
                },
                "permittedValues": {
                    "type": "string"
                },
                "labels": {
                    "type": "string"
                },
                "referenceType": {
                    "type": "integer"
                },
                "laterality": {
                    "type": "string"
                },
                "cdiscName": {
                    "type": "string"
                }
            }
        },
        "Sections": {
            "type": "object",
            "properties": {
                "id": {
                    "type": "integer",
                    "example": 1
                },
                "name": {
                    "type": "string",
                    "example": "Symptoms"
                },
                "module": {
                    "type": "string"
                }
            }
        },
        "Types": {
            "type": "object",
            "properties": {
                "id": {
                    "type": "integer",
                    "example": 1
                },
                "name": {
                    "type": "string"
                },
                "module": {
                    "type": "string",
                    "enum": [
                        "MS"
                    ]
                }
            }
        },
        "IdValue": {
            "type": "object",
            "properties": {
                "id": {
                    "type": "integer"
                },
                "value": {
                    "type": "string"
                }
            }
        },
        "DemographicFields": {
            "type": "object",
            "properties": {
                "genders": {
                    "type": "array",
                    "items": {
                        "$ref": "#/definitions/IdValue"
                    }
                },
                "dominant_hands": {
                    "type": "array",
                    "items": {
                        "$ref": "#/definitions/IdValue"
                    }
                },
                "ethnicities": {
                    "type": "array",
                    "items": {
                        "$ref": "#/definitions/IdValue"
                    }
                },
                "countries": {
                    "type": "array",
                    "items": {
                        "type": "object",
                        "properties": {
                            "id": {
                                "type": "integer"
                            },
                            "country": {
                                "type": "string"
                            }
                        }
                    }
                },
                "alcohol_usage": {
                    "type": "array",
                    "items": {
                        "$ref": "#/definitions/IdValue"
                    }
                },
                "smoking_history": {
                    "type": "array",
                    "items": {
                        "$ref": "#/definitions/IdValue"
                    }
                }
            }
        },
        "MedicalConditionFields": {
            "type": "object",
            "properties": {
                "relations": {
                    "type": "array",
                    "items": {
                        "$ref": "#/definitions/IdValue"
                    }
                },
                "conditions": {
                    "type": "array",
                    "items": {
                        "$ref": "#/definitions/IdValue"
                    }
                }
            }
        },
        "Log": {
            "type": "object",
            "properties": {
                "id": {
                    "type": "integer"
                },
                "router": {
                    "type": "string"
                },
                "method": {
                    "type": "string"
                },
                "user": {
                    "type": "string"
                },
                "body": {
                    "type": "object"
                },
                "createdTime": {
                    "type": "string"
                }
            }
        },
        "NoRights": {
            "type": "object",
            "properties": {
                "error": {
                    "type": "string",
                    "enum": [
                        "Unauthorized to do this action"
                    ]
                }
            }
        },
        "EntryNotFound": {
            "type": "object",
            "properties": {
                "error": {
                    "type": "string",
                    "enum": [
                        "Couldn't find the entry"
                    ]
                }
            }
        },
        "GetFail": {
            "type": "object",
            "properties": {
                "error": {
                    "type": "string",
                    "enum": [
                        "Couldn't fetch the entry",
                        "The request is missing some arguments"
                    ]
                }
            }
        },
        "CreateFail": {
            "type": "object",
            "properties": {
                "error": {
                    "type": "string",
                    "enum": [
                        "Couldn't create the entry",
                        "The request is missing some arguments",
                        "Wrong value in the given arguments"
                    ]
                }
            }
        },
        "CreateFailDate": {
            "type": "object",
            "properties": {
                "error": {
                    "type": "string",
                    "enum": [
                        "Couldn't create entry",
                        "The request is missing some arguments",
                        "Wrong value in the given arguments",
                        "The date provided is not valid"
                    ]
                }
            }
        },
        "UpdateFail": {
            "type": "object",
            "properties": {
                "error": {
                    "type": "string",
                    "enum": [
                        "Couldn't update the entry",
                        "Couldn't find the entry",
                        "The request is missing some arguments",
                        "Wrong value in the given arguments"
                    ]
                }
            }
        },
        "UpdateFailDate": {
            "type": "object",
            "properties": {
                "error": {
                    "type": "string",
                    "enum": [
                        "Couldn't update entry",
                        "The request is missing some arguments",
                        "Wrong value in the given arguments",
                        "The date provided is not valid"
                    ]
                }
            }
        },
        "DeleteFail": {
            "type": "object",
            "properties": {
                "error": {
                    "type": "string",
                    "enum": [
                        "Couldn't delete the entry",
                        "The request is missing some arguments",
                        "Wrong value in the given arguments"
                    ]
                }
            }
        }
    }
}