<?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.lymsh.mommybaby.earlydata.dao.PlatMapper">

    <resultMap id="PlatDataTypeResultMap" type="com.lymsh.mommybaby.earlydata.model.PlatDataType">
        <result column="DT_ID" property="dtId" jdbcType="VARCHAR"/>
        <result column="DT_NAME" property="dtName" jdbcType="VARCHAR"/>
    </resultMap>

    <sql id="PlatDataTypeColumns">
         DT_ID,DT_NAME
    </sql>

    <select id="selectPlatDataType" resultMap="PlatDataTypeResultMap" parameterType="com.lymsh.mommybaby.earlydata.model.OracleCommonQuery">
        select
        <include refid="PlatDataTypeColumns"/>
        from (select<include refid="PlatDataTypeColumns"/>,rownum r
        from (
        select
        <include refid="PlatDataTypeColumns"/>
        from PLAT_DATATYPE t
         where DT_OPERTIME >= #{startTime}
        ) h where
        <![CDATA[ rownum <= #{endRow} ]]>
        )
        where
        <![CDATA[ r >= #{startRow} ]]>
    </select>




    <resultMap id="PlatDataContentResultMap" type="com.lymsh.mommybaby.earlydata.model.PlatDataContent">
        <result column="DC_ID" property="dcId" jdbcType="VARCHAR"/>
        <result column="DC_NAME" property="dcName" jdbcType="VARCHAR"/>
        <result column="DC_NO" property="dcNo" jdbcType="VARCHAR"/>
        <result column="DC_PARENTID" property="dcParentid" jdbcType="VARCHAR"/>
        <result column="DC_DATATYPEID" property="dcDatatypeid" jdbcType="VARCHAR"/>
    </resultMap>

    <sql id="PlatDataContentColumns">
         DC_ID,DC_NAME,DC_PARENTID,DC_DATATYPEID,DC_NO
    </sql>

    <select id="selectPlatDataContent" resultMap="PlatDataContentResultMap" parameterType="com.lymsh.mommybaby.earlydata.model.OracleCommonQuery">
        select
        <include refid="PlatDataContentColumns"/>
        from (select<include refid="PlatDataContentColumns"/>,rownum r
        from (
        select
        <include refid="PlatDataContentColumns"/>
        from PLAT_DATACONTENT t
        where DC_OPERTIME >= #{startTime} and DC_DATATYPEID != 'b7ea005c-dfac-4c2a-bdae-25239b3f44fd'
        ) h where
        <![CDATA[ rownum <= #{endRow} ]]>
        )
        where
        <![CDATA[ r >= #{startRow} ]]>
    </select>



    <resultMap id="PlatHospitalResultMap" type="com.lymsh.mommybaby.earlydata.model.PlatHospital">
        <result column="H_ID" property="hId" jdbcType="VARCHAR"/>
        <result column="H_NAME" property="hName" jdbcType="VARCHAR"/>
    </resultMap>

    <sql id="PlatHospitalColumns">
        H_ID,H_NAME
    </sql>

    <select id="selectPlatHospital" resultMap="PlatHospitalResultMap" parameterType="com.lymsh.mommybaby.earlydata.model.OracleCommonQuery">
        select
        <include refid="PlatHospitalColumns"/>
        from (select<include refid="PlatHospitalColumns"/>,rownum r
        from (
        select
        <include refid="PlatHospitalColumns"/>
        from PLAT_HOSPITAL t
        ) h where
        <![CDATA[ rownum <= #{endRow} ]]>
        )
        where
        <![CDATA[ r >= #{startRow} ]]>
    </select>



    <resultMap id="PlatUsersResultMap" type="com.lymsh.mommybaby.earlydata.model.PlatUsers">
        <result column="U_ID" property="uId" jdbcType="VARCHAR"/>
        <result column="U_USERNAME" property="uUsername" jdbcType="VARCHAR"/>
        <result column="U_USERPWD" property="uUserpwd" jdbcType="VARCHAR"/>
        <result column="U_EMPLOYEEID" property="uEmployeeid" jdbcType="VARCHAR"/>
        <result column="U_LOGINNUM" property="uLoginnum" jdbcType="VARCHAR"/>
        <result column="U_ISVALID" property="uIsvalid" jdbcType="INTEGER"/>
    </resultMap>

    <sql id="PlatUsersColumns">
        U_ID,U_USERNAME,U_USERPWD,U_EMPLOYEEID,U_LOGINNUM,U_ISVALID
    </sql>

    <select id="selectPlatUsers" resultMap="PlatUsersResultMap" parameterType="com.lymsh.mommybaby.earlydata.model.OracleCommonQuery">
        select
        <include refid="PlatUsersColumns"/>
        from (select<include refid="PlatUsersColumns"/>,rownum r
        from (
        select
        <include refid="PlatUsersColumns"/>
        from PLAT_USERS t
        where U_OPERTIME >= #{startTime}
        ) h where
        <![CDATA[ rownum <= #{endRow} ]]>
        )
        where
        <![CDATA[ r >= #{startRow} ]]>
    </select>



    <resultMap id="PlatPatientResultMap" type="com.lymsh.mommybaby.earlydata.model.PlatPatient">
        <result column="P_ID" property="pId" jdbcType="VARCHAR"/>
        <result column="P_NAME" property="pName" jdbcType="VARCHAR"/>
        <result column="P_SEX" property="pSex" jdbcType="INTEGER"/>
        <result column="P_ISVALID" property="pIsvalid" jdbcType="INTEGER"/>
        <result column="P_BIRTHDAY" property="pBirthday" jdbcType="TIMESTAMP"/>
        <result column="P_MOBILEPHONE" property="pMobilephone" jdbcType="VARCHAR"/>
    </resultMap>

    <sql id="PlatPatientColumns">
        P_ID,P_NAME,P_SEX,P_BIRTHDAY,P_MOBILEPHONE,P_ISVALID
    </sql>

    <select id="selectPlatPatient" resultMap="PlatPatientResultMap" parameterType="com.lymsh.mommybaby.earlydata.model.OracleCommonQuery">
        select
        <include refid="PlatPatientColumns"/>
        from (select<include refid="PlatPatientColumns"/>,rownum r
        from (
        select
        <include refid="PlatPatientColumns"/>
        from PLAT_PATIENT t
        where P_OPERTIME >= #{startTime}
        ) h where
        <![CDATA[ rownum <= #{endRow} ]]>
        )
        where
        <![CDATA[ r >= #{startRow} ]]>
    </select>

    <select id="selectTable" resultType="hashmap" parameterType="com.lymsh.mommybaby.earlydata.model.OracleCommonQuery">
        select
        *
        from (select h.* ,rownum r
        from (
        select
        t.*
        from ${tableName} t
        where ${timeColumnName} >= #{startTime} <if test="condition != null and condition != ''"> and ${condition} </if>
        ) h where
        <![CDATA[ rownum <= #{endRow} ]]>
        )
        where
        <![CDATA[ r >= #{startRow} ]]>
    </select>

    <select id="selectAllByHospitalId" resultType="hashmap" parameterType="map">
                select
                 pp.P_ID,pp.P_NAME,pp.P_SEX,pp.P_BIRTHDAY,pp.P_MOBILEPHONE,pp.P_ISVALID, mp.P_NO,mp.P_OPERUSER,mp.P_TYPE,mp.P_PLATPATIENTID,mp.P_LASTMENSTRUALPERIOD,mp.P_ISVALID,mp.P_SERVICETYPE,mp.P_ISVIP,mp.P_FILINGOPER,
        vp.DC_NAME as V_DC_NAME,vp.ME_COLORNAME as V_ME_COLORNAME,vp.FENSHU as V_FENSHU,vp.PI_AGEMONTH,first.*,result.*,pd.dc_name,pd.dc_no,me.me_colorname

                 from plat_patient pp left join  mommy_patient mp on pp.p_id = mp.p_platpatientid left join V_GETALLPATIENT vp on pp.p_id = vp.P_PLATPATIENTID
                 left join MOMMY_FIRSTEXAMINE first on  first.fe_triageorderno = mp.P_NO left join MOMMY_EXAMINERESULT result on  result.er_triageorderno = mp.P_NO left join MOMMY_EXAMINWARNING me on (me.me_examinid = first.fe_id or me.me_examinid = result.er_id)
                  left join PLAT_DATACONTENT pd on  me.ME_WORNINGID = pd.DC_Id
        where mp.p_hospitalid = #{hospitalId}
        <if test="startTime != null">
            and (mp.p_opertime >= #{startTime} or first.fe_opertime  >= #{startTime} or result.er_opertime  >= #{startTime} )
        </if>
        order by pp.p_id,first.fe_id,result.er_id
    </select>


    <resultMap id="ViewPatientResultMap" type="com.lymsh.mommybaby.earlydata.model.ViewPatient">
        <result column="DC_NAME" property="dcName" jdbcType="VARCHAR"/>
        <result column="ME_COLORNAME" property="meColorname" jdbcType="VARCHAR"/>
        <result column="PI_AGEMONTH" property="ageMonth" jdbcType="VARCHAR"/>
        <result column="FENSHU" property="fenshu" jdbcType="INTEGER"/>
    </resultMap>


    <select id="selectViewPatient" resultMap="ViewPatientResultMap" parameterType="java.lang.String">
        select DC_NAME,ME_COLORNAME,FENSHU,PI_AGEMONTH FROM V_GETALLPATIENT WHERE P_PLATPATIENTID = #{patientId}
    </select>

    <resultMap id="RiskDetailsResultMap" type="com.lymsh.mommybaby.earlydata.model.ViewPatient">
        <result column="DC_NAME" property="dcName" jdbcType="VARCHAR"/>
        <result column="ME_COLORNAME" property="meColorname" jdbcType="VARCHAR"/>
        <result column="FENSHU" property="fenshu" jdbcType="INTEGER"/>
    </resultMap>

    <select id="selectRiskDetails" resultMap="RiskDetailsResultMap" parameterType="java.lang.String">
        SELECT pd.dc_name as DC_NAME,pd.dc_no as FENSHU,me.me_colorname as ME_COLORNAME FROM MOMMY_EXAMINWARNING  ME
   LEFT JOIN PLAT_DATACONTENT PD
    ON ME.ME_WORNINGID = PD.DC_ID where me.me_examinid = #{examineId}
    </select>

    <select id="selectOtherRiskDetails" resultMap="RiskDetailsResultMap" parameterType="java.lang.String">
        select id as ME_COLORNAME,mo_content as DC_NAME,mo_values as FENSHU from MOMMY_OTHERWORNING where id = #{examineId}
    </select>



</mapper>