<?xml version="1.0" encoding="utf-8" ?>
<!--<sqlMap namespace="CLIP.e-Form.Consent.Dfh" xmlns="http://ibatis.apache.org/mapping" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" >-->
<sqlMap namespace="CLIP.e-Form.Consent.Knuh" xmlns="http://ibatis.apache.org/mapping" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" >
  <statements>
    <statement id="GET_USER_INFO" parameterClass="System.Collections.Hashtable" resultMap="UserMap">
      <![CDATA[
        SELECT USRB.USERID                                                               AS userId,
               USRB.USERNM                                                               AS userName,
               USRD.DUTPLCECD                                                            AS userdeptCode,
               DEPT.DEPTHNGNM                                                            AS userDeptName,
               DEPT.DEPTENGABBR                                                          AS deptEngAbbr,
               USRD.JOBKINDCD                                                            AS jobKindCd,
               (SELECT CDNM
                  FROM COM.ZBCMCODE D
                 WHERE D.CDGRUPID = 'R0061'
                   AND D.CDID     = USRD.JOBKINDCD
                   AND TO_CHAR(SYSDATE, 'YYYYMMDD') BETWEEN D.VALIFROMDD AND D.VALITODD
               )                                                                         AS jobKindNm,
               USRB.DUTINSTCD AS instCd,
               CASE WHEN USRD.JOBKINDCD LIKE '03%' THEN
                         (SELECT PDANO
                            FROM COM.ZSUMUSRB D
                           WHERE D.USERID = USRB.USERID
                             AND D.DUTINSTCD = #instCd#
                             AND TO_CHAR(SYSDATE, 'YYYYMMDD') BETWEEN D.USERFROMDD AND D.USERTODD
                         )
                    ELSE (SELECT MPPHONNO
                            FROM COM.ZSUMUSRB D
                           WHERE D.USERID = USRB.USERID
                             AND D.DUTINSTCD = #instCd#
                             AND TO_CHAR(SYSDATE, 'YYYYMMDD') BETWEEN D.USERFROMDD AND D.USERTODD
                         )
               END                                                                       AS userTelNo,
               DECODE(DEPT.ORDDEPTFLAG, 'W', 'I', 'O')                                   AS ioFlag
          FROM EMA.VW_COM_ZSUMUSRB USRB,
               COM.ZSUMUSRD USRD,
               COM.ZSDDDEPT DEPT
         WHERE USRB.USERID                     =       #userId#
           AND TO_CHAR(SYSDATE, 'YYYYMMDD') BETWEEN USRB.USERFROMDD AND USRB.USERTODD
           AND USRD.USERID                     =       USRB.USERID
      ]]>
      <isNotEmpty property="deptCd">
        <![CDATA[
          AND USRD.DUTPLCECD                  =       #deptCd#
        ]]>
      </isNotEmpty>
      <![CDATA[
           AND USRD.PSNWORKYN                  = 'N'
           AND NVL(USRD.TEMPYN, '-')          != 'C'
           AND TO_CHAR(SYSDATE, 'YYYYMMDD') BETWEEN USRD.FROMDD AND USRD.TODD
           AND USRB.DUTINSTCD                  = #instCd#
           AND DEPT.INSTCD                     = USRD.DUTPLCEINSTCD
           AND DEPT.DEPTCD                     = USRD.DUTPLCECD
           AND TO_CHAR(SYSDATE, 'YYYYMMDD') BETWEEN DEPT.VALIFROMDD AND DEPT.VALITODD
      ]]>
    </statement>
