<?xml version="1.0" encoding="UTF-8"?>
<pipeline>
  <info>
    <name>medical_authorities</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 hiv</from>
      <to>Table output</to>
      <enabled>N</enabled>
    </hop>
    <hop>
      <from>Table input 2</from>
      <to>Table output 2</to>
      <enabled>N</enabled>
    </hop>
    <hop>
      <from>Table input hiv</from>
      <to>Insert / update</to>
      <enabled>Y</enabled>
    </hop>
    <hop>
      <from>Table input 2</from>
      <to>Insert / update 2</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>10000</commit>
    <connection>ervu-dashboard</connection>
    <lookup>
      <key>
        <condition>=</condition>
        <field>recruit_id</field>
        <name>recruit_id</name>
        <name2/>
      </key>
      <schema>ervu_dashboard</schema>
      <table>medical_authorities</table>
      <value>
        <name>recruit_id</name>
        <rename>recruit_id</rename>
        <update>N</update>
      </value>
      <value>
        <name>close_date</name>
        <rename>close_date</rename>
        <update>Y</update>
      </value>
      <value>
        <name>hiv</name>
        <rename>hiv</rename>
        <update>Y</update>
      </value>
      <value>
        <name>start_date</name>
        <rename>start_date</rename>
        <update>Y</update>
      </value>
    </lookup>
    <update_bypassed>N</update_bypassed>
    <attributes/>
    <GUI>
      <xloc>672</xloc>
      <yloc>208</yloc>
    </GUI>
  </transform>
  <transform>
    <name>Insert / update 2</name>
    <type>InsertUpdate</type>
    <description/>
    <distribute>Y</distribute>
    <custom_distribution/>
    <copies>1</copies>
    <partitioning>
      <method>none</method>
      <schema_name/>
    </partitioning>
    <commit>10000</commit>
    <connection>ervu-dashboard</connection>
    <lookup>
      <key>
        <condition>=</condition>
        <field>recruit_id</field>
        <name>recruit_id</name>
      </key>
      <schema>ervu_dashboard</schema>
      <table>medical_authorities</table>
      <value>
        <name>recruit_id</name>
        <rename>recruit_id</rename>
        <update>N</update>
      </value>
      <value>
        <name>change_date</name>
        <rename>change_date</rename>
        <update>Y</update>
      </value>
      <value>
        <name>close_date</name>
        <rename>close_date</rename>
        <update>Y</update>
      </value>
      <value>
        <name>start_date</name>
        <rename>start_date</rename>
        <update>Y</update>
      </value>
      <value>
        <name>registered_in_pnd</name>
        <rename>registered_in_pnd</rename>
        <update>Y</update>
      </value>
    </lookup>
    <update_bypassed>N</update_bypassed>
    <attributes/>
    <GUI>
      <xloc>672</xloc>
      <yloc>352</yloc>
    </GUI>
  </transform>
  <transform>
    <name>Table input 2</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 uchet as
         (select ri.recruit_id,
                 jsonb_array_elements(ri.info -> 'svedFL' -> 'svedPND' -> 'svedUchetDisp' ->
                                      'svedUchet') u,
                 ri.info -> 'svedFL' -> 'svedPND' -> 'svedUchetDisp' -> 'svedUchet' ->>
                 'priznakNalichSved' = '1' as registered_in_pnd
          from public.recruits_info ri
                   join public.recruits r
                        ON r.id = ri.recruit_id
                            AND r.system_update_date >= '${UP_D}'
          where jsonb_typeof(ri.info -> 'svedFL' -> 'svedPND' -> 'svedUchetDisp' -> 'svedUchet') =
                'array')
select recruit_id,
       u ->> 'dataPostUchet'  start_date,
       u ->> 'dataSnyatUchet' close_date,
       u ->> 'dataPlan'       change_date,
       registered_in_pnd
from uchet;
</sql>
    <variables_active>Y</variables_active>
    <attributes/>
    <GUI>
      <xloc>208</xloc>
      <yloc>352</yloc>
    </GUI>
  </transform>
  <transform>
    <name>Table input hiv</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 uchet as
         (select ri.recruit_id,
                 jsonb_array_elements(ri.info->'svedFL'->'svedUchetVICH'->'uchetVICH') u,
                 ri.info->'svedFL'->'svedUchetVICH'->>'priznakNalichSved' = '1' has_vich
          from public.recruits_info ri
                   join public.recruits r
                        ON r.id = ri.recruit_id
                            AND r.system_update_date >= '${UP_D}'
          where jsonb_typeof(ri.info->'svedFL'->'svedUchetVICH'->'uchetVICH') = 'array')
select
    recruit_id,
    to_date(u->>'dataPostUchet', 'YYYY-MM-DD') start_date,
    to_date(u->>'dataSnyat', 'YYYY-MM-DD') close_date,
    true HIV
from uchet;</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>1000</commit>
    <connection>ervu-dashboard</connection>
    <fields>
</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>N</specify_fields>
    <table>medical_authorities</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>416</xloc>
      <yloc>80</yloc>
    </GUI>
  </transform>
  <transform>
    <name>Table output 2</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>
</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>N</specify_fields>
    <table>medical_authorities</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>432</xloc>
      <yloc>480</yloc>
    </GUI>
  </transform>
  <transform_error_handling>
  </transform_error_handling>
  <attributes/>
</pipeline>
