package thyyxxk.webserver.dao.his.heliyongyao;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Constants;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import thyyxxk.webserver.entity.heliyongyao.RationalUsePatient;
import thyyxxk.webserver.entity.heliyongyao.XunHuanJieDian;
import thyyxxk.webserver.entity.heliyongyao.YaoPin;

import java.util.List;
import java.util.Map;

/**
 * <p>
 * 描述： 合理用药
 * </p>
 *
 * @author xc
 * @date 2022-03-29 11:27
 */
@Mapper
public interface RationalUseDao {

    @Select("select          dept_code  , " +
            "    dept_name = (select rtrim(name) from zd_unit_code where zd_unit_code.code = dept_code), " +
            "                code, " +
            "                rtrim(name)     name, " +
            "                emp_tit_code as type, " +
            "    type_name = (select rtrim(name) from zd_emp_title where zd_emp_title.code = emp_tit_code) " +
            "from a_employee_mi " +
            "where code = #{code}  ")
    Map<String, String> yiShenXinXi(String code);


    @Select("select pati_id = rtrim(a.inpatient_no) + '_' + cast(admiss_times as varchar), " +
            "                 rtrim(a.name) name, " +
            "       birth=(convert(varchar(10), birth_date, 21)), " +
            "                 a.sex, " +
            "                 social_no as  id_card " +
            "from zy_actpatient a, " +
            "     a_patient_mi b " +
            "where a.inpatient_no = b.inpatient_no " +
            "  and a.inpatient_no = #{patNo} " +
            "  and a.admiss_times = #{times}")
    RationalUsePatient huanZheXinXi(@Param("patNo") String patNo,
                                    @Param("times") Integer times);

    @Select("select allergen_code code, b.name as name, case b.class when 'A' then '1' when 'B' then '2' end as type " +
            "from patient_allergen_info a, " +
            "     zd_allergen b " +
            "where a.allergen_code = b.code " +
            "  and pat_no = '0363308' " +
            "  and a.type = 0 " +
            "union all " +
            "select allergen_code, (select name from yp_zd_dict where yp_zd_dict.code = allergen_code) as allergenName, type = 5 " +
            "from patient_allergen_info " +
            "where pat_no = '0363308' " +
            "  and type = 1")
    List<XunHuanJieDian> guoMin(@Param("patNo") String patNo);

    /**
     * 获取患者诊断
     *
     * @param patNo 住院号
     * @param times 住院次数
     * @return 诊断
     */
    @Select("select type = '0', " +
            "              rtrim(dis_diag_comment) as name, " +
            "              rtrim(dis_diag)         as code " +
            "from ba_first_page1 " +
            "where inpatient_no = #{patNo} " +
            "  and admiss_times = #{times}")
    List<XunHuanJieDian> zhenDuan(@Param("patNo") String patNo,
                                  @Param("times") Integer times);

    @Select("select national_code, rtrim(pzwh) pzwh, isnull(pack_retprice,1) pack_retprice,rtrim(code) + rtrim(serial) as id " +
            "from yp_zd_dict " +
            "${ew.customSqlSegment}")
    List<YaoPin> yaoPingXinXi(@Param(Constants.WRAPPER) QueryWrapper<?> queryWrapper);

}
