feat(emr): 同步时清空归档假数据并从病历表生成真实归档记录
- 清空emr_archive_record表假数据 - 从doc_emr同步生成归档记录 - 同步统计增加归档记录数量
This commit is contained in:
@@ -10,8 +10,10 @@ import com.healthlink.his.administration.mapper.EncounterMapper;
|
||||
import com.healthlink.his.administration.mapper.PatientMapper;
|
||||
import com.healthlink.his.document.domain.Emr;
|
||||
import com.healthlink.his.document.service.IEmrService;
|
||||
import com.healthlink.his.emr.domain.EmrArchiveRecord;
|
||||
import com.healthlink.his.emr.domain.EmrRevision;
|
||||
import com.healthlink.his.emr.domain.EmrSearchIndex;
|
||||
import com.healthlink.his.emr.service.IEmrArchiveRecordService;
|
||||
import com.healthlink.his.emr.service.IEmrRevisionService;
|
||||
import com.healthlink.his.emr.service.IEmrSearchIndexService;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
@@ -36,6 +38,7 @@ public class EmrSyncController {
|
||||
private final IEmrService emrService;
|
||||
private final IEmrRevisionService emrRevisionService;
|
||||
private final IEmrSearchIndexService emrSearchIndexService;
|
||||
private final IEmrArchiveRecordService emrArchiveRecordService;
|
||||
private final JdbcTemplate jdbcTemplate;
|
||||
private final PatientMapper patientMapper;
|
||||
private final EncounterMapper encounterMapper;
|
||||
@@ -54,7 +57,8 @@ public class EmrSyncController {
|
||||
try {
|
||||
jdbcTemplate.execute("TRUNCATE TABLE emr_revision CASCADE");
|
||||
jdbcTemplate.execute("TRUNCATE TABLE emr_search_index CASCADE");
|
||||
log.info("已清空emr_revision和emr_search_index表");
|
||||
jdbcTemplate.execute("TRUNCATE TABLE emr_archive_record CASCADE");
|
||||
log.info("已清空emr_revision、emr_search_index和emr_archive_record表");
|
||||
} catch (Exception e) {
|
||||
log.warn("TRUNCATE失败,尝试使用DELETE: {}", e.getMessage());
|
||||
// 备用方案:查询所有ID后删除
|
||||
@@ -68,6 +72,11 @@ public class EmrSyncController {
|
||||
if (!searchIndexIds.isEmpty()) {
|
||||
emrSearchIndexService.removeByIds(searchIndexIds);
|
||||
}
|
||||
List<Long> archiveIds = emrArchiveRecordService.list(new LambdaQueryWrapper<EmrArchiveRecord>().select(EmrArchiveRecord::getId))
|
||||
.stream().map(EmrArchiveRecord::getId).toList();
|
||||
if (!archiveIds.isEmpty()) {
|
||||
emrArchiveRecordService.removeByIds(archiveIds);
|
||||
}
|
||||
}
|
||||
|
||||
// 2. 从doc_emr获取所有病历
|
||||
@@ -89,6 +98,7 @@ public class EmrSyncController {
|
||||
|
||||
int revisionCount = 0;
|
||||
int searchIndexCount = 0;
|
||||
int archiveCount = 0;
|
||||
|
||||
for (Emr emr : emrList) {
|
||||
// 3. 创建修订历史
|
||||
@@ -188,12 +198,29 @@ public class EmrSyncController {
|
||||
index.setCreateTime(emr.getCreateTime());
|
||||
emrSearchIndexService.save(index);
|
||||
searchIndexCount++;
|
||||
|
||||
// 5. 创建归档记录
|
||||
EmrArchiveRecord archive = new EmrArchiveRecord();
|
||||
archive.setEmrId(emr.getId());
|
||||
archive.setEncounterId(emr.getEncounterId());
|
||||
archive.setPatientId(emr.getPatientId());
|
||||
archive.setPatientName(patientName);
|
||||
archive.setEmrType(emr.getClassEnum() != null && emr.getClassEnum() == 1 ? "OUTPATIENT" : "INPATIENT");
|
||||
archive.setEmrTitle(chiefComplaint.isEmpty() ? "未命名病历" : chiefComplaint);
|
||||
archive.setArchiveType("PRINT");
|
||||
archive.setArchiveStatus("PRINTED");
|
||||
archive.setPrintTime(emr.getCreateTime());
|
||||
archive.setPrintBy(doctorName);
|
||||
archive.setPrintCount(1);
|
||||
archive.setCreateTime(emr.getCreateTime());
|
||||
emrArchiveRecordService.save(archive);
|
||||
archiveCount++;
|
||||
} catch (Exception e) {
|
||||
log.warn("创建搜索索引失败: emrId={}, error={}", emr.getId(), e.getMessage(), e);
|
||||
}
|
||||
}
|
||||
|
||||
String result = String.format("同步完成: 修订历史%d条, 搜索索引%d条", revisionCount, searchIndexCount);
|
||||
String result = String.format("同步完成: 修订历史%d条, 搜索索引%d条, 归档记录%d条", revisionCount, searchIndexCount, archiveCount);
|
||||
log.info(result);
|
||||
return R.ok(result);
|
||||
}
|
||||
@@ -208,6 +235,7 @@ public class EmrSyncController {
|
||||
stats.put("emrCount", emrService.count());
|
||||
stats.put("revisionCount", emrRevisionService.count());
|
||||
stats.put("searchIndexCount", emrSearchIndexService.count());
|
||||
stats.put("archiveCount", emrArchiveRecordService.count());
|
||||
return R.ok(stats);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user