feat(mrhomepage): 病案示踪管理

This commit is contained in:
2026-06-17 14:46:17 +08:00
parent 786fc14147
commit f1a8fafb72
3 changed files with 163 additions and 0 deletions

View File

@@ -0,0 +1,15 @@
package com.healthlink.his.web.mrhomepage.appservice;
import com.healthlink.his.mrhomepage.domain.MrBorrowing;
import com.healthlink.his.mrhomepage.domain.MrTracking;
import java.util.Map;
public interface IMrTrackingAppService {
Map<String, Object> trackStatus(Long homepageId);
MrBorrowing borrowRecord(MrBorrowing borrowing);
void returnRecord(Long borrowingId);
}

View File

@@ -0,0 +1,105 @@
package com.healthlink.his.web.mrhomepage.appservice.impl;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.healthlink.his.mrhomepage.domain.MrBorrowing;
import com.healthlink.his.mrhomepage.domain.MrTracking;
import com.healthlink.his.mrhomepage.service.IMrBorrowingService;
import com.healthlink.his.mrhomepage.service.IMrTrackingService;
import com.healthlink.his.web.mrhomepage.appservice.IMrTrackingAppService;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@Service
public class MrTrackingAppServiceImpl implements IMrTrackingAppService {
@Resource
private IMrTrackingService trackingService;
@Resource
private IMrBorrowingService borrowingService;
@Override
public Map<String, Object> trackStatus(Long homepageId) {
LambdaQueryWrapper<MrTracking> wrapper = new LambdaQueryWrapper<>();
wrapper.eq(MrTracking::getMedicalRecordId, homepageId)
.orderByDesc(MrTracking::getMoveTime);
List<MrTracking> records = trackingService.list(wrapper);
Map<String, Object> result = new HashMap<>();
result.put("records", records);
long inShelf = records.stream().filter(r -> "IN_SHELF".equals(r.getStatus())).count();
long borrowed = records.stream().filter(r -> "BORROWED".equals(r.getStatus())).count();
long archived = records.stream().filter(r -> "ARCHIVED".equals(r.getStatus())).count();
long lost = records.stream().filter(r -> "LOST".equals(r.getStatus())).count();
Map<String, Long> stats = new HashMap<>();
stats.put("inShelf", inShelf);
stats.put("borrowed", borrowed);
stats.put("archived", archived);
stats.put("lost", lost);
result.put("stats", stats);
MrTracking current = records.isEmpty() ? null : records.get(0);
result.put("currentStatus", current != null ? current.getStatus() : "UNKNOWN");
result.put("currentLocation", current != null ? current.getLocation() : null);
return result;
}
@Override
@Transactional(rollbackFor = Exception.class)
public MrBorrowing borrowRecord(MrBorrowing borrowing) {
borrowing.setStatus(0);
borrowing.setBorrowDate(new Date());
borrowing.setCreateTime(new Date());
borrowingService.save(borrowing);
LambdaQueryWrapper<MrTracking> wrapper = new LambdaQueryWrapper<>();
wrapper.eq(MrTracking::getMedicalRecordId, borrowing.getMedicalRecordId())
.eq(MrTracking::getStatus, "IN_SHELF");
MrTracking track = trackingService.getOne(wrapper);
if (track != null) {
track.setStatus("BORROWED");
track.setLocation(borrowing.getBorrowerDept() != null ? borrowing.getBorrowerDept() : "借出");
track.setLocationType("BORROWED");
track.setMovedBy(borrowing.getBorrowerName());
track.setMoveTime(new Date());
trackingService.updateById(track);
}
return borrowing;
}
@Override
@Transactional(rollbackFor = Exception.class)
public void returnRecord(Long borrowingId) {
MrBorrowing borrowing = borrowingService.getById(borrowingId);
if (borrowing == null) {
throw new RuntimeException("借阅记录不存在");
}
borrowing.setActualReturnDate(new Date());
borrowing.setStatus(3);
borrowing.setUpdateTime(new Date());
borrowingService.updateById(borrowing);
LambdaQueryWrapper<MrTracking> wrapper = new LambdaQueryWrapper<>();
wrapper.eq(MrTracking::getMedicalRecordId, borrowing.getMedicalRecordId())
.eq(MrTracking::getStatus, "BORROWED");
MrTracking track = trackingService.getOne(wrapper);
if (track != null) {
track.setStatus("IN_SHELF");
track.setLocation("病案室");
track.setLocationType("STORAGE");
track.setMovedBy("系统自动归还");
track.setMoveTime(new Date());
trackingService.updateById(track);
}
}
}

View File

@@ -0,0 +1,43 @@
package com.healthlink.his.web.mrhomepage.controller;
import com.core.common.core.domain.R;
import com.healthlink.his.mrhomepage.domain.MrBorrowing;
import com.healthlink.his.web.mrhomepage.appservice.IMrTrackingAppService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
import java.util.Map;
@RestController
@RequestMapping("/api/v1/mr-homepage/tracking")
@Tag(name = "病案示踪管理")
public class MrTrackingController {
@Resource
private IMrTrackingAppService mrTrackingAppService;
@GetMapping("/{homepageId}")
@PreAuthorize("hasAuthority('inpatient:mrhomepage:list')")
@Operation(summary = "查询病案示踪状态")
public R<Map<String, Object>> trackStatus(@PathVariable Long homepageId) {
return R.ok(mrTrackingAppService.trackStatus(homepageId));
}
@PostMapping("/borrow")
@PreAuthorize("hasAuthority('inpatient:mrhomepage:edit')")
@Operation(summary = "病案借阅")
public R<MrBorrowing> borrowRecord(@RequestBody MrBorrowing borrowing) {
return R.ok(mrTrackingAppService.borrowRecord(borrowing));
}
@PostMapping("/return")
@PreAuthorize("hasAuthority('inpatient:mrhomepage:edit')")
@Operation(summary = "病案归还")
public R<Void> returnRecord(@RequestParam Long borrowingId) {
mrTrackingAppService.returnRecord(borrowingId);
return R.ok();
}
}