package com.fs.his.mapper;

import com.fs.course.param.FsInquiryPatientInfoUParam;
import com.fs.course.vo.FsInquiryPatientInfoListUVO;
import com.fs.his.domain.FsInquiryPatientInfo;
import com.fs.his.vo.FsInquiryPatientVO;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

public interface FsInquiryPatientInfoMapper {

    int insertFsInquiryPatientInfo(FsInquiryPatientInfo fsInquiryPatientInfo);

    int updateFsInquiryPatientInfo(FsInquiryPatientInfo fsInquiryPatientInfo);

    FsInquiryPatientInfo selectFsInquiryPatientInfoInquiryOrderId(Long inquiryOrderId);

    FsInquiryPatientVO selectUserAndCompanyUserByInquiryOrderId(Long inquiryOrderId);

    @Select({"<script>" +
            "SELECT pi.*,p.patient_name,p.birthday,p.sex, u.nick_name companyUserName,d.doctor_name FROM fs_inquiry_patient_info pi " +
            "LEFT JOIN fs_patient p ON p.patient_id  = pi.patient_id " +
            "LEFT JOIN company_user u ON u.user_id = pi.company_user_id " +
            " left join fs_doctor d on d.doctor_id = pi.sub_doctor_id  " +
            " where 1 = 1 " +
            "<if test='param.userId != null'> AND pi.user_id = #{param.userId} </if> " +
            "ORDER BY pi.create_time desc " +
            "</script>"})
    List<FsInquiryPatientInfoListUVO> selectFsInquiryPatientInfoListUVO(@Param("param") FsInquiryPatientInfoUParam param);

    @Select({"<script>" +
            "SELECT pi.*,p.patient_name,p.birthday,p.sex, u.nick_name companyUserName,d.doctor_name FROM fs_inquiry_patient_info pi " +
            "LEFT JOIN fs_patient p ON p.patient_id  = pi.patient_id " +
            "LEFT JOIN company_user u ON u.user_id = pi.company_user_id " +
            " left join fs_doctor d on d.doctor_id = pi.sub_doctor_id  " +
            "WHERE pi.id = #{id} " +
            "</script>"})
    FsInquiryPatientInfoListUVO getInfo(Long id);
}
