qi-blood-fluids #74
|
|
@ -16,7 +16,7 @@ import { useContentSearchInfiniteQuery } from "../../hooks/use-content-search-in
|
||||||
interface PatternData {
|
interface PatternData {
|
||||||
name: string;
|
name: string;
|
||||||
code?: string;
|
code?: string;
|
||||||
clinicalManifestation?: string[];
|
clinicalManifestation?: string | string[];
|
||||||
pathology?: string;
|
pathology?: string;
|
||||||
treatment?: string;
|
treatment?: string;
|
||||||
}
|
}
|
||||||
|
|
@ -335,10 +335,15 @@ export function ThreeBurnersDetailRenderer({
|
||||||
<Hero title={activePatternData.name} />
|
<Hero title={activePatternData.name} />
|
||||||
|
|
||||||
{/* 1. Clinical Manifestations Card */}
|
{/* 1. Clinical Manifestations Card */}
|
||||||
{activePatternData.clinicalManifestation &&
|
{activePatternData.clinicalManifestation ? (
|
||||||
activePatternData.clinicalManifestation.length > 0 ? (
|
|
||||||
<SectionCard title="Clinical Manifestations">
|
<SectionCard title="Clinical Manifestations">
|
||||||
<BulletList items={activePatternData.clinicalManifestation} />
|
<BulletList
|
||||||
|
items={
|
||||||
|
Array.isArray(activePatternData.clinicalManifestation)
|
||||||
|
? activePatternData.clinicalManifestation
|
||||||
|
: parseBullets(activePatternData.clinicalManifestation)
|
||||||
|
}
|
||||||
|
/>
|
||||||
</SectionCard>
|
</SectionCard>
|
||||||
) : null}
|
) : null}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -9,24 +9,40 @@ import { BackActionContext } from "../../context/BackActionContext";
|
||||||
import { Hero } from "../shared/Hero";
|
import { Hero } from "../shared/Hero";
|
||||||
import { SectionCard } from "../shared/SectionCard";
|
import { SectionCard } from "../shared/SectionCard";
|
||||||
import { Paragraphs } from "../shared/Paragraphs";
|
import { Paragraphs } from "../shared/Paragraphs";
|
||||||
import { asString } from "../helpers/value";
|
import { BulletList } from "../shared/BulletList";
|
||||||
|
import { asString, asStringArray } from "../helpers/value";
|
||||||
import { useContentSearchInfiniteQuery } from "../../hooks/use-content-search-infinite-query";
|
import { useContentSearchInfiniteQuery } from "../../hooks/use-content-search-infinite-query";
|
||||||
|
|
||||||
interface ConnectingChannelDetails {
|
interface ConnectingChannelDetails {
|
||||||
empty?: string;
|
empty?: string[];
|
||||||
full?: string;
|
full?: string[];
|
||||||
}
|
}
|
||||||
|
|
||||||
interface ChannelData {
|
interface ChannelData {
|
||||||
name: string;
|
name: string;
|
||||||
code?: string;
|
code?: string;
|
||||||
mainChannel?: string;
|
mainChannel?: string[];
|
||||||
connectingChannel?: ConnectingChannelDetails | string;
|
connectingChannel?: ConnectingChannelDetails | string[];
|
||||||
muscleChannel?: string;
|
muscleChannel?: string[];
|
||||||
greatConnectingChannelOfSpleen?: string;
|
greatConnectingChannelOfSpleen?: string[];
|
||||||
}
|
}
|
||||||
|
|
||||||
const FALLBACK_CHANNELS: ChannelData[] = [
|
interface RawChannelData {
|
||||||
|
name: string;
|
||||||
|
code?: string;
|
||||||
|
mainChannel?: string | string[];
|
||||||
|
connectingChannel?:
|
||||||
|
| {
|
||||||
|
empty?: string | string[];
|
||||||
|
full?: string | string[];
|
||||||
|
}
|
||||||
|
| string
|
||||||
|
| string[];
|
||||||
|
muscleChannel?: string | string[];
|
||||||
|
greatConnectingChannelOfSpleen?: string | string[];
|
||||||
|
}
|
||||||
|
|
||||||
|
const FALLBACK_CHANNELS: RawChannelData[] = [
|
||||||
{
|
{
|
||||||
name: "Lungs",
|
name: "Lungs",
|
||||||
code: "lungs",
|
code: "lungs",
|
||||||
|
|
@ -217,23 +233,74 @@ function normalizeKey(str: string): string {
|
||||||
return str.toLowerCase().replace(/[^a-z0-9]/g, "");
|
return str.toLowerCase().replace(/[^a-z0-9]/g, "");
|
||||||
}
|
}
|
||||||
|
|
||||||
function parseConnectingChannel(val: unknown): ConnectingChannelDetails | string | undefined {
|
function parseBullets(raw: unknown): string[] {
|
||||||
|
if (Array.isArray(raw)) {
|
||||||
|
return asStringArray(raw);
|
||||||
|
}
|
||||||
|
const text = asString(raw).trim();
|
||||||
|
if (!text) return [];
|
||||||
|
|
||||||
|
if (text.includes("\n")) {
|
||||||
|
return text
|
||||||
|
.split("\n")
|
||||||
|
.map((s) => s.replace(/^[•\-\*\d+\.]\s*/, "").trim())
|
||||||
|
.filter((s) => s.length > 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (text.includes(";")) {
|
||||||
|
return text
|
||||||
|
.split(";")
|
||||||
|
.map((s) => s.trim().replace(/^and\s+/i, ""))
|
||||||
|
.filter((s) => s.length > 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
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 parseConnectingChannel(val: unknown): ConnectingChannelDetails | string[] | undefined {
|
||||||
if (!val) return undefined;
|
if (!val) return undefined;
|
||||||
if (typeof val === "string") return val;
|
if (Array.isArray(val)) {
|
||||||
|
const arr = parseBullets(val);
|
||||||
|
return arr.length > 0 ? arr : undefined;
|
||||||
|
}
|
||||||
|
if (typeof val === "string") {
|
||||||
|
const bullets = parseBullets(val);
|
||||||
|
return bullets.length > 0 ? bullets : undefined;
|
||||||
|
}
|
||||||
if (typeof val === "object") {
|
if (typeof val === "object") {
|
||||||
const obj = val as Record<string, unknown>;
|
const obj = val as Record<string, unknown>;
|
||||||
const empty = asString(obj.empty);
|
const empty = parseBullets(obj.empty);
|
||||||
const full = asString(obj.full);
|
const full = parseBullets(obj.full);
|
||||||
if (empty || full) {
|
if (empty.length > 0 || full.length > 0) {
|
||||||
return {
|
return {
|
||||||
empty: empty || undefined,
|
empty: empty.length > 0 ? empty : undefined,
|
||||||
full: full || undefined,
|
full: full.length > 0 ? full : undefined,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return undefined;
|
return undefined;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function toChannelData(raw: RawChannelData): ChannelData {
|
||||||
|
return {
|
||||||
|
name: raw.name,
|
||||||
|
code: raw.code,
|
||||||
|
mainChannel: raw.mainChannel ? parseBullets(raw.mainChannel) : undefined,
|
||||||
|
connectingChannel: parseConnectingChannel(raw.connectingChannel),
|
||||||
|
muscleChannel: raw.muscleChannel ? parseBullets(raw.muscleChannel) : undefined,
|
||||||
|
greatConnectingChannelOfSpleen: raw.greatConnectingChannelOfSpleen
|
||||||
|
? parseBullets(raw.greatConnectingChannelOfSpleen)
|
||||||
|
: undefined,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
export function TwelveChannelsDetailRenderer({
|
export function TwelveChannelsDetailRenderer({
|
||||||
content,
|
content,
|
||||||
data,
|
data,
|
||||||
|
|
@ -259,9 +326,10 @@ export function TwelveChannelsDetailRenderer({
|
||||||
|
|
||||||
// 1. Seed fallback channels
|
// 1. Seed fallback channels
|
||||||
for (const ch of FALLBACK_CHANNELS) {
|
for (const ch of FALLBACK_CHANNELS) {
|
||||||
map.set(normalizeKey(ch.name), ch);
|
const parsed = toChannelData(ch);
|
||||||
if (ch.code) map.set(normalizeKey(ch.code), ch);
|
map.set(normalizeKey(parsed.name), parsed);
|
||||||
list.push(ch);
|
if (parsed.code) map.set(normalizeKey(parsed.code), parsed);
|
||||||
|
list.push(parsed);
|
||||||
}
|
}
|
||||||
|
|
||||||
// 2. Overlay live queried items if available
|
// 2. Overlay live queried items if available
|
||||||
|
|
@ -272,27 +340,29 @@ export function TwelveChannelsDetailRenderer({
|
||||||
const name = asString(a.name) || item.title;
|
const name = asString(a.name) || item.title;
|
||||||
if (!name) continue;
|
if (!name) continue;
|
||||||
|
|
||||||
const mainChannel = asString(a.main_channel);
|
const mainChannel = parseBullets(a.main_channel);
|
||||||
const connectingChannel = parseConnectingChannel(a.connecting_channel);
|
const connectingChannel = parseConnectingChannel(a.connecting_channel);
|
||||||
const muscleChannel = asString(a.muscle_channel);
|
const muscleChannel = parseBullets(a.muscle_channel);
|
||||||
|
|
||||||
const greatConnecting = a.great_connecting_channel_of_the_spleen;
|
const greatConnecting = a.great_connecting_channel_of_the_spleen;
|
||||||
let greatConnectingStr: string | undefined;
|
let greatConnectingBullets: string[] | undefined;
|
||||||
if (typeof greatConnecting === "object" && greatConnecting !== null) {
|
if (typeof greatConnecting === "object" && greatConnecting !== null) {
|
||||||
greatConnectingStr = asString(
|
const g = parseBullets(
|
||||||
(greatConnecting as Record<string, unknown>).clinical_manifestations,
|
(greatConnecting as Record<string, unknown>).clinical_manifestations,
|
||||||
);
|
);
|
||||||
} else if (typeof greatConnecting === "string") {
|
if (g.length > 0) greatConnectingBullets = g;
|
||||||
greatConnectingStr = greatConnecting;
|
} else if (greatConnecting) {
|
||||||
|
const g = parseBullets(greatConnecting);
|
||||||
|
if (g.length > 0) greatConnectingBullets = g;
|
||||||
}
|
}
|
||||||
|
|
||||||
const channelData: ChannelData = {
|
const channelData: ChannelData = {
|
||||||
name,
|
name,
|
||||||
code: asString(a.code) || item.slug,
|
code: asString(a.code) || item.slug,
|
||||||
mainChannel: mainChannel || undefined,
|
mainChannel: mainChannel.length > 0 ? mainChannel : undefined,
|
||||||
connectingChannel,
|
connectingChannel,
|
||||||
muscleChannel: muscleChannel || undefined,
|
muscleChannel: muscleChannel.length > 0 ? muscleChannel : undefined,
|
||||||
greatConnectingChannelOfSpleen: greatConnectingStr || undefined,
|
greatConnectingChannelOfSpleen: greatConnectingBullets,
|
||||||
};
|
};
|
||||||
|
|
||||||
const key = normalizeKey(name);
|
const key = normalizeKey(name);
|
||||||
|
|
@ -324,23 +394,29 @@ export function TwelveChannelsDetailRenderer({
|
||||||
const activeChannelData: ChannelData | null = useMemo(() => {
|
const activeChannelData: ChannelData | null = useMemo(() => {
|
||||||
if (isDirectLeafChannel) {
|
if (isDirectLeafChannel) {
|
||||||
const name = asString(data.name) || content.title || "Twelve Channels";
|
const name = asString(data.name) || content.title || "Twelve Channels";
|
||||||
|
const mainChannel = parseBullets(data.main_channel);
|
||||||
|
const connectingChannel = parseConnectingChannel(data.connecting_channel);
|
||||||
|
const muscleChannel = parseBullets(data.muscle_channel);
|
||||||
|
|
||||||
const greatConnecting = data.great_connecting_channel_of_the_spleen;
|
const greatConnecting = data.great_connecting_channel_of_the_spleen;
|
||||||
let greatConnectingStr: string | undefined;
|
let greatConnectingBullets: string[] | undefined;
|
||||||
if (typeof greatConnecting === "object" && greatConnecting !== null) {
|
if (typeof greatConnecting === "object" && greatConnecting !== null) {
|
||||||
greatConnectingStr = asString(
|
const g = parseBullets(
|
||||||
(greatConnecting as Record<string, unknown>).clinical_manifestations,
|
(greatConnecting as Record<string, unknown>).clinical_manifestations,
|
||||||
);
|
);
|
||||||
} else if (typeof greatConnecting === "string") {
|
if (g.length > 0) greatConnectingBullets = g;
|
||||||
greatConnectingStr = greatConnecting;
|
} else if (greatConnecting) {
|
||||||
|
const g = parseBullets(greatConnecting);
|
||||||
|
if (g.length > 0) greatConnectingBullets = g;
|
||||||
}
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
name,
|
name,
|
||||||
code: asString(data.code) || undefined,
|
code: asString(data.code) || undefined,
|
||||||
mainChannel: asString(data.main_channel) || undefined,
|
mainChannel: mainChannel.length > 0 ? mainChannel : undefined,
|
||||||
connectingChannel: parseConnectingChannel(data.connecting_channel),
|
connectingChannel,
|
||||||
muscleChannel: asString(data.muscle_channel) || undefined,
|
muscleChannel: muscleChannel.length > 0 ? muscleChannel : undefined,
|
||||||
greatConnectingChannelOfSpleen: greatConnectingStr,
|
greatConnectingChannelOfSpleen: greatConnectingBullets,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -388,9 +464,9 @@ export function TwelveChannelsDetailRenderer({
|
||||||
<Hero title={activeChannelData.name} />
|
<Hero title={activeChannelData.name} />
|
||||||
|
|
||||||
{/* 1. Main Channel Card */}
|
{/* 1. Main Channel Card */}
|
||||||
{activeChannelData.mainChannel ? (
|
{activeChannelData.mainChannel && activeChannelData.mainChannel.length > 0 ? (
|
||||||
<SectionCard title="Main Channel" defaultExpanded>
|
<SectionCard title="Main Channel" defaultExpanded>
|
||||||
<Paragraphs items={[activeChannelData.mainChannel]} />
|
<BulletList items={activeChannelData.mainChannel} />
|
||||||
</SectionCard>
|
</SectionCard>
|
||||||
) : null}
|
) : null}
|
||||||
|
|
||||||
|
|
@ -399,47 +475,46 @@ export function TwelveChannelsDetailRenderer({
|
||||||
<SectionCard title="Connecting Channel" defaultExpanded>
|
<SectionCard title="Connecting Channel" defaultExpanded>
|
||||||
{isConnectingObj ? (
|
{isConnectingObj ? (
|
||||||
<View style={styles.connectingDetailsContainer}>
|
<View style={styles.connectingDetailsContainer}>
|
||||||
{(connecting as ConnectingChannelDetails).full ? (
|
{(connecting as ConnectingChannelDetails).full &&
|
||||||
|
(connecting as ConnectingChannelDetails).full!.length > 0 ? (
|
||||||
<View style={styles.conditionBlock}>
|
<View style={styles.conditionBlock}>
|
||||||
<View style={styles.conditionHeader}>
|
<View style={styles.conditionHeader}>
|
||||||
<View style={[styles.conditionDot, { backgroundColor: Colors.error || "#EF4444" }]} />
|
<View style={[styles.conditionDot, { backgroundColor: Colors.error || "#EF4444" }]} />
|
||||||
<Text style={styles.conditionTitle}>Full Condition</Text>
|
<Text style={styles.conditionTitle}>Full Condition</Text>
|
||||||
</View>
|
</View>
|
||||||
<Text style={styles.conditionText}>
|
<BulletList items={(connecting as ConnectingChannelDetails).full!} />
|
||||||
{(connecting as ConnectingChannelDetails).full}
|
|
||||||
</Text>
|
|
||||||
</View>
|
</View>
|
||||||
) : null}
|
) : null}
|
||||||
|
|
||||||
{(connecting as ConnectingChannelDetails).empty ? (
|
{(connecting as ConnectingChannelDetails).empty &&
|
||||||
|
(connecting as ConnectingChannelDetails).empty!.length > 0 ? (
|
||||||
<View style={[styles.conditionBlock, { marginTop: moderateScale(10) }]}>
|
<View style={[styles.conditionBlock, { marginTop: moderateScale(10) }]}>
|
||||||
<View style={styles.conditionHeader}>
|
<View style={styles.conditionHeader}>
|
||||||
<View style={[styles.conditionDot, { backgroundColor: "#3B82F6" }]} />
|
<View style={[styles.conditionDot, { backgroundColor: "#3B82F6" }]} />
|
||||||
<Text style={styles.conditionTitle}>Empty Condition</Text>
|
<Text style={styles.conditionTitle}>Empty Condition</Text>
|
||||||
</View>
|
</View>
|
||||||
<Text style={styles.conditionText}>
|
<BulletList items={(connecting as ConnectingChannelDetails).empty!} />
|
||||||
{(connecting as ConnectingChannelDetails).empty}
|
|
||||||
</Text>
|
|
||||||
</View>
|
</View>
|
||||||
) : null}
|
) : null}
|
||||||
</View>
|
</View>
|
||||||
) : typeof connecting === "string" ? (
|
) : Array.isArray(connecting) ? (
|
||||||
<Paragraphs items={[connecting]} />
|
<BulletList items={connecting} />
|
||||||
) : null}
|
) : null}
|
||||||
</SectionCard>
|
</SectionCard>
|
||||||
) : null}
|
) : null}
|
||||||
|
|
||||||
{/* 3. Muscle Channel Card */}
|
{/* 3. Muscle Channel Card */}
|
||||||
{activeChannelData.muscleChannel ? (
|
{activeChannelData.muscleChannel && activeChannelData.muscleChannel.length > 0 ? (
|
||||||
<SectionCard title="Muscle Channel" defaultExpanded>
|
<SectionCard title="Muscle Channel" defaultExpanded>
|
||||||
<Paragraphs items={[activeChannelData.muscleChannel]} />
|
<BulletList items={activeChannelData.muscleChannel} />
|
||||||
</SectionCard>
|
</SectionCard>
|
||||||
) : null}
|
) : null}
|
||||||
|
|
||||||
{/* 4. Great Connecting Channel of the Spleen (if present) */}
|
{/* 4. Great Connecting Channel of the Spleen (if present) */}
|
||||||
{activeChannelData.greatConnectingChannelOfSpleen ? (
|
{activeChannelData.greatConnectingChannelOfSpleen &&
|
||||||
|
activeChannelData.greatConnectingChannelOfSpleen.length > 0 ? (
|
||||||
<SectionCard title="Great Connecting Channel of the Spleen" defaultExpanded>
|
<SectionCard title="Great Connecting Channel of the Spleen" defaultExpanded>
|
||||||
<Paragraphs items={[activeChannelData.greatConnectingChannelOfSpleen]} />
|
<BulletList items={activeChannelData.greatConnectingChannelOfSpleen} />
|
||||||
</SectionCard>
|
</SectionCard>
|
||||||
) : null}
|
) : null}
|
||||||
</ScrollView>
|
</ScrollView>
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue