package com.fs.hospital.mapper;

import java.util.List;
import com.fs.hospital.domain.HospitalPatient;
import com.fs.hospital.vo.HospitalPatientHVO;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Repository;

/**
 * 患者Mapper接口
 *
 * @author fs
 * @date 2024-03-04
 */
@Repository
public interface HospitalPatientMapper
{
    /**
     * 查询患者
     *
     * @param patientId 患者主键
     * @return 患者
     */
    public HospitalPatient selectHospitalPatientByPatientId(Long patientId);

    /**
     * 查询患者列表
     *
     * @param hospitalPatient 患者
     * @return 患者集合
     */
    public List<HospitalPatient> selectHospitalPatientList(HospitalPatient hospitalPatient);

    /**
     * 查询患者列表（模糊）
     *
     * @param hospitalPatient 患者
     * @return 患者集合
     */
    public List<HospitalPatient> selectHospitalPatientScreenList(HospitalPatient hospitalPatient);

    /**
     * 新增患者
     *
     * @param hospitalPatient 患者
     * @return 结果
     */
    public int insertHospitalPatient(HospitalPatient hospitalPatient);

    /**
     * 修改患者
     *
     * @param hospitalPatient 患者
     * @return 结果
     */
    public int updateHospitalPatient(HospitalPatient hospitalPatient);

    /**
     * 删除患者
     *
     * @param patientId 患者主键
     * @return 结果
     */
    public int deleteHospitalPatientByPatientId(Long patientId);

    /**
     * 批量删除患者
     *
     * @param patientIds 需要删除的数据主键集合
     * @return 结果
     */
    public int deleteHospitalPatientByPatientIds(Long[] patientIds);
    @Select("select p.*,h.hospital_name FROM hospital_patient p LEFT JOIN hospital h ON h.hospital_id=p.hospital_id  where p.patient_id=#{patientId}")
    HospitalPatientHVO selectHospitalPatientPVOByPatientId(Long patientId);

    @Select({"<script> " +
            "select * from hospital_patient " +
            "where\n" +
            " member_id is null " +
            "            <if test=\"patientName != null  and patientName != ''\"> and patient_name like concat('%', #{patientName}, '%')</if>\n" +
            "            <if test=\"memberId != null \"> and member_id = #{memberId}</if>\n" +
            "            <if test=\"idCard != null  and idCard != ''\"> and id_card = #{idCard}</if>\n" +
            "            <if test=\"birthday != null \"> and birthday = #{birthday}</if>\n" +
            "            <if test=\"sex != null \"> and sex = #{sex}</if>\n" +
            "            <if test=\"weight != null \"> and weight = #{weight}</if>\n" +
            "            <if test=\"mobile != null  and mobile != ''\"> and mobile = #{mobile}</if>\n" +
            "            <if test=\"isDel != null \"> and is_del = #{isDel}</if>\n" +
            "            <if test=\"status != null \"> and status = #{status}</if>\n" +
            "            <if test=\"relation != null  and relation != ''\"> and relation = #{relation}</if>\n" +
            "            <if test=\"liverUnusual != null  and liverUnusual != ''\"> and liver_unusual = #{liverUnusual}</if>\n" +
            "            <if test=\"renalUnusual != null  and renalUnusual != ''\"> and renal_unusual = #{renalUnusual}</if>\n" +
            "            <if test=\"historyAllergic != null  and historyAllergic != ''\"> and history_allergic = #{historyAllergic}</if>\n" +
            "            <if test=\"familyMedHistory != null  and familyMedHistory != ''\"> and family_med_history = #{familyMedHistory}</if>\n" +
            "            <if test=\"selfMedHistory != null  and selfMedHistory != ''\"> and self_med_history = #{selfMedHistory}</if>\n" +
            "            <if test=\"tags != null  and tags != ''\"> and tags = #{tags}</if>\n" +
            "            <if test=\"hospitalId != null \"> and hospital_id = #{hospitalId}</if>\n" +
            "</script>"})
    List<HospitalPatient> selectHospitalPatientListPVO(HospitalPatient hospitalPatient);
}
