.yaml

openapi: 3.0.0
info:
  title: Vienotais pieraksts API
  version: v1
  description: API for managing calendar availability, bookings, services, and medical specialists.

servers: [] # You can add server URLs here if needed

paths:
  /availability:
    post:
      summary: Get specialist availability for a specific date, institution, and service.
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/CalendarQuery'
      responses:
        '200':
          description: Successful response with specialist availability information.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/SpecialistAvailability'
        '400':
          description: Invalid request parameters.
          # You might want to define a specific error schema here
        '500':
          description: Internal server error.
          # You might want to define a specific error schema here
  /bookings:
    post:
      summary: Create a new booking.
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/BookingRequest'
      responses:
        '201':
          description: Booking successfully created.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/BookingResponse'
        '400':
          description: Invalid request parameters.
          # You might want to define a specific error schema here
        '500':
          description: Internal server error.
          # You might want to define a specific error schema here
  /bookings/cancel:
    post:
      summary: Cancel an existing booking.
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/CancelAppointmentRequest'
      responses:
        '200':
          description: Appointment successfully cancelled.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/CancelAppointmentResponse'
        '400':
          description: Invalid request parameters.
          # You might want to define a specific error schema here
        '404':
          description: Appointment not found.
          # You might want to define a specific error schema here
        '500':
          description: Internal server error.
          # You might want to define a specific error schema here
  /services:
    get:
      summary: Get a list of services.
      responses:
        '200':
          description: Successful response with a list of services.
          content:
            application/json:
              schema:
                type: array
                items:
                  $ref: '#/components/schemas/ServiceEntry'
        '500':
          description: Internal server error.
          # You might want to define a specific error schema here
  /institutions:
    get:
      summary: Get a list of medical institutions with their branches.
      responses:
        '200':
          description: Successful response with a list of medical institutions and branches.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/MedicalInstitutionWithBranches'
        '500':
          description: Internal server error.
          # You might want to define a specific error schema here
  /specialists:
    get:
      summary: Get a list of specialists.
      responses:
        '200':
          description: Successful response with a list of specialists.
          content:
            application/json:
              schema:
                type: array
                items:
                  $ref: '#/components/schemas/Specialist'
        '500':
          description: Internal server error.
          # You might want to define a specific error schema here

