Skip to content

Commit

Permalink
Merge pull request #779 from synthetichealth/procedure-fix
Browse files Browse the repository at this point in the history
Fix procedures with delays to ensure the record entry is only added once
  • Loading branch information
eedrummer authored Sep 3, 2020
2 parents b5da647 + 2fad978 commit 129825c
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 4 deletions.
19 changes: 16 additions & 3 deletions src/main/java/org/mitre/synthea/engine/State.java
Original file line number Diff line number Diff line change
Expand Up @@ -438,9 +438,24 @@ public abstract static class Delayable extends State {

public abstract long endOfDelay(long time, Person person);

/**
* Process any aspect of this state which should only happen once.
* Because of the nature of Delay states, this state may get called
* multiple times: once per timestep while delaying. To ensure
* any actions which are supposed to happen only happen once,
* this function should be overriden in subclasses.
*
* @param person the person being simulated
* @param time the date within the simulated world
*/
public void processOnce(Person person, long time) {
// do nothing. allow subclasses to override
}

@Override
public boolean process(Person person, long time) {
if (this.next == null) {
this.processOnce(person, time);
this.next = this.endOfDelay(time, person);
}

Expand Down Expand Up @@ -1366,7 +1381,7 @@ public long endOfDelay(long time, Person person) {
}

@Override
public boolean process(Person person, long time) {
public void processOnce(Person person, long time) {
String primaryCode = codes.get(0).code;
HealthRecord.Procedure procedure = person.record.procedure(time, primaryCode);
entry = procedure;
Expand Down Expand Up @@ -1406,8 +1421,6 @@ public boolean process(Person person, long time) {
if (assignToAttribute != null) {
person.attributes.put(assignToAttribute, procedure);
}

return super.process(person, time);
}
}

Expand Down
5 changes: 4 additions & 1 deletion src/test/java/org/mitre/synthea/engine/StateTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -617,7 +617,10 @@ public void procedure_during_encounter() throws Exception {
long nextStep = time + Utilities.convertTime("days", 7);
assertTrue(appendectomy.process(person, nextStep));

HealthRecord.Procedure proc = person.record.encounters.get(0).procedures.get(0);
List<HealthRecord.Procedure> procedures = person.record.encounters.get(0).procedures;
assertEquals(1, procedures.size());

HealthRecord.Procedure proc = procedures.get(0);
Code code = proc.codes.get(0);

assertEquals("6025007", code.code);
Expand Down

0 comments on commit 129825c

Please sign in to comment.