<?xml version="1.0" encoding="UTF-8"?>
<pipeline>
  <info>
    <name>citizen_flags</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/22 16:26:01.929</created_date>
    <modified_user>-</modified_user>
    <modified_date>2025/04/22 16:26:01.929</modified_date>
  </info>
  <notepads>
  </notepads>
  <order>
    <hop>
      <from>children_flags</from>
      <to>Update_children_flags</to>
      <enabled>Y</enabled>
    </hop>
    <hop>
      <from>opekun_flag</from>
      <to>Update_opekun_flag</to>
      <enabled>Y</enabled>
    </hop>
    <hop>
      <from>driver_licence_output</from>
      <to>Update_driver_licence_flag</to>
      <enabled>Y</enabled>
    </hop>
    <hop>
      <from>citizenship_flag_output</from>
      <to>Update_citizenship_flag</to>
      <enabled>Y</enabled>
    </hop>
    <hop>
      <from>property_flag_output</from>
      <to>Update_property_flag</to>
      <enabled>Y</enabled>
    </hop>
    <hop>
      <from>deputy_input</from>
      <to>Update_deputy_flag</to>
      <enabled>Y</enabled>
    </hop>
    <hop>
      <from>has_criminal_prosecution</from>
      <to>Update_has_criminal_prosecution</to>
      <enabled>Y</enabled>
    </hop>
    <hop>
      <from>criminal_record</from>
      <to>Update_criminal_record</to>
      <enabled>Y</enabled>
    </hop>
  </order>
  <transform>
    <name>Update_children_flags</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_dead_child</name>
        <rename>has_dead_child</rename>
      </value>
      <value>
        <name>has_minor_child</name>
        <rename>has_minor_child</rename>
      </value>
      <value>
        <name>minors_count</name>
        <rename>minors</rename>
      </value>
    </lookup>
    <skip_lookup>N</skip_lookup>
    <use_batch>Y</use_batch>
    <attributes/>
    <GUI>
      <xloc>384</xloc>
      <yloc>304</yloc>
    </GUI>
  </transform>
  <transform>
    <name>Update_citizenship_flag</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_russian_citizenship</name>
        <rename>has_russian_citizenship</rename>
      </value>
      <value>
        <name>has_foreign_citizenship</name>
        <rename>has_foreign_citizenship</rename>
      </value>
    </lookup>
    <skip_lookup>N</skip_lookup>
    <use_batch>Y</use_batch>
    <attributes/>
    <GUI>
      <xloc>384</xloc>
      <yloc>672</yloc>
    </GUI>
  </transform>
  <transform>
    <name>Update_deputy_flag</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>is_deputy</name>
        <rename>is_deputy</rename>
      </value>
      <value>
        <name>is_deputy_candidate</name>
        <rename>is_deputy_candidate</rename>
      </value>
    </lookup>
    <skip_lookup>N</skip_lookup>
    <use_batch>Y</use_batch>
    <attributes/>
    <GUI>
      <xloc>384</xloc>
      <yloc>912</yloc>
    </GUI>
  </transform>
  <transform>
    <name>Update_driver_licence_flag</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>tractor_license</name>
        <rename>has_tractor_licence</rename>
      </value>
      <value>
        <name>has_driver_license</name>
        <rename>has_driver_license</rename>
      </value>
    </lookup>
    <skip_lookup>N</skip_lookup>
    <use_batch>Y</use_batch>
    <attributes/>
    <GUI>
      <xloc>384</xloc>
      <yloc>560</yloc>
    </GUI>
  </transform>
  <transform>
    <name>Update_opekun_flag</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>is_guardian</name>
        <rename>is_guardian</rename>
      </value>
    </lookup>
    <skip_lookup>N</skip_lookup>
    <use_batch>Y</use_batch>
    <attributes/>
    <GUI>
      <xloc>384</xloc>
      <yloc>432</yloc>
    </GUI>
  </transform>
  <transform>
    <name>Update_property_flag</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_ground_transport</name>
        <rename>has_ground_transport</rename>
      </value>
      <value>
        <name>has_air_transport</name>
        <rename>has_air_transport</rename>
      </value>
      <value>
        <name>has_water_transport</name>
        <rename>has_water_transport</rename>
      </value>
      <value>
        <name>has_property</name>
        <rename>has_property</rename>
      </value>
    </lookup>
    <skip_lookup>N</skip_lookup>
    <use_batch>Y</use_batch>
    <attributes/>
    <GUI>
      <xloc>384</xloc>
      <yloc>800</yloc>
    </GUI>
  </transform>
  <transform>
    <name>children_flags</name>
    <type>TableInput</type>
    <description/>
    <distribute>Y</distribute>
    <custom_distribution/>
    <copies>1</copies>
    <partitioning>
      <method>none</method>
      <schema_name/>
    </partitioning>
    <connection>ervu-dashboard</connection>
    <execute_each_row>N</execute_each_row>
    <limit>0</limit>
    <sql>WITH age_threshold AS (
    SELECT current_date - interval '18 years' AS cutoff
)
select
    recruit_id,                                                                                                                                                                                                 
    COUNT(*) FILTER (WHERE birth_date > cutoff) AS minors,
    bool_or(death_date is not null) as has_dead_child,
    bool_or(birth_date > cutoff) as has_minor_child
