Kulcare Docs
DeveloperCare plansCare planLhr

Medication Continuity - Simplified Implementation

Overview

This document describes a simplified medication continuity feature that tracks chronic medications across encounters. This is a basic implementation focused on continuity without complex reconciliation workflows.

Approach: Track medication types (chronic/acute) and allow doctors to review and update chronic medications in new encounters.

Medication Continuity Implementation

1. Basic Medication Continuity Service

class MedicationContinuityService
  def initialize(patient_id)
    @patient = Patient.find(patient_id)
  end
  
  # Get chronic medications that should be reviewed in new encounter
  def get_chronic_medications
    @patient.encounter_medicines
            .joins(:encounter)
            .where(medication_status: 'active')
            .where(prescription_type: 'chronic')
            .order(created_at: :desc)
            .distinct
            .select('encounter_medicines.*, MAX(encounters.created_at) as last_prescribed_date')
            .group('encounter_medicines.medicine_name, encounter_medicines.generic_name')
  end
  
  # Simple method to carry forward chronic medications
  def copy_to_new_encounter(encounter_id, medication_ids)
    encounter = Encounter.find(encounter_id)
    copied_medications = []
    
    medication_ids.each do |med_id|
      original = EncounterMedicine.find(med_id)
      
      # Create new prescription based on previous one
      new_medication = encounter.encounter_medicines.create!(
        medicine_name: original.medicine_name,
        generic_name: original.generic_name,
        dosage: original.dosage,
        frequency: original.frequency,
        duration: original.duration,
        duration_unit: original.duration_unit,
        medication_status: 'active',
        prescription_type: 'chronic',
        start_date: Date.current,
        parent_prescription_id: original.id,
        instructions: original.instructions
      )
      
      copied_medications << new_medication
    end
    
    copied_medications
  end
  
  # Update dosage for existing chronic medication
  def update_medication_dosage(medication_id, new_dosage, new_frequency = nil)
    medication = EncounterMedicine.find(medication_id)
    
    medication.update!(
      dosage: new_dosage,
      frequency: new_frequency || medication.frequency,
      updated_at: Time.current
    )
  end
end

2. Simple Controller Actions

class MedicationContinuityController < ApiController
  before_action :authenticate_user!
  before_action :set_encounter
  
  # GET /api/encounters/:encounter_id/chronic_medications
  # Get list of patient's chronic medications for review
  def chronic_medications
    service = MedicationContinuityService.new(@encounter.patient_id)
    chronic_meds = service.get_chronic_medications
    
    render json: {
      chronic_medications: chronic_meds.map do |med|
        {
          id: med.id,
          medicine_name: med.medicine_name,
          generic_name: med.generic_name,
          dosage: med.dosage,
          frequency: med.frequency,
          duration: med.duration,
          last_prescribed_date: med.last_prescribed_date,
          instructions: med.instructions
        }
      end
    }
  end
  
  # POST /api/encounters/:encounter_id/continue_medications
  # Continue selected chronic medications in current encounter
  def continue_medications
    service = MedicationContinuityService.new(@encounter.patient_id)
    medication_ids = params[:medication_ids]
    
    # Copy selected medications to current encounter
    copied_medications = service.copy_to_new_encounter(@encounter.id, medication_ids)
    
    render json: {
      success: true,
      continued_count: copied_medications.count,
      medications: copied_medications
    }
  end
  
  # PATCH /api/encounter_medicines/:id/update_dosage
  # Update dosage for a medication
  def update_dosage
    medication = EncounterMedicine.find(params[:id])
    
    medication.update!(
      dosage: params[:dosage],
      frequency: params[:frequency],
      instructions: params[:instructions]
    )
    
    render json: {
      success: true,
      medication: medication
    }
  end
  
  private
  
  def set_encounter
    @encounter = Encounter.find(params[:encounter_id])
  end
end

3. Database Fields Required

# Only these fields needed in encounter_medicines table:
# - medication_status: active/discontinued
# - prescription_type: chronic/acute/prn
# - parent_prescription_id: to track medication history
# - start_date, end_date: for duration tracking

# No complex reconciliation tables or tracking needed

UI Integration

Simple Workflow

  1. New Encounter Creation:

    • If patient has chronic medications, show list for review
    • Doctor can select which to continue
    • Selected medications are copied to new encounter
  2. During Encounter:

    • Doctor can update dosage/frequency of any medication
    • Can mark medications as discontinued
    • Can add new medications (marking as chronic/acute)
  3. No Complex Workflows:

    • No reconciliation status tracking
    • No interaction checking
    • No duplicate detection
    • Just simple medication continuity

Example UI Flow

// When creating new encounter
const ChronicMedicationReview = ({ encounterId, patientId }) => {
  const [chronicMeds, setChronicMeds] = useState([]);
  const [selectedMeds, setSelectedMeds] = useState([]);
  
  useEffect(() => {
    // Fetch patient's chronic medications
    fetchChronicMedications(encounterId);
  }, [encounterId]);
  
  const continueMedications = () => {
    // Continue selected medications
    api.post(`/encounters/${encounterId}/continue_medications`, {
      medication_ids: selectedMeds
    });
  };
  
  return (
    <div>
      <h3>Review Chronic Medications</h3>
      {chronicMeds.map(med => (
        <div key={med.id}>
          <input 
            type="checkbox" 
            onChange={(e) => toggleMedication(med.id)}
          />
          <span>{med.medicine_name} - {med.dosage}</span>
          <small>Last prescribed: {med.last_prescribed_date}</small>
        </div>
      ))}
      <button onClick={continueMedications}>
        Continue Selected Medications
      </button>
    </div>
  );
};

Simplified Implementation Summary:

✅ Basic Continuity: Track chronic vs acute medications
✅ Simple Review: Show previous chronic medications in new encounters
✅ Easy Updates: Allow dosage/frequency updates
✅ No Complex Workflows: No reconciliation tracking or interaction checking
✅ Minimal Changes: Just add prescription_type field and basic logic

Benefits:

  • Ensures chronic medications aren't accidentally discontinued
  • Saves time by carrying forward long-term prescriptions
  • Simple to implement and understand
  • No additional UI complexity

On this page