> ## Documentation Index
> Fetch the complete documentation index at: https://developer.flabslis.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Create Pre-booking

> Create a pre-booking in the Flabs system with patient details and test/package information. This initiates the billing workflow.

## Overview

Create a pre-booking in the Flabs system to initiate the laboratory workflow. This endpoint accepts patient details and test/package information to start the billing process.

## Authentication

Requires a valid Bearer token from the [authentication API](/auth/endpoint/get_auth_token).

## Request Parameters

### Required Fields

| Field                        | Type    | Description                                                 |
| ---------------------------- | ------- | ----------------------------------------------------------- |
| `patient_details`            | object  | Patient information (required)                              |
| `patient_details.first_name` | string  | Patient's first name                                        |
| `patient_details.gender`     | string  | Patient's gender (`male`, `female`, `other`)                |
| `patient_details.age`        | integer | Patient's age                                               |
| `patient_details.age_type`   | string  | Age unit (`year`, `month`, `day`)                           |
| `integrator_id`              | string  | Your unique identifier for this booking                     |
| `lead_source`                | string  | Source of the booking (contact Flabs for available sources) |

### Test/Package Requirements

At least one of the following is required:

| Field                          | Type  | Description                                          |
| ------------------------------ | ----- | ---------------------------------------------------- |
| `mapped_tests`                 | array | Tests mapped with Flabs (use `flabs_id` or `id`)     |
| `unmapped_tests`               | array | Tests not mapped with Flabs                          |
| `mapped_packages`              | array | Packages mapped with Flabs (use `id` only)           |
| `unmapped_packages`            | array | Packages not mapped with Flabs                       |
| `unmapped_packages_with_tests` | array | Packages with associated tests not mapped with Flabs |

### Optional Fields

| Field                       | Type   | Description                                                     |
| --------------------------- | ------ | --------------------------------------------------------------- |
| `barCode`                   | string | Unique barcode identifier                                       |
| `patient_details.last_name` | string | Patient's last name                                             |
| `doctor`                    | string | Referring doctor ID (contact Flabs for the ID)                  |
| `hospital`                  | string | Referring hospital ID (contact Flabs for the ID)                |
| `rate_list_type`            | string | Rate list to apply for pricing (contact Flabs for valid values) |

## Important Notes

<Warning>
  * Patient details are mandatory with all required fields - At least one test
    or package array must be provided - Barcodes must be unique across the system
  * Contact Flabs team for available lead sources - Contact Flabs team for
    `doctor` / `hospital` IDs and valid `rate_list_type` values
</Warning>

<Note>
  * Use `flabs_id` or `id` for mapped tests - Only `id` is available for mapped
    packages (no `flabs_id`) - The `preBookingID` in the response is used to track
    the booking through the workflow
</Note>


## OpenAPI

````yaml POST /client/billing/create
openapi: 3.0.3
info:
  title: Billing API
  version: 1.0.0
  description: >-
    APIs for creating pre-bookings and managing the billing workflow in the
    Flabs system.
servers:
  - url: https://v2.flabs.in
    description: Production Server
security: []
paths:
  /client/billing/create:
    post:
      summary: Create pre-booking
      description: >-
        Create a pre-booking in the Flabs system with patient details and
        test/package information. This initiates the billing workflow.
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              properties:
                labID:
                  type: string
                  description: >-
                    Flabs lab (branch) identifier. Fetch the list of labs via
                    GET /client/labs.
                patient_details:
                  type: object
                  properties:
                    first_name:
                      type: string
                      description: Patient's first name
                    last_name:
                      type: string
                      description: Patient's last name (optional)
                    gender:
                      type: string
                      enum:
                        - male
                        - female
                        - other
                      description: Patient's gender
                    age:
                      type: integer
                      description: Patient's age
                    age_type:
                      type: string
                      enum:
                        - year
                        - month
                        - day
                      description: Age unit type
                  required:
                    - first_name
                    - gender
                    - age
                    - age_type
                integrator_id:
                  type: string
                  description: Your unique identifier for this booking
                unmapped_tests:
                  type: array
                  items:
                    type: string
                  description: Tests not mapped between your system and Flabs
                mapped_tests:
                  type: array
                  items:
                    type: object
                    properties:
                      flabs_id:
                        type: string
                        description: Flabs test identifier
                      id:
                        type: string
                        description: Alternative test identifier
                  description: Tests mapped with Flabs system
                mapped_packages:
                  type: array
                  items:
                    type: object
                    properties:
                      id:
                        type: string
                        description: Package identifier
                    required:
                      - id
                  description: Packages mapped with Flabs system
                unmapped_packages:
                  type: array
                  items:
                    type: string
                  description: Packages not mapped between your system and Flabs
                unmapped_packages_with_tests:
                  type: array
                  items:
                    type: object
                    properties:
                      package_name:
                        type: string
                        description: Name of the unmapped package
                      tests:
                        type: array
                        items:
                          type: string
                        description: List of tests associated with this package
                    required:
                      - package_name
                      - tests
                  description: >-
                    Packages with associated tests not mapped between your
                    system and Flabs
                lead_source:
                  type: string
                  description: >-
                    Source of the lead (contact Flabs team for available
                    sources)
                barCode:
                  type: string
                  description: Optional barcode (must be unique)
              required:
                - labID
                - patient_details
                - integrator_id
                - lead_source
            example:
              labID: your_flabs_lab_id
              patient_details:
                first_name: name
                last_name: surname
                gender: male
                age: 24
                age_type: year
              integrator_id: your_unique_integrator_id
              unmapped_tests:
                - unmapped test name
              mapped_tests:
                - flabs_id: FLABSTESTID
                - id: test_id
              mapped_packages:
                - id: package_id
              unmapped_packages:
                - unmapped package name
              unmapped_packages_with_tests:
                - package_name: package name
                  tests:
                    - test name 1
                    - test name 2
              lead_source: <lead source>
      responses:
        '201':
          description: Pre-booking created successfully
          content:
            application/json:
              schema:
                type: object
                properties:
                  success:
                    type: boolean
                    example: true
                  message:
                    type: string
                    example: Booking created successfully
                  integrator_id:
                    type: string
                    description: Your unique integrator ID
                  preBookingID:
                    type: string
                    description: Flabs pre-booking identifier
              example:
                success: true
                message: Booking created successfully
                integrator_id: your_unique_integrator_id
                preBookingID: pre_booking_id
        4XX:
          description: Error response
          content:
            application/json:
              schema:
                type: object
                properties:
                  success:
                    type: boolean
                    example: false
                  status:
                    type: integer
                  message:
                    type: string
                  error:
                    type: object
                    properties:
                      details:
                        type: string
              example:
                success: false
                status: 400
                message: Bad Request
                error:
                  details: Barcode already exists or invalid request data
        5XX:
          description: Error response
          content:
            application/json:
              schema:
                type: object
                properties:
                  success:
                    type: boolean
                    example: false
                  status:
                    type: integer
                  message:
                    type: string
                  error:
                    type: object
                    properties:
                      details:
                        type: string
              example:
                success: false
                status: 500
                message: Internal Server Error
                error:
                  details: An unexpected error occurred
      security:
        - bearerAuth: []
components:
  securitySchemes:
    bearerAuth:
      type: http
      scheme: bearer
      bearerFormat: JWT
      description: JWT token obtained from the authentication endpoint

````