Browse Source

正确拉取身体部位信息并显示在注册页面的过滤区域

ddx 2 months ago
parent
commit
95bf718507

+ 45 - 0
mocks/handlers.js

@@ -45,4 +45,49 @@ export const handlers = [
       }
       }
     );
     );
   }),
   }),
+  // Handler 2: 获取body part
+  http.get('/dr/api/v1/auth/protocol/body_part', async () => {
+    // eslint-disable-next-line
+    return new Response(
+      JSON.stringify({
+        code: '0x000000',
+        description: 'Success',
+        solution: '',
+        data: {
+          body_part_list: [
+            {
+              id: '1',
+              body_part_id: 'Human_SKULL',
+              body_part_name: '颅骨',
+              body_part_local: '颅骨',
+              body_part_description: 'Skull',
+              patient_type: 'Human',
+              category: 'DX',
+              sort: 1,
+              is_enabled: true,
+              product: 'DROC',
+              is_pre_install: true,
+            },
+            {
+              id: '2',
+              body_part_id: 'Human_NECK',
+              body_part_name: '颈部',
+              body_part_local: '颈部',
+              body_part_description: 'Neck',
+              patient_type: 'Human',
+              category: 'DX',
+              sort: 2,
+              is_enabled: true,
+              product: 'DROC',
+              is_pre_install: true,
+            },
+          ],
+        },
+      }),
+      {
+        status: 200,
+        headers: { 'Content-Type': 'application/json' },
+      }
+    );
+  }),
 ];
 ];

+ 101 - 33
mocks/handlers.md

@@ -17,40 +17,39 @@
 
 
 ### Response Data: Returns a JSON
 ### Response Data: Returns a JSON
 
 
-    Example:
-
-    ``` json
-    {
-    "code": "0x000000",
-    "description": "Success",
-    "solution": "",
-    "data": {
-        "patient_type_list": [
-            {
-                "id": "1",
-                "patient_type_id": "Human",
-                "patient_type_name": "Human",
-                "patient_type_local": "Human",
-                "patient_type_description": "Human",
-                "sort": 1,
-                "is_enabled": true,
-                "product": "DROC",
-                "is_pre_install": true
-            },
-            {
-                "id": "2",
-                "patient_type_id": "SpecialType",
-                "patient_type_name": "SpecialType",
-                "patient_type_local": "SpecialType",
-                "patient_type_description": "SpecialType",
-                "sort": 2,
-                "is_enabled": false,
-                "product": "DROC",
-                "is_pre_install": true
-            }
-        ]
-    }
+Example:
 
 
+```json
+{
+  "code": "0x000000",
+  "description": "Success",
+  "solution": "",
+  "data": {
+    "patient_type_list": [
+      {
+        "id": "1",
+        "patient_type_id": "Human",
+        "patient_type_name": "Human",
+        "patient_type_local": "Human",
+        "patient_type_description": "Human",
+        "sort": 1,
+        "is_enabled": true,
+        "product": "DROC",
+        "is_pre_install": true
+      },
+      {
+        "id": "2",
+        "patient_type_id": "SpecialType",
+        "patient_type_name": "SpecialType",
+        "patient_type_local": "SpecialType",
+        "patient_type_description": "SpecialType",
+        "sort": 2,
+        "is_enabled": false,
+        "product": "DROC",
+        "is_pre_install": true
+      }
+    ]
+  }
 }
 }
 ```
 ```
 
 
@@ -59,3 +58,72 @@
 ### Delay: 500ms to simulate network latency
 ### Delay: 500ms to simulate network latency
 
 
 ### Error Handling: None
 ### Error Handling: None
+
+## handler 2:
+
+### HTTP Method: GET
+
+### Headers
+
+- **Authorization**
+- **Language**: `en` 或 `zh`
+- **Product**: `DROS` 或 `VETDROS`
+- **Source**: `Electron` 或 `Browser` 或 `Android`
+
+### Endpoint URL: /dr/api/v1/auth/protocol/body_part
+
+### query params
+
+- patient_type:从患者类型接口获取
+- modality:暂时只有DX
+- is_enabled:true 或 false
+
+### Response Status: 200 (OK)
+
+### Response Data: Returns a JSON
+
+响应数据示例:
+
+```json
+{
+  "code": "0x000000",
+  "description": "Success",
+  "solution": "",
+  "data": {
+    "body_part_list": [
+      {
+        "id": "1",
+        "body_part_id": "Human_SKULL",
+        "body_part_name": "颅骨",
+        "body_part_local": "颅骨",
+        "body_part_description": "Skull",
+        "patient_type": "Human",
+        "category": "DX",
+        "sort": 1,
+        "is_enabled": true,
+        "product": "DROC",
+        "is_pre_install": true
+      },
+      {
+        "id": "2",
+        "body_part_id": "Human_NECK",
+        "body_part_name": "颈部",
+        "body_part_local": "颈部",
+        "body_part_description": "Neck",
+        "patient_type": "Human",
+        "category": "DX",
+        "sort": 2,
+        "is_enabled": true,
+        "product": "DROC",
+        "is_pre_install": true
+      }
+    ]
+  }
+}
+```
+
+### Dynamic Behavior: None
+
+### Delay: None
+
+### Error Handling: None

