<?xml version="1.0" encoding="UTF-8"?>
<pipeline>
  <info>
    <name>citizen_guardianship_flow5</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/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>
    <notepad>
      <backgroundcolorblue>251</backgroundcolorblue>
      <backgroundcolorgreen>232</backgroundcolorgreen>
      <backgroundcolorred>201</backgroundcolorred>
      <bordercolorblue>90</bordercolorblue>
      <bordercolorgreen>58</bordercolorgreen>
      <bordercolorred>14</bordercolorred>
      <fontbold>N</fontbold>
      <fontcolorblue>90</fontcolorblue>
      <fontcolorgreen>58</fontcolorgreen>
      <fontcolorred>14</fontcolorred>
      <fontitalic>N</fontitalic>
      <fontname>Segoe UI</fontname>
      <fontsize>9</fontsize>
      <height>26</height>
      <xloc>704</xloc>
      <yloc>256</yloc>
      <note>сведения о лице опекаемом или находящемся на попечении</note>
      <width>349</width>
    </notepad>
  </notepads>
  <order>
    <hop>
      <from>Table input</from>
      <to>Insert / update</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>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_guardianship</table>
      <value>
        <name>recruit_id</name>
        <rename>recruit_id</rename>
        <update>N</update>
      </value>
      <value>
        <name>birth_date</name>
        <rename>birth_date</rename>
        <update>Y</update>
      </value>
      <value>
        <name>full_name</name>
        <rename>full_name</rename>
        <update>Y</update>
      </value>
      <value>
        <name>snils</name>
        <rename>snils</rename>
        <update>Y</update>
      </value>
    </lookup>
    <update_bypassed>N</update_bypassed>
    <attributes/>
    <GUI>
      <xloc>1024</xloc>
      <yloc>368</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 person as
(select jsonb_array_elements(ri.info->'svedFL'->'svedOpekun'->'svedSoczPod') ch,
 		ri.recruit_id
from ervu_dashboard.recruits_info ri
join ervu_dashboard.citizen r ON r.recruit_id = ri.recruit_id AND '${ID_F5}' != ''  -- Проверка на пустую строку
    AND COALESCE(ri.current_recruitment_id, ri.target_recruitment_id) = '${ID_F5}'
    AND '${M_R_CR_DATE}'::timestamp >= ri.created_at
where jsonb_typeof(ri.info->'svedFL'->'svedOpekun'->'svedSoczPod') = 'array')
select 
	r.recruit_id AS recruit_id,
	concat_ws(' ', ch->'fioOpek'->>'familiya',
			       ch->'fioOpek'->>'imya',
				   ch->'fioOpek'->>'otchestvo') full_name,
	make_date(NULLIF(ch->'dataRozhdDok'->>'god', '')::int, 
              NULLIF(ch->'dataRozhdDok'->>'mesyacz','')::int, 
              NULLIF(ch->'dataRozhdDok'->>'den','')::int) birth_date,
	ch->>'snils' snils
from ervu_dashboard.citizen r
join person on r.recruit_id = person.recruit_id</sql>
    <variables_active>Y</variables_active>
    <attributes/>
    <GUI>
      <xloc>560</xloc>
      <yloc>368</yloc>
    </GUI>
  </transform>
  <transform_error_handling>
  </transform_error_handling>
  <attributes/>
</pipeline>
