<?xml version="1.0" encoding="UTF-8"?>
<pipeline>
  <info>
    <name>deferments</name>
    <name_sync_with_filename>Y</name_sync_with_filename>
    <description/>
    <extended_description/>
    <pipeline_version/>
    <pipeline_type>Normal</pipeline_type>
    <parameters>
    </parameters>
    <capture_transform_performance>N</capture_transform_performance>
    <transform_performance_capturing_delay>1000</transform_performance_capturing_delay>
    <transform_performance_capturing_size_limit>100</transform_performance_capturing_size_limit>
    <created_user>-</created_user>
    <created_date>2025/04/20 11:21:19.116</created_date>
    <modified_user>-</modified_user>
    <modified_date>2025/04/20 11:21:19.116</modified_date>
  </info>
  <notepads>
  </notepads>
  <order>
    <hop>
      <from>deferment_right_input</from>
      <to>Insert / update</to>
      <enabled>Y</enabled>
    </hop>
    <hop>
      <from>deferment_input</from>
      <to>Insert / update 2</to>
      <enabled>Y</enabled>
    </hop>
  </order>
  <transform>
    <name>Insert / update</name>
    <type>InsertUpdate</type>
    <description/>
    <distribute>Y</distribute>
    <custom_distribution/>
    <copies>1</copies>
    <partitioning>
      <method>none</method>
      <schema_name/>
    </partitioning>
    <commit>10000</commit>
    <connection>ervu-dashboard</connection>
    <lookup>
      <key>
        <condition>=</condition>
        <field>recruit_id</field>
        <name>recruit_id</name>
      </key>
      <schema>ervu_dashboard</schema>
      <table>citizen_deferment_right</table>
      <value>
        <name>recruit_id</name>
        <rename>recruit_id</rename>
        <update>N</update>
      </value>
      <value>
        <name>start_date</name>
        <rename>start_date</rename>
        <update>Y</update>
      </value>
      <value>
        <name>end_date</name>
        <rename>end_date</rename>
        <update>Y</update>
      </value>
      <value>
        <name>code</name>
        <rename>code</rename>
        <update>Y</update>
      </value>
      <value>
        <name>has_deferment_right</name>
        <rename>has_deferment_right</rename>
        <update>Y</update>
      </value>
    </lookup>
    <update_bypassed>N</update_bypassed>
    <attributes/>
    <GUI>
      <xloc>544</xloc>
      <yloc>208</yloc>
    </GUI>
  </transform>
  <transform>
    <name>Insert / update 2</name>
    <type>InsertUpdate</type>
    <description/>
    <distribute>Y</distribute>
    <custom_distribution/>
    <copies>1</copies>
    <partitioning>
      <method>none</method>
      <schema_name/>
    </partitioning>
    <commit>10000</commit>
    <connection>ervu-dashboard</connection>
    <lookup>
      <key>
        <condition>=</condition>
        <field>recruit_id</field>
        <name>recruit_id</name>
      </key>
      <schema>ervu_dashboard</schema>
      <table>citizen_deferment</table>
      <value>
        <name>recruit_id</name>
        <rename>recruit_id</rename>
        <update>N</update>
      </value>
      <value>
        <name>decision_number</name>
        <rename>decision_number</rename>
        <update>Y</update>
      </value>
      <value>
        <name>deferment_type</name>
        <rename>deferment_type</rename>
        <update>Y</update>
      </value>
      <value>
        <name>start_date</name>
        <rename>start_date</rename>
        <update>Y</update>
      </value>
      <value>
        <name>end_date</name>
        <rename>end_date</rename>
        <update>Y</update>
      </value>
      <value>
        <name>reason_code</name>
        <rename>reason_code</rename>
        <update>Y</update>
      </value>
      <value>
        <name>has_active_deferment</name>
        <rename>has_active_deferment</rename>
        <update>Y</update>
      </value>
      <value>
        <name>has_exemption</name>
        <rename>has_exemption</rename>
        <update>Y</update>
      </value>
      <value>
        <name>active</name>
        <rename>active</rename>
        <update>Y</update>
      </value>
    </lookup>
    <update_bypassed>N</update_bypassed>
    <attributes/>
    <GUI>
      <xloc>544</xloc>
      <yloc>336</yloc>
    </GUI>
  </transform>
  <transform>
    <name>deferment_input</name>
    <type>TableInput</type>
    <description/>
    <distribute>Y</distribute>
    <custom_distribution/>
    <copies>1</copies>
    <partitioning>
      <method>none</method>
      <schema_name/>
    </partitioning>
    <connection>ervu_person_registry</connection>
    <execute_each_row>N</execute_each_row>
    <limit>0</limit>
    <sql>select
    ddd.recruit_id,
    ddd.decision_number,
    ddd.type->>'value' as deferment_type,
    ddd.decision_date as start_date,
    ddd.postponement_date as end_date,
    ddd.base_deferment as reason_code,
    ddd.type->>'code' = '1' as has_active_deferment,
    ddd.type->>'code' = '2' as has_exemption,
    not ddd.hidden as active
from decision_deferment_dto ddd 
         join public.recruits r 
             ON r.id = ddd.recruit_id 
                  AND r.system_update_date >= '${UP_D}'
where hidden is false;</sql>
    <variables_active>Y</variables_active>
    <attributes/>
    <GUI>
      <xloc>272</xloc>
      <yloc>336</yloc>
    </GUI>
  </transform>
  <transform>
    <name>deferment_right_input</name>
    <type>TableInput</type>
    <description/>
    <distribute>Y</distribute>
    <custom_distribution/>
    <copies>1</copies>
    <partitioning>
      <method>none</method>
      <schema_name/>
    </partitioning>
    <connection>ervu_person_registry</connection>
    <execute_each_row>N</execute_each_row>
    <limit>0</limit>
    <sql>select
    rd.recruit_id,
    rd.date_of_information as start_date,
    rd.postponement_date as end_date,
    erfd.code,
    true as has_deferment_right
from recruits_deferment rd
         join ervu_reason_for_deferment erfd
              on erfd.id = rd.ervu_reason_for_deferment_id
         join public.recruits r
              ON r.id = rd.recruit_id
                  AND r.system_update_date >= '${UP_D}'
where rd.hidden is false;</sql>
    <variables_active>Y</variables_active>
    <attributes/>
    <GUI>
      <xloc>272</xloc>
      <yloc>208</yloc>
    </GUI>
  </transform>
  <transform_error_handling>
  </transform_error_handling>
  <attributes/>
</pipeline>
