/** * Mock handlers for date range query testing * 用于测试按日期范围查询 study 的功能 */ import dayjs from 'dayjs'; // ============ Aliases ============ const aliasOfFetchTodayStudies = 'fetchTodayStudies'; export const FetchTodayStudies = `@${aliasOfFetchTodayStudies}`; const aliasOfFetch7DaysStudies = 'fetch7DaysStudies'; export const Fetch7DaysStudies = `@${aliasOfFetch7DaysStudies}`; const aliasOfFetchAllStudies = 'fetchAllStudies'; export const FetchAllStudies = `@${aliasOfFetchAllStudies}`; const aliasOfFetchCustomRangeStudies = 'fetchCustomRangeStudies'; export const FetchCustomRangeStudies = `@${aliasOfFetchCustomRangeStudies}`; const aliasOfFetchEmptyResult = 'fetchEmptyResult'; export const FetchEmptyResult = `@${aliasOfFetchEmptyResult}`; const aliasOfFetchCombinedQuery = 'fetchCombinedQuery'; export const FetchCombinedQuery = `@${aliasOfFetchCombinedQuery}`; // ============ Mock Functions ============ /** * Mock: 查询今天的 study(Worklist) */ export function mockFetchTodayStudiesWorklist() { const today = dayjs().format('YYYY-MM-DD'); cy.intercept('GET', '/dr/api/v1/auth/study*', (req) => { const url = new URL(req.url); const status = url.searchParams.get('status'); const startTime = url.searchParams.get('start_time'); // 只匹配包含今天日期范围的请求 if (status === 'Arrived,InProgress' && startTime?.includes(today)) { req.reply({ statusCode: 200, body: { code: '0x000000', description: 'Success', solution: '', data: { '@type': 'type.googleapis.com/dr.study.StudyList', count: 2, studies: [ { study_instance_uid: '2.25.TODAY.001', study_id: 'TODAY001', public_study_id: '', specific_character_set: 'ISO_IR 192', accession_number: 'ACC_TODAY_001', ref_physician: 'Dr. Wang', patient_id: 'PT_TODAY_001', patient_name: '今天患者1', patient_english_name: 'Today Patient 1', patient_former_name: '', patient_size: 'Medium', other_patient_ids: '', other_patient_names: '', patient_age: '35Y', patient_dob: '1990-01-01T00:00:00Z', patient_sex: 'M', sex_neutered: '', pregnancy_status: '', patient_state: '', admitting_time: null, priority: '', reg_source: '', study_description: '', study_start_datetime: `${today}T08:00:00Z`, study_end_datetime: null, scheduled_procedure_step_start_date: null, performed_physician: '', study_lock: 'Unlocked', folder_path: '', operator_name: 'OP001', modality: 'DX', weight: 70, thickness: 20, length: 175, patient_type: 'Human', study_type: 'Normal', owner_name: '', chip_number: '', variety: '', is_anaesthesia: false, is_sedation: false, mwl: '', is_exported: false, is_edited: false, is_appended: false, department: '', mapped_status: false, qc_result: false, comment: '今天的检查1', study_status: 'Arrived', sort: 0, product: 'DROS', series: [], }, { study_instance_uid: '2.25.TODAY.002', study_id: 'TODAY002', public_study_id: '', specific_character_set: 'ISO_IR 192', accession_number: 'ACC_TODAY_002', ref_physician: 'Dr. Wang', patient_id: 'PT_TODAY_002', patient_name: '今天患者2', patient_english_name: 'Today Patient 2', patient_former_name: '', patient_size: 'Medium', other_patient_ids: '', other_patient_names: '', patient_age: '40Y', patient_dob: '1985-01-01T00:00:00Z', patient_sex: 'F', sex_neutered: '', pregnancy_status: '', patient_state: '', admitting_time: null, priority: '', reg_source: '', study_description: '', study_start_datetime: `${today}T10:00:00Z`, study_end_datetime: null, scheduled_procedure_step_start_date: null, performed_physician: '', study_lock: 'Unlocked', folder_path: '', operator_name: 'OP002', modality: 'DX', weight: 65, thickness: 18, length: 165, patient_type: 'Human', study_type: 'Normal', owner_name: '', chip_number: '', variety: '', is_anaesthesia: false, is_sedation: false, mwl: '', is_exported: false, is_edited: false, is_appended: false, department: '', mapped_status: false, qc_result: false, comment: '今天的检查2', study_status: 'InProgress', sort: 0, product: 'DROS', series: [], }, ], }, }, }); } }).as(aliasOfFetchTodayStudies); } /** * Mock: 查询最近7天的 study(Worklist) */ export function mockFetch7DaysStudiesWorklist() { const today = dayjs(); const sevenDaysAgo = today.subtract(7, 'day'); cy.intercept('GET', '/dr/api/v1/auth/study*', (req) => { const url = new URL(req.url); const status = url.searchParams.get('status'); const startTime = url.searchParams.get('start_time'); // 只匹配包含7天前日期的请求 if ( status === 'Arrived,InProgress' && startTime?.includes(sevenDaysAgo.format('YYYY-MM-DD')) ) { req.reply({ statusCode: 200, body: { code: '0x000000', description: 'Success', solution: '', data: { '@type': 'type.googleapis.com/dr.study.StudyList', count: 5, studies: [ // 今天 { study_instance_uid: '2.25.7DAYS.001', study_id: '7DAYS001', patient_name: '7天患者1', patient_id: 'PT_7D_001', accession_number: 'ACC_7D_001', study_start_datetime: today.format('YYYY-MM-DD') + 'T08:00:00Z', study_status: 'Arrived', patient_type: 'Human', modality: 'DX', study_lock: 'Unlocked', product: 'DROS', series: [], }, // 3天前 { study_instance_uid: '2.25.7DAYS.002', study_id: '7DAYS002', patient_name: '7天患者2', patient_id: 'PT_7D_002', accession_number: 'ACC_7D_002', study_start_datetime: today.subtract(3, 'day').format('YYYY-MM-DD') + 'T10:00:00Z', study_status: 'InProgress', patient_type: 'Human', modality: 'DX', study_lock: 'Unlocked', product: 'DROS', series: [], }, // 5天前 { study_instance_uid: '2.25.7DAYS.003', study_id: '7DAYS003', patient_name: '7天患者3', patient_id: 'PT_7D_003', accession_number: 'ACC_7D_003', study_start_datetime: today.subtract(5, 'day').format('YYYY-MM-DD') + 'T14:00:00Z', study_status: 'Arrived', patient_type: 'Human', modality: 'DX', study_lock: 'Unlocked', product: 'DROS', series: [], }, // 6天前 { study_instance_uid: '2.25.7DAYS.004', study_id: '7DAYS004', patient_name: '7天患者4', patient_id: 'PT_7D_004', accession_number: 'ACC_7D_004', study_start_datetime: today.subtract(6, 'day').format('YYYY-MM-DD') + 'T09:00:00Z', study_status: 'InProgress', patient_type: 'Human', modality: 'DX', study_lock: 'Unlocked', product: 'DROS', series: [], }, // 7天前 { study_instance_uid: '2.25.7DAYS.005', study_id: '7DAYS005', patient_name: '7天患者5', patient_id: 'PT_7D_005', accession_number: 'ACC_7D_005', study_start_datetime: today.subtract(7, 'day').format('YYYY-MM-DD') + 'T11:00:00Z', study_status: 'Arrived', patient_type: 'Human', modality: 'DX', study_lock: 'Unlocked', product: 'DROS', series: [], }, ].map((study) => ({ ...study, specific_character_set: 'ISO_IR 192', ref_physician: 'Dr. Li', patient_english_name: study.patient_name + ' EN', patient_former_name: '', patient_size: 'Medium', other_patient_ids: '', other_patient_names: '', patient_age: '35Y', patient_dob: '1990-01-01T00:00:00Z', patient_sex: 'M', sex_neutered: '', pregnancy_status: '', patient_state: '', admitting_time: null, priority: '', reg_source: '', study_description: '', study_end_datetime: null, scheduled_procedure_step_start_date: null, performed_physician: '', folder_path: '', operator_name: 'OP001', weight: 70, thickness: 20, length: 175, study_type: 'Normal', owner_name: '', chip_number: '', variety: '', is_anaesthesia: false, is_sedation: false, mwl: '', is_exported: false, is_edited: false, is_appended: false, department: '', mapped_status: false, qc_result: false, comment: '', sort: 0, public_study_id: '', })), }, }, }); } }).as(aliasOfFetch7DaysStudies); } /** * Mock: 查询所有 study(不限日期) */ export function mockFetchAllStudiesWorklist() { cy.intercept('GET', '/dr/api/v1/auth/study*', (req) => { const url = new URL(req.url); const status = url.searchParams.get('status'); const startTime = url.searchParams.get('start_time'); const endTime = url.searchParams.get('end_time'); // 匹配不包含日期范围参数的请求 if (status === 'Arrived,InProgress' && !startTime && !endTime) { req.reply({ statusCode: 200, body: { code: '0x000000', description: 'Success', solution: '', data: { '@type': 'type.googleapis.com/dr.study.StudyList', count: 10, studies: Array.from({ length: 10 }, (_, index) => ({ study_instance_uid: `2.25.ALL.${String(index + 1).padStart(3, '0')}`, study_id: `ALL${String(index + 1).padStart(3, '0')}`, public_study_id: '', specific_character_set: 'ISO_IR 192', accession_number: `ACC_ALL_${String(index + 1).padStart(3, '0')}`, ref_physician: 'Dr. Zhang', patient_id: `PT_ALL_${String(index + 1).padStart(3, '0')}`, patient_name: `所有患者${index + 1}`, patient_english_name: `All Patient ${index + 1}`, patient_former_name: '', patient_size: 'Medium', other_patient_ids: '', other_patient_names: '', patient_age: '35Y', patient_dob: '1990-01-01T00:00:00Z', patient_sex: index % 2 === 0 ? 'M' : 'F', sex_neutered: '', pregnancy_status: '', patient_state: '', admitting_time: null, priority: '', reg_source: '', study_description: '', study_start_datetime: dayjs() .subtract(index * 2, 'day') .format('YYYY-MM-DD') + 'T10:00:00Z', study_end_datetime: null, scheduled_procedure_step_start_date: null, performed_physician: '', study_lock: 'Unlocked', folder_path: '', operator_name: 'OP001', modality: 'DX', weight: 70, thickness: 20, length: 175, patient_type: 'Human', study_type: 'Normal', owner_name: '', chip_number: '', variety: '', is_anaesthesia: false, is_sedation: false, mwl: '', is_exported: false, is_edited: false, is_appended: false, department: '', mapped_status: false, qc_result: false, comment: `检查记录${index + 1}`, study_status: index % 2 === 0 ? 'Arrived' : 'InProgress', sort: 0, product: 'DROS', series: [], })), }, }, }); } }).as(aliasOfFetchAllStudies); } /** * Mock: 自定义日期范围查询 */ export function mockFetchCustomRangeStudies(startDate: string, endDate: string) { cy.intercept('GET', '/dr/api/v1/auth/study*', (req) => { const url = new URL(req.url); const status = url.searchParams.get('status'); const startTime = url.searchParams.get('start_time'); // 匹配包含指定日期范围的请求 if (status && startTime?.includes(startDate)) { req.reply({ statusCode: 200, body: { code: '0x000000', description: 'Success', solution: '', data: { '@type': 'type.googleapis.com/dr.study.StudyList', count: 3, studies: [ { study_instance_uid: '2.25.CUSTOM.001', study_id: 'CUSTOM001', patient_name: '自定义范围患者1', patient_id: 'PT_CUSTOM_001', accession_number: 'ACC_CUSTOM_001', study_start_datetime: startDate + 'T08:00:00Z', study_status: 'Arrived', patient_type: 'Human', modality: 'DX', study_lock: 'Unlocked', product: 'DROS', series: [], }, { study_instance_uid: '2.25.CUSTOM.002', study_id: 'CUSTOM002', patient_name: '自定义范围患者2', patient_id: 'PT_CUSTOM_002', accession_number: 'ACC_CUSTOM_002', study_start_datetime: dayjs(startDate).add(2, 'day').format('YYYY-MM-DD') + 'T10:00:00Z', study_status: 'InProgress', patient_type: 'Human', modality: 'DX', study_lock: 'Unlocked', product: 'DROS', series: [], }, { study_instance_uid: '2.25.CUSTOM.003', study_id: 'CUSTOM003', patient_name: '自定义范围患者3', patient_id: 'PT_CUSTOM_003', accession_number: 'ACC_CUSTOM_003', study_start_datetime: dayjs(startDate).add(5, 'day').format('YYYY-MM-DD') + 'T14:00:00Z', study_status: 'Arrived', patient_type: 'Human', modality: 'DX', study_lock: 'Unlocked', product: 'DROS', series: [], }, ].map((study) => ({ ...study, specific_character_set: 'ISO_IR 192', ref_physician: 'Dr. Custom', patient_english_name: study.patient_name + ' EN', patient_former_name: '', patient_size: 'Medium', other_patient_ids: '', other_patient_names: '', patient_age: '35Y', patient_dob: '1990-01-01T00:00:00Z', patient_sex: 'M', sex_neutered: '', pregnancy_status: '', patient_state: '', admitting_time: null, priority: '', reg_source: '', study_description: '', study_end_datetime: null, scheduled_procedure_step_start_date: null, performed_physician: '', folder_path: '', operator_name: 'OP001', weight: 70, thickness: 20, length: 175, study_type: 'Normal', owner_name: '', chip_number: '', variety: '', is_anaesthesia: false, is_sedation: false, mwl: '', is_exported: false, is_edited: false, is_appended: false, department: '', mapped_status: false, qc_result: false, comment: '', sort: 0, public_study_id: '', })), }, }, }); } }).as(aliasOfFetchCustomRangeStudies); } /** * Mock: 空结果(无数据) */ export function mockFetchEmptyResult() { cy.intercept('GET', '/dr/api/v1/auth/study*', { statusCode: 200, body: { code: '0x000000', description: 'Success', solution: '', data: { '@type': 'type.googleapis.com/dr.study.StudyList', count: 0, studies: [], }, }, }).as(aliasOfFetchEmptyResult); } /** * Mock: 组合查询(日期范围 + 患者名称) */ export function mockFetchCombinedQuery() { const today = dayjs().format('YYYY-MM-DD'); cy.intercept('GET', '/dr/api/v1/auth/study*', (req) => { const url = new URL(req.url); const status = url.searchParams.get('status'); const startTime = url.searchParams.get('start_time'); const patientName = url.searchParams.get('patient_name'); // 匹配包含日期范围和患者名称的请求 if (status && startTime?.includes(today) && patientName) { req.reply({ statusCode: 200, body: { code: '0x000000', description: 'Success', solution: '', data: { '@type': 'type.googleapis.com/dr.study.StudyList', count: 1, studies: [ { study_instance_uid: '2.25.COMBINED.001', study_id: 'COMBINED001', public_study_id: '', specific_character_set: 'ISO_IR 192', accession_number: 'ACC_COMBINED_001', ref_physician: 'Dr. Combined', patient_id: 'PT_COMBINED_001', patient_name: patientName, patient_english_name: patientName + ' EN', patient_former_name: '', patient_size: 'Medium', other_patient_ids: '', other_patient_names: '', patient_age: '35Y', patient_dob: '1990-01-01T00:00:00Z', patient_sex: 'M', sex_neutered: '', pregnancy_status: '', patient_state: '', admitting_time: null, priority: '', reg_source: '', study_description: '', study_start_datetime: today + 'T09:00:00Z', study_end_datetime: null, scheduled_procedure_step_start_date: null, performed_physician: '', study_lock: 'Unlocked', folder_path: '', operator_name: 'OP001', modality: 'DX', weight: 70, thickness: 20, length: 175, patient_type: 'Human', study_type: 'Normal', owner_name: '', chip_number: '', variety: '', is_anaesthesia: false, is_sedation: false, mwl: '', is_exported: false, is_edited: false, is_appended: false, department: '', mapped_status: false, qc_result: false, comment: '组合查询结果', study_status: 'Arrived', sort: 0, product: 'DROS', series: [], }, ], }, }, }); } }).as(aliasOfFetchCombinedQuery); } // ============ History Mock Functions ============ /** * Mock: 查询今天的 study(History - Completed) */ export function mockFetchTodayStudiesHistory() { const today = dayjs().format('YYYY-MM-DD'); cy.intercept('GET', '/dr/api/v1/auth/study*', (req) => { const url = new URL(req.url); const status = url.searchParams.get('status'); const startTime = url.searchParams.get('start_time'); if (status === 'Completed' && startTime?.includes(today)) { req.reply({ statusCode: 200, body: { code: '0x000000', description: 'Success', solution: '', data: { '@type': 'type.googleapis.com/dr.study.StudyList', count: 2, studies: [ { study_instance_uid: '2.25.HIST.TODAY.001', study_id: 'HIST_TODAY001', patient_name: 'History今天患者1', patient_id: 'PT_HIST_TODAY_001', accession_number: 'ACC_HIST_TODAY_001', study_start_datetime: today + 'T08:00:00Z', study_status: 'Completed', is_exported: true, patient_type: 'Human', modality: 'DX', study_lock: 'Unlocked', product: 'DROS', series: [], }, { study_instance_uid: '2.25.HIST.TODAY.002', study_id: 'HIST_TODAY002', patient_name: 'History今天患者2', patient_id: 'PT_HIST_TODAY_002', accession_number: 'ACC_HIST_TODAY_002', study_start_datetime: today + 'T10:00:00Z', study_status: 'Completed', is_exported: true, patient_type: 'Human', modality: 'DX', study_lock: 'Unlocked', product: 'DROS', series: [], }, ].map((study) => ({ ...study, specific_character_set: 'ISO_IR 192', ref_physician: 'Dr. History', patient_english_name: study.patient_name + ' EN', patient_former_name: '', patient_size: 'Medium', other_patient_ids: '', other_patient_names: '', patient_age: '35Y', patient_dob: '1990-01-01T00:00:00Z', patient_sex: 'M', sex_neutered: '', pregnancy_status: '', patient_state: '', admitting_time: null, priority: '', reg_source: '', study_description: '', study_end_datetime: null, scheduled_procedure_step_start_date: null, performed_physician: '', folder_path: '', operator_name: 'OP001', weight: 70, thickness: 20, length: 175, study_type: 'Normal', owner_name: '', chip_number: '', variety: '', is_anaesthesia: false, is_sedation: false, mwl: '', is_edited: false, is_appended: false, department: '', mapped_status: true, qc_result: true, comment: '', sort: 0, public_study_id: '', })), }, }, }); } }).as(aliasOfFetchTodayStudies); } /** * Mock: 查询最近7天的 study(History - Completed) */ export function mockFetch7DaysStudiesHistory() { const today = dayjs(); const sevenDaysAgo = today.subtract(7, 'day'); cy.intercept('GET', '/dr/api/v1/auth/study*', (req) => { const url = new URL(req.url); const status = url.searchParams.get('status'); const startTime = url.searchParams.get('start_time'); if ( status === 'Completed' && startTime?.includes(sevenDaysAgo.format('YYYY-MM-DD')) ) { req.reply({ statusCode: 200, body: { code: '0x000000', description: 'Success', solution: '', data: { '@type': 'type.googleapis.com/dr.study.StudyList', count: 4, studies: Array.from({ length: 4 }, (_, index) => ({ study_instance_uid: `2.25.HIST.7DAYS.${String(index + 1).padStart(3, '0')}`, study_id: `HIST_7DAYS${String(index + 1).padStart(3, '0')}`, public_study_id: '', specific_character_set: 'ISO_IR 192', accession_number: `ACC_HIST_7D_${String(index + 1).padStart(3, '0')}`, ref_physician: 'Dr. History7D', patient_id: `PT_HIST_7D_${String(index + 1).padStart(3, '0')}`, patient_name: `History7天患者${index + 1}`, patient_english_name: `History 7Days Patient ${index + 1}`, patient_former_name: '', patient_size: 'Medium', other_patient_ids: '', other_patient_names: '', patient_age: '35Y', patient_dob: '1990-01-01T00:00:00Z', patient_sex: 'M', sex_neutered: '', pregnancy_status: '', patient_state: '', admitting_time: null, priority: '', reg_source: '', study_description: '', study_start_datetime: today.subtract(index + 1, 'day').format('YYYY-MM-DD') + 'T10:00:00Z', study_end_datetime: null, scheduled_procedure_step_start_date: null, performed_physician: '', study_lock: 'Unlocked', folder_path: '', operator_name: 'OP001', modality: 'DX', weight: 70, thickness: 20, length: 175, study_type: 'Normal', owner_name: '', chip_number: '', variety: '', is_anaesthesia: false, is_sedation: false, mwl: '', is_exported: true, is_edited: false, is_appended: false, department: '', mapped_status: true, qc_result: true, comment: '', study_status: 'Completed', sort: 0, product: 'DROS', series: [], })), }, }, }); } }).as(aliasOfFetch7DaysStudies); } /** * Mock: 查询所有 study(History - Completed) */ export function mockFetchAllStudiesHistory() { cy.intercept('GET', '/dr/api/v1/auth/study*', (req) => { const url = new URL(req.url); const status = url.searchParams.get('status'); const startTime = url.searchParams.get('start_time'); const endTime = url.searchParams.get('end_time'); // 匹配不包含日期范围参数的请求 if (status === 'Completed' && !startTime && !endTime) { req.reply({ statusCode: 200, body: { code: '0x000000', description: 'Success', solution: '', data: { '@type': 'type.googleapis.com/dr.study.StudyList', count: 8, studies: Array.from({ length: 8 }, (_, index) => ({ study_instance_uid: `2.25.HIST.ALL.${String(index + 1).padStart(3, '0')}`, study_id: `HIST_ALL${String(index + 1).padStart(3, '0')}`, public_study_id: '', specific_character_set: 'ISO_IR 192', accession_number: `ACC_HIST_ALL_${String(index + 1).padStart(3, '0')}`, ref_physician: 'Dr. HistoryAll', patient_id: `PT_HIST_ALL_${String(index + 1).padStart(3, '0')}`, patient_name: `History所有患者${index + 1}`, patient_english_name: `History All Patient ${index + 1}`, patient_former_name: '', patient_size: 'Medium', other_patient_ids: '', other_patient_names: '', patient_age: '35Y', patient_dob: '1990-01-01T00:00:00Z', patient_sex: index % 2 === 0 ? 'M' : 'F', sex_neutered: '', pregnancy_status: '', patient_state: '', admitting_time: null, priority: '', reg_source: '', study_description: '', study_start_datetime: dayjs() .subtract(index * 3, 'day') .format('YYYY-MM-DD') + 'T10:00:00Z', study_end_datetime: null, scheduled_procedure_step_start_date: null, performed_physician: '', study_lock: 'Unlocked', folder_path: '', operator_name: 'OP001', modality: 'DX', weight: 70, thickness: 20, length: 175, patient_type: 'Human', study_type: 'Normal', owner_name: '', chip_number: '', variety: '', is_anaesthesia: false, is_sedation: false, mwl: '', is_exported: true, is_edited: false, is_appended: false, department: '', mapped_status: true, qc_result: true, comment: `History检查记录${index + 1}`, study_status: 'Completed', sort: 0, product: 'DROS', series: [], })), }, }, }); } }).as(aliasOfFetchAllStudies); }