Skip to content

Conversation

@rahu1ramesh
Copy link
Contributor

@rahu1ramesh rahu1ramesh commented Jun 5, 2025

JIRABN-84

Description

This PR implements a major architectural refactor of the consultation pad and related components, focusing on simplifying state management, improving error handling, and enhancing code maintainability. The changes eliminate the complexity of Prop drilling in favor of focused individual hooks and improve the overall user experience with better loading states and error feedback.


Key Features

  • Simplified State Management: Removed centralized encounterDetailsStore and replaced with focused individual hooks
  • Enhanced Error Handling: Implemented user-friendly notification system instead of throwing errors
  • Improved Component Architecture: Refactored components for better separation of concerns and reusability
  • Better UX: Added proper loading states and error feedback throughout the consultation workflow
  • Terminology Clarity: Renamed "active visit" to "current encounter" for better domain alignment

Implementation Details

  • UI Components

    • Refactored ConsultationPad component to use individual hooks instead of centralized store
    • Simplified BasicForm component to be props-driven instead of hook-heavy
    • Added loading and error states with proper visual feedback using Carbon Loading component
    • Removed button disabled state management from ActionArea component
  • State Management

    • BREAKING: Removed Prop Drilling in ConsultationPad entirely
    • Replaced with focused hooks: useCurrentEncounter, useActivePractitioner, useEncounterConcepts, useLocations
    • Simplified data flow with props-based component communication
  • Custom Hooks

    • Renamed useActiveVisituseCurrentEncounter for clarity
    • Updated hooks to use notification system instead of throwing errors
    • Improved error handling with user-friendly messages and proper cleanup
  • API Integration

    • Renamed service methods: getActiveVisitgetCurrentEncounter
    • Updated endpoint constants: PATIENT_VISITS_URLPATIENT_ENCOUNTER_RESOURCE_URL
    • Enhanced error handling in userService and locationService
  • Performance & Optimization

    • Reduced unnecessary re-renders by eliminating complex state dependencies
    • Simplified component lifecycle management
    • Improved data fetching patterns with better loading states
  • Internationalisation

    • Cleaned up unused error message keys from locale files
    • Maintained consistency across English and Spanish translations
    • Removed redundant error messages that are now handled by notification system
  • Accessibility

    • Maintained WCAG compliance with proper loading states
    • Enhanced screen reader support with better state communication
    • Improved keyboard navigation patterns
  • Limitations

    • This is a breaking change requiring component API updates
    • Some complex state scenarios may need additional handling
    • Migration path needed for existing implementations

Testing & Type Definitions

  • Unit Tests

    • Completely rewrote ConsultationPad tests to match new architecture
    • Updated BasicForm tests for props-based approach
    • Added comprehensive tests for new hook implementations
    • Removed tests for deleted encounterDetailsStore
  • Integration Tests

    • Simplified integration tests with better mock strategies
    • Enhanced test coverage for error scenarios
    • Updated test data and mocks to match new naming conventions
  • Type Definitions

    • Maintained strict TypeScript compliance throughout refactor
    • Updated interface definitions for new component props
    • Enhanced type safety with better error handling patterns

Screenshots

Feature / State Screenshot
Loading State Loading spinner with proper messaging
Error State User-friendly error messages with retry options
Success State Clean consultation pad interface

Note: Please ensure sensitive information is not included in screenshots.


Next Steps

  • Monitor for any regression issues in consultation workflow
  • Consider further optimization opportunities in related components
  • Plan migration guide for teams using the old encounterDetailsStore
  • Evaluate similar refactoring opportunities in other parts of the application

Important

Checklist

  • Code adheres to project linting and formatting standards.
  • New components added to Storybook.
  • Tests written and passing (unit + integration).
  • Labels and text support i18n.
  • Follows accessibility and responsive design guidelines.
  • PR reviewed by at least one other developer.

Reviewer(s)

@bahnew/developers
This is a significant architectural change - please review carefully for any potential impacts on existing workflows.


mohan-13 and others added 27 commits May 30, 2025 14:40
@rahu1ramesh rahu1ramesh merged commit b4e959b into main Jun 5, 2025
2 checks passed
@rahu1ramesh rahu1ramesh deleted the BN-84-basic-form branch June 5, 2025 16:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants