package com.xinelu.manage.service.patientvisitouthospital.impl;

import com.xinelu.common.utils.DateUtils;
import com.xinelu.manage.domain.patientvisitouthospital.PatientVisitOutHospital;
import com.xinelu.manage.mapper.patientvisitouthospital.PatientVisitOutHospitalMapper;
import com.xinelu.manage.service.patientvisitouthospital.IPatientVisitOutHospitalService;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;

import javax.annotation.Resource;
import java.time.LocalDateTime;
import java.util.List;

/**
 * 患者就诊出院记录信息Service业务层处理
 *
 * @author xinelu
 * @date 2024-02-26
 */
@Service
public class PatientVisitOutHospitalServiceImpl implements IPatientVisitOutHospitalService {
    @Resource
    private PatientVisitOutHospitalMapper patientVisitOutHospitalMapper;

    /**
     * 查询患者就诊出院记录信息
     *
     * @param id 患者就诊出院记录信息主键
     * @return 患者就诊出院记录信息
     */
    @Override
    public PatientVisitOutHospital selectPatientVisitOutHospitalById(Long id) {
        return patientVisitOutHospitalMapper.selectPatientVisitOutHospitalById(id);
    }

    /**
     * 查询患者就诊出院记录信息列表
     *
     * @param patientVisitOutHospital 患者就诊出院记录信息
     * @return 患者就诊出院记录信息
     */
    @Override
    public List<PatientVisitOutHospital> selectPatientVisitOutHospitalList(PatientVisitOutHospital patientVisitOutHospital) {
        return patientVisitOutHospitalMapper.selectPatientVisitOutHospitalList(patientVisitOutHospital);
    }

    @Override
    public PatientVisitOutHospital getByVisitRecord(Long patientVisitRecordId) {
        PatientVisitOutHospital patientVisitOutHospital = new PatientVisitOutHospital();
        patientVisitOutHospital.setPatientVisitRecordId(patientVisitRecordId);
        List<PatientVisitOutHospital> list = patientVisitOutHospitalMapper.selectPatientVisitOutHospitalList(patientVisitOutHospital);
        if (CollectionUtils.isEmpty(list)) {
            return null;
        }
        return list.get(0);
    }

    /**
     * 新增患者就诊出院记录信息
     *
     * @param patientVisitOutHospital 患者就诊出院记录信息
     * @return 结果
     */
    @Override
    public int insertPatientVisitOutHospital(PatientVisitOutHospital patientVisitOutHospital) {
        patientVisitOutHospital.setCreateTime(LocalDateTime.now());
        return patientVisitOutHospitalMapper.insertPatientVisitOutHospital(patientVisitOutHospital);
    }

    /**
     * 修改患者就诊出院记录信息
     *
     * @param patientVisitOutHospital 患者就诊出院记录信息
     * @return 结果
     */
    @Override
    public int updatePatientVisitOutHospital(PatientVisitOutHospital patientVisitOutHospital) {
        patientVisitOutHospital.setUpdateTime(LocalDateTime.now());
        return patientVisitOutHospitalMapper.updatePatientVisitOutHospital(patientVisitOutHospital);
    }

    /**
     * 批量删除患者就诊出院记录信息
     *
     * @param ids 需要删除的患者就诊出院记录信息主键
     * @return 结果
     */
    @Override
    public int deletePatientVisitOutHospitalByIds(Long[] ids) {
        return patientVisitOutHospitalMapper.deletePatientVisitOutHospitalByIds(ids);
    }

    /**
     * 删除患者就诊出院记录信息信息
     *
     * @param id 患者就诊出院记录信息主键
     * @return 结果
     */
    @Override
    public int deletePatientVisitOutHospitalById(Long id) {
        return patientVisitOutHospitalMapper.deletePatientVisitOutHospitalById(id);
    }
}
