Skip to content

Commit

Permalink
Merge pull request tech-by-design#987 from alan-francis/main
Browse files Browse the repository at this point in the history
Add sftp session id to the master zip table db updates with unit tests
  • Loading branch information
alan-francis authored Jan 3, 2025
2 parents 9be03f0 + a6d4d25 commit a869e93
Show file tree
Hide file tree
Showing 4 changed files with 99 additions and 19 deletions.
Binary file modified hub-prime/lib/techbd-udi-jooq-ingress.auto.jar
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -236,16 +236,11 @@ AS SELECT tenant_id,
* If an error occurs during any step, the function logs the error using the `register_issue` procedure and returns NULL.
*******************************************************************************************************************************/


DROP FUNCTION IF EXISTS techbd_udi_ingress.register_interaction_http_request(text, text, jsonb, text, text, jsonb, jsonb, text, text, text, text, text, text, text, text, timestamptz, text, text, bool, text, bytea, text, text, text, text, text, text, text, text, text, text, text, text, text, text, text, text, text);

DROP FUNCTION IF EXISTS techbd_udi_ingress.register_interaction_http_request(text, text, jsonb, text, text, jsonb, jsonb, text, text, text, text, text, text, text, text, timestamptz, text, text, bool, text, bytea, text, text, text, text, text, text, text, text, text, text, text, text, text, text, text, text, text);

DROP FUNCTION IF EXISTS techbd_udi_ingress.register_interaction_http_request(text, text, jsonb, text, text, jsonb, jsonb, text, text, text, text, text, text, text, text, timestamptz, text, text, bool, text, bytea, text, text, text, text, text, text, text, text, text, text, text, text, text, text, text, text);

DROP FUNCTION IF EXISTS techbd_udi_ingress.register_interaction_http_request(text, text, jsonb, text, text, jsonb, jsonb, text, text, text, text, text, text, text, text, timestamptz, text, text, bool, text, bytea, text, text, text, text, text, text, text, text, text, text, text, text, text, text, text);
DROP FUNCTION IF EXISTS techbd_udi_ingress.register_interaction_http_request(text, text, jsonb, text, text, jsonb, jsonb, text, text, text, text, text, text, text, text, timestamptz, text, text, bool, text, bytea, text, text, text, text, text, text, text, text, text, text, text, text, text, text, text, text, text);

CREATE OR REPLACE FUNCTION techbd_udi_ingress.register_interaction_http_request(interaction_id text, interaction_key text, payload jsonb DEFAULT NULL::jsonb, payload_text text DEFAULT NULL::text, rule_namespace text DEFAULT NULL::text, elaboration jsonb DEFAULT NULL::jsonb, nature jsonb DEFAULT NULL::jsonb, content_type text DEFAULT NULL::text, from_state text DEFAULT NULL::text, to_state text DEFAULT NULL::text, state_transition_reason text DEFAULT NULL::text, user_id text DEFAULT NULL::text, user_name text DEFAULT NULL::text, user_session text DEFAULT NULL::text, user_role text DEFAULT NULL::text, created_at timestamp with time zone DEFAULT NULL::timestamp with time zone, created_by text DEFAULT NULL::text, provenance text DEFAULT NULL::text, hub_upsert_behavior boolean DEFAULT true, csv_zip_file_name text DEFAULT NULL::text, csv_zip_file_content bytea DEFAULT NULL::bytea, csv_group_id text DEFAULT NULL::text, csv_status text DEFAULT NULL::text, csv_screening_observation_data_payload_text text DEFAULT NULL::text, csv_screening_profile_data_payload_text text DEFAULT NULL::text, csv_demographic_data_payload_text text DEFAULT NULL::text, csv_qe_admin_data_payload_text text DEFAULT NULL::text, csv_screening_observation_data_file_name text DEFAULT NULL::text, csv_screening_profile_data_file_name text DEFAULT NULL::text, csv_demographic_data_file_name text DEFAULT NULL::text, csv_qe_admin_data_file_name text DEFAULT NULL::text, source_hub_interaction_id text DEFAULT NULL::text, client_ip_address text DEFAULT NULL::text, user_agent text DEFAULT NULL::text, origin text DEFAULT NULL::text, source_type text DEFAULT NULL::text, group_hub_interaction_id text DEFAULT NULL::text)
CREATE OR REPLACE FUNCTION techbd_udi_ingress.register_interaction_http_request(interaction_id text, interaction_key text, payload jsonb DEFAULT NULL::jsonb, payload_text text DEFAULT NULL::text, rule_namespace text DEFAULT NULL::text, elaboration jsonb DEFAULT NULL::jsonb, nature jsonb DEFAULT NULL::jsonb, content_type text DEFAULT NULL::text, from_state text DEFAULT NULL::text, to_state text DEFAULT NULL::text, state_transition_reason text DEFAULT NULL::text, user_id text DEFAULT NULL::text, user_name text DEFAULT NULL::text, user_session text DEFAULT NULL::text, user_role text DEFAULT NULL::text, created_at timestamp with time zone DEFAULT NULL::timestamp with time zone, created_by text DEFAULT NULL::text, provenance text DEFAULT NULL::text, hub_upsert_behavior boolean DEFAULT true, csv_zip_file_name text DEFAULT NULL::text, csv_zip_file_content bytea DEFAULT NULL::bytea, csv_group_id text DEFAULT NULL::text, csv_status text DEFAULT NULL::text, csv_screening_observation_data_payload_text text DEFAULT NULL::text, csv_screening_profile_data_payload_text text DEFAULT NULL::text, csv_demographic_data_payload_text text DEFAULT NULL::text, csv_qe_admin_data_payload_text text DEFAULT NULL::text, csv_screening_observation_data_file_name text DEFAULT NULL::text, csv_screening_profile_data_file_name text DEFAULT NULL::text, csv_demographic_data_file_name text DEFAULT NULL::text, csv_qe_admin_data_file_name text DEFAULT NULL::text, source_hub_interaction_id text DEFAULT NULL::text, client_ip_address text DEFAULT NULL::text, user_agent text DEFAULT NULL::text, origin text DEFAULT NULL::text, source_type text DEFAULT NULL::text, group_hub_interaction_id text DEFAULT NULL::text, sftp_session_id text DEFAULT NULL::text)
RETURNS jsonb
LANGUAGE plpgsql
AS $function$
Expand Down Expand Up @@ -499,7 +494,8 @@ BEGIN
zip_file_hub_interaction_id => register_interaction_http_request.source_hub_interaction_id,
client_ip_address => register_interaction_http_request.client_ip_address,
user_agent => register_interaction_http_request.user_agent,
origin => register_interaction_http_request.origin
origin => register_interaction_http_request.origin,
sftp_session_id => register_interaction_http_request.sftp_session_id
);
/*---register diagnostic log---*/
v_elaboration := jsonb_build_object(
Expand Down Expand Up @@ -3285,13 +3281,11 @@ GROUP BY
organization_id,
organization_name;


DROP FUNCTION IF EXISTS techbd_udi_ingress.sat_interaction_csv_request_upserted(text, text, text, text, text, bytea, text, text, text, text, text, text, text, text, text, text, text, text, text, text, text, text, jsonb, text, text, text, timestamptz, text, text, jsonb);
DROP FUNCTION IF EXISTS techbd_udi_ingress.sat_interaction_csv_request_upserted(text, text, text, text, text, bytea, text, text, text, text, text, text, text, text, text, text, text, text, text, text, text, text, jsonb, text, text, text, timestamptz, text, text, jsonb, text);
DROP FUNCTION IF EXISTS techbd_udi_ingress.sat_interaction_csv_request_upserted(text, text, text, text, text, bytea, text, text, text, text, text, text, text, text, text, text, jsonb, text, text, text, timestamptz, text, text, jsonb, text, text, text, text);
DROP FUNCTION IF EXISTS techbd_udi_ingress.sat_interaction_csv_request_upserted(text, text, text, text, text, bytea, text, text, text, text, text, text, text, text, text, text, jsonb, text, text, text, timestamptz, text, text, jsonb, text, text, text, text, text);


CREATE OR REPLACE FUNCTION techbd_udi_ingress.sat_interaction_csv_request_upserted(interaction_id text, uri text, nature text, tenant_id text DEFAULT NULL::text, csv_zip_file_name text DEFAULT NULL::text, csv_zip_file_content bytea DEFAULT NULL::bytea, group_id text DEFAULT NULL::text, status text DEFAULT NULL::text, csv_screening_observation_data_payload_text text DEFAULT NULL::text, csv_screening_profile_data_payload_text text DEFAULT NULL::text, csv_demographic_data_payload_text text DEFAULT NULL::text, csv_qe_admin_data_payload_text text DEFAULT NULL::text, csv_screening_observation_data_file_name text DEFAULT NULL::text, csv_screening_profile_data_file_name text DEFAULT NULL::text, csv_demographic_data_file_name text DEFAULT NULL::text, csv_qe_admin_data_file_name text DEFAULT NULL::text, validation_result_payload jsonb DEFAULT NULL::jsonb, from_state text DEFAULT NULL::text, to_state text DEFAULT NULL::text, state_transition_reason text DEFAULT NULL::text, created_at timestamp with time zone DEFAULT NULL::timestamp with time zone, created_by text DEFAULT NULL::text, provenance text DEFAULT NULL::text, elaboration jsonb DEFAULT NULL::jsonb, zip_file_hub_interaction_id text DEFAULT NULL::text, client_ip_address text DEFAULT NULL::text, user_agent text DEFAULT NULL::text, origin text DEFAULT NULL::text)
CREATE OR REPLACE FUNCTION techbd_udi_ingress.sat_interaction_csv_request_upserted(interaction_id text, uri text, nature text, tenant_id text DEFAULT NULL::text, csv_zip_file_name text DEFAULT NULL::text, csv_zip_file_content bytea DEFAULT NULL::bytea, group_id text DEFAULT NULL::text, status text DEFAULT NULL::text, csv_screening_observation_data_payload_text text DEFAULT NULL::text, csv_screening_profile_data_payload_text text DEFAULT NULL::text, csv_demographic_data_payload_text text DEFAULT NULL::text, csv_qe_admin_data_payload_text text DEFAULT NULL::text, csv_screening_observation_data_file_name text DEFAULT NULL::text, csv_screening_profile_data_file_name text DEFAULT NULL::text, csv_demographic_data_file_name text DEFAULT NULL::text, csv_qe_admin_data_file_name text DEFAULT NULL::text, validation_result_payload jsonb DEFAULT NULL::jsonb, from_state text DEFAULT NULL::text, to_state text DEFAULT NULL::text, state_transition_reason text DEFAULT NULL::text, created_at timestamp with time zone DEFAULT NULL::timestamp with time zone, created_by text DEFAULT NULL::text, provenance text DEFAULT NULL::text, elaboration jsonb DEFAULT NULL::jsonb, zip_file_hub_interaction_id text DEFAULT NULL::text, client_ip_address text DEFAULT NULL::text, user_agent text DEFAULT NULL::text, origin text DEFAULT NULL::text, sftp_session_id text DEFAULT NULL::text)

RETURNS text
LANGUAGE plpgsql
Expand Down Expand Up @@ -3338,7 +3332,7 @@ BEGIN
sat_interaction_zip_file_request_id, hub_interaction_id, tenant_id, tenant_id_lower, uri, nature,
group_id, status, csv_zip_file_name, csv_zip_file_content,
client_ip_address, user_agent,
elaboration, created_at, created_by, provenance, validation_result_payload, origin
elaboration, created_at, created_by, provenance, validation_result_payload, origin, sftp_session_id
)
VALUES (
gen_random_uuid()::TEXT, -- Generate a unique UUID for the primary key
Expand All @@ -3355,7 +3349,8 @@ BEGIN
client_ip_address, user_agent,
NULL, v_created_at, v_created_by, v_provenance,
sat_interaction_csv_request_upserted.validation_result_payload,
sat_interaction_csv_request_upserted.origin
sat_interaction_csv_request_upserted.origin,
sat_interaction_csv_request_upserted.sftp_session_id
) RETURNING sat_interaction_zip_file_request_id INTO v_return; -- Return the generated UUID

