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

import com.xinelu.manage.domain.patientvisitinhospital.PatientVisitInHospital;
import com.xinelu.manage.mapper.patientvisitinhospital.PatientVisitInHospitalMapper;
import com.xinelu.manage.service.patientvisitinhospital.IPatientVisitInHospitalService;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;

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

/**
 * 患者就诊入院记录信息Service业务层处理
 *
 * @author haown
 * @date 2024-02-26
 */
@Service
public class PatientVisitInHospitalServiceImpl implements IPatientVisitInHospitalService {
    @Resource
    private PatientVisitInHospitalMapper patientVisitInHospitalMapper;

    /**
     * 查询患者就诊入院记录信息
     *
     * @param id 患者就诊入院记录信息主键
     * @return 患者就诊入院记录信息
     */
    @Override
    public PatientVisitInHospital selectPatientVisitInHospitalById(Long id) {
        return patientVisitInHospitalMapper.selectPatientVisitInHospitalById(id);
    }

    @Override
    public PatientVisitInHospital getByVisitRecord(Long patientVisitRecordId) {
        PatientVisitInHospital patientVisitInHospital = new PatientVisitInHospital();
        patientVisitInHospital.setPatientVisitRecordId(patientVisitRecordId);
        List<PatientVisitInHospital> list = patientVisitInHospitalMapper.selectPatientVisitInHospitalList(patientVisitInHospital);
        if (CollectionUtils.isEmpty(list)) {
            return null;
        }
        return list.get(0);
    }

    /**
     * 查询患者就诊入院记录信息列表
     *
     * @param patientVisitInHospital 患者就诊入院记录信息
     * @return 患者就诊入院记录信息
     */
    @Override
    public List<PatientVisitInHospital> selectPatientVisitInHospitalList(PatientVisitInHospital patientVisitInHospital) {
        return patientVisitInHospitalMapper.selectPatientVisitInHospitalList(patientVisitInHospital);
    }

    /**
     * 新增患者就诊入院记录信息
     *
     * @param patientVisitInHospital 患者就诊入院记录信息
     * @return 结果
     */
    @Override
    public int insertPatientVisitInHospital(PatientVisitInHospital patientVisitInHospital) {
        patientVisitInHospital.setCreateTime(LocalDateTime.now());
        return patientVisitInHospitalMapper.insertPatientVisitInHospital(patientVisitInHospital);
    }

    /**
     * 修改患者就诊入院记录信息
     *
     * @param patientVisitInHospital 患者就诊入院记录信息
     * @return 结果
     */
    @Override
    public int updatePatientVisitInHospital(PatientVisitInHospital patientVisitInHospital) {
        patientVisitInHospital.setUpdateTime(LocalDateTime.now());
        return patientVisitInHospitalMapper.updatePatientVisitInHospital(patientVisitInHospital);
    }

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

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