<?xml version="1.0" encoding="UTF-8"?>
<pipeline>
  <info>
    <name>child_flow1</name>
    <name_sync_with_filename>Y</name_sync_with_filename>
    <description/>
    <extended_description/>
    <pipeline_version/>
    <pipeline_type>Normal</pipeline_type>
    <pipeline_status>0</pipeline_status>
    <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/05/21 14:05:02.260</created_date>
    <modified_user>-</modified_user>
    <modified_date>2025/05/21 14:05:02.260</modified_date>
  </info>
  <notepads>
  </notepads>
  <order>
    <hop>
      <from>Table input</from>
      <to>Select values 4 2</to>
      <enabled>N</enabled>
    </hop>
    <hop>
      <from>Select values 4 2</from>
      <to>Get variables</to>
      <enabled>N</enabled>
    </hop>
    <hop>
      <from>Table input</from>
      <to>Insert / update</to>
      <enabled>Y</enabled>
    </hop>
  </order>
  <transform>
    <name>Get variables</name>
    <type>GetVariable</type>
    <description/>
    <distribute>Y</distribute>
    <custom_distribution/>
    <copies>1</copies>
    <partitioning>
      <method>none</method>
      <schema_name/>
    </partitioning>
    <fields>
      <field>
        <length>-1</length>
        <name>recruitment_id</name>
        <precision>-1</precision>
        <trim_type>none</trim_type>
        <type>String</type>
        <variable>ID_F1</variable>
      </field>
    </fields>
    <attributes/>
    <GUI>
      <xloc>976</xloc>
      <yloc>400</yloc>
    </GUI>
  </transform>
  <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>100</commit>
    <connection>ervu-dashboard</connection>
    <lookup>
      <key>
        <condition>=</condition>
        <field>recruit_id</field>
        <name>recruit_id</name>
      </key>
      <schema>ervu_dashboard</schema>
      <table>citizen_child</table>
      <value>
        <name>recruit_id</name>
        <rename>recruit_id</rename>
        <update>N</update>
      </value>
      <value>
        <name>birth_az_number</name>
        <rename>birth_az_number</rename>
        <update>Y</update>
      </value>
      <value>
        <name>birth_date</name>
        <rename>birth_date</rename>
        <update>Y</update>
      </value>
      <value>
        <name>death_az_number</name>
        <rename>death_az_number</rename>
        <update>Y</update>
      </value>
      <value>
        <name>death_date</name>
        <rename>death_date</rename>
        <update>Y</update>
      </value>
      <value>
        <name>full_name</name>
        <rename>full_name</rename>
        <update>Y</update>
      </value>
      <value>
        <name>kinship_type</name>
        <rename>kinship_type</rename>
        <update>Y</update>
      </value>
    </lookup>
    <update_bypassed>N</update_bypassed>
    <attributes/>
    <GUI>
      <xloc>944</xloc>
      <yloc>288</yloc>
    </GUI>
  </transform>
  <transform>
    <name>Select values 4 2</name>
    <type>SelectValues</type>
    <description/>
    <distribute>Y</distribute>
    <custom_distribution/>
    <copies>1</copies>
    <partitioning>
      <method>none</method>
      <schema_name/>
    </partitioning>
    <fields>
      <select_unspecified>N</select_unspecified>
      <meta>
        <name>ID_F1</name>
        <rename>ID_F1</rename>
        <type>String</type>
        <length>-2</length>
        <precision>-2</precision>
        <conversion_mask/>
        <date_format_lenient>false</date_format_lenient>
        <date_format_locale/>
        <date_format_timezone/>
        <lenient_string_to_number>false</lenient_string_to_number>
        <encoding/>
        <decimal_symbol/>
        <grouping_symbol/>
        <currency_symbol/>
        <storage_type/>
      </meta>
    </fields>
    <attributes/>
    <GUI>
      <xloc>720</xloc>
      <yloc>400</yloc>
    </GUI>
  </transform>
  <transform>
    <name>Table 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>with child as
(select jsonb_array_elements(ri.info->'svedFL'->'svedDeti'->'rebenok') ch,
   ri.recruit_id
from ervu_dashboard.recruits_info ri
join ervu_dashboard.citizen r ON r.recruit_id = ri.recruit_id AND '${ID_F1}' != ''  -- Проверка на пустую строку
    AND COALESCE(ri.current_recruitment_id, ri.target_recruitment_id) = '${ID_F1}'
    AND '${M_R_CR_DATE}'::timestamp >= ri.created_at
where jsonb_typeof(ri.info->'svedFL'->'svedDeti'->'rebenok') = 'array'
)
select 
 r.recruit_id::uuid recruit_id,
 ch->>'naimRodstvSvyazReb' kinship_type,
 concat_ws(' ', ch->'svedFLBS'->'fio'->>'familiya',
          ch->'svedFLBS'->'fio'->>'imya',
       ch->'svedFLBS'->'fio'->>'otchestvo') full_name,
 make_date(NULLIF(ch->'svedFLBS'->'dataRozhdDok'->>'god', '')::int, 
              NULLIF(ch->'svedFLBS'->'dataRozhdDok'->>'mesyacz','')::int, 
              NULLIF(ch->'svedFLBS'->'dataRozhdDok'->>'den','')::int) birth_date,
 make_date(NULLIF(ch->'svedSmert'->'dataSmert'->>'god', '')::int, 
              NULLIF(ch->'svedSmert'->'dataSmert'->>'mesyacz','')::int, 
              NULLIF(ch->'svedSmert'->'dataSmert'->>'den','')::int) death_date,
 ch->'svedSmert'->>'nomerZapis' death_az_number, 
 ch->'svedAZRozhd'->>'nomerZapis' birth_az_number
from ervu_dashboard.citizen r
join child on r.recruit_id = child.recruit_id</sql>
    <variables_active>Y</variables_active>
    <attributes/>
    <GUI>
      <xloc>448</xloc>
      <yloc>288</yloc>
    </GUI>
  </transform>
  <transform_error_handling>
    <error>
      <source_transform>Select values 4 2</source_transform>
      <target_transform>Get variables</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>
