diff --git a/docs/test-types-reference.md b/docs/test-types-reference.md new file mode 100644 index 0000000..bda2fc0 --- /dev/null +++ b/docs/test-types-reference.md @@ -0,0 +1,434 @@ +# ๐Ÿ“‹ Test Types & Reference Types Guide + +> **Quick Overview**: This guide helps you understand the different types of tests and how to display them in the frontend. + +--- + +## ๐ŸŽฏ What Are Test Types? + +Think of test types as "categories" that determine how a test behaves and what information it needs. + +### Quick Reference Card + +``` +โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” +โ”‚ Type โ”‚ Use This For... โ”‚ Example โ”‚ +โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค +โ”‚ TEST โ”‚ Standard lab tests โ”‚ Blood Glucose, CBC โ”‚ +โ”‚ PARAM โ”‚ Components of a test โ”‚ WBC count (in CBC) โ”‚ +โ”‚ CALC โ”‚ Formula-based results โ”‚ BMI, eGFR โ”‚ +โ”‚ GROUP โ”‚ Panels/batteries โ”‚ Lipid Panel, CMP โ”‚ +โ”‚ TITLE โ”‚ Section headers โ”‚ "Hematology Results" โ”‚ +โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ +``` + +--- + +## ๐Ÿงช Detailed Test Types + +### 1. TEST - Standard Laboratory Test +**Icon**: ๐Ÿงซ **Color**: Blue + +Use this for regular tests that have: +- Reference ranges (normal values) +- Units (mg/dL, mmol/L, etc.) +- Collection requirements + +**Example**: Blood Glucose, Hemoglobin, Cholesterol + +**What to Display**: +- Test code and name +- Reference range +- Units +- Collection instructions +- Expected turnaround time + +--- + +### 2. PARAM - Parameter +**Icon**: ๐Ÿ“Š **Color**: Light Blue + +Use this for individual components within a larger test. + +**Example**: +- Complete Blood Count (GROUP) contains: + - WBC (PARAM) + - RBC (PARAM) + - Hemoglobin (PARAM) + +**What to Display**: +- Same as TEST, but shown indented under parent +- Often part of a GROUP + +--- + +### 3. CALC - Calculated Test +**Icon**: ๐Ÿงฎ **Color**: Purple + +Use this for tests computed from other test results using formulas. + +**Example**: +- BMI (calculated from height & weight) +- eGFR (calculated from creatinine, age, etc.) + +**What to Display**: +- Formula description +- Input parameters (which tests feed into this) +- Result value +- Reference range (if applicable) + +**Special Fields**: +- `FormulaInput` - What values go in? +- `FormulaCode` - How is it calculated? + +--- + +### 4. GROUP - Group Test (Panel/Battery) +**Icon**: ๐Ÿ“ฆ **Color**: Green + +Use this to bundle multiple related tests together. + +**Example**: +- Lipid Panel (GROUP) contains: + - Total Cholesterol (PARAM) + - HDL (PARAM) + - LDL (PARAM) + - Triglycerides (PARAM) + +**What to Display**: +- Group name +- List of member tests +- Individual results for each member + +**Structure**: +``` +๐Ÿ“ฆ Lipid Panel (GROUP) + โ”œโ”€โ”€ Total Cholesterol (PARAM): 180 mg/dL + โ”œโ”€โ”€ HDL (PARAM): 55 mg/dL + โ”œโ”€โ”€ LDL (PARAM): 110 mg/dL + โ””โ”€โ”€ Triglycerides (PARAM): 150 mg/dL +``` + +--- + +### 5. TITLE - Section Header +**Icon**: ๐Ÿ“Œ **Color**: Gray + +Use this for organizing tests into sections on reports. + +**Example**: "Hematology", "Chemistry", "Urinalysis" + +**What to Display**: +- Just the title text +- No results or values +- Used for organization only + +--- + +## ๐Ÿ“ Reference Types Explained + +Reference types tell you **how to interpret the results** - what "normal" looks like. + +### Choose Your Reference Type: + +``` + โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” + โ”‚ Reference Type? โ”‚ + โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ + โ”‚ + โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” + โ”‚ โ”‚ โ”‚ + Numbers? Text values? Threshold? + โ”‚ โ”‚ โ”‚ + โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ–ผโ”€โ”€โ”€โ”€โ”€โ”€โ” โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ–ผโ”€โ”€โ”€โ”€โ”€โ”€โ” โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ–ผโ”€โ”€โ”€โ”€โ”€โ”€โ” + โ”‚ NMRC โ”‚ โ”‚ TEXT โ”‚ โ”‚ THOLD โ”‚ + โ”‚ (Numeric) โ”‚ โ”‚ (Text) โ”‚ โ”‚ (Threshold) โ”‚ + โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”˜ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”˜ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”˜ + โ”‚ โ”‚ โ”‚ + โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ–ผโ”€โ”€โ”€โ”€โ”€โ”€โ” โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ–ผโ”€โ”€โ”€โ”€โ”€โ”€โ” โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ–ผโ”€โ”€โ”€โ”€โ”€โ”€โ” + โ”‚ RANGE โ”‚ โ”‚ Free โ”‚ โ”‚ Positive/ โ”‚ + โ”‚ (Min-Max) โ”‚ โ”‚ Text โ”‚ โ”‚ Negative โ”‚ + โ”‚ OR โ”‚ โ”‚ OR โ”‚ โ”‚ OR โ”‚ + โ”‚ THOLD โ”‚ โ”‚ VSET โ”‚ โ”‚ < > = โ”‚ + โ”‚ (Threshold) โ”‚ โ”‚ (Dropdown) โ”‚ โ”‚ cutoff โ”‚ + โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ +``` + +### Reference Type Details + +| Type | Visual | Example | +|------|--------|---------| +| **NMRC** - Numeric Range | `70 - 100 mg/dL` | Blood glucose: 70-100 mg/dL | +| **TEXT** - Text Value | `"Normal"` or `"Positive"` | Urinalysis: "Clear", "Cloudy" | +| **THOLD** - Threshold | `> 60` or `< 5.5` | eGFR: > 60 (normal) | +| **VSET** - Value Set | Dropdown options | Organism: [E.coli, Staph, etc.] | + +--- + +## ๐ŸŽจ Frontend Display Patterns + +### Pattern 1: Test List View + +```javascript +// When showing a list of tests +function renderTestCard(test) { + const typeIcon = getIcon(test.TestType); + const typeColor = getColor(test.TestType); + + return ` +
+ ${typeIcon} +

${test.TestSiteName}

+ ${test.TestTypeLabel} + ${test.TestSiteCode} +
+ `; +} +``` + +### Pattern 2: Reference Range Display + +```javascript +// Show reference range based on type +function renderReferenceRange(test) { + switch(test.RefType) { + case 'NMRC': + return `${test.MinValue} - ${test.MaxValue} ${test.Unit}`; + + case 'TEXT': + return test.ReferenceText || 'See report'; + + case 'THOLD': + return `${test.ThresholdOperator} ${test.ThresholdValue}`; + + case 'VSET': + return 'Select from list'; + } +} +``` + +### Pattern 3: Group Test Expansion + +```javascript +// Expandable group test +function renderGroupTest(test) { + return ` +
+ +
+ ${test.testdefgrp.map(member => renderTestRow(member)).join('')} +
+
+ `; +} +``` + +--- + +## ๐Ÿ—‚๏ธ Data Structure Visualization + +### Test Hierarchy + +``` +โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” +โ”‚ TEST DEFINITION โ”‚ +โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค +โ”‚ TestSiteID: 12345 โ”‚ +โ”‚ TestSiteCode: GLUC โ”‚ +โ”‚ TestSiteName: Glucose โ”‚ +โ”‚ TestType: TEST โ”‚ +โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค +โ”‚ ๐Ÿ“Ž Additional Info (loaded based on TestType): โ”‚ +โ”‚ โ”‚ +โ”‚ โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” โ”‚ +โ”‚ โ”‚ TestDefTech (for TEST/PARAM) โ”‚ โ”‚ +โ”‚ โ”‚ - DisciplineID, DepartmentID โ”‚ โ”‚ +โ”‚ โ”‚ - ResultType, RefType โ”‚ โ”‚ +โ”‚ โ”‚ - Unit, Method, ExpectedTAT โ”‚ โ”‚ +โ”‚ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ โ”‚ +โ”‚ โ”‚ +โ”‚ โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” โ”‚ +โ”‚ โ”‚ TestDefCal (for CALC) โ”‚ โ”‚ +โ”‚ โ”‚ - FormulaInput, FormulaCode โ”‚ โ”‚ +โ”‚ โ”‚ - RefType, Unit, Decimal โ”‚ โ”‚ +โ”‚ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ โ”‚ +โ”‚ โ”‚ +โ”‚ โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” โ”‚ +โ”‚ โ”‚ TestDefGrp (for GROUP) โ”‚ โ”‚ +โ”‚ โ”‚ - Array of member tests โ”‚ โ”‚ +โ”‚ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ โ”‚ +โ”‚ โ”‚ +โ”‚ โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” โ”‚ +โ”‚ โ”‚ TestMap (for ALL types) โ”‚ โ”‚ +โ”‚ โ”‚ - Mapping to external systems โ”‚ โ”‚ +โ”‚ โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ โ”‚ +โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ +``` + +--- + +## ๐Ÿ’ก Common Scenarios + +### Scenario 1: Creating a Simple Test + +**Need**: Add "Hemoglobin" test +**Choose**: TEST type with NMRC reference + +```javascript +const hemoglobin = { + TestSiteCode: 'HGB', + TestSiteName: 'Hemoglobin', + TestType: 'TEST', + testdeftech: { + RefType: 'NMRC', + Unit: 'g/dL', + // Reference range: 12-16 g/dL + } +}; +``` + +### Scenario 2: Creating a Panel + +**Need**: "Complete Blood Count" with multiple components +**Choose**: GROUP type with PARAM children + +```javascript +const cbc = { + TestSiteCode: 'CBC', + TestSiteName: 'Complete Blood Count', + TestType: 'GROUP', + testdefgrp: [ + { TestSiteCode: 'WBC', TestType: 'PARAM' }, + { TestSiteCode: 'RBC', TestType: 'PARAM' }, + { TestSiteCode: 'HGB', TestType: 'PARAM' }, + { TestSiteCode: 'PLT', TestType: 'PARAM' } + ] +}; +``` + +### Scenario 3: Calculated Result + +**Need**: BMI from height and weight +**Choose**: CALC type with formula + +```javascript +const bmi = { + TestSiteCode: 'BMI', + TestSiteName: 'Body Mass Index', + TestType: 'CALC', + testdefcal: { + FormulaInput: 'HEIGHT,WEIGHT', + FormulaCode: 'WEIGHT / ((HEIGHT/100) * (HEIGHT/100))', + RefType: 'NMRC', + Unit: 'kg/mยฒ' + } +}; +``` + +--- + +## ๐ŸŽจ Visual Style Guide + +### Color Coding + +| Type | Primary Color | Background | Usage | +|------|---------------|------------|-------| +| TEST | `#0066CC` | `#E6F2FF` | Main test cards | +| PARAM | `#3399FF` | `#F0F8FF` | Component rows | +| CALC | `#9933CC` | `#F5E6FF` | Calculated fields | +| GROUP | `#00AA44` | `#E6F9EE` | Expandable panels | +| TITLE | `#666666` | `#F5F5F5` | Section headers | + +### Icons + +| Type | Icon | Unicode | +|------|------|---------| +| TEST | ๐Ÿงซ | `\u{1F9EB}` | +| PARAM | ๐Ÿ“Š | `\u{1F4CA}` | +| CALC | ๐Ÿงฎ | `\u{1F9EE}` | +| GROUP | ๐Ÿ“ฆ | `\u{1F4E6}` | +| TITLE | ๐Ÿ“Œ | `\u{1F4CC}` | + +--- + +## ๐Ÿ”Œ Quick API Reference + +### Fetch Tests + +```javascript +// Get all tests for a site +GET /api/tests?siteId=123 + +// Get specific test type +GET /api/tests?testType=GROUP + +// Search tests +GET /api/tests?search=glucose + +// Get single test with details +GET /api/tests/12345 +``` + +### Value Set Helpers + +```javascript +// Get human-readable labels +const labels = { + testType: valueSet.getLabel('test_type', test.TestType), + refType: valueSet.getLabel('reference_type', test.RefType), + resultType: valueSet.getLabel('result_type', test.ResultType) +}; + +// Get dropdown options +const testTypes = valueSet.get('test_type'); +// Returns: [{value: "TEST", label: "Test"}, ...] +``` + +--- + +## ๐Ÿ“š Value Set File Locations + +``` +app/Libraries/Data/ +โ”œโ”€โ”€ test_type.json # TEST, PARAM, CALC, GROUP, TITLE +โ”œโ”€โ”€ reference_type.json # NMRC, TEXT, THOLD, VSET +โ”œโ”€โ”€ result_type.json # NMRIC, RANGE, TEXT, VSET +โ”œโ”€โ”€ numeric_ref_type.json # RANGE, THOLD +โ””โ”€โ”€ text_ref_type.json # VSET, TEXT +``` + +--- + +## โœ… Checklist for Frontend Developers + +- [ ] Show correct icon for each test type +- [ ] Display reference ranges based on RefType +- [ ] Handle GROUP tests as expandable panels +- [ ] Show TITLE tests as section headers +- [ ] Display CALC formulas when available +- [ ] Use ValueSet labels for all coded fields +- [ ] Respect VisibleScr/VisibleRpt flags +- [ ] Handle soft-deleted tests (EndDate check) + +--- + +## ๐Ÿ†˜ Need Help? + +**Q: When do I use PARAM vs TEST?** +A: Use PARAM for sub-components of a GROUP. Use TEST for standalone tests. + +**Q: What's the difference between NMRC and THOLD?** +A: NMRC shows a range (70-100). THOLD shows a threshold (> 60 or < 5.5). + +**Q: Can a GROUP contain other GROUPs?** +A: Yes! Groups can be nested (though typically only 1-2 levels deep). + +**Q: How do I know which details to fetch?** +A: Check `TestType` first, then look for the corresponding property: +- TEST/PARAM โ†’ `testdeftech` +- CALC โ†’ `testdefcal` +- GROUP โ†’ `testdefgrp` +- All types โ†’ `testmap` +