package com.fs.hospital.mapper;

import java.util.List;
import com.fs.hospital.domain.HospitalInspectOrder;
import com.fs.hospital.param.HospitalInspectOrderParam;
import com.fs.hospital.vo.HospitalInspectOrderVO;
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 HospitalInspectOrderMapper
{
    /**
     * 查询检查单
     *
     * @param orderId 检查单主键
     * @return 检查单
     */
    @Select("select io.*,hu.user_name,h.hospital_name,oo.order_code as outpatientOrderCode,oo.diagnose as clinicalDiagnose " +
            "from hospital_inspect_order io " +
            "left join hospital_user hu on hu.user_id = io.user_id " +
            "left join hospital h on h.hospital_id = io.hospital_id " +
            "left join hospital_outpatient_order oo on oo.order_id= io.outpatient_order_id " +
            "where io.order_id=#{orderId} " +
            "")
    public HospitalInspectOrderVO selectHospitalInspectOrderVOByOrderId(Long orderId);


    /**
     * 查询检查单列表
     *
     * @param param 检查单参数
     * @return 检查单集合
     */
    @Select("<script> " +
            "select io.*,hp.patient_name,hu.user_name  from hospital_inspect_order io " +
            "left join hospital_patient hp on hp.patient_id = io.patient_id " +
            "left join hospital_user hu on hu.user_id = io.user_id " +
            "where 1=1 " +
            "<if test = ' maps.hospitalId!=null and maps.hospitalId!=\"\" '> " +
            "and io.hospital_id = #{maps.hospitalId} " +
            "</if>" +
            "<if test = ' maps.status!=null and  maps.status!= \"\"'> " +
            "and io.status = #{maps.status} " +
            "</if>" +
            "<if test = \"maps.beginTime!=null and maps.beginTime!='' and maps.endTime!=null and maps.endTime!=''\"> " +
            "and io.create_time BETWEEN #{maps.beginTime} and #{maps.endTime} " +
            "</if>" +
            "<if test = \"maps.opTime!=null and maps.opTime!=''\"> " +
            "and io.op_time like concat('%', #{maps.opTime}, '%') " +
            "</if>" +
            "<if test = ' maps.orderCode!=null and maps.orderCode!= \"\" '> " +
            "and io.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 io.order_id desc "+
            "</script>")
    public List<HospitalInspectOrderVO> selectHospitalInspectOrderListVO(@Param("maps") HospitalInspectOrderParam param);

    /**
     * 新增检查单
     *
     * @param hospitalInspectOrder 检查单
     * @return 结果
     */
    public int insertHospitalInspectOrder(HospitalInspectOrder hospitalInspectOrder);

    /**
     * 修改检查单
     *
     * @param hospitalInspectOrder 检查单
     * @return 结果
     */
    public int updateHospitalInspectOrder(HospitalInspectOrder hospitalInspectOrder);


}
