Skip to content

Commit

Permalink
bug: Phone Numbers are not loaded from webEOC (#279)
Browse files Browse the repository at this point in the history
  • Loading branch information
barrfalk authored Feb 12, 2024
1 parent 8f743bc commit 3be7baf
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 7 deletions.
40 changes: 35 additions & 5 deletions backend/db/migrations/R__0.14.0__CE-101.sql
Original file line number Diff line number Diff line change
@@ -1,7 +1,16 @@
CREATE OR replace FUNCTION PUBLIC.insert_complaint_from_staging(_complaint_identifier CHARACTER varying) returns void LANGUAGE plpgsql
CREATE OR replace FUNCTION PUBLIC.insert_complaint_from_staging(_complaint_identifier CHARACTER varying) returns void LANGUAGE plpgsql
AS
$function$
DECLARE
declare
non_digit_regex CONSTANT text := '[^\d]'; -- used to strip out non-numeric characters from the phone number fields

-- jsonb attribute names
jsonb_cos_primary_phone CONSTANT text := 'cos_primary_phone';
jsonb_cos_alt_phone CONSTANT text := 'cos_alt_phone';
jsonb_cos_alt_phone_2 CONSTANT text := 'cos_alt_phone_2';



complaint_data jsonb;
-- Variable to hold the JSONB data from staging_complaint. Used to create a new complaint
-- Variables for 'complaint' table
Expand Down Expand Up @@ -92,9 +101,30 @@ AS
ELSE
''
END;
_caller_phone_1 := left(regexp_replace(complaint_data ->> 'cos_primary_phone', '[^\d]', '', 'g'), 15);
_caller_phone_2 := left(regexp_replace(complaint_data ->> 'cos_alt_phone', '[^\d]', '', 'g'), 15);
_caller_phone_3 := left(regexp_replace(complaint_data ->> 'cos_alt_phone_2', '[^\d]', '', 'g'), 15);

-- phone numbers must be formatted as +1##########.
-- If the numbers from webeoc contain non-numeric characters, strip those and
-- add the + (or +1) prefix

_caller_phone_1 := CASE
WHEN left(regexp_replace(complaint_data ->> jsonb_cos_primary_phone, non_digit_regex, '', 'g'), 15) ~ '^1'
THEN '+' || left(regexp_replace(complaint_data ->> jsonb_cos_primary_phone, non_digit_regex, '', 'g'), 15)
ELSE '+1' || regexp_replace(complaint_data ->> jsonb_cos_primary_phone, non_digit_regex, '', 'g')
END;

_caller_phone_2 := CASE
WHEN left(regexp_replace(complaint_data ->> jsonb_cos_alt_phone, non_digit_regex, '', 'g'), 15) ~ '^1'
THEN '+' || left(regexp_replace(complaint_data ->> jsonb_cos_alt_phone, non_digit_regex, '', 'g'), 15)
ELSE '+1' || regexp_replace(complaint_data ->> jsonb_cos_alt_phone, non_digit_regex, '', 'g')
END;

_caller_phone_3 := CASE
WHEN left(regexp_replace(complaint_data ->> jsonb_cos_alt_phone_2, non_digit_regex, '', 'g'), 15) ~ '^1'
THEN '+' || left(regexp_replace(complaint_data ->> jsonb_cos_alt_phone_2, non_digit_regex, '', 'g'), 15)
ELSE '+1' || regexp_replace(complaint_data ->> jsonb_cos_alt_phone_2, non_digit_regex, '', 'g')
END;


_location_summary_text := left(complaint_data ->> 'address', 100)
||
CASE
Expand Down
4 changes: 2 additions & 2 deletions frontend/cypress/e2e/complaint-search.v2.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,14 +48,14 @@ describe("Complaint Search Functionality", () => {
cy.navigateToTab(complaintTypes[1], true);

//-- there should be a whole page of complaints
cy.get("#complaint-list tbody").find("tr").should("be.gt", 10);
cy.get("#complaint-list tbody").find("tr").should("have.length.at.least", 10);

//-- search for Oil and verify there's at least 23 complaints (this may increase as new complaints are added from WebEOC)
cy.get("#complaint-search").click({ force: true });
cy.get("#complaint-search").clear().type("Oil{enter}"); //-- {enter} will perform an enter keypress

//-- verify one complaint, and verify complaint-id
cy.get("#complaint-list tbody").find("tr").should("be.gt", 23);
cy.get("#complaint-list tbody").find("tr").should("have.length.at.least", 23);

//-- switch tabs
cy.get(complaintTypes[0]).click({ force: true });
Expand Down

0 comments on commit 3be7baf

Please sign in to comment.