<?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_PATIENT_DETAIL_INFO" parameterClass="System.Collections.Hashtable" resultMap="PatientMap">
      <![CDATA[
        select #pid# IO_Pt_ID,
       'M/90y05m' IO_sex_age_y_m,
       '홍길동' IO_Pt_Name,
       '123456-1234567' IO_JuminNo,
       '111' IO_HosType,
       #cretno# IO_CretNo,
       '본관' IO_Ward,
       '906' IO_roomNO,
       '2016-07-01' IO_ADdate,
       #ordtype# IO_VisitType,
       #ordddeptcd# IO_DeptCd,
       #ordddeptcd# IO_DeptNm,
       'CV' IO_OPdeptCd,
       '신경정신과' IO_OPdeptNm,
       '123456' IO_OPdrId,
       '나의사' IO_OPdrNm, 
       '' IO_DxCd,  
       '진단명' IO_DxNm,  
       null IO_bp, null IO_dm, null IO_heart, null IO_kidney, null IO_respiration, 
       null IO_hx, null IO_allergy, null IO_drug, null IO_smoking, 
       null IO_idio, null IO_nacrotics, null IO_airway, null IO_hemorrhage, 
       '요거이 테스트' IO_status_etc, 
       456 IO_OrderNo,
       '' IO_printtime,
       '' IO_maindrId,
       '' IO_maindrNm,
       '' IO_ocrcd,
       '' IO_INPUTId,
       '' IO_INPUTNM,
       '' IO_SIGNIMG
        from DUAL
      ]]>
    </statement>

    <statement id="GET_TRMT_DATE_LIST2" parameterClass="System.Collections.Hashtable" resultMap="ClnDateForDropdownMap">
      <isEqual property="searchType" compareValue="=">
        <![CDATA[
        select '20160701' ClnDate, '2016-07-01' ClnFormatDate, 'CV' VisitType, '외래' VisitTypeName, 'CV' ClnDeptCode, '신경정신과' ClnDeptName
          from DUAL
        ]]>
      </isEqual>
      <isNotEqual property="searchType" compareValue="=">
        <![CDATA[
        select '20160613' ClnDate, '2016-06-13' ClnFormatDate, 'CV' VisitType, '외래' VisitTypeName, 'CV2' ClnDeptCode, '치과' ClnDeptName
          from DUAL
         union
        select '20160625' ClnDate, '2016-06-25' ClnFormatDate, 'CV' VisitType, '외래' VisitTypeName, 'CV' ClnDeptCode, '신경정신과' ClnDeptName
          from DUAL
         union 
        select '20160701' ClnDate, '2016-07-01' ClnFormatDate, 'CV' VisitType, '외래' VisitTypeName, 'CV' ClnDeptCode, '신경정신과' ClnDeptName
          from DUAL
        ]]>
      </isNotEqual>
    </statement>

    <statement id="GET_TRMT_DATE_LIST" parameterClass="System.Collections.Hashtable" resultMap="ClnDateForDropdownMap">
      <isEqual property="searchType" compareValue="=">
        <![CDATA[
        SELECT DISTINCT
               CASE WHEN NVL(#ordType#, '-') IN ('I', 'D', 'E') THEN '1'
                    ELSE '2'
                END                                                                         AS ORDERBY
             , indd                                                                         AS ClnDate
             , SUBSTR(indd, 1, 4) || '-' || SUBSTR(indd, 5, 2) || '-' || SUBSTR(indd, 7, 2) AS ClnFormatDate
             , inpt.ordtype                                                                 AS VisitType
             , ( SELECT cdnm
                   FROM com.zbcmcode c
                  WHERE c.cdgrupid =       'P0001'
                    AND c.cdid     =       inpt.ordtype
                    AND inpt.indd  BETWEEN c.valifromdd AND c.valitodd
               )                                                                            AS VisitTypeName
             , dept.deptengabbr                                                             AS ClnDeptCode
             , dept.depthngnm                                                               AS ClnDeptName
             , dept.deptcd                                                                  AS DeptCd
             , inpt.cretno
             , inpt.medispclid                                                              AS orddrid
          FROM pam.pmihinpt inpt
               LEFT OUTER JOIN com.zsdddept dept
                            ON dept.instcd   = inpt.instcd
                           AND dept.deptcd   = inpt.orddeptcd
                           AND dept.valitodd = '99991231'
         WHERE inpt.instcd    = #instcd#
           AND inpt.pid       = #pid#
           AND inpt.indd      = #searchClnDate#
           AND inpt.histstat  = 'Y'
           AND inpt.mskind    = 'M'
           AND inpt.orddeptcd = #orddeptcd#
         UNION ALL
        SELECT DISTINCT
               CASE WHEN NVL(#ordType#, '-') IN ('O', 'S') THEN '1'
                    ELSE '2'
                END                                                                            AS ORDERBY
             , orddd                                                                           AS ClnDate
             , SUBSTR(orddd, 1, 4) || '-' || SUBSTR(orddd, 5, 2) || '-' || SUBSTR(orddd, 7, 2) AS ClnFormatDate
             , otpt.ordtype                                                                    AS VisitType
             , ( SELECT cdnm
                   FROM com.zbcmcode c
                  WHERE c.cdgrupid =       'P0001'
                    AND c.cdid     =       otpt.ordtype
                    AND otpt.orddd BETWEEN c.valifromdd AND c.valitodd
               )                                                                               AS VisitTypeName
             , dept.deptengabbr                                                                AS ClnDeptCode
             , dept.depthngnm                                                                  AS ClnDeptName
             , dept.deptcd                                                                     AS DeptCd
             , otpt.cretno
             , otpt.orddrid                                                                    AS orddrid
          FROM pam.pmohotpt otpt
               LEFT OUTER JOIN com.zsdddept dept
                            ON dept.instcd   = otpt.instcd
                           AND dept.deptcd   = otpt.orddeptcd
                           AND dept.valitodd = '99991231'
         WHERE otpt.instcd    =  #instcd#
           AND otpt.pid       =  #pid#
           AND otpt.orddd     =  #searchClnDate#
           AND otpt.orddeptcd =  #orddeptcd#
           AND otpt.histstat  IN ('R', 'T')
           AND otpt.mskind    =  'M'
         UNION ALL 
        SELECT DISTINCT
               '99'                                                                         AS ORDERBY
             , indd                                                                         AS ClnDate
             , substr(indd, 1, 4) || '-' || substr(indd, 5, 2) || '-' || substr(indd, 7, 2) AS ClnFormatDate
             , inpt.ordtype                                                                 AS VisitType
             , ( SELECT cdnm
                   FROM com.zbcmcode c
                  WHERE c.cdgrupid =       'P0001'
                    AND c.cdid     =       inpt.ordtype
                    AND inpt.indd  BETWEEN c.valifromdd AND c.valitodd
               )                                                                            AS VisitTypeName
             , dept.deptengabbr                                                             AS ClnDeptCode
             , dept.depthngnm                                                               AS ClnDeptName
             , dept.deptcd                                                                  AS DeptCd
             , inpt.cretno
             , inpt.medispclid                                                              AS orddrid
          FROM pam.pmihinpt inpt
               LEFT OUTER JOIN com.zsdddept dept
                            ON dept.instcd   = inpt.instcd
                           AND dept.deptcd   = inpt.orddeptcd
                           AND dept.valitodd = '99991231'
         WHERE inpt.instcd     = #instcd#
           AND inpt.pid        = #pid#
           AND inpt.indd       = #searchClnDate#
           AND inpt.histstat   = 'Y'
           AND inpt.mskind     = 'M'
           AND inpt.orddeptcd != #orddeptcd#
         UNION ALL
        SELECT DISTINCT
               '99'                                                                            AS ORDERBY
             , orddd                                                                           AS ClnDate
             , SUBSTR(orddd, 1, 4) || '-' || SUBSTR(orddd, 5, 2) || '-' || SUBSTR(orddd, 7, 2) AS ClnFormatDate
             , otpt.ordtype                                                                    AS VisitType
             , ( SELECT cdnm
                   FROM com.zbcmcode c
                  WHERE c.cdgrupid =       'P0001'
                    AND c.cdid     =       otpt.ordtype
                    AND otpt.orddd BETWEEN c.valifromdd AND c.valitodd
               )                                                                               AS VisitTypeName
             , dept.deptengabbr                                                                AS ClnDeptCode
             , dept.depthngnm                                                                  AS ClnDeptName
             , dept.deptcd                                                                     AS DeptCd
             , otpt.cretno
             , otpt.orddrid                                                                    AS orddrid
          FROM pam.pmohotpt otpt
               LEFT OUTER JOIN com.zsdddept dept
                            ON dept.instcd   = otpt.instcd
                           AND dept.deptcd   = otpt.orddeptcd
                           AND dept.valitodd = '99991231'
         WHERE otpt.instcd     =  #instcd#
           AND otpt.pid        =  #pid#
           AND otpt.orddd      =  #searchClnDate#
           AND otpt.orddeptcd !=  #orddeptcd#
           AND otpt.histstat   IN ('R', 'T')
           AND otpt.mskind     =  'M'
        ORDER BY ORDERBY, cretno DESC]]>
      </isEqual>
      <isNotEqual property="searchType" compareValue="=">
        <![CDATA[
        SELECT DISTINCT
               CASE WHEN NVL(#ordType#, '-') IN ('I', 'D', 'E') THEN '1'
                    ELSE '2'
                END                                                                         AS ORDERBY
             , indd                                                                         AS ClnDate
             , substr(indd, 1, 4) || '-' || substr(indd, 5, 2) || '-' || substr(indd, 7, 2) AS ClnFormatDate
             , inpt.ordtype                                                                 AS VisitType
             , ( SELECT cdnm
                   FROM com.zbcmcode c
                  WHERE c.cdgrupid =       'P0001'
                    AND c.cdid     =       inpt.ordtype
                    AND inpt.indd  BETWEEN c.valifromdd AND c.valitodd
               )                                                                            AS VisitTypeName
             , dept.deptengabbr                                                             AS ClnDeptCode
             , dept.depthngnm                                                               AS ClnDeptName
             , dept.deptcd
             , inpt.cretno
             , inpt.medispclid                                                              AS orddrid
          FROM pam.pmihinpt inpt
               LEFT OUTER JOIN com.zsdddept dept
                            ON dept.instcd =       inpt.instcd
                           AND dept.deptcd =       inpt.orddeptcd
                           AND inpt.indd   BETWEEN dept.valifromdd AND dept.valitodd
         WHERE inpt.instcd    = #instcd#
           AND inpt.pid       = #pid#
           AND inpt.indd     >= #searchClnDate#
           AND inpt.histstat  = 'Y'
           AND inpt.mskind    = 'M'
         UNION ALL
        SELECT DISTINCT
               CASE WHEN NVL(#ordType#, '-') IN ('O', 'S') THEN '1'
                    ELSE '2'
                END                                                                            AS ORDERBY
             , orddd                                                                           AS ClnDate
             , substr(orddd, 1, 4) || '-' || substr(orddd, 5, 2) || '-' || substr(orddd, 7, 2) AS ClnFormatDate
             , otpt.ordtype                                                                    AS VisitType
             , ( SELECT cdnm
                   FROM com.zbcmcode c
                  WHERE c.cdgrupid =       'P0001'
                    AND c.cdid     =       otpt.ordtype
                    AND otpt.orddd BETWEEN c.valifromdd AND c.valitodd
               )                                                                               AS VisitTypeName
             , dept.deptengabbr                                                                AS ClnDeptCode
             , dept.depthngnm                                                                  AS ClnDeptName
             , dept.deptcd
             , otpt.cretno
             , otpt.orddrid
          FROM pam.pmohotpt otpt
               LEFT OUTER JOIN com.zsdddept dept
                            ON dept.instcd =       otpt.instcd
                           AND dept.deptcd =       otpt.orddeptcd
                           AND otpt.orddd  BETWEEN dept.valifromdd AND dept.valitodd
         WHERE otpt.instcd    =  #instcd#
           AND otpt.pid       =  #pid#
           AND otpt.orddd    >=  #searchClnDate#
           AND otpt.histstat  IN ('R', 'T')
           AND otpt.mskind    =  'M'
         ORDER BY 2, cretno]]>
      </isNotEqual>
    </statement>

    <statement id="getPatientInfoOut" parameterClass="System.Collections.Hashtable" resultMap="PatientMap">
      <![CDATA[
        SELECT OTPT.ORDDEPTCD                                                        AS ordDeptCd,
               (SELECT DEPTENGABBR 
                  FROM COM.ZSDDDEPT DEPT
                 WHERE DEPT.INSTCD = OTPT.INSTCD
                   AND DEPT.DEPTCD = OTPT.ORDDEPTCD
                   AND OTPT.ORDDD BETWEEN DEPT.VALIFROMDD AND DEPT.VALITODD)          AS deptEngAbbr,
               COM.FN_ZS_GETDEPTNAME(OTPT.INSTCD, OTPT.ORDDEPTCD, OTPT.ORDDD)        AS ordDeptNm,
               OTPT.PID                                                              AS pid,
               TO_CHAR(OTPT.cretno)                                                  AS cretNo,
               ''                                                                    AS roomCd,
               OTPT.ORDDD                                                            AS inDd,
               ''                                                                    AS dschDd, 
               OTPT.ORDTYPE                                                          AS ordType,
               OTPT.INSTCD                                                           AS instCd,
               OTPT.ORDDRID                                                          AS mainDrId,
               COM.FN_ZS_GETUSERNM(OTPT.ORDDRID, OTPT.ORDDD)                         AS mainDrName,
               ''                                                                    AS erDrNm,
               TO_CHAR(OTPT.FSTRGSTDT)                                               AS firstRgstDt,
               PTBS.SEX || '/' || COM.FN_ZZ_GETAGEAS(PTBS.RRGSTNO1
                                                   , PTBS.RRGSTNO2
                                                   , TO_CHAR(SYSDATE, 'YYYYMMDD')
                                                   , 'A'
                                                   , PTBS.BRTHDD)                    AS sa,
               PTBS.HNGNM                                                            AS patientName,
               PTBS.RRGSTNO1 || '-' || SUBSTR(PTBS.RRGSTNO2, 1, 1) || '******'       AS juminNo,
               PTBS.ZIPCDADDR                                                        AS zipCdAddr,
               PTBS.MPPHONTEL                                                        AS telNum,
               (SELECT CDNM
                  FROM COM.ZBCMCODE
                 WHERE CDGRUPID = 'P0008'
                   AND CDID     = OTPT.INSUKIND)                                     AS insuKind,
               ''                                                                    AS ward,
               (SELECT DIAG.DIAGCD
                  FROM EMR.MMOHDIAG DIAG
                 WHERE DIAG.INSTCD         = #instCd#
                   AND DIAG.PID            = OTPT.PID
                   AND DIAG.ORDDD          = OTPT.ORDDD
                   AND DIAG.CRETNO         = OTPT.CRETNO
                   AND DIAG.DIAGHISTCD     = 'O'
                   AND DIAG.DIAGTYPECD     = 'D'
                   AND DIAG.DIAGKINDCDFLAG = 'M'
                   AND ROWNUM = 1
                   AND DIAG.DIAGHISTNO     = (SELECT MAX(DIAGH.DIAGHISTNO)
                                                FROM EMR.MMOHDIAG DIAGH
                                               WHERE DIAGH.INSTCD         = #instCd#
                                                 AND DIAGH.PID            = OTPT.PID
                                                 AND DIAGH.ORDDD          = OTPT.ORDDD
                                                 AND DIAGH.CRETNO         = OTPT.CRETNO
                                                 AND DIAGH.DIAGHISTCD     = 'O'
                                                 AND DIAGH.DIAGTYPECD     = 'D'
                                                 AND DIAGH.DIAGKINDCDFLAG = 'M')
               )                                                                  AS dxCd,
               ( SELECT TERM.DIAGHNGNM
                   FROM EMR.MMOHDIAG DIAG
                      , EMR.MMBVDIAG TERM
                  WHERE DIAG.INSTCD         = #instCd#
                    AND DIAG.PID            = OTPT.PID
                    AND DIAG.ORDDD          = OTPT.ORDDD
                    AND DIAG.CRETNO         = OTPT.CRETNO
                    AND DIAG.DIAGHISTCD     = 'O'
                    AND DIAG.DIAGTYPECD     = 'D'
                    AND DIAG.DIAGKINDCDFLAG = 'M'
                    AND TERM.INSTCD         = DIAG.INSTCD
                    AND TERM.ORGDIAGCD      = DIAG.DIAGCD
                    AND DIAG.DIAGDD         BETWEEN TERM.TERMFROMDD AND TERM.TERMTODD
                    AND DIAG.DIAGDD         BETWEEN TERM.DIAGATTRFROMDD AND TERM.DIAGATTRTODD
                    AND ROWNUM = 1
                    AND DIAG.DIAGHISTNO     = (SELECT MAX(DIAGH.DIAGHISTNO)
                                                 FROM EMR.MMOHDIAG DIAGH
                                                WHERE DIAGH.INSTCD         = #instCd#
                                                  AND DIAGH.PID            = OTPT.PID
                                                  AND DIAGH.ORDDD          = OTPT.ORDDD
                                                  AND DIAGH.CRETNO         = OTPT.CRETNO
                                                  AND DIAGH.DIAGHISTCD     = 'O'
                                                  AND DIAGH.DIAGTYPECD     = 'D'
                                                  AND DIAGH.DIAGKINDCDFLAG = 'M')
               )                                                                  AS dxNm,
               (SELECT LISTAGG(DECODE(ISOLDISPCD, 'A','공기주의(A)',
                                                  'B','혈액주의(B)',
                                                  'C','접촉주의(C)',
                                                  'D','비말주의(D)'), ', ') WITHIN GROUP (ORDER BY ISOLDISPCD) AS gbn
                  FROM AST.ASBHISPT
                 WHERE INSTCD                 = #instCd#
                   AND PID                    = #pid#
                   AND ISOLDISPCD             IN ('A', 'B','C', 'D')
                   AND ((TO_CHAR(SYSDATE,'YYYYMMDD') < SUBSTR(DISPTODT, 1, 8))
                    OR ((SUBSTR(DISPFROMDT, 1, 8) <= TO_CHAR(SYSDATE,'YYYYMMDD'))
                   AND SUBSTR(DISPTODT, 1, 8) IS NULL)))                              AS gbn,
                ''                                                                    AS opDeptCd,
                ''                                                                    AS opDeptNm,
                ''                                                                    AS opDrNm,
                ''                                                                    AS opDrId,
                ''                                                                    AS opCnfmDd,
                ''                                                                    AS perfDrNm,
                ''                                                                    AS perfDrFlag,
                ''                                                                    AS perfDrDept,
                ''                                                                    AS opDiagNm,
                ''                                                                    AS opNm,
                ''                                                                    AS anstDrNm1,
                ''                                                                    AS anstDrFlag1,
                ''                                                                    AS anstDeptNm1,
                ''                                                                    AS anstDrNm2,
                ''                                                                    AS anstDrFlag2,
                ''                                                                    AS anstDeptNm2,
                ''                                                                    AS anstDrNm3,
                ''                                                                    AS anstDrFlag3,
                ''                                                                    AS anstDeptNm3,
                ''                                                                    AS opRsrvNo,
                ''                                                                    AS orderNo,
                ''                                                                    AS printTime,
                ''                                                                    AS ocrCd,
                ''                                                                    AS inputId,
                ''                                                                    AS inputNm,
                ''                                                                    AS signImg,

                ''                                                                    AS bp,
                ''                                                                    AS dm,
                ''                                                                    AS heart,
                ''                                                                    AS kidney,
                ''                                                                    AS respiration,
                ''                                                                    AS hx,
                ''                                                                    AS allergy,
                ''                                                                    AS drug,
                ''                                                                    AS smoking,
                ''                                                                    AS idio,
                ''                                                                    AS nacrotics,
                ''                                                                    AS airway,
                ''                                                                    AS hemorrhage,
                ''                                                                    AS statusEtc
          FROM PAM.PMOHOTPT OTPT
               LEFT OUTER JOIN EMA.VW_PAM_PMCMPTBS PTBS
                            ON PTBS.PID    = OTPT.PID
                           AND PTBS.INSTCD = OTPT.INSTCD
         WHERE OTPT.INSTCD    =  #instCd#
           AND OTPT.PID       =  #pid#
           AND OTPT.ORDDD     =  #inDd#
           AND OTPT.HISTSTAT  IN ('R', 'T')
           AND OTPT.MSKIND    =  'M'
           AND OTPT.CRETNO    = #cretNo#
      ]]>
    </statement>

    <statement id="getPatientInfoIn" parameterClass="System.Collections.Hashtable" resultMap="PatientMap">
      <![CDATA[
         SELECT INPT.ORDDEPTCD                                                               AS ordDeptCd,
                (SELECT DEPTENGABBR 
                   FROM COM.ZSDDDEPT DEPT
                  WHERE DEPT.INSTCD = INPT.INSTCD
                    AND DEPT.DEPTCD = INPT.ORDDEPTCD
                    AND INPT.INDD BETWEEN DEPT.VALIFROMDD AND DEPT.VALITODD)                 AS deptEngAbbr,
                COM.FN_ZS_GETDEPTNAME(INPT.INSTCD, INPT.ORDDEPTCD, INPT.INDD)                AS ordDeptNm,
                INPT.PID                                                                     AS pid,
                TO_CHAR(INPT.CRETNO)                                                         AS cretNo,
                INPT.ROOMCD                                                                  AS roomCd,
                INPT.INDD                                                                    AS inDd,
                INPT.DSCHDD                                                                  AS dschDd,
                INPT.ORDTYPE                                                                 AS ordType,
                INPT.INSTCD                                                                  AS instCd,
                INPT.MEDISPCLID                                                              AS mainDrId,
                COM.FN_ZS_GETUSERNM(INPT.MEDISPCLID, INPT.INDD)                              AS mainDrName,
                COM.FN_ZS_GETUSERNM(INPT.ERMEDISPCLID, INPT.INDD)                            AS erDrNm,
                TO_CHAR(INPT.FSTRGSTDT)                                                      AS firstRgstDt,
                PTBS.SEX || '/' || COM.FN_ZZ_GETAGEAS(PTBS.RRGSTNO1,
                                                      PTBS.RRGSTNO2,
                                                      TO_CHAR(SYSDATE, 'YYYYMMDD'),
                                                      'A', PTBS.BRTHDD)                      AS sa,
                PTBS.HNGNM                                                                   AS patientName,
                PTBS.RRGSTNO1 || '-' || SUBSTR(PTBS.RRGSTNO2, 1, 1) || '******'              AS juminNo,
                PTBS.ZIPCDADDR                                                               AS zipCdAddr,
                PTBS.MPPHONTEL                                                               AS telNum,
                (SELECT CDNM
                   FROM COM.ZBCMCODE
                  WHERE CDGRUPID = 'P0008'
                    AND CDID     = INPT.INSUKIND)                                            AS insuKind,
                (SELECT DEPT.DEPTENGABBR
                   FROM COM.ZSDDDEPT DEPT
                  WHERE DEPT.INSTCD =       INPT.INSTCD
                    AND DEPT.DEPTCD =       INPT.WARDCD
                    AND INPT.INDD      BETWEEN DEPT.VALIFROMDD AND DEPT.VALITODD)               AS ward,
                (SELECT DIAG.DIAGCD
                   FROM EMR.MMOHDIAG DIAG
                  WHERE DIAG.INSTCD         = #instCd#
                    AND DIAG.PID            = INPT.PID
                    AND DIAG.ORDDD          = INPT.INDD
                    AND DIAG.CRETNO         = INPT.CRETNO
                    AND DIAG.ORDDEPTCD      = INPT.ORDDEPTCD
                    AND DIAG.DIAGHISTCD     = 'O'
                    AND DIAG.DIAGTYPECD     = 'D'
                    AND DIAG.DIAGKINDCDFLAG = 'M'
                    AND ROWNUM = 1
                    AND DIAG.DIAGHISTNO     = (SELECT MAX(DIAGH.DIAGHISTNO)
                                                 FROM EMR.MMOHDIAG DIAGH
                                                WHERE DIAGH.INSTCD         = #instCd#
                                                  AND DIAGH.PID            = INPT.PID
                                                  AND DIAGH.ORDDD          = INPT.INDD
                                                  AND DIAGH.CRETNO         = INPT.CRETNO
                                                  AND DIAGH.ORDDEPTCD      = INPT.ORDDEPTCD
                                                  AND DIAGH.DIAGHISTCD     = 'O'
                                                  AND DIAGH.DIAGTYPECD     = 'D'
                                                  AND DIAGH.DIAGKINDCDFLAG = 'M')
                )                                                                            AS dxCd,
                (SELECT TERM.DIAGHNGNM
                   FROM EMR.MMOHDIAG DIAG,
                        EMR.MMBVDIAG TERM
                  WHERE DIAG.INSTCD         =       #instCd#
                    AND DIAG.PID            =       INPT.PID
                    AND DIAG.ORDDD          =       INPT.INDD
                    AND DIAG.CRETNO         =       INPT.CRETNO
                    AND DIAG.ORDDEPTCD      =       INPT.ORDDEPTCD
                    AND DIAG.DIAGHISTCD     =       'O'
                    AND DIAG.DIAGTYPECD     =       'D'
                    AND DIAG.DIAGKINDCDFLAG =       'M'
                    AND TERM.INSTCD         =       DIAG.INSTCD
                    AND TERM.ORGDIAGCD      =       DIAG.DIAGCD
                    AND DIAG.DIAGDD         BETWEEN TERM.TERMFROMDD AND TERM.TERMTODD
                    AND DIAG.DIAGDD         BETWEEN TERM.DIAGATTRFROMDD AND TERM.DIAGATTRTODD
                    AND ROWNUM = 1
                    AND DIAG.DIAGHISTNO     =       (SELECT MAX(DIAGH.DIAGHISTNO)
                                                       FROM EMR.MMOHDIAG DIAGH
                                                      WHERE diagh.instcd         = #instCd#
                                                        AND DIAGH.PID            = INPT.PID
                                                        AND DIAGH.ORDDD          = INPT.INDD
                                                        AND DIAGH.CRETNO         = INPT.CRETNO
                                                        AND DIAGH.ORDDEPTCD      = INPT.ORDDEPTCD
                                                        AND DIAGH.DIAGHISTCD     = 'O'
                                                        AND DIAGH.DIAGTYPECD     = 'D'
                                                        AND DIAGH.DIAGKINDCDFLAG = 'M')
                )                                                                     AS dxNm,
                (SELECT LISTAGG(DECODE(ISOLDISPCD, 'A','공기주의(A)',
                                                   'B','혈액주의(B)',
                                                   'C','접촉주의(C)',
                                                   'D','비말주의(D)'), ', ') WITHIN GROUP (ORDER BY ISOLDISPCD) AS gbn
                   FROM AST.ASBHISPT
                  WHERE INSTCD                 = #instCd#
                    AND PID                    = #pid#
                    AND ISOLDISPCD             IN ('A', 'B','C', 'D')
                    AND ((TO_CHAR(SYSDATE,'YYYYMMDD') < SUBSTR(DISPTODT, 1, 8))
                     OR ((SUBSTR(DISPFROMDT, 1, 8) <= TO_CHAR(SYSDATE,'YYYYMMDD'))
                    AND SUBSTR(DISPTODT, 1, 8) IS NULL))
                )                                                                                            AS gbn,
                OPRS.PERFDRDEPTCD                                                     AS opDeptCd,
                OPRS.PERFDRDEPT                                                       AS opDeptNm,
                OPRS.PERFDRNM                                                         AS opDrNm,
                OPRS.PERFDRID                                                         AS opDrId,
                OPRS.OPCNFMDD                                                         AS opCnfmDd,
                OPRS.PERFDRNM                                                         AS perfDrNm,
                OPRS.PERFDRFLAG                                                       AS perfDrFlag,
                OPRS.PERFDRDEPT                                                       AS perfDrDept,
                OPRS.OPDIAGNM                                                         AS opDiagNm,
                OPRS.OPNM                                                             AS opNm,
                OPRS.ANSTDRNM1                                                        AS anstDrNm1,
                OPRS.ANSTDRFLAG1                                                      AS anstDrFlag1,
                OPRS.ANSTDEPTNM1                                                      AS anstDeptNm1,
                OPRS.ANSTDRNM2                                                        AS anstDrNm2,
                OPRS.ANSTDRFLAG2                                                      AS anstDrFlag2,
                OPRS.ANSTDEPTNM2                                                      AS anstDeptNm2,
                OPRS.ANSTDRNM3                                                        AS anstDrNm3,
                OPRS.ANSTDRFLAG3                                                      AS anstDrFlag3,
                OPRS.ANSTDEPTNM3                                                      AS anstDeptNm3,
                #opRsrvNo#                                                            AS opRsrvNo,
                ''                                                                    AS orderNo,
                ''                                                                    AS printTime,
                ''                                                                    AS ocrCd,
                ''                                                                    AS inputId,
                ''                                                                    AS inputNm,
                ''                                                                    AS signImg,

                ''                                                                    AS bp,
                ''                                                                    AS dm,
                ''                                                                    AS heart,
                ''                                                                    AS kidney,
                ''                                                                    AS respiration,
                ''                                                                    AS hx,
                ''                                                                    AS allergy,
                ''                                                                    AS drug,
                ''                                                                    AS smoking,
                ''                                                                    AS idio,
                ''                                                                    AS nacrotics,
                ''                                                                    AS airway,
                ''                                                                    AS hemorrhage,
                ''                                                                    AS statusEtc
          FROM PAM.PMIHINPT        INPT,
               EMA.VW_PAM_PMCMPTBS PTBS
      ]]>
      <isNotEmpty property="opRsrvNo">
        <![CDATA[
             , ( SELECT a.opcnfmdd
                      , a.perfdrid
                      , a.perfdrnm
                      , a.perfdrflag
                      , a.perfdeptcd                                                               AS perfdrdeptcd
                      , a.perfdeptnm                                                               AS perfdrdept
                      , a.opdiagnm
                      , a.opnm
                      , MAX(CASE WHEN a.opcnfmno = 1 AND NVL(a.anstdrid, '-') != '-' THEN
                                      COM.FN_ZS_GETUSERNM(a.anstdrid, a.opcnfmdd)
                                 WHEN a.opcnfmno = 1 AND NVL(a.anstdrid1, '-') NOT IN ('-', 'undefined') THEN
                                      COM.FN_ZS_GETUSERNM(a.anstdrid1, a.opcnfmdd)
                                 ELSE ''
                             END)                                                                  AS anstdrnm1
                      , MAX(CASE WHEN a.opcnfmno = 1 AND NVL(a.anstdrid, '-') != '-' THEN
                                      CASE WHEN b.jobposcd IN ('1800', '1799') THEN
                                                '전공의'
                                           ELSE '전문의'
                                       END
                                 WHEN a.opcnfmno = 1 AND NVL(a.anstdrid1, '-') NOT IN ('-', 'undefined') THEN
                                      ( SELECT CASE WHEN c.jobposcd IN ('1800', '1799') THEN
                                                         '전공의'
                                                    ELSE '전문의'
                                                END
                                          FROM com.zsumusrd c
                                         WHERE c.dutplceinstcd =       a.instcd
                                           AND c.userid        =       a.anstdrid1
                                           AND a.opcnfmdd      BETWEEN c.fromdd AND c.todd
                                           AND c.dutplcecd     =       '2090000000'
                                           AND c.psnworkyn     =       'N'
                                      )
                                 ELSE ''
                             END)                                                                  AS anstdrflag1
                      , MAX(CASE WHEN a.opcnfmno = 1 AND NVL(a.anstdrid, '-') != '-' THEN
                                      a.anstdeptnm
                                 WHEN a.opcnfmno = 1 AND NVL(a.anstdrid1, '-') NOT IN ('-', 'undefined') THEN
                                      a.anstdeptnm
                                 ELSE ''
                             END)                                                                  AS anstdeptnm1
                      , MAX(CASE WHEN a.opcnfmno = 2 AND NVL(a.anstdrid, '-') != '-' THEN
                                      COM.FN_ZS_GETUSERNM(a.anstdrid, a.opcnfmdd)
                                 WHEN a.opcnfmno = 2 AND NVL(a.anstdrid2, '-') NOT IN ('-', 'undefined') THEN
                                      COM.FN_ZS_GETUSERNM(a.anstdrid2, a.opcnfmdd)
                                 ELSE ''
                             END)                                                                  AS anstdrnm2
                      , MAX(CASE WHEN a.opcnfmno = 2 AND NVL(a.anstdrid, '-') != '-' THEN
                                      CASE WHEN b.jobposcd IN ('1800', '1799') THEN
                                                '전공의'
                                           ELSE '전문의'
                                       END
                                 WHEN a.opcnfmno = 2 AND NVL(a.anstdrid2, '-') NOT IN ('-', 'undefined') THEN
                                      ( SELECT CASE WHEN c.jobposcd IN ('1800', '1799') THEN
                                                         '전공의'
                                                    ELSE '전문의'
                                                END
                                          FROM com.zsumusrd c
                                         WHERE c.dutplceinstcd =       a.instcd
                                           AND c.userid        =       a.anstdrid2
                                           AND a.opcnfmdd      BETWEEN c.fromdd AND c.todd
                                           AND c.dutplcecd     =       '2090000000'
                                           AND c.psnworkyn     =       'N'
                                      )
                                 ELSE ''
                             END)                                                                  AS anstdrflag2
                      , MAX(CASE WHEN a.opcnfmno = 2 AND NVL(a.anstdrid, '-') != '-' THEN
                                      a.anstdeptnm
                                 WHEN a.opcnfmno = 2 AND NVL(a.anstdrid2, '-') NOT IN ('-', 'undefined') THEN
                                      a.anstdeptnm
                                 ELSE ''
                             END)                                                                  AS anstdeptnm2
                      , MAX(CASE WHEN a.opcnfmno = 3 AND NVL(a.anstdrid, '-') != '-' THEN
                                      COM.FN_ZS_GETUSERNM(a.anstdrid, a.opcnfmdd)
                                 WHEN a.opcnfmno = 3 AND NVL(a.anstdrid3, '-') NOT IN ('-', 'undefined') THEN
                                      COM.FN_ZS_GETUSERNM(a.anstdrid3, a.opcnfmdd)
                                 ELSE ''
                             END)                                                                  AS anstdrnm3
                      , MAX(CASE WHEN a.opcnfmno = 3 AND NVL(a.anstdrid, '-') != '-' THEN
                                      CASE WHEN b.jobposcd IN ('1800', '1799') THEN
                                                '전공의'
                                           ELSE '전문의'
                                       END
                                 WHEN a.opcnfmno = 3 AND NVL(a.anstdrid3, '-') NOT IN ('-', 'undefined') THEN
                                      ( SELECT CASE WHEN c.jobposcd IN ('1800', '1799') THEN
                                                         '전공의'
                                                    ELSE '전문의'
                                                END
                                          FROM com.zsumusrd c
                                         WHERE c.dutplceinstcd =       a.instcd
                                           AND c.userid        =       a.anstdrid3
                                           AND a.opcnfmdd      BETWEEN c.fromdd AND c.todd
                                           AND c.dutplcecd     =       '2090000000'
                                           AND c.psnworkyn     =       'N'
                                      )
                                 ELSE ''
                             END)                                                                  AS anstdrflag3
                      , MAX(CASE WHEN a.opcnfmno = 3 AND NVL(a.anstdrid, '-') != '-' THEN
                                      a.anstdeptnm
                                 WHEN a.opcnfmno = 3 AND NVL(a.anstdrid3, '-') NOT IN ('-', 'undefined') THEN
                                      a.anstdeptnm
                                 ELSE ''
                             END)                                                                  AS anstdeptnm3
                   FROM ( SELECT a.instcd
                               , a.opcnfmdd
                               , a.perfdrid
                               , COM.FN_ZS_GETUSERNM(a.perfdrid, a.opcnfmdd)                    AS perfdrnm
                               , CASE WHEN b.jobposcd IN ('1800', '1799') THEN
                                           '전공의'
                                      ELSE '전문의'
                                   END                                                          AS perfdrflag
                               , a.perfdeptcd
                               , COM.FN_ZS_GETDEPTNM(a.instcd, a.perfdeptcd, a.opcnfmdd)        AS perfdeptnm
                               , MAX(CASE WHEN c.termflag = '0' AND c.termcd = a.diagcd THEN
                                               NVL(c.termhngnm, c.termengnm)
                                          ELSE ''
                                      END)                                                      AS opdiagnm
                               , MAX(CASE WHEN c.termflag = '9' AND c.termcd = a.opcd THEN
                                               NVL(c.termhngnm, c.termengnm)
                                          ELSE ''
                                      END)                                                      AS opnm
                               , d.opcnfmno
                               , d.anstdrid
                               , COM.FN_ZS_GETDEPTNM(a.instcd, '2090000000', a.opcnfmdd)        AS anstdeptnm
                               , MAX(e.anstdrid)                                                AS anstdrid1
                               , MAX(e.anstdrid2)                                               AS anstdrid2
                               , MAX(e.anstdrid3)                                               AS anstdrid3
                            FROM emr.mmohoprs a
                               , com.zsumusrd b
                               , emr.mrtmterm c
                               , emr.mmodocad d
                               , emr.mmodoprs e
                           WHERE a.instcd        =       #instCd#
                             AND a.oprsrvno      =       #opRsrvNo#
                             AND a.ophistcd      =       'O'
                             AND b.dutplceinstcd =       a.instcd
                             AND b.userid        =       a.perfdrid
                             AND b.dutplcecd     =       a.perfdeptcd
                             AND a.opcnfmdd      BETWEEN b.fromdd AND b.todd
                             AND c.instcd        =       a.instcd
                             AND c.termflag      IN      ('0', '9')
                             AND c.termcd        IN      (a.diagcd, a.opcd)
                             AND a.opcnfmdd      BETWEEN c.termfromdd AND c.termtodd
                             AND d.instcd(+)     =       a.instcd
                             AND d.oprsrvno(+)   =       a.oprsrvno
                             AND d.opcnfmno(+)   IN      (1, 2, 3)
                             AND e.instcd(+)     =       a.instcd
                             AND a.opcnfmdd      BETWEEN e.appstartdd(+) AND e.appenddd(+)
                             AND e.usedwflag(+)  =       TO_CHAR(TO_DATE(a.opcnfmdd, 'YYYYMMDD'), 'd')
                             AND e.oproomcd(+)   =       a.oproomcd
                             AND CASE WHEN SUBSTR(a.opfromtmcd, 1, 4) BETWEEN '0000' AND '1200' THEN
                                           '1'
                                      ELSE '2'
                                  END            =       e.usescheflag(+)
                           GROUP BY a.instcd
                                  , a.opcnfmdd
                                  , a.perfdrid
                                  , a.perfdeptcd
                                  , b.jobposcd
                                  , d.opcnfmno
                                  , d.anstdrid
                        ) a
                      , com.zsumusrd b
                  WHERE b.dutplceinstcd(+) =       a.instcd
                    AND b.userid(+)        =       a.anstdrid
                    AND a.opcnfmdd         BETWEEN b.fromdd(+) AND b.todd(+)
                    AND b.dutplcecd(+)     =       '2090000000'
                    AND b.psnworkyn(+)     =       'N'
                  GROUP BY a.opcnfmdd
                         , a.perfdrid
                         , a.perfdrnm
                         , a.perfdrflag
                         , a.perfdeptcd
                         , a.perfdeptnm
                         , a.opdiagnm
                         , a.opnm
               ) oprs
        ]]>
      </isNotEmpty>
      <isEmpty property="opRsrvNo">
        <![CDATA[
             , ( SELECT ''    AS opcnfmdd
                      , ''    AS perfdrid
                      , ''    AS perfdrnm
                      , ''    AS perfdrflag
                      , ''    AS perfdrdeptcd
                      , ''    AS perfdrdept
                      , ''    AS opdiagnm
                      , ''    AS opnm
                      , ''    AS anstdrnm1
                      , ''    AS anstdrflag1
                      , ''    AS anstdeptnm1
                      , ''    AS anstdrnm2
                      , ''    AS anstdrflag2
                      , ''    AS anstdeptnm2
                      , ''    AS anstdrnm3
                      , ''    AS anstdrflag3
                      , ''    AS anstdeptnm3
                   FROM DUAL
               ) oprs
        ]]>
      </isEmpty>
      <![CDATA[
         WHERE 1 = 1
           AND INPT.INSTCD       = #instCd#
           AND INPT.PID          = #pid#
           AND INPT.HISTSTAT     = 'Y'
           AND INPT.MSKIND       = 'M'
           AND INPT.CRETNO       = #cretNo#
           AND INPT.INDD         = #inDd#
           AND PTBS.INSTCD(+)    = INPT.INSTCD
           AND PTBS.PID(+)       = INPT.PID
      ]]>
      <isEmpty property="opRsrvNo">
        <![CDATA[
           AND INPT.ORDDEPTCD    = #ordDeptCd#
        ]]>
      </isEmpty>
      <![CDATA[
        ORDER BY INPT.FSTRGSTDT DESC
      ]]>
    </statement>

    <statement id="getOcrTag" parameterClass="System.Collections.Hashtable" resultClass="System.String">
      <![CDATA[ 
        SELECT TO_CHAR(SYSDATE, 'YYYYMMDD') || SUBSTR(LPAD(EMR.SQ_MRFMOCRP_01.NEXTVAL, 10, '0'), 6, 5) AS ocrtag
		      FROM DUAL]]>
    </statement>

    <statement id="getDiagList" parameterClass="System.Collections.Hashtable" resultClass="System.String">
      <![CDATA[ 
        SELECT term.diaghngnm 
          FROM emr.mmohdiag diag,
               emr.mmbvdiag term,
               pam.pmihinpt inpt
         WHERE inpt.instcd = #instcd#
               AND inpt.pid = #pid#
               AND inpt.indd = #orddd#
               AND inpt.histstat = 'Y'
               AND inpt.mskind = 'M'
               AND inpt.pid = diag.pid
               AND inpt.indd = diag.orddd
               AND diag.cretno = inpt.cretno
               AND diag.instcd = inpt.instcd
               AND diag.instcd = term.instcd
               AND diag.diagcd = term.orgdiagcd
               AND diag.diaghistcd = 'O'
               AND diag.diagtypecd = 'D'
               AND diag.diagdd >= term.termfromdd
               AND diag.diagdd <= term.termtodd
               AND diag.diagdd >= term.diagattrfromdd
               AND diag.diagdd <= term.diagattrtodd
               AND diag.genrflagcd in ('I','E')
        union all
        SELECT term.diaghngnm as diaghngnm
          FROM emr.mmohdiag diag,
               emr.mmbvdiag term,
               pam.pmohotpt otpt
         WHERE otpt.instcd = #instcd#
               AND otpt.pid = #pid#
               AND otpt.orddd = #orddd#
               AND otpt.pid = diag.pid
               AND otpt.orddd = diag.orddd
               AND diag.cretno = otpt.cretno
               AND diag.instcd = otpt.instcd
               AND diag.instcd = term.instcd
               AND diag.diagcd = term.orgdiagcd
               AND diag.diaghistcd = 'O'
               AND diag.diagtypecd = 'D'
               AND diag.diagdd >= term.termfromdd
               AND diag.diagdd <= term.termtodd
               AND diag.diagdd >= term.diagattrfromdd
               AND diag.diagdd <= term.diagattrtodd
               AND diag.genrflagcd in ('O','S')
      ]]>
    </statement>

    <insert id="setFileName" parameterClass="System.Collections.Hashtable">
      <![CDATA[ 
        declare
            I_PID        VARCHAR2(10) := #pid#;
            I_IOFLAG     VARCHAR2(1)  := #ordtype#;
            I_ORDDD      VARCHAR2(8)  := #orddd#;
            I_DSCHDD     VARCHAR2(8)  := #dschdd#;
            I_CRETNO     NUMBER(10)   := #cretno#;
            I_FILESIZE   NUMBER(18)   := #filesize#;
            I_FORMCD     VARCHAR2(10) := #formcd#;
            I_PAGE       NUMBER(18)   := #pageno#;
            I_OCRCODE    VARCHAR2(13) := #ocrtag#;
            I_USERID     VARCHAR2(10) := #userid#;
            I_ORDDEPTCD     VARCHAR2(10) := #orddeptcd#;
        begin
          EMR.LCTECH_PROCESS(I_PID, I_IOFLAG, I_ORDDD, I_DSCHDD, I_CRETNO, I_FILESIZE, I_FORMCD, I_PAGE, I_OCRCODE, I_ORDDEPTCD, I_USERID);
        end;
      ]]>
    </insert>

    <insert id="delEformData" parameterClass="System.Collections.Hashtable">
      <![CDATA[ 
        declare
            I_PID              VARCHAR2(10) := #pid#;           /* 등록번호 */
            I_IOFLAG           VARCHAR2(1)  := #ordtype#;       /* 입원/외래 구분 */
            I_ORDDD            VARCHAR2(8)  := #orddd#;         /* 입원일 또는 진료일 */
            I_DSCHDD           VARCHAR2(8)  := #dschdd#;        /* 입원환자 퇴원일 외래환자면 값이 '' */
            I_CRETNO           NUMBER(10)   := #cretno#;        /* 원무정보의 생성번호 */
            I_FORMCD           VARCHAR2(10) := #formcd#;        /* FORMCD */
            I_OCRCODE          VARCHAR2(13) := #ocrtag#;        /* OCRCODE */
            I_USERID           VARCHAR2(10) := #userid#;        /* 사용자 ID 실제 동의서 구득 행위를 하는 사람 */
            I_USERNM           VARCHAR2(10) := #username#;      /* 사용자 이름 */
            I_CONSENT_MST_RID  NUMBER(18)   := #consentmstrid#; /* 동의서 작성 마스터 ID */
            I_HOS_TYPE         VARCHAR2(10) := #hostype#;       /* 병원구분(경북대학교 본원 - '031', 경북대학교 칠곡 - '032') */
            I_ORDDEPTCD        VARCHAR2(10) := #orddeptcd#;
        begin
          EMA.EFORM_DELETE(I_PID, I_IOFLAG, I_ORDDD, I_DSCHDD, I_CRETNO, I_FORMCD, I_OCRCODE, I_USERID, I_USERNM, I_CONSENT_MST_RID, I_ORDDEPTCD, I_HOS_TYPE);
        end;
      ]]>
    </insert>
    <statement id="getFileName" parameterClass="System.Collections.Hashtable" resultClass="System.String">
      <![CDATA[ 
          SELECT substr(c.cdate,1,8)||'\'||to_char(c.pageno) AS filename
          FROM cmr.treatt a, cmr.chartpaget b, cmr.paget c, cmr.patht d
         WHERE a.patid    = #pid#
           and a.TREATNO  =  b.TREATNO        
           and b.ocrcode  = #ocrtag#
           and b.page     = #pageno#
           and b.pageno   = c.pageno
           and d.pathid   = c.pathid
           and d.active   = 'Y'
           ]]>
    </statement>
    <statement id="getFormFromdt" parameterClass="System.Collections.Hashtable" resultClass="System.String">
      <![CDATA[ 
          select a.formfromdt
            from emr.mrfmform a
          where instcd = #instcd#
                and formcd = #formcd#
                and formtodt like '99991231%'
         ]]>
    </statement>

    <update id="UPDATE_USERSETUP" parameterClass="System.Collections.Hashtable">
      <![CDATA[
        MERGE INTO EMA.EFORM_HOSPUSERS HOSP
          USING DUAL ON (HOSP.HOSPUSER_ID = #userId# AND HOSP.HOSPITALCD = #instCd#)
          WHEN MATCHED THEN
              UPDATE
                SET HOSP.HOSPAPPSTATUS = #status#
          WHEN NOT MATCHED THEN
              INSERT (HOSP.HOSPITALCD,
                      HOSP.HOSPAPPSTATUS,
                      HOSP.HOSPUSER_ID)
              VALUES(#instCd#,
                     #status#,
                     #userId#)
      ]]>
    </update>

    <statement id="getHardCodeYN" parameterClass="System.Collections.Hashtable" resultClass="System.String">
      <![CDATA[ 
        SELECT 'Y'
          FROM emr.mnwmcode a
         WHERE a.instcd        = #instcd#
           AND a.cdgrupid      = '399'
           AND SUBSTR(cdid, 3) = #formcd#
           AND ROWNUM          = 1]]>
    </statement>
    <statement id="checkPrintablePatient" parameterClass="System.Collections.Hashtable">
      <![CDATA[
      SELECT COUNT(*)
        FROM PAM.PMOHOTPT OTPT
        WHERE OTPT.INSTCD = #instcd#
            AND PID = #pid#
            AND CRETNO = #cretno#
            AND OTPT.ORDDD LIKE #orddd#
            AND OTPT.HISTSTAT IN ('R', 'T')
            AND OTPT.MEDAMTFREERESN IN ('01', '10')
      ]]>
    </statement>
    <statement id="checkHardcd" parameterClass="System.Collections.Hashtable">
      <![CDATA[
      SELECT COUNT(*)
        FROM EMR.MMBDHRCD A
       WHERE  INSTCD = #instcd#
          AND HARDCDNO = #hardcdno#
          AND TRGTCD = #trgtcd#
          AND TO_CHAR (SYSDATE, 'YYYYMMDD') BETWEEN VALIFROMDD AND VALITODD
      ]]>
    </statement>
  </statements>
</sqlMap>