Skip to content

Commit

Permalink
Merge pull request #1312 from synthetichealth/symptoms
Browse files Browse the repository at this point in the history
Symptoms
  • Loading branch information
eedrummer committed Jun 13, 2023
2 parents e02dc81 + 2dca863 commit f838c51
Show file tree
Hide file tree
Showing 3 changed files with 125 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/main/java/org/mitre/synthea/engine/ExpressedSymptom.java
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ public void addInfo(String cause, long time, int value, Boolean addressed) {
* Get the current value of the symptom.
*/
public Integer getCurrentValue() {
if (timeInfos.containsKey(lastUpdateTime)) {
if (lastUpdateTime != null && timeInfos.containsKey(lastUpdateTime)) {
return timeInfos.get(lastUpdateTime).getValue();
}
return null;
Expand Down Expand Up @@ -202,7 +202,7 @@ public String getSourceWithHighValue() {
* Method for retrieving the value associated to a given source.
*/
public Integer getValueFromSource(String source) {
if (!sources.containsKey(source)) {
if (source == null || !sources.containsKey(source)) {
return null;
}
return sources.get(source).getCurrentValue();
Expand All @@ -212,7 +212,7 @@ public Integer getValueFromSource(String source) {
* Method for addressing a given source.
*/
public void addressSource(String source) {
if (sources.containsKey(source)) {
if (source != null && sources.containsKey(source)) {
sources.get(source).resolve();
}
}
Expand All @@ -222,7 +222,7 @@ public void addressSource(String source) {
*/
public Long getSymptomLastUpdatedTime(String module) {
Long result = null;
if (sources.containsKey(module)) {
if (module != null && sources.containsKey(module)) {
result = sources.get(module).getLastUpdateTime();
}
return result;
Expand Down
1 change: 1 addition & 0 deletions src/main/java/org/mitre/synthea/export/CCDAExporter.java
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ public static String export(Person person, long time) {
// causes an exception, then we fake an insurance
// plan for the purposes of creating the super encounter.
person.coverage.setPlanToNoInsurance(time);
person.coverage.setPlanToNoInsurance(Long.MAX_VALUE);
}
// create a super encounter... this makes it easier to access
// all the Allergies (for example) in the export templates,
Expand Down
120 changes: 120 additions & 0 deletions src/test/java/org/mitre/synthea/engine/ExpressedSymptomTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
package org.mitre.synthea.engine;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;

import org.junit.Test;
import org.mitre.synthea.engine.ExpressedSymptom.SymptomInfo;
import org.mitre.synthea.engine.ExpressedSymptom.SymptomSource;

public class ExpressedSymptomTest {

@Test
public void testSymptomInfo() {
String name = "pain";
ExpressedSymptom symptom = new ExpressedSymptom(name);
String cause = "test";
Integer value = 100;
Long time = 0L;

SymptomInfo info = symptom.new SymptomInfo(cause, value, time);
assertEquals(cause, info.getCause());
assertEquals(value, info.getValue());
assertEquals(time, info.getTime());

SymptomInfo clone = info.clone();
assertEquals(info.getCause(), clone.getCause());
assertEquals(info.getValue(), clone.getValue());
assertEquals(info.getTime(), clone.getTime());
}

@Test
public void testSymptomSource() {
String name = "pain";
ExpressedSymptom symptom = new ExpressedSymptom(name);
String sourceName = "unit_test";

SymptomSource source = symptom.new SymptomSource(sourceName);
assertEquals(sourceName, source.getSource());
assertNull(source.getCurrentValue());
assertNull(source.getLastUpdateTime());
assertFalse(source.isResolved());
assertTrue(source.getTimeInfos().isEmpty());

source.resolve();
assertTrue(source.isResolved());

source.activate();
assertFalse(source.isResolved());

String causeA = "foo";
Integer valueA = 100;
Long timeA = 0L;

source.addInfo(causeA, timeA, valueA, false);
assertEquals(valueA, source.getCurrentValue());
assertEquals(timeA, source.getLastUpdateTime());
assertFalse(source.isResolved());
assertFalse(source.getTimeInfos().isEmpty());
assertEquals(valueA, source.getTimeInfos().get(timeA).getValue());

String causeB = "bar";
Integer valueB = 200;
Long timeB = 1L;

source.addInfo(causeB, timeB, valueB, true);
assertEquals(valueB, source.getCurrentValue());
assertEquals(timeB, source.getLastUpdateTime());
assertTrue(source.isResolved());
assertFalse(source.getTimeInfos().isEmpty());
assertEquals(valueB, source.getTimeInfos().get(timeB).getValue());
assertEquals(valueA, source.getTimeInfos().get(timeA).getValue());
}

@Test
public void testExpressedSymtpom() {
String name = "pain";
ExpressedSymptom symptom = new ExpressedSymptom(name);
assertTrue(symptom.getSources().isEmpty());
assertEquals(0, symptom.getSymptom());
assertNull(symptom.getSourceWithHighValue());
assertNull(symptom.getValueFromSource(null));
assertNull(symptom.getSymptomLastUpdatedTime(null));
symptom.addressSource(null);

String module = "testModule";
String cause = "testCause";
assertNull(symptom.getSourceWithHighValue());
assertNull(symptom.getValueFromSource(module));
assertNull(symptom.getSymptomLastUpdatedTime(module));
symptom.addressSource(module);

for (long l = 0L; l < 3L; l++) {
symptom.onSet(module, cause, l, (int) (100 * l), false);
assertEquals(module, symptom.getSourceWithHighValue());
assertEquals(Integer.valueOf((int) (100 * l)), symptom.getValueFromSource(module));
assertEquals((int) (100 * l), symptom.getSymptom());
assertEquals(Long.valueOf(l), symptom.getSymptomLastUpdatedTime(module));
}

String anotherModule = "anotherModule";
for (long l = 0L; l < 3L; l++) {
symptom.onSet(anotherModule, cause, l, (int) (10 * l), false);
assertEquals(module, symptom.getSourceWithHighValue());
assertEquals(Integer.valueOf((int) (10 * l)), symptom.getValueFromSource(anotherModule));
assertEquals(200, symptom.getSymptom());
assertEquals(Long.valueOf(l), symptom.getSymptomLastUpdatedTime(anotherModule));
}

symptom.addressSource(module);
assertEquals(anotherModule, symptom.getSourceWithHighValue());
assertEquals(20, symptom.getSymptom());
assertEquals(Integer.valueOf(20), symptom.getValueFromSource(anotherModule));

symptom.addressSource(anotherModule);
assertEquals(0, symptom.getSymptom());
assertNull(symptom.getSourceWithHighValue());
}
}

0 comments on commit f838c51

Please sign in to comment.