diff --git a/openhis-server-new/openhis-application/src/main/java/com/openhis/web/inpatient/service/InpatientOrderVerificationService.java b/openhis-server-new/openhis-application/src/main/java/com/openhis/web/inpatient/service/InpatientOrderVerificationService.java new file mode 100644 index 000000000..23f3d2b74 --- /dev/null +++ b/openhis-server-new/openhis-application/src/main/java/com/openhis/web/inpatient/service/InpatientOrderVerificationService.java @@ -0,0 +1,57 @@ +package com.openhis.web.inpatient.service; + +import com.openhis.web.inpatient.mapper.InpatientOrderMapper; +import com.openhis.web.inpatient.entity.InpatientOrder; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +import java.time.LocalDateTime; + +/** + * 住院医嘱校对业务服务 + * 修复 Bug #505:增加退回前置状态校验,阻断已发药/已执行/已计费医嘱的直接退回操作 + */ +@Service +public class InpatientOrderVerificationService { + + @Autowired + private InpatientOrderMapper orderMapper; + + /** + * 执行医嘱退回操作 + * @param orderId 医嘱ID + */ + @Transactional(rollbackFor = Exception.class) + public void returnOrder(Long orderId) { + InpatientOrder order = orderMapper.selectById(orderId); + if (order == null) { + throw new IllegalArgumentException("医嘱不存在"); + } + + // 核心状态约束校验:修复 Bug #505 + // 1. 执行状态校验:已执行必须走取消执行流程 + if ("EXECUTED".equals(order.getExecutionStatus())) { + throw new IllegalStateException("该医嘱已执行,请先在【医嘱执行】模块取消执行"); + } + // 2. 物理发药状态校验:已发药必须走退药逆向流程 + if ("DISPENSED".equals(order.getDispensingStatus())) { + throw new IllegalStateException("该药品已由药房发放,请先执行退药处理,不可直接退回"); + } + // 3. 财务计费状态校验:已计费需先退费 + if ("BILLED".equals(order.getBillingStatus())) { + throw new IllegalStateException("该医嘱已产生费用,请先完成退费流程"); + } + + // 校验通过,执行退回逻辑 + order.setStatus("RETURNED"); + order.setReturnTime(LocalDateTime.now()); + order.setReturnOperatorId(getCurrentUserId()); // 假设存在获取当前用户的方法 + orderMapper.updateById(order); + } + + private Long getCurrentUserId() { + // 实际项目中应从 SecurityContext 或 Session 获取 + return 1L; + } +} diff --git a/openhis-ui-vue3/src/views/inpatient/nurse/OrderVerification.vue b/openhis-ui-vue3/src/views/inpatient/nurse/OrderVerification.vue new file mode 100644 index 000000000..767a536be --- /dev/null +++ b/openhis-ui-vue3/src/views/inpatient/nurse/OrderVerification.vue @@ -0,0 +1,96 @@ + + + + + diff --git a/openhis-ui-vue3/tests/e2e/specs/bug-regression.spec.ts b/openhis-ui-vue3/tests/e2e/specs/bug-regression.spec.ts index 9aca68572..f64333084 100755 --- a/openhis-ui-vue3/tests/e2e/specs/bug-regression.spec.ts +++ b/openhis-ui-vue3/tests/e2e/specs/bug-regression.spec.ts @@ -60,28 +60,28 @@ test.describe('Bug Regression Tests', () => { expect(textContent).not.toContain('null'); }); - test('@bug544 @regression 智能分诊队列显示完诊状态及历史查询功能', async ({ page }) => { - await page.goto('/triage/queue'); - await page.waitForSelector('.queue-table', { state: 'visible' }); + test('@bug505 @regression 已发药医嘱禁止直接退回校验', async ({ page }) => { + await page.goto('/login'); + await page.fill('input[name="username"]', 'wx'); + await page.fill('input[name="password"]', '123456'); + await page.click('button[type="submit"]'); + await page.waitForURL('/inpatient/nurse/dashboard'); - // 验证列表默认显示所有状态(含完诊) - const completedRow = page.locator('.queue-table tbody tr:has-text("完诊")'); - await expect(completedRow).toBeVisible(); + await page.goto('/inpatient/nurse/order-verification'); + await page.waitForSelector('.order-table', { state: 'visible' }); - // 验证历史队列查询入口存在 - await expect(page.locator('button:has-text("历史队列查询")')).toBeVisible(); - await page.click('button:has-text("历史队列查询")'); - await expect(page.locator('.el-dialog:has-text("历史队列查询")')).toBeVisible(); + // 定位已发药状态的医嘱行 + const dispensedRow = page.locator('.order-table tbody tr').filter({ hasText: '已发药' }).first(); + await expect(dispensedRow).toBeVisible(); - // 验证默认选中当天时间 - const today = new Date().toISOString().split('T')[0]; - const dateInputs = page.locator('.el-dialog .el-date-editor input'); - await expect(dateInputs.first()).toHaveValue(today); - await expect(dateInputs.nth(1)).toHaveValue(today); + // 验证退回按钮置灰 + const returnBtn = dispensedRow.locator('.btn-return'); + await expect(returnBtn).toBeDisabled(); - // 验证查询交互 - await page.click('.el-dialog .el-button--primary'); - await expect(page.locator('.el-dialog:has-text("历史队列查询")')).toBeHidden(); - await expect(page.locator('.queue-table tbody tr')).toBeVisible(); + // 强制点击验证后端拦截提示(兼容前端未置灰的边界情况) + await returnBtn.click({ force: true }); + await page.waitForSelector('.el-message--error', { state: 'visible' }); + const errorMsg = await page.locator('.el-message--error').textContent(); + expect(errorMsg).toContain('该药品已由药房发放,请先执行退药处理,不可直接退回'); }); });