<?xml version="1.0" encoding="UTF-8"?>
<pipeline>
  <info>
    <name>disease_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>2024/08/15 14:02:51.713</created_date>
    <modified_user>-</modified_user>
    <modified_date>2024/08/15 14:02:51.713</modified_date>
  </info>
  <notepads>
  </notepads>
  <order>
    <hop>
      <from>Table input</from>
      <to>Table output</to>
      <enabled>Y</enabled>
    </hop>
    <hop>
      <from>Table output</from>
      <to>Update</to>
      <enabled>Y</enabled>
    </hop>
  </order>
  <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_person_registry</connection>
    <execute_each_row>N</execute_each_row>
    <limit>0</limit>
    <sql>with zdorov as (select ri.recruit_id,
                       jsonb_array_elements(
                               ri.info -> 'svedFL' -> 'svedSostZdorov' -> 'svedZdorov' ->
                               'sostZdorov') z,
                       case
                           when ri.info -> 'svedFL' -> 'svedSostZdorov' -> 'svedZdorov' ->>
                                'priznakNalichSved' = '1'
                               then true
                           else false end as has_disease
                from public.recruits_info ri
                         join public.recruits r
                              ON r.id = ri.recruit_id
                                  AND (r.target_recruitment_id = '${RCRT_C}' or
                                       r.current_recruitment_id = '${RCRT_C}')
                where jsonb_typeof(ri.info -> 'svedFL' -> 'svedSostZdorov' -> 'svedZdorov' ->
                                   'sostZdorov') = 'array')
select recruit_id,
       z ->> 'kodZabol'                         code,
       z ->> 'naimZabol'                        name,
       has_disease,
       to_date(z ->> 'dataDiagn', 'YYYY-MM-DD') reg_date
from zdorov;</sql>
    <variables_active>Y</variables_active>
    <attributes/>
    <GUI>
      <xloc>208</xloc>
      <yloc>208</yloc>
    </GUI>
  </transform>
  <transform>
    <name>Table output</name>
    <type>TableOutput</type>
    <description/>
    <distribute>Y</distribute>
    <custom_distribution/>
    <copies>1</copies>
    <partitioning>
      <method>none</method>
      <schema_name/>
    </partitioning>
    <commit>20000</commit>
    <connection>ervu-dashboard</connection>
    <fields>
      <field>
        <column_name>recruit_id</column_name>
        <stream_name>recruit_id</stream_name>
      </field>
      <field>
        <column_name>code</column_name>
        <stream_name>code</stream_name>
      </field>
      <field>
        <column_name>name</column_name>
        <stream_name>name</stream_name>
      </field>
      <field>
        <column_name>reg_date</column_name>
        <stream_name>reg_date</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_field/>
    <partitioning_monthly>Y</partitioning_monthly>
    <return_field/>
    <return_keys>N</return_keys>
    <schema>ervu_dashboard</schema>
    <specify_fields>Y</specify_fields>
    <table>disease</table>
    <tablename_field/>
    <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>416</xloc>
      <yloc>208</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>50000</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_disease</name>
        <rename>has_disease</rename>
      </value>
    </lookup>
    <skip_lookup>N</skip_lookup>
    <use_batch>Y</use_batch>
    <attributes/>
    <GUI>
      <xloc>592</xloc>
      <yloc>208</yloc>
    </GUI>
  </transform>
  <transform_error_handling>
  </transform_error_handling>
  <attributes/>
</pipeline>