components:
  schemas:
    CalendarQuery:
      type: object
      required:
        - dateFrom
        - institutionCode
        - serviceCode
      properties:
        dateFrom:
          type: string
          format: date
          description: Datums no kura sākt kalendāra datu izgūšanu (formātā DD.MM.YYYY)
          example: "2025-05-01"
        institutionCode:
          type: string
          description: Ārstniecības iestādes kods, kuras kalendāru jāizgūst
          example: "HOSP001"
        serviceCode:
          type: string
          description: Pakalpojuma kods, kuram jāattēlo pieejamie speciālisti un laiki
          example: "CONSULT"
        serviceType:
          type: ["string", "null"]
          description: Pakalpojuma veids (piem., "OnPremises" vai "Remote"). Var būt null, ja netiek filtrēts
          example: "OnPremises"
    SpecialistAvailability:
      type: object
      properties:
        selectedInstitution:
          type: ["string", "null"]
          description: Atlasītās iestādes identifikators
          example: "HOSP001"
        selectedService:
          type: ["string", "null"]
          description: Atlasītais pakalpojums
          example: "CONSULT"
        selectedSpecialists:
          type: array
          description: Atlasīto speciālistu saraksts
          items:
            type: object
            # Add properties if you know the structure of a selected specialist
        otherSpecialists:
          type: array
          description: Citu pieejamo speciālistu saraksts
          items:
            type: object
            required:
              - institutionCode
              - institutionDisplayName
              - institutionAddress
              - institutionBranchCode
              - parentInstitutionCode
              - displayName
              - specialistCode
              - specialityCode
              - specialityDisplayName
              - gender
              - timeSlots
              - dateFrom
              - externalId
              - type
              - services
              - isDirectAccessSpecialist
              - creationDate
              - releaseDate
            properties:
              institutionCode:
                type: string
                description: Medicīnas iestādes kods
                example: "CLIN005"
              institutionDisplayName:
                type: string
                description: Medicīnas iestādes nosaukums
                example: "Veselības Centrs 1"
              institutionAddress:
                type: string
                description: Iestādes adrese
                example: "Brīvības iela 10, Rīga"
              institutionBranchCode:
                type: string
                description: Filiāļu kodi
                example: "BRANCH01"
              parentInstitutionCode:
                type: string
                description: Galvenās iestādes kods
                example: "HOSP001"
              displayName:
                type: string
                description: Ārsta vārds, uzvārds
                example: "Dr. Jānis Bērziņš"
              specialistCode:
                type: string
                description: Ārsta ID
                example: "SPEC001"
              specialityCode:
                type: string
                description: Specialitātes kods
                example: "THERAP"
              specialityDisplayName:
                type: string
                description: Specialitātes nosaukums
                example: "Terapeits"
              description:
                type: string
                description: Papildu apraksts
                example: "Prakse Rīgas centrā."
              gender:
                type: integer
                description: Dzimums (0 – nenoteikts/nezināms, 1 – vīrietis, 2 – sieviete)
                example: 1
              languages:
                type: array
                items:
                  type: string
                description: Speciālista valodu saraksts
                example: ["lv", "ru"]
              timeSlots:
                type: object
                description: Pieejamie laiki pēc datuma
                additionalProperties:
                  type: array
                  items:
                    type: object
                    required:
                      - dateFrom
                      - externalId
                      - type
                      - services
                      - isDirectAccessSpecialist
                      - creationDate
                      - releaseDate
                    properties:
                      dateFrom:
                        type: string
                        format: date-time
                        description: Laika loga sākuma datums un laiks
                        example: "2025-05-02T10:00:00Z"
                      externalId:
                        type: string
                        description: Ārējais laika loga identifikators
                        example: "SLOT123"
                      type:
                        type: string
                        description: Laika veids (piemēram, maksas/valsts)
                        example: "valsts"
                      services:
                        type: array
                        items:
                          type: object
                          properties:
                            displayName:
                              type: string
                              example: "Konsultācija"
                            code:
                              type: string
                              example: "CONSULT"
                            type:
                              type: integer
                              example: 1
                        description: Laika logam piesaistītie pakalpojumi
                      serviceTypes:
                        type: array
                        items:
                          type: integer
                        description: Pakalpojumu tipu kodi
                        example: [1, 2]
                      isDirectAccessSpecialist:
                        type: boolean
                        description: Norāda, vai TPS pakalpojums
                        example: true
                      directAccessSpecialistDG:
                        type: ["boolean", "null"]
                        description: Norāda, vai TPS pakalpojumam nepieciešams apliecinājums par dg
                        example: false
                      creationDate:
                        type: string
                        format: date-time
                        description: Laika loga izveides datums
                        example: "2025-04-30T09:00:00Z"
                      releaseDate:
                        type: string
                        format: date-time
                        description: Laika loga publicēšanas datums
                        example: "2025-04-30T09:30:00Z"
              nextAvailability:
                type: object
                description: Nākamais pieejamais laiks
                properties:
                  dateFrom:
                    type: string
                    format: date-time
                    example: "2025-05-03T11:00:00Z"
                  type:
                    type: string
                    example: "valsts"
    BookingRequest:
      type: object
      required:
        - slotId
        - patientId
        - contactPhone
        - contactEmail
        - serviceId
        - fundingType
      properties:
        slotId:
          type: string
          description: Izvēlētā laika slota ID
          example: "slot-12345"
        patientId:
          type: string
          description: Pacienta unikālais identifikators
          example: "patient-67890"
        contactPhone:
          type: string
          description: Pacienta telefona numurs
          example: "+37122334455"
        contactEmail:
          type: string
          format: email
          description: Pacienta e-pasta adrese
          example: "patient@example.com"
        serviceId:
          type: string
          description: Pakalpojuma ID, kuram pierakstās
          example: "service-abcde"
        fundingType:
          type: string
          enum:
            - state
            - private
          description: "\"state\" (valsts apmaksāts) vai \"private\" (maksas)"
          example: "state"
        basedOn:
          type: string
          description: Nosūtījuma ID, ja pieraksts tiek veikts ar nosūtījumu
          example: "referral-fghij"
        isDirectAccessSpecialist:
          type: string
          enum:
            - "direct-access"
          description: Ja TPS pakalpojums, vērtība \"direct-access\"
          example: "direct-access"
        directAccessSpecialistDG:
          type: boolean
          description: Ja TPS pakalpojums prasa apliecinājumu par diagnozi – obligāti true
          example: true
        note:
          type: string
          description: Brīvs komentārs pie pieraksta
          example: "Lūdzu zvanīt stundu pirms vizītes."
        paperReferral:
          type: object
          description: Papīra nosūtījuma fails (Attachment formātā)
          properties:
            contentType:
              type: string
              description: Faila MIME tips (piemēram, application/pdf)
              example: "application/pdf"
            data:
              type: string
              description: Faila saturs base64 kodējumā
              example: "JVBERi0xLjUKJcKl..."
            fileName:
              type: string
              description: Faila nosaukums
              example: "nosutijums.pdf"
          required:
            - contentType
            - data
            - fileName
    BookingResponse:
      type: object
      required:
        - appointmentId
        - status
      properties:
        appointmentId:
          type: string
          description: Izveidotā pieraksta ID
          example: "appointment-123"
        status:
          type: string
          enum:
            - booked
          description: Statuss – 'booked', ja pieraksts veiksmīgi izveidots
          example: "booked"
    ServiceEntry:
      type: object
      required:
        - code
        - name
        - isActive
        - level
        - parent
        - isTPS
        - needsDG
        - dateActiveFrom
        - sequence
      properties:
        code:
          type: string
          description: "Pakalpojuma kods. No klasifikatora: 1.3.6.1.4.1.38760.2.nnn"
          example: "1.3.6.1.4.1.38760.2.100"
        name:
          type: string
          description: Pakalpojuma nosaukums attēlošanai portālā
          example: "Ģimenes ārsta konsultācija"
        description:
          type: string
          description: Apraksts
          example: "Primārā aprūpes konsultācija pie ģimenes ārsta."
        isActive:
          type: boolean
          description: Ir aktuāls
          example: true
        level:
          type: integer
          description: Ieraksta līmenis
          example: 1
        parent:
          type: string
          description: Ieraksts kuram pieder konkrētais pakalpojums
          example: "1.3.6.1.4.1.38760.2"
        isDirectAccessSpecialist:
          type: boolean
          description: Ir tiešās pieejamības pakalpojums
          example: false
        directAccessSpecialistDG:
          type: boolean
          description: Pazīme vai nepieciešams apliecinājums par dg, ja TPS
          example: false
        dateActiveFrom:
          type: string
          format: date-time
          description: Datums no kura pakalpojums ir aktīvs
          example: "2023-01-01T00:00:00Z"
        dateActiveTill:
          type: ["string", "null"]
          format: date-time
          description: Datums līdz kuram pakalpojums ir aktīvs
          example: null
        sequence:
          type: integer
          description: Sequences numurs pakalpojumam
          example: 1
    MedicalInstitutionWithBranches:
      type: array
      items:
        type: object
        required:
          - branchCode
          - branchName
          - id
          - code
          - name
          - address
          - dateActiveFrom
        properties:
          branchCode:
            type: string
            description: Filiāles kods medicīnas iestādei
            example: "BRANCH01"
          branchName:
            type: string
            description: Filiāles nosaukums
            example: "Rīgas filiāle"
          id:
            type: string
            description: Unikāls identifikators – medicīnas iestādes ID + filiāles kods
            example: "HOSP001-BRANCH01"
          code:
            type: string
            description: Medicīnas iestādes kods
            example: "HOSP001"
          name:
            type: string
            description: Medicīnas iestādes nosaukums
            example: "Veselības Centrs 1"
          address:
            type: string
            description: Adrese, kur atrodas iestāde vai filiāle
            example: "Brīvības iela 10, Rīga"
          dateActiveFrom:
            type: string
            format: date-time
            description: Datums no kura ieraksts ir aktīvs
            example: "2024-01-15T00:00:00Z"
          dateActiveTill:
            type
            ```