<?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>
    <!--insert id="INSERT_CONSENT_MST" parameterClass="System.Collections.Hashtable">
      <![CDATA[
        insert into CONSENT_MST
        (
          CONSENT_MST_RID,
          HOS_TYPE, 
          PID,
          VISIT_TYPE,
          OCR_NUMBER,
          CLN_DEPT_CD,
          CLN_DATE,
          CRETNO,
          WARDCD,
          ROOMCD,
          FORM_RID,
          CONSENT_STATE,
          COMPLETE_YN,
          COMPLETE_DATETIME,
          PAPER_YN,
          REISSUE_YN,
          REISSUE_CONSENT_MST_RID,
          REWRITE_YN,
          REWRITE_CONSENT_MST_RID,
          USE_YN,
          MAIN_DR_ID,
          CREATE_USER_ID,
          CREATE_DATETIME,
          MODIFY_USER_ID,
          MODIFY_DATETIME,
          CREATE_USER_NAME,
          MODIFY_USER_NAME,
          oprsrvno
        )
        values
        (
          #consentMstRid#,
          #hosType#,
          #patientCode#,
          #vistType#,
          #ocrCode#,
          #clnDeptCd#,
          #clnDate#,
          #cretno#,
          #ward#,
          #roomcd#,
          #formRid#,
          #consentState#,
          #completeYn#,
          $completeDateTimeToChars$,
          #paperYn#,
          #reissueYn#,
          #reissueConsentMstRid#,
          #rewriteYn#,
          #rewriteConsentMstRid#,
          'Y',
          #mainDrId#,
          #userId#,
          TO_CHAR(SYSDATE,'yyyy-mm-dd hh24:mi:ss'),
          #userId#,
          TO_CHAR(SYSDATE,'yyyy-mm-dd hh24:mi:ss'),
          #createUserName#,
          #modifyUserName#,
          #opRsrvNo#
        )
      ]]>
    </insert-->
    
    <insert id="INSERT_CONSENT_DATA" parameterClass="System.Collections.Hashtable">
      <![CDATA[
        insert into CONSENT_DATA
        (
          CONSENT_DATA_RID,
          CONSENT_MST_RID,
          FORM_RID,
          DEVICE_TYPE,
          DEVICE_IDENT_NO,
          COMPLETE_YN,
          CREATE_USER_ID,
          CREATE_DATETIME,
          FORM_XML,
          DATA_XML
        )
        values
        (
          #consentDataRid#,
          #consentMstRid#,
          #formRid#,
          #deviceType#,
          #deviceIdentNo#,
          #completeYn#,
          #userId#,
          TO_CHAR(SYSDATE,'yyyy-mm-dd hh24:mi:ss'),
          #formXml#,
          #dataXml#
        )
      ]]>
    </insert>
    
    <!-- 2019.01.07 수정본 -->
    <!-- insert id="INSERT_CONSENT_MST" parameterClass="System.Collections.Hashtable">
      <![CDATA[
        MERGE INTO CONSENT_MST
        USING DUAL ON (CONSENT_MST_RID = #consentMstRid# AND PID = #patientCode# AND HOS_TYPE = #hosType#)
         WHEN MATCHED THEN
              SELECT CONSENT_MST_RID
                FROM CONSENT_MST
               WHERE CONSENT_MST_RID = #consentMstRid#
         WHEN NOT MATCHED THEN
              insert
              (
               CONSENT_MST_RID,
               HOS_TYPE, 
               PID,
               VISIT_TYPE,
               OCR_NUMBER,
               CLN_DEPT_CD,
               CLN_DATE,
               CRETNO,
               WARDCD,
               ROOMCD,
               FORM_RID,
               CONSENT_STATE,
               COMPLETE_YN,
               COMPLETE_DATETIME,
               PAPER_YN,
               REISSUE_YN,
               REISSUE_CONSENT_MST_RID,
               REWRITE_YN,
               REWRITE_CONSENT_MST_RID,
               USE_YN,
               MAIN_DR_ID,
               CREATE_USER_ID,
               CREATE_DATETIME,
               MODIFY_USER_ID,
               MODIFY_DATETIME,
               CREATE_USER_NAME,
               MODIFY_USER_NAME,
               oprsrvno
              )
              values
              (
               #consentMstRid#,
               #hosType#,
               #patientCode#,
               #vistType#,
               #ocrCode#,
               #clnDeptCd#,
               #clnDate#,
               #cretno#,
               #ward#,
               #roomcd#,
               #formRid#,
               #consentState#,
               #completeYn#,
               $completeDateTimeToChars$,
               #paperYn#,
               #reissueYn#,
               #reissueConsentMstRid#,
               #rewriteYn#,
               #rewriteConsentMstRid#,
               'Y',
               #mainDrId#,
               #userId#,
               TO_CHAR(SYSDATE,'yyyy-mm-dd hh24:mi:ss'),
               #userId#,
               TO_CHAR(SYSDATE,'yyyy-mm-dd hh24:mi:ss'),
               #createUserName#,
               #modifyUserName#,
               #opRsrvNo#
              )
      ]]>
    </insert -->

    <insert id="INSERT_CONSENT_MST" parameterClass="System.Collections.Hashtable">
      <![CDATA[
        MERGE INTO CONSENT_MST
        USING DUAL ON (CONSENT_MST_RID = #consentMstRid# AND PID = #patientCode# AND HOS_TYPE = #hosType#)
         WHEN NOT MATCHED THEN
              insert
              (
               CONSENT_MST_RID,
               HOS_TYPE, 
               PID,
               VISIT_TYPE,
               OCR_NUMBER,
               CLN_DEPT_CD,
               CLN_DATE,
               CRETNO,
               WARDCD,
               ROOMCD,
               FORM_RID,
               CONSENT_STATE,
               COMPLETE_YN,
               COMPLETE_DATETIME,
               PAPER_YN,
               REISSUE_YN,
               REISSUE_CONSENT_MST_RID,
               REWRITE_YN,
               REWRITE_CONSENT_MST_RID,
               USE_YN,
               MAIN_DR_ID,
               CREATE_USER_ID,
               CREATE_DATETIME,
               MODIFY_USER_ID,
               MODIFY_DATETIME,
               CREATE_USER_NAME,
               MODIFY_USER_NAME,
               oprsrvno
              )
              values
              (
               #consentMstRid#,
               #hosType#,
               #patientCode#,
               #vistType#,
               #ocrCode#,
               #clnDeptCd#,
               #clnDate#,
               #cretno#,
               #ward#,
               #roomcd#,
               #formRid#,
               #consentState#,
               #completeYn#,
               $completeDateTimeToChars$,
               #paperYn#,
               #reissueYn#,
               #reissueConsentMstRid#,
               #rewriteYn#,
               #rewriteConsentMstRid#,
               'Y',
               #mainDrId#,
               #userId#,
               TO_CHAR(SYSDATE,'yyyy-mm-dd hh24:mi:ss'),
               #userId#,
               TO_CHAR(SYSDATE,'yyyy-mm-dd hh24:mi:ss'),
               #createUserName#,
               #modifyUserName#,
               #opRsrvNo#
              )
      ]]>
    </insert>
    
    <insert id="INSERT_CONSENT_IMAGE" parameterClass="System.Collections.Hashtable">
      <![CDATA[
        insert into CONSENT_IMAGE
        (
          CONSENT_Image_RID,
          CONSENT_MST_RID,
          FORM_RID,
          IMAGE_PATH,
          IMAGE_FILENAME,
          COMPLETE_YN,
          CREATE_USER_ID,
          CREATE_DATETIME
        )
        values
        (
          #consentImageRid#,
          #consentMstRid#,
          #formRid#,
          #imagePath#,
          #imageFilename#,
          #completeYn#,
          #userId#,
          TO_CHAR(SYSDATE,'yyyy-mm-dd hh24:mi:ss')
        )
      ]]>
    </insert>
    <!--
    <insert id="INSERT_CONSENT_IMAGE_SIGN" parameterClass="System.Collections.Hashtable">
      <![CDATA[
        insert into CONSENT_IMAGE_SIGN
        (
          CONSENT_MST_RID,
          CONSENT_IMAGE_RID,
          CERT_TARGET,
          CERT_RESULT,
          CERT_STATUS,
          CREATE_USER_ID,
          CREATE_DATETIME,
          MODIFY_USER_ID,
          MODIFY_DATETIME
        )
        values
        (
          #consentMstRid#,
          #consentImageRid#,
          #certTarget#,
          #certResult#,
          DECODE( #certResult#, '', 'N', 'Y'),
          #userId#,
          TO_CHAR(SYSDATE,'yyyy-mm-dd hh24:mi:ss'),
           #userId#,
          TO_CHAR(SYSDATE,'yyyy-mm-dd hh24:mi:ss')
        )
      ]]>
    </insert>
    -->
    <insert id="INSERT_CONSENT_IMAGE_SIGN" parameterClass="System.Collections.Hashtable">
      <![CDATA[
        DECLARE
        
        v_cnt NUMBER:=0;
        
        BEGIN

          SELECT  COUNT(*) INTO V_CNT
            FROM  CONSENT_IMAGE_SIGN
           WHERE  CONSENT_MST_RID = #consentMstRid# 
             AND  CONSENT_IMAGE_RID = #consentImageRid#;

          IF v_cnt = 0 THEN

            insert into CONSENT_IMAGE_SIGN
            (
              CONSENT_MST_RID,
              CONSENT_IMAGE_RID,
              CERT_TARGET,
              CERT_RESULT,
              CERT_STATUS,
              CREATE_USER_ID,
              CREATE_DATETIME,
              MODIFY_USER_ID,
              MODIFY_DATETIME
            )
            values
            (
              #consentMstRid#,
              #consentImageRid#,
              #certTarget#,
              #certResult#,
              DECODE( #certResult#, '', 'N', 'Y'),
              #userId#,
              TO_CHAR(SYSDATE,'yyyy-mm-dd hh24:mi:ss'),
               #userId#,
              TO_CHAR(SYSDATE,'yyyy-mm-dd hh24:mi:ss')
            );

          ELSE
            
            update CONSENT_IMAGE_SIGN
               set CERT_RESULT = #certResult#,
                   CERT_STATUS = DECODE( #certResult#, '', 'N', 'Y'),
                   MODIFY_USER_ID = #userId#,
                   MODIFY_DATETIME = TO_CHAR(SYSDATE,'yyyy-mm-dd hh24:mi:ss')
            WHERE  CONSENT_MST_RID = #consentMstRid# 
              AND  CONSENT_IMAGE_RID = #consentImageRid#;

          END IF;

        END;
      ]]>
    </insert>
    <insert id="UPDATE_CONSENT_MST" parameterClass="System.Collections.Hashtable">
      <![CDATA[
        UPDATE  CONSENT_MST SET
                CONSENT_STATE = #consentState#,
                COMPLETE_YN = #completeYn#,
                COMPLETE_DATETIME = $completeDateTimeToChars$,
                PAPER_YN = #paperYn#,
                MODIFY_USER_ID = #userId#,
                MODIFY_DATETIME = TO_CHAR(SYSDATE,'yyyy-mm-dd hh24:mi:ss'),
                MODIFY_USER_NAME = COM.FN_ZS_GETUSERNM(#userId#, TO_CHAR(SYSDATE, 'YYYYMMDD'))
         WHERE  CONSENT_MST_RID = #consentMstRid#
      ]]>
    </insert>
    <insert id="UPDATE_CONSENT_MST_STATUS" parameterClass="System.Collections.Hashtable">
      <![CDATA[
        UPDATE  CONSENT_MST SET
                CONSENT_STATE = #consentState#,
                MODIFY_USER_ID = #userId#,
                MODIFY_DATETIME = TO_CHAR(SYSDATE,'yyyy-mm-dd hh24:mi:ss'),
                MODIFY_USER_NAME = COM.FN_ZS_GETUSERNM(#userId#, TO_CHAR(SYSDATE, 'YYYYMMDD'))
         WHERE  CONSENT_MST_RID = #consentMstRid#
      ]]>
    </insert>
    <insert id="UPDATE_CONSENT_MST_FOR_REISSUE" parameterClass="System.Collections.Hashtable">
      <![CDATA[
        UPDATE CONSENT_MST 
           SET MODIFY_USER_ID = #userId#,
               MODIFY_DATETIME = TO_CHAR(SYSDATE,'yyyy-mm-dd hh24:mi:ss'),
               REISSUE_YN = 'Y',
               MODIFY_USER_NAME = COM.FN_ZS_GETUSERNM(#userId#, TO_CHAR(SYSDATE, 'YYYYMMDD'))
         WHERE CONSENT_MST_RID = #consentMstRid#
      ]]>
    </insert>
    <update id="UPDATE_CONSENT_MST_FOR_DELETE" parameterClass="System.Collections.Hashtable">
      <![CDATA[
        UPDATE CONSENT_MST
           SET MODIFY_USER_ID = #userId#,
               MODIFY_DATETIME = TO_CHAR(SYSDATE,'yyyy-mm-dd hh24:mi:ss'),
               USE_YN = 'N',
               REASON_FOR_USE_N = #reasonForUseN#,
               MODIFY_USER_NAME = COM.FN_ZS_GETUSERNM(#userId#, TO_CHAR(SYSDATE, 'YYYYMMDD'))
         WHERE CONSENT_MST_RID = #consentMstRid#
      ]]>
    </update>

    <delete id="DELETE_CHARTPAGET" parameterClass="System.Collections.Hashtable">
      <![CDATA[
        DELETE CMR.CHARTPAGET WHERE OCRCODE = #ocrTag#
      ]]>
    </delete>
    
    <insert id="SET_MEDI_HISTORY" parameterClass="System.Collections.Hashtable">
      <![CDATA[
        DECLARE
        
        v_cnt NUMBER:=0;
        
        BEGIN

          SELECT  COUNT(*) INTO V_CNT
            FROM  CONSENT_DATA_EX
           WHERE  PID = #patientCode# 
             AND  CLN_DATE = #clnDate#;

          IF v_cnt = 0 THEN

            insert into consent_data_ex
              (pid, cln_date, use_yn, bp, dm, heart, kidney, respiration, hx, allergy, drug, smoking, idio, nacrotics, airway, hemorrhage, etc, create_user_id, create_datetime, modify_user_id, modify_datetime)
            values
              (#patientCode#, #clnDate#,'Y', #bp#, #dm#, #heart#, #kidney#, #respiration#, #hx#, #allergy#, #drug#, #smoking#, #idio#, #nacrotics#, #airway#, #hemorrhage#, #status_etc#, #userId#, TO_CHAR(SYSDATE,'yyyy-mm-dd hh24:mi:ss'), #userId#, TO_CHAR(SYSDATE,'yyyy-mm-dd hh24:mi:ss'));
           

          ELSE
            
            update consent_data_ex
                set bp = #bp#,
                    dm = #dm#,
                    heart = #heart#,
                    kidney = #kidney#,
                    respiration = #respiration#,
                    hx = #hx#,
                    allergy = #allergy#,
                    drug = #drug#,
                    smoking = #smoking#,
                    idio = #idio#,
                    nacrotics = #nacrotics#,
                    airway = #airway#,
                    hemorrhage = #hemorrhage#,
                    etc = #status_etc#,
                    modify_user_id = #userId#,
                    modify_datetime = TO_CHAR(SYSDATE,'yyyy-mm-dd hh24:mi:ss')
              where PID = #patientCode# 
               AND  CLN_DATE = #clnDate# ;

          END IF;

        END;
      ]]>
    </insert>

    <statement id="getOcrPrntHistYN" parameterClass="System.Collections.Hashtable" resultClass="System.String">
      <![CDATA[
        SELECT MIN(histyn)
          FROM ( SELECT NVL(MIN(ocrtagprntyn), 'N')    AS histyn
                   FROM ema.v_eform_formdoc
                  WHERE form_cd = #formcd#
                  UNION ALL
                 SELECT CASE WHEN #actkind# IN ('T', 'P')
                              AND NVL(statcd, '-') = DECODE(#actkind#, 'T', 'P', #actkind#)
                              AND NVL(scanyn, '-') = DECODE(#actkind#, 'C', 'Y', 'N') THEN
                                  'N'
                             ELSE 'Y'
                         END                           AS histyn
                   FROM emr.mrfhocrprnt a
                  WHERE instcd = #instcd#
                    AND ocrtag = #ocrtag#
               )
      ]]>
    </statement>

    <insert id="setOcrPrntInfo" parameterClass="System.Collections.Hashtable">
      <![CDATA[
        MERGE INTO emr.mrfmocrprnt
              USING DUAL ON ( instcd = #instcd#
                          AND ocrtag = #ocrtag# )
        WHEN MATCHED THEN
             UPDATE
                SET eocryn      = DECODE(#actkind#, 'P', 'N', 'Y')
                  , updtdt      = #updtdt#
                  , updtdeptcd  = #fstprntdeptcd#
                  , updtuserid  = #fstprntid#
                  , lastupdtrid = #fstprntid#
                  , lastupdtdt  = SYSTIMESTAMP
        WHEN NOT MATCHED THEN
           INSERT ( instcd
                  , ocrtag
                  , pid
                  , ordtype
                  , orddd
                  , cretno
                  , orddrid
                  , orddeptcd
                  , formcd
                  , formfromdt
                  , diagnm
                  , opnm
                  , fstprntdt
                  , fstprntdeptcd
                  , fstprntid
                  , updtdt
                  , updtdeptcd
                  , updtuserid
                  , fstrgstrid
                  , fstrgstdt
                  , lastupdtrid
                  , lastupdtdt
                  , rcpdd
                  , prcpno
                  , prcphistno
                  , execprcpno
                  , eocryn
                  , realprntyn
                  , inputflag
                  , verflag )
           VALUES ( #instcd#
                  , #ocrtag#
                  , #pid#
                  , #ordtype#
                  , #orddd#
                  , #cretno#
                  , #orddrid#
                  , #orddeptcd#
                  , #formcd#
                  , ( SELECT MAX(a.formfromdt)
                        FROM emr.mrfmform a
                       WHERE instcd   =       #instcd#
                         AND formcd   =       #formcd#
                         AND #updtdt# BETWEEN formfromdt AND formtodt )
                  , ''
                  , ''
                  , #updtdt#
                  , #fstprntdeptcd#
                  , #fstprntid#
                  , #updtdt#
                  , #fstprntdeptcd#
                  , #fstprntid#
                  , #fstprntid#
                  , SYSTIMESTAMP
                  , #fstprntid#
                  , SYSTIMESTAMP
                  , ''
                  , ''
                  , ''
                  , ''
                  , DECODE(#actkind#, 'P', 'N', 'Y')
                  , ''
                  , #clienttype#
                  , 'L' )]]>
    </insert>

    <insert id="setOcrPrntHistInfo" parameterClass="System.Collections.Hashtable">
      <![CDATA[ 
        INSERT INTO emr.mrfhocrprnt
                  ( instcd
                  , ocrtag
                  , updtdt
                  , updtuserid
                  , statcd
                  , updtresncnts
                  , updtdeptcd
                  , scanyn
                  , pagecnt
                  , scanpagecnt
                  , fstrgstrid
                  , fstrgstdt
                  , lastupdtrid
                  , lastupdtdt
                  , ENDYN)
           VALUES ( #instcd#
                  , #ocrtag#
                  , #updtdt#
                  , #fstprntid#
                  , DECODE(#actkind#, 'T', 'P', #actkind#)
                  , #updtresncnts#
                  , #fstprntdeptcd#
                  , DECODE(#actkind#, 'C', 'Y', 'N')
                  , CASE WHEN TO_NUMBER(#pagecnt#) < 0 THEN
                              ( SELECT COUNT(1)
                                  FROM emr.mrfmocr  a
                                     , emr.mrfmform b
                                 WHERE a.formcd     =       #formcd#
                                   AND b.instcd     =       a.instcd
                                   AND b.formcd     =       a.formcd
                                   AND b.formfromdt =       a.formfromdt
                                   AND #updtdt#     BETWEEN b.formfromdt AND b.formtodt
                              )
                         ELSE TO_NUMBER(#pagecnt#)
                     END
                  , DECODE(#actkind#, 'P', 0
                                    ,  CASE WHEN TO_NUMBER(#pagecnt#) < 0 THEN
                                                 ( SELECT COUNT(1)
                                                    FROM emr.mrfmocr  a
                                                       , emr.mrfmform b
                                                   WHERE a.formcd     =       #formcd#
                                                     AND b.instcd     =       a.instcd
                                                     AND b.formcd     =       a.formcd
                                                     AND b.formfromdt =       a.formfromdt
                                                     AND #updtdt#     BETWEEN b.formfromdt AND b.formtodt
                                                )
                                           ELSE TO_NUMBER(#pagecnt#)
                                        END)
                  , #fstprntid#
                  , SYSTIMESTAMP
                  , #fstprntid#
                  , SYSTIMESTAMP
                  , #endYn#)
      ]]>
    </insert>

    <!-- insert id="setOcrPrntHistInfo" parameterClass="System.Collections.Hashtable">
      <![CDATA[
        MERGE INTO emr.mrfhocrprnt
        USING DUAL ON (INSTCD = #instcd# AND OCRTAG = #ocrtag#)
         WHEN NOT MATCHED THEN
              INSERT ( instcd
                       , ocrtag
                       , updtdt
                       , updtuserid
                       , statcd
                       , updtresncnts
                       , updtdeptcd
                       , scanyn
                       , pagecnt
                       , scanpagecnt
                       , fstrgstrid
                       , fstrgstdt
                       , lastupdtrid
                       , lastupdtdt )
              VALUES ( #instcd#
                       , #ocrtag#
                       , #updtdt#
                       , #fstprntid#
                       , DECODE(#actkind#, 'T', 'P', #actkind#)
                       , #updtresncnts#
                       , #fstprntdeptcd#
                       , DECODE(#actkind#, 'C', 'Y', 'N')
                       , CASE WHEN TO_NUMBER(#pagecnt#) < 0 THEN
                                   ( SELECT COUNT(1)
                                       FROM emr.mrfmocr  a
                                          , emr.mrfmform b
                                      WHERE a.formcd     =       #formcd#
                                        AND b.instcd     =       a.instcd
                                        AND b.formcd     =       a.formcd
                                        AND b.formfromdt =       a.formfromdt
                                        AND #updtdt#     BETWEEN b.formfromdt AND b.formtodt
                                   )
                              ELSE TO_NUMBER(#pagecnt#)
                          END
                       , DECODE(#actkind#, 'P', 0
                                         ,  CASE WHEN TO_NUMBER(#pagecnt#) < 0 THEN
                                                      ( SELECT COUNT(1)
                                                          FROM emr.mrfmocr  a
                                                               , emr.mrfmform b
                                                         WHERE a.formcd     =       #formcd#
                                                           AND b.instcd     =       a.instcd
                                                           AND b.formcd     =       a.formcd
                                                           AND b.formfromdt =       a.formfromdt
                                                           AND #updtdt#     BETWEEN b.formfromdt AND b.formtodt
                                                       )
                                                 ELSE TO_NUMBER(#pagecnt#)
                                              END)
                       , #fstprntid#
                       , SYSTIMESTAMP
                       , #fstprntid#
                       , SYSTIMESTAMP )
      ]]>
    </insert -->

    <!-- 선택 진료 신청 정보 -->
    <insert id="insPmcmspif" parameterClass="System.Collections.Hashtable">
      <![CDATA[
        INSERT INTO pam.pmcmspif
                  ( pid
                  , signflag
                  , ocrtag
                  , seqno
                  , instcd
                  , orddd
                  , cretno
                  , ioflag
                  , msflag
                  , orddeptkind
                  , histstat
                  , fromdd
                  , todd
                  , orddeptcd
                  , orddrid
                  , specordyn
                  , choiflag
                  , specdeptcd
                  , specdrid
                  , appdd
                  , returnyn
                  , returnrid
                  , returntm
                  , remfact
                  , elctappsignkey
                  , elctappsigncnts
                  , elctapprelakey
                  , elctapprelacnts
                  , fstrgstrid
                  , fstrgstdt
                  , lastupdtrid
                  , lastupdtdt
                  , etcflag )
           VALUES ( #pid#
                  , 'S'
                  , #ocrtag#
                  , ( SELECT COALESCE(MAX(seqno), 0) + 1
                        FROM pam.pmcmspif
                       WHERE instcd   = #instcd#
                         AND pid      = #pid#
                         AND signflag = 'S'
                         AND ocrtag   = #ocrtag#
                    )
                  , #instcd#
                  , #orddd#
                  , #cretno#
                  , #ordtype#
                  , #msflag#
                  , #orddeptkind#
                  , 'Y'
                  , #orddd#
                  , '99991231'
                  , #orddeptcd#
                  , #orddrid#
                  , #specordyn#
                  , 'B'
                  , '-'
                  , #specdrid#
                  , TO_CHAR(SYSDATE, 'YYYYMMDD')
                  , 'Y'
                  , #userid#
                  , TO_CHAR(SYSDATE, 'YY/MM/DD HH24:MI')
                  , '전자동의서'
                  , ''
                  , ''
                  , ''
                  , ''
                  , #userid#
                  , SYSTIMESTAMP
                  , #userid#
                  , SYSTIMESTAMP
                  , '' )]]>
    </insert>

    <!-- 입원 약정서 정보 -->
    <insert id="insPmihagmt" parameterClass="System.Collections.Hashtable">
      <![CDATA[
        INSERT INTO pam.pmihagmt
                  ( instcd
                  , pid
                  , ocrtagno
                  , fromdd
                  , seqno
                  , todd
                  , agmttype
                  , rsrvyn
                  , rmk
                  , histstat
                  , fstrgstrid
                  , fstrgstdt
                  , lastupdtrid
                  , lastupdtdt
                  , ocrtype )
           VALUES ( #instcd#
                  , #pid#
                  , #ocrtag#
                  , #contfromdd#
                  , NVL(( SELECT MAX(seqno)
                            FROM pam.pmihagmt
                           WHERE instcd   = #instcd#
                             AND pid      = #pid#
                             AND fromdd   = #contfromdd#
                             AND agmttype = #agmttype#), 0) + 1
                  , #conttodd#
                  , #agmttype#
                  , 'N'
                  , '전자서명'
                  , 'Y'
                  , #userid#
                  , SYSTIMESTAMP
                  , #userid#
                  , SYSTIMESTAMP
                  , 'S' )]]>
    </insert>

    <!-- 개인 정보 이용 동의서 정보 -->
    <insert id="insPmcminfo" parameterClass="System.Collections.Hashtable">
      <![CDATA[
        INSERT INTO pam.pmcminfo
                  ( instcd
                  , pid
                  , ocrtag
                  , formcd
                  , histstat
                  , fromdd
                  , todd
                  , chkitem
                  , chkvalue
                  , fstrgstrid
                  , fstrgstdt
                  , lastupdtrid
                  , lastupdtdt )
           VALUES ( #instcd#
                  , #pid#
                  , #ocrtag#
                  , #formcd#
                  , 'Y'
                  , TO_CHAR(SYSDATE, 'YYYYMMDD')
                  , '99991231'
                  , #chkitem#
                  , #chkvalue#
                  , #userid#
                  , SYSTIMESTAMP
                  , #userid#
                  , SYSTIMESTAMP )]]>
    </insert>
    <statement id="getOcrType6Forms" parameterClass="System.Collections.Hashtable" resultClass="System.String">
      <![CDATA[ 
        select FORMCD
          from emr.mrfmform
          where FORMPROGFLAG like 'OCR%'
            AND  FORMTYPECLS = '6'
            AND  instcd = #instcd#
            and  formtodt like '9999%']]>
    </statement>
  </statements>
</sqlMap>