<?xml version="1.0" encoding="utf-8" ?>
<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="getInPatList" parameterClass="System.Collections.Hashtable" resultMap="PatListMap">
      <isEqual property="patientState" compareValue="C">
        <![CDATA[
          with tmp as
          (SELECT   /*+ leading(h m c) materialize */ m.instcd,m.pid ,m.cretno,m.orddd
           FROM ema.consent_mst c,
                emr.mrfmocrprnt m,
                emr.mrfhocrprnt h
              WHERE c.use_yn = 'Y'
                AND c.consent_state IN ('UNFINISHED', 'TEMP', 'ELECTR_CMP')
                AND m.instcd = c.hos_type
                AND m.ocrtag = c.ocr_number
                and m.instcd = h.instcd
                and m.ocrtag = h.ocrtag
                and m.updtdt = h.updtdt
                and h.statcd = 'P'
                and h.updtdt like #srchDd#||'%'
                and h.instcd = #instCd# )
        ]]>
      </isEqual>
      <![CDATA[
        SELECT ptbs.pid                                                                        AS pid,
               inpt.indd                                                                       AS inDd,
               inpt.cretno                                                                     AS cretNo,
               inpt.instcd                                                                     AS instCd,
               inpt.ordtype                                                                    AS ordType,
               ptbs.hngnm                                                                      AS hngNm,
               inpt.orddeptcd                                                                  AS ordDeptCd,
               inpt.medispclid                                                                 AS doctorId,
               ptbs.sex ||'/'||com.Fn_zz_getage('','',TO_CHAR(SYSDATE, 'yyyymmdd'),'B',brthdd) AS sa,
               com.fn_zs_getdeptnm(inpt.instcd,inpt.orddeptcd,inpt.dschdd)                     AS deptNm,
               com.fn_zs_getusernm(inpt.medispclid,inpt.dschdd)                                AS doctorNm,
               inpt.roomCd                                                                     AS roomCd,
               ''                                                                              AS opRoomNm,
               ''                                                                              AS oprsRvNo
          FROM pam.pmihinpt inpt,
               pam.pmcmptbs ptbs
      ]]>
      <isEqual property="srchYN" compareValue="N">
        <isEqual property="myPatient" compareValue="Y">
          <![CDATA[
            , emr.mnwhsetp setp
          ]]>
        </isEqual>
      </isEqual>
      <![CDATA[
          WHERE  inpt.instcd = #instCd#
      ]]>
      <isNotEmpty property="pid">
        <![CDATA[
          AND inpt.pid = #pid#
        ]]>
      </isNotEmpty>
      <isEqual property="patientState" compareValue="A">
        <!-- 재원 -->
        <![CDATA[
          and inpt.indschacptstat = 'A'
        ]]>
      </isEqual>
      <isEqual property="patientState" compareValue="0">
        <!-- 입원 -->
        <![CDATA[
          AND inpt.careinrmdd = #srchDd#
        ]]>
      </isEqual>
      <isEqual property="patientState" compareValue="1">
        <!-- 퇴원 -->
        <![CDATA[
          AND inpt.indschacptstat in ('T','D')
          AND inpt.dschdd = #srchDd#
        ]]>
      </isEqual>
      <isEqual property="patientState" compareValue="C">
        <![CDATA[
          AND EXISTS (SELECT 1
                        FROM  tmp a
                       where a.instcd = inpt.instcd
                         and   a.pid    = inpt.pid
                         and   a.orddd  = inpt.indd
                         and   a.cretno = inpt.cretno )
        ]]>
        <!--![CDATA[
          AND EXISTS  ( SELECT 1
                          FROM ema.consent_mst c
                               , emr.mrfmocrprnt m
                               , emr.mrfhocrprnt h
                         WHERE m.instcd        =  inpt.instcd
                           AND m.pid           =  inpt.pid
                           AND m.cretno        =  inpt.cretno
                           AND m.orddd         = inpt.indd
                           AND c.use_yn        =  'Y'
                           AND c.consent_state IN ('UNFINISHED', 'TEMP')
                           AND m.instcd        =  c.hos_type
                           AND m.ocrtag        =  c.ocr_number
                           AND h.instcd        =  m.instcd
                           AND h.ocrtag        =  m.ocrtag
                           AND h.updtdt        =  m.updtdt
                           AND h.statcd        =  'P'
                           AND instr(H.UPDTDT, #srchDd#) > 0 
                      )
        ]] -->
        <!-- AND instr(H.UPDTDT, #srchDd#) > 0 -->
      </isEqual>
      <isNotEmpty property="patientState">
        <isNotEmpty property="wardCd">
          <![CDATA[
            AND inpt.wardcd = #wardCd#
          ]]>
        </isNotEmpty>
        <isEqual property="myPatient" compareValue="N">
          <isNotEmpty property="doctorId">
            <!-- 전공의(A), 담당교수(B), 그외 직종(C) 구분코드-->
            <![CDATA[
            AND CASE
                  WHEN #drKind# = 'A'
                    THEN inpt.atdoctid
                  ELSE inpt.medispclid
                END = #doctorId#
          ]]>
          </isNotEmpty>
        </isEqual>

        <isNotEmpty property="ordDeptCd">
          <![CDATA[
            AND inpt.orddeptcd = #ordDeptCd#
          ]]>
        </isNotEmpty>
      </isNotEmpty>
      <!-- isEmpty property="patientState">
        <![CDATA[
          AND EXISTS ( SELECT 1 
                         FROM pam.pmihicdr icdr
                        WHERE icdr.instcd = inpt.instcd
                          AND icdr.pid = inpt.pid
                          AND icdr.indd = inpt.indd
                          AND icdr.cretno = inpt.cretno
                          AND icdr.histstat = 'Y'
                          AND #srchDd# between icdr.fromdd and icdr.todd
        ]]>
        <isNotEmpty property="wardCd">
          <![CDATA[
                          AND icdr.wardCd = #wardCd#
          ]]>
        </isNotEmpty>
        <isNotEmpty property="doctorId">
          <![CDATA[
                         AND CASE WHEN #drKind# = 'A' THEN icdr.atdoctid ELSE icdr.medispclid END = #doctorId#
          ]]>
        </isNotEmpty>
        <isNotEmpty property="ordDeptCd">
          <![CDATA[
                         AND icdr.orddeptCd = #ordDeptCd#
          ]]>
        </isNotEmpty>
        <![CDATA[
                     )
        ]]>

      </isEmpty -->
      <isEqual property="srchYN" compareValue="N">
        <isEqual property="myPatient" compareValue="Y">
          <![CDATA[
            AND setp.nursid = #userId#
            AND setp.pid = inpt.pid
            AND setp.fromdt < '99999999999999'
            AND setp.todt > SYSTIMESTAMP   
            AND setp.instcd =  #instCd#]]>
        </isEqual>
      </isEqual>

      <![CDATA[
         AND inpt.mskind = 'M'
         AND inpt.histstat = 'Y'
         AND inpt.ordtype in ('I','D')
         AND ptbs.instcd = inpt.instcd
         AND ptbs.pid = inpt.pid
       ORDER BY inpt.roomcd,
                ptbs.hngnm,
                inpt.indd
      ]]>
    </statement>

    <statement id="getOutPatList"  parameterClass="System.Collections.Hashtable" resultMap="PatListMap">
      <isEqual property="patientState" compareValue="3">
        <![CDATA[
          with tmp as
          (SELECT   /*+ leading(h m c) materialize */ m.instcd,m.pid ,m.cretno,m.orddd
           FROM ema.consent_mst c,
                emr.mrfmocrprnt m,
                emr.mrfhocrprnt h
              WHERE c.use_yn = 'Y'
                AND c.consent_state IN ('UNFINISHED', 'TEMP', 'ELECTR_CMP')
                AND m.instcd = c.hos_type
                AND m.ocrtag = c.ocr_number
                and m.instcd = h.instcd
                and m.ocrtag = h.ocrtag
                and m.updtdt = h.updtdt
                and h.statcd = 'P'
                and h.updtdt like #srchDd#||'%'
                and h.instcd = #instCd# )
        ]]>
      </isEqual>
      <![CDATA[
        SELECT ptbs.pid                                                   AS pid,
               otpt.orddd                                                 AS inDd,
               otpt.cretno                                                AS cretNo,
               otpt.instcd                                                AS instCd,
               otpt.ordtype                                               AS ordType,
               ptbs.hngnm                                                 AS hngNm,
               otpt.orddeptcd                                             AS ordDeptCd,
               otpt.orddrid                                               AS doctorId,
               ptbs.sex ||'/'||com.Fn_zz_getage('','',orddd,'B',brthdd)   AS sa,
               com.fn_zs_getdeptnm(otpt.instcd,otpt.orddeptcd,otpt.orddd) AS deptnm,
               com.fn_zs_getusernm(otpt.orddrid,otpt.orddd)               AS doctorNm,
               ''                                                         AS roomCd,
               ''                                                         AS opRoomNm,
               ''                                                         AS oprsRvNo
          FROM pam.pmohotpt otpt,
               pam.pmcmptbs ptbs
         WHERE otpt.instcd = #instCd#
           AND otpt.mskind = 'M'
           AND otpt.histstat IN ('R', 'T')
           AND otpt.ordtype IN ('O','S')
           AND ptbs.instcd = otpt.instcd
           AND ptbs.pid = otpt.pid
      ]]>

      <isEqual property="srchYN" compareValue="N">
        <![CDATA[
          AND otpt.orddd = #srchDd#
        ]]>
      </isEqual>

      <isNotEmpty property="ordDeptCd">
        <![CDATA[
          AND otpt.orddeptcd = #ordDeptCd#
        ]]>
      </isNotEmpty>
      <isNotEmpty property="doctorId">
        <![CDATA[
          AND otpt.orddrid= #doctorId#
        ]]>
      </isNotEmpty>
      <isNotEqual property="patientState" compareValue="3">
        <isNotEmpty property="patientState">
          <isEqual property="srchYN" compareValue="N">
            <isNotEqual property="patientState" compareValue="A">
              <![CDATA[
                AND otpt.elbulbodstat = #patientState#
              ]]>
            </isNotEqual>
          </isEqual>
        </isNotEmpty>
      </isNotEqual>
      <isEqual property="patientState" compareValue="3">
        <![CDATA[
          AND EXISTS (SELECT 1
                        FROM  tmp a
                       where a.instcd = otpt.instcd
                         and   a.pid    = otpt.pid
                         and   a.orddd  = otpt.orddd
                         and   a.cretno = otpt.cretno )
        ]]>
        <!-- ![CDATA[
        AND EXISTS ( SELECT 1
                       FROM ema.consent_mst c
                            , emr.mrfmocrprnt m
                            , emr.mrfhocrprnt h
                      WHERE c.hos_type      =  otpt.instcd
                        AND c.pid           =  otpt.pid
                        AND c.cretno        =  otpt.cretno
                        AND c.visit_type    =  otpt.ordtype
                        AND c.use_yn        =  'Y'
                        AND c.consent_state IN ('UNFINISHED', 'TEMP')
                        AND m.instcd        =  c.hos_type
                        AND m.ocrtag        =  c.ocr_number
                        AND h.instcd        =  m.instcd
                        AND h.ocrtag        =  m.ocrtag
                        AND h.updtdt        =  m.updtdt
                        AND h.statcd        =  'P'
                        AND instr(H.UPDTDT, #srchDd#) > 0 
                   )
      ]] -->
      </isEqual>
      <isNotEmpty property="pid">
        <![CDATA[
          AND otpt.pid = #pid#
        ]]>
      </isNotEmpty>
      <![CDATA[
        ORDER BY ptbs.hngnm, otpt.orddd DESC
      ]]>
    </statement>

    <statement id="getOpPatList" parameterClass="System.Collections.Hashtable" resultMap="PatListMap">
      <![CDATA[
        SELECT oprs.pid                                                       AS pid,
               to_char(to_date(inpt.indd,'yyyymmdd'),'yyyymmdd')              AS inDd,
               inpt.cretno                                                    AS cretNo,
               inpt.instcd                                                    AS instcd,
               inpt.ordtype                                                   AS ordType,
               ptbs.hngnm                                                     AS hngNm,
               oprs.perfdeptcd                                                AS ordDeptCd,
               oprs.perfdrid                                                  AS doctorId,
               ptbs.sex ||'/'||com.Fn_zz_getage('','',dschdd,'B',brthdd)      AS sa,
               com.fn_zs_getdeptnm(oprs.instcd,oprs.perfdeptcd,oprs.opcnfmdd) AS deptNm,
               com.fn_zs_getusernm(oprs.perfdrid,oprs.opcnfmdd)               AS doctorNm,
               inpt.roomcd                                                    AS roomCd,
               oproomcd                                                       AS opRoomNm,
               oprs.oprsrvno                                                  AS oprsRvNo
          FROM emr.mmohoprs oprs
               ,pam.pmcmptbs ptbs
               ,pam.pmihinpt inpt
         WHERE oprs.ophistcd = 'O'
           AND inpt.histstat = 'Y'
           AND inpt.mskind = 'M'
           AND ptbs.instcd = oprs.instcd
           AND ptbs.pid = oprs.pid
           AND inpt.instcd = oprs.instcd
           AND inpt.pid = oprs.pid
           AND oprs.opcnfmdd BETWEEN inpt.indd AND inpt.dschdd
           AND oprs.instcd = #instCd#
           AND oprs.opcnfmdd = #srchDd#

      ]]>
      <isNotEmpty property="ordDeptCd">
        <!-- 과 선택시 -->
        <![CDATA[
          AND oprs.perfdeptcd = #ordDeptCd#
        ]]>
      </isNotEmpty>
      <isNotEmpty property="doctorId">
        <!-- 의사 선택시 -->
        <![CDATA[
          AND oprs.perfdrid = #doctorId#
        ]]>
      </isNotEmpty>
      <isNotEmpty property="pid">
        <!-- 환자 등록번호 -->
        <![CDATA[
          AND oprs.pid = #pid#
        ]]>
      </isNotEmpty>
      <isEqual property="patientState" compareValue="0">
        <!-- 미착 -->
        <![CDATA[
          AND oprs.opstatcd   IN      ('10', '20')
        ]]>
      </isEqual>
      <isEqual property="patientState" compareValue="1">
        <!-- 준비 -->
        <![CDATA[
          AND oprs.opstatcd =       '30'
        ]]>
      </isEqual>
      <isEqual property="patientState" compareValue="2">
        <!-- 진행 -->
        <![CDATA[
          AND oprs.opstatcd = '40'
        ]]>
      </isEqual>
      <isEqual property="patientState" compareValue="3">
        <!-- 완료 -->
        <![CDATA[
          AND oprs.opstatcd IN ('50', '60', '70')
        ]]>
      </isEqual>
    </statement>

    <statement id="getErPatList" parameterClass="System.Collections.Hashtable" resultMap="PatListMap">
      <isEqual property="patientState" compareValue="C">
        <![CDATA[
          with tmp as
          (SELECT   /*+ leading(h m c) materialize */ m.instcd,m.pid ,m.cretno,m.orddd
           FROM ema.consent_mst c,
                emr.mrfmocrprnt m,
                emr.mrfhocrprnt h
              WHERE c.use_yn = 'Y'
                AND c.consent_state IN ('UNFINISHED', 'TEMP', 'ELECTR_CMP')
                AND m.instcd = c.hos_type
                AND m.ocrtag = c.ocr_number
                and m.instcd = h.instcd
                and m.ocrtag = h.ocrtag
                and m.updtdt = h.updtdt
                and h.statcd = 'P'
                and h.updtdt like #srchDd#||'%'
                and h.instcd = #instCd# )
        ]]>
      </isEqual>
      <![CDATA[
        SELECT ptbs.pid                                                                        AS pid,
               inpt.indd                                                                       AS indd,
               inpt.cretno                                                                     AS cretNo,
               inpt.instCd                                                                     AS instCD,
               inpt.ordtype                                                                    AS ordType,
               ptbs.hngnm                                                                      AS hngNm,
               inpt.orddeptcd                                                                  AS ordDeptCd,
               inpt.medispclid                                                                 AS doctorId,
               ptbs.sex ||'/'||com.Fn_zz_getage('','',TO_CHAR(SYSDATE, 'yyyymmdd'),'B',brthdd) AS sa,
               com.fn_zs_getdeptnm(inpt.instcd,inpt.orddeptcd,inpt.dschdd)                     AS deptNm,
               com.fn_zs_getusernm(inpt.medispclid,inpt.dschdd)                                AS doctorNm,
               inpt.roomcd                                                                     AS roomCd,
               ''                                                                              AS opRoomNm,
               ''                                                                              AS oprsRvNo
          FROM pam.pmihinpt inpt,
               pam.pmcmptbs ptbs
         WHERE inpt.instcd = #instCd#
           AND inpt.mskind = 'M'
           AND inpt.histstat = 'Y'
           AND inpt.ordtype = 'E'
           AND ptbs.instcd = inpt.instcd
           AND ptbs.pid = inpt.pid
      ]]>
      <isEqual property="patientState" compareValue="A">
        <!-- 재원 -->
        <![CDATA[
          AND inpt.indschacptstat = 'A'
          AND inpt.eroutdt = '-'
        ]]>
      </isEqual>
      <isEqual property="patientState" compareValue="0">
        <!-- 퇴원 -->
        <![CDATA[
          AND inpt.indschacptstat in ('T','D')
          AND inpt.dschdd = #srchDd#
        ]]>
      </isEqual>
      <isEqual property="patientState" compareValue="1">
        <!-- 퇴실정리 -->
        <![CDATA[
          AND inpt.indschacptstat = 'A'
          AND inpt.eroutdt       !=       '-' 
          AND inpt.eroutdt       !=       '99991231235959'
          AND inpt.dschdd         =       '99991231'
        ]]>
      </isEqual>
      <isEqual property="patientState" compareValue="C">
        <![CDATA[
          AND EXISTS (SELECT 1
                        FROM  tmp a
                       where a.instcd = inpt.instcd
                         and   a.pid    = inpt.pid
                         and   a.orddd  = inpt.indd
                         and   a.cretno = inpt.cretno )
        ]]>
        <!-- ![CDATA[
          AND EXISTS ( SELECT 1
                         FROM ema.consent_mst c
                              , emr.mrfmocrprnt m
                              , emr.mrfhocrprnt h
                        WHERE m.instcd        =  inpt.instcd
                          AND m.pid           =  inpt.pid
                          AND m.cretno        =  inpt.cretno
                          AND m.orddd         = inpt.indd
                          AND c.use_yn        =  'Y'
                          AND c.consent_state IN ('UNFINISHED', 'TEMP')
                          AND m.instcd        =  c.hos_type
                          AND m.ocrtag        =  c.ocr_number
                          AND h.instcd        =  m.instcd
                          AND h.ocrtag        =  m.ocrtag
                          AND h.updtdt        =  m.updtdt
                          AND h.statcd        =  'P'
                          AND instr(H.UPDTDT, #srchDd#) > 0 
                     )
        ]] -->
      </isEqual>

      <isNotEmpty property="pid">
        <![CDATA[
          AND inpt.pid = #pid#
        ]]>
      </isNotEmpty>

      <!-- 상태가 전체가 아니면 -->
      <isNotEmpty property="patientState">
        <isNotEmpty property="ordDeptCd">
          <![CDATA[
            AND inpt.orddeptcd = #ordDeptCd#
          ]]>
        </isNotEmpty>
        <isNotEmpty property="doctorId">
          <![CDATA[
            AND CASE WHEN #drKind# = 'A' THEN inpt.atdoctid ELSE inpt.medispclid END = #doctorId#
          ]]>
        </isNotEmpty>
      </isNotEmpty>

      <!-- 상태가 전체이면 -->
      <!-- isEmpty property="patientState">
        <![CDATA[
          AND EXISTS ( SELECT 1
                         FROM pam.pmihicdr icdr
                        WHERE icdr.instcd = inpt.instcd
                          AND icdr.pid = inpt.pid
                          AND icdr.indd = inpt.indd
                          AND icdr.cretno = inpt.cretno
                          AND icdr.histstat = 'Y'
                          AND #srchDd# BETWEEN icdr.fromdd
                          AND icdr.todd
                          

        ]]>
        <isNotEmpty property="ordDeptCd">
          <![CDATA[
            AND icdr.orddeptcd = #ordDeptCd#
          ]]>
        </isNotEmpty>
        <isNotEmpty property="doctorId">
          <![CDATA[
            AND CASE 
                  WHEN #drKind# = 'A'
                    THEN icdr.atdoctid
                    ELSE icdr.medispclid
                  END = #doctorId#
          ]]>
        </isNotEmpty>

        <![CDATA[
                     )
        ]]>
      </isEmpty -->

      <![CDATA[
        ORDER BY ptbs.hngnm,inpt.indd,inpt.intm
      ]]>
    </statement>

    <statement id="getSrchPatInfo" parameterClass="System.Collections.Hashtable" resultMap="PatInfoListMap">
      <![CDATA[
        SELECT a.pid
             , a.hngnm  AS hngnm
             , a.rrgstno1
             , substr(a.rrgstno2,1,1) || '******' as rrgstno2
             , COM.FN_ZZ_GETAGE(a.rrgstno1, a.rrgstno2, TO_CHAR(SYSDATE, 'YYYYMMDD'), 'A', a.brthdd)    AS age
             , a.mpphontel
             , a.zipcdaddr as addr
             , a.detladdr
             , ( SELECT /*+ INDEX_DESC(b pk_pmohotpt) */
                        orddd
                   FROM pam.pmohotpt b
                  WHERE b.instcd = #instcd#
                    AND b.pid    = a.pid
                    AND histstat = 'R'
                    AND dracptyn = 'Y'
                    AND ROWNUM   = 1
               )                                                                                        AS lastorddd
             , ( SELECT /*+ INDEX_DESC(mohotpt pk_pmohotpt) */ 
                        ( SELECT dept.depthngnm
                            FROM com.zsdddept dept
                           WHERE dept.instcd   = mohotpt.instcd
                             AND dept.deptcd   = mohotpt.orddeptcd
                             AND dept.valitodd = '99991231'
                        )
                   FROM pam.pmohotpt mohotpt
                  WHERE mohotpt.instcd   = #instcd#
                    AND mohotpt.pid      = a.pid
                    AND mohotpt.histstat = 'R'
                    AND mohotpt.dracptyn = 'Y'
                    AND ROWNUM           = 1
               )                                                                                        AS lastorddept
             , ( SELECT /*+ INDEX_DESC(i pk_pmohotpt) */
                        ( SELECT cdnm
                            FROM com.zbcmcode
                           WHERE cdgrupid    = 'P0008'
                             AND cdid        = i.insukind
                             AND valifromdd <= TO_CHAR(SYSDATE, 'YYYYMMDD')
                             AND valitodd   >= TO_CHAR(SYSDATE, 'YYYYMMDD')
                             AND ROWNUM      = 1
                        )
                   FROM pam.pmohotpt i
                  WHERE i.instcd   = #instcd#
                    AND i.pid      = a.pid
                    AND i.histstat = 'R'
                    AND i.dracptyn = 'Y'
                    AND ROWNUM     = 1
               )                                                                                        AS lastinsukind
          FROM ( SELECT *
                   FROM ema.vw_pam_pmcmptbs ptbs]]>
      <isEqual property="srchcond" compareValue="1">
        <![CDATA[
                  WHERE ptbs.instcd = #instcd#
                    AND ptbs.pid LIKE #pid# || '%' ]]>
      </isEqual>
      <isEqual property="srchcond" compareValue="2">
        <![CDATA[
                  WHERE ptbs.instcd = #instcd#
                    AND ptbs.hngnm LIKE REPLACE(#hngnm#, '★', '')  || '%' ]]>
      </isEqual>
      <isEqual property="srchcond" compareValue="3">
        <![CDATA[
                  WHERE ptbs.instcd = #instcd#
                    AND ( ptbs.rrgstno1 LIKE #rrgstno1# || '%' AND ptbs.rrgstno2 LIKE #rrgstno2# || '%' )]]>
      </isEqual>
      <![CDATA[
                    AND ROWNUM < 2000
               ) a
         ORDER BY hngnm, rrgstno1, rrgstno2]]>
    </statement>

    <statement id="getDeptList" parameterClass="System.Collections.Hashtable" resultMap="DeptListMap">
      <![CDATA[
        SELECT ' '                    AS deptCd,
               '진료과(전체)'          AS deptNm,
               0                      AS sort
          FROM dual
         UNION ALL
        SELECT deptcd                 AS deptCd,
               depthngnm              AS deptNm,
               1                      AS sort
          FROM com.zsdddept
         WHERE instcd      = #instCd#
           AND TO_CHAR(CURRENT_DATE,'YYYYMMDD') BETWEEN valifromdd AND valitodd
      ]]>
      <isEqual property="ordType" compareValue="OP">
        <![CDATA[
           AND orddeptflag = 'D'
           AND orduseyn    = 'Y'
         ORDER BY sort, deptnm]]>
      </isEqual>
      <isNotEqual property="ordType" compareValue="OP">
        <![CDATA[
           AND rcptuseyn = 'Y'
         ORDER BY sort, deptnm]]>
      </isNotEqual>
    </statement>

    <statement id="getDocList" parameterClass="System.Collections.Hashtable" resultMap="DocListMap">
      <![CDATA[
        SELECT ' '                                   AS doctorId,
               '진료의(전체)'                         AS doctorNm,
               '일반의'                               AS doctorKind,
               ' '                                   AS drkind,
               1                                     AS sort
          FROM DUAL
         UNION
        SELECT b.userid                              AS doctorId,
               b.usernm                              AS doctorNm,
               DECODE(a.jobposcd, '1800', '전공의'
                                , '1799', '전공의'
                                , '전문의')          AS doctorKind,
               CASE 
                 WHEN jobkindcd like '03%' and jobposcd in ('1799','1800')
                   THEN 'A'
                 WHEN jobkindcd like '03%' then 'B' else 'C'
               END drKind,
               2                                     AS sort
          FROM com.zsumusrd a
             , com.zsumusrb b
         WHERE a.dutplceinstcd     =       #instCd#
           AND a.psnworkyn         =       'N'
           AND NVL(a.tempyn, '-') !=       'C'
           AND a.jobkindcd         LIKE    '03%'
      ]]>
      <isNotEmpty property="ordDeptCd">
        <![CDATA[
           AND a.dutplcecd         =       #ordDeptCd#
        ]]>
      </isNotEmpty>
        <![CDATA[
           AND #srchDd#            BETWEEN a.fromdd AND a.todd
           AND b.userid            =       a.userid
           AND #srchDd#            BETWEEN b.userfromdd AND b.usertodd
         ORDER BY sort, doctorid
       ]]>
    </statement>

    <statement id="getWardList" parameterClass="System.Collections.Hashtable" resultMap="DeptListMap">
      <![CDATA[
        SELECT ' '               AS deptCd,
               '병동(전체)'       AS deptNm,
               1                 AS sort
          FROM DUAL
         UNION ALL
        SELECT dept.deptcd       AS deptcd,
               dept.depthngnm    AS deptnm,
               2                 AS sort
          FROM com.zsdddept dept
          WHERE dept.instcd      = #instCd#
            AND dept.orddeptflag = 'W'
            AND dept.orduseyn    = 'Y'
            AND TO_CHAR(SYSDATE, 'YYYYMMDD') BETWEEN dept.valifromdd AND dept.valitodd
          ORDER BY sort, deptnm
      ]]>
    </statement>
  </statements>
</sqlMap>