from citizen_child, age_threshold
group by recruit_id;</sql>
    <variables_active>N</variables_active>
    <attributes/>
    <GUI>
      <xloc>208</xloc>
      <yloc>304</yloc>
    </GUI>
  </transform>
  <transform>
    <name>citizenship_flag_output</name>
    <type>TableInput</type>
    <description/>
    <distribute>Y</distribute>
    <custom_distribution/>
    <copies>1</copies>
    <partitioning>
      <method>none</method>
      <schema_name/>
    </partitioning>
    <connection>ervu-dashboard</connection>
    <execute_each_row>N</execute_each_row>
    <limit>0</limit>
    <sql>with foreign_citizenship as (
    select recruit_id, true as has_foreign_citizenship
    from citizenship_foreign
)
select
    citizenship.recruit_id,
    true as has_russian_citizenship,
    coalesce(has_foreign_citizenship, false) as has_foreign_citizenship
    from citizenship
    left join foreign_citizenship
    on foreign_citizenship.recruit_id = citizenship.recruit_id
where renunciation_number is null;</sql>
    <variables_active>N</variables_active>
    <attributes/>
    <GUI>
      <xloc>208</xloc>
      <yloc>672</yloc>
    </GUI>
  </transform>
  <transform>
    <name>deputy_input</name>
    <type>TableInput</type>
    <description/>
    <distribute>Y</distribute>
    <custom_distribution/>
    <copies>1</copies>
    <partitioning>
      <method>none</method>
      <schema_name/>
    </partitioning>
    <connection>ervu-dashboard</connection>
    <execute_each_row>N</execute_each_row>
    <limit>0</limit>
    <sql>
SELECT
    recruit_id,
    COALESCE(deputy.deputy, false) AS is_deputy,
    NOT COALESCE(deputy.deputy, false) AS is_deputy_candidate
FROM deputy;</sql>
    <variables_active>N</variables_active>
    <attributes/>
    <GUI>
      <xloc>208</xloc>
      <yloc>912</yloc>
    </GUI>
  </transform>
  <transform>
    <name>driver_licence_output</name>
    <type>TableInput</type>
    <description/>
    <distribute>Y</distribute>
    <custom_distribution/>
    <copies>1</copies>
    <partitioning>
      <method>none</method>
      <schema_name/>
    </partitioning>
    <connection>ervu-dashboard</connection>
    <execute_each_row>N</execute_each_row>
    <limit>0</limit>
    <sql>select
    recruit_id,
    bool_or(not tractor_driver) as has_driver_license,
    bool_or(tractor_driver) as has_tractor_licence
