<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.lantone.security.mapper.MedoupDoctorMapper">

    <select id="getDoctorIdByMedoup" resultType="java.lang.Long">
        SELECT DISTINCT
            d.id
        FROM
            sys_doctor d,
            sys_medoup_doctor md
        WHERE
            d.id = md.doctor_id
            AND d.is_deleted = 'N'
            AND md.is_deleted = 'N'
        AND md.medoup_id IN (
            SELECT DISTINCT
                md.medoup_id
            FROM
                sys_user u,
                sys_doctor d,
                sys_medoup_doctor md
            WHERE
                u.is_deleted = 'N'
            AND d.is_deleted = 'N'
            AND md.is_deleted = 'N'
            AND u.`status` = '1'
            AND u.job_no = d.`code`
            AND md.doctor_id = d.id
          AND u.id = #{userId}
        )
    </select>
</mapper>