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 { ContentLinkAttributeSections } from "../shared/ContentLinkAttributeSections";
|
||||||
import { Hero } from "../shared/Hero";
|
import { Hero } from "../shared/Hero";
|
||||||
import { SectionCard } from "../shared/SectionCard";
|
import { SectionCard } from "../shared/SectionCard";
|
||||||
|
import { BulletList } from "../shared/BulletList";
|
||||||
import { Paragraphs } from "../shared/Paragraphs";
|
import { Paragraphs } from "../shared/Paragraphs";
|
||||||
import { asString, humanizeKey } from "../helpers/value";
|
import { asString, asStringArray, humanizeKey } from "../helpers/value";
|
||||||
|
|
||||||
const RESERVED_METADATA_KEYS = new Set([
|
const RESERVED_METADATA_KEYS = new Set([
|
||||||
"name",
|
"name",
|
||||||
|
|
@ -36,12 +37,46 @@ interface PatternItem {
|
||||||
|
|
||||||
interface ParsedNode {
|
interface ParsedNode {
|
||||||
overview?: string;
|
overview?: string;
|
||||||
clinical?: string;
|
clinicalItems: string[];
|
||||||
analysis?: string;
|
analysis?: string;
|
||||||
subItems: PatternItem[];
|
subItems: PatternItem[];
|
||||||
otherTextEntries: Array<{ key: string; text: string }>;
|
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 {
|
function extractCategoryOverview(data: Record<string, unknown>, categoryCode: string): string {
|
||||||
const normalizedCode = categoryCode.toLowerCase().replace(/[^a-z0-9_]/g, "_");
|
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.content === "string" ? raw.content.trim() : undefined) ||
|
||||||
(typeof raw.overview === "string" ? raw.overview.trim() : undefined);
|
(typeof raw.overview === "string" ? raw.overview.trim() : undefined);
|
||||||
|
|
||||||
const clinical =
|
const clinicalRaw =
|
||||||
asString(contentTarget["Clinical manifestations"]) ||
|
contentTarget["Clinical manifestations"] ??
|
||||||
asString(contentTarget.clinical_manifestations) ||
|
contentTarget.clinical_manifestations ??
|
||||||
asString(contentTarget.clinical_manifestation) ||
|
contentTarget.clinical_manifestation ??
|
||||||
asString(raw["Clinical manifestations"]) ||
|
raw["Clinical manifestations"] ??
|
||||||
asString(raw.clinical_manifestations);
|
raw.clinical_manifestations;
|
||||||
|
const clinicalItems = parseClinicalManifestations(clinicalRaw);
|
||||||
|
|
||||||
const analysis =
|
const analysis =
|
||||||
asString(contentTarget.Analysis) ||
|
asString(contentTarget.Analysis) ||
|
||||||
|
|
@ -161,7 +197,7 @@ function parseNode(raw: Record<string, unknown>): ParsedNode {
|
||||||
|
|
||||||
return {
|
return {
|
||||||
overview: overview || undefined,
|
overview: overview || undefined,
|
||||||
clinical: clinical || undefined,
|
clinicalItems,
|
||||||
analysis: analysis || undefined,
|
analysis: analysis || undefined,
|
||||||
subItems,
|
subItems,
|
||||||
otherTextEntries,
|
otherTextEntries,
|
||||||
|
|
@ -227,9 +263,9 @@ export function QiBloodDetailRenderer({
|
||||||
) : null}
|
) : null}
|
||||||
|
|
||||||
{/* 2. Clinical Manifestations Card */}
|
{/* 2. Clinical Manifestations Card */}
|
||||||
{parsed.clinical ? (
|
{parsed.clinicalItems.length > 0 ? (
|
||||||
<SectionCard title="Clinical Manifestations">
|
<SectionCard title="Clinical Manifestations">
|
||||||
<Paragraphs items={[parsed.clinical]} />
|
<BulletList items={parsed.clinicalItems} />
|
||||||
</SectionCard>
|
</SectionCard>
|
||||||
) : null}
|
) : null}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue