Skip to content
This repository has been archived by the owner on Jun 23, 2023. It is now read-only.

Commit

Permalink
API-2832 questionnaire read (#5)
Browse files Browse the repository at this point in the history
  • Loading branch information
jblefkove-va authored Nov 3, 2020
1 parent c934f98 commit 981257d
Show file tree
Hide file tree
Showing 27 changed files with 1,071 additions and 22 deletions.
1 change: 1 addition & 0 deletions make-configs.sh
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,5 @@ makeConfig patient-generated-data $PROFILE
configValue patient-generated-data $PROFILE spring.datasource.password '<YourStrong!Passw0rd>'
configValue patient-generated-data $PROFILE spring.datasource.url 'jdbc:sqlserver://localhost:1633;database=pgd;sendStringParametersAsUnicode=false'
configValue patient-generated-data $PROFILE spring.datasource.username 'SA'
configValue patient-generated-data $PROFILE web-exception-key '-sharktopus-v-pteracuda-'
checkForUnsetValues patient-generated-data $PROFILE
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
# patient-generated-data-local-db
# patient-generated-data-synthetic

This project builds a SQL Server Docker image
for local development. This is the operational database for
Patient Generated Data.
An H2 database instance is also built for use by integration tests.
Synthetic data for local and development environments.
This project also builds a SQL Server Docker image
for local development, and an H2 database for use by integration tests.

## Local Development

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,4 @@ docker run \
-p 1633:1433 \
-d mcr.microsoft.com/mssql/server:2017-latest

mvn clean install -Ppopulaterator -P'!standard'
mvn clean install -Ppopulaterator -P'!standard' -Dexec.cleanupDaemonThreads=false
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,12 @@
<version>7.0.15</version>
<relativePath/>
</parent>
<artifactId>patient-generated-data-local-db</artifactId>
<artifactId>patient-generated-data-synthetic</artifactId>
<version>0.0.7-SNAPSHOT</version>
<packaging>jar</packaging>
<properties>
<fhir-resources.version>5.0.11</fhir-resources.version>
<javax.el.version>3.0.1-b12</javax.el.version>
<populaterator.sqlserver>false</populaterator.sqlserver>
</properties>
<dependencies>
Expand All @@ -22,10 +24,24 @@
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
</dependency>
<dependency>
<groupId>gov.va.api.health</groupId>
<artifactId>us-core-r4</artifactId>
<version>${fhir-resources.version}</version>
</dependency>
<dependency>
<groupId>com.microsoft.sqlserver</groupId>
<artifactId>mssql-jdbc</artifactId>
</dependency>
<dependency>
<groupId>org.glassfish</groupId>
<artifactId>javax.el</artifactId>
<version>${javax.el.version}</version>
</dependency>
<dependency>
<groupId>org.hibernate.validator</groupId>
<artifactId>hibernate-validator</artifactId>
</dependency>
<dependency>
<groupId>org.liquibase</groupId>
<artifactId>liquibase-core</artifactId>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,23 @@
package gov.va.api.health.patientgenerateddata;

import static com.google.common.base.Preconditions.checkState;
import static java.util.stream.Collectors.joining;

import com.fasterxml.jackson.databind.ObjectMapper;
import gov.va.api.health.r4.api.resources.Questionnaire;
import java.io.File;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Optional;
import java.util.Set;
import java.util.concurrent.TimeUnit;
import java.util.stream.IntStream;
import javax.validation.ConstraintViolation;
import javax.validation.Validation;
import liquibase.Contexts;
import liquibase.LabelExpression;
import liquibase.Liquibase;
Expand All @@ -20,6 +31,12 @@
import lombok.Value;

public final class Populaterator {
private static final ObjectMapper MAPPER = new ObjectMapper();

private static String baseDir() {
return System.getProperty("basedir", ".");
}

@SneakyThrows
private static void bootstrap(@NonNull Db db) {
log("Bootstrapping " + db.name());
Expand All @@ -30,7 +47,6 @@ private static void bootstrap(@NonNull Db db) {
var conn = maybeConn.get();
for (var n : db.bootstrapDatabases()) {
log("Creating database " + n);
conn.prepareStatement("DROP DATABASE IF EXISTS " + n).execute();
conn.prepareStatement("CREATE DATABASE " + n).execute();
}
conn.commit();
Expand All @@ -43,10 +59,9 @@ private static void liquibase(@NonNull Db db) {
Database database =
DatabaseFactory.getInstance()
.findCorrectDatabaseImplementation(new JdbcConnection(connection));
String baseDir = System.getProperty("basedir", ".");
try (Liquibase liquibase =
new Liquibase(
baseDir
baseDir()
+ "/../patient-generated-data/src/main/resources/db/changelog/db.changelog-master.yaml",
new FileSystemResourceAccessor(),
database)) {
Expand All @@ -61,8 +76,10 @@ private static void log(@NonNull String msg) {
@SneakyThrows
public static void main(String[] args) {
if (Boolean.parseBoolean(System.getProperty("populaterator.h2", "true"))) {
String baseDir = System.getProperty("basedir", ".");
populate(H2.builder().dbFile(baseDir + "/target/pgd-db").build());
String dbFile = baseDir() + "/target/pgd-db";
new File(dbFile + ".mv.db").delete();
new File(dbFile + ".trace.db").delete();
populate(H2.builder().dbFile(dbFile).build());
}
if (Boolean.parseBoolean(System.getProperty("populaterator.sqlserver", "false"))) {
populate(
Expand All @@ -73,7 +90,6 @@ public static void main(String[] args) {
.password("<YourStrong!Passw0rd>")
.database("pgd")
.build());
System.exit(0);
}
}

Expand All @@ -84,12 +100,43 @@ private static void populate(@NonNull Db db) {
bootstrap(db);
liquibase(db);
var connection = db.connection();
// populate individual resources
questionnaire(connection);
connection.commit();
connection.close();
log("Finished " + db.name());
}

@SneakyThrows
private static void questionnaire(@NonNull Connection connection) {
Set<String> ids = new HashSet<>();
for (File f : new File(baseDir() + "/src/test/resources/questionnaire").listFiles()) {
Questionnaire questionnaire = MAPPER.readValue(f, Questionnaire.class);
Set<ConstraintViolation<Questionnaire>> violations =
Validation.buildDefaultValidatorFactory().getValidator().validate(questionnaire);
checkState(violations.isEmpty(), "Invalid payload: " + violations);

String id = questionnaire.id();
checkState(id != null);
checkState(!ids.contains(id), "Duplicate ID " + id);
ids.add(id);

try (PreparedStatement statement =
connection.prepareStatement(
"insert into app.questionnaire ("
+ "id,"
+ "payload,"
+ "version"
+ ") values ("
+ IntStream.range(0, 3).mapToObj(v -> "?").collect(joining(","))
+ ")")) {
statement.setObject(1, id);
statement.setObject(2, new ObjectMapper().writeValueAsString(questionnaire));
statement.setObject(3, 0);
statement.execute();
}
}
}

@SneakyThrows
private static void waitForStartup(@NonNull Db db) {
for (int i = 1; i <= 30; i++) {
Expand Down Expand Up @@ -131,8 +178,6 @@ public Optional<Connection> bootstrapConnection() {
@Override
@SneakyThrows
public Connection connection() {
new File(dbFile + ".mv.db").delete();
new File(dbFile + ".trace.db").delete();
return DriverManager.getConnection("jdbc:h2:" + dbFile, "sa", "sa");
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,157 @@
{
"resourceType" : "Questionnaire",
"id" : "3141",
"text" : {
"status" : "generated",
"div" : "<div xmlns=\"http://www.w3.org/1999/xhtml\"> <pre> 1.Comorbidity? 1.1 Cardial Comorbidity 1.1.1 Angina? 1.1.2 MI? 1.2 Vascular Comorbidity? ... Histopathology Abdominal pT category? ... </pre> </div>"
},
"url" : "http://hl7.org/fhir/Questionnaire/3141",
"title" : "Cancer Quality Forum Questionnaire 2012",
"status" : "draft",
"subjectType" : [
"Patient"
],
"date" : "2012-01",
"item" : [
{
"linkId" : "1",
"code" : [
{
"system" : "http://example.org/system/code/sections",
"code" : "COMORBIDITY"
}
],
"type" : "group",
"item" : [
{
"linkId" : "1.1",
"code" : [
{
"system" : "http://example.org/system/code/questions",
"code" : "COMORB"
}
],
"prefix" : "1",
"type" : "choice",
"answerValueSet" : "http://hl7.org/fhir/ValueSet/yesnodontknow",
"item" : [
{
"linkId" : "1.1.1",
"code" : [
{
"system" : "http://example.org/system/code/sections",
"code" : "CARDIAL"
}
],
"type" : "group",
"enableWhen" : [
{
"question" : "1.1",
"operator" : "=",
"answerCoding" : {
"system" : "http://terminology.hl7.org/CodeSystem/v2-0136",
"code" : "Y"
}
}
],
"item" : [
{
"linkId" : "1.1.1.1",
"code" : [
{
"system" : "http://example.org/system/code/questions",
"code" : "COMORBCAR"
}
],
"prefix" : "1.1",
"type" : "choice",
"answerValueSet" : "http://hl7.org/fhir/ValueSet/yesnodontknow",
"item" : [
{
"linkId" : "1.1.1.1.1",
"code" : [
{
"system" : "http://example.org/system/code/questions",
"code" : "COMCAR00",
"display" : "Angina Pectoris"
},
{
"system" : "http://snomed.info/sct",
"code" : "194828000",
"display" : "Angina (disorder)"
}
],
"prefix" : "1.1.1",
"type" : "choice",
"answerValueSet" : "http://hl7.org/fhir/ValueSet/yesnodontknow"
},
{
"linkId" : "1.1.1.1.2",
"code" : [
{
"system" : "http://snomed.info/sct",
"code" : "22298006",
"display" : "Myocardial infarction (disorder)"
}
],
"prefix" : "1.1.2",
"type" : "choice",
"answerValueSet" : "http://hl7.org/fhir/ValueSet/yesnodontknow"
}
]
},
{
"linkId" : "1.1.1.2",
"code" : [
{
"system" : "http://example.org/system/code/questions",
"code" : "COMORBVAS"
}
],
"prefix" : "1.2",
"type" : "choice",
"answerValueSet" : "http://hl7.org/fhir/ValueSet/yesnodontknow"
}
]
}
]
}
]
},
{
"linkId" : "2",
"code" : [
{
"system" : "http://example.org/system/code/sections",
"code" : "HISTOPATHOLOGY"
}
],
"type" : "group",
"item" : [
{
"linkId" : "2.1",
"code" : [
{
"system" : "http://example.org/system/code/sections",
"code" : "ABDOMINAL"
}
],
"type" : "group",
"item" : [
{
"linkId" : "2.1.2",
"code" : [
{
"system" : "http://example.org/system/code/questions",
"code" : "STADPT",
"display" : "pT category"
}
],
"type" : "choice"
}
]
}
]
}
]
}
Loading

0 comments on commit 981257d

Please sign in to comment.