feat(m0013): render clinical manifestations using BulletList in QiBloodDetailRenderer
This commit is contained in:
parent
abcb9823c2
commit
2a2c9ebc80
|
|
@ -9,8 +9,9 @@ import { BackActionContext } from "../../context/BackActionContext";
|
|||
import { ContentLinkAttributeSections } from "../shared/ContentLinkAttributeSections";
|
||||
import { Hero } from "../shared/Hero";
|
||||
import { SectionCard } from "../shared/SectionCard";
|
||||
import { BulletList } from "../shared/BulletList";
|
||||
import { Paragraphs } from "../shared/Paragraphs";
|
||||
import { asString, humanizeKey } from "../helpers/value";
|
||||
import { asString, asStringArray, humanizeKey } from "../helpers/value";
|
||||
|
||||
const RESERVED_METADATA_KEYS = new Set([
|
||||
"name",
|
||||
|
|
@ -36,12 +37,46 @@ interface PatternItem {
|
|||
|
||||
interface ParsedNode {
|
||||
overview?: string;
|
||||
clinical?: string;
|
||||
clinicalItems: string[];
|
||||
analysis?: string;
|
||||
subItems: PatternItem[];
|
||||
otherTextEntries: Array<{ key: string; text: string }>;
|
||||
}
|
||||
|
||||
function parseClinicalManifestations(raw: unknown): string[] {
|
||||
if (Array.isArray(raw)) {
|
||||
return asStringArray(raw);
|
||||
}
|
||||
const text = asString(raw).trim();
|
||||
if (!text) return [];
|
||||
|
||||
// Check if string is semicolon or newline separated
|
||||
if (text.includes("\n")) {
|
||||
return text
|
||||
.split("\n")
|
||||
.map((s) => s.replace(/^[•\-\*\d+\.]\s*/, "").trim())
|
||||
.filter((s) => s.length > 0);
|
||||
}
|
||||
|
||||
// If semicolon separated
|
||||
if (text.includes(";")) {
|
||||
return text
|
||||
.split(";")
|
||||
.map((s) => s.trim().replace(/^and\s+/i, ""))
|
||||
.filter((s) => s.length > 0);
|
||||
}
|
||||
|
||||
// Split by comma outside parentheses
|
||||
const parts = text.split(/,\s*(?![^()]*\))/);
|
||||
if (parts.length > 1) {
|
||||
return parts
|
||||
.map((s) => s.trim().replace(/\.$/, "").replace(/^and\s+/i, ""))
|
||||
.filter((s) => s.length > 0);
|
||||
}
|
||||
|
||||
return [text];
|
||||
}
|
||||
|
||||
function extractCategoryOverview(data: Record<string, unknown>, categoryCode: string): string {
|
||||
const normalizedCode = categoryCode.toLowerCase().replace(/[^a-z0-9_]/g, "_");
|
||||
|
||||
|
|
@ -121,12 +156,13 @@ function parseNode(raw: Record<string, unknown>): ParsedNode {
|
|||
(typeof raw.content === "string" ? raw.content.trim() : undefined) ||
|
||||
(typeof raw.overview === "string" ? raw.overview.trim() : undefined);
|
||||
|
||||
const clinical =
|
||||
asString(contentTarget["Clinical manifestations"]) ||
|
||||
asString(contentTarget.clinical_manifestations) ||
|
||||
asString(contentTarget.clinical_manifestation) ||
|
||||
asString(raw["Clinical manifestations"]) ||
|
||||
asString(raw.clinical_manifestations);
|
||||
const clinicalRaw =
|
||||
contentTarget["Clinical manifestations"] ??
|
||||
contentTarget.clinical_manifestations ??
|
||||
contentTarget.clinical_manifestation ??
|
||||
raw["Clinical manifestations"] ??
|
||||
raw.clinical_manifestations;
|
||||
const clinicalItems = parseClinicalManifestations(clinicalRaw);
|
||||
|
||||
const analysis =
|
||||
asString(contentTarget.Analysis) ||
|
||||
|
|
@ -161,7 +197,7 @@ function parseNode(raw: Record<string, unknown>): ParsedNode {
|
|||
|
||||
return {
|
||||
overview: overview || undefined,
|
||||
clinical: clinical || undefined,
|
||||
clinicalItems,
|
||||
analysis: analysis || undefined,
|
||||
subItems,
|
||||
otherTextEntries,
|
||||
|
|
@ -227,9 +263,9 @@ export function QiBloodDetailRenderer({
|
|||
) : null}
|
||||
|
||||
{/* 2. Clinical Manifestations Card */}
|
||||
{parsed.clinical ? (
|
||||
{parsed.clinicalItems.length > 0 ? (
|
||||
<SectionCard title="Clinical Manifestations">
|
||||
<Paragraphs items={[parsed.clinical]} />
|
||||
<BulletList items={parsed.clinicalItems} />
|
||||
</SectionCard>
|
||||
) : null}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue