ข้ามไปที่เนื้อหา

ภาพรวมระบบเภสัชกรรม (Pharmacy System Overview)

📋 สารบัญ


ภาพรวมระบบ

ระบบเภสัชกรรม (Pharmacy System) เป็นส่วนหนึ่งของระบบสารสนเทศโรงพยาบาล (HIS) ที่จัดการกระบวนการทั้งหมดเกี่ยวกับยาและเวชภัณฑ์ ตั้งแต่การสั่งยาจากแพทย์ การตรวจสอบปฏิกิริยายา การจ่ายยา จนถึงการจัดการคลังยา

วัตถุประสงค์หลัก

  1. จัดการการจ่ายยาผู้ป่วยนอก (OPD Dispensing)
  2. รับใบสั่งยาจากแพทย์
  3. ตรวจสอบความปลอดภัย (Drug Interaction, Allergy)
  4. จัดเตรียมและจ่ายยาให้ผู้ป่วย
  5. พิมพ์ฉลากยาและใบแนะนำการใช้ยา

  6. จัดการการจ่ายยาผู้ป่วยใน (IPD Dispensing)

  7. รับคำสั่งยาต่อเนื่อง (Continue Order)
  8. รับคำสั่งยา PRN (เมื่อจำเป็น)
  9. รับคำสั่งยา STAT (ด่วนทันที)
  10. จัดส่งยาตามเวลาให้ยา (Administration Time)
  11. บันทึกการจ่ายยาและสถานะ

  12. ตรวจสอบปฏิกิริยาระหว่างยา (Drug Interaction)

  13. ตรวจสอบอัตโนมัติเมื่อสั่งยา
  14. แสดงคำเตือนตามระดับความรุนแรง (Major, Moderate, Minor)
  15. แนะนำการจัดการปฏิกิริยายา

  16. จัดการชุดยาแพทย์ (Medication Templates)

  17. สร้างชุดยาที่ใช้บ่อย (Personal/Shared)
  18. เรียกใช้ชุดยาอย่างรวดเร็ว (RE MED)
  19. จัดการและแก้ไขชุดยา

  20. จัดการคลังยา (Drug Inventory)

  21. ตรวจสอบสต็อคยา
  22. แจ้งเตือนยาใกล้หมด
  23. ติดตามยาหมดอายุ

สถาปัตยกรรมระบบ

Architecture Diagram

┌─────────────────────────────────────────────────────────────────┐
│                        PRESENTATION LAYER                        │
│                         (HTML + CSS + JS)                        │
├─────────────────────────────────────────────────────────────────┤
│                                                                   │
│  ┌──────────────┐  ┌──────────────┐  ┌──────────────┐          │
│  │ OPD          │  │ IPD          │  │ Drug         │          │
│  │ Dispensing   │  │ Dispensing   │  │ Interaction  │          │
│  └──────────────┘  └──────────────┘  └──────────────┘          │
│                                                                   │
│  ┌──────────────┐  ┌──────────────┐  ┌──────────────┐          │
│  │ Medication   │  │ Drug         │  │ Dashboard    │          │
│  │ Templates    │  │ Inventory    │  │              │          │
│  └──────────────┘  └──────────────┘  └──────────────┘          │
│                                                                   │
└─────────────────────────────────────────────────────────────────┘
                              ↕
┌─────────────────────────────────────────────────────────────────┐
│                         SERVICE LAYER                            │
│                      (Business Logic)                            │
├─────────────────────────────────────────────────────────────────┤
│                                                                   │
│                    ┌──────────────────────┐                     │
│                    │ MedicationService     │                     │
│                    │ (Singleton)           │                     │
│                    ├──────────────────────┤                     │
│                    │ - init()              │                     │
│                    │ - searchMedication()  │                     │
│                    │ - checkInteractions() │                     │
│                    │ - checkAllergies()    │                     │
│                    │ - getTemplates()      │                     │
│                    │ - savePrescription()  │                     │
│                    │ - dispenseMedication()│                     │
│                    └──────────────────────┘                     │
│                                                                   │
└─────────────────────────────────────────────────────────────────┘
                              ↕
