Skip to content

Commit

Permalink
feat: update register interaction with misc errors for CCDA along wit…
Browse files Browse the repository at this point in the history
…h test case updates tech-by-design#1011
  • Loading branch information
alan-francis committed Jan 15, 2025
1 parent b690f67 commit 76ccc9a
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 10 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 @@ -371,8 +371,7 @@ BEGIN
IF((v_nature_denorm = 'org.techbd.service.http.Interactions$RequestResponseEncountered' AND trim(register_interaction_http_request.interaction_key) NOT IN ('/Hl7/v2', '/Hl7/v2/', '/flatfile/csv/Bundle', '/flatfile/csv/Bundle/', '/flatfile/csv/Bundle/$validate')) /*fhir bundle*/
OR (v_nature_denorm = 'Original HL7 Payload' AND trim(register_interaction_http_request.interaction_key) IN ('/Hl7/v2', '/Hl7/v2/')) /*hl7*/
OR (v_nature_denorm = 'Original CSV Zip Archive' AND trim(register_interaction_http_request.interaction_key) IN ('/flatfile/csv/Bundle', '/flatfile/csv/Bundle/', '/flatfile/csv/Bundle/$validate')) /*csv*/
--OR (v_nature_denorm = 'org.techbd.service.http.Interactions$RequestResponseEncountered' AND trim(register_interaction_http_request.interaction_key) IN ('/ccda/Bundle', '/ccda/Bundle/$validate')) /*ccda*/
) THEN
) THEN
PERFORM techbd_udi_ingress.sat_interaction_user_upserted(
hub_interaction_id => register_interaction_http_request.interaction_id,
hub_interaction_key => register_interaction_http_request.interaction_key,
Expand Down Expand Up @@ -403,7 +402,7 @@ BEGIN
END IF;

--2.1) Call the function with the defined parameters to upsert interaction FHIR request info.
IF trim(register_interaction_http_request.interaction_key) IN ('/Bundle', '/Bundle/', '/Bundle/$validate', '/api/expect/fhir/bundle', '/Hl7/v2', '/Hl7/v2/', '/flatfile/csv/Bundle', '/flatfile/csv/Bundle/', '/flatfile/csv/Bundle/$validate', '/ccda/Bundle', '/ccda/Bundle/$validate')
IF trim(register_interaction_http_request.interaction_key) IN ('/Bundle', '/Bundle/', '/Bundle/$validate', '/api/expect/fhir/bundle', '/Hl7/v2', '/Hl7/v2/', '/flatfile/csv/Bundle', '/flatfile/csv/Bundle/', '/flatfile/csv/Bundle/$validate', '/ccda/Bundle')
AND v_nature_denorm NOT IN ('Original HL7 Payload', 'Original CSV Zip Archive', 'Original Flat File CSV', 'CSV Validation Result', 'Converted to FHIR') THEN

PERFORM techbd_udi_ingress.sat_interaction_fhir_request_upserted(
Expand Down Expand Up @@ -3286,10 +3285,10 @@ GROUP BY

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);
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, jsonb);


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)

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, zip_file_processing_errors jsonb DEFAULT NULL::jsonb)
RETURNS text
LANGUAGE plpgsql
AS $function$
Expand Down Expand Up @@ -3324,6 +3323,13 @@ BEGIN
SET validation_result_payload = sat_interaction_csv_request_upserted.validation_result_payload
WHERE hub_interaction_id = sat_interaction_csv_request_upserted.interaction_id;
v_return := sat_interaction_csv_request_upserted.interaction_id;

ELSIF nature = 'Update Zip File Processing Details' THEN /*Update the errors and status after the zip file is processed*/
UPDATE techbd_udi_ingress.sat_interaction_zip_file_request
SET status = sat_interaction_csv_request_upserted.status::text,
misc_errors = sat_interaction_csv_request_upserted.zip_file_processing_errors::jsonb
WHERE hub_interaction_id = sat_interaction_csv_request_upserted.interaction_id;
v_return := sat_interaction_csv_request_upserted.interaction_id;

ELSIF nature = 'Original CSV Zip Archive' THEN
/*lo_id := lo_create(0); -- Create a new large OBJECT
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1168,6 +1168,10 @@ const migrateSP = pgSQLa.storedProcedure(
ALTER TABLE techbd_udi_ingress.sat_interaction_zip_file_request
ADD COLUMN IF NOT EXISTS sftp_session_id text NULL;
ALTER TABLE techbd_udi_ingress.sat_interaction_zip_file_request
ADD COLUMN IF NOT EXISTS misc_errors jsonb NULL;
${dependenciesSQL}
CREATE EXTENSION IF NOT EXISTS pgtap SCHEMA ${assuranceSchema.sqlNamespace};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ DECLARE
v_source_type TEXT;
v_group_hub_interaction_id TEXT;
v_sftp_session_id TEXT;
v_zip_file_processing_errors jsonb;

BEGIN

Expand Down Expand Up @@ -87,7 +88,7 @@ BEGIN

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', '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', 'jsonb'],
'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 @@ -119,7 +120,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','sftp_session_id'],
'elaboration', 'created_at', 'created_by', 'provenance', 'origin', 'validation_result_payload','sftp_session_id', 'misc_errors'],
'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 @@ -643,17 +644,31 @@ test-MRN|CNYSCN|Crossroads NY Social Care Network|SCN|25 W 45th st|Suite 16|New
'CSV - Successfully inserted one record into the table sat_interaction_flat_file_csv_request with "Converted to FHIR" as nature'
);

/*To update validation_result_payload for the full zip file, call techbd_udi_ingress.sat_interaction_csv_request_upserted function with interaction_id, uri, tenant_id, validation_result_payload and nature as 'Update Zip File Payload'.*/
/*To update validation_result_payload for the full zip file, call techbd_udi_ingress.sat_interaction_csv_request_upserted function with interaction_id, uri, validation_result_payload and nature as 'Update Zip File Payload'.*/
SELECT techbd_udi_ingress.sat_interaction_csv_request_upserted(
interaction_id => v_source_hub_interaction_id::text,
uri => v_interaction_key::text,
--tenant_id => v_nature->>'tenant_id',
validation_result_payload => v_payload::jsonb,
nature => 'Update Zip File Payload'::text
) INTO v_interaction_id;

RETURN NEXT ok(v_interaction_id = v_source_hub_interaction_id, 'CSV - Successfully updated the table sat_interaction_zip_file_request with consolidated payload');


/*To update the errors and status after the zip file is processed, call techbd_udi_ingress.sat_interaction_csv_request_upserted function with interaction_id, uri, error details and nature as 'Update Zip File Processing Details'.*/
v_zip_file_processing_errors := '{"error1": "error details 1", "error2": "error details 2"}';
v_status := 'PROCESSED';
v_interaction_id := NULL;
SELECT techbd_udi_ingress.sat_interaction_csv_request_upserted(
interaction_id => v_source_hub_interaction_id::text,
uri => v_interaction_key::text,
status => v_status::text,
zip_file_processing_errors => v_zip_file_processing_errors::jsonb,
nature => 'Update Zip File Processing Details'::text
) INTO v_interaction_id;

RETURN NEXT ok(v_interaction_id = v_source_hub_interaction_id, 'CSV - Successfully updated the table sat_interaction_zip_file_request with status and error details');


/* Last call to insert the FHIR bundle which is generated from CSV file with interaction_key = '/flatfile/csv/Bundle'*/
v_interaction_id := 'b99ddd45-9a4f-5cc8-9c5d-b45245d90fb0';
v_nature := '{"nature": "org.techbd.service.http.Interactions$RequestResponseEncountered", "tenant_id": "N/A"}';
Expand Down

0 comments on commit 76ccc9a

Please sign in to comment.