The B2B (Business-to-Business) feature allows organizations to register patients under their entity, manage their usage limits, and enable them to book appointments without direct payment (or with special payment handling). This report details the B2B flow, its integration with the rest of the system, and the payment process, using user stories and ASCII diagrams.
- Coordinator: Admin user who creates and manages B2B patients.
- B2B Patient: End-user registered under a business entity.
- System: Backend and frontend services.
- Doctor: Healthcare provider.
- Payment Gateway: Handles payment processing (e.g., Moyasar).
+----------------+ +----------------+ +------------------+
| Coordinator | | System | | B2B Patient |
+----------------+ +----------------+ +------------------+
| | |
|---[1. Create B2B Patient]| |
|------------------------->| |
| |---[2. Send Credentials]-->|
| | |
| |<--[3. Login/Access]-------|
| | |
| |---[4. Book Appointment]-->|
| | |
| |---[5. Payment Handling]-->|
| | |
| |---[6. Usage Limit Check]--|
| | |
| |---[7. Appointment Flow]-->|
| | |
Goal: Register a new B2B patient with a usage limit.
- Coordinator navigates to the B2B patient management page.
- Coordinator fills in patient details: name, email, phone, usage limit.
- Coordinator submits the form.
- System validates input (
/packages/client/src/inputs/btob-patients.ts). - System creates the B2B patient and generates credentials (
/packages/client/src/outputs/create-b2-b-patient.ts). - System returns credentials to the coordinator.
Coordinator
|
|--[Fill B2B Patient Form]--> System
|<--[Validation/Success]-----|
|--[Receive Credentials]-----|
As a coordinator, I want to create a B2B patient with a usage limit so that the organization can control the number of appointments the patient can book.
Goal: Access the platform using credentials.
- B2B Patient receives credentials.
- B2B Patient logs in via the platform.
- System authenticates and identifies user as
userType: 'B2B'.
B2B Patient
|
|--[Login with Credentials]--> System
|<--[Authenticated Session]---|
As a B2B patient, I want to log in using my credentials so I can access the platform and book appointments.
Goal: Book an appointment using the organization's quota.
- B2B Patient navigates to appointment booking.
- System identifies user as B2B and displays available specialties.
- B2B Patient selects a specialty and time slot.
- System checks usage limit (
usageLimitin/packages/client/src/outputs/get-b2-b-patient.ts). - If usage limit > 0: Allow booking.
- If usage limit == 0: Show error, block booking.
B2B Patient
|
|--[Book Appointment]--------> System
|--[Select Specialty/Time]--->|
|<--[Check Usage Limit]-------|
| |--[usageLimit > 0]------>|
| |<--[Allow Booking]-------|
| |--[usageLimit == 0]----->|
| |<--[Block Booking]-------|
As a B2B patient, I want to book an appointment using my organization's quota, so I don't have to pay directly.
Goal: Integrate payment logic for B2B patients.
- System detects
userType: 'B2B'during booking. - System skips or customizes payment step (e.g., no payment, or internal billing).
- System decrements
usageLimitafter successful booking. - System records the appointment.
System
|
|--[Detect B2B User]----------|
|--[Skip/Customize Payment]---|
|--[Decrement usageLimit]-----|
|--[Record Appointment]-------|
As a system, I want to handle payment differently for B2B patients so that they are not charged directly, and their usage is tracked against their quota.
Goal: See remaining quota.
- B2B Patient views profile.
- System displays
usageLimitand organization name (/apps/patients/src/app/components/header/profile-card.tsx).
B2B Patient
|
|--[View Profile]------------> System
|<--[Show usageLimit/org]-----|
As a B2B patient, I want to see my remaining usage limit so I know how many appointments I can still book.
Goal: View and manage all B2B patients.
- Coordinator lists B2B patients (
/packages/client/src/outputs/list-b2-b-patients.ts). - Coordinator can search, sort, and paginate.
- Coordinator can update or delete B2B patients.
Coordinator
|
|--[List/Search/Sort]--------> System
|<--[Paginated Results]-------|
|--[Update/Delete]----------->|
|<--[Success/Error]-----------|
As a coordinator, I want to view, search, and manage B2B patients so I can maintain accurate records and control access.
- File:
/packages/client/src/api/payments.ts - Schema:
/packages/client/src/inputs/payments.ts - B2B Logic: For B2B, the payment step is either skipped or handled via internal billing (not via the public payment API).
- Component:
/apps/patients/src/app/components/booking/payment-card.tsx - Logic: If
userType !== 'B2B', show payment details. For B2B, this is hidden or replaced with a message.
if (identity.userType !== 'B2B') {
show <PriceLine value={fee} />
} else {
// Hide or show "Paid by organization"
}
- On Booking: Before confirming, system checks
usageLimit. - On Success: Decrement
usageLimitfor the B2B patient. - On Failure: Block booking and show error.
- User Type Propagation:
userType: 'B2B'is set at login and used throughout the app to control UI and logic. - Profile Card: Shows organization and usage limit for B2B users.
- Booking Flow: Payment and quota logic branches based on user type.
- Coordinator Tools: CRUD for B2B patients, usage tracking.
+-------------------+ +-------------------+ +-------------------+
| B2C Patient | | System | | Payment Gateway |
+-------------------+ +-------------------+ +-------------------+
| | |
|--[Book Appointment]----->| |
| |--[Show Payment UI]------->|
| |<--[Process Payment]-------|
|<--[Booking Confirmed]----| |
+-------------------+ +-------------------+ +-------------------+
| B2B Patient | | System | | Payment Gateway |
+-------------------+ +-------------------+ +-------------------+
| | |
|--[Book Appointment]----->| |
| |--[Check usageLimit]-------|
| |--[Skip Payment UI]--------|
| |--[Decrement usageLimit]---|
|<--[Booking Confirmed]----| |
-
B2B Patient Creation:
/packages/client/src/inputs/btob-patients.ts
/packages/client/src/outputs/create-b2-b-patient.ts -
B2B Patient Listing:
/packages/client/src/outputs/list-b2-b-patients.ts -
Profile Card (UI):
/apps/patients/src/app/components/header/profile-card.tsx -
Payment Handling:
/apps/patients/src/app/components/booking/payment-card.tsx
/apps/patients/src/app/hooks/use-payment-info.ts -
Booking Flow:
/apps/patients/src/app/routes/booking/book-appointment.tsx
/apps/patients/src/app/components/booking/specialty-selection-card.tsx
| Actor | Action | System Behavior (B2B) | Payment Handling | Usage Limit |
|---|---|---|---|---|
| Coordinator | Create B2B Patient | Registers, sets usage limit | N/A | Set |
| B2B Patient | Book Appointment | Checks usage, skips payment | Skipped/Custom | Decrement |
| B2B Patient | View Profile | Shows org & usage limit | N/A | Display |
| Coordinator | List/Manage Patients | CRUD, search, paginate | N/A | Manage |
The B2B flow is tightly integrated into the Virtual Care platform, affecting authentication, booking, payment, and user management. The system uses the userType field to branch logic and UI, ensuring B2B patients are handled according to their organization's agreement, with usage limits enforced and payment steps customized or skipped.
End of Report