┌─────────────────────────────────────────────────────────────────┐
│                         DATA LAYER                               │
│                    (JSON Mock Data)                              │
├─────────────────────────────────────────────────────────────────┤
│                                                                   │
│  medications-master.json     ← รายการยาทั้งหมด (Item Master)   │
│  master-drug-dropdown.json   ← Dropdown data (frequency, route) │
│  medication-templates.json   ← ชุดยาแพทย์ (Shared)              │
│  drug-interactions.json      ← ปฏิกิริยาระหว่างยา               │
│  prescription-history.json   ← ประวัติการสั่งยา                 │
│  pharmacy-opd-queue.json     ← คิวจ่ายยา OPD                    │
│  pharmacy-ipd-orders.json    ← คำสั่งยา IPD                     │
│  pharmacy-return-history.json← ประวัติคืนยา                     │
│                                                                   │
│  localStorage:                                                    │
│  - his_medication_templates_{doctorId} ← Personal templates     │
│                                                                   │
└─────────────────────────────────────────────────────────────────┘

Technology Stack

Layer Technology Purpose
Frontend HTML5, CSS3, Vanilla JavaScript UI และ User Interaction
CSS Framework Bootstrap 5.3, Custom CSS Responsive Design
Icons Bootstrap Icons UI Icons
Data Storage JSON Files (Mock) Server-side data simulation
Local Storage localStorage API Personal templates, session data
Pattern MVC (Model-View-Controller) Code organization
Service Pattern Singleton Service Centralized business logic

โมดูลหลัก

1. Dashboard (index.html)

ไฟล์: modules/pharmacy/index.html

หน้าที่: - แสดงสถิติการทำงานของระบบเภสัชกรรม - จำนวนคิวรอจ่ายยา OPD/IPD - สถานะสต็อคยา - ลิงก์ไปยังโมดูลต่างๆ

Stats แสดง:

- จำนวนคิวรอจ่ายยา OPD
- จำนวนคำสั่งยา IPD ที่รอดำเนินการ
- จำนวนยาใกล้หมด
- จำนวนชุดยาที่บันทึกไว้


2. OPD Dispensing (opd-dispensing.html)

ไฟล์: modules/pharmacy/opd-dispensing.html (2353 lines)

หน้าที่: - จัดการการจ่ายยาผู้ป่วยนอก - รับคิวจากใบสั่งยาแพทย์ - ตรวจสอบความปลอดภัย - พิมพ์ฉลากยาและใบแนะนำการใช้ยา

Workflow สรุป: 1. เภสัชกรเลือกผู้ป่วยจากรายการคิว (Patient Queue) 2. ระบบแสดงรายการยาที่แพทย์สั่ง 3. เภสัชกรตรวจสอบและเลือกรายการยาที่จะจ่าย 4. พิมพ์ฉลากยาและจัดเตรียมยา 5. เรียกผู้ป่วยมารับยาและให้คำแนะนำ 6. บันทึกการจ่ายยาเสร็จสิ้น

UI Layout:

┌────────────────────────────────────────────────────┐
│ [Patient Queue]       │  [Patient Details]        │
│                       │                            │
│ ■ สมชาย ใจดี         │  ชื่อ: สมชาย ใจดี         │
│   HN000123            │  HN: HN000123             │
│   คลินิกอายุรกรรม     │  อายุ: 45 ปี              │
│                       │  แพ้ยา: Penicillin        │
│ □ สมหญิง แข็งแรง      │                            │
│   HN000456            │  [Tabs]                    │
│                       │  • รายการยา                │
│ □ ประเสริฐ สุขดี      │  • ประวัติการสั่งยา        │
│   HN000789            │  • Drug Interaction        │
│                       │                            │
│                       │  [Medication List]         │
│                       │  □ Paracetamol 500mg x20   │
│                       │  □ Amoxicillin 500mg x21   │
│                       │                            │
│                       │  [Actions]                 │
│                       │  [พิมพ์ฉลาก] [จ่ายยา]      │
└────────────────────────────────────────────────────┘

เอกสารเพิ่มเติม:WORKFLOW_OPD_DISPENSING.md


3. IPD Dispensing (ipd-dispensing.html)

ไฟล์: modules/pharmacy/ipd-dispensing.html (4084 lines)

