gynecology #102
|
|
@ -1,5 +1,14 @@
|
|||
import React from "react";
|
||||
import { Pressable, StyleSheet, Text, View } from "react-native";
|
||||
import React, { useState } from "react";
|
||||
import {
|
||||
ActivityIndicator,
|
||||
LayoutAnimation,
|
||||
Platform,
|
||||
Pressable,
|
||||
StyleSheet,
|
||||
Text,
|
||||
UIManager,
|
||||
View,
|
||||
} from "react-native";
|
||||
import { Ionicons } from "@expo/vector-icons";
|
||||
import { moderateScale, verticalScale } from "react-native-size-matters";
|
||||
|
||||
|
|
@ -7,20 +16,250 @@ import { Colors } from "@/theme";
|
|||
import { asNumber, asString, asStringArray, humanizeKey } from "../helpers/value";
|
||||
import { CollectionScaffold } from "../shared/CollectionScaffold";
|
||||
import { ContentCountBadge } from "../shared/ContentCountBadge";
|
||||
import { useModuleContentDetailQuery } from "../../hooks/use-content-queries";
|
||||
import type {
|
||||
CollectionItemRendererProps,
|
||||
CollectionRendererProps,
|
||||
} from "../../types/renderer.types";
|
||||
|
||||
if (Platform.OS === "android" && UIManager.setLayoutAnimationEnabledExperimental) {
|
||||
UIManager.setLayoutAnimationEnabledExperimental(true);
|
||||
}
|
||||
|
||||
export function ModuleCatalogCollectionRenderer(props: CollectionRendererProps) {
|
||||
return <CollectionScaffold {...props} />;
|
||||
}
|
||||
|
||||
export function PatternAccordionCardRenderer({
|
||||
item,
|
||||
onPress,
|
||||
}: CollectionItemRendererProps) {
|
||||
const [expanded, setExpanded] = useState(false);
|
||||
const attributes = item.attributes;
|
||||
const rawTitle = asString(attributes.name) || item.title;
|
||||
const title = humanizeKey(rawTitle);
|
||||
|
||||
const link = attributes?.link as Record<string, unknown> | undefined;
|
||||
const linkTarget = link?.target as Record<string, unknown> | undefined;
|
||||
const contentId = (linkTarget?.content_id as string) || item.id;
|
||||
const moduleCode = (linkTarget?.module_code as string) || "m0042";
|
||||
|
||||
const detailQuery = useModuleContentDetailQuery(
|
||||
{ module_code: moduleCode },
|
||||
contentId,
|
||||
);
|
||||
|
||||
const toggle = () => {
|
||||
LayoutAnimation.configureNext(LayoutAnimation.Presets.easeInEaseOut);
|
||||
setExpanded((prev) => !prev);
|
||||
};
|
||||
|
||||
const detailData = (detailQuery.data?.data as Record<string, unknown> | undefined) || attributes;
|
||||
|
||||
// Extract fields matching the user's diagram
|
||||
const rawManifestations = detailData.clinical_manifestations;
|
||||
const clinicalManifestations: string[] = Array.isArray(rawManifestations)
|
||||
? (rawManifestations as string[]).map(String)
|
||||
: typeof rawManifestations === "string" && rawManifestations.trim()
|
||||
? rawManifestations.split("\n").map((s) => s.trim()).filter(Boolean)
|
||||
: [];
|
||||
|
||||
const tongue = asString(detailData.tongue);
|
||||
const pulse = asString(detailData.pulse);
|
||||
const treatmentPrinciple = asString(detailData.treatment_principle);
|
||||
|
||||
const rawAcupuncture = detailData.acupuncture;
|
||||
let acuPoints = "";
|
||||
let acuMethod = "";
|
||||
if (rawAcupuncture && typeof rawAcupuncture === "object") {
|
||||
const acuObj = rawAcupuncture as Record<string, unknown>;
|
||||
acuPoints = asString(acuObj.points);
|
||||
acuMethod = asString(acuObj.method);
|
||||
} else if (typeof rawAcupuncture === "string") {
|
||||
acuPoints = rawAcupuncture;
|
||||
}
|
||||
|
||||
const rawExplanation = detailData.explanation;
|
||||
const explanations: string[] = Array.isArray(rawExplanation)
|
||||
? (rawExplanation as string[]).map(String)
|
||||
: typeof rawExplanation === "string" && rawExplanation.trim()
|
||||
? rawExplanation.split("\n").map((s) => s.trim()).filter(Boolean)
|
||||
: [];
|
||||
|
||||
const category = asString(detailData.category);
|
||||
|
||||
// Split points by comma into chips
|
||||
const pointChips = acuPoints
|
||||
? acuPoints.split(/,\s*/).map((p) => p.trim()).filter(Boolean)
|
||||
: [];
|
||||
|
||||
return (
|
||||
<View style={accordionStyles.cardContainer}>
|
||||
<Pressable
|
||||
accessibilityRole="button"
|
||||
accessibilityLabel={`${expanded ? "Collapse" : "Expand"} ${title}`}
|
||||
onPress={toggle}
|
||||
style={({ pressed }) => [
|
||||
accordionStyles.headerRow,
|
||||
expanded && accordionStyles.headerRowExpanded,
|
||||
pressed && accordionStyles.pressed,
|
||||
]}
|
||||
>
|
||||
<Text style={accordionStyles.title}>{title}</Text>
|
||||
<View style={accordionStyles.chevronWrapper}>
|
||||
<Ionicons
|
||||
name={expanded ? "chevron-up" : "chevron-down"}
|
||||
size={20}
|
||||
color={expanded ? Colors.primary : "#6B7280"}
|
||||
/>
|
||||
</View>
|
||||
</Pressable>
|
||||
|
||||
{expanded ? (
|
||||
<View style={accordionStyles.expandedBody}>
|
||||
{detailQuery.isLoading && !detailQuery.data ? (
|
||||
<View style={accordionStyles.loadingRow}>
|
||||
<ActivityIndicator size="small" color={Colors.primary} />
|
||||
<Text style={accordionStyles.loadingText}>Loading pattern details…</Text>
|
||||
</View>
|
||||
) : (
|
||||
<View style={accordionStyles.innerBox}>
|
||||
{/* 1. Clinical Manifestations */}
|
||||
{clinicalManifestations.length > 0 ? (
|
||||
<View style={accordionStyles.section}>
|
||||
<Text style={accordionStyles.sectionTitle}>
|
||||
Clinical Manifestations
|
||||
</Text>
|
||||
<View style={accordionStyles.bulletList}>
|
||||
{clinicalManifestations.map((itemText, idx) => (
|
||||
<View key={idx} style={accordionStyles.bulletRow}>
|
||||
<Text style={accordionStyles.bulletDot}>•</Text>
|
||||
<Text style={accordionStyles.bulletText}>{itemText}</Text>
|
||||
</View>
|
||||
))}
|
||||
</View>
|
||||
</View>
|
||||
) : null}
|
||||
|
||||
{/* 2. Tongue & Pulse (Side-by-Side as drawn) */}
|
||||
{tongue || pulse ? (
|
||||
<View style={[accordionStyles.section, accordionStyles.twoColumnBox]}>
|
||||
{tongue ? (
|
||||
<View style={accordionStyles.column}>
|
||||
<Text style={accordionStyles.columnLabel}>Tongue</Text>
|
||||
<Text style={accordionStyles.columnValue}>{tongue}</Text>
|
||||
</View>
|
||||
) : null}
|
||||
{tongue && pulse ? <View style={accordionStyles.columnDivider} /> : null}
|
||||
{pulse ? (
|
||||
<View style={accordionStyles.column}>
|
||||
<Text style={accordionStyles.columnLabel}>Pulse</Text>
|
||||
<Text style={accordionStyles.columnValue}>{pulse}</Text>
|
||||
</View>
|
||||
) : null}
|
||||
</View>
|
||||
) : null}
|
||||
|
||||
{/* 3. Treatment Principle */}
|
||||
{treatmentPrinciple ? (
|
||||
<View style={accordionStyles.section}>
|
||||
<Text style={accordionStyles.sectionTitle}>
|
||||
Treatment Principle
|
||||
</Text>
|
||||
<Text style={accordionStyles.principleText}>
|
||||
{treatmentPrinciple}
|
||||
</Text>
|
||||
</View>
|
||||
) : null}
|
||||
|
||||
{/* 4. Acupuncture Points & Method */}
|
||||
{pointChips.length > 0 || acuMethod ? (
|
||||
<View style={accordionStyles.section}>
|
||||
<Text style={accordionStyles.sectionTitle}>
|
||||
Acupuncture Points
|
||||
</Text>
|
||||
{pointChips.length > 0 ? (
|
||||
<View style={accordionStyles.chipsContainer}>
|
||||
{pointChips.map((pt, idx) => (
|
||||
<View key={idx} style={accordionStyles.pointChip}>
|
||||
<Text style={accordionStyles.pointChipText}>{pt}</Text>
|
||||
</View>
|
||||
))}
|
||||
</View>
|
||||
) : null}
|
||||
{acuMethod ? (
|
||||
<View style={accordionStyles.methodContainer}>
|
||||
<Text style={accordionStyles.subSectionLabel}>Method:</Text>
|
||||
<Text style={accordionStyles.methodText}>{acuMethod}</Text>
|
||||
</View>
|
||||
) : null}
|
||||
</View>
|
||||
) : null}
|
||||
|
||||
{/* 5. Explanation */}
|
||||
{explanations.length > 0 ? (
|
||||
<View style={accordionStyles.section}>
|
||||
<Text style={accordionStyles.sectionTitle}>
|
||||
Explanation
|
||||
</Text>
|
||||
<View style={accordionStyles.explanationList}>
|
||||
{explanations.map((exp, idx) => (
|
||||
<View key={idx} style={accordionStyles.explanationRow}>
|
||||
<Text style={accordionStyles.explanationBullet}>–</Text>
|
||||
<Text style={accordionStyles.explanationText}>{exp}</Text>
|
||||
</View>
|
||||
))}
|
||||
</View>
|
||||
</View>
|
||||
) : null}
|
||||
|
||||
{/* 6. Category */}
|
||||
{category ? (
|
||||
<View style={accordionStyles.categoryRow}>
|
||||
<Text style={accordionStyles.categoryLabel}>Category:</Text>
|
||||
<View style={accordionStyles.categoryBadge}>
|
||||
<Text style={accordionStyles.categoryBadgeText}>{category}</Text>
|
||||
</View>
|
||||
</View>
|
||||
) : null}
|
||||
|
||||
{/* Optional link to navigate to full detail screen */}
|
||||
{onPress ? (
|
||||
<Pressable
|
||||
accessibilityRole="button"
|
||||
onPress={onPress}
|
||||
style={({ pressed }) => [
|
||||
accordionStyles.viewFullDetailBtn,
|
||||
pressed && accordionStyles.pressed,
|
||||
]}
|
||||
>
|
||||
<Text style={accordionStyles.viewFullDetailText}>
|
||||
View Full Details
|
||||
</Text>
|
||||
<Ionicons name="arrow-forward" size={14} color={Colors.primary} />
|
||||
</Pressable>
|
||||
) : null}
|
||||
</View>
|
||||
)}
|
||||
</View>
|
||||
) : null}
|
||||
</View>
|
||||
);
|
||||
}
|
||||
|
||||
export function ModuleCatalogCardRenderer({
|
||||
item,
|
||||
onPress,
|
||||
}: CollectionItemRendererProps) {
|
||||
const attributes = item.attributes;
|
||||
const link = attributes?.link as Record<string, unknown> | undefined;
|
||||
const isContentRef = link?.type === "content_ref";
|
||||
|
||||
// If this item points to a pattern content item, render inline accordion
|
||||
if (isContentRef) {
|
||||
return <PatternAccordionCardRenderer item={item} onPress={onPress} />;
|
||||
}
|
||||
|
||||
const rawTitle = asString(attributes.name) || item.title;
|
||||
const parenMatch = rawTitle.match(/^(.*?)\s*\(([^()]+)\)\s*(.*?)$/);
|
||||
const title = parenMatch
|
||||
|
|
@ -76,6 +315,239 @@ export function ModuleCatalogCardRenderer({
|
|||
);
|
||||
}
|
||||
|
||||
const accordionStyles = StyleSheet.create({
|
||||
cardContainer: {
|
||||
backgroundColor: "#FFFFFF",
|
||||
marginHorizontal: moderateScale(14),
|
||||
marginVertical: verticalScale(5),
|
||||
borderRadius: moderateScale(14),
|
||||
borderWidth: 1,
|
||||
borderColor: "#E5E7EB",
|
||||
overflow: "hidden",
|
||||
shadowColor: "#000",
|
||||
shadowOffset: { width: 0, height: 1 },
|
||||
shadowOpacity: 0.05,
|
||||
shadowRadius: 3,
|
||||
elevation: 1,
|
||||
},
|
||||
headerRow: {
|
||||
minHeight: verticalScale(52),
|
||||
flexDirection: "row",
|
||||
alignItems: "center",
|
||||
justifyContent: "space-between",
|
||||
paddingHorizontal: moderateScale(16),
|
||||
paddingVertical: verticalScale(12),
|
||||
backgroundColor: "#FFFFFF",
|
||||
},
|
||||
headerRowExpanded: {
|
||||
backgroundColor: "#F0FDF4",
|
||||
borderBottomWidth: 1,
|
||||
borderBottomColor: "#DCFCE7",
|
||||
},
|
||||
pressed: {
|
||||
opacity: 0.75,
|
||||
},
|
||||
title: {
|
||||
flex: 1,
|
||||
fontSize: moderateScale(15),
|
||||
fontWeight: "600",
|
||||
color: "#111827",
|
||||
marginRight: moderateScale(10),
|
||||
},
|
||||
chevronWrapper: {
|
||||
width: moderateScale(28),
|
||||
height: moderateScale(28),
|
||||
borderRadius: moderateScale(14),
|
||||
alignItems: "center",
|
||||
justifyContent: "center",
|
||||
backgroundColor: "#F3F4F6",
|
||||
},
|
||||
expandedBody: {
|
||||
padding: moderateScale(12),
|
||||
backgroundColor: "#F9FAFB",
|
||||
},
|
||||
loadingRow: {
|
||||
flexDirection: "row",
|
||||
alignItems: "center",
|
||||
justifyContent: "center",
|
||||
paddingVertical: verticalScale(16),
|
||||
gap: moderateScale(8),
|
||||
},
|
||||
loadingText: {
|
||||
fontSize: moderateScale(13),
|
||||
color: "#6B7280",
|
||||
},
|
||||
innerBox: {
|
||||
backgroundColor: "#FFFFFF",
|
||||
borderRadius: moderateScale(10),
|
||||
borderWidth: 1,
|
||||
borderColor: "#E5E7EB",
|
||||
padding: moderateScale(14),
|
||||
gap: verticalScale(12),
|
||||
},
|
||||
section: {
|
||||
borderBottomWidth: 1,
|
||||
borderBottomColor: "#F3F4F6",
|
||||
paddingBottom: verticalScale(10),
|
||||
gap: verticalScale(6),
|
||||
},
|
||||
sectionTitle: {
|
||||
fontSize: moderateScale(12),
|
||||
fontWeight: "700",
|
||||
color: "#059669",
|
||||
textTransform: "uppercase",
|
||||
letterSpacing: 0.4,
|
||||
},
|
||||
bulletList: {
|
||||
gap: verticalScale(4),
|
||||
},
|
||||
bulletRow: {
|
||||
flexDirection: "row",
|
||||
alignItems: "flex-start",
|
||||
gap: moderateScale(6),
|
||||
},
|
||||
bulletDot: {
|
||||
fontSize: moderateScale(14),
|
||||
color: "#10B981",
|
||||
lineHeight: moderateScale(18),
|
||||
},
|
||||
bulletText: {
|
||||
flex: 1,
|
||||
fontSize: moderateScale(13),
|
||||
color: "#374151",
|
||||
lineHeight: moderateScale(18),
|
||||
},
|
||||
twoColumnBox: {
|
||||
flexDirection: "row",
|
||||
backgroundColor: "#F9FAFB",
|
||||
borderRadius: moderateScale(8),
|
||||
borderWidth: 1,
|
||||
borderColor: "#E5E7EB",
|
||||
padding: moderateScale(10),
|
||||
alignItems: "stretch",
|
||||
},
|
||||
column: {
|
||||
flex: 1,
|
||||
gap: verticalScale(2),
|
||||
},
|
||||
columnDivider: {
|
||||
width: 1,
|
||||
backgroundColor: "#E5E7EB",
|
||||
marginHorizontal: moderateScale(10),
|
||||
},
|
||||
columnLabel: {
|
||||
fontSize: moderateScale(11),
|
||||
fontWeight: "700",
|
||||
color: "#4B5563",
|
||||
textTransform: "uppercase",
|
||||
},
|
||||
columnValue: {
|
||||
fontSize: moderateScale(13),
|
||||
color: "#111827",
|
||||
fontWeight: "500",
|
||||
lineHeight: moderateScale(18),
|
||||
},
|
||||
principleText: {
|
||||
fontSize: moderateScale(13),
|
||||
color: "#1F2937",
|
||||
lineHeight: moderateScale(19),
|
||||
fontStyle: "italic",
|
||||
backgroundColor: "#ECFDF5",
|
||||
padding: moderateScale(8),
|
||||
borderRadius: moderateScale(6),
|
||||
borderLeftWidth: 3,
|
||||
borderLeftColor: "#10B981",
|
||||
},
|
||||
chipsContainer: {
|
||||
flexDirection: "row",
|
||||
flexWrap: "wrap",
|
||||
gap: moderateScale(6),
|
||||
},
|
||||
pointChip: {
|
||||
backgroundColor: "#E0E7FF",
|
||||
borderWidth: 1,
|
||||
borderColor: "#C7D2FE",
|
||||
paddingHorizontal: moderateScale(8),
|
||||
paddingVertical: verticalScale(3),
|
||||
borderRadius: moderateScale(6),
|
||||
},
|
||||
pointChipText: {
|
||||
fontSize: moderateScale(12),
|
||||
fontWeight: "700",
|
||||
color: "#3730A3",
|
||||
},
|
||||
methodContainer: {
|
||||
marginTop: verticalScale(4),
|
||||
flexDirection: "row",
|
||||
alignItems: "flex-start",
|
||||
gap: moderateScale(4),
|
||||
},
|
||||
subSectionLabel: {
|
||||
fontSize: moderateScale(12),
|
||||
fontWeight: "600",
|
||||
color: "#4B5563",
|
||||
},
|
||||
methodText: {
|
||||
flex: 1,
|
||||
fontSize: moderateScale(12),
|
||||
color: "#4B5563",
|
||||
lineHeight: moderateScale(17),
|
||||
},
|
||||
explanationList: {
|
||||
gap: verticalScale(4),
|
||||
},
|
||||
explanationRow: {
|
||||
flexDirection: "row",
|
||||
alignItems: "flex-start",
|
||||
gap: moderateScale(6),
|
||||
},
|
||||
explanationBullet: {
|
||||
fontSize: moderateScale(13),
|
||||
color: "#9CA3AF",
|
||||
lineHeight: moderateScale(17),
|
||||
},
|
||||
explanationText: {
|
||||
flex: 1,
|
||||
fontSize: moderateScale(12),
|
||||
color: "#4B5563",
|
||||
lineHeight: moderateScale(17),
|
||||
},
|
||||
categoryRow: {
|
||||
flexDirection: "row",
|
||||
alignItems: "center",
|
||||
gap: moderateScale(8),
|
||||
paddingTop: verticalScale(2),
|
||||
},
|
||||
categoryLabel: {
|
||||
fontSize: moderateScale(12),
|
||||
fontWeight: "600",
|
||||
color: "#6B7280",
|
||||
},
|
||||
categoryBadge: {
|
||||
backgroundColor: "#F3F4F6",
|
||||
paddingHorizontal: moderateScale(8),
|
||||
paddingVertical: verticalScale(2),
|
||||
borderRadius: moderateScale(6),
|
||||
},
|
||||
categoryBadgeText: {
|
||||
fontSize: moderateScale(12),
|
||||
fontWeight: "600",
|
||||
color: "#374151",
|
||||
},
|
||||
viewFullDetailBtn: {
|
||||
flexDirection: "row",
|
||||
alignItems: "center",
|
||||
justifyContent: "flex-end",
|
||||
gap: moderateScale(4),
|
||||
paddingTop: verticalScale(4),
|
||||
},
|
||||
viewFullDetailText: {
|
||||
fontSize: moderateScale(12),
|
||||
fontWeight: "600",
|
||||
color: Colors.primary,
|
||||
},
|
||||
});
|
||||
|
||||
const styles = StyleSheet.create({
|
||||
row: {
|
||||
minHeight: moderateScale(68),
|
||||
|
|
@ -111,3 +583,4 @@ const styles = StyleSheet.create({
|
|||
lineHeight: moderateScale(16),
|
||||
},
|
||||
});
|
||||
|
||||
|
|
|
|||
|
|
@ -2,7 +2,11 @@ import type { CollectionItemRendererComponent, CollectionRendererComponent, Deta
|
|||
import { GenericCollectionRenderer } from "./GenericCollectionRenderer";
|
||||
import { GenericCardRenderer } from "./GenericCardRenderer";
|
||||
import { GenericDetailRenderer } from "./GenericDetailRenderer";
|
||||
import { ModuleCatalogCollectionRenderer, ModuleCatalogCardRenderer } from "./collections/ModuleCatalogRenderers";
|
||||
import {
|
||||
ModuleCatalogCollectionRenderer,
|
||||
ModuleCatalogCardRenderer,
|
||||
PatternAccordionCardRenderer,
|
||||
} from "./collections/ModuleCatalogRenderers";
|
||||
import { AcuPointCollectionRenderer, AcuPointIndexCollectionRenderer, AcuPointCardRenderer, AcuPointIndexCardRenderer } from "./collections/PointRenderers";
|
||||
import { MeridianCollectionRenderer, MeridianIndexCollectionRenderer, MeridianCardRenderer, MeridianIndexCardRenderer } from "./collections/MeridianRenderers";
|
||||
import { EovCollectionRenderer, EovIndexCollectionRenderer, EovCardRenderer, EovIndexCardRenderer } from "./collections/EovRenderers";
|
||||
|
|
@ -74,6 +78,7 @@ export const collectionRenderers: Readonly<Record<string, CollectionRendererComp
|
|||
});
|
||||
export const collectionItemRenderers: Readonly<Record<string, CollectionItemRendererComponent>> = Object.freeze({
|
||||
module_catalog_card: ModuleCatalogCardRenderer,
|
||||
pattern_accordion_card: PatternAccordionCardRenderer,
|
||||
acu_point_index_card: AcuPointIndexCardRenderer,
|
||||
acu_point_card: AcuPointCardRenderer,
|
||||
meridian_index_card: MeridianIndexCardRenderer,
|
||||
|
|
|
|||
Loading…
Reference in New Issue