Compare commits

..

No commits in common. "feat/module-builder-clinical-ux" and "main" have entirely different histories.

2 changed files with 116 additions and 442 deletions

View File

@ -15,22 +15,22 @@ import {
import { ErrorBoundary } from '../common/ErrorBoundary'; import { ErrorBoundary } from '../common/ErrorBoundary';
const COMMON_TONGUE_SUGGESTIONS = [ const COMMON_TONGUE_SUGGESTIONS = [
'Pale and Thin', 'Pale and Thin.',
'Purple', 'Purple.',
'Normal', 'Normal.',
'Red with yellow coat', 'Red with yellow coat.',
'Pale with tooth marks', 'Pale with tooth marks.',
'Slightly Red sides or normal', 'Slightly Red sides or normal.',
]; ];
const COMMON_PULSE_SUGGESTIONS = [ const COMMON_PULSE_SUGGESTIONS = [
'Choppy', 'Choppy.',
'Wiry', 'Wiry.',
'Deep and Wiry', 'Deep and Wiry.',
'Deep and Weak', 'Deep and Weak.',
'Choppy or Fine', 'Choppy or Fine.',
'Rapid and Slippery', 'Rapid and Slippery.',
'Floating', 'Floating.',
]; ];
const COMMON_POINT_SUGGESTIONS = [ const COMMON_POINT_SUGGESTIONS = [
@ -66,22 +66,6 @@ const formatApiError = (err: any, fallback: string): string => {
return String(detail); return String(detail);
}; };
const normalizeTreatmentPrinciple = (val: string[] | string | undefined): string[] => {
if (Array.isArray(val)) {
const cleaned = val.map((v) => String(v || '').trim()).filter(Boolean);
return cleaned.length > 0 ? cleaned : [''];
}
const s = String(val || '').trim();
return s ? [s] : [''];
};
const suggestHyphenatedPoint = (raw: string): string | null => {
const cleaned = raw.trim().toUpperCase();
const match = cleaned.match(/^([A-Z]{1,4})\s+(\d+[A-Z]?)$/) || cleaned.match(/^([A-Z]{1,4})(\d+[A-Z]?)$/);
if (!match) return null;
return `${match[1]}-${match[2]}`;
};
const createBlankPattern = (moduleCode: string, catCode: string, disCode: string): BuilderPattern => ({ const createBlankPattern = (moduleCode: string, catCode: string, disCode: string): BuilderPattern => ({
module_code: moduleCode, module_code: moduleCode,
category_code: catCode, category_code: catCode,
@ -93,7 +77,7 @@ const createBlankPattern = (moduleCode: string, catCode: string, disCode: string
clinical_manifestations: [''], clinical_manifestations: [''],
tongue: '', tongue: '',
pulse: '', pulse: '',
treatment_principle: [''], treatment_principle: '',
acupuncture: { points: '', method: '' }, acupuncture: { points: '', method: '' },
explanation: [''], explanation: [''],
}, },
@ -148,11 +132,8 @@ export const ModuleBuilderTabContent: React.FC = () => {
const [newDiseaseName, setNewDiseaseName] = useState(''); const [newDiseaseName, setNewDiseaseName] = useState('');
const [modalDisError, setModalDisError] = useState<string | null>(null); const [modalDisError, setModalDisError] = useState<string | null>(null);
// Chip & Point input state // Point input state
const [customPointInput, setCustomPointInput] = useState(''); const [customPointInput, setCustomPointInput] = useState('');
const [customTongueInput, setCustomTongueInput] = useState('');
const [customPulseInput, setCustomPulseInput] = useState('');
const [pendingPointSuggestion, setPendingPointSuggestion] = useState<{ raw: string; suggested: string } | null>(null);
// 0. Load Modules List // 0. Load Modules List
const fetchModules = async (selectCode?: string) => { const fetchModules = async (selectCode?: string) => {
@ -281,7 +262,7 @@ export const ModuleBuilderTabContent: React.FC = () => {
: [''], : [''],
tongue: p.clinical_data?.tongue || '', tongue: p.clinical_data?.tongue || '',
pulse: p.clinical_data?.pulse || '', pulse: p.clinical_data?.pulse || '',
treatment_principle: normalizeTreatmentPrinciple(p.clinical_data?.treatment_principle), treatment_principle: p.clinical_data?.treatment_principle || '',
acupuncture: { acupuncture: {
points: p.clinical_data?.acupuncture?.points || '', points: p.clinical_data?.acupuncture?.points || '',
method: p.clinical_data?.acupuncture?.method || '', method: p.clinical_data?.acupuncture?.method || '',
@ -507,7 +488,7 @@ export const ModuleBuilderTabContent: React.FC = () => {
clinical_manifestations: [''], clinical_manifestations: [''],
tongue: '', tongue: '',
pulse: '', pulse: '',
treatment_principle: [''], treatment_principle: '',
acupuncture: { points: '', method: '' }, acupuncture: { points: '', method: '' },
explanation: [''], explanation: [''],
}, },
@ -565,143 +546,24 @@ export const ModuleBuilderTabContent: React.FC = () => {
})); }));
}; };
// Treatment Principle Row Helpers
const activePrinciples = Array.isArray(activePattern?.clinical_data?.treatment_principle)
? activePattern.clinical_data.treatment_principle
: normalizeTreatmentPrinciple(activePattern?.clinical_data?.treatment_principle);
const handlePrincipleChange = (pIdx: number, val: string) => {
updateActivePattern(p => {
const list = Array.isArray(p.clinical_data?.treatment_principle)
? [...p.clinical_data.treatment_principle]
: normalizeTreatmentPrinciple(p.clinical_data?.treatment_principle);
list[pIdx] = val;
return {
...p,
clinical_data: { ...p.clinical_data, treatment_principle: list },
};
});
};
const handleAddPrinciple = () => {
updateActivePattern(p => {
const list = Array.isArray(p.clinical_data?.treatment_principle)
? p.clinical_data.treatment_principle
: normalizeTreatmentPrinciple(p.clinical_data?.treatment_principle);
return {
...p,
clinical_data: {
...p.clinical_data,
treatment_principle: [...list, ''],
},
};
});
};
const handleRemovePrinciple = (pIdx: number) => {
updateActivePattern(p => {
const list = Array.isArray(p.clinical_data?.treatment_principle)
? p.clinical_data.treatment_principle
: normalizeTreatmentPrinciple(p.clinical_data?.treatment_principle);
return {
...p,
clinical_data: {
...p.clinical_data,
treatment_principle: list.filter((_, i) => i !== pIdx),
},
};
});
};
// Tongue & Pulse Chips Helpers
const parseCommaChips = (val?: string) =>
(val || '')
.split(',')
.map(s => s.trim().replace(/\.+$/, ''))
.filter(Boolean);
const currentTongueChips = parseCommaChips(activePattern?.clinical_data?.tongue);
const currentPulseChips = parseCommaChips(activePattern?.clinical_data?.pulse);
const handleAddDiagnosisChip = (field: 'tongue' | 'pulse', raw: string) => {
const parts = raw
.split(',')
.map(s => s.trim().replace(/\.+$/, ''))
.filter(Boolean);
if (parts.length === 0) return;
const existing = field === 'tongue' ? currentTongueChips : currentPulseChips;
const merged = [...existing];
let addedAny = false;
for (const part of parts) {
if (!merged.some(item => item.toLowerCase() === part.toLowerCase())) {
merged.push(part);
addedAny = true;
}
}
if (!addedAny) {
setError(`${field === 'tongue' ? 'Tongue' : 'Pulse'} finding "${parts[0]}" is already selected.`);
return;
}
setError(null);
updateActivePattern(p => ({
...p,
clinical_data: { ...p.clinical_data, [field]: merged.join(', ') },
}));
if (field === 'tongue') setCustomTongueInput('');
else setCustomPulseInput('');
};
const handleRemoveDiagnosisChip = (field: 'tongue' | 'pulse', chipToRemove: string) => {
const existing = field === 'tongue' ? currentTongueChips : currentPulseChips;
const updated = existing.filter(c => c !== chipToRemove).join(', ');
updateActivePattern(p => ({
...p,
clinical_data: { ...p.clinical_data, [field]: updated },
}));
};
// Point Chips Helpers (100% Safe Optional Chaining) // Point Chips Helpers (100% Safe Optional Chaining)
const currentPoints = (activePattern?.clinical_data?.acupuncture?.points || '') const currentPoints = (activePattern?.clinical_data?.acupuncture?.points || '')
.split(',') .split(',')
.map(s => s.trim()) .map(s => s.trim())
.filter(Boolean); .filter(Boolean);
const handleAddPointChip = (point: string, forceRaw = false) => { const handleAddPointChip = (point: string) => {
const parts = point const trimmed = point.trim().toUpperCase();
.split(',') if (!trimmed) {
.map(s => s.trim().toUpperCase()) setError('Please enter a valid acupuncture point code (e.g. ST-36, RN-6).');
.filter(Boolean);
if (parts.length === 0) {
setError('Please enter an acupuncture point code (e.g. ST-36, RN-6).');
return; return;
} }
if (currentPoints.includes(trimmed)) {
if (!forceRaw && parts.length === 1) { setError(`Point "${trimmed}" is already added to this prescription.`);
const suggested = suggestHyphenatedPoint(parts[0]);
if (suggested && suggested !== parts[0]) {
setPendingPointSuggestion({ raw: parts[0], suggested });
setError(null);
return;
}
}
const merged = [...currentPoints];
let addedAny = false;
for (const pt of parts) {
if (!merged.includes(pt)) {
merged.push(pt);
addedAny = true;
}
}
if (!addedAny) {
setError(`Point "${parts[0]}" is already added to this prescription.`);
return; return;
} }
setError(null); setError(null);
setPendingPointSuggestion(null); const updated = [...currentPoints, trimmed].join(', ');
const updated = merged.join(', ');
updateActivePattern(p => ({ updateActivePattern(p => ({
...p, ...p,
clinical_data: { clinical_data: {
@ -763,104 +625,56 @@ export const ModuleBuilderTabContent: React.FC = () => {
// Save Full Disease & Patterns with Granular Validation // Save Full Disease & Patterns with Granular Validation
const handleSaveFullDisease = async () => { const handleSaveFullDisease = async () => {
const showValidationError = (msg: string) => {
setError(msg);
window.scrollTo({ top: 0, behavior: 'smooth' });
};
if (!selectedCategoryCode) { if (!selectedCategoryCode) {
showValidationError('Please select or create a Category before saving.'); setError('Please select or create a Category before saving.');
return; return;
} }
const effectiveDiseaseName = diseaseName.trim(); const effectiveDiseaseName = diseaseName.trim();
if (!effectiveDiseaseName) { if (!effectiveDiseaseName) {
showValidationError('Please enter a Disease Name before saving.'); setError('Please enter a Disease Name before saving.');
return; return;
} }
if (!patterns || patterns.length === 0) { if (!patterns || patterns.length === 0) {
showValidationError('A disease must contain at least one clinical pattern before saving.'); setError('A disease must contain at least one clinical pattern before saving.');
return; return;
} }
// Auto-commit any uncommitted chip inputs on the active pattern before validating
let patternsToSave = patterns;
if (customPointInput.trim()) {
const rawPt = customPointInput.trim().toUpperCase();
const suggested = suggestHyphenatedPoint(rawPt);
if (suggested && suggested !== rawPt) {
setPendingPointSuggestion({ raw: rawPt, suggested });
showValidationError(
`Please confirm whether to use "${suggested}" or keep "${rawPt}" in the Acupuncture Prescription before saving.`,
);
return;
}
const pendingParts = rawPt.split(',').map(s => s.trim()).filter(Boolean);
const mergedPts = [...currentPoints];
for (const pt of pendingParts) {
if (!mergedPts.includes(pt)) mergedPts.push(pt);
}
const nextPts = mergedPts.join(', ');
patternsToSave = patternsToSave.map((p, idx) =>
idx === activePatternIndex
? { ...p, clinical_data: { ...p.clinical_data, acupuncture: { points: nextPts, method: p.clinical_data?.acupuncture?.method || '' } } }
: p,
);
setPatterns(patternsToSave);
setCustomPointInput('');
}
if (customTongueInput.trim()) {
const nextTongue = [...currentTongueChips, ...parseCommaChips(customTongueInput)].join(', ');
patternsToSave = patternsToSave.map((p, idx) =>
idx === activePatternIndex ? { ...p, clinical_data: { ...p.clinical_data, tongue: nextTongue } } : p,
);
setPatterns(patternsToSave);
setCustomTongueInput('');
}
if (customPulseInput.trim()) {
const nextPulse = [...currentPulseChips, ...parseCommaChips(customPulseInput)].join(', ');
patternsToSave = patternsToSave.map((p, idx) =>
idx === activePatternIndex ? { ...p, clinical_data: { ...p.clinical_data, pulse: nextPulse } } : p,
);
setPatterns(patternsToSave);
setCustomPulseInput('');
}
// Validate Pattern Names & Duplicates // Validate Pattern Names & Duplicates
const seenPatternNames = new Set<string>(); const seenPatternNames = new Set<string>();
for (let i = 0; i < patternsToSave.length; i++) { for (let i = 0; i < patterns.length; i++) {
const pName = patternsToSave[i]?.name?.trim(); const pName = patterns[i]?.name?.trim();
if (!pName) { if (!pName) {
setActivePatternIndex(i); setActivePatternIndex(i);
showValidationError(`Clinical Pattern #${i + 1} is missing a name. Please enter a pattern name.`); setError(`Clinical Pattern #${i + 1} is missing a name. Please enter a pattern name.`);
return; return;
} }
const lower = pName.toLowerCase(); const lower = pName.toLowerCase();
if (seenPatternNames.has(lower)) { if (seenPatternNames.has(lower)) {
setActivePatternIndex(i); setActivePatternIndex(i);
showValidationError(`Duplicate pattern name "${pName}". Each clinical pattern within a disease must have a distinct name.`); setError(`Duplicate pattern name "${pName}". Each clinical pattern within a disease must have a distinct name.`);
return; return;
} }
seenPatternNames.add(lower); seenPatternNames.add(lower);
} }
// Validate Symptoms exist // Validate Symptoms exist
for (let i = 0; i < patternsToSave.length; i++) { for (let i = 0; i < patterns.length; i++) {
const cleanSymptoms = (patternsToSave[i].clinical_data?.clinical_manifestations || []).filter(s => s && s.trim().length > 0); const cleanSymptoms = (patterns[i].clinical_data?.clinical_manifestations || []).filter(s => s && s.trim().length > 0);
if (cleanSymptoms.length === 0) { if (cleanSymptoms.length === 0) {
setActivePatternIndex(i); setActivePatternIndex(i);
showValidationError(`Pattern "${patternsToSave[i].name}" has no symptoms. Please enter at least one clinical symptom before saving.`); setError(`Pattern "${patterns[i].name}" has no symptoms. Please enter at least one clinical symptom before saving.`);
return; return;
} }
} }
// Validate Points formula exist // Validate Points formula exist
for (let i = 0; i < patternsToSave.length; i++) { for (let i = 0; i < patterns.length; i++) {
const pts = (patternsToSave[i].clinical_data?.acupuncture?.points || '').trim(); const pts = (patterns[i].clinical_data?.acupuncture?.points || '').trim();
if (!pts) { if (!pts) {
setActivePatternIndex(i); setActivePatternIndex(i);
showValidationError(`Pattern "${patternsToSave[i].name}" has no acupuncture points. Please select or add at least one point before saving.`); setError(`Pattern "${patterns[i].name}" has no acupuncture points. Please select or add at least one point before saving.`);
return; return;
} }
} }
@ -884,7 +698,7 @@ export const ModuleBuilderTabContent: React.FC = () => {
disease_code: effectiveDiseaseCode, disease_code: effectiveDiseaseCode,
name: effectiveDiseaseName, name: effectiveDiseaseName,
overview: diseaseOverview, overview: diseaseOverview,
patterns: patternsToSave.map((p, idx) => ({ patterns: patterns.map((p, idx) => ({
category_code: selectedCategoryCode, category_code: selectedCategoryCode,
disease_code: effectiveDiseaseCode, disease_code: effectiveDiseaseCode,
pattern_code: toSnakeCase(p.name?.trim() || `pattern_${idx + 1}`), pattern_code: toSnakeCase(p.name?.trim() || `pattern_${idx + 1}`),
@ -894,13 +708,7 @@ export const ModuleBuilderTabContent: React.FC = () => {
clinical_manifestations: (p.clinical_data?.clinical_manifestations || []).filter(s => s && s.trim().length > 0), clinical_manifestations: (p.clinical_data?.clinical_manifestations || []).filter(s => s && s.trim().length > 0),
tongue: (p.clinical_data?.tongue || '').trim(), tongue: (p.clinical_data?.tongue || '').trim(),
pulse: (p.clinical_data?.pulse || '').trim(), pulse: (p.clinical_data?.pulse || '').trim(),
treatment_principle: ( treatment_principle: (p.clinical_data?.treatment_principle || '').trim(),
Array.isArray(p.clinical_data?.treatment_principle)
? p.clinical_data.treatment_principle
: normalizeTreatmentPrinciple(p.clinical_data?.treatment_principle)
)
.map(tp => tp.trim())
.filter(Boolean),
acupuncture: { acupuncture: {
points: (p.clinical_data?.acupuncture?.points || '').trim(), points: (p.clinical_data?.acupuncture?.points || '').trim(),
method: (p.clinical_data?.acupuncture?.method || '').trim(), method: (p.clinical_data?.acupuncture?.method || '').trim(),
@ -1973,164 +1781,87 @@ export const ModuleBuilderTabContent: React.FC = () => {
{/* Tongue */} {/* Tongue */}
<div className="space-y-1.5"> <div className="space-y-1.5">
<label className="text-[10px] uppercase font-bold text-slate-500">👅 Tongue Diagnosis</label> <label className="text-[10px] uppercase font-bold text-slate-500">👅 Tongue Diagnosis</label>
<div className="flex flex-wrap items-center gap-1.5 min-h-[38px] p-2 bg-slate-50 border border-slate-200 rounded-xl"> <input
{currentTongueChips.map((chip, idx) => ( type="text"
<span value={activePattern.clinical_data?.tongue || ''}
key={idx} onChange={(e) =>
className="inline-flex items-center gap-1 px-2 py-0.5 rounded-lg bg-rose-50 border border-rose-200 text-rose-700 text-xs font-bold" updateActivePattern(p => ({
> ...p,
{chip} clinical_data: { ...p.clinical_data, tongue: e.target.value },
<button }))
type="button" }
onClick={() => handleRemoveDiagnosisChip('tongue', chip)} placeholder="e.g. Pale and Thin."
className="text-rose-400 hover:text-rose-700 cursor-pointer" className="w-full bg-slate-50 border border-slate-200 rounded-xl px-3 py-2 text-xs font-bold text-slate-800 focus:outline-none focus:border-indigo-500"
title="Remove tongue finding" />
>
<X className="h-3 w-3" />
</button>
</span>
))}
<input
type="text"
value={customTongueInput}
onChange={(e) => setCustomTongueInput(e.target.value)}
onKeyDown={(e) => {
if (e.key === 'Enter' || e.key === ',') {
e.preventDefault();
handleAddDiagnosisChip('tongue', customTongueInput);
}
}}
onBlur={() => {
if (customTongueInput.trim()) {
handleAddDiagnosisChip('tongue', customTongueInput);
}
}}
placeholder={currentTongueChips.length === 0 ? 'Type tongue finding and press Enter...' : '+ add...'}
className="flex-1 text-xs font-semibold text-slate-800 focus:outline-none bg-transparent min-w-[120px] px-1 py-0.5"
/>
</div>
<div className="flex flex-wrap gap-1.5 pt-1"> <div className="flex flex-wrap gap-1.5 pt-1">
{COMMON_TONGUE_SUGGESTIONS.map((t, idx) => { {COMMON_TONGUE_SUGGESTIONS.map((t, idx) => (
const isAdded = currentTongueChips.some(c => c.toLowerCase() === t.toLowerCase()); <button
return ( key={idx}
<button type="button"
key={idx} onClick={() =>
type="button" updateActivePattern(p => ({
disabled={isAdded} ...p,
onClick={() => handleAddDiagnosisChip('tongue', t)} clinical_data: { ...p.clinical_data, tongue: t },
className={`text-[10px] px-2 py-0.5 rounded-lg border font-medium transition-colors ${ }))
isAdded }
? 'bg-slate-200 text-slate-400 border-slate-200 cursor-default' className="text-[10px] px-2 py-0.5 rounded-lg bg-slate-100 hover:bg-slate-200 text-slate-600 font-medium"
: 'bg-slate-100 hover:bg-rose-50 border-slate-200 hover:border-rose-300 text-slate-600 hover:text-rose-700 cursor-pointer' >
}`} {t}
> </button>
+{t} ))}
</button>
);
})}
</div> </div>
</div> </div>
{/* Pulse */} {/* Pulse */}
<div className="space-y-1.5"> <div className="space-y-1.5">
<label className="text-[10px] uppercase font-bold text-slate-500">💓 Pulse Diagnosis</label> <label className="text-[10px] uppercase font-bold text-slate-500">💓 Pulse Diagnosis</label>
<div className="flex flex-wrap items-center gap-1.5 min-h-[38px] p-2 bg-slate-50 border border-slate-200 rounded-xl"> <input
{currentPulseChips.map((chip, idx) => ( type="text"
<span value={activePattern.clinical_data?.pulse || ''}
key={idx} onChange={(e) =>
className="inline-flex items-center gap-1 px-2 py-0.5 rounded-lg bg-pink-50 border border-pink-200 text-pink-700 text-xs font-bold" updateActivePattern(p => ({
> ...p,
{chip} clinical_data: { ...p.clinical_data, pulse: e.target.value },
<button }))
type="button" }
onClick={() => handleRemoveDiagnosisChip('pulse', chip)} placeholder="e.g. Choppy."
className="text-pink-400 hover:text-pink-700 cursor-pointer" className="w-full bg-slate-50 border border-slate-200 rounded-xl px-3 py-2 text-xs font-bold text-slate-800 focus:outline-none focus:border-indigo-500"
title="Remove pulse finding" />
>
<X className="h-3 w-3" />
</button>
</span>
))}
<input
type="text"
value={customPulseInput}
onChange={(e) => setCustomPulseInput(e.target.value)}
onKeyDown={(e) => {
if (e.key === 'Enter' || e.key === ',') {
e.preventDefault();
handleAddDiagnosisChip('pulse', customPulseInput);
}
}}
onBlur={() => {
if (customPulseInput.trim()) {
handleAddDiagnosisChip('pulse', customPulseInput);
}
}}
placeholder={currentPulseChips.length === 0 ? 'Type pulse finding and press Enter...' : '+ add...'}
className="flex-1 text-xs font-semibold text-slate-800 focus:outline-none bg-transparent min-w-[120px] px-1 py-0.5"
/>
</div>
<div className="flex flex-wrap gap-1.5 pt-1"> <div className="flex flex-wrap gap-1.5 pt-1">
{COMMON_PULSE_SUGGESTIONS.map((pls, idx) => { {COMMON_PULSE_SUGGESTIONS.map((pls, idx) => (
const isAdded = currentPulseChips.some(c => c.toLowerCase() === pls.toLowerCase()); <button
return ( key={idx}
<button type="button"
key={idx} onClick={() =>
type="button" updateActivePattern(p => ({
disabled={isAdded} ...p,
onClick={() => handleAddDiagnosisChip('pulse', pls)} clinical_data: { ...p.clinical_data, pulse: pls },
className={`text-[10px] px-2 py-0.5 rounded-lg border font-medium transition-colors ${ }))
isAdded }
? 'bg-slate-200 text-slate-400 border-slate-200 cursor-default' className="text-[10px] px-2 py-0.5 rounded-lg bg-slate-100 hover:bg-slate-200 text-slate-600 font-medium"
: 'bg-slate-100 hover:bg-pink-50 border-slate-200 hover:border-pink-300 text-slate-600 hover:text-pink-700 cursor-pointer' >
}`} {pls}
> </button>
+{pls} ))}
</button>
);
})}
</div> </div>
</div> </div>
</div> </div>
{/* Treatment Principle (Rows like Clinical Manifestations) */} {/* Treatment Principle */}
<div className="space-y-2"> <div className="space-y-1">
<div className="flex justify-between items-center"> <label className="text-[10px] uppercase font-bold text-slate-500">🎯 Treatment Principle</label>
<label className="text-[10px] uppercase font-bold text-slate-500"> <input
🎯 Treatment Principle ({activePrinciples.length}) type="text"
</label> value={activePattern.clinical_data?.treatment_principle || ''}
<button onChange={(e) =>
type="button" updateActivePattern(p => ({
onClick={handleAddPrinciple} ...p,
className="text-indigo-600 hover:text-indigo-800 text-[11px] font-bold flex items-center gap-1 cursor-pointer" clinical_data: { ...p.clinical_data, treatment_principle: e.target.value },
> }))
<Plus className="h-3 w-3" /> Add Principle }
</button> placeholder="e.g. Tonify Qi, nourish Blood, stop pain."
</div> className="w-full bg-slate-50 border border-slate-200 rounded-xl px-3 py-2 text-xs font-bold text-slate-800 focus:outline-none focus:border-indigo-500"
<div className="space-y-2"> />
{activePrinciples.map((principle, pIdx) => (
<div key={pIdx} className="flex items-center gap-2">
<span className="text-[10px] font-mono text-slate-400 w-4 text-right">{pIdx + 1}.</span>
<input
type="text"
value={principle}
onChange={(e) => handlePrincipleChange(pIdx, e.target.value)}
placeholder="e.g. Tonify Qi and nourish Blood"
className="flex-1 bg-slate-50 border border-slate-200 rounded-xl px-3 py-1.5 text-xs font-medium text-slate-800 focus:outline-none focus:border-indigo-500"
/>
{activePrinciples.length > 1 && (
<button
type="button"
onClick={() => handleRemovePrinciple(pIdx)}
className="p-1.5 text-slate-400 hover:text-rose-500 transition-colors cursor-pointer"
title="Remove principle"
>
<Trash2 className="h-3.5 w-3.5" />
</button>
)}
</div>
))}
</div>
</div> </div>
{/* Acupuncture Formula & Points Chips */} {/* Acupuncture Formula & Points Chips */}
@ -2162,61 +1893,17 @@ export const ModuleBuilderTabContent: React.FC = () => {
<input <input
type="text" type="text"
value={customPointInput} value={customPointInput}
onChange={(e) => { onChange={(e) => setCustomPointInput(e.target.value)}
setCustomPointInput(e.target.value);
if (pendingPointSuggestion) setPendingPointSuggestion(null);
}}
onKeyDown={(e) => { onKeyDown={(e) => {
if (e.key === 'Enter' || e.key === ',') { if (e.key === 'Enter') {
e.preventDefault(); e.preventDefault();
handleAddPointChip(customPointInput); handleAddPointChip(customPointInput);
} }
}} }}
onBlur={() => {
if (customPointInput.trim()) {
handleAddPointChip(customPointInput);
}
}}
placeholder={currentPoints.length === 0 ? 'Type point (e.g. RN-6) and hit Enter...' : '+ add...'} placeholder={currentPoints.length === 0 ? 'Type point (e.g. RN-6) and hit Enter...' : '+ add...'}
className="flex-1 text-xs font-semibold text-slate-800 focus:outline-none bg-transparent min-w-[120px] px-1 py-0.5" className="text-xs font-semibold text-slate-800 focus:outline-none bg-transparent min-w-[120px] px-1 py-0.5"
/> />
{customPointInput.trim() && (
<button
type="button"
onMouseDown={(e) => {
e.preventDefault();
handleAddPointChip(customPointInput);
}}
className="px-2 py-0.5 rounded-lg bg-indigo-600 text-white text-[10px] font-bold hover:bg-indigo-500 cursor-pointer"
>
+ Add
</button>
)}
</div> </div>
{pendingPointSuggestion && (
<div className="flex flex-wrap items-center justify-between gap-2 px-3 py-2 rounded-xl bg-amber-50 border border-amber-200 text-xs text-amber-900">
<span>
Acupuncture points use a hyphen format. Did you mean{' '}
<strong className="font-mono">{pendingPointSuggestion.suggested}</strong>?
</span>
<div className="flex items-center gap-1.5">
<button
type="button"
onClick={() => handleAddPointChip(pendingPointSuggestion.suggested, true)}
className="px-2.5 py-1 rounded-lg bg-amber-600 hover:bg-amber-700 text-white text-[11px] font-bold cursor-pointer"
>
Use {pendingPointSuggestion.suggested}
</button>
<button
type="button"
onClick={() => handleAddPointChip(pendingPointSuggestion.raw, true)}
className="px-2.5 py-1 rounded-lg bg-white hover:bg-amber-100 text-amber-800 border border-amber-300 text-[11px] font-bold cursor-pointer"
>
Keep {pendingPointSuggestion.raw}
</button>
</div>
</div>
)}
</div> </div>
{/* Quick Suggestions for Points */} {/* Quick Suggestions for Points */}
@ -2449,23 +2136,10 @@ export const ModuleBuilderTabContent: React.FC = () => {
{/* Treatment Principle */} {/* Treatment Principle */}
<div className="p-3 bg-white rounded-xl border border-amber-200 text-xs"> <div className="p-3 bg-white rounded-xl border border-amber-200 text-xs">
<span className="text-[10px] font-black uppercase text-amber-600 block mb-1">Treatment Principle</span> <span className="text-[10px] font-black uppercase text-amber-600 block mb-0.5">Treatment Principle</span>
{(() => { <span className="font-bold text-slate-800">
const tpList = normalizeTreatmentPrinciple( {patterns[previewPatternIdx].clinical_data?.treatment_principle || '—'}
patterns[previewPatternIdx].clinical_data?.treatment_principle, </span>
).filter(Boolean);
if (tpList.length === 0) return <span className="font-bold text-slate-400">—</span>;
return (
<ul className="space-y-1">
{tpList.map((tp, idx) => (
<li key={idx} className="font-bold text-slate-800 flex items-start gap-1.5">
<span className="text-amber-500 mt-0.5">•</span>
<span>{tp}</span>
</li>
))}
</ul>
);
})()}
</div> </div>
{/* Acupuncture Prescription */} {/* Acupuncture Prescription */}

View File

@ -44,7 +44,7 @@ export interface PatternClinicalData {
clinical_manifestations: string[]; clinical_manifestations: string[];
tongue: string; tongue: string;
pulse: string; pulse: string;
treatment_principle: string[] | string; treatment_principle: string;
acupuncture: { acupuncture: {
points: string; points: string;
method: string; method: string;