package com.diagbot.service.impl;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.diagbot.dto.DoctorAdviceDTO;
import com.diagbot.entity.DoctorAdvice;
import com.diagbot.mapper.DoctorAdviceMapper;
import com.diagbot.service.DoctorAdviceService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.diagbot.vo.DoctorAdviceVO;
import com.diagbot.vo.FilterVO;
import org.apache.commons.collections4.CollectionUtils;
import org.springframework.stereotype.Service;

import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;

/**
 * <p>
 * 病人医嘱 服务实现类
 * </p>
 *
 * @author zhoutg
 * @time: 2024-04-13
 */
@Service
public class DoctorAdviceServiceImpl extends ServiceImpl<DoctorAdviceMapper, DoctorAdvice> implements DoctorAdviceService {
    /**
     * 根据医嘱ID和医院编码-批量更新数据
     *
     * @param list
     */
    public void updateBatchByKey(List<DoctorAdvice> list) {
        this.baseMapper.updateBatchByKey(list);
    }



    public IPage<DoctorAdviceDTO> getPage(DoctorAdviceVO doctorAdviceVO) {

        List<String> infos = this.baseMapper.getInfo(doctorAdviceVO.getHospitalId(), doctorAdviceVO.getBehospitalCode());
        Set<String> infoSet = new HashSet<>();
        for (String s : infos) {
            if (s.contains("医嘱：")) {
                String[] split = s.split("_");
                for (String info : split) {
                    String[] targetInfos = info.split("：");
                    for (String target : targetInfos) {
                        if (!"医嘱".equals(target)) {
                            infoSet.add(target);
                        }
                    }
                }
            }
        }

        IPage<DoctorAdviceDTO> page = this.baseMapper.getPage(doctorAdviceVO, infoSet);
        return page;
    }


    /**
     * 获取医嘱
     */
    public List<Map<String, String>> getDoctorAdviceNum(FilterVO filterVO){
        return baseMapper.getDoctorAdviceNum(filterVO);
    }
}
