package com.openhis.clinical.service.impl;

import java.util.Date;
import java.util.List;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.openhis.common.enums.DelFlag;
import org.springframework.stereotype.Service;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.core.common.utils.SecurityUtils;
import com.openhis.clinical.domain.Condition;
import com.openhis.clinical.mapper.ConditionMapper;
import com.openhis.clinical.service.IConditionService;

/**
 * 疾病与诊断管理Service业务层处理
 *
 * @author system
 * @date 2025-02-20
 */
@Service
public class ConditionServiceImpl extends ServiceImpl<ConditionMapper, Condition> implements IConditionService {

    /**
     * 医生门诊就诊时保存诊断
     *
     * @param condition 诊断信息
     * @return 主键ID
     */
    @Override
    public Long saveConditionByDoctor(Condition condition) {
        condition.setRecordedDatetime(new Date());
        condition.setRecorderId(SecurityUtils.getLoginUser().getPractitionerId());// 记录人
        if (condition.getId() == null) {
            baseMapper.insert(condition);
        } else {
            baseMapper.updateById(condition);
        }
        return condition.getId();
    }

    /**
     * 根据id查诊断集合
     * 
     * @param collect id集合
     * @return 诊断集合
     */
    @Override
    public List<Condition> getConditionListById(List<Long> collect) {
        return baseMapper.selectList(new LambdaQueryWrapper<Condition>().in(Condition::getId, collect)
            .eq(Condition::getDeleteFlag, DelFlag.NO.getCode()));
    }
}