swagger: '2.0'

info:
  title: eHealth SSL Order service
  version: 1.0.0
  description: eHealth SSL Order service
  termsOfService: http://ehealth.sundhed.dk/terms/
  license:
    name: Proprietary
  contact:
    name: Systematic A/S
    url: https://systematic.com/
    email: support.ehealth.servicedesk@systematic.com

host: ssl-order.{environment}.ehealth.sundhed.dk
basePath: /v1

externalDocs:
  description: "eHealth documentation"
  url: "http://ehealth-documentation.s3-website-eu-west-1.amazonaws.com/"

tags:
  - name: order
    description: Operations with orders
  - name: order line
    description: Operations with order lines
  - name: trace line
    description: Operations with trace lines
  - name: Party
    description: Operations with parties
  - name: Contract
    description: Operations with contracts

schemes:
  - http
  - https

securityDefinitions:
  bearerAuth:
    description: Bearer authorization (JWT) token, e.g. `Bearer <token>`
    type: apiKey
    in: header
    name: Authorization

security:
  - bearerAuth: []

paths:
  /party:
    post:
      tags:
        - Party
      summary: Create new Party
      consumes:
        - application/json
      description: Create new Party
      operationId: createParty
      parameters:
        - name: party
          in: body
          description: Party which should be created.
          required: true
          schema:
            $ref: '#/definitions/Party'
      responses:
        201:
          description: The Party was successfully created
          headers:
            location:
              type: string
              format: uri
              description: The location of the newly created Party.
        400:
          description: Invalid input
          schema:
            $ref: '#/definitions/Error'
        500:
          description: The server encountered an unexpected condition which prevented it from fulfilling the request
          schema:
            $ref: '#/definitions/Error'
        default:
          description: Unexpected error
          schema:
            $ref: '#/definitions/Error'
    put:
      tags:
        - Party
      summary: Update Party
      consumes:
        - application/json
      description: Update Party
      operationId: updateParty
      parameters:
        - name: party
          in: body
          description: Party with data to update
          required: true
          schema:
            $ref: '#/definitions/Party'
      responses:
        204:
          description: The Party was successfully updated
        400:
          description: Invalid input
          schema:
            $ref: '#/definitions/Error'
        404:
          description: Party not found
          schema:
            $ref: '#/definitions/Error'
        500:
          description: The server encountered an unexpected condition which prevented it from fulfilling the request
          schema:
            $ref: '#/definitions/Error'
        default:
          description: Unexpected error
          schema:
            $ref: '#/definitions/Error'
    get:
      tags:
        - Party
      summary: Search parties by parameters
      description: Search parties by parameters
      produces:
        - application/json
      operationId: getParties
      parameters:
        - name: name
          in: query
          description: Multiple name values can be provided
          type: array
          items:
            type: string
            pattern: ^(?!\s*$).+
          collectionFormat: multi
        - name: role
          in: query
          description: Multiple role values can be provided
          type: array
          items:
            type: string
            enum:
              - ACCOUNTING
              - BUYER
              - SELLER
          collectionFormat: multi
      responses:
        200:
          description: List of Parties was successfully returned
          schema:
            type: array
            items:
              $ref: '#/definitions/Party'
        400:
          description: Invalid input
          schema:
            $ref: '#/definitions/Error'
        500:
          description: The server encountered an unexpected condition which prevented it from fulfilling the request
          schema:
            $ref: '#/definitions/Error'
        default:
          description: Unexpected error
          schema:
            $ref: '#/definitions/Error'

  /party/{id}:
    get:
      tags:
        - Party
      summary: Return Party by id
      description: Return Party by id
      operationId: getPartyById
      produces:
        - application/json
      parameters:
        - name: id
          in: path
          description: Id of Party
          required: true
          type: string
      responses:
        200:
          description: The Party was successfully returned
          schema:
            $ref: '#/definitions/Party'
        400:
          description: Invalid input
          schema:
            $ref: '#/definitions/Error'
        404:
          description: Party not found
          schema:
            $ref: '#/definitions/Error'
        500:
          description: The server encountered an unexpected condition which prevented it from fulfilling the request
          schema:
            $ref: '#/definitions/Error'
        default:
          description: Unexpected error
          schema:
            $ref: '#/definitions/Error'

  /contract:
    post:
      tags:
        - Contract
      summary: Create new Contract
      consumes:
        - application/json
      description: Create new Contract
      operationId: createContract
      parameters:
        - name: contract
          in: body
          description: Contract which should be created
          required: true
          schema:
            $ref: '#/definitions/Contract'
      responses:
        201:
          description: The Contract was successfully created
          headers:
            location:
              type: string
              format: uri
              description: The location of the newly created Contract
        400:
          description: Invalid input
          schema:
            $ref: '#/definitions/Error'
        500:
          description: The server encountered an unexpected condition which prevented it from fulfilling the request
          schema:
            $ref: '#/definitions/Error'
        default:
          description: Unexpected error
          schema:
            $ref: '#/definitions/Error'
    get:
      tags:
        - Contract
      summary: Search for Contracts by parameters
      produces:
        - application/json
      description: Search for Contracts by parameters
      operationId: getContracts
      parameters:
        - name: seller
          in: query
          description: Single seller reference can be provided
          type: string
        - name: account
          in: query
          description: Single account reference can be provided
          type: string
        - name: buyer
          in: query
          description: Single buyer reference can be provided
          type: string
      responses:
        200:
          description: List of Contracts was successfully returned
          schema:
            type: array
            items:
              $ref: '#/definitions/Contract'
        400:
          description: Invalid input
          schema:
            $ref: '#/definitions/Error'
        500:
          description: The server encountered an unexpected condition which prevented it from fulfilling the request
          schema:
            $ref: '#/definitions/Error'
        default:
          description: Unexpected error
          schema:
            $ref: '#/definitions/Error'

  /contract/{id}:
    get:
      tags:
        - Contract
      summary: Return Contract by id
      description: Return Contract by id
      produces:
        - application/json
      operationId: getContractById
      parameters:
        - name: id
          in: path
          description: Id of Contract
          required: true
          type: string
      responses:
        200:
          description: The Contract was successfully returned
          schema:
            $ref: '#/definitions/Contract'
        400:
          description: Invalid input
          schema:
            $ref: '#/definitions/Error'
        404:
          description: Contract not found
          schema:
            $ref: '#/definitions/Error'
        500:
          description: The server encountered an unexpected condition which prevented it from fulfilling the request
          schema:
            $ref: '#/definitions/Error'
        default:
          description: Unexpected error
          schema:
            $ref: '#/definitions/Error'
    patch:
      tags:
        - Contract
      summary: Patch selected fields of the given contract
      description: Patch selected fields of the given contract
      operationId: patchContract
      consumes:
        - application/json-patch+json
      parameters:
        - name: id
          in: path
          format: uuid
          description: Id of Contract
          required: true
          type: string
        - name: jsonPatch
          in: body
          required: true
          description: The JSON patch object
          schema:
            $ref: '#/definitions/PatchRequest'
      responses:
        204:
          description: The contract was successfully updated.
        400:
          description: Invalid input
          schema:
            $ref: '#/definitions/Error'
        404:
          description: The contract was not found
          schema:
            $ref: '#/definitions/Error'
        500:
          description: The server encountered an unexpected condition which prevented it from fulfilling the request
          schema:
            $ref: '#/definitions/Error'

  /order:
    post:
      operationId: createOrder
      summary: Create a new order.
      consumes:
        - application/json
      tags:
        - order
      parameters:
        - name: order
          in: body
          required: true
          schema:
            $ref: '#/definitions/Order'
      responses:
        201:
          description: The order was successfully created.
          headers:
            Location:
              type: string
              format: uri
              description: The location of the newly created Order.
        400:
          description: The request could not be understood.
          schema:
            $ref: '#/definitions/Error'
        500:
          description: The server encountered an unexpected condition which prevented it from fulfilling the request.
          schema:
            $ref: '#/definitions/Error'
        default:
          description: Unexpected error
          schema:
            $ref: '#/definitions/Error'
    put:
      summary: Update an order.
      consumes:
        - application/json
      description: id property is required.
      tags:
        - order
      operationId: updateOrder
      parameters:
        - name: order
          in: body
          required: true
          schema:
            $ref: '#/definitions/Order'
      responses:
        204:
          description: The order was successfully updated.
        400:
          description: The request could not be understood.
          schema:
            $ref: '#/definitions/Error'
        401:
          description: User is unauthorized to change field.
          schema:
            $ref: '#/definitions/Error'
        403:
          description: Ilegal state changes are attempted.
          schema:
            $ref: '#/definitions/Error'
        500:
          description: The server encountered an unexpected condition which prevented it from fulfilling the request.
          schema:
            $ref: '#/definitions/Error'
        default:
          description: Unexpected error
          schema:
            $ref: '#/definitions/Error'

  /order/{id}:
    get:
      operationId: getOrderById
      summary: Retrieve an order
      produces:
        - application/json
      tags:
        - order
      parameters:
        - name: id
          in: path
          required: true
          description: The id of the order to retrieve.
          type: string
      responses:
        200:
          description: The order was successfully retrieved.
          schema:
            $ref: '#/definitions/Order'
        400:
          description: The request could not be understood
          schema:
            $ref: '#/definitions/Error'
        401:
          description: Unauthorized
          schema:
            $ref: '#/definitions/Error'
        500:
          description: The server encountered an unexpected condition which prevented it from fulfilling the request.
          schema:
            $ref: '#/definitions/Error'
        default:
          description: Unexpected error
          schema:
            $ref: '#/definitions/Error'
    patch:
      operationId: updatedPartialOrder
      summary: Update an order partially
      consumes:
        - application/json
      tags:
        - order
      parameters:
        - name: id
          in: path
          required: true
          description: The id of the order to update partially.
          type: string
        - name: order
          in: body
          required: true
          description: The data of order to update partially.
          schema:
            $ref: '#/definitions/OrderBase'
      responses:
        204:
          description: The order was successfully updated.
        400:
          description: The request could not be understood
          schema:
            $ref: '#/definitions/Error'
        401:
          description: Unauthorized
          schema:
            $ref: '#/definitions/Error'
        403:
          description: Illegal state changes are attempted.
          schema:
            $ref: '#/definitions/Error'
        500:
          description: The server encountered an unexpected condition which prevented it from fulfilling the request.
          schema:
            $ref: '#/definitions/Error'
        default:
          description: Unexpected error
          schema:
            $ref: '#/definitions/Error'
    delete:
      operationId: deleteOrder
      summary: Delete an order
      tags:
        - order
      parameters:
        - name: id
          in: path
          required: true
          description: The id of the order to delete.
          type: string
      responses:
        204:
          description: The order was successfully deleted.
        400:
          description: The request could not be understood
          schema:
            $ref: '#/definitions/Error'
        401:
          description: Unauthorized
          schema:
            $ref: '#/definitions/Error'
        403:
          description: Order is not in state suitable for deletion.
          schema:
            $ref: '#/definitions/Error'
        500:
          description: The server encountered an unexpected condition which prevented it from fulfilling the request.
          schema:
            $ref: '#/definitions/Error'
        default:
          description: Unexpected error
          schema:
            $ref: '#/definitions/Error'

  /order/{id}/details:
    get:
      operationId: getOrderDetails
      summary: Retrieve details of an order.
      produces:
        - application/json
      tags:
        - order
      parameters:
        - name: id
          in: path
          required: true
          description: The id of the order details to retrieve.
          type: string
      responses:
        200:
          description: The order details were successfully retrieved.
          schema:
            $ref: '#/definitions/OrderDetails'
        400:
          description: The request could not be understood
          schema:
            $ref: '#/definitions/Error'
        401:
          description: Unauthorized
          schema:
            $ref: '#/definitions/Error'
        500:
          description: The server encountered an unexpected condition which prevented it from fulfilling the request.
          schema:
            $ref: '#/definitions/Error'
        default:
          description: Unexpected error
          schema:
            $ref: '#/definitions/Error'

  /order/{id}/note:
    post:
      operationId: createOrderNote
      summary: Create new note for the order.
      produces:
        - application/json
      tags:
        - order
      parameters:
        - name: id
          in: path
          required: true
          description: the id of the order notes to retrieve
          type: string
        - name: note
          in: body
          required: true
          schema:
            $ref: '#/definitions/OrderNotes'
      responses:
        204:
          description: The OrderNotes was successfully added to order.
        400:
          description: The request could not be understood
          schema:
            $ref: '#/definitions/Error'
        401:
          description: Unauthorized
          schema:
            $ref: '#/definitions/Error'
        500:
          description: The server encountered an unexpected condition which prevented it from fulfilling the request.
          schema:
            $ref: '#/definitions/Error'
        default:
          description: Unexpected error
          schema:
            $ref: '#/definitions/Error'

  /orders:
    get:
      operationId: getOrders
      summary: Search orders by parameters
      produces:
        - application/json
      tags:
        - order
      parameters:
        - name: seller
          in: query
          description: Multiple references to SellerSupplierParty can be provided.
          type: array
          items:
            type: string
          collectionFormat: multi
        - name: buyer
          in: query
          description: Multiple references to BuyerCustomerParty can be provided.
          type: array
          items:
            type: string
          collectionFormat: multi
        - name: identifier
          in: query
          description: Multiple identifier values like http://ehealth.xxx.dk/somesystem|somecode can be provided.
          type: array
          items:
            type: string
          collectionFormat: multi
        - name: patient
          in: query
          description: Multiple patient refernces from clinical domain can be provided.
          type: array
          items:
            type: string
          collectionFormat: multi
      responses:
        200:
          description: Orders were successfully retrieved.
          schema:
            type: array
            items:
              $ref: '#/definitions/Order'
        400:
          description: The request could not be understood
          schema:
            $ref: '#/definitions/Error'
        401:
          description: Unauthorized
          schema:
            $ref: '#/definitions/Error'
        500:
          description: The server encountered an unexpected condition which prevented it from fulfilling the request.
          schema:
            $ref: '#/definitions/Error'
        default:
          description: Unexpected error
          schema:
            $ref: '#/definitions/Error'

  /order-line:
    post:
      operationId: createOrderLine
      summary: Create a new order line.
      consumes:
        - application/json
      tags:
        - order line
      parameters:
        - name: order-line
          in: body
          required: true
          schema:
            $ref: '#/definitions/OrderLine'
      responses:
        201:
          description: The order line was successfully created.
          headers:
            Location:
              type: string
              format: uri
              description: The location of the newly created order line.
        400:
          description: The request could not be understood.
          schema:
            $ref: '#/definitions/Error'
        500:
          description: The server encountered an unexpected condition which prevented it from fulfilling the request.
          schema:
            $ref: '#/definitions/Error'
        default:
          description: Unexpected error
          schema:
            $ref: '#/definitions/Error'
    put:
      summary: Update an order line.
      description: id property is required.
      consumes:
        - application/json
      tags:
        - order line
      operationId: updateOrderLine
      parameters:
        - name: order-line
          in: body
          required: true
          schema:
            $ref: '#/definitions/OrderLine'
      responses:
        204:
          description: The order line was successfully updated.
        400:
          description: The request could not be understood.
          schema:
            $ref: '#/definitions/Error'
        401:
          description: User is unauthorized to change field.
          schema:
            $ref: '#/definitions/Error'
        403:
          description: Ilegal state changes are attempted.
          schema:
            $ref: '#/definitions/Error'
        500:
          description: The server encountered an unexpected condition which prevented it from fulfilling the request.
          schema:
            $ref: '#/definitions/Error'
        default:
          description: Unexpected error
          schema:
            $ref: '#/definitions/Error'

  /order-line/{id}:
    get:
      operationId: getOrderLineById
      summary: Retrieve an order line
      produces:
        - application/json
      tags:
        - order line
      parameters:
        - name: id
          in: path
          required: true
          description: The id of the order line to retrieve.
          type: string
      responses:
        200:
          description: The order line was successfully retrieved.
          schema:
            $ref: '#/definitions/OrderLine'
        400:
          description: The request could not be understood
          schema:
            $ref: '#/definitions/Error'
        401:
          description: Unauthorized
          schema:
            $ref: '#/definitions/Error'
        500:
          description: The server encountered an unexpected condition which prevented it from fulfilling the request.
          schema:
            $ref: '#/definitions/Error'
        default:
          description: Unexpected error
          schema:
            $ref: '#/definitions/Error'
    patch:
      tags:
        - order line
      summary: Patch the selected fields for a given order line
      description: Patch the selected fields for a given order line
      operationId: patchOrderLine
      consumes:
        - application/json-patch+json
      parameters:
        - name: id
          in: path
          format: string
          description: Id of the order line
          required: true
          type: string
        - name: jsonPatch
          in: body
          required: true
          description: The JSON patch object
          schema:
            $ref: '#/definitions/PatchRequest'
      responses:
        204:
          description: The order line was successfully updated.
        400:
          description: Invalid input
          schema:
            $ref: '#/definitions/Error'
        404:
          description: The order line was not found
          schema:
            $ref: '#/definitions/Error'
        500:
          description: The server encountered an unexpected condition which prevented it from fulfilling the request
          schema:
            $ref: '#/definitions/Error'
    delete:
      operationId: deleteOrderLine
      summary: Delete an order line
      tags:
        - order line
      parameters:
        - name: id
          in: path
          required: true
          description: The id of the order line to delete.
          type: string
      responses:
        204:
          description: The order line was successfully deleted.
        400:
          description: The request could not be understood
          schema:
            $ref: '#/definitions/Error'
        401:
          description: Unauthorized
          schema:
            $ref: '#/definitions/Error'
        403:
          description: Order line is not in state suitable for deletion.
          schema:
            $ref: '#/definitions/Error'
        500:
          description: The server encountered an unexpected condition which prevented it from fulfilling the request.
          schema:
            $ref: '#/definitions/Error'
        default:
          description: Unexpected error
          schema:
            $ref: '#/definitions/Error'

  /order-lines:
    post:
      operationId: createOrderLines
      summary: Create new order lines
      consumes:
        - application/json
      tags:
        - order line
      parameters:
        - name: order-lines
          in: body
          required: true
          schema:
            type: array
            items:
              $ref: '#/definitions/OrderLine'
      responses:
        201:
          description: The order lines were successfully created.
          headers:
            Location:
              type: array
              description: The location of the newly created order lines.
              items:
                type: string
                format: uri
        400:
          description: The request could not be understood.
          schema:
            $ref: '#/definitions/Error'
        401:
          description: Unauthorized.
          schema:
            $ref: '#/definitions/Error'
        500:
          description: The server encountered an unexpected condition which prevented it from fulfilling the request.
          schema:
            $ref: '#/definitions/Error'
        default:
          description: Unexpected error
          schema:
            $ref: '#/definitions/Error'
    put:
      operationId: updateOrderLines
      summary: Update existing order lines
      consumes:
        - application/json
      tags:
        - order line
      parameters:
        - name: order-lines
          in: body
          required: true
          schema:
            type: array
            items:
              $ref: '#/definitions/OrderLine'
      responses:
        204:
          description: Order lines were successfully updated.
        400:
          description: The request could not be understood.
          schema:
            $ref: '#/definitions/Error'
        401:
          description: Unauthorized.
          schema:
            $ref: '#/definitions/Error'
        403:
          description: Illegal state changes are attempted.
          schema:
            $ref: '#/definitions/Error'
        500:
          description: The server encountered an unexpected condition which prevented it from fulfilling the request.
          schema:
            $ref: '#/definitions/Error'
        default:
          description: Unexpected error
          schema:
            $ref: '#/definitions/Error'
    get:
      operationId: getOrderLines
      summary: Search order lines by parameters
      produces:
        - application/json
      tags:
        - order line
      parameters:
        - name: order
          in: query
          description: Multiple references to Order can be provided.
          type: array
          items:
            type: string
          collectionFormat: multi
      responses:
        200:
          description: Order lines were successfully retrieved.
          schema:
            type: array
            items:
              $ref: '#/definitions/OrderLine'
        400:
          description: The request could not be understood
          schema:
            $ref: '#/definitions/Error'
        401:
          description: Unauthorized
          schema:
            $ref: '#/definitions/Error'
        500:
          description: The server encountered an unexpected condition which prevented it from fulfilling the request.
          schema:
            $ref: '#/definitions/Error'
        default:
          description: Unexpected error
          schema:
            $ref: '#/definitions/Error'

  /system/findOrCreateParty:
    post:
      tags:
        - Party
      summary: Find or create Party for given organizationReference
      consumes:
        - application/json
      description: >-
        This is a infrastructure-only operation that will search for a Party having the given organizationReference.


        If no Party is found a Party will be created referencing the given organizationReference and an empty list of allowedRoles.
      operationId: systemFindOrCreatePartyMethod
      parameters:
        - name: organizationReference
          in: body
          description: OrganizationReference of the Party
          required: true
          schema:
            $ref: '#/definitions/OrganizationReference'
      responses:
        201:
          description: The Party was successfully found or created
          headers:
            location:
              type: string
              format: uri
              description: The location of the found or created Party.
        400:
          description: Invalid input
          schema:
            $ref: '#/definitions/Error'
        500:
          description: The server encountered an unexpected condition which prevented it from fulfilling the request
          schema:
            $ref: '#/definitions/Error'
        default:
          description: Unexpected error
          schema:
            $ref: '#/definitions/Error'

  /system/hasOpenOrder:
    get:
      tags:
        - Order
      summary: Check if an open order exists for the careplan
      produces:
        - application/json
      description: Check if an open order exists for the careplan
      operationId: hasOpenOrder
      parameters:
        - name: careplan
          description: Single careplan reference can be provided
          in: query
          type: string
          required: true
        #          pattern: '^((http[s]?):\/)?\/?([^:\/\s]+)((\/\w+)*\/)([\w\-\.]+[^#?\s]+)(.*)?(#[\w\-]+)?$'
      responses:
        200:
          description: Boolean {body} = true if an open order exists for the careplan exists, and body = {false} if no order or status is not open
          schema:
            type: boolean
        400:
          description: Invalid input
          schema:
            $ref: '#/definitions/Error'
        500:
          description: The server encountered an unexpected condition which prevented it from fulfilling the request
          schema:
            $ref: '#/definitions/Error'

  /custom/hasValidContract:
    get:
      tags:
        - Contract
      summary: Check if a valid contract exists between the two parties
      produces:
        - application/json
      description: Check if a valid contract exists between the two parties
      operationId: hasValidContract
      parameters:
        - name: seller
          description: Single seller reference can be provided, e.g. "http://ssl-order.ehealth.sundhed.dk/v1/party/b83e7b2e-779f-44fc-9c4d-b1f564303a31"
          in: query
          type: string
          required: true
        #          pattern: '^((http[s]?):\/)?\/?([^:\/\s]+)((\/\w+)*\/)([\w\-\.]+[^#?\s]+)(.*)?(#[\w\-]+)?$'
        - name: buyer
          description: Single buyer reference can be provided, e.g. "https://ssl-order.ehealth.sundhed.dk/v1/party/d36202ed-4751-449b-a371-53a94b6b3ca4"
          in: query
          type: string
          required: true
      #          pattern: ^((http[s]?):\/)?\/?([^:\/\s]+)((\/\w+)*\/)([\w\-\.]+[^#?\s]+)(.*)?(#[\w\-]+)?$
      responses:
        200:
          description: Boolean {body} = true if valid contract between seller and buyer exists, and body = {false} if no contract
          schema:
            type: boolean
        400:
          description: Invalid input
          schema:
            $ref: '#/definitions/Error'
        500:
          description: The server encountered an unexpected condition which prevented it from fulfilling the request
          schema:
            $ref: '#/definitions/Error'
        default:
          description: Unexpected error
          schema:
            $ref: '#/definitions/Error'

  /custom/findOrCreateParty:
    post:
      tags:
        - Party
      summary: Find or create Party for given organizationReference
      consumes:
        - application/json
      description: >-
        This operation will search for a Party having the given organizationReference.


        If no Party is found a Party will be created referencing the given organizationReference and a list of allowedRoles depending on the user type supplied in the authentication token:

        - UserType PRACITIONER, allowedRoles: BUYER, ACCOUNTING

        - UserType SSL, allowedRoles: SELLER


        The given organizationReference must match the organization context supplied in the authentication token.
      operationId: findOrCreatePartyMethod
      parameters:
        - name: organizationReference
          in: body
          description: OrganizationReference of the Party
          required: true
          schema:
            $ref: '#/definitions/OrganizationReference'
      responses:
        201:
          description: The Party was successfully found or created
          headers:
            location:
              type: string
              format: uri
              description: The location of the found or created Party.
        400:
          description: Invalid input
          schema:
            $ref: '#/definitions/Error'
        500:
          description: The server encountered an unexpected condition which prevented it from fulfilling the request
          schema:
            $ref: '#/definitions/Error'
        default:
          description: Unexpected error
          schema:
            $ref: '#/definitions/Error'

definitions:
  Party:
    type: object
    required:
      - allowedRoles
      - name
    properties:
      id:
        type: string
        description: Unique ID of this Party. Assigned by server
        example: 1
      allowedRoles:
        type: array
        items:
          type: string
          enum:
            - ACCOUNTING
            - BUYER
            - SELLER
        description: Allowed roles for this party
        example: [BUYER, ACCOUNTING]
      name:
        type: string
        pattern: ^(?!\s*$).+
        description: Party name
        example: Aarhus University Hospital
      email:
        type: string
        format: email
        description: Party contact person email
        example: auh@rm.dk
      organization:
        type: string
        #        pattern: ^(?:http(s)?:\/\/)?[\w.-]+(?:\.[\w\.-]+)+[\w\-\._~:/?#[\]@!\$&'\(\)\*\+,;=.]+\/Organization/\d+$
        description: Reference to the corresponding ehealth-organisation in the clinical domain. Pattern should be used ^(?:http(s)?:\/\/)?[\w.-]+(?:\.[\w\.-]+)+[\w\-\._~:/?#[\]@!\$&'\(\)\*\+,;=.]+\/Organization/\d+$
        example: https://ehealth.sundhed.dk/organization/fhir/Organization/1566241

  Contract:
    type: object
    required:
      - validityPeriod
      - seller
      - account
    properties:
      id:
        type: string
        description: Unique ID of this contract. Assigned by server
        example: 2
      name:
        type: string
        pattern: '^(?!\s*$).+'
        description: A human readable short headline describing this contract.
        example: XYZ Supplier 2019-21 for Mainland area
      validityPeriod:
        type: object
        required:
          - start
        properties:
          start:
            type: string
            format: date
            description: Start Date for this time period
            example: '2019-01-01'
          end:
            type: string
            format: date
            description: Last day of contract validity period
            example: '2020-01-01'
        description: Period where this contract is valid
      seller:
        type: string
        #        pattern: ^((http[s]?):\/)?\/?([^:\/\s]+)((\/\w+)*\/)([\w\-\.]+[^#?\s]+)(.*)?(#[\w\-]+)?$
        example: http://ehealth.sundhed.dk/ssl-governance/v1/party/456
        description: Reference (by rest url) to the SSL service provider
      account:
        type: string
        #        pattern: ^((http[s]?):\/)?\/?([^:\/\s]+)((\/\w+)*\/)([\w\-\.]+[^#?\s]+)(.*)?(#[\w\-]+)?$
        example: http://ehealth.sundhed.dk/ssl-governance/v1/party/457
        description: Reference (by rest url) to the healthcare organisation responsible for paying for services. Typically this will be a high level organisation like a region or municipality
      buyer:
        type: array
        items:
          type: string
        #          pattern: ^((http[s]?):\/)?\/?([^:\/\s]+)((\/\w+)*\/)([\w\-\.]+[^#?\s]+)(.*)?(#[\w\-]+)?$
        example: ['http://ehealth.sundhed.dk/ssl-governance/v1/party/458', 'http://ehealth.sundhed.dk/ssl-governance/v1/party/459']
        description: References (by rest url) to the healthcare organisations ordering services. A contract can support multiple buyers (e.g. different hospitals or departments)
      reminderDays:
        type: integer
        format: int32
        description: Default number of days before an appointment with a patient where a reminder should be sent
        example: 30

  Order:
    type: object
    description: An order represents a request for items and services to be delivered to a recipient. The order is placed by a practioner and executed by a provider.
    allOf:
      - required:
          - status
          - buyer
          - receiver
      - $ref: '#/definitions/OrderBase'

  OrderBase:
    properties:
      id:
        type: string
        description: Globally unique ID of this order. Assigned by server.
      threadId:
        type: string
        description: Thread id for ehealth-messages for this order.
      identifiers:
        type: array
        description: Identifiers to connect Order to external content available in other frameworks or protocols.
        items:
          $ref: '#/definitions/Identifier'
      status:
        $ref: '#/definitions/OrderStatus'
      priority:
        type: boolean
        description: Shows if this order has high priority.
      notes:
        type: array
        description: Notes attached to the order by buyer or seller. These are intended to contain remarks or details about the fulfilment of the order
        example: [{'timestamp':'2020-01-01T00:00:00Z', 'authorName':'John Doe', 'authorOrganization':'Some organization', 'text':'Some note'}]
        items:
          $ref: '#/definitions/OrderNotes'
      buyer:
        type: string
        description: Reference to BuyerCustomerParty on behalf of which this order is placed.
        example: https://ehealth.sundhed.dk/ssl-governance/v1/party/313
      seller:
        type: string
        description: Reference to SellerSupplierParty which is responsible for supplying the items required to fulfil this order.
        example: https://ehealth.sundhed.dk/ssl-governance/v1/party/312
      sellerDeliveryContactEmail:
        type: string
        description: Email or a label
        example: viggo@somemail.com
      carePlanRef:
        type: string
        description: Reference to careplan.
        example: https://ehealth.sundhed.dk/careplan/fhir/CarePlan/15241
      carePlanTitle:
        type: string
        description: The title of the careplan. Automatically filled by the system based on carePlanRef.
        example: KOL
      earliestDeliveryDate:
        type: string
        format: date
        description: Earliest delivery date of order. Automatically filled by the system based on the agreedDate of unfulfilled order lines.
        example: '2020-01-01'
      latestDeliveryDate:
        type: string
        format: date
        description: Latest delivery date of order. Automatically filled by the system based on the agreedDate of unfulfilled order lines.
        example: '2020-02-02'
      receiver:
        $ref: '#/definitions/OrderReceiver'

  OrderReceiver:
    type: object
    description: Contact information of the recipient to whom the items and services in this order are to be delivered or picked-up.
    properties:
      name:
        type: string
      addressLine1:
        type: string
      addressLine2:
        type: string
      postalCode:
        type: string
      postalDistrict:
        type: string
      email:
        type: string
      phone:
        type: string
      patient:
        type: string
        # pattern: ^(?:http(s)?:\/\/)?[\w.-]+(?:\.[\w\.-]+)+[\w\-\._~:/?#[\]@!\$&'\(\)\*\+,;=.]+\/Patient/\d+$
        description: Reference to the corresponding ehealth-patient in the clinical domain. Pattern should be used - ^(?:http(s)?:\/\/)?[\w.-]+(?:\.[\w\.-]+)+[\w\-\._~:/?#[\]@!\$&'\(\)\*\+,;=.]+\/Patient/\d+$
        example: https://ehealth.sundhed.dk/patient/fhir/Patient/1566241

  OrderDetails:
    type: object
    description: An order details represent all information about order, order lines and trace lines related to this order.
    required:
      - order
    properties:
      order:
        $ref: '#/definitions/Order'
      orderLines:
        type: array
        description: Order lines information related to this order.
        items:
          $ref: '#/definitions/OrderLine'
      traceLines:
        type: array
        description: Trace lines information related to this order.
        items:
          $ref: '#/definitions/TraceLine'

  OrderLine:
    type: object
    description: An order represents a request for items and services to be delivered to a recipient. The order is placed by a practioner and executed by a provider.
    required:
      - order
      - status
    properties:
      id:
        type: string
        description: Globally unique ID of this order item. Assigned by server
      order:
        type: string
        description: Reference to order to which this order line belongs
        example: https://ssl-order.ehealth.sundhed.dk/v1/order/21
      status:
        $ref: '#/definitions/OrderLineStatus'
      item:
        type: string
        description: Reference to ordered catalog item
        example: https://ssl-catalogue.ehealth.sundhed.dk/v1/catalogue-item/14
      agreedDate:
        type: string
        format: date
        description: The date agreed between the seller and the receiver for the next delivery or pickup attempt or shipment to be made.
        example: '2020-01-01'
      device:
        type: object
        description: The actual device to be delivered or picked up. Only relevant when the fulfilment involves an actual device (opposed to delivery of a service).
        properties:
          externalId:
            type: string
            description: External id of the device
          identifiers:
            type: array
            description: Identifiers to connect Device instance to external content available in other frameworks or protocols.
            items:
              $ref: '#/definitions/Identifier'
          clinicalRef:
            type: string
            description: A reference to the corresponding Device resource in the FHIR-based clinical backend.
            #pattern: ^(?:http(s)?:\/\/)?[\w.-]+(?:\.[\w\.-]+)+[\w\-\._~:/?#[\]@!\$&'\(\)\*\+,;=.]+\/Device/\d+$
            example: https://ehealth.sundhed.dk/device/fhir/Device/1566241

  TraceLine:
    type: object
    description: A trace line documents a single atomic business event related to an order and optionally a number of order lines.
    required:
      - createdByOrganization
      - text
      - order
    properties:
      id:
        type: string
        description: Globally unique ID of this order item. Assigned by server
      timestamp:
        type: string
        format: date-time
        description: Date and time at which this trace line was created.
        example: '2020-01-01T00:00:00Z'
      createdByOrganization:
        type: string
        description: The name of the organization which created or directly caused this trace line.
      createdByUser:
        type: string
        description: The name of the user which created or directly caused this trace line.
      text:
        type: string
        description: A Danish-language human-readable text lines carrying the a description of what triggered this trace line.
      supplementaryText:
        type: string
        description: A supplementary Danish-language human-readable text lines carrying the a description of what triggered this trace line.
      order:
        type: string
        description: Reference to Order to which this trace line is related.
        example: https://ssl-order.ehealth.sundhed.dk/v1/order/21
      orderLine:
        type: string
        description: Reference to order line to which this trace line is related.
        example: https://ssl-order.ehealth.sundhed.dk/v1/order-line/21
      statusChange:
        $ref: '#/definitions/StatusChange'

  StatusChange:
    type: object
    description: StatusChange represents changes of status for order or order line.
    required:
      - oldStatus
      - newStatus
    properties:
      oldStatus:
        type: string
        description: Status of the resource immediately prior to the event which triggered this TraceLine.
      newStatus:
        type: string
        description: Status of the resource immediately after to the event which triggered this TraceLine.

  OrganizationReference:
    type: object
    description: OrganizationReference contains a reference to an organization.
    required:
      - organizationReference
    properties:
      organizationReference:
        type: string
        description: Reference to Organization.
        example: https://ehealth.sundhed.dk/organization/fhir/Organization/123

  Coding:
    type: object
    description: Coding system from clinical domain.
    required:
      - system
      - code
    properties:
      system:
        type: string
        format: uri
        description: A URI string referring the Identity of the terminology system
        example: http://ehealth.sundhed.dk/vs/device-measuring-quality
      code:
        type: string
        pattern: '[^\s]+([\s]?[^\s]+)*'
        description: Code value taken from a set of controlled strings defined in the system
        example: MEDIUM
      display:
        type: string
        readOnly: true
        description: Human-readable value taken from a set of controlled strings defined in the system
        example: Precision < 0.5kg

  Identifier:
    type: object
    description: A numeric or alphanumeric string that is associated with a single object or entity within a given system. Typically, identifiers are used to connect content in resources to external content available in other frameworks or protocols. Identifiers are associated with objects and may be changed or retired due to human or system process and errors.
    properties:
      system:
        type: string
        description: The namespace for the identifier value
        example: urn:ietf:rfc:3986
      value:
        type: string
        description: The value that is unique
        pattern: '^(?!\s*$).+'
        example: NUC8766
      assigner:
        type: string
        description: Organization that issued id (may be just text)
        example: Danish Health Authorities

  OrderNotes:
    type: object
    description: Notes attached to the order by buyer or seller. These are intended to contain remarks or details about the fulfilment of the order
    required:
      - text
    properties:
      timestamp:
        type: string
        format: date-time
      authorName:
        type: string
      authorOrganization:
        type: string
      text:
        type: string



  Error:
    type: object
    description: An business process error reported by the server.
    required:
      - id
      - time
      - message
    properties:
      id:
        type: string
        format: uuid
        description: Unique ID of this error
        example: e1f6678e-512c-11e9-8647-d663bd873d93
      time:
        type: string
        format: date-time
        description: Date and time this error occurred
        example: '2020-01-01T01:00:00Z'
      code:
        type: string
        format: string
        description: A protocol defined code allowing the client to understand the error and act appropriately
        example: ORD00125
      message:
        type: string
        format: string
        description: An English text describing the error in end-user terms
        example: Some server or client error
      technicalDetails:
        type: string
        format: string
        description: An detailed technical description of an internal, non-business error
        example: <A stack trace>

  OrderStatus:
    type: string
    enum:
      - DRAFT
      - SUBMITTED
      - ASSIGNED
      - VALIDATED
      - CONDITIONALLY_ACCEPTED
      - CONDITIONS_ACCEPTED
      - DECLINED
      - ACCEPTED
      - TIME_OF_FULFILLMENT_AGREED
      - FULFILLED
      - REVOKED

  OrderLineStatus:
    type: string
    enum:
      - UNFULFILLED
      - SUBMITTED
      - ACCEPTED
      - DELIVERYORPICKUPDATEAGREED
      - FULFILLED
      - FAILEDFULFILMENTDUETOCITIZEN
      - FAILEDFULFILMENTDUETOPROVIDER
      - RETURNED

  PatchRequest:
    description: A JSONPatch request
    type: array
    items:
      $ref: "#/definitions/PatchDocument"

  PatchDocument:
    description: A JSONPatch document as defined by RFC 6902
    required:
      - op
      - path
    properties:
      op:
        type: string
        description: The operation to be performed
        enum:
          - "add"
          - "remove"
          - "replace"
          - "move"
          - "copy"
          - "test"
      path:
        type: string
        description: A JSON-Pointer
      value:
        type: object
        description: The value to be used within the operations.
      from:
        type: string
        description: A string containing a JSON Pointer value.
