feat(module-builder): multi-select Tongue/Pulse chips, Treatment Principle rows, point auto-commit & RN-6 prompt

This commit is contained in:
Urvish Prajapati 2026-12-04 13:36:06 +05:30
parent 6c59b0ce3a
commit b1cdd222ca
2 changed files with 438 additions and 112 deletions

View File

@ -15,22 +15,22 @@ import {
import { ErrorBoundary } from '../common/ErrorBoundary';
const COMMON_TONGUE_SUGGESTIONS = [
'Pale and Thin.',
'Purple.',
'Normal.',
'Red with yellow coat.',
'Pale with tooth marks.',
'Slightly Red sides or normal.',
'Pale and Thin',
'Purple',
'Normal',
'Red with yellow coat',
'Pale with tooth marks',
'Slightly Red sides or normal',
];
const COMMON_PULSE_SUGGESTIONS = [
'Choppy.',
'Wiry.',
'Deep and Wiry.',
'Deep and Weak.',
'Choppy or Fine.',
'Rapid and Slippery.',
'Floating.',
'Choppy',
'Wiry',
'Deep and Wiry',
'Deep and Weak',
'Choppy or Fine',
'Rapid and Slippery',
'Floating',
];
const COMMON_POINT_SUGGESTIONS = [
@ -66,6 +66,22 @@ const formatApiError = (err: any, fallback: string): string => {
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 => ({
module_code: moduleCode,
category_code: catCode,
@ -77,7 +93,7 @@ const createBlankPattern = (moduleCode: string, catCode: string, disCode: string
clinical_manifestations: [''],
tongue: '',
pulse: '',
treatment_principle: '',
treatment_principle: [''],
acupuncture: { points: '', method: '' },
explanation: [''],
},
@ -132,8 +148,11 @@ export const ModuleBuilderTabContent: React.FC = () => {
const [newDiseaseName, setNewDiseaseName] = useState('');
const [modalDisError, setModalDisError] = useState<string | null>(null);
// Point input state
// Chip & Point input state
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
const fetchModules = async (selectCode?: string) => {
@ -262,7 +281,7 @@ export const ModuleBuilderTabContent: React.FC = () => {
: [''],
tongue: p.clinical_data?.tongue || '',
pulse: p.clinical_data?.pulse || '',
treatment_principle: p.clinical_data?.treatment_principle || '',
treatment_principle: normalizeTreatmentPrinciple(p.clinical_data?.treatment_principle),
acupuncture: {
points: p.clinical_data?.acupuncture?.points || '',
method: p.clinical_data?.acupuncture?.method || '',
@ -488,7 +507,7 @@ export const ModuleBuilderTabContent: React.FC = () => {
clinical_manifestations: [''],
tongue: '',
pulse: '',
treatment_principle: '',
treatment_principle: [''],
acupuncture: { points: '', method: '' },
explanation: [''],
},
@ -546,24 +565,143 @@ 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)
const currentPoints = (activePattern?.clinical_data?.acupuncture?.points || '')
.split(',')
.map(s => s.trim())
.filter(Boolean);
const handleAddPointChip = (point: string) => {
const trimmed = point.trim().toUpperCase();
if (!trimmed) {
setError('Please enter a valid acupuncture point code (e.g. ST-36, RN-6).');
const handleAddPointChip = (point: string, forceRaw = false) => {
const parts = point
.split(',')
.map(s => s.trim().toUpperCase())
.filter(Boolean);
if (parts.length === 0) {
setError('Please enter an acupuncture point code (e.g. ST-36, RN-6).');
return;
}
if (currentPoints.includes(trimmed)) {
setError(`Point "${trimmed}" is already added to this prescription.`);
if (!forceRaw && parts.length === 1) {
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;
}
setError(null);
const updated = [...currentPoints, trimmed].join(', ');
setPendingPointSuggestion(null);
const updated = merged.join(', ');
updateActivePattern(p => ({
...p,
clinical_data: {
@ -625,56 +763,104 @@ export const ModuleBuilderTabContent: React.FC = () => {
// Save Full Disease & Patterns with Granular Validation
const handleSaveFullDisease = async () => {
const showValidationError = (msg: string) => {
setError(msg);
window.scrollTo({ top: 0, behavior: 'smooth' });
};
if (!selectedCategoryCode) {
setError('Please select or create a Category before saving.');
showValidationError('Please select or create a Category before saving.');
return;
}
const effectiveDiseaseName = diseaseName.trim();
if (!effectiveDiseaseName) {
setError('Please enter a Disease Name before saving.');
showValidationError('Please enter a Disease Name before saving.');
return;
}
if (!patterns || patterns.length === 0) {
setError('A disease must contain at least one clinical pattern before saving.');
showValidationError('A disease must contain at least one clinical pattern before saving.');
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
const seenPatternNames = new Set<string>();
for (let i = 0; i < patterns.length; i++) {
const pName = patterns[i]?.name?.trim();
for (let i = 0; i < patternsToSave.length; i++) {
const pName = patternsToSave[i]?.name?.trim();
if (!pName) {
setActivePatternIndex(i);
setError(`Clinical Pattern #${i + 1} is missing a name. Please enter a pattern name.`);
showValidationError(`Clinical Pattern #${i + 1} is missing a name. Please enter a pattern name.`);
return;
}
const lower = pName.toLowerCase();
if (seenPatternNames.has(lower)) {
setActivePatternIndex(i);
setError(`Duplicate pattern name "${pName}". Each clinical pattern within a disease must have a distinct name.`);
showValidationError(`Duplicate pattern name "${pName}". Each clinical pattern within a disease must have a distinct name.`);
return;
}
seenPatternNames.add(lower);
}
// Validate Symptoms exist
for (let i = 0; i < patterns.length; i++) {
const cleanSymptoms = (patterns[i].clinical_data?.clinical_manifestations || []).filter(s => s && s.trim().length > 0);
for (let i = 0; i < patternsToSave.length; i++) {
const cleanSymptoms = (patternsToSave[i].clinical_data?.clinical_manifestations || []).filter(s => s && s.trim().length > 0);
if (cleanSymptoms.length === 0) {
setActivePatternIndex(i);
setError(`Pattern "${patterns[i].name}" has no symptoms. Please enter at least one clinical symptom before saving.`);
showValidationError(`Pattern "${patternsToSave[i].name}" has no symptoms. Please enter at least one clinical symptom before saving.`);
return;
}
}
// Validate Points formula exist
for (let i = 0; i < patterns.length; i++) {
const pts = (patterns[i].clinical_data?.acupuncture?.points || '').trim();
for (let i = 0; i < patternsToSave.length; i++) {
const pts = (patternsToSave[i].clinical_data?.acupuncture?.points || '').trim();
if (!pts) {
setActivePatternIndex(i);
setError(`Pattern "${patterns[i].name}" has no acupuncture points. Please select or add at least one point before saving.`);
showValidationError(`Pattern "${patternsToSave[i].name}" has no acupuncture points. Please select or add at least one point before saving.`);
return;
}
}
@ -698,7 +884,7 @@ export const ModuleBuilderTabContent: React.FC = () => {
disease_code: effectiveDiseaseCode,
name: effectiveDiseaseName,
overview: diseaseOverview,
patterns: patterns.map((p, idx) => ({
patterns: patternsToSave.map((p, idx) => ({
category_code: selectedCategoryCode,
disease_code: effectiveDiseaseCode,
pattern_code: toSnakeCase(p.name?.trim() || `pattern_${idx + 1}`),
@ -708,7 +894,13 @@ export const ModuleBuilderTabContent: React.FC = () => {
clinical_manifestations: (p.clinical_data?.clinical_manifestations || []).filter(s => s && s.trim().length > 0),
tongue: (p.clinical_data?.tongue || '').trim(),
pulse: (p.clinical_data?.pulse || '').trim(),
treatment_principle: (p.clinical_data?.treatment_principle || '').trim(),
treatment_principle: (
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: {
points: (p.clinical_data?.acupuncture?.points || '').trim(),
method: (p.clinical_data?.acupuncture?.method || '').trim(),
@ -1781,87 +1973,164 @@ export const ModuleBuilderTabContent: React.FC = () => {
{/* Tongue */}
<div className="space-y-1.5">
<label className="text-[10px] uppercase font-bold text-slate-500">👅 Tongue Diagnosis</label>
<input
type="text"
value={activePattern.clinical_data?.tongue || ''}
onChange={(e) =>
updateActivePattern(p => ({
...p,
clinical_data: { ...p.clinical_data, tongue: e.target.value },
}))
}
placeholder="e.g. Pale and Thin."
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="flex flex-wrap gap-1.5 pt-1">
{COMMON_TONGUE_SUGGESTIONS.map((t, idx) => (
<button
<div className="flex flex-wrap items-center gap-1.5 min-h-[38px] p-2 bg-slate-50 border border-slate-200 rounded-xl">
{currentTongueChips.map((chip, idx) => (
<span
key={idx}
type="button"
onClick={() =>
updateActivePattern(p => ({
...p,
clinical_data: { ...p.clinical_data, tongue: t },
}))
}
className="text-[10px] px-2 py-0.5 rounded-lg bg-slate-100 hover:bg-slate-200 text-slate-600 font-medium"
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"
>
{t}
</button>
{chip}
<button
type="button"
onClick={() => handleRemoveDiagnosisChip('tongue', chip)}
className="text-rose-400 hover:text-rose-700 cursor-pointer"
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">
{COMMON_TONGUE_SUGGESTIONS.map((t, idx) => {
const isAdded = currentTongueChips.some(c => c.toLowerCase() === t.toLowerCase());
return (
<button
key={idx}
type="button"
disabled={isAdded}
onClick={() => handleAddDiagnosisChip('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'
: '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>
);
})}
</div>
</div>
{/* Pulse */}
<div className="space-y-1.5">
<label className="text-[10px] uppercase font-bold text-slate-500">💓 Pulse Diagnosis</label>
<input
type="text"
value={activePattern.clinical_data?.pulse || ''}
onChange={(e) =>
updateActivePattern(p => ({
...p,
clinical_data: { ...p.clinical_data, pulse: e.target.value },
}))
}
placeholder="e.g. Choppy."
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="flex flex-wrap gap-1.5 pt-1">
{COMMON_PULSE_SUGGESTIONS.map((pls, idx) => (
<button
<div className="flex flex-wrap items-center gap-1.5 min-h-[38px] p-2 bg-slate-50 border border-slate-200 rounded-xl">
{currentPulseChips.map((chip, idx) => (
<span
key={idx}
type="button"
onClick={() =>
updateActivePattern(p => ({
...p,
clinical_data: { ...p.clinical_data, pulse: pls },
}))
}
className="text-[10px] px-2 py-0.5 rounded-lg bg-slate-100 hover:bg-slate-200 text-slate-600 font-medium"
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"
>
{pls}
</button>
{chip}
<button
type="button"
onClick={() => handleRemoveDiagnosisChip('pulse', chip)}
className="text-pink-400 hover:text-pink-700 cursor-pointer"
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">
{COMMON_PULSE_SUGGESTIONS.map((pls, idx) => {
const isAdded = currentPulseChips.some(c => c.toLowerCase() === pls.toLowerCase());
return (
<button
key={idx}
type="button"
disabled={isAdded}
onClick={() => handleAddDiagnosisChip('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'
: '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>
);
})}
</div>
</div>
</div>
{/* Treatment Principle */}
<div className="space-y-1">
<label className="text-[10px] uppercase font-bold text-slate-500">🎯 Treatment Principle</label>
<input
type="text"
value={activePattern.clinical_data?.treatment_principle || ''}
onChange={(e) =>
updateActivePattern(p => ({
...p,
clinical_data: { ...p.clinical_data, treatment_principle: e.target.value },
}))
}
placeholder="e.g. Tonify Qi, nourish Blood, stop pain."
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"
/>
{/* Treatment Principle (Rows like Clinical Manifestations) */}
<div className="space-y-2">
<div className="flex justify-between items-center">
<label className="text-[10px] uppercase font-bold text-slate-500">
🎯 Treatment Principle ({activePrinciples.length})
</label>
<button
type="button"
onClick={handleAddPrinciple}
className="text-indigo-600 hover:text-indigo-800 text-[11px] font-bold flex items-center gap-1 cursor-pointer"
>
<Plus className="h-3 w-3" /> Add Principle
</button>
</div>
<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>
{/* Acupuncture Formula & Points Chips */}
@ -1893,17 +2162,61 @@ export const ModuleBuilderTabContent: React.FC = () => {
<input
type="text"
value={customPointInput}
onChange={(e) => setCustomPointInput(e.target.value)}
onChange={(e) => {
setCustomPointInput(e.target.value);
if (pendingPointSuggestion) setPendingPointSuggestion(null);
}}
onKeyDown={(e) => {
if (e.key === 'Enter') {
if (e.key === 'Enter' || e.key === ',') {
e.preventDefault();
handleAddPointChip(customPointInput);
}
}}
onBlur={() => {
if (customPointInput.trim()) {
handleAddPointChip(customPointInput);
}
}}
placeholder={currentPoints.length === 0 ? 'Type point (e.g. RN-6) and hit Enter...' : '+ add...'}
className="text-xs font-semibold text-slate-800 focus:outline-none bg-transparent min-w-[120px] px-1 py-0.5"
className="flex-1 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>
{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>
{/* Quick Suggestions for Points */}
@ -2136,10 +2449,23 @@ export const ModuleBuilderTabContent: React.FC = () => {
{/* Treatment Principle */}
<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-0.5">Treatment Principle</span>
<span className="font-bold text-slate-800">
{patterns[previewPatternIdx].clinical_data?.treatment_principle || '—'}
</span>
<span className="text-[10px] font-black uppercase text-amber-600 block mb-1">Treatment Principle</span>
{(() => {
const tpList = normalizeTreatmentPrinciple(
patterns[previewPatternIdx].clinical_data?.treatment_principle,
).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>
{/* Acupuncture Prescription */}

View File

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