from drivers_licence
group by recruit_id;</sql>
    <variables_active>N</variables_active>
    <attributes/>
    <GUI>
      <xloc>208</xloc>
      <yloc>560</yloc>
    </GUI>
  </transform>
  <transform>
    <name>opekun_flag</name>
    <type>TableInput</type>
    <description/>
    <distribute>Y</distribute>
    <custom_distribution/>
    <copies>1</copies>
    <partitioning>
      <method>none</method>
      <schema_name/>
    </partitioning>
    <connection>ervu-dashboard</connection>
    <execute_each_row>N</execute_each_row>
    <limit>0</limit>
    <sql>select distinct
    recruit_id,
    true as is_guardian
    from citizen_guardianship;</sql>
    <variables_active>N</variables_active>
    <attributes/>
    <GUI>
      <xloc>208</xloc>
      <yloc>432</yloc>
    </GUI>
  </transform>
  <transform>
    <name>property_flag_output</name>
    <type>TableInput</type>
    <description/>
    <distribute>Y</distribute>
    <custom_distribution/>
    <copies>1</copies>
    <partitioning>
      <method>none</method>
      <schema_name/>
    </partitioning>
    <connection>ervu-dashboard</connection>
    <execute_each_row>N</execute_each_row>
    <limit>0</limit>
    <sql>select
    recruit_id,
    bool_or(type_property = 'ground_transportation') as has_ground_transport,
    bool_or(type_property = 'air_vehicles') as has_air_transport,
    bool_or(type_property = 'water_vehicles') as has_water_transport,
    bool_or(type_property = 'realty') as has_property
    from property
group by recruit_id;</sql>
    <variables_active>N</variables_active>
    <attributes/>
    <GUI>
      <xloc>208</xloc>
      <yloc>800</yloc>
    </GUI>
  </transform>
  <transform>
    <name>Update_has_criminal_prosecution</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>
    <ignore_flag_field/>
    <lookup>
      <key>
        <condition>=</condition>
        <field>recruit_id</field>
        <name>recruit_id</name>
        <name2/>
      </key>
      <schema>ervu_dashboard</schema>
      <table>citizen</table>
      <value>
        <name>has_criminal_prosecution</name>
        <rename>has_criminal_prosecution</rename>
      </value>
    </lookup>
    <skip_lookup>N</skip_lookup>
    <use_batch>Y</use_batch>
    <attributes/>
    <GUI>
      <xloc>432</xloc>
      <yloc>1024</yloc>
    </GUI>
  </transform>
  <transform>
    <name>has_criminal_prosecution</name>
    <type>TableInput</type>
    <description/>
    <distribute>Y</distribute>
    <custom_distribution/>
    <copies>1</copies>
    <partitioning>
      <method>none</method>
      <schema_name/>
    </partitioning>
    <connection>ervu-dashboard</connection>
    <execute_each_row>N</execute_each_row>
    <limit>0</limit>
    <sql>
SELECT
distinct
recruit_id,
true as has_criminal_prosecution
FROM prosecution
where close_date is null;</sql>
    <variables_active>N</variables_active>
    <attributes/>
    <GUI>
      <xloc>208</xloc>
      <yloc>1024</yloc>
    </GUI>
  </transform>
  <transform>
    <name>Update_criminal_record</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>
    <ignore_flag_field/>
    <lookup>
      <key>
        <condition>=</condition>
        <field>recruit_id</field>
        <name>recruit_id</name>
        <name2/>
      </key>
      <schema>ervu_dashboard</schema>
      <table>citizen</table>
      <value>
        <name>serving_sentence</name>
        <rename>serving_sentence</rename>
      </value>
      <value>
        <name>has_sentence</name>
        <rename>has_sentence</rename>
      </value>
      <value>
        <name>has_criminal_record</name>
        <rename>has_criminal_record</rename>
      </value>
    </lookup>
    <skip_lookup>N</skip_lookup>
    <use_batch>Y</use_batch>
    <attributes/>
    <GUI>
      <xloc>432</xloc>
      <yloc>1120</yloc>
    </GUI>
  </transform>
  <transform>
    <name>criminal_record</name>
    <type>TableInput</type>
    <description/>
    <distribute>Y</distribute>
    <custom_distribution/>
    <copies>1</copies>
    <partitioning>
      <method>none</method>
      <schema_name/>
    </partitioning>
    <connection>ervu-dashboard</connection>
    <execute_each_row>N</execute_each_row>
    <limit>0</limit>
    <sql>SELECT
recruit_id,
bool_or(start_date &lt; current_date and (release_date isnull or release_date > current_date)) as serving_sentence,
true as has_sentence,
true as has_criminal_record
FROM ervu_dashboard.punishment
group by recruit_id;</sql>
    <variables_active>N</variables_active>
    <attributes/>
    <GUI>
      <xloc>208</xloc>
      <yloc>1120</yloc>
    </GUI>
  </transform>
  <transform_error_handling>
  </transform_error_handling>
  <attributes/>
</pipeline>