<!--
    <statement id="getUserFormSet" parameterClass="System.Collections.Hashtable" resultMap="ConsentSetMap">
      <![CDATA[        
            SELECT 'PERS_SET' AS SET_AUTH,
                    'bf159c4f-bb03-49ba-bc61-9d635f350c8d' AS FORM_GUID, 
                    '안와골절 정복술 설명 및 동의서' AS FORM_NAME,
                    109 AS FORM_RID,
                    #userid# AS FORM_CD,  
                    1 AS PRNTCNT
            FROM    DUAL
            UNION ALL
            SELECT 'PERS_SET' AS SET_AUTH,
                    '8095dad0-7318-4782-adfb-a2db2f0258e3' AS FORM_GUID, 
                    'Safe Guard 사용 동의서' AS FORM_NAME,
                    110 AS FORM_RID,
                     #userid# || '0000002' AS FORM_CD,
                     1 AS PRNTCNT
            FROM    DUAL   
      ]]>
    </statement>
 -->

    <!--statement id="getUserFormSet" parameterClass="System.Collections.Hashtable" resultMap="ConsentSetMap">
      <![CDATA[ 
        SELECT 'PERS_SET'                                                                           AS set_auth
             , a.linkcd                                                                             AS form_cd
             , b.form_name                                                                          AS form_name
             , '' AS FULL_CATEGORY_NAME
             , b.form_guid
             , b.form_rid
             , b.prntcnt
             , b.print_only
             , b.ocrtagprntyn
             , ( SELECT formprntnm
                   FROM emr.mrfmform c
                  WHERE c.instcd = #instcd#
                    AND c.formcd = b.form_cd
                    AND TO_CHAR(SYSDATE, 'YYYYMMDDHH24MISS') BETWEEN c.formfromdt AND c.formtodt
               )                                                                                    AS formprntnm
             , c.opdiagnm
             , c.opnm
             , CASE WHEN EXISTS ( SELECT 1
                                    FROM emr.mmbdhrcd c
                                   WHERE c.instcd   = a.instcd
                                     AND c.hardcdno = '6920'
                                     AND c.trgtcd   = a.linkcd
                                ) THEN
                         'N'
                    ELSE 'Y'
                END                                                                                 AS userdrflag
             , ( SELECT d.rmk
                   FROM emr.mmbmhrcd d
                      , emr.mmbdhrcd e
                  WHERE d.instcd              = #instcd#
                    AND d.hardcdno            = '6011'
                    AND e.instcd              = d.instcd
                    AND e.hardcdno            = d.hardcdno 
                    AND e.trgtcd             != d.rmk
                    AND e.trgtcd              = b.form_cd
                    AND NVL(e.hardspec, 'Y')  = 'Y'
                    AND TO_CHAR(SYSDATE, 'YYYYMMDD')  BETWEEN e.valifromdd AND e.valitodd
                    AND ROWNUM                = 1
               )                                                                                    AS lnkformcd
          FROM emr.mrfmsetindx a
             , ema.v_eform_formdoc b
             , ( SELECT trgtcd
                      , trgtcdnm  AS opdiagnm
                      , trgtcdsnm AS opnm
                   FROM emr.mmbdhrcd
                  WHERE instcd   = #instcd#
                    AND hardcdno = '6011'
                    AND TO_CHAR(SYSDATE, 'YYYYMMDD') BETWEEN valifromdd AND valitodd
               ) c
         WHERE a.userid    = #userid#
           AND a.instcd    = #instcd#
           AND a.valiyn    = 'Y'
           AND b.form_cd   = a.linkcd
           AND c.trgtcd(+) = b.form_cd
         ORDER BY form_name]]>
    </statement-->

    <statement id="getUserFormSet" parameterClass="System.Collections.Hashtable" resultMap="ConsentFormMap">
      <![CDATA[
        SELECT ''                                                                         AS CONSENT_MST_RID,
               ''                                                                         AS CREATE_USER_ID,
               ''                                                                         AS OCR_TAG,
               ''                                                                         AS PID,
               ''                                                                         AS INDD,
               ''                                                                         AS ORD_TYPE,
               ''                                                                         AS ORD_DEPT_CD,
               ''                                                                         AS CRET_NO,
               ''                                                                         AS OPRSRVNO,
               ''                                                                         AS PATIENT_NAME,
               ''                                                                         AS CONSENT_STATE,
               ''                                                                         AS CONSENT_STATE_ENG,
               VF.FORM_CD                                                                 AS FORM_CD,
               VF.FORM_GUID                                                               AS FORM_GUID,
               VF.FORM_NAME                                                               AS FORM_NAME,
               VF.FORM_RID                                                                AS FORM_RID,
               VF.PRINT_ONLY                                                              AS PRNT_ONLY,
               VF.PRNTCNT                                                                 AS PRINT_CNT,
               VF.OCRTAGPRNTYN                                                            AS OCR_TAG_PRNT_YN,
               MRFM.FORMPRNTNM                                                            AS FORM_PRNT_NM,
               DECODE(MRFM.CERTUSEYN, 'Y', MRFM.CERTUSEYN, 'N')                           AS CERT_USE_YN,
               OP.OPDIAGNM                                                                AS OP_DIAG_NM,
               OP.OPNM                                                                    AS OP_NM,
               CASE 
                 WHEN EXISTS (SELECT 1
                                FROM EMR.MMBDHRCD C
                               WHERE C.INSTCD   = #instCd#
                                 AND C.HARDCDNO = '6920'
                                 AND C.TRGTCD   = VF.FORM_CD
                             ) THEN
                        'N'
                 ELSE 'Y'
               END                                                                        AS USERDRFLAG,
               (SELECT C.RMK
                  FROM EMR.MMBMHRCD C,
                       EMR.MMBDHRCD D
                 WHERE C.INSTCD              = #instCd#
                   AND C.HARDCDNO            = '6011'
                   AND D.INSTCD              = C.INSTCD
                   AND D.HARDCDNO            = C.HARDCDNO 
                   AND D.TRGTCD             != C.RMK
                   AND D.TRGTCD              = VF.FORM_CD
                   AND NVL(D.HARDSPEC, 'Y')  = 'Y'
                   AND TO_CHAR(SYSDATE, 'YYYYMMDD')  BETWEEN D.VALIFROMDD AND D.VALITODD
                   AND ROWNUM                = 1
               )                                                                          AS LNKFORMCD,
               (SELECT DECODE(COUNT(FORM.FORMCD), 0, '-', '1100010977')
                  FROM EMR.MRFMCALCMECH MECH,
                       EMR.MRFMFORM FORM
                 WHERE MECH.INSTCD = #instCd#
                   AND FORM.FORMCD = VF.FORM_CD
                   AND MECH.INSTCD = FORM.INSTCD
                   AND MECH.FORMCD = FORM.FORMCD
                   AND TO_CHAR(SYSDATE, 'YYYYMMDDHH24MISS') BETWEEN FORM.FORMFROMDT AND FORM.FORMTODT
                   AND MECH.BIZFLAG='JINJEONG')                                           AS JINJEONGCD
          FROM EMA.V_EFORM_FORMDOC VF,
               EMR.MRFMSETINDX MRFS,
               EMR.MRFMFORM MRFM,
               (SELECT TRGTCD,
                       TRGTCDNM AS OPDIAGNM,
                       TRGTCDSNM AS OPNM
                  FROM EMR.MMBDHRCD
                 WHERE INSTCD   = #instCd#
                   AND HARDCDNO = '6011'
                   AND TO_CHAR(SYSDATE, 'YYYYMMDD') BETWEEN VALIFROMDD AND VALITODD
               ) OP
         WHERE 1 = 1
           AND OP.TRGTCD(+) = VF.FORM_CD
           AND MRFS.USERID  = #userId#
           AND MRFS.INSTCD  = #instCd#
           AND MRFM.INSTCD  = #instCd#
           AND VF.FORM_CD   = MRFS.LINKCD
           AND MRFS.VALIYN  = 'Y'
           AND MRFM.FORMPROGFLAG LIKE 'OCR%'
           AND VF.FORM_CD   = MRFM.FORMCD
           AND TO_CHAR(SYSDATE, 'YYYYMMDDHH24MISS') BETWEEN MRFM.FORMFROMDT AND MRFM.FORMTODT
         ORDER BY VF.FORM_CD
      ]]>
    </statement>

    <!-- insert id="setUserFormSet" parameterClass="System.Collections.Hashtable">
      <![CDATA[ 
        INSERT INTO emr.mrfmsetindx(
                    instcd,
                    itemindxseq,
                    supitemindxseq,
                    indxflag,
                    indxnm,
                    indxcnts,
                    deptcd,
                    userid,
                    linkflag,
                    linkcd,
                    comnseq,
                    fstrgstrid,
                    fstrgstdt,
                    lastupdtrid,
                    lastupdtdt,
                    jobkind,
                    slipno
                    )
             VALUES(
                    #instCd#,
                    EMR.SQ_MRFMSETINDX_01.NEXTVAL,
                    472,
                    'O',
                    '',
                    '',
                    '',
                    #userId#,
                    'Y',
                    #formCd#,
                    '',
                    #userId#,
                    systimestamp,
                    #userId#,
                    systimestamp,
                    '',
                    '')
        ]]>

      <selectKey type="post" resultClass="System.Int32" property="itemindxseq">
        <![CDATA[SELECT EMR.SQ_MRFMSETINDX_01.CURRVAL AS itemindxseq FROM DUAL]]>
      </selectKey>
    </insert -->

    <insert id="setUserFormSet" parameterClass="System.Collections.Hashtable">
      <![CDATA[ 
        INSERT INTO emr.mrfmsetindx(
                instcd,
                itemindxseq,
                supitemindxseq,
                indxflag,
                indxnm,
                indxcnts,
                deptcd,
                userid,
                linkflag,
                linkcd,
                comnseq,
                fstrgstrid,
                fstrgstdt,
                lastupdtrid,
                lastupdtdt,
                jobkind,
                slipno
                )
        VALUES(
                #instCd#,
                EMR.SQ_MRFMSETINDX_01.NEXTVAL,
                472,
                'O',
                '',
                '',
                '',
                #userId#,
                'Y',
                #formCd#,
                '',
                #userId#,
                systimestamp,
                #userId#,
                systimestamp,
                '',
                '')
        ]]>
      <selectKey type="post" resultClass="System.Int32" property="itemindxseq">
        <![CDATA[SELECT EMR.SQ_MRFMSETINDX_01.CURRVAL AS itemindxseq FROM DUAL]]>
      </selectKey>
    </insert>
    
    <delete id="delUserFormSet" parameterClass="System.Collections.Hashtable">
      <![CDATA[
        UPDATE EMR.MRFMSETINDX
           SET INSTCD = '999'
         WHERE USERID = #userId#
           AND INSTCD = #instCd#
           AND LINKCD = #formCd#
        ]]>
    </delete>

    <statement id="getUserSignImage" parameterClass="System.Collections.Hashtable" resultMap="UserSignImageMap">
      <![CDATA[ 
        SELECT SIGNDATA
          FROM EMR.MRFMSIGNIMGE
         WHERE USERID = #userId#
           AND INSTCD = #instCd#
           AND REPRYN = 'Y'
           AND TO_CHAR(SYSDATE, 'YYYYMMDD') BETWEEN SIGNIMGEFROMDD AND SIGNIMGETODD
        ]]>
    </statement>

    <statement id="CHECK_OCRTAG_DUP" parameterClass="System.Collections.Hashtable">
      <![CDATA[
      SELECT COUNT(OCRTAG)
        FROM EMR.MRFMOCRPRNT
        WHERE INSTCD = #instCd#
            AND OCRTAG = #ocrTag#
      ]]>
    </statement>

    <statement id="getPenOptions" parameterClass="System.Collections.Hashtable">
      <![CDATA[
      SELECT TRGTCD || ',' || TRGTCDNM || ',' || HARDSPEC as RESULT
        FROM EMR.MMBDHRCD
        WHERE INSTCD = #instcd#
            AND HARDCDNO = 6963
            AND TO_CHAR(SYSDATE, 'YYYYMMDD') BETWEEN VALIFROMDD AND VALITODD
      ]]>
    </statement>
    <statement id="getZoomRate" parameterClass="System.Collections.Hashtable">
      <![CDATA[
      SELECT TRGTCD as RESULT
        FROM EMR.MMBDHRCD
        WHERE INSTCD = #instcd#
            AND HARDCDNO = 6964
            AND TO_CHAR(SYSDATE, 'YYYYMMDD') BETWEEN VALIFROMDD AND VALITODD
      ]]>
    </statement>
    <statement id="getPrintOnly" parameterClass="System.Collections.Hashtable">
      <![CDATA[
      SELECT PRINTONLY
          FROM (
              SELECT FORMCD, NVL (PRINT_ONLY, 'N') AS PRINTONLY
                FROM EMR.MRFMFORM A
               WHERE A.INSTCD = #instcd#
                     AND TO_CHAR (SYSDATE, 'YYYYMMDD') BETWEEN FORMFROMDT AND FORMTODT
                     AND FORMPROGFLAG LIKE '%OCR%'
                     AND FORMLEVLCD != '-'
                     AND TO_CHAR (SYSDATE, 'YYYYMMDDHH24MISS') BETWEEN FORMFROMDT AND FORMTODT
          ) B
       WHERE B.FORMCD = #formcd#
      ]]>
    </statement>
    <statement id="getMultiprintable" parameterClass="System.Collections.Hashtable">
      <![CDATA[
        SELECT COUNT(*)
          FROM EMR.MMBDHRCD A
         WHERE  INSTCD = #instcd#
            AND HARDCDNO = 6965
            AND TRGTCD = #formcd#
            AND TO_CHAR (SYSDATE, 'YYYYMMDD') BETWEEN VALIFROMDD AND VALITODD
      ]]>
    </statement>
    <statement id="getPrintControlMsg" parameterClass="System.Collections.Hashtable">
      <![CDATA[
      SELECT TRGTCDNM
        FROM EMR.MMBDHRCD A
        WHERE INSTCD = #instcd#
            AND HARDCDNO = 6966
            AND TRGTCD = #ordtype#
            AND TO_CHAR(SYSDATE, 'YYYYMMDD') BETWEEN VALIFROMDD AND VALITODD
      ]]>
    </statement>
    
    <statement id="GetUnfinishedListPerDoctor" parameterClass="System.Collections.Hashtable" resultMap="UnFinishedListMap">
      <![CDATA[
        SELECT pid                                                             AS patientCode
             , ( SELECT ptbs.hngnm
                   FROM ema.vw_pam_pmcmptbs ptbs
                  WHERE ptbs.instcd = #instcd#
                    AND ptbs.pid    = a.pid
               )                                                               AS hngnm
             , ( SELECT v.form_cd
                   FROM ema.v_eform_formdoc v
                  WHERE v.form_rid = a.form_rid
               )                                                               AS formcd
             , ( SELECT v.form_name
                   FROM ema.v_eform_formdoc v
                  WHERE v.form_rid = a.form_rid
               )                                                               AS consentName
             , ( SELECT v.print_only
                   FROM ema.v_eform_formdoc v
                  WHERE v.form_rid = a.form_rid
               )                                                               AS printonly
             , a.order_date                                                    AS orderdate
             , ( SELECT s.cert_target
                   FROM ema.consent_image_sign s
                  WHERE s.consent_mst_rid = a.consent_mst_rid
               )                                                               AS certtarget
             , a.consent_state                                                 AS consentState
             , a.consent_mst_rid                                               AS consentMstRid
             , a.cln_date                                                      AS orddd
             , a.visit_type                                                    AS visitType
             , a.cln_dept_cd                                                   AS orddeptcd
             , a.order_no                                                      AS orderno
             , a.order_cd                                                      AS ordercd
             , a.ocr_number                                                    AS ocrNumber
             , a.cretno
             , a.create_user_name                                              AS createusername
             , a.form_rid                                                      AS formrid
             , ( SELECT doc.form_guid 
                   FROM ema.v_eform_formdoc doc 
                 where doc.form_rid = a.form_rid
               )                                                               AS formguid
          FROM ema.consent_mst a
         WHERE a.hos_type       = #instcd#
           AND a.modify_user_id = #userid#
           AND a.use_yn         = 'Y'
           AND SUBSTR(a.create_datetime, 1, 10) BETWEEN TO_CHAR(TO_DATE(#fromdd#, 'yyyymmdd'), 'yyyy-mm-dd')
                                                    AND TO_CHAR(TO_DATE(#todd#, 'yyyymmdd'), 'yyyy-mm-dd')]]>
      <isNotEqual property="status" compareValue="ALL">
        <![CDATA[
           AND a.consent_state  IN ($status$)]]>
      </isNotEqual><![CDATA[
           AND CASE WHEN EXISTS ( SELECT 1
                                    FROM emr.mrfmocrprnt d
                                   WHERE d.instcd = #instcd#
                                     AND d.ocrtag = a.ocr_number ) THEN
                         CASE WHEN a.consent_state IN ('TEMP', 'PAPER_OUT')
                               AND EXISTS ( SELECT 1
                                              FROM emr.mrfmocrprnt d
                                                 , emr.mrfhocrprnt e
                                             WHERE d.instcd = #instcd#
                                               AND d.ocrtag = a.ocr_number
                                               AND e.instcd = d.instcd
                                               AND e.ocrtag = d.ocrtag
                                               AND e.updtdt = d.updtdt
                                               AND e.statcd = 'P'
                                          ) THEN 'Y'
                              WHEN a.consent_state = 'CERTIFY_CMP'
                               AND EXISTS ( SELECT 1
                                              FROM emr.mrfmocrprnt d
                                                 , emr.mrfhocrprnt e
                                             WHERE d.instcd = #instcd#
                                               AND d.ocrtag = a.ocr_number
                                               AND e.instcd = d.instcd
                                               AND e.ocrtag = d.ocrtag
                                               AND e.updtdt = d.updtdt
                                               AND e.statcd = 'C'
                                          ) THEN 'Y'
                              ELSE 'N'
                         END
                    ELSE 'Y'
                END = 'Y']]>
    </statement>
    
    <statement  id="doLogin" parameterClass="System.Collections.Hashtable" resultMap="MobileLoginResultMap">
      <![CDATA[ 
      SELECT usrb.usernm              AS usernm
           , upwd.pwd_sha256          AS pwd_sha256
           , usrb.userid              AS userid
        FROM (
              SELECT userb.userid as userid, userb.usernm as usernm
                FROM com.zsumusrb userb, 
                   (SELECT userid, max(userfromdd) as userfromdd 
                      FROM com.zsumusrb
                     WHERE userid = #userid#
                  GROUP BY userid
                   ) max_userb
               WHERE userb.userid = max_userb.userid
                 AND userb.userfromdd = max_userb.userfromdd
             ) usrb,
             com.zsumupwd upwd,
             com.zsumpwlg pwlg
       WHERE upwd.userid(+) = usrb.userid
         AND pwlg.userid(+) = usrb.userid
      ]]>   
    </statement>
    
    <!--<statement  id="getUserdeptList" parameterClass="System.Collections.Hashtable" resultMap="UserLoginDeptListResultMap">
      <![CDATA[ 
      SELECT code.cdid AS dutplceinstcd,
          code.cdnm AS dutplceinstnm,
          dept.deptcd AS dutplcecd,
          dept.depthngnm AS depthngnm,
          code.cdnm || ':'|| dept.depthngnm AS deptnm,
          usrd.fromdd AS fromdd,
          seq.sortno  AS sortno,
          code.cdid || ':' || dept.deptcd AS deptcd,
          usrd.jobkindcd AS jobkindcd,
          (SELECT cdnm FROM com.zbcmcode WHERE cdgrupid = 'R0061' AND cdid = usrd.jobkindcd) AS jobkindnm,
          HOSUSER.HOSPAPPSTATUS as mobile
      FROM com.ZBCMCODE code,
          com.ZSDDDEPT dept,
          EMA.EFORM_HOSPUSERS hosuser,
          com.ZSUMUSRD usrd left outer join com.ZSUMSORT seq on (
                  usrd.userid = seq.userid
              and usrd.dutplceinstcd = seq.dutplceinstcd
              and usrd.dutplcecd = seq.dutplcecd), 
          (SELECT cdrl.subcdsid
              FROM com.ZBCDCDGL cdgl,
                  com.ZBCDCDRL cdrl,
                  com.ZBCMCDGR cdgr,
                  com.ZBCMCODE code
              WHERE cdgr.cdgrupid = 'Z0011'
              AND cdgr.cdgrupid = cdgl.supcdgrupid
              AND TO_CHAR(SYSDATE, 'YYYYMMDD') BETWEEN cdgr.valifromdd AND cdgr.valitodd
              AND TO_CHAR(SYSDATE, 'YYYYMMDD') BETWEEN code.valifromdd ANd code.valitodd
              AND code.cdid = #syscd#
              AND code.cdsid = cdrl.supcdsid   ) a
      WHERE a.subcdsid = code.cdsid
      AND code.cdid = usrd.dutplceinstcd
      AND usrd.userid = #userid#
      AND HOSUSER.HOSPUSER_ID = usrd.userid 
      AND usrd.dutplcecd = dept.deptcd
      AND usrd.dutplceinstcd = dept.instcd
      AND usrd.psnworkyn = 'N'
      AND TO_CHAR(SYSDATE, 'YYYYMMDD') BETWEEN code.valifromdd AND code.valitodd
      AND TO_CHAR(SYSDATE, 'YYYYMMDD') BETWEEN dept.valifromdd AND dept.valitodd
      AND TO_CHAR(SYSDATE, 'YYYYMMDD') BETWEEN usrd.fromdd AND usrd.todd
      ORDER BY sortno ASC
      ]]>
    </statement>-->
    <statement  id="getUserdeptList" parameterClass="System.Collections.Hashtable" resultMap="UserLoginDeptListResultMap">
      <![CDATA[
        SELECT code.cdid AS dutplceInstCd,
               code.cdnm AS dutplceInstNm,
               dept.deptcd AS dutplceCd,
               dept.depthngnm AS deptHngNm,
               code.cdnm || ':'|| dept.depthngnm AS deptNm,
               usrd.fromdd AS fromDd,
               seq.sortno  AS sortNo,
               code.cdid || ':' || dept.deptcd AS deptCd,
               NVL(usrd.jobkindcd, '1140') AS jobKindCd,
               NVL((SELECT cdnm FROM com.zbcmcode WHERE cdgrupid = 'R0061' AND cdid = usrd.jobkindcd), '-') AS jobKindNm,
               NVL((SELECT HOSP.HOSPAPPSTATUS
                      FROM EMA.EFORM_HOSPUSERS hosp
                     WHERE HOSP.HOSPUSER_ID = #userid#
                   ), 'I') as mobile,
               USRD.USERID as userId,
               usrb.USERNM as userName,
               case when jobkindcd like '03%' and jobposcd in ('1799','1800') then 'A'
               when jobkindcd like '03%' then 'B' else 'C' end drKind
          FROM com.ZBCMCODE code,
               com.ZSDDDEPT dept,
               (
                SELECT userb.userid as userid, userb.usernm as usernm
                  FROM com.zsumusrb userb, 
                       (SELECT userid, max(userfromdd) as userfromdd 
                          FROM com.zsumusrb
                         WHERE userid = #userid#
                         GROUP BY userid
                       ) max_userb
                 WHERE userb.userid = max_userb.userid
                   AND userb.userfromdd = max_userb.userfromdd
               ) usrb,
               com.ZSUMUSRD usrd left outer join com.ZSUMSORT seq on (
                    usrd.userid = seq.userid
                and usrd.dutplceinstcd = seq.dutplceinstcd
                and usrd.dutplcecd = seq.dutplcecd), 
               (SELECT cdrl.subcdsid
                  FROM com.ZBCDCDRL cdrl,
                       com.ZBCMCODE code
                 WHERE code.cdgrupid = 'Z0011'
                   AND TO_CHAR(SYSDATE, 'YYYYMMDD') BETWEEN code.valifromdd ANd code.valitodd
                   AND code.cdid = #syscd#
                   AND code.cdsid = cdrl.supcdsid   ) a
              WHERE a.subcdsid = code.cdsid
                AND code.cdid = usrd.dutplceinstcd
                AND usrd.userid = #userid#
                AND USRD.USERID = usrb.USERID 
                AND usrd.dutplcecd = dept.deptcd
                AND usrd.dutplceinstcd = dept.instcd
                AND usrd.psnworkyn = 'N'
                AND TO_CHAR(SYSDATE, 'YYYYMMDD') BETWEEN code.valifromdd AND code.valitodd
                AND TO_CHAR(SYSDATE, 'YYYYMMDD') BETWEEN dept.valifromdd AND dept.valitodd
                AND TO_CHAR(SYSDATE, 'YYYYMMDD') BETWEEN usrd.fromdd AND usrd.todd
              ORDER BY sortno ASC
      ]]>
    </statement>
    
    <statement  id="getMobileUserInfo" parameterClass="System.Collections.Hashtable" resultMap="MobileUserInfoResultMap">
      <![CDATA[ 
      SELECT TRIM(userd.userid) AS userid,
          TRIM(userb.usernm) AS usernm,
          TRIM(userb.userengnm) AS userengnm,
          TRIM(userb.posinstcd) AS posinstcd,
          TRIM(userb.posdeptcd) AS posdeptcd,
          TRIM(userb.orgdeptcd) AS orgdeptcd,
          TRIM(userd.dutplcecd) AS dutplcecd,
          TRIM(userd.fstrgstrid) AS fstrgstrid,
          TRIM(userd.lastupdtrid) AS lastupdtrid,
          userd.jobposcd AS jobposcd,
          userd.jobrespcd AS jobrespcd,
          userd.prfshipflagcd AS prfshipflagcd,
          userd.psnworkyn AS psnworkyn,
          userd.apntflag AS apntflag,
          userd.tempyn AS tempyn,
          userd.fstrgstdt AS fstrgstdt,
          userd.fromdd AS fromdd,
          userd.todd AS todd,
          userd.licnsno AS licnsno,
          userd.specordyn AS specordyn,
          userd.majorfild AS majorfild,
          userd.jobkindcd AS jobkindcd,
          userb.userkindcd AS userkindcd,
          userb.orginstcd AS orginstcd,
          userb.grupjoblncd AS grupjoblncd,
          userb.dutinstcd AS dutinstcd,
          userb.dutunitcd AS dutunitcd,
          userb.mpphonno AS mpphonno,
          userd.dutplceinstcd AS dutplceinstcd,
          userd.medispclno AS medispclno, 
          userd.lastupdtdt AS lastupdtdt,
          (SELECT cdnm FROM com.zbcmcode WHERE cdgrupid = 'Z0007' AND cdid = userb.posinstcd) AS posinstnm,
          (SELECT cdnm FROM com.zbcmcode WHERE cdgrupid = 'Z0016' AND cdid = userb.userkindcd) AS userkindnm,
          (SELECT cdnm FROM com.zbcmcode WHERE cdgrupid = 'Z0007' AND cdid = userb.posinstcd) AS posinstnm,
          (SELECT depthngnm FROM com.zsdddept WHERE instcd = userb.posinstcd AND deptcd = userb.posdeptcd AND TO_CHAR (SYSDATE, 'YYYYMMDD') BETWEEN valifromdd AND valitodd) AS posdeptnm,
          (SELECT cdnm FROM com.zbcmcode WHERE cdgrupid = 'Z0007' AND cdid = userb.orginstcd) AS orginstnm,
          (SELECT depthngnm FROM com.zsdddept WHERE instcd = userb.orginstcd AND deptcd = userb.orgdeptcd AND TO_CHAR(SYSDATE, 'YYYYMMDD') BETWEEN valifromdd AND valitodd) AS orgdeptnm,
          (SELECT cdnm FROM com.zbcmcode WHERE cdgrupid = 'R0059' AND cdid = userb.grupjoblncd) AS grupjoblnnm,
          (SELECT cdnm FROM com.zbcmcode WHERE cdgrupid = 'Z0007' AND cdid = userb.dutinstcd) AS dutinstnm,
          (SELECT depthngnm FROM com.zsdddept WHERE instcd = userb.dutinstcd AND deptcd = userb.dutunitcd AND TO_CHAR(SYSDATE, 'YYYYMMDD') BETWEEN valifromdd AND valitodd) AS dutunitnm,
          (SELECT cdnm FROM com.zbcmcode WHERE cdgrupid = 'Z0007' AND cdid = userd.dutplceinstcd) AS dutplceinstnm,
          (SELECT ordsupdeptcd FROM com.zsdddept WHERE instcd = userd.dutplceinstcd AND deptcd = dutplcecd AND TO_CHAR(SYSDATE, 'YYYYMMDD') BETWEEN valifromdd AND valitodd) AS ordsupdeptcd,
          (SELECT depthngnm FROM com.zsdddept WHERE instcd = userd.dutplceinstcd AND deptcd = userd.dutplcecd AND TO_CHAR(SYSDATE, 'YYYYMMDD') BETWEEN valifromdd AND valitodd) AS dutplcenm,
          (SELECT cdnm FROM com.zbcmcode WHERE cdgrupid = 'R0061' AND cdid = userd.jobkindcd) AS jobkindnm,
          (SELECT cdnm FROM com.zbcmcode WHERE cdgrupid = 'R0062' AND cdid = userd.jobposcd) AS jobposnm,
          (SELECT cdnm FROM com.zbcmcode WHERE cdgrupid = 'R0063' AND cdid = userd.jobrespcd) AS jobrespnm,
          (SELECT cdnm FROM com.zbcmcode WHERE cdgrupid = 'R0058' and cdid = userd.prfshipflagcd) AS prfshipflagnm,
          (SELECT cdnm FROM com.zbcmcode WHERE cdgrupid = 'R0090' and cdid = userd.apntflag) AS apntflagnm,
          (SELECT deptengabbr FROM com.zsdddept WHERE instcd = userd.dutplceinstcd AND deptcd = userd.dutplcecd AND TO_CHAR(SYSDATE, 'YYYYMMDD') BETWEEN valifromdd AND valitodd) AS deptabbr,
          (SELECT deptengnm FROM com.zsdddept WHERE instcd = userd.dutplceinstcd AND deptcd = userd.dutplcecd AND TO_CHAR(SYSDATE, 'YYYYMMDD') BETWEEN valifromdd AND valitodd) AS deptengnm,
          (SELECT orddeptflag FROM com.zsdddept WHERE instcd = userd.dutplceinstcd AND deptcd = userd.dutplcecd AND TO_CHAR(SYSDATE, 'YYYYMMDD') BETWEEN valifromdd AND valitodd) AS orddeptflag,
          userb.email AS email
      FROM  com.zsumusrb userb,
          com.zsumusrd userd
      WHERE userb.userid = userd.userid
          AND userd.userid = #userid#
          AND userd.dutplceinstcd = #dutplceinstcd#
          AND userd.dutplcecd = #dutplcecd#
          AND userd.psnworkyn = 'N'
          AND TO_CHAR(SYSDATE, 'YYYYMMDD') BETWEEN userb.userfromdd AND userb.usertodd
          AND TO_CHAR(SYSDATE, 'YYYYMMDD') BETWEEN userd.fromdd AND userd.todd
      
      ]]>
    </statement>

    <statement id="GetSessionTime" parameterClass="System.Collections.Hashtable" resultClass="System.String">
      <![CDATA[
        SELECT TRGTCDNM AS SESSION_TIME
          FROM EMR.MMBDHRCD
          WHERE INSTCD = '031'
            AND HARDCDNO = '6580'
      ]]>
    </statement>
  </statements>
</sqlMap>
