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

Commit

Permalink
API-2835 QuestionnaireResponse synthetic data (#7)
Browse files Browse the repository at this point in the history
  • Loading branch information
apeirats-va authored Nov 16, 2020
1 parent 4ec4672 commit db86088
Show file tree
Hide file tree
Showing 6 changed files with 243 additions and 11 deletions.
2 changes: 1 addition & 1 deletion patient-generated-data-synthetic/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
<version>0.0.9-SNAPSHOT</version>
<packaging>jar</packaging>
<properties>
<fhir-resources.version>5.0.11</fhir-resources.version>
<fhir-resources.version>5.0.13</fhir-resources.version>
<javax.el.version>3.0.1-b12</javax.el.version>
<populaterator.sqlserver>false</populaterator.sqlserver>
</properties>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,12 @@

import com.fasterxml.jackson.databind.ObjectMapper;
import gov.va.api.health.r4.api.resources.Questionnaire;
import gov.va.api.health.r4.api.resources.QuestionnaireResponse;
import java.io.File;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.util.Collection;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
Expand Down Expand Up @@ -101,6 +103,7 @@ private static void populate(@NonNull Db db) {
liquibase(db);
var connection = db.connection();
questionnaire(connection);
questionnaireResponse(connection);
connection.commit();
connection.close();
log("Finished " + db.name());
Expand All @@ -120,15 +123,8 @@ private static void questionnaire(@NonNull Connection connection) {
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(","))
+ ")")) {
String sqlInsert = sqlInsert("app.Questionnaire", List.of("id", "payload", "version"));
try (PreparedStatement statement = connection.prepareStatement(sqlInsert)) {
statement.setObject(1, id);
statement.setObject(2, new ObjectMapper().writeValueAsString(questionnaire));
statement.setObject(3, 0);
Expand All @@ -137,6 +133,42 @@ private static void questionnaire(@NonNull Connection connection) {
}
}

@SneakyThrows
private static void questionnaireResponse(@NonNull Connection connection) {
Set<String> ids = new HashSet<>();

for (File f : new File(baseDir() + "/src/test/resources/questionnaireResponse").listFiles()) {
QuestionnaireResponse response = MAPPER.readValue(f, QuestionnaireResponse.class);
Set<ConstraintViolation<QuestionnaireResponse>> violations =
Validation.buildDefaultValidatorFactory().getValidator().validate(response);
checkState(violations.isEmpty(), "Invalid payload: " + violations);

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

String sqlInsert =
sqlInsert("app.QuestionnaireResponse", List.of("id", "payload", "version"));
try (PreparedStatement statement = connection.prepareStatement(sqlInsert)) {
statement.setObject(1, id);
statement.setObject(2, new ObjectMapper().writeValueAsString(response));
statement.setObject(3, 0);
statement.execute();
}
}
}

private static String sqlInsert(@NonNull String table, @NonNull Collection<String> columns) {
return "insert into "
+ table
+ " ("
+ columns.stream().collect(joining(","))
+ ") values ("
+ IntStream.range(0, columns.size()).mapToObj(v -> "?").collect(joining(","))
+ ")";
}

@SneakyThrows
private static void waitForStartup(@NonNull Db db) {
for (int i = 1; i <= 30; i++) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
{
"resourceType" : "QuestionnaireResponse",
"id" : "3141",
"text" : {
"status" : "generated",
"div" : "<div xmlns=\"http://www.w3.org/1999/xhtml\"> <pre> Comorbidity? YES Cardial Comorbidity? YES Angina? YES MI? NO Vascular Comorbidity? (no answers) ... Histopathology Abdominal pT category: 1a ... </pre> </div>"
},
"status" : "completed",
"authored" : "2013-02-19T14:15:00-05:00",
"item" : [
{
"linkId" : "1",
"item" : [
{
"linkId" : "1.1",
"answer" : [
{
"valueCoding" : {
"system" : "http://cancer.questionnaire.org/system/code/yesno",
"code" : "1",
"display" : "Yes"
},
"item" : [
{
"linkId" : "1.1.1",
"item" : [
{
"linkId" : "1.1.1.1",
"answer" : [
{
"valueCoding" : {
"system" : "http://cancer.questionnaire.org/system/code/yesno",
"code" : "1"
}
}
]
},
{
"linkId" : "1.1.1.2",
"answer" : [
{
"valueCoding" : {
"system" : "http://cancer.questionnaire.org/system/code/yesno",
"code" : "1"
}
}
]
},
{
"linkId" : "1.1.1.3",
"answer" : [
{
"valueCoding" : {
"system" : "http://cancer.questionnaire.org/system/code/yesno",
"code" : "0"
}
}
]
}
]
}
]
}
]
}
]
}
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
{
"resourceType" : "QuestionnaireResponse",
"id" : "f201",
"text" : {
"status" : "generated",
"div" : "<div xmlns=\"http://www.w3.org/1999/xhtml\"><p><b>Generated Narrative with Details</b></p><p><b>id</b>: f201</p><p><b>status</b>: completed</p><p><b>subject</b>: <a>Roel</a></p><p><b>authored</b>: 18/06/2013 12:00:00 AM</p><p><b>author</b>: <a>Practitioner/f201</a></p><p><b>source</b>: <a>Practitioner/f201</a></p><blockquote><p><b>item</b></p><p><b>linkId</b>: 1</p><h3>Items</h3><table><tr><td>-</td></tr><tr><td>*</td></tr></table></blockquote><blockquote><p><b>item</b></p><p><b>linkId</b>: 2</p><p><b>text</b>: General questions</p><h3>Items</h3><table><tr><td>-</td></tr><tr><td>*</td></tr><tr><td>*</td></tr><tr><td>*</td></tr><tr><td>*</td></tr></table></blockquote><blockquote><p><b>item</b></p><p><b>linkId</b>: 3</p><p><b>text</b>: Intoxications</p><h3>Items</h3><table><tr><td>-</td></tr><tr><td>*</td></tr><tr><td>*</td></tr></table></blockquote></div>"
},
"status" : "completed",
"authored" : "2013-06-18T00:00:00+01:00",
"item" : [
{
"linkId" : "1",
"item" : [
{
"linkId" : "1.1",
"text" : "Do you have allergies?",
"answer" : [
{
"valueString" : "I am allergic to house dust"
}
]
}
]
},
{
"linkId" : "2",
"text" : "General questions",
"item" : [
{
"linkId" : "2.1",
"text" : "What is your gender?",
"answer" : [
{
"valueString" : "Male"
}
]
},
{
"linkId" : "2.2",
"text" : "What is your date of birth?",
"answer" : [
{
"valueDate" : "1960-03-13"
}
]
},
{
"linkId" : "2.3",
"text" : "What is your country of birth?",
"answer" : [
{
"valueString" : "The Netherlands"
}
]
},
{
"linkId" : "2.4",
"text" : "What is your marital status?",
"answer" : [
{
"valueString" : "married"
}
]
}
]
},
{
"linkId" : "3",
"text" : "Intoxications",
"item" : [
{
"linkId" : "3.1",
"text" : "Do you smoke?",
"answer" : [
{
"valueString" : "No"
}
]
},
{
"linkId" : "3.2",
"text" : "Do you drink alchohol?",
"answer" : [
{
"valueString" : "No, but I used to drink"
}
]
}
]
}
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
@Data
@Entity
@Builder
@Table(name = "questionnaire", schema = "app")
@Table(name = "Questionnaire", schema = "app")
@NoArgsConstructor(access = AccessLevel.PRIVATE)
@AllArgsConstructor(access = AccessLevel.PRIVATE)
@EqualsAndHashCode(onlyExplicitlyIncluded = true)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,42 @@ databaseChangeLog:
type: int
constraints:
nullable: false

- changeSet:
id: 3
author: pteracuda
changes:
# table renames are *not* case sensitive, so rename to a temporary name first
- renameTable:
schemaName: app
oldTableName: questionnaire
newTableName: questionnaire_temp
- renameTable:
schemaName: app
oldTableName: questionnaire_temp
newTableName: Questionnaire

- changeSet:
id: 4
author: pteracuda
changes:
- createTable:
tableName: QuestionnaireResponse
schemaName: app
columns:
- column:
name: id
type: varchar(32)
constraints:
primaryKey: true
nullable: false
- column:
name: payload
type: clob
constraints:
nullable: false
- column:
name: version
type: int
constraints:
nullable: false

0 comments on commit db86088

Please sign in to comment.