<?xml version="1.0" encoding="UTF-8"?>
<pipeline>
  <info>
    <name>deferments_once</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>deferment_right_output</to>
      <enabled>Y</enabled>
    </hop>
    <hop>
      <from>deferment_input</from>
      <to>deferment_output</to>
      <enabled>Y</enabled>
    </hop>
    <hop>
      <from>deferment_right_output</from>
      <to>Update</to>
      <enabled>Y</enabled>
    </hop>
    <hop>
      <from>deferment_output</from>
      <to>Update 2</to>
      <enabled>Y</enabled>
    </hop>
    <hop>
      <from>deferment_output</from>
      <to>Dummy (do nothing)</to>
      <enabled>Y</enabled>
    </hop>
  </order>
  <transform>
    <name>Dummy (do nothing)</name>
    <type>Dummy</type>
    <description/>
    <distribute>Y</distribute>
    <custom_distribution/>
    <copies>1</copies>
    <partitioning>
      <method>none</method>
      <schema_name/>
    </partitioning>
    <attributes/>
    <GUI>
      <xloc>768</xloc>
      <yloc>480</yloc>
    </GUI>
  </transform>
  <transform>
    <name>Update</name>
    <type>Update</type>
    <description/>
    <distribute>Y</distribute>
    <custom_distribution/>
    <copies>1</copies>
    <partitioning>
      <method>none</method>
      <schema_name/>
    </partitioning>
    <commit>1000</commit>
    <connection>ervu-dashboard</connection>
    <error_ignored>Y</error_ignored>
    <lookup>
      <key>
        <condition>=</condition>
        <field>recruit_id</field>
        <name>recruit_id</name>
      </key>
      <schema>ervu_dashboard</schema>
      <table>citizen</table>
      <value>
        <name>has_deferment_right</name>
        <rename>has_deferment_right</rename>
      </value>
    </lookup>
    <skip_lookup>N</skip_lookup>
    <use_batch>Y</use_batch>
    <attributes/>
    <GUI>
      <xloc>720</xloc>
      <yloc>208</yloc>
    </GUI>
  </transform>
  <transform>
    <name>Update 2</name>
    <type>Update</type>
    <description/>
    <distribute>Y</distribute>
    <custom_distribution/>
    <copies>1</copies>
    <partitioning>
      <method>none</method>
      <schema_name/>
    </partitioning>
    <commit>1000</commit>
    <connection>ervu-dashboard</connection>
    <error_ignored>Y</error_ignored>
    <lookup>
      <key>
        <condition>=</condition>
        <field>recruit_id</field>
        <name>recruit_id</name>
      </key>
      <schema>ervu_dashboard</schema>
      <table>citizen</table>
      <value>
        <name>has_deferment</name>
        <rename>has_active_deferment</rename>
      </value>
      <value>
        <name>has_exemption</name>
        <rename>has_exemption</rename>
      </value>
    </lookup>
    <skip_lookup>N</skip_lookup>
    <use_batch>Y</use_batch>
    <attributes/>
    <GUI>
      <xloc>768</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 '${RCRT_C}' IN (r.target_recruitment_id, r.current_recruitment_id)
where hidden is false;</sql>
    <variables_active>Y</variables_active>
    <attributes/>
    <GUI>
      <xloc>272</xloc>
      <yloc>336</yloc>
    </GUI>
  </transform>
  <transform>
    <name>deferment_output</name>
    <type>TableOutput</type>
    <description/>
    <distribute>Y</distribute>
    <custom_distribution/>
    <copies>1</copies>
    <partitioning>
      <method>none</method>
      <schema_name/>
    </partitioning>
    <commit>1000</commit>
    <connection>ervu-dashboard</connection>
    <fields>
      <field>
        <column_name>recruit_id</column_name>
        <stream_name>recruit_id</stream_name>
      </field>
      <field>
        <column_name>decision_number</column_name>
        <stream_name>decision_number</stream_name>
      </field>
      <field>
        <column_name>type</column_name>
        <stream_name>deferment_type</stream_name>
      </field>
      <field>
        <column_name>start_date</column_name>
        <stream_name>start_date</stream_name>
      </field>
      <field>
        <column_name>end_date</column_name>
        <stream_name>end_date</stream_name>
      </field>
      <field>
        <column_name>reason_code</column_name>
        <stream_name>reason_code</stream_name>
      </field>
      <field>
        <column_name>active</column_name>
        <stream_name>active</stream_name>
      </field>
    </fields>
    <ignore_errors>N</ignore_errors>
    <only_when_have_rows>N</only_when_have_rows>
    <partitioning_daily>N</partitioning_daily>
    <partitioning_enabled>N</partitioning_enabled>
    <partitioning_monthly>Y</partitioning_monthly>
    <return_keys>N</return_keys>
    <schema>ervu_dashboard</schema>
    <specify_fields>Y</specify_fields>
    <table>citizen_deferment</table>
    <tablename_in_field>N</tablename_in_field>
    <tablename_in_table>Y</tablename_in_table>
    <truncate>N</truncate>
    <use_batch>Y</use_batch>
    <attributes/>
    <GUI>
      <xloc>544</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 '${RCRT_C}' IN (r.target_recruitment_id, r.current_recruitment_id)
where rd.hidden is false;</sql>
    <variables_active>Y</variables_active>
    <attributes/>
    <GUI>
      <xloc>272</xloc>
      <yloc>208</yloc>
    </GUI>
  </transform>
  <transform>
    <name>deferment_right_output</name>
    <type>TableOutput</type>
    <description/>
    <distribute>Y</distribute>
    <custom_distribution/>
    <copies>1</copies>
    <partitioning>
      <method>none</method>
      <schema_name/>
    </partitioning>
    <commit>1000</commit>
    <connection>ervu-dashboard</connection>
    <fields>
      <field>
        <column_name>recruit_id</column_name>
        <stream_name>recruit_id</stream_name>
      </field>
      <field>
        <column_name>start_date</column_name>
        <stream_name>start_date</stream_name>
      </field>
      <field>
        <column_name>end_date</column_name>
        <stream_name>end_date</stream_name>
      </field>
      <field>
        <column_name>code</column_name>
        <stream_name>code</stream_name>
      </field>
      <field>
        <column_name>actual</column_name>
        <stream_name>has_deferment_right</stream_name>
      </field>
    </fields>
    <ignore_errors>N</ignore_errors>
    <only_when_have_rows>N</only_when_have_rows>
    <partitioning_daily>N</partitioning_daily>
    <partitioning_enabled>N</partitioning_enabled>
    <partitioning_monthly>Y</partitioning_monthly>
    <return_keys>N</return_keys>
    <schema>ervu_dashboard</schema>
    <specify_fields>Y</specify_fields>
    <table>citizen_deferment_right</table>
    <tablename_in_field>N</tablename_in_field>
    <tablename_in_table>Y</tablename_in_table>
    <truncate>N</truncate>
    <use_batch>Y</use_batch>
    <attributes/>
    <GUI>
      <xloc>544</xloc>
      <yloc>208</yloc>
    </GUI>
  </transform>
  <transform_error_handling>
    <error>
      <source_transform>deferment_output</source_transform>
      <target_transform>Dummy (do nothing)</target_transform>
      <is_enabled>Y</is_enabled>
      <nr_valuename/>
      <descriptions_valuename/>
      <fields_valuename/>
      <codes_valuename/>
      <max_errors/>
      <max_pct_errors/>
      <min_pct_rows/>
    </error>
  </transform_error_handling>
  <attributes/>
</pipeline>
