123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103 |
- package thyyxxk.webserver.service.zhuyuanyisheng;
- import lombok.extern.slf4j.Slf4j;
- import org.springframework.stereotype.Service;
- import thyyxxk.webserver.config.exception.ExceptionEnum;
- import thyyxxk.webserver.dao.his.zhuyuanyisheng.EmrPatientDao;
- import thyyxxk.webserver.entity.ResultVo;
- import thyyxxk.webserver.entity.zhuyuanyisheng.EmrPatientData;
- import thyyxxk.webserver.utils.DateUtil;
- import thyyxxk.webserver.utils.ResultVoUtil;
- import thyyxxk.webserver.utils.TokenUtil;
- import java.util.ArrayList;
- import java.util.List;
- import java.util.Map;
- import java.util.stream.Collectors;
- @Service
- @Slf4j
- public class EmrServer {
- private final EmrPatientDao dao;
- public EmrServer(EmrPatientDao dao) {
- this.dao = dao;
- }
- /**
- * 获取这个患者这个住院次数的全部电子病历
- *
- * @param patNo 住院号
- * @param times 住院次数
- * @return 数据
- */
- public ResultVo<List<EmrPatientData>> getPatientData(String patNo, Integer times) {
- List<EmrPatientData> data = new ArrayList<>();
- Map<String, List<EmrPatientData>> map = dao.getPatientData(patNo, times).stream().collect(
- Collectors.groupingBy(EmrPatientData::getEmrCategoryCode)
- );
- for (Map.Entry<String, List<EmrPatientData>> key : map.entrySet()) {
- if (key.getValue().size() == 1) {
- EmrPatientData parentNode = key.getValue().get(0);
- String name = parentNode.getName() + "/" + DateUtil.formatDatetime(parentNode.getModifyDate() != null ? parentNode.getModifyDate() : parentNode.getCreateDate());
- key.getValue().get(0).setName(name);
- data.add(key.getValue().get(0));
- } else {
- EmrPatientData item = new EmrPatientData();
- List<EmrPatientData> children = new ArrayList<>();
- for (int i = 0, len = key.getValue().size(); i < len; i++) {
- EmrPatientData childNode = key.getValue().get(i);
- String name = childNode.getName() + "/" + DateUtil.formatDatetime(childNode.getModifyDate() != null ? childNode.getModifyDate() : childNode.getCreateDate());
- childNode.setName(name);
- children.add(childNode);
- }
- item.setName(key.getValue().get(0).getEmrName());
- item.setChildren(new ArrayList<>()).getChildren().addAll(children);
- data.add(item);
- }
- }
- return ResultVoUtil.success(data);
- }
- /**
- * 保存患者电子病历信息
- *
- * @param param 参数
- * @return 提示
- */
- public ResultVo<String> insertEmrData(EmrPatientData param) {
- param.setCreateId(TokenUtil.getTokenUserId());
- if (dao.isThereARecordOfTheCourseOfTheDisease(param.getPatNo(), param.getTimes()) != null) {
- return ResultVoUtil.fail(ExceptionEnum.INTERNAL_SERVER_ERROR, "该患者已经存在病程记录了,请勿重新填写。");
- }
- try {
- dao.emrInsertForTheFirstTime(param);
- } catch (Exception e) {
- dao.updateCreatedTemplate(param);
- return ResultVoUtil.success(ExceptionEnum.SUCCESS_AND_NOTIFICATION, "保存成功,已覆盖原数据。");
- }
- return ResultVoUtil.success(ExceptionEnum.SUCCESS_AND_NOTIFICATION, "保存到本院成功");
- }
- /**
- * 根据患者的电子病历 id 来删除
- * 这里用的是逻辑删除
- *
- * @param documentId 电子病历id
- * @return 提示
- */
- public ResultVo<String> deletePatientEmrByDocumentId(String documentId) {
- dao.deletePatientEmrByDocumentId(documentId, TokenUtil.getTokenUserId());
- return ResultVoUtil.success(ExceptionEnum.SUCCESS_AND_NOTIFICATION, "删除成功.");
- }
- }
|