Frontend Migration Guide: Careplan → Prescription
Overview
This document provides a comprehensive guide for the frontend team to update legacy and new apps with the careplan → prescription terminology changes. All backend APIs, routes, parameters, and responses have been updated to use "prescription" terminology.
Important: This migration affects ALL frontend applications (legacy and new) that interact with prescription/careplan functionality.
🚨 CRITICAL CHANGES SUMMARY
1. API Route Changes
Core API Endpoints
# OLD ROUTES (NO LONGER WORK)
- POST /api/v1/careplans
- GET /api/v1/careplans/:id
- PUT /api/v1/careplans/:id
- DELETE /api/v1/careplans/:id
- GET /api/v1/careplans
# NEW ROUTES (UPDATED)
+ POST /api/v1/prescriptions
+ GET /api/v1/prescriptions/:id
+ PUT /api/v1/prescriptions/:id
+ DELETE /api/v1/prescriptions/:id
+ GET /api/v1/prescriptionsNested Resource Routes
# Medicine Routes
- POST /api/v1/careplans/:id/medicines
- PUT /api/v1/careplans/:id/medicines/:medicine_id
+ POST /api/v1/prescriptions/:id/medicines
+ PUT /api/v1/prescriptions/:id/medicines/:medicine_id
# Complaint Routes
- POST /api/v1/careplans/:id/complaints
- PUT /api/v1/careplans/:id/complaints/:complaint_id
+ POST /api/v1/prescriptions/:id/complaints
+ PUT /api/v1/prescriptions/:id/complaints/:complaint_id
# Test Routes
- POST /api/v1/careplans/:id/tests
- PUT /api/v1/careplans/:id/tests/:test_id
+ POST /api/v1/prescriptions/:id/tests
+ PUT /api/v1/prescriptions/:id/tests/:test_id
# Procedure Routes
- POST /api/v1/careplans/:id/procedures
- PUT /api/v1/careplans/:id/procedures/:procedure_id
+ POST /api/v1/prescriptions/:id/procedures
+ PUT /api/v1/prescriptions/:id/procedures/:procedure_id
# Diet & Advice Routes
- POST /api/v1/careplans/:id/diets
- POST /api/v1/careplans/:id/advices
+ POST /api/v1/prescriptions/:id/diets
+ POST /api/v1/prescriptions/:id/advicesTemplate Routes
- GET /api/v1/careplan_templates
- POST /api/v1/careplan_templates
- PUT /api/v1/careplan_templates/:id
+ GET /api/v1/prescription_templates
+ POST /api/v1/prescription_templates
+ PUT /api/v1/prescription_templates/:idClinic-specific Routes
- GET /api/v1/clinics/:clinic_id/careplans
- POST /api/v1/clinics/:clinic_id/patients/:patient_id/previous_careplan
+ GET /api/v1/clinics/:clinic_id/prescriptions
+ POST /api/v1/clinics/:clinic_id/patients/:patient_id/previous_prescription2. Request Parameter Changes
Main Request Body Parameters
# Prescription Creation/Update
{
- "careplan_details": {
+ "prescription_details": {
"complaints": [...],
"medicines": [...],
"tests": [...],
"procedures": [...],
"advice": "...",
"diet": "...",
"diagnosis": "...",
"notes": "...",
"is_final": true,
"next_visit_value": 7,
"next_visit_units": "DAYS"
}
}ID Parameter Changes
# In request bodies and query parameters
- careplan_id: 123
+ prescription_id: 123
# URL parameters automatically change with routes
- /careplans/:careplan_id/medicines
+ /prescriptions/:prescription_id/medicinesTemplate Parameters
{
- "careplan_template": {
+ "prescription_template": {
"name": "Template Name",
"medicines": [...],
"tests": [...]
}
}3. Response JSON Structure Changes
Main Response Objects
# Prescription Response
{
"type": "show",
"message": "prescription saved",
"records": {
- "careplan": {
+ "prescription": {
"id": 123,
"doctor_id": 456,
"patient_id": 789,
"clinic_patient_id": 101,
"is_final": true,
"diagnosis": "...",
"advice": "...",
"diet": "...",
"notes": "...",
"created_at": "2024-01-01T00:00:00.000Z",
"updated_at": "2024-01-01T00:00:00.000Z",
// Associated objects also renamed
- "careplan_medicines": [...],
- "careplan_complaints": [...],
- "careplan_tests": [...],
- "careplan_procedures": [...],
- "careplan_advices": [...],
- "careplan_diets": [...]
+ "prescription_medicines": [...],
+ "prescription_complaints": [...],
+ "prescription_tests": [...],
+ "prescription_procedures": [...],
+ "prescription_advices": [...],
+ "prescription_diets": [...]
}
}
}List Response Format
{
"type": "index",
"message": "prescriptions fetched",
"records": {
- "careplans": [
+ "prescriptions": [
{
"id": 123,
// ... prescription object
}
]
}
}Previous Prescription Response
{
"type": "show",
"message": "prescription fetched",
"records": {
"event_id": 456,
"event_type": "Appointment",
- "careplan": {
+ "prescription": {
// ... prescription object
}
}
}4. Database Field Changes (Important for Filters)
Foreign Key Column Names
# When building filters or queries that reference DB columns
- careplan_id
+ prescription_id
# This affects filter parameters in APIs
- ?filter[careplan_id]=123
+ ?filter[prescription_id]=123Table Names (for advanced filtering)
# If directly referencing table names in any queries
- careplans
- careplan_medicines
- careplan_complaints
- careplan_tests
- careplan_procedures
- careplan_advices
- careplan_diets
+ prescriptions
+ prescription_medicines
+ prescription_complaints
+ prescription_tests
+ prescription_procedures
+ prescription_advices
+ prescription_diets5. Push Notifications & Real-time Updates
Pusher Channel Names
# Prescription-related pusher channels
- prescription_attached_{clinic_id}
+ prescription_attached_{clinic_id}
- prescription_pdf_generated_{clinic_id}
+ prescription_pdf_generated_{clinic_id}
# Note: Channel names already used 'prescription' so minimal changes herePush Notification Event Types
# Mobile push notification types (PRESERVED for backward compatibility)
# These were NOT changed to avoid breaking existing mobile apps
- "appointment.careplan_added" (KEPT AS-IS)
- "prescription.pdf_generated" (KEPT AS-IS)
# The notification content/keys remain the same for compatibilitySilent Notification Payloads
# Silent notification data structure
{
"event_type": "prescription.pdf_generated",
"data": {
- "careplan_id": 123,
+ "prescription_id": 123,
"appointment_id": 456,
"doctor_name": "Dr. Smith",
"clinic_name": "Clinic ABC"
}
}6. SMS Message References
SMS Template Updates
Most SMS templates remain unchanged as they reference generic terms. However, any SMS content that specifically mentioned "careplan" has been updated to "prescription" in the backend.
SMS Service Configuration
# SMS service type identifiers
- send_careplan_sms (setting name preserved for backward compatibility)
+ Still uses send_careplan_sms in database
# Message type identifiers
- "send_careplan"
+ "send_prescription"7. File Upload & Document Management
Document Type References
# When uploading or referencing prescription documents
- document_type: "CAREPLAN"
+ document_type: "PRESCRIPTION"
# File naming patterns
- "careplan_12345.pdf"
+ "prescription_12345.pdf"Medical Record Types
{
"medical_record_details": {
- "record_type": "CAREPLAN",
+ "record_type": "PRESCRIPTION",
"record_date": "2024-01-01",
"related_practice": "Dr. Smith"
}
}8. State Management & Local Storage
Local Storage Keys
# Update any localStorage or sessionStorage keys
- "selectedCareplan"
- "careplanDraft"
- "careplanTemplates"
+ "selectedPrescription"
+ "prescriptionDraft"
+ "prescriptionTemplates"Redux/State Management
# State object structures
const state = {
- careplans: {
- list: [],
- selected: null,
- templates: []
- }
+ prescriptions: {
+ list: [],
+ selected: null,
+ templates: []
+ }
}
# Action types
- 'FETCH_CAREPLANS_SUCCESS'
- 'CREATE_CAREPLAN_SUCCESS'
- 'UPDATE_CAREPLAN_SUCCESS'
+ 'FETCH_PRESCRIPTIONS_SUCCESS'
+ 'CREATE_PRESCRIPTION_SUCCESS'
+ 'UPDATE_PRESCRIPTION_SUCCESS'9. Form Validation & Error Handling
Validation Error Keys
# Error response format remains similar, but field names updated
{
"errors": {
- "careplan_complaints": ["is missing"],
- "careplan_details": {
+ "prescription_complaints": ["is missing"],
+ "prescription_details": {
"complaints": ["can't be blank"],
"diagnosis": ["is too long"]
}
}
}Form Field Names
# HTML form field names
- name="careplan[diagnosis]"
- name="careplan[advice]"
- name="careplan[diet]"
- name="careplan[notes]"
+ name="prescription[diagnosis]"
+ name="prescription[advice]"
+ name="prescription[diet]"
+ name="prescription[notes]"10. URL Patterns & Routing
Frontend Route Patterns
# Frontend application routes should be updated
- /cms/careplan/new
- /cms/careplan/:id/edit
- /cms/careplan/:id/view
- /cms/careplan/templates
- /cms/careplan/:id/:patient_id/queue?did=:doctor_id
+ /cms/prescription/new
+ /cms/prescription/:id/edit
+ /cms/prescription/:id/view
+ /cms/prescription/templates
+ /cms/prescription/:id/:patient_id/queue?did=:doctor_idQueue Management Routes (Testing Route)
# Prescription queue management routes
- /cms/careplan/:prescription_id/:patient_id/queue?did=:doctor_id
+ /cms/prescription/:prescription_id/:patient_id/queue?did=:doctor_id
# Example for testing:
# OLD: /cms/careplan/28/21/queue?did=8
# NEW: /cms/prescription/28/21/queue?did=8 ✅ (READY TO TEST)Deep Link Patterns
# Patient app deep links
- kulcare://careplan/:id
- kulcare://careplan/share/:token
+ kulcare://prescription/:id
+ kulcare://prescription/share/:token🛠️ IMPLEMENTATION CHECKLIST
Phase 1: Critical API Updates (MUST DO FIRST)
- Update all API endpoint URLs from
/careplansto/prescriptions - Update all request parameter names:
careplan_details→prescription_details - Update all response object parsing:
careplan→prescription - Update all associated object arrays:
careplan_medicines→prescription_medicines
Phase 2: State Management Updates
- Update Redux/state management object keys
- Update action creators and action types
- Update selectors and reducers
- Update local storage keys
Phase 3: UI & Form Updates
- Update form field names
- Update validation error handling
- Update route patterns
- Update component props and variable names
Phase 4: Real-time & Notifications
- Update Pusher channel listeners (if any channel names changed)
- Update push notification payload parsing
- Update silent notification data structure handling
Phase 5: Document & File Handling
- Update document type references
- Update file naming patterns
- Update medical record type handling
⚠️ BACKWARD COMPATIBILITY NOTES
What Was Preserved (NO CHANGES NEEDED)
- Push notification event types:
appointment.careplan_addedremains unchanged - SMS database settings:
send_careplan_smssetting name preserved - System log constants: Audit trail keys remain as
CAREPLAN_*
Breaking Changes (MUST UPDATE)
- All API routes: Complete change from
/careplansto/prescriptions - All request/response JSON: Object keys changed from
careplantoprescription - All associated model arrays:
careplan_medicines→prescription_medicines - All foreign key references:
careplan_id→prescription_id
🧪 TESTING REQUIREMENTS
API Integration Tests
- Test all prescription CRUD operations
- Test all nested resource operations (medicines, complaints, etc.)
- Test template operations
- Test clinic-specific prescription operations
- Test error handling with new error keys
UI/UX Tests
- Test form submissions with new parameter names
- Test data display with new response structure
- Test routing with updated URL patterns
- Test real-time updates (Pusher/WebSocket)
Queue Management Route Testing (PRIORITY)
# Test Route: /cms/prescription/28/21/queue?did=8
# This route should work after frontend updates
# Expected API calls from this route:
- GET /api/v1/prescriptions/28 # Fetch prescription details
- GET /api/v1/prescriptions/28/medicines # Fetch prescription medicines
- GET /api/v1/prescriptions/28/tests # Fetch prescription tests
- GET /api/v1/clinic_patients/21 # Fetch patient details
- Any queue management API calls should use prescription_id=28
# Required Frontend Updates for this route:
1. Update route definition: careplan → prescription
2. Update API calls: /careplans/ → /prescriptions/
3. Update state management: careplan → prescription
4. Update component props: careplanId → prescriptionId
5. Update local storage keys if anyTesting Checklist for /cms/prescription/28/21/queue?did=8
- Route loads without 404 errors
- Prescription data (ID: 28) loads correctly
- Patient data (ID: 21) displays properly
- Doctor context (ID: 8) works correctly
- All API calls use
/prescriptions/endpoints - No console errors related to undefined careplan variables
- Queue functionality works as expected
- All form submissions use prescription_id parameter
Mobile App Tests
- Test deep linking with new URL patterns
- Test push notification handling
- Test offline data sync with updated object structure
- Test patient prescription sharing functionality
📞 SUPPORT & QUESTIONS
For questions about this migration:
- Check the backend migration history:
backend/docs/04-features/prescription-migration/migration-history.md - Review API documentation for updated endpoints
- Contact backend team for clarification on specific response structures
Last Updated: Current Session (Updated with Phase 7F changes)
Backend Migration Status: 100% Complete ✅
Frontend Migration Status: Ready to Begin
🆕 RECENT UPDATES (Phase 7F)
Additional Template-Related Changes
Template Foreign Key Updates
# Template medicine associations
- doctor_careplan_template_id: 123
+ doctor_prescription_template_id: 123
# Template test list associations
- careplan_template_test_list_id: 456
+ prescription_template_test_list_id: 456
# Test list associations
- careplan_test_list_id: 789
+ prescription_test_list_id: 789Additional Database Table References
If your frontend directly references database table names (advanced use cases):
# Template tables
- doctor_careplan_templates
- careplan_template_medicines
- careplan_template_test_lists
- careplan_template_tests
- careplan_tests
+ doctor_prescription_templates
+ prescription_template_medicines
+ prescription_template_test_lists
+ prescription_template_tests
+ prescription_testsAdditional Foreign Key References
# In documents, activities, and shared prescriptions
- careplan_id: 123
+ prescription_id: 123
# This affects any frontend code that directly references these foreign keysImportant Notes for Frontend Team
- Complete Backend Migration: All backend changes are now 100% complete
- No More Breaking Changes: No additional backend changes will be made
- Database Ready: All database migrations are prepared and ready
- Models Updated: All ActiveRecord models and associations updated
- API Stability: All API endpoints and responses are finalized
Quick Reference for Route: /cms/prescription/28/21/queue?did=8
Critical Frontend Changes Required:
// 1. Route Definition Update
// OLD: path: "/cms/careplan/:id/:patientId/queue"
// NEW: path: "/cms/prescription/:id/:patientId/queue"
// 2. API Endpoint Updates
// OLD: GET `/api/v1/careplans/${prescriptionId}`
// NEW: GET `/api/v1/prescriptions/${prescriptionId}`
// 3. Component Props/State Updates
// OLD: const { careplanId, careplan } = props
// NEW: const { prescriptionId, prescription } = props
// 4. Redux/State Updates
// OLD: state.careplans.selected
// NEW: state.prescriptions.selected
// 5. Form Field Updates
// OLD: <input name="careplan[diagnosis]" />
// NEW: <input name="prescription[diagnosis]" />Backend Endpoints Ready for Testing:
- ✅
GET /api/v1/prescriptions/28- Prescription details - ✅
GET /api/v1/prescriptions/28/medicines- Prescription medicines - ✅
GET /api/v1/prescriptions/28/complaints- Prescription complaints - ✅
GET /api/v1/prescriptions/28/tests- Prescription tests - ✅
PUT /api/v1/prescriptions/28- Update prescription - ✅ All nested resource endpoints updated and ready