หน้าที่: - จัดการการจ่ายยาผู้ป่วยใน - จัดการคำสั่งยา 3 ประเภท: - Continue Order: ยาต่อเนื่อง (ให้ตามเวลาที่กำหนด) - PRN Order: ยาเมื่อจำเป็น (as needed) - STAT Order: ยาด่วนทันที

Workflow สรุป: 1. เภสัชกรเลือก Ward/หอผู้ป่วย 2. เลือกผู้ป่วยในแต่ละหอ 3. ดูคำสั่งยาทั้งหมดของผู้ป่วย (แยกตาม Order Type) 4. จัดเตรียมยาตามเวลาให้ยา 5. พิมพ์ใบจ่ายยาส่งหอผู้ป่วย 6. บันทึกการจ่ายยา

UI Layout:

┌────────────────────────────────────────────────────┐
│ [Ward List]           │  [Order Details]          │
│                       │                            │
│ ▼ Medical Ward (5)    │  ผู้ป่วย: สมหญิง รักษาดี  │
│   ├─ สมหญิง รักษาดี   │  AN: AN-2025-001          │
│   ├─ ประเสริฐ สุขใจ    │  Ward: Medical Ward       │
│   └─ ...              │  Bed: M301-1              │
│                       │                            │
│ ▶ Surgical Ward (3)   │  [Tabs]                    │
│                       │  • Continue Order          │
│ ▶ ICU (2)             │  • PRN Order               │
│                       │  • STAT Order              │
│                       │  • ประวัติการจ่าย          │
│                       │                            │
│                       │  [Active Orders]           │
│                       │  ☑ NSS 0.9% 1000ml         │
│                       │     เวลา: 06:00, 18:00     │
│                       │  ☑ Omeprazole 40mg         │
│                       │     เวลา: 08:00, 20:00     │
│                       │                            │
│                       │  [จัดเตรียมยา] [ส่งยา]     │
└────────────────────────────────────────────────────┘

เอกสารเพิ่มเติม:WORKFLOW_IPD_DISPENSING.md


4. Drug Interaction (drug-interaction.html)

ไฟล์: modules/pharmacy/drug-interaction.html (1066 lines)

หน้าที่: - แสดงและจัดการปฏิกิริยาระหว่างยา - ค้นหาปฏิกิริยายา - แสดงคำเตือนตามระดับความรุนแรง: - 🔴 Major: รุนแรง ควรหลีกเลี่ยง - 🟡 Moderate: ปานกลาง ต้องระวัง - 🟢 Minor: เล็กน้อย ตรวจสอบได้

Workflow สรุป: 1. ระบบตรวจสอบอัตโนมัติเมื่อสั่งยา (Real-time Check) 2. แสดง Alert ถ้าพบปฏิกิริยายา 3. เภสัชกร/แพทย์พิจารณาดำเนินการ: - เปลี่ยนยา - ปรับขนาดยา - ติดตามอาการใกล้ชิด - Override (มีเหตุผลทางการแพทย์)

Severity Levels:

Severity Description Action
Major ปฏิกิริยารุนแรง อาจเป็นอันตรายถึงชีวิต ❌ ไม่ควรใช้ร่วมกัน
Moderate ปฏิกิริยาปานกลาง ต้องติดตามอาการ ⚠️ ระวังใช้ ปรับขนาดยา
Minor ปฏิกิริยาเล็กน้อย ✓ ใช้ได้ แนะนำให้ความรู้

เอกสารเพิ่มเติม:WORKFLOW_DRUG_INTERACTION.md


5. Medication Templates (medication-templates.html)

ไฟล์: modules/pharmacy/medication-templates.html

หน้าที่: - จัดการชุดยาที่ใช้บ่อย (Frequently Used Medication Sets) - รองรับ 2 ประเภท: - Personal Templates: ชุดยาส่วนตัวแพทย์ (บันทึกใน localStorage) - Shared Templates: ชุดยาของโรงพยาบาล (บันทึกในฐานข้อมูล)

Workflow สรุป: 1. แพทย์สร้างชุดยาจากยาที่สั่งบ่อย 2. ตั้งชื่อชุดยาและระบุประเภทโรค 3. บันทึกเป็น Template 4. เมื่อต้องการใช้ → เลือก Template → ยาทั้งชุดถูกเพิ่มอัตโนมัติ 5. แพทย์สามารถแก้ไขก่อน Confirm ได้

