123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193 |
- package thyyxxk.webserver.service.triage;
- import com.baomidou.mybatisplus.core.metadata.IPage;
- import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
- import lombok.extern.slf4j.Slf4j;
- import org.springframework.beans.factory.annotation.Value;
- import org.springframework.stereotype.Service;
- import org.springframework.transaction.annotation.Transactional;
- import org.springframework.web.client.RestTemplate;
- import thyyxxk.webserver.config.exception.ExceptionEnum;
- import thyyxxk.webserver.constants.Capacity;
- import thyyxxk.webserver.dao.his.triage.TriageDao;
- import thyyxxk.webserver.entity.ResultVo;
- import thyyxxk.webserver.entity.dictionary.CodeName;
- import thyyxxk.webserver.entity.triage.*;
- import thyyxxk.webserver.utils.ResultVoUtil;
- import thyyxxk.webserver.utils.StringUtil;
- import thyyxxk.webserver.utils.TokenUtil;
- import java.util.*;
- /**
- * @author dj
- */
- @Slf4j
- @Service
- public class TriageService {
- private final TriageDao dao;
- @Value("${triage-notify-url}")
- private String triageNotifyUrl;
- public TriageService(TriageDao dao) {
- this.dao = dao;
- }
- public ResultVo<Map<String, Object>> getUnTriagedPatients(Integer currentPage, Integer pageSize) {
- String[] depts = StringUtil.triageDeptString2Array(dao.selectChosenDepts(TokenUtil.getTokenUserId()));
- Map<String, Object> map = new HashMap<>(Capacity.TWO);
- if (depts.length == 0) {
- map.put("totalSize", 0);
- map.put("list", new ArrayList<>());
- return ResultVoUtil.success(map);
- }
- IPage<MzfzPatientOrder> iPage = new Page<>(currentPage, pageSize);
- iPage = dao.getUnTriagedPatients(iPage, depts);
- map.put("totalSize", iPage.getTotal());
- map.put("list", iPage.getRecords());
- return ResultVoUtil.success(map);
- }
- public ResultVo<List<MzfzPatientOrder>> getTriagedPatients() {
- String[] depts = StringUtil.triageDeptString2Array(dao.selectChosenDepts(TokenUtil.getTokenUserId()));
- return ResultVoUtil.success(dao.getTriagedPatients(depts));
- }
- public ResultVo<List<FloorScreen>> getBigScreenData(Boolean fullName) {
- String[] depts = StringUtil.triageDeptString2Array(dao.selectChosenDepts(TokenUtil.getTokenUserId()));
- List<MzfzPatientOrder> list = dao.getBigScreenData(depts);
- Map<String, FloorScreen> map = new HashMap<>(Capacity.DEFAULT);
- for (MzfzPatientOrder item : list) {
- if (!fullName) {
- String name = item.getName();
- if (name.length() == 2) {
- name = name.charAt(0) + "*";
- } else {
- name = name.charAt(0) + "*" + name.substring(2);
- }
- item.setName(name);
- }
- if (!map.containsKey(item.getRoomCode())) {
- FloorScreen fl = new FloorScreen();
- fl.setDeptName(item.getDeptName());
- fl.setDoctorTitle(item.getDoctorTitle());
- fl.setDoctorName(item.getDoctorName());
- fl.setRoomNo(item.getRoomNo());
- List<MzfzPatientOrder> temp = new ArrayList<>();
- temp.add(item);
- fl.setPatients(temp);
- map.put(item.getRoomCode(), fl);
- } else {
- map.get(item.getRoomCode()).getPatients().add(item);
- }
- }
- List<FloorScreen> ret = new ArrayList<>();
- for (Map.Entry<String, FloorScreen> entry : map.entrySet()) {
- ret.add(entry.getValue());
- }
- for (FloorScreen item : ret) {
- int size = item.getPatients().size();
- if (size % 4 == 0) {
- item.setPageNum(size / 4);
- } else {
- item.setPageNum(size / 4 + 1);
- }
- }
- return ResultVoUtil.success(ret);
- }
- public ResultVo<List<CodeName>> getChosenDept() {
- String[] depts = StringUtil.triageDeptString2Array(dao.selectChosenDepts(TokenUtil.getTokenUserId()));
- return ResultVoUtil.success(dao.getDept(depts));
- }
- public ResultVo<List<MzfzZdDeptRoom>> getRooms(String deptCode) {
- return ResultVoUtil.success(dao.getRooms(deptCode));
- }
- public ResultVo<String> hasDoneCovidAssessment(String patientId) {
- final String socialNo = dao.getSocialNo(patientId);
- final Integer has = dao.getCovidAssessment(socialNo);
- if (null == has) {
- return ResultVoUtil.fail(ExceptionEnum.NULL_POINTER, "此患者近期未做流调。");
- }
- return ResultVoUtil.success();
- }
- @Transactional(rollbackFor = Exception.class)
- public ResultVo<String> fenZhen(MzfzZdDeptRoom room) {
- int patientNum = dao.getPatientNum(room.getDeptCode(), room.getRoomCode());
- if (patientNum >= 0) {
- room.setPatientNum(patientNum);
- }
- dao.updatePatientNum(room.getDeptCode(), room.getRoomCode(), patientNum);
- dao.fenZhen(room);
- log.info("分诊:update mzfz_patient_order set status_flag=1, slow_flag=0, " +
- "dept_code={}, room_code={}, doctor_code={}, fz_no={} where serial_no={}",
- room.getDeptCode(), room.getRoomCode(), room.getDoctorCode(),
- room.getPatientNum(), room.getSerialNo());
- PatientSidContainer.getInstance().put(room.getSerialNo(), TokenUtil.getTokenUserId());
- return ResultVoUtil.success("分诊成功。");
- }
- public ResultVo<Boolean> notifyComplete(Integer serialNo) {
- log.info("通知完毕>>> {}", serialNo);
- return ResultVoUtil.success(PatientSidContainer.getInstance().delete(serialNo));
- }
- public ResultVo<Integer> fuZhen(Integer serialNo) {
- return ResultVoUtil.success(dao.fuZhen(serialNo));
- }
- public ResultVo<Integer> cancelTriage(Integer serialNo) {
- Integer ret = dao.cancelTriage(serialNo);
- PatientSidContainer.getInstance().delete(serialNo);
- return ResultVoUtil.success(ret);
- }
- public ResultVo<Map<String, Object>> getAllPatients(String searchContent, Integer currentPage, Integer pageSize) {
- String[] depts = StringUtil.triageDeptString2Array(dao.selectChosenDepts(TokenUtil.getTokenUserId()));
- Map<String, Object> map = new HashMap<>(Capacity.TWO);
- searchContent = StringUtil.isBlank(searchContent) ? "%%" : searchContent + "%";
- IPage<MzfzPatientOrder> iPage = new Page<>(currentPage, pageSize);
- iPage = dao.getAllPatients(iPage, depts, searchContent);
- map.put("totalSize", iPage.getTotal());
- map.put("list", iPage.getRecords());
- return ResultVoUtil.success(map);
- }
- public ResultVo<MzYshTzxx> getMzVitalSigns(String patientId) {
- log.info("获取生命体征:{}", patientId);
- MzYshTzxx vitalSigns = dao.getMzVitalSigns(patientId);
- if (null == vitalSigns) {
- vitalSigns = new MzYshTzxx();
- }
- vitalSigns.setPatientId(patientId);
- vitalSigns.setVisitDate(new Date());
- return ResultVoUtil.success(vitalSigns);
- }
- public ResultVo<String> saveMzVitalSigns(MzYshTzxx param) {
- log.info("保存生命体征:{}", param);
- if (null == dao.getMzVitalSigns(param.getPatientId())) {
- dao.insertMzVitalSigns(param);
- } else {
- dao.updateMzVitalSigns(param);
- }
- return ResultVoUtil.success("保存成功");
- }
- public ResultVo<String> notifyMessage(MessageForPush param) {
- MessageForPush prm = dao.selectMessageForPush(param.getSerialNo());
- if (null == prm) {
- return ResultVoUtil.fail(ExceptionEnum.NO_DATA_EXIST, "没有找到此患者的分诊信息!");
- }
- prm.setAction(param.getAction());
- dao.updateStatus(param.getSerialNo());
- log.info("消息推送>>> {}", prm);
- RestTemplate template = new RestTemplate();
- String result = template.postForObject(triageNotifyUrl, prm, String.class);
- return ResultVoUtil.success(result);
- }
- }
|