feat(gynecology): link all acupuncture points and explanation references to m0001 point details
This commit is contained in:
parent
053c93e708
commit
68f122cc7e
|
|
@ -1,4 +1,4 @@
|
|||
import React, { useState } from "react";
|
||||
import React, { useMemo, useState } from "react";
|
||||
import {
|
||||
ActivityIndicator,
|
||||
LayoutAnimation,
|
||||
|
|
@ -10,6 +10,7 @@ import {
|
|||
View,
|
||||
} from "react-native";
|
||||
import { Ionicons } from "@expo/vector-icons";
|
||||
import { useRouter } from "expo-router";
|
||||
import { moderateScale, verticalScale } from "react-native-size-matters";
|
||||
|
||||
import { Colors } from "@/theme";
|
||||
|
|
@ -17,7 +18,10 @@ import { asNumber, asString, asStringArray, humanizeKey } from "../helpers/value
|
|||
import { CollectionScaffold } from "../shared/CollectionScaffold";
|
||||
import { ContentCountBadge } from "../shared/ContentCountBadge";
|
||||
import { greenTone } from "../shared/reading-palette";
|
||||
import { useModuleContentDetailQuery } from "../../hooks/use-content-queries";
|
||||
import {
|
||||
useModuleContentDetailQuery,
|
||||
useModuleTemplateContentDetailsQuery,
|
||||
} from "../../hooks/use-content-queries";
|
||||
import type {
|
||||
CollectionItemRendererProps,
|
||||
CollectionRendererProps,
|
||||
|
|
@ -31,10 +35,55 @@ export function ModuleCatalogCollectionRenderer(props: CollectionRendererProps)
|
|||
return <CollectionScaffold {...props} />;
|
||||
}
|
||||
|
||||
function normalizePointCode(raw: string): string {
|
||||
let code = raw.replace(/\s*\([^)]*\)/g, "").trim().toLowerCase();
|
||||
code = code.replace(/^ren-/, "cv-");
|
||||
code = code.replace(/^rn-/, "cv-");
|
||||
code = code.replace(/^du-/, "gv-");
|
||||
code = code.replace(/^sj-/, "te-");
|
||||
code = code.replace(/^tb-/, "te-");
|
||||
code = code.replace(/^liv-/, "lr-");
|
||||
code = code.replace(/^ub-/, "bl-");
|
||||
return code;
|
||||
}
|
||||
|
||||
function renderExplanationParts(
|
||||
text: string,
|
||||
onPointPress: (code: string) => void,
|
||||
) {
|
||||
const pointRegex = /\b([A-Za-z]{1,4}-\d{1,2})\b/g;
|
||||
const parts: React.ReactNode[] = [];
|
||||
let lastIndex = 0;
|
||||
let match: RegExpExecArray | null;
|
||||
|
||||
while ((match = pointRegex.exec(text)) !== null) {
|
||||
if (match.index > lastIndex) {
|
||||
parts.push(text.substring(lastIndex, match.index));
|
||||
}
|
||||
const ptCode = match[1];
|
||||
parts.push(
|
||||
<Text
|
||||
key={`pt-${match.index}`}
|
||||
accessibilityRole="button"
|
||||
onPress={() => onPointPress(ptCode)}
|
||||
style={accordionStyles.pointTextLink}
|
||||
>
|
||||
{ptCode}
|
||||
</Text>
|
||||
);
|
||||
lastIndex = match.index + match[0].length;
|
||||
}
|
||||
if (lastIndex < text.length) {
|
||||
parts.push(text.substring(lastIndex));
|
||||
}
|
||||
return parts.length > 0 ? parts : text;
|
||||
}
|
||||
|
||||
export function PatternAccordionCardRenderer({
|
||||
item,
|
||||
onPress,
|
||||
}: CollectionItemRendererProps) {
|
||||
const router = useRouter();
|
||||
const [expanded, setExpanded] = useState(false);
|
||||
const attributes = item.attributes;
|
||||
const rawTitle = asString(attributes.name) || item.title;
|
||||
|
|
@ -50,6 +99,59 @@ export function PatternAccordionCardRenderer({
|
|||
contentId,
|
||||
);
|
||||
|
||||
// Query all acupuncture points from m0001 to resolve links
|
||||
const { data: pointsData } = useModuleTemplateContentDetailsQuery({
|
||||
module_code: "m0001",
|
||||
template_code: "m0001_ct0003",
|
||||
});
|
||||
|
||||
const pointsMap = useMemo(() => {
|
||||
const map = new Map<string, string>();
|
||||
if (!pointsData?.items) return map;
|
||||
for (const pItem of pointsData.items) {
|
||||
const id = pItem.content.id;
|
||||
const code = asString(pItem.data.code) || asString(pItem.data.name);
|
||||
if (code) {
|
||||
const lower = code.toLowerCase().trim();
|
||||
map.set(lower, id);
|
||||
if (lower.startsWith("cv-")) {
|
||||
map.set(lower.replace("cv-", "ren-"), id);
|
||||
map.set(lower.replace("cv-", "rn-"), id);
|
||||
}
|
||||
if (lower.startsWith("gv-")) {
|
||||
map.set(lower.replace("gv-", "du-"), id);
|
||||
}
|
||||
if (lower.startsWith("te-")) {
|
||||
map.set(lower.replace("te-", "sj-"), id);
|
||||
map.set(lower.replace("te-", "tb-"), id);
|
||||
}
|
||||
if (lower.startsWith("lr-")) {
|
||||
map.set(lower.replace("lr-", "liv-"), id);
|
||||
}
|
||||
if (lower.startsWith("bl-")) {
|
||||
map.set(lower.replace("bl-", "ub-"), id);
|
||||
}
|
||||
}
|
||||
if (pItem.content.title) {
|
||||
map.set(pItem.content.title.toLowerCase().trim(), id);
|
||||
}
|
||||
}
|
||||
return map;
|
||||
}, [pointsData?.items]);
|
||||
|
||||
const handlePointPress = (rawPt: string) => {
|
||||
const match = rawPt.match(/([A-Za-z]{1,4}-\d{1,2})/);
|
||||
const pointCode = match ? match[1] : rawPt.trim();
|
||||
const normalized = normalizePointCode(pointCode);
|
||||
const pointContentId = pointsMap.get(normalized);
|
||||
|
||||
if (pointContentId) {
|
||||
router.push(`/modules/m0001/m0001_ct0003/${encodeURIComponent(pointContentId)}` as never);
|
||||
} else {
|
||||
router.push(`/modules/m0001/search?q=${encodeURIComponent(pointCode)}` as never);
|
||||
}
|
||||
};
|
||||
|
||||
const toggle = () => {
|
||||
LayoutAnimation.configureNext(LayoutAnimation.Presets.easeInEaseOut);
|
||||
setExpanded((prev) => !prev);
|
||||
|
|
@ -187,9 +289,24 @@ export function PatternAccordionCardRenderer({
|
|||
{pointChips.length > 0 ? (
|
||||
<View style={accordionStyles.chipsContainer}>
|
||||
{pointChips.map((pt, idx) => (
|
||||
<View key={idx} style={accordionStyles.pointChip}>
|
||||
<Pressable
|
||||
key={idx}
|
||||
accessibilityRole="button"
|
||||
accessibilityLabel={`View ${pt} acupuncture point`}
|
||||
onPress={() => handlePointPress(pt)}
|
||||
style={({ pressed }) => [
|
||||
accordionStyles.pointChip,
|
||||
pressed && accordionStyles.pointChipPressed,
|
||||
]}
|
||||
>
|
||||
<Text style={accordionStyles.pointChipText}>{pt}</Text>
|
||||
</View>
|
||||
<Ionicons
|
||||
name="chevron-forward"
|
||||
size={12}
|
||||
color="#35664E"
|
||||
style={{ marginLeft: 2 }}
|
||||
/>
|
||||
</Pressable>
|
||||
))}
|
||||
</View>
|
||||
) : null}
|
||||
|
|
@ -212,7 +329,9 @@ export function PatternAccordionCardRenderer({
|
|||
{explanations.map((exp, idx) => (
|
||||
<View key={idx} style={accordionStyles.explanationRow}>
|
||||
<View style={accordionStyles.explanationDot} />
|
||||
<Text style={accordionStyles.explanationText}>{exp}</Text>
|
||||
<Text style={accordionStyles.explanationText}>
|
||||
{renderExplanationParts(exp, handlePointPress)}
|
||||
</Text>
|
||||
</View>
|
||||
))}
|
||||
</View>
|
||||
|
|
@ -477,6 +596,8 @@ const accordionStyles = StyleSheet.create({
|
|||
gap: moderateScale(7),
|
||||
},
|
||||
pointChip: {
|
||||
flexDirection: "row",
|
||||
alignItems: "center",
|
||||
backgroundColor: "#EEF7F1",
|
||||
borderWidth: 1,
|
||||
borderColor: "#D5E8DB",
|
||||
|
|
@ -484,12 +605,21 @@ const accordionStyles = StyleSheet.create({
|
|||
paddingVertical: verticalScale(5),
|
||||
borderRadius: moderateScale(999),
|
||||
},
|
||||
pointChipPressed: {
|
||||
opacity: 0.72,
|
||||
transform: [{ scale: 0.96 }],
|
||||
},
|
||||
pointChipText: {
|
||||
fontSize: moderateScale(13),
|
||||
lineHeight: moderateScale(18),
|
||||
fontWeight: "700",
|
||||
color: "#35664E",
|
||||
},
|
||||
pointTextLink: {
|
||||
color: "#285A44",
|
||||
fontWeight: "700",
|
||||
textDecorationLine: "underline",
|
||||
},
|
||||
methodContainer: {
|
||||
marginTop: verticalScale(4),
|
||||
flexDirection: "row",
|
||||
|
|
|
|||
Loading…
Reference in New Issue