Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .dockerignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
*/bin/
*/obj/
*/out/
*/.vs
.vscode
Expand Down
8 changes: 5 additions & 3 deletions containerize_leaf.sh
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
set -e

# Set configurable stuff
SA_PASSWORD=Th3PA55--8zz # DB password
Expand All @@ -15,7 +16,7 @@ if [ -z ${LEAF_JWT_KEY+x} ]; then echo "LEAF_JWT_KEY is unset!" exit; fi
if [ -z ${LEAF_JWT_KEY_PW+x} ]; then echo "LEAF_JWT_KEY_PW is unset!" exit; fi

# Extract cert/key path from ENVs
KEYS_PATH=`echo $LEAF_JWT_CERT | sed 's/\/cert.pem.*//'`
KEYS_PATH=$(dirname "$LEAF_JWT_CERT")
if [ -z ${KEYS_PATH+x} ]; then echo "Couldn't find cert+key path! Are you sure LEAF_JWT_CERT is a valid path?" && exit; fi

#--------------
Expand All @@ -25,7 +26,7 @@ docker run -d -e "ACCEPT_EULA=Y" -e "SA_PASSWORD=$SA_PASSWORD" -p 1433:1433 \
-v leaf_sqlvolume:/var/opt/mssql \
--name leaf_db_demo mcr.microsoft.com/mssql/server:2017-latest

sleep 10s
sleep 10

