From aafc593eb9f3aabce8cd7abc98e2448833b00c13 Mon Sep 17 00:00:00 2001 From: stephhou Date: Fri, 10 Apr 2026 16:52:39 +0100 Subject: [PATCH 1/8] feature: New SQL script to copy NHS numbers into CSV file on AVD --- scripts/sql/export_valid_responses.sql | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 scripts/sql/export_valid_responses.sql diff --git a/scripts/sql/export_valid_responses.sql b/scripts/sql/export_valid_responses.sql new file mode 100644 index 00000000..70dbc911 --- /dev/null +++ b/scripts/sql/export_valid_responses.sql @@ -0,0 +1,6 @@ +# SQL script to export valid responses to a CSV file on to AVD +# Run script using psql command line tool or pgAdmin query tool + +\set ON_ERROR_STOP on +\copy (SELECT DISTINCT qu.nhs_number FROM questions_user qu JOIN questions_responseset qrs ON qrs.user_id = qu.id JOIN questions_checkneedappointmentresponse qcnar ON qcnar.response_set_id = qrs.id WHERE qcnar.value = TRUE OR qrs.submitted_at IS NOT NULL) TO 'C:/Users/*YourUsername*/Documents/valid_responses.csv' WITH (FORMAT csv, HEADER true); + From 44cf3069da5a88a9bde04b35d9a5cfc77564f685 Mon Sep 17 00:00:00 2001 From: stephhou Date: Fri, 10 Apr 2026 16:58:18 +0100 Subject: [PATCH 2/8] fix: fixed comments --- scripts/sql/export_valid_responses.sql | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/scripts/sql/export_valid_responses.sql b/scripts/sql/export_valid_responses.sql index 70dbc911..7b4ea5c3 100644 --- a/scripts/sql/export_valid_responses.sql +++ b/scripts/sql/export_valid_responses.sql @@ -1,5 +1,6 @@ -# SQL script to export valid responses to a CSV file on to AVD -# Run script using psql command line tool or pgAdmin query tool +-- SQL script to export a csv file containing NHS numbers of valid responses to a CSV file on to AVD. +-- A valid response is defined as a response where the user has either submitted a response set or has a response to the question "Do you think you need to see a doctor about your symptoms?" with a value of "Yes". +-- Run script using psql command line tool or pgAdmin query tool \set ON_ERROR_STOP on \copy (SELECT DISTINCT qu.nhs_number FROM questions_user qu JOIN questions_responseset qrs ON qrs.user_id = qu.id JOIN questions_checkneedappointmentresponse qcnar ON qcnar.response_set_id = qrs.id WHERE qcnar.value = TRUE OR qrs.submitted_at IS NOT NULL) TO 'C:/Users/*YourUsername*/Documents/valid_responses.csv' WITH (FORMAT csv, HEADER true); From 129da1160806f23bb37123764286825f2c71e79c Mon Sep 17 00:00:00 2001 From: stephhou Date: Fri, 10 Apr 2026 17:00:38 +0100 Subject: [PATCH 3/8] fix: fixed comments --- scripts/sql/export_valid_responses.sql | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/sql/export_valid_responses.sql b/scripts/sql/export_valid_responses.sql index 7b4ea5c3..73968adc 100644 --- a/scripts/sql/export_valid_responses.sql +++ b/scripts/sql/export_valid_responses.sql @@ -1,5 +1,5 @@ -- SQL script to export a csv file containing NHS numbers of valid responses to a CSV file on to AVD. --- A valid response is defined as a response where the user has either submitted a response set or has a response to the question "Do you think you need to see a doctor about your symptoms?" with a value of "Yes". +-- A valid response is defined as a response where the user has either submitted the questionnaire or has a response to the question "Do you need a face to face appointment?" with a value of "Yes". -- Run script using psql command line tool or pgAdmin query tool \set ON_ERROR_STOP on From d884a6eeaccb23981521a47e9348255b542b0e7b Mon Sep 17 00:00:00 2001 From: stephhou Date: Mon, 13 Apr 2026 12:40:14 +0100 Subject: [PATCH 4/8] fix: removed check need appointment condition --- scripts/sql/export_valid_responses.sql | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/sql/export_valid_responses.sql b/scripts/sql/export_valid_responses.sql index 73968adc..4651c448 100644 --- a/scripts/sql/export_valid_responses.sql +++ b/scripts/sql/export_valid_responses.sql @@ -3,5 +3,5 @@ -- Run script using psql command line tool or pgAdmin query tool \set ON_ERROR_STOP on -\copy (SELECT DISTINCT qu.nhs_number FROM questions_user qu JOIN questions_responseset qrs ON qrs.user_id = qu.id JOIN questions_checkneedappointmentresponse qcnar ON qcnar.response_set_id = qrs.id WHERE qcnar.value = TRUE OR qrs.submitted_at IS NOT NULL) TO 'C:/Users/*YourUsername*/Documents/valid_responses.csv' WITH (FORMAT csv, HEADER true); +\copy (SELECT DISTINCT qu.nhs_number FROM questions_user qu JOIN questions_responseset qrs ON qrs.user_id = qu.id WHERE qrs.submitted_at IS NOT NULL) TO 'C:/Users/*YourUsername*/Documents/valid_responses.csv' WITH (FORMAT csv, HEADER true); From 18932e61d3e87daedd6f29b5d3d309cef4be910f Mon Sep 17 00:00:00 2001 From: stephhou Date: Mon, 13 Apr 2026 12:48:43 +0100 Subject: [PATCH 5/8] chore: updated comments to match script --- scripts/sql/export_valid_responses.sql | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/scripts/sql/export_valid_responses.sql b/scripts/sql/export_valid_responses.sql index 4651c448..928c2733 100644 --- a/scripts/sql/export_valid_responses.sql +++ b/scripts/sql/export_valid_responses.sql @@ -1,6 +1,6 @@ --- SQL script to export a csv file containing NHS numbers of valid responses to a CSV file on to AVD. --- A valid response is defined as a response where the user has either submitted the questionnaire or has a response to the question "Do you need a face to face appointment?" with a value of "Yes". --- Run script using psql command line tool or pgAdmin query tool +-- SQL script to export a csv file containing NHS numbers of submitted responses to a CSV file on to AVD. +-- A valid response is defined as a response where the user has submitted the questionnaire. +-- Run script using psql command line tool or pgAdmin query tool on AVD. \set ON_ERROR_STOP on \copy (SELECT DISTINCT qu.nhs_number FROM questions_user qu JOIN questions_responseset qrs ON qrs.user_id = qu.id WHERE qrs.submitted_at IS NOT NULL) TO 'C:/Users/*YourUsername*/Documents/valid_responses.csv' WITH (FORMAT csv, HEADER true); From 138a4e064efc61c55b070d32745cbaffdde061ca Mon Sep 17 00:00:00 2001 From: stephhou Date: Mon, 13 Apr 2026 13:11:08 +0100 Subject: [PATCH 6/8] fix: typo in comments --- scripts/sql/export_valid_responses.sql | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/sql/export_valid_responses.sql b/scripts/sql/export_valid_responses.sql index 928c2733..66ab84b1 100644 --- a/scripts/sql/export_valid_responses.sql +++ b/scripts/sql/export_valid_responses.sql @@ -1,4 +1,4 @@ --- SQL script to export a csv file containing NHS numbers of submitted responses to a CSV file on to AVD. +-- SQL script to export a csv file containing NHS numbers of submitted responses to a folder on an AVD. -- A valid response is defined as a response where the user has submitted the questionnaire. -- Run script using psql command line tool or pgAdmin query tool on AVD. From db95530dd4edc6129e44bcecb96789b7ef9edd0c Mon Sep 17 00:00:00 2001 From: Steph Housden <167300771+stephhou@users.noreply.github.com> Date: Tue, 21 Apr 2026 13:30:42 +0100 Subject: [PATCH 7/8] Update scripts/sql/export_valid_responses.sql Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> Signed-off-by: Steph Housden <167300771+stephhou@users.noreply.github.com> --- scripts/sql/export_valid_responses.sql | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/sql/export_valid_responses.sql b/scripts/sql/export_valid_responses.sql index 66ab84b1..1d8f63e2 100644 --- a/scripts/sql/export_valid_responses.sql +++ b/scripts/sql/export_valid_responses.sql @@ -1,6 +1,6 @@ -- SQL script to export a csv file containing NHS numbers of submitted responses to a folder on an AVD. -- A valid response is defined as a response where the user has submitted the questionnaire. --- Run script using psql command line tool or pgAdmin query tool on AVD. +-- Run script using the psql command line tool on AVD; this file uses psql meta-commands (\set, \copy) and will not run in pgAdmin Query Tool. \set ON_ERROR_STOP on \copy (SELECT DISTINCT qu.nhs_number FROM questions_user qu JOIN questions_responseset qrs ON qrs.user_id = qu.id WHERE qrs.submitted_at IS NOT NULL) TO 'C:/Users/*YourUsername*/Documents/valid_responses.csv' WITH (FORMAT csv, HEADER true); From 41807216e03ee4cc5d2fd263e8593674fc182d1b Mon Sep 17 00:00:00 2001 From: stephhou <167300771+stephhou@users.noreply.github.com> Date: Thu, 23 Apr 2026 14:58:05 +0100 Subject: [PATCH 8/8] fix: update file path and comments --- scripts/sql/export_valid_responses.sql | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/scripts/sql/export_valid_responses.sql b/scripts/sql/export_valid_responses.sql index 1d8f63e2..fb2d3155 100644 --- a/scripts/sql/export_valid_responses.sql +++ b/scripts/sql/export_valid_responses.sql @@ -1,7 +1,8 @@ -- SQL script to export a csv file containing NHS numbers of submitted responses to a folder on an AVD. -- A valid response is defined as a response where the user has submitted the questionnaire. --- Run script using the psql command line tool on AVD; this file uses psql meta-commands (\set, \copy) and will not run in pgAdmin Query Tool. +-- Run script using the psql command line tool on AVD. +-- Update PATH_TO_EXPORT_FILE before running to specify the location and name of the exported file. The file will be created if it does not exist, or overwritten if it does. \set ON_ERROR_STOP on -\copy (SELECT DISTINCT qu.nhs_number FROM questions_user qu JOIN questions_responseset qrs ON qrs.user_id = qu.id WHERE qrs.submitted_at IS NOT NULL) TO 'C:/Users/*YourUsername*/Documents/valid_responses.csv' WITH (FORMAT csv, HEADER true); +\copy (SELECT DISTINCT qu.nhs_number FROM questions_user qu JOIN questions_responseset qrs ON qrs.user_id = qu.id WHERE qrs.submitted_at IS NOT NULL) TO 'PATH_TO_EXPORT_FILE' WITH (FORMAT csv, HEADER true);