+ 12 - 2
src/API/bodyPart.ts

@@ -27,7 +27,7 @@ export async function fetchBodyParts(
   product = 'DROS',
   product = 'DROS',
   source = 'Electron'
   source = 'Electron'
 ): Promise<BodyPart[]> {
 ): Promise<BodyPart[]> {
-  const response = await axios.get('/api/body-parts', {
+  const response = await axios.get('/dr/api/v1/auth/protocol/body_part', {
     params,
     params,
     headers: {
     headers: {
       Authorization: `Bearer ${token}`,
       Authorization: `Bearer ${token}`,
@@ -36,5 +36,15 @@ export async function fetchBodyParts(
       Source: source,
       Source: source,
     },
     },
   });
   });
-  return response.data;
+  // 兼容接口返回结构
+  if (
+    response.data &&
+    response.data.code === '0x000000' &&
+    response.data.data &&
+    Array.isArray(response.data.data.body_part_list)
+  ) {
+    return response.data.data.body_part_list;
+  }
+  // 兼容原有结构
+  return Array.isArray(response.data) ? response.data : response.data.data;
 }
 }

+ 7 - 0
src/pages/demo/AppInitializer.tsx

@@ -1,6 +1,7 @@
 import React, { useEffect } from 'react';
 import React, { useEffect } from 'react';
 import { useDispatch, useSelector } from 'react-redux';
 import { useDispatch, useSelector } from 'react-redux';
 import { getPatientTypes } from '@/states/patientTypeSlice';
 import { getPatientTypes } from '@/states/patientTypeSlice';
+import { getBodyParts } from '@/states/bodyPartSlice';
 import type { RootState, AppDispatch } from '@/states/store';
 import type { RootState, AppDispatch } from '@/states/store';
 
 
 interface AppInitializerProps {
 interface AppInitializerProps {
@@ -15,6 +16,12 @@ const AppInitializer: React.FC<AppInitializerProps> = ({ onInitialized }) => {
     const fetchData = async () => {
     const fetchData = async () => {
       if (userInfo && userInfo.token) {
       if (userInfo && userInfo.token) {
         await dispatch(getPatientTypes({ params: {}, token: userInfo.token }));
         await dispatch(getPatientTypes({ params: {}, token: userInfo.token }));
+        await dispatch(
+          getBodyParts({
+            params: {},
+            token: userInfo.token,
+          })
+        );
       }
       }
       onInitialized();
       onInitialized();
     };
     };

+ 5 - 1
src/pages/patient/components/RegisterAvailableFilterBar.tsx

@@ -3,6 +3,7 @@ import { Row, Col, Select, Segmented } from 'antd';
 import { useSelector } from 'react-redux';
 import { useSelector } from 'react-redux';
 import { RootState } from '@/states/store';
 import { RootState } from '@/states/store';
 import { PatientType } from '@/API/patientType';
 import { PatientType } from '@/API/patientType';
+import { BodyPart } from '@/API/bodyPart';
 
 
 interface Props {
 interface Props {
   selected: 'protocol' | 'view';
   selected: 'protocol' | 'view';
@@ -54,7 +55,10 @@ const RegisterAvailableFilterBar: React.FC<Props> = ({
             allowClear
             allowClear
             style={{ width: '100%' }}
             style={{ width: '100%' }}
             placeholder="身体部位"
             placeholder="身体部位"
-            options={bodyParts}
+            options={bodyParts.map((item: BodyPart) => ({
+              label: item.body_part_name,
+              value: item.body_part_id,
+            }))}
             value={bodyPart}
             value={bodyPart}
             onChange={setBodyPart}
             onChange={setBodyPart}
           />
           />

+ 2 - 0
src/states/bodyPartSlice.ts

@@ -25,6 +25,8 @@ export const getBodyParts = createAsyncThunk(
       return data;
       return data;
     } catch (err: unknown) {
     } catch (err: unknown) {
       let errorMessage = 'Failed to fetch body parts';
       let errorMessage = 'Failed to fetch body parts';
+      console.log(errorMessage);
+
       if (
       if (
         err &&
         err &&
         typeof err === 'object' &&
         typeof err === 'object' &&