docker_sqlcmd() {
path="$1"
Expand All @@ -36,7 +37,7 @@ docker_sqlcmd() {
/opt/mssql-tools/bin/sqlcmd -S 'host.docker.internal' -U SA -P "$SA_PASSWORD" "$@" -i /sql/"$path"
}

docker_getDbs(){
docker_getDbs() {
docker run --rm \
-v "$PWD"/src/db/build/:/sql \
mcr.microsoft.com/mssql-tools \
Expand Down Expand Up @@ -67,6 +68,7 @@ docker run \
-e "LEAF_APP_DB=Server=$DB_SERVER,1433;Database=LeafDB;uid=sa;Password=$SA_PASSWORD" \
-e "LEAF_CLIN_DB=Server=$DB_SERVER,1433;Database=TestDB;uid=sa;Password=$SA_PASSWORD" \
-e "LEAF_JWT_KEY_PW=$LEAF_JWT_KEY_PW" \
-e "UnsecuredIsAdmin"="true" \
-p 5001:5001 \
-v ${PWD}/src/server:/app \
-v ${KEYS_PATH}:/.keys \
Expand Down
15 changes: 5 additions & 10 deletions src/db/build/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
FROM microsoft/mssql-server-linux:2017-latest
FROM mcr.microsoft.com/mssql/server:2017-latest

ARG sapw

RUN mkdir data

# Include schema and initial data
COPY ./LeafDB.sql ./LeafDB.Data.sql ./LeafDB.Exec.sql ./SynPuf_OMOP.Restore.sql ./SynPuf_OMOP.Shrink.sql ./
COPY ./SynPuf_OMOP.bak ./data/
COPY ./LeafDB.sql ./LeafDB.Init.sql ./TestDB.sql ./

# Accept EULA
ENV ACCEPT_EULA Y
Expand All @@ -20,10 +19,6 @@ VOLUME /bak
# Set up database
RUN /opt/mssql/bin/sqlservr & sleep 10 \
&& /opt/mssql-tools/bin/sqlcmd -S localhost -U SA -P ${MSSQL_SA_PASSWORD} -i ./LeafDB.sql \
&& /opt/mssql-tools/bin/sqlcmd -S localhost -U SA -P ${MSSQL_SA_PASSWORD} -i ./LeafDB.Data.sql \
&& /opt/mssql-tools/bin/sqlcmd -S localhost -U SA -P ${MSSQL_SA_PASSWORD} -i ./LeafDB.Exec.sql \
&& /opt/mssql-tools/bin/sqlcmd -S localhost -U SA -P ${MSSQL_SA_PASSWORD} -i ./SynPuf_OMOP.Restore.sql \
&& /opt/mssql-tools/bin/sqlcmd -S localhost -U SA -P ${MSSQL_SA_PASSWORD} -i ./SynPuf_OMOP.Shrink.sql \
&& pkill sqlservr

RUN rm /data/SynPuf_OMOP.bak
&& /opt/mssql-tools/bin/sqlcmd -S localhost -U SA -P ${MSSQL_SA_PASSWORD} -i ./LeafDB.Init.sql -d LeafDB \
&& /opt/mssql-tools/bin/sqlcmd -S localhost -U SA -P ${MSSQL_SA_PASSWORD} -i ./TestDB.sql \
Comment thread
ElevnLi marked this conversation as resolved.
&& pkill sqlservr
245 changes: 1 addition & 244 deletions src/db/build/TestDB.sql
Original file line number Diff line number Diff line change
Expand Up @@ -5,247 +5,4 @@ GO
* TestDB
*/
CREATE DATABASE [TestDB]
GO

ALTER DATABASE [TestDB] SET RECOVERY SIMPLE
GO

USE [TestDB]
GO

SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[person](
[person_id] [int] NULL,
[age] [int] NULL,
[gender] [nvarchar](20) NULL
) ON [PRIMARY]
GO

SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[visit_occurrence](
[person_id] [int] NULL,
[visit_occurrence_id] [int] NULL,
[visit_date] [datetime] NULL,
[visit_type] [nvarchar](10) NULL
) ON [PRIMARY]
GO

INSERT [dbo].[person] ([person_id], [age], [gender]) VALUES (1, 28, N'F')
GO
INSERT [dbo].[person] ([person_id], [age], [gender]) VALUES (2, 74, N'M')
GO
INSERT [dbo].[person] ([person_id], [age], [gender]) VALUES (3, 55, N'M')
GO
INSERT [dbo].[person] ([person_id], [age], [gender]) VALUES (4, 43, N'F')
GO
INSERT [dbo].[person] ([person_id], [age], [gender]) VALUES (5, 99, N'F')
GO
INSERT [dbo].[visit_occurrence] ([person_id], [visit_occurrence_id], [visit_date], [visit_type]) VALUES (1, 100, CAST(N'2020-08-14T00:00:00.000' AS DateTime), N'IP')
GO
INSERT [dbo].[visit_occurrence] ([person_id], [visit_occurrence_id], [visit_date], [visit_type]) VALUES (1, 101, CAST(N'2020-09-22T00:00:00.000' AS DateTime), N'OP')
GO
INSERT [dbo].[visit_occurrence] ([person_id], [visit_occurrence_id], [visit_date], [visit_type]) VALUES (2, 102, CAST(N'2018-06-01T00:00:00.000' AS DateTime), N'IP')
GO
INSERT [dbo].[visit_occurrence] ([person_id], [visit_occurrence_id], [visit_date], [visit_type]) VALUES (2, 103, CAST(N'2018-02-28T00:00:00.000' AS DateTime), N'ED')
GO
INSERT [dbo].[visit_occurrence] ([person_id], [visit_occurrence_id], [visit_date], [visit_type]) VALUES (3, 104, CAST(N'2015-01-01T00:00:00.000' AS DateTime), N'OP')
GO
INSERT [dbo].[visit_occurrence] ([person_id], [visit_occurrence_id], [visit_date], [visit_type]) VALUES (4, 105, CAST(N'2022-09-19T00:00:00.000' AS DateTime), N'OP')
GO
INSERT [dbo].[visit_occurrence] ([person_id], [visit_occurrence_id], [visit_date], [visit_type]) VALUES (4, 106, CAST(N'2028-01-01T00:00:00.000' AS DateTime), N'IP')
GO

USE [LeafDB]
GO


DECLARE @user NVARCHAR(20) = 'TestDB.sql'
DECLARE @yes BIT = 1
DECLARE @no BIT = 0

INSERT INTO app.ConceptSqlSet (SqlSetFrom, IsEncounterBased, IsEventBased, SqlFieldDate, Created, CreatedBy, Updated, UpdatedBy)
SELECT *
FROM (VALUES ('dbo.person', @no, @no, NULL, GETDATE(), @user, GETDATE(), @user),
('dbo.visit_occurrence', @yes, @no, '@.visit_date', GETDATE(), @user, GETDATE(), @user)
) AS X(col1,col2,col3,col4,col5,col6,col7,col8)

DECLARE @sqlset_person INT = (SELECT TOP 1 Id FROM LeafDB.app.ConceptSqlSet WHERE SqlSetFrom = 'dbo.person')
DECLARE @sqlset_visit_occurrence INT = (SELECT TOP 1 Id FROM LeafDB.app.ConceptSqlSet WHERE SqlSetFrom = 'dbo.visit_occurrence')

INSERT INTO app.Concept (ExternalId, ExternalParentId, [IsNumeric], IsParent, IsRoot, SqlSetId, SqlSetWhere,
SqlFieldNumeric, UiDisplayName, UiDisplayText, UiDisplayUnits, UiNumericDefaultText, UiDisplayPatientCount)
SELECT ExternalId = 'A'
, ExternalParentId = NULL
, [IsNumeric] = @no
, IsParent = @yes
, IsRoot = @yes
, SqlSetId = @sqlset_person
, SqlSetWhere = NULL
, SqlFieldNumeric = NULL
, UiDisplayName = 'Demographics'
, UiDisplayText = 'Have demographics'
, UiDisplayUnits = NULL
, UiNumericDefaultText = NULL
, UiDisplayPatientCount = (SELECT COUNT(*) FROM TestDB.dbo.person)
UNION ALL
SELECT ExternalId = 'A1'
, ExternalParentId = 'A'
, [IsNumeric] = @no
, IsParent = @yes
, IsRoot = @no
, SqlSetId = @sqlset_person
, SqlSetWhere = '@.gender IS NOT NULL'
, SqlFieldNumeric = NULL
, UiDisplayName = 'Gender'
, UiDisplayText = 'Identify with a gender'
, UiDisplayUnits = NULL
, UiNumericDefaultText = NULL
, UiDisplayPatientCount = (SELECT COUNT(*) FROM TestDB.dbo.person)
UNION ALL
SELECT ExternalId = 'A11'
, ExternalParentId = 'A1'
, [IsNumeric] = @no
, IsParent = @no
, IsRoot = @no
, SqlSetId = @sqlset_person
, SqlSetWhere = '@.gender = ''F'''
, SqlFieldNumeric = NULL
, UiDisplayName = 'Female'
, UiDisplayText = 'Identify as Female'
, UiDisplayUnits = NULL
, UiNumericDefaultText = NULL
, UiDisplayPatientCount = (SELECT COUNT(*) FROM TestDB.dbo.person WHERE gender = 'F')
UNION ALL
SELECT ExternalId = 'A12'
, ExternalParentId = 'A1'
, [IsNumeric] = @no
, IsParent = @no
, IsRoot = @no
, SqlSetId = @sqlset_person
, SqlSetWhere = '@.gender = ''M'''
, SqlFieldNumeric = NULL
, UiDisplayName = 'Male'
, UiDisplayText = 'Identify as Male'
, UiDisplayUnits = NULL
, UiNumericDefaultText = NULL
, UiDisplayPatientCount = (SELECT COUNT(*) FROM TestDB.dbo.person WHERE gender = 'M')
UNION ALL
SELECT ExternalId = 'A2'
, ExternalParentId = 'A'
, [IsNumeric] = @yes
, IsParent = @no
, IsRoot = @no
, SqlSetId = @sqlset_person
, SqlSetWhere = '@.age IS NOT NULL'
, SqlFieldNumeric = '@.age'
, UiDisplayName = 'Age'
, UiDisplayText = 'Are currently'
, UiDisplayUnits = 'years of age'
, UiNumericDefaultText = 'any age'
, UiDisplayPatientCount = (SELECT COUNT(*) FROM TestDB.dbo.person WHERE age IS NOT NULL)
UNION ALL
SELECT ExternalId = 'B'
, ExternalParentId = NULL
, [IsNumeric] = @no
, IsParent = @yes
, IsRoot = @yes
, SqlSetId = @sqlset_visit_occurrence
, SqlSetWhere = NULL
, SqlFieldNumeric = NULL
, UiDisplayName = 'Encounters'
, UiDisplayText = 'Had an encounter'
, UiDisplayUnits = NULL
, UiNumericDefaultText = NULL
, UiDisplayPatientCount = (SELECT COUNT(*) FROM TestDB.dbo.visit_occurrence)
UNION ALL
SELECT ExternalId = 'B1'
, ExternalParentId = 'B'
, [IsNumeric] = @no
, IsParent = @no
, IsRoot = @no
, SqlSetId = @sqlset_visit_occurrence
, SqlSetWhere = NULL
, SqlFieldNumeric = NULL
, UiDisplayName = 'Inpatient'
, UiDisplayText = 'Had an Inpatient encounter'
, UiDisplayUnits = NULL
, UiNumericDefaultText = NULL
, UiDisplayPatientCount = (SELECT COUNT(*) FROM TestDB.dbo.visit_occurrence WHERE visit_type = 'IP')
UNION ALL
SELECT ExternalId = 'B2'
, ExternalParentId = 'B'
, [IsNumeric] = @no
, IsParent = @no
, IsRoot = @no
, SqlSetId = @sqlset_visit_occurrence
, SqlSetWhere = NULL
, SqlFieldNumeric = NULL
, UiDisplayName = 'Outpatient'
, UiDisplayText = 'Had an Outpatient encounter'
, UiDisplayUnits = NULL
, UiNumericDefaultText = NULL
, UiDisplayPatientCount = (SELECT COUNT(*) FROM TestDB.dbo.visit_occurrence WHERE visit_type = 'OP')
UNION ALL
SELECT ExternalId = 'B3'
, ExternalParentId = 'B'
, [IsNumeric] = @no
, IsParent = @no
, IsRoot = @no
, SqlSetId = @sqlset_visit_occurrence
, SqlSetWhere = NULL
, SqlFieldNumeric = NULL
, UiDisplayName = 'Emergency'
, UiDisplayText = 'Had an Emergency Department encounter'
, UiDisplayUnits = NULL
, UiNumericDefaultText = NULL
, UiDisplayPatientCount = (SELECT COUNT(*) FROM TestDB.dbo.visit_occurrence WHERE visit_type = 'ED')



/**
* Set ParentId based on ExternalIds
*/
UPDATE LeafDB.app.Concept
SET ParentId = P.Id
FROM LeafDB.app.Concept AS C
INNER JOIN (SELECT P.Id, P.ParentId, P.ExternalId
FROM LeafDB.app.Concept AS P) AS P
ON C.ExternalParentID = P.ExternalID
WHERE C.ParentId IS NULL

/**
* Set RootIds
*/
; WITH roots AS
(
SELECT RootId = C.Id
, RootUiDisplayName = C.UiDisplayName
, C.IsRoot
, C.Id
, C.ParentId
, C.UiDisplayName
FROM LeafDB.app.Concept AS C
WHERE C.IsRoot = 1
UNION ALL
SELECT roots.RootId
, roots.RootUiDisplayName
, C2.IsRoot
, C2.Id
, C2.ParentId
, C2.UiDisplayName
FROM roots
INNER JOIN LeafDB.app.Concept AS C2
ON C2.ParentId = roots.Id
)
UPDATE LeafDB.app.Concept
SET RootId = roots.RootId
FROM LeafDB.app.Concept AS C
INNER JOIN roots
ON C.Id = roots.Id
WHERE C.RootId IS NULL
GO
53 changes: 53 additions & 0 deletions src/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
version: '3'
services:

db:
build:
context: ./db/build
args:
- sapw=${SA_PASSWORD}
image: leaf_db
container_name: leaf_db_demo
ports:
- 1433:1433
restart: always
networks:
- leaf

server:
build: ./server
image: leaf_api
container_name: leaf_api_demo
volumes:
- server-log:/logs
environment:
- LEAF_APP_DB=${LEAF_APP_DB}
- LEAF_CLIN_DB=${LEAF_CLIN_DB}
- LEAF_JWT_KEY_PW=${LEAF_JWT_KEY_PW}
- UnsecuredIsAdmin=${UnsecuredIsAdminProd}
restart: always
networks:
- leaf
depends_on:
- db

ui-client:
build:
context: ./ui-client
container_name: leaf_ui
ports:
- 80:80
restart: always
networks:
- leaf
stdin_open: true
depends_on:
- db
- server

networks:
leaf:


volumes:
server-log:
4 changes: 0 additions & 4 deletions src/server/.dockerignore
Original file line number Diff line number Diff line change
@@ -1,4 +0,0 @@
**/bin/
**/obj/
out/
.vs
Loading