/*---register diagnostic log---*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1165,7 +1165,8 @@ const migrateSP = pgSQLa.storedProcedure(
ALTER TABLE techbd_udi_ingress.sat_interaction_fhir_request
ADD COLUMN IF NOT EXISTS is_bundle_valid BOOLEAN NULL;
ALTER TABLE techbd_udi_ingress.sat_interaction_zip_file_request
ADD COLUMN IF NOT EXISTS sftp_session_id text NULL;
${dependenciesSQL}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ DECLARE
v_origin TEXT;
v_source_type TEXT;
v_group_hub_interaction_id TEXT;
v_sftp_session_id TEXT;

BEGIN

Expand Down Expand Up @@ -79,14 +80,14 @@ BEGIN

-- Check existence of required functions
RETURN NEXT has_function(schema_name, 'register_interaction_http_request',
ARRAY['text', 'text', 'jsonb', 'text', 'text', 'jsonb', 'jsonb', 'text', 'text', 'text', 'text', 'text', 'text', 'text', 'text', 'timestamptz', 'text', 'text', 'bool', 'text', 'bytea', 'text', 'text', 'text', 'text', 'text', 'text', 'text', 'text', 'text', 'text', 'text', 'text', 'text', 'text', 'text', 'text'],
ARRAY['text', 'text', 'jsonb', 'text', 'text', 'jsonb', 'jsonb', 'text', 'text', 'text', 'text', 'text', 'text', 'text', 'text', 'timestamptz', 'text', 'text', 'bool', 'text', 'bytea', 'text', 'text', 'text', 'text', 'text', 'text', 'text', 'text', 'text', 'text', 'text', 'text', 'text', 'text', 'text', 'text', 'text'],
'Function register_interaction_http_request exists');

RETURN NEXT has_function(schema_name, 'register_issue', ARRAY['text', 'text', 'text', 'text', 'text', 'text', 'text', 'text', 'text', 'text', 'jsonb'], 'Function register_issue exists');

RETURN NEXT has_function(schema_name, 'sat_interaction_fhir_request_upserted', ARRAY['text', 'text', 'text', 'text', 'text', 'text', 'jsonb', 'text', 'timestamptz', 'text', 'text', 'jsonb', 'text', 'text', 'text'], 'Function sat_interaction_fhir_request_upserted exists');

RETURN NEXT has_function(schema_name, 'sat_interaction_csv_request_upserted', ARRAY['text', 'text', 'text', 'text', 'text', 'bytea', 'text', 'text', 'text', 'text', 'text', 'text', 'text', 'text', 'text', 'text', 'jsonb', 'text', 'text', 'text', 'timestamptz', 'text', 'text', 'jsonb', 'text', 'text', 'text', 'text'],
RETURN NEXT has_function(schema_name, 'sat_interaction_csv_request_upserted', ARRAY['text', 'text', 'text', 'text', 'text', 'bytea', 'text', 'text', 'text', 'text', 'text', 'text', 'text', 'text', 'text', 'text', 'jsonb', 'text', 'text', 'text', 'timestamptz', 'text', 'text', 'jsonb', 'text', 'text', 'text', 'text', 'text'],
'Function sat_interaction_csv_request_upserted exists');
RETURN NEXT has_table(schema_name, 'sat_interaction_flat_file_csv_request', 'The table techbd_udi_ingress.sat_interaction_flat_file_csv_request should exist.');

Expand Down Expand Up @@ -118,7 +119,7 @@ BEGIN
ARRAY['sat_interaction_zip_file_request_id', 'hub_interaction_id', 'tenant_id', 'tenant_id_lower', 'uri', 'nature', 'group_id', 'status',
'csv_zip_file_name', 'csv_zip_file_content',
'client_ip_address', 'user_agent',
'elaboration', 'created_at', 'created_by', 'provenance', 'origin', 'validation_result_payload'],
'elaboration', 'created_at', 'created_by', 'provenance', 'origin', 'validation_result_payload','sftp_session_id'],
'The columns of techbd_udi_ingress.sat_interaction_zip_file_request should match the expected structure.');

RETURN NEXT col_type_is(schema_name, 'sat_interaction_zip_file_request', 'csv_zip_file_content', 'bytea', 'The column csv_zip_file_content should be of type bytea.');
Expand Down Expand Up @@ -240,6 +241,7 @@ test-MRN|CNYSCN|Crossroads NY Social Care Network|SCN|25 W 45th st|Suite 16|New
v_client_ip_address := 'test_client_ip_address';
v_user_agent := 'test_user_agent';
v_source_type := 'csv';
v_sftp_session_id := NULL::text;

PERFORM techbd_udi_ingress.register_interaction_http_request(
interaction_id => v_interaction_id,
Expand All @@ -264,7 +266,89 @@ test-MRN|CNYSCN|Crossroads NY Social Care Network|SCN|25 W 45th st|Suite 16|New
client_ip_address => v_client_ip_address,
user_agent => v_user_agent,
origin => v_origin,
source_type => v_source_type
source_type => v_source_type,
sftp_session_id => v_sftp_session_id
);

RETURN NEXT ok(
EXISTS(SELECT 1 FROM techbd_udi_ingress.hub_interaction hub_intr
WHERE hub_intr.hub_interaction_id = v_interaction_id
AND hub_intr."key" = v_interaction_key
AND hub_intr.created_by = v_created_by
AND hub_intr.provenance = v_provenance
),
'CSV - Successfully inserted into the table hub_interaction'
);

/*Test 1 raw is inserted into sat_interaction_http_request table*/
RETURN NEXT ok(
EXISTS(SELECT 1 FROM techbd_udi_ingress.sat_interaction_http_request sat_intr
WHERE sat_intr.hub_interaction_id = v_interaction_id
AND sat_intr.nature = v_nature
AND sat_intr.nature_denorm = v_nature->>'nature'
AND sat_intr.created_by = v_created_by
AND sat_intr.provenance = v_provenance
),
'CSV - Successfully inserted one record into the table sat_interaction_http_request with "Original CSV Zip Archive" as nature'
);