ตัวอย่าง Templates:

{
  "id": "TPL001",
  "name": "ชุดยารักษาหวัด",
  "type": "shared",
  "disease": "Upper Respiratory Tract Infection",
  "medications": [
    {
      "drugCode": "MED001",
      "tradeName": "Paracetamol 500mg",
      "dosage": "1-2 tab",
      "frequency": "q4-6h",
      "duration": "PRN"
    },
    {
      "drugCode": "MED005",
      "tradeName": "Chlorpheniramine 4mg",
      "dosage": "1 tab",
      "frequency": "tid",
      "duration": "5 days"
    }
  ]
}

เอกสารเพิ่มเติม:WORKFLOW_MEDICATION_TEMPLATES.md


6. Drug Inventory (drug-inventory.html)

ไฟล์: modules/pharmacy/drug-inventory.html

หน้าที่: - ตรวจสอบสต็อคยา - แจ้งเตือนยาใกล้หมด (Reorder Level) - ติดตามยาหมดอายุ - ค้นหายาในคลัง

Features: - Real-time Stock Display - Low Stock Alert (สีแดงเมื่อต่ำกว่า Reorder Level) - Expiry Date Tracking - Search & Filter


Data Flow

1. OPD Dispensing Flow

graph TB
    A[แพทย์สั่งยา] --> B[ใบสั่งยาเข้าระบบ]
    B --> C[prescription-history.json]
    C --> D[pharmacy-opd-queue.json]
    D --> E[OPD Queue Display]
    E --> F{เภสัชกรเลือกผู้ป่วย}
    F --> G[ดึงข้อมูลยาจาก medications-master.json]
    F --> H[ตรวจสอบ Drug Interaction]
    H --> I[drug-interactions.json]
    F --> J[ตรวจสอบ Allergy]
    J --> K[Patient Allergies]
    G --> L{พร้อมจ่าย?}
    L -->|Yes| M[พิมพ์ฉลากยา]
    L -->|No| N[รอยาเพิ่มเติม]
    M --> O[จ่ายยาให้ผู้ป่วย]
    O --> P[บันทึกการจ่ายยา]
    P --> Q[อัปเดตสถานะ: dispensed]

2. IPD Dispensing Flow

graph TB
    A[แพทย์สั่งยา IPD] --> B[คำสั่งยาเข้าระบบ]
    B --> C[pharmacy-ipd-orders.json]
    C --> D[แยกตาม Order Type]
    D --> E[Continue Order]
    D --> F[PRN Order]
    D --> G[STAT Order]
    E --> H{ถึงเวลาให้ยา?}
    H -->|Yes| I[เภสัชกรจัดเตรียมยา]
    H -->|No| J[รอถึงเวลา]
    F --> K{พยาบาล Request?}
    K -->|Yes| I
    G --> L[จัดเตรียมทันที]
    L --> I
    I --> M[พิมพ์ใบจ่ายยา]
    M --> N[ส่งยาไปหอผู้ป่วย]
    N --> O[บันทึกการจ่าย]
    O --> P[อัปเดตสถานะ]

3. Template Usage Flow

graph LR
    A[แพทย์เลือก Template] --> B{ประเภท?}
    B -->|Personal| C[localStorage]
    B -->|Shared| D[medication-templates.json]
    C --> E[โหลดยาทั้งชุด]
    D --> E
    E --> F[แสดงรายการยา]
    F --> G{แพทย์แก้ไข?}
    G -->|Yes| H[ปรับปรุงรายการ]
    G -->|No| I[Confirm]
    H --> I
    I --> J[สั่งยา]

Service Layer

MedicationService (Singleton)

ไฟล์: assets/js/services/MedicationService.js (1255 lines)

Purpose: Service หลักสำหรับจัดการทุกอย่างเกี่ยวกับยา

สถาปัตยกรรม

class MedicationService {
    constructor() {
        this.medications = [];        // รายการยาทั้งหมด
        this.masterDropdown = {};     // Dropdown data
        this.templates = [];          // ชุดยา
        this.drugInteractions = [];   // ปฏิกิริยายา
        this.prescriptionHistory = []; // ประวัติสั่งยา
        this.initialized = false;
    }
}

// Singleton Instance
const medicationService = new MedicationService();

