Skip to content
This repository has been archived by the owner on Jan 28, 2024. It is now read-only.

Commit

Permalink
docs(readme): add sql deployment section
Browse files Browse the repository at this point in the history
  • Loading branch information
Frazer Smith committed Jan 8, 2021
1 parent 54e45aa commit b3af0c0
Show file tree
Hide file tree
Showing 3 changed files with 93 additions and 0 deletions.
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,13 @@ This is [Yeovil District Hospital NHSFT](https://yeovilhospital.co.uk/)'s backen
- [SQL Server](https://www.microsoft.com/en-gb/sql-server/sql-server-downloads)
- [Yarn](https://classic.yarnpkg.com)

### SQL Server setup

1. Connect to your SQL Server instance and use the script found in `./sql/create_tables.sql` to create the tables required for this app to function
2. Create a separate user account with read/write access to the database where you have chosen to create these tables, and the tables themselves

Make a note of the credentials of the user created, the server, the database the tables reside in, and the name of the tables (if changed from the originals in the script), as these are needed for the `DB_` environment variables in the `.env` file mentioned in the following deployment sections.

## Deployment

### Standard deployment
Expand Down
54 changes: 54 additions & 0 deletions sql/create_tables.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO

CREATE SCHEMA lookup;
GO

CREATE SCHEMA patient;
GO

CREATE SCHEMA receipt;
GO

CREATE TABLE lookup.preferenceType
(
preferenceTypeId INT IDENTITY(1,1) NOT NULL,
preferenceType VARCHAR(MAX) NOT NULL,
CONSTRAINT PK_PreferenceTypeId PRIMARY KEY (preferenceTypeId)
);
GO

CREATE TABLE lookup.preferenceValue
(
preferenceValueId INT IDENTITY(1,1) NOT NULL,
preferenceValue VARCHAR(255) NOT NULL,
CONSTRAINT PK_PreferenceValueId PRIMARY KEY (preferenceValueId)
);
GO

CREATE TABLE patient.preferences
(
patientId VARCHAR(255) NOT NULL,
preferenceTypeId INT NOT NULL,
preferenceValueId INT NULL,
preferencePriority INT NULL,
created DATETIME NOT NULL,
lastUpdated DATETIME,
CONSTRAINT CK_PatientPreference PRIMARY KEY (patientId, preferenceTypeId),
CONSTRAINT FK_PreferenceType FOREIGN KEY (preferenceTypeId) REFERENCES lookup.preferenceType(preferenceTypeId),
CONSTRAINT FK_PreferenceValue FOREIGN KEY (preferenceValueId) REFERENCES lookup.preferenceValue(preferenceValueid)
);
GO


CREATE TABLE receipt.documents
(
patientId VARCHAR(255) NOT NULL,
[guid] CHAR(36) NOT NULL,
ts DATETIME NOT NULL,
CONSTRAINT CK_DocumentReceipt PRIMARY KEY (patientId, [guid])
);
GO
32 changes: 32 additions & 0 deletions sql/insert_test_records.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO

INSERT INTO lookup.preferenceType
(preferenceType)
VALUES
('SMS'),
('Email'),
('Phone'),
('Letters');
GO

INSERT INTO lookup.preferenceValue
(preferenceValue)
VALUES
('yes'),
('no');
GO

INSERT INTO patient.preferences
(patientId, preferenceTypeId, preferenceValueId, preferencePriority, created)
VALUES
(1, 1, 1, 0, CURRENT_TIMESTAMP),
(1, 2, 2, 1, CURRENT_TIMESTAMP),
(1, 3, 1, 2, CURRENT_TIMESTAMP),
(1, 4, 2, 3, CURRENT_TIMESTAMP),
(2, 1, 1, 0, CURRENT_TIMESTAMP),
(2, 2, 2, 1, CURRENT_TIMESTAMP);
GO

0 comments on commit b3af0c0

Please sign in to comment.