package com.fs.hospital.mapper;

import java.util.List;
import com.fs.hospital.domain.HospitalExamOrder;
import com.fs.hospital.param.HospitalExamOrderParam;
import com.fs.hospital.vo.HospitalExamOrderVO;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Repository;

/**
 * 检验单Mapper接口
 *
 * @author fs
 * @date 2024-03-26
 */
@Repository
public interface HospitalExamOrderMapper
{
    /**
     * 查询检验单
     *
     * @param orderId 检验单主键
     * @return 检验单
     */
    @Select("select eo.*,hu.user_name,h.hospital_name,oo.order_code as outpatientOrderCode,oo.diagnose as clinicalDiagnose " +
            "from hospital_exam_order eo " +
            "left join hospital_user hu on hu.user_id = eo.user_id " +
            "left join hospital h on h.hospital_id = eo.hospital_id " +
            "left join hospital_outpatient_order oo on oo.order_id= eo.outpatient_order_id " +
            "where eo.order_id=#{orderId} " +
            "")
    public HospitalExamOrderVO selectHospitalExamOrderVOByOrderId(Long orderId);

    /**
     * 查询检验单列表
     *
     * @param Param 检验单参数
     * @return 检验单集合
     */
    @Select("<script> " +
            "select eo.*,hp.patient_name,hu.user_name  from hospital_exam_order eo " +
            "left join hospital_patient hp on hp.patient_id = eo.patient_id " +
            "left join hospital_user hu on hu.user_id = eo.user_id " +
            "where 1=1 " +
            "<if test = ' maps.hospitalId!=null and maps.hospitalId!=\"\" '> " +
            "and eo.hospital_id = #{maps.hospitalId} " +
            "</if>" +
            "<if test = ' maps.status!=null and  maps.status!= \"\"'> " +
            "and eo.status = #{maps.status} " +
            "</if>" +
            "<if test = \"maps.beginTime!=null and maps.beginTime!='' and maps.endTime!=null and maps.endTime!=''\"> " +
            "and eo.create_time BETWEEN #{maps.beginTime} and #{maps.endTime} " +
            "</if>" +
            "<if test = \"maps.opTime!=null and maps.opTime!=''\"> " +
            "and eo.op_time like concat('%', #{maps.opTime}, '%') " +
            "</if>" +
            "<if test = ' maps.orderCode!=null and maps.orderCode!= \"\" '> " +
            "and eo.order_code like concat('%', #{maps.orderCode}, '%') " +
            "</if>" +
            "<if test = ' maps.patientName!=null and maps.patientName != \"\"  '> " +
            "and hp.patient_name like concat('%', #{maps.patientName}, '%') " +
            "</if>" +
            " order by eo.order_id desc "+
            "</script>")
    public List<HospitalExamOrderVO> selectHospitalExamOrderListVO(@Param("maps") HospitalExamOrderParam Param);

    /**
     * 新增检验单
     *
     * @param hospitalExamOrder 检验单
     * @return 结果
     */
    public int insertHospitalExamOrder(HospitalExamOrder hospitalExamOrder);

    /**
     * 修改检验单
     *
     * @param hospitalExamOrder 检验单
     * @return 结果
     */
    public int updateHospitalExamOrder(HospitalExamOrder hospitalExamOrder);

}