/*Test 1 raw is inserted into sat_interaction_zip_file_request table*/
RETURN NEXT ok(
EXISTS(SELECT 1 FROM techbd_udi_ingress.sat_interaction_zip_file_request sat_intr
WHERE sat_intr.hub_interaction_id = v_interaction_id
AND sat_intr.uri = v_interaction_key
AND sat_intr.nature = v_nature->>'nature'
AND sat_intr.created_by = v_created_by
AND sat_intr.provenance = v_provenance
AND group_id = v_group_id
AND status = v_status
AND client_ip_address = v_client_ip_address
AND user_agent = v_user_agent
),
'CSV - Successfully inserted one record into the table sat_interaction_zip_file_request with "Original CSV Zip Archive" as nature'
);

/*Test one record is inserted into sat_interaction_user table*/
RETURN NEXT ok(
EXISTS(SELECT 1 FROM techbd_udi_ingress.sat_interaction_user sat_intr
WHERE sat_intr.hub_interaction_id = v_interaction_id
AND sat_intr.uri = v_interaction_key
AND sat_intr.nature = v_nature->>'nature'
AND sat_intr.created_by = v_created_by
AND sat_intr.provenance = v_provenance
),
'CSV - Successfully inserted into the table sat_interaction_user'
);

/*Test for sftp and storing sftp session id*/

v_sftp_session_id := '0cc90e96-b8bc-4642-b4ae-910444360636';

PERFORM techbd_udi_ingress.register_interaction_http_request(
interaction_id => v_interaction_id,
interaction_key => v_interaction_key,
payload => NULL::jsonb,
payload_text => NULL::text,
rule_namespace => v_rule_namespace,
elaboration => v_elaboration,
nature => v_nature,
content_type => v_content_type,
from_state => v_from_state,
to_state => v_to_state,
state_transition_reason => v_state_transition_reason,
created_at => v_created_at,
created_by => v_created_by,
provenance => v_provenance,
hub_upsert_behavior => TRUE,
csv_group_id => v_group_id,
csv_status => v_status,
csv_zip_file_name => v_csv_zip_file_name,
csv_zip_file_content => v_csv_zip_file_content,
client_ip_address => v_client_ip_address,
user_agent => v_user_agent,
origin => 'sftp',
source_type => v_source_type,
sftp_session_id => v_sftp_session_id
);

RETURN NEXT ok(
Expand Down

0 comments on commit a869e93

Please sign in to comment.