Key Methods

1. Initialization
async init()
// โหลดข้อมูลทั้งหมดจาก JSON files
// - medications-master.json
// - master-drug-dropdown.json
// - medication-templates.json
// - drug-interactions.json
// - prescription-history.json
2. Search & Retrieve
searchMedications(query, options)
// ค้นหายาจาก trade name, generic name, drug code

getMedicationById(medicationId)
// ดึงข้อมูลยาจาก ID

getMedicationByCode(drugCode)
// ดึงข้อมูลยาจาก Drug Code
3. Drug Safety Checks
checkDrugInteractions(medications)
// ตรวจสอบปฏิกิริยาระหว่างยา
// Returns: [{ severity, drug1, drug2, description, management }]

checkAllergies(medications, patientAllergies)
// ตรวจสอบการแพ้ยา
// Returns: warnings array

checkPregnancySafety(medications)
// ตรวจสอบความปลอดภัยสำหรับสตรีมีครรภ์

checkLactationSafety(medications)
// ตรวจสอบความปลอดภัยสำหรับสตรีให้นมบุตร

checkPediatricSafety(medications)
// ตรวจสอบความปลอดภัยสำหรับเด็ก

checkAllWarnings(medication, patient)
// ตรวจสอบคำเตือนทั้งหมด
4. Template Management
getTemplates(doctorId, type)
// ดึงรายการ Templates (all, personal, shared)

getTemplateById(templateId)
// ดึง Template จาก ID

saveTemplate(templateData)
// บันทึก Template ใหม่

updateTemplate(templateId, updateData)
// อัปเดต Template

deleteTemplate(templateId, doctorId)
// ลบ Template
5. Prescription Management
savePrescription(hn, visitId, medications, patientAllergies)
// บันทึกการสั่งยา พร้อมตรวจสอบความปลอดภัย
// Returns: { success, warnings, errors, prescriptionId }

getPrescriptionHistory(hn, options)
// ดึงประวัติการสั่งยา

getLastPrescription(hn)
// ดึงใบสั่งยาล่าสุด (สำหรับ RE MED)
6. Utility Functions
calculateQuantityFromDuration(duration, frequencyCode, dosagePerTime)
// คำนวณจำนวนยาจากระยะเวลา

calculateDurationFromQuantity(quantity, frequencyCode, dosagePerTime)
// คำนวณระยะเวลาจากจำนวนยา

getDropdownOptions(type)
// ดึงข้อมูล Dropdown (frequency, route, timing)

getDisplayText(type, code, lang)
// แปลง code เป็น text สำหรับแสดงผล

เอกสารที่เกี่ยวข้อง

เอกสาร คำอธิบาย
WORKFLOW_OPD_DISPENSING.md Workflow การจ่ายยาผู้ป่วยนอกแบบละเอียด
WORKFLOW_IPD_DISPENSING.md Workflow การจ่ายยาผู้ป่วยในแบบละเอียด
WORKFLOW_DRUG_INTERACTION.md Workflow การตรวจสอบปฏิกิริยายา
WORKFLOW_MEDICATION_TEMPLATES.md Workflow การจัดการชุดยาแพทย์
DATA_STRUCTURES.md โครงสร้างข้อมูลทั้งหมดที่ใช้ในระบบ

หมายเหตุสำหรับ Developer

Path Resolution

Service ใช้ detectBasePath() เพื่อหา path ของ JSON files อัตโนมัติ:

detectBasePath() {
    const currentPath = window.location.pathname;
    if (currentPath.includes('/modules/')) {
        return '../../data/';
    }
    return '/data/';
}

Data Persistence Strategy

  • Shared Data: JSON files (simulating server database)
  • Personal Data: localStorage (per doctor)
  • Key format: his_medication_templates_{doctorId}

Error Handling

Service มี fallback mechanism:

try {
    // Load from medications-master.json
} catch (error) {
    // Fallback to medications.json
}

Script Load Order

<!-- MUST load in this order -->
<script src="/assets/js/models/Medication.js"></script>
<script src="/assets/js/services/MedicationService.js"></script>
<script>
    // Then initialize
    await medicationService.init();
</script>

สร้างเมื่อ: 6 มกราคม 2026
สถานะ: Active Development
Version: 1.0