openapi: 3.0.2
info:
  title: API for Disability Assisance
  description: Disability Assistance Requirements and Summary
  version: 0.0.1
  contact:
    name: Te Whatu Ora
    email: integration@health.govt.nz
    url: https://tewhatuora.govt.nz  
  license:
    name: Creative Commons Zero v1.0 Universal
    url: http://spdx.org/licenses/CC0-1.0.html
servers:
  - url: https://fhir.api.digital.health.nz/R4
    description: Disability Assistance Requirements and Summary

tags:
  - name: default
    description: System Default endpoints
  - name: assistance-needs
    description: Medicines Data Repository RHIR
    
paths:
  /metadata:
    summary: Access to the Server's Capability Statement
    description: >-
      All FHIR Servers return a CapabilityStatement that describes what services
      they perform
    get:
      security: []
      summary: Return the server's capability statement
      description: CapabilityStatement
      tags:
        - default
      operationId: metadata
      responses:
        '200':
          description: the capability statement
          content:
            application/fhir+json:
              schema:
                description: >-
                  A Capability Statement documents a set of capabilities
                  (behaviors) of a FHIR Server or Client for a particular
                  version of FHIR that may be used as a statement of actual
                  server functionality or a statement of required or desired
                  server implementation.
                properties:
                  resourceType:
                    description: This is a CapabilityStatement resource
                  id:
                    description: >-
                      The logical id of the resource, as used in the URL for the
                      resource. Once assigned, this value never changes.
                    pattern: ^[A-Za-z0-9\-\.]{1,64}$
                    type: string
                type: object
                additionalProperties: false
                required:
                  - resourceType
        '401':
          $ref: '#/components/responses/UnauthorizedError'
        '404':
          $ref: '#/components/responses/NotFoundError'
        default:
          description: Error, with details
          content:
            application/fhir+json:
              schema:
                description: >-
                  A collection of error, warning, or information messages that
                  result from a system action.
                properties:
                  resourceType:
                    description: This is a OperationOutcome resource
                  id:
                    description: >-
                      The logical id of the resource, as used in the URL for the
                      resource. Once assigned, this value never changes.
                    pattern: ^[A-Za-z0-9\-\.]{1,64}$
                    type: string
                type: object
                additionalProperties: false
                required:
                  - issue
                  - resourceType
  /Condition:
    get:
      summary: Search for Condition
      description: Retrieve Assistance Needs bundle
      tags:
        - assistance-needs
      security:
        -  oauth2:
            - system/Condition.r      
      operationId: search-typeCondition
      parameters:
        # Headers
        - $ref: '#/components/parameters/X-Api-Key'
        - $ref: '#/components/parameters/X-Request-Context'
        
        # Query        
        - $ref: '#/components/parameters/format'
        - $ref: '#/components/parameters/pretty'
        - $ref: '#/components/parameters/summary'
        - $ref: '#/components/parameters/elements'
        - $ref: '#/components/parameters/count'
        - name: subject:identifier
          in: query
          description: Patient NHI Number
          schema:
            type: string
        - name: category
          in: query
          description: Search by condition category
          schema:
            type: string
        - name: code
          in: query
          description: Search by condition code
          schema:
            type: string          
      responses:
        '200':
          description: Successful response
          content:
            application/json:
              schema:
                type: array
                items:
                  $ref: '#/components/schemas/Bundle'
        '401':
          $ref: '#/components/responses/UnauthorizedError'
  /Condition/{rid}:
    get:
      summary: Retrieve Condition
      description: Retreive a specific assistance need
      operationId: readCondition
      tags:
        - assistance-needs
      security:
        -  oauth2:
            - system/Condition.r      
      parameters:
        # Headers
        - $ref: '#/components/parameters/X-Api-Key'
        - $ref: '#/components/parameters/X-Request-Context'

        # Query        
        - $ref: '#/components/parameters/rid'
        - $ref: '#/components/parameters/format'
        - $ref: '#/components/parameters/pretty'
      responses:
        '200':
          description: Successful response
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Condition'
        '401':
          $ref: '#/components/responses/UnauthorizedError'
        '404':
          $ref: '#/components/responses/NotFoundError'

components:
  parameters: 
    X-Api-Key:
      name: "x-api-key"
      in: "header"
      required: true
      schema:
        type: "string"
    X-Request-Context:
      name: "X-Request-Context"
      in: "header"
      required: false
      schema:
        type: "string"
    rid:
      name: rid
      in: path
      description: id of the resource (=Resource.id)
      required: true
      allowEmptyValue: false
      style: simple
      schema:
        type: string
    summary:
      name: _summary
      in: query
      description: Requests the server to return a designated subset of the resource
      allowEmptyValue: true
      style: form
      schema:
        type: string
        enum:
          - 'true'
          - text
          - data
          - count
          - 'false'
    format:
      name: _format
      in: query
      description: >-
        Specify alternative response formats by their MIME-types (when a client
        is unable to access accept: header)
      allowEmptyValue: true
      style: form
      schema:
        type: string
        format: mime-type
    pretty:
      name: _pretty
      in: query
      description: Ask for a pretty printed response for human convenience
      allowEmptyValue: true
      style: form
      schema:
          type: boolean
    elements:
      name: _elements
      in: query
      description: Requests the server to return a collection of elements from the resource
      allowEmptyValue: true
      style: form
      explode: false
      schema:
        type: array
        format: string
        items:
          format: string
    count:
      name: _count
      in: query
      description: >-
        The maximum number of search results on a page. The server is not bound
        to return the number requested, but cannot return more
      schema:
        type: number

  schemas:
    Bundle:
      description: A container for a collection of resources.
      properties:
        resourceType:
          description: This is a Bundle resource
      type: object
      additionalProperties: false
      required:
        - resourceType
    Condition:
      description: >-
        A clinical condition, problem, diagnosis, or other event, situation,
        issue, or clinical concept that has risen to a level of concern.
      properties:
        resourceType:
          description: This is a Condition resource
      type: object
      additionalProperties: false
      required:
        - subject
        - clinicalStatus
        - resourceType

  securitySchemes:
    X-Api-Key:
      type: "apiKey"
      name: "x-api-key"
      in: "header"
    oauth2:
      type: oauth2
      flows:
        authorizationCode:
          authorizationUrl: https://auth.integration.covid19.health.nz/oauth2/authorize
          tokenUrl: https://auth.integration.covid19.health.nz/oauth2/token
          scopes:
            system/Condition.r: Grant read access to Medicine resources

  responses:
    UnauthorizedError:
      description: Unauthorized
      content:
        application/json:
          schema:
            type: string
            example: Unauthorized access
    NotFoundError:
      description: Resource not found
      content:
        application/json:
          schema:
            type: string
            example: Resource not found
security:
  - oauth2: []
