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

Commit

Permalink
API-2834 observation synthetic data (#10)
Browse files Browse the repository at this point in the history
  • Loading branch information
that-guy-is-it authored Nov 18, 2020
1 parent 4b7c662 commit 0e505d8
Show file tree
Hide file tree
Showing 6 changed files with 264 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import static java.util.stream.Collectors.joining;

import com.fasterxml.jackson.databind.ObjectMapper;
import gov.va.api.health.r4.api.resources.Observation;
import gov.va.api.health.r4.api.resources.Questionnaire;
import gov.va.api.health.r4.api.resources.QuestionnaireResponse;
import java.io.File;
Expand Down Expand Up @@ -95,13 +96,39 @@ public static void main(String[] args) {
}
}

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

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

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

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

@SneakyThrows
private static void populate(@NonNull Db db) {
log("Populating " + db.name());
waitForStartup(db);
bootstrap(db);
liquibase(db);
var connection = db.connection();
observation(connection);
questionnaire(connection);
questionnaireResponse(connection);
connection.commit();
Expand All @@ -112,6 +139,7 @@ private static void populate(@NonNull Db db) {
@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 =
Expand All @@ -126,7 +154,7 @@ private static void questionnaire(@NonNull Connection connection) {
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(2, MAPPER.writeValueAsString(questionnaire));
statement.setObject(3, 0);
statement.execute();
}
Expand All @@ -137,7 +165,7 @@ private static void questionnaire(@NonNull Connection connection) {
private static void questionnaireResponse(@NonNull Connection connection) {
Set<String> ids = new HashSet<>();

for (File f : new File(baseDir() + "/src/test/resources/questionnaireResponse").listFiles()) {
for (File f : new File(baseDir() + "/src/test/resources/questionnaire-response").listFiles()) {
QuestionnaireResponse response = MAPPER.readValue(f, QuestionnaireResponse.class);
Set<ConstraintViolation<QuestionnaireResponse>> violations =
Validation.buildDefaultValidatorFactory().getValidator().validate(response);
Expand All @@ -152,7 +180,7 @@ private static void questionnaireResponse(@NonNull Connection connection) {
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(2, MAPPER.writeValueAsString(response));
statement.setObject(3, 0);
statement.execute();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
{
"resourceType" : "Observation",
"id" : "ekg",
"text" : {
"status" : "generated",
"div" : "<div xmlns=\"http://www.w3.org/1999/xhtml\"><p><b>Generated Narrative with Details</b></p><p><b>id</b>: ekg</p><p><b>status</b>: final</p><p><b>category</b>: Procedure <span>(Details : {http://terminology.hl7.org/CodeSystem/observation-category code 'procedure' = 'Procedure', given as 'Procedure'})</span></p><p><b>code</b>: MDC_ECG_ELEC_POTL <span>(Details : {urn:oid:2.16.840.1.113883.6.24 code '131328' = '131328', given as 'MDC_ECG_ELEC_POTL'})</span></p><p><b>subject</b>: <a>P. van de Heuvel</a></p><p><b>effective</b>: 19/02/2015 9:30:35 AM</p><p><b>performer</b>: <a>A. Langeveld</a></p><p><b>device</b>: 12 lead EKG Device Metric</p><blockquote><p><b>component</b></p><p><b>code</b>: MDC_ECG_ELEC_POTL_I <span>(Details : {urn:oid:2.16.840.1.113883.6.24 code '131329' = '131329', given as 'MDC_ECG_ELEC_POTL_I'})</span></p><p><b>value</b>: Origin: (system = '[not stated]' code null = 'null'), Period: 10, Factor: 1.612, Lower: -3300, Upper: 3300, Dimensions: 1, Data: 2041 2043 2037 2047 2060 2062 2051 2023 2014 2027 2034 2033 2040 2047 2047 2053 2058 2064 2059 2063 2061 2052 2053 2038 1966 1885 1884 2009 2129 2166 2137 2102 2086 2077 2067 2067 2060 2059 2062 2062 2060 2057 2045 2047 2057 2054 2042 2029 2027 2018 2007 1995 2001 2012 2024 2039 2068 2092 2111 2125 2131 2148 2137 2138 2128 2128 2115 2099 2097 2096 2101 2101 2091 2073 2076 2077 2084 2081 2088 2092 2070 2069 2074 2077 2075 2068 2064 2060 2062 2074 2075 2074 2075 2063 2058 2058 2064 2064 2070 2074 2067 2060 2062 2063 2061 2059 2048 2052 2049 2048 2051 2059 2059 2066 2077 2073</p></blockquote><blockquote><p><b>component</b></p><p><b>code</b>: MDC_ECG_ELEC_POTL_II <span>(Details : {urn:oid:2.16.840.1.113883.6.24 code '131330' = '131330', given as 'MDC_ECG_ELEC_POTL_II'})</span></p><p><b>value</b>: Origin: (system = '[not stated]' code null = 'null'), Period: 10, Factor: 1.612, Lower: -3300, Upper: 3300, Dimensions: 1, Data: 2041 2043 2037 2047 2060 2062 2051 2023 2014 2027 2034 2033 2040 2047 2047 2053 2058 2064 2059 2063 2061 2052 2053 2038 1966 1885 1884 2009 2129 2166 2137 2102 2086 2077 2067 2067 2060 2059 2062 2062 2060 2057 2045 2047 2057 2054 2042 2029 2027 2018 2007 1995 2001 2012 2024 2039 2068 2092 2111 2125 2131 2148 2137 2138 2128 2128 2115 2099 2097 2096 2101 2101 2091 2073 2076 2077 2084 2081 2088 2092 2070 2069 2074 2077 2075 2068 2064 2060 2062 2074 2075 2074 2075 2063 2058 2058 2064 2064 2070 2074 2067 2060 2062 2063 2061 2059 2048 2052 2049 2048 2051 2059 2059 2066 2077 2073</p></blockquote><blockquote><p><b>component</b></p><p><b>code</b>: MDC_ECG_ELEC_POTL_III <span>(Details : {urn:oid:2.16.840.1.113883.6.24 code '131389' = '131389', given as 'MDC_ECG_ELEC_POTL_III'})</span></p><p><b>value</b>: Origin: (system = '[not stated]' code null = 'null'), Period: 10, Factor: 1.612, Lower: -3300, Upper: 3300, Dimensions: 1, Data: 2041 2043 2037 2047 2060 2062 2051 2023 2014 2027 2034 2033 2040 2047 2047 2053 2058 2064 2059 2063 2061 2052 2053 2038 1966 1885 1884 2009 2129 2166 2137 2102 2086 2077 2067 2067 2060 2059 2062 2062 2060 2057 2045 2047 2057 2054 2042 2029 2027 2018 2007 1995 2001 2012 2024 2039 2068 2092 2111 2125 2131 2148 2137 2138 2128 2128 2115 2099 2097 2096 2101 2101 2091 2073 2076 2077 2084 2081 2088 2092 2070 2069 2074 2077 2075 2068 2064 2060 2062 2074 2075 2074 2075 2063 2058 2058 2064 2064 2070 2074 2067 2060 2062 2063 2061 2059 2048 2052 2049 2048 2051 2059 2059 2066 2077 2073</p></blockquote></div>"
},
"status" : "final",
"category" : [
{
"coding" : [
{
"system" : "http://terminology.hl7.org/CodeSystem/observation-category",
"code" : "procedure",
"display" : "Procedure"
}
]
}
],
"code" : {
"coding" : [
{
"system" : "urn:oid:2.16.840.1.113883.6.24",
"code" : "131328",
"display" : "MDC_ECG_ELEC_POTL"
}
]
},
"subject" : {
"reference" : "Patient/f001",
"display" : "P. van de Heuvel"
},
"effectiveDateTime" : "2015-02-19T09:30:35+01:00",
"performer" : [
{
"reference" : "Practitioner/f005",
"display" : "A. Langeveld"
}
],
"device" : {
"display" : "12 lead EKG Device Metric"
},
"component" : [
{
"code" : {
"coding" : [
{
"system" : "urn:oid:2.16.840.1.113883.6.24",
"code" : "131329",
"display" : "MDC_ECG_ELEC_POTL_I"
}
]
},
"valueSampledData" : {
"origin" : {
"value" : 2048
},
"period" : 10,
"factor" : 1.612,
"lowerLimit" : -3300,
"upperLimit" : 3300,
"dimensions" : 1,
"data" : "2041 2043 2037 2047 2060 2062 2051 2023 2014 2027 2034 2033 2040 2047 2047 2053 2058 2064 2059 2063 2061 2052 2053 2038 1966 1885 1884 2009 2129 2166 2137 2102 2086 2077 2067 2067 2060 2059 2062 2062 2060 2057 2045 2047 2057 2054 2042 2029 2027 2018 2007 1995 2001 2012 2024 2039 2068 2092 2111 2125 2131 2148 2137 2138 2128 2128 2115 2099 2097 2096 2101 2101 2091 2073 2076 2077 2084 2081 2088 2092 2070 2069 2074 2077 2075 2068 2064 2060 2062 2074 2075 2074 2075 2063 2058 2058 2064 2064 2070 2074 2067 2060 2062 2063 2061 2059 2048 2052 2049 2048 2051 2059 2059 2066 2077 2073"
}
},
{
"code" : {
"coding" : [
{
"system" : "urn:oid:2.16.840.1.113883.6.24",
"code" : "131330",
"display" : "MDC_ECG_ELEC_POTL_II"
}
]
},
"valueSampledData" : {
"origin" : {
"value" : 2048
},
"period" : 10,
"factor" : 1.612,
"lowerLimit" : -3300,
"upperLimit" : 3300,
"dimensions" : 1,
"data" : "2041 2043 2037 2047 2060 2062 2051 2023 2014 2027 2034 2033 2040 2047 2047 2053 2058 2064 2059 2063 2061 2052 2053 2038 1966 1885 1884 2009 2129 2166 2137 2102 2086 2077 2067 2067 2060 2059 2062 2062 2060 2057 2045 2047 2057 2054 2042 2029 2027 2018 2007 1995 2001 2012 2024 2039 2068 2092 2111 2125 2131 2148 2137 2138 2128 2128 2115 2099 2097 2096 2101 2101 2091 2073 2076 2077 2084 2081 2088 2092 2070 2069 2074 2077 2075 2068 2064 2060 2062 2074 2075 2074 2075 2063 2058 2058 2064 2064 2070 2074 2067 2060 2062 2063 2061 2059 2048 2052 2049 2048 2051 2059 2059 2066 2077 2073"
}
},
{
"code" : {
"coding" : [
{
"system" : "urn:oid:2.16.840.1.113883.6.24",
"code" : "131389",
"display" : "MDC_ECG_ELEC_POTL_III"
}
]
},
"valueSampledData" : {
"origin" : {
"value" : 2048
},
"period" : 10,
"factor" : 1.612,
"lowerLimit" : -3300,
"upperLimit" : 3300,
"dimensions" : 1,
"data" : "2041 2043 2037 2047 2060 2062 2051 2023 2014 2027 2034 2033 2040 2047 2047 2053 2058 2064 2059 2063 2061 2052 2053 2038 1966 1885 1884 2009 2129 2166 2137 2102 2086 2077 2067 2067 2060 2059 2062 2062 2060 2057 2045 2047 2057 2054 2042 2029 2027 2018 2007 1995 2001 2012 2024 2039 2068 2092 2111 2125 2131 2148 2137 2138 2128 2128 2115 2099 2097 2096 2101 2101 2091 2073 2076 2077 2084 2081 2088 2092 2070 2069 2074 2077 2075 2068 2064 2060 2062 2074 2075 2074 2075 2063 2058 2058 2064 2064 2070 2074 2067 2060 2062 2063 2061 2059 2048 2052 2049 2048 2051 2059 2059 2066 2077 2073"
}
}
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
{
"resourceType" : "Observation",
"id" : "satO2",
"meta" : {
"profile" : [
"http://hl7.org/fhir/StructureDefinition/vitalsigns"
]
},
"text" : {
"status" : "generated",
"div" : "<div xmlns=\"http://www.w3.org/1999/xhtml\"><p><b>Generated Narrative with Details</b></p><p><b>id</b>: satO2</p><p><b>meta</b>: </p><p><b>identifier</b>: o1223435-10</p><p><b>partOf</b>: <a>Procedure/ob</a></p><p><b>status</b>: final</p><p><b>category</b>: Vital Signs <span>(Details : {http://terminology.hl7.org/CodeSystem/observation-category code 'vital-signs' = 'Vital Signs', given as 'Vital Signs'})</span></p><p><b>code</b>: Oxygen saturation in Arterial blood <span>(Details : {LOINC code '2708-6' = 'Oxygen saturation in Arterial blood', given as 'Oxygen saturation in Arterial blood'}; {LOINC code '59408-5' = 'Oxygen saturation in Arterial blood by Pulse oximetry', given as 'Oxygen saturation in Arterial blood by Pulse oximetry'}; {urn:iso:std:iso:11073:10101 code '150456' = '150456', given as 'MDC_PULS_OXIM_SAT_O2'})</span></p><p><b>subject</b>: <a>Patient/example</a></p><p><b>effective</b>: 05/12/2014 9:30:10 AM</p><p><b>value</b>: 95 %<span> (Details: UCUM code % = '%')</span></p><p><b>interpretation</b>: Normal (applies to non-numeric results) <span>(Details : {http://terminology.hl7.org/CodeSystem/v3-ObservationInterpretation code 'N' = 'Normal', given as 'Normal'})</span></p><p><b>device</b>: <a>DeviceMetric/example</a></p><h3>ReferenceRanges</h3><table><tr><td>-</td><td><b>Low</b></td><td><b>High</b></td></tr><tr><td>*</td><td>90 %<span> (Details: UCUM code % = '%')</span></td><td>99 %<span> (Details: UCUM code % = '%')</span></td></tr></table></div>"
},
"identifier" : [
{
"system" : "http://goodcare.org/observation/id",
"value" : "o1223435-10"
}
],
"partOf" : [
{
"reference" : "Procedure/ob"
}
],
"status" : "final",
"category" : [
{
"coding" : [
{
"system" : "http://terminology.hl7.org/CodeSystem/observation-category",
"code" : "vital-signs",
"display" : "Vital Signs"
}
],
"text" : "Vital Signs"
}
],
"code" : {
"coding" : [
{
"system" : "http://loinc.org",
"code" : "2708-6",
"display" : "Oxygen saturation in Arterial blood"
},
{
"system" : "http://loinc.org",
"code" : "59408-5",
"display" : "Oxygen saturation in Arterial blood by Pulse oximetry"
},
{
"system" : "urn:iso:std:iso:11073:10101",
"code" : "150456",
"display" : "MDC_PULS_OXIM_SAT_O2"
}
]
},
"subject" : {
"reference" : "Patient/example"
},
"effectiveDateTime" : "2014-12-05T09:30:10+01:00",
"valueQuantity" : {
"value" : 95,
"unit" : "%",
"system" : "http://unitsofmeasure.org",
"code" : "%"
},
"interpretation" : [
{
"coding" : [
{
"system" : "http://terminology.hl7.org/CodeSystem/v3-ObservationInterpretation",
"code" : "N",
"display" : "Normal"
}
],
"text" : "Normal (applies to non-numeric results)"
}
],
"device" : {
"reference" : "DeviceMetric/example"
},
"referenceRange" : [
{
"low" : {
"value" : 90,
"unit" : "%",
"system" : "http://unitsofmeasure.org",
"code" : "%"
},
"high" : {
"value" : 99,
"unit" : "%",
"system" : "http://unitsofmeasure.org",
"code" : "%"
}
}
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -72,3 +72,28 @@ databaseChangeLog:
type: int
constraints:
nullable: false

- changeSet:
id: 5
author: pteracuda
changes:
- createTable:
tableName: Observation
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 0e505d8

Please sign in to comment.