Skip to content

Commit

Permalink
Merge pull request #465 from synthetichealth/flapping_test
Browse files Browse the repository at this point in the history
Fix #454 intermittent failures.
  • Loading branch information
jawalonoski authored Jan 19, 2019
2 parents 070185e + 2b7e70b commit 4fbc463
Show file tree
Hide file tree
Showing 2 changed files with 114 additions and 9 deletions.
21 changes: 12 additions & 9 deletions src/main/java/org/mitre/synthea/modules/EncounterModule.java
Original file line number Diff line number Diff line change
Expand Up @@ -145,18 +145,18 @@ public static Code getWellnessVisitCode(Person person, long time) {
}
}

/**
* Process all emergency events. Emergency events must be processed immediately rather
* than waiting until the next timestep. Patient may die before the next timestep.
* @param person The patient having the emergency encounter.
* @param time The time of the encounter in milliseconds.
*/
public static void emergencyVisit(Person person, long time) {
// processes all emergency events. Implemented as a function instead of a rule because
// emergency events must be processed immediately rather than waiting til the next time
// period. Patient may die, resulting in rule not being called.

for (Event event : person.events.before(time, "emergency_encounter")) {
if (event.processed) {
continue;
}

event.processed = true;

emergencyEncounter(person, time);
}

Expand All @@ -165,11 +165,8 @@ public static void emergencyVisit(Person person, long time) {
|| event.type.equals("cardiac_arrest") || event.type.equals("stroke"))) {
continue;
}

event.processed = true;

CardiovascularDiseaseModule.performEmergency(person, time, event.type);

}
}

Expand All @@ -180,6 +177,9 @@ public static void emergencyEncounter(Person person, long time) {

Encounter encounter = person.record.encounterStart(time, "emergency");
encounter.codes.add(ENCOUNTER_EMERGENCY);
encounter.provider = provider;
encounter.clinician = provider.chooseClinicianList(ClinicianSpecialty.GENERAL_PRACTICE,
person.random);
// TODO: emergency encounters need their duration to be defined by the activities performed
// based on the emergencies given here (heart attack, stroke)
// assume people will be in the hospital for observation for a few days
Expand All @@ -193,6 +193,9 @@ public static void urgentCareEncounter(Person person, long time) {

Encounter encounter = person.record.encounterStart(time, "urgent_care");
encounter.codes.add(ENCOUNTER_URGENTCARE);
encounter.provider = provider;
encounter.clinician = provider.chooseClinicianList(ClinicianSpecialty.GENERAL_PRACTICE,
person.random);
// assume people will be in urgent care for one hour
person.record.encounterEnd(time + TimeUnit.HOURS.toMillis(1), "urgent_care");
}
Expand Down
102 changes: 102 additions & 0 deletions src/test/java/org/mitre/synthea/modules/EncounterModuleTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
package org.mitre.synthea.modules;

import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;

import java.io.IOException;

import org.junit.Before;
import org.junit.Test;
import org.mitre.synthea.world.agents.Person;
import org.mitre.synthea.world.agents.Provider;
import org.mitre.synthea.world.concepts.HealthRecord.Encounter;
import org.mitre.synthea.world.geography.Location;

public class EncounterModuleTest {

private Location location;
private Person person;
private EncounterModule module;

/**
* Setup the Encounter Module Tests.
* @throws IOException on loading error
*/
@Before
public void setup() throws IOException {
person = new Person(0L);
location = new Location("Massachusetts", null);
location.assignPoint(person, location.randomCityName(person.random));
Provider.loadProviders(location);
module = new EncounterModule();
}

@Test
public void testEmergencyEncounterHasClinician() {
EncounterModule.emergencyEncounter(person, System.currentTimeMillis());
assertNotNull(person.record);
assertFalse(person.record.encounters.isEmpty());
int last = person.record.encounters.size() - 1;
Encounter encounter = person.record.encounters.get(last);
assertNotNull("Encounter must have clinician", encounter.clinician);
assertNotNull("Encounter must have provider organization", encounter.provider);
}

@Test
public void testUrgentcareEncounterHasClinician() {
EncounterModule.urgentCareEncounter(person, System.currentTimeMillis());
assertNotNull(person.record);
assertFalse(person.record.encounters.isEmpty());
int last = person.record.encounters.size() - 1;
Encounter encounter = person.record.encounters.get(last);
assertNotNull("Encounter must have clinician", encounter.clinician);
assertNotNull("Encounter must have provider organization", encounter.provider);
}

@Test
public void testEncounterHasClinician() {
module.process(person, System.currentTimeMillis());
assertNotNull(person.record);
assertFalse(person.record.encounters.isEmpty());
int last = person.record.encounters.size() - 1;
Encounter encounter = person.record.encounters.get(last);
assertNotNull("Encounter must have clinician", encounter.clinician);
assertNotNull("Encounter must have provider organization", encounter.provider);
}

@Test
public void testEmergencySymptomEncounterHasClinician() {
person.setSymptom("Test", "Test", EncounterModule.EMERGENCY_SYMPTOM_THRESHOLD + 1, false);
module.process(person, System.currentTimeMillis());
assertNotNull(person.record);
assertFalse(person.record.encounters.isEmpty());
int last = person.record.encounters.size() - 1;
Encounter encounter = person.record.encounters.get(last);
assertNotNull("Encounter must have clinician", encounter.clinician);
assertNotNull("Encounter must have provider organization", encounter.provider);
}

@Test
public void testUrgentcareSymptomEncounterHasClinician() {
person.setSymptom("Test", "Test", EncounterModule.URGENT_CARE_SYMPTOM_THRESHOLD + 1, false);
module.process(person, System.currentTimeMillis());
assertNotNull(person.record);
assertFalse(person.record.encounters.isEmpty());
int last = person.record.encounters.size() - 1;
Encounter encounter = person.record.encounters.get(last);
assertNotNull("Encounter must have clinician", encounter.clinician);
assertNotNull("Encounter must have provider organization", encounter.provider);
}

@Test
public void testPrimarySymptomEncounterHasClinician() {
person.setSymptom("Test", "Test", EncounterModule.PCP_SYMPTOM_THRESHOLD + 1, false);
module.process(person, System.currentTimeMillis());
assertNotNull(person.record);
assertFalse(person.record.encounters.isEmpty());
int last = person.record.encounters.size() - 1;
Encounter encounter = person.record.encounters.get(last);
assertNotNull("Encounter must have clinician", encounter.clinician);
assertNotNull("Encounter must have provider organization", encounter.provider);
}
}

0 comments on commit 4fbc463

Please sign in to comment.