Skip to content

Commit 129825c

Browse files
authored
Merge pull request #779 from synthetichealth/procedure-fix
Fix procedures with delays to ensure the record entry is only added once
2 parents b5da647 + 2fad978 commit 129825c

File tree

2 files changed

+20
-4
lines changed

2 files changed

+20
-4
lines changed

src/main/java/org/mitre/synthea/engine/State.java

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -438,9 +438,24 @@ public abstract static class Delayable extends State {
438438

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

441+
/**
442+
* Process any aspect of this state which should only happen once.
443+
* Because of the nature of Delay states, this state may get called
444+
* multiple times: once per timestep while delaying. To ensure
445+
* any actions which are supposed to happen only happen once,
446+
* this function should be overriden in subclasses.
447+
*
448+
* @param person the person being simulated
449+
* @param time the date within the simulated world
450+
*/
451+
public void processOnce(Person person, long time) {
452+
// do nothing. allow subclasses to override
453+
}
454+
441455
@Override
442456
public boolean process(Person person, long time) {
443457
if (this.next == null) {
458+
this.processOnce(person, time);
444459
this.next = this.endOfDelay(time, person);
445460
}
446461

@@ -1366,7 +1381,7 @@ public long endOfDelay(long time, Person person) {
13661381
}
13671382

13681383
@Override
1369-
public boolean process(Person person, long time) {
1384+
public void processOnce(Person person, long time) {
13701385
String primaryCode = codes.get(0).code;
13711386
HealthRecord.Procedure procedure = person.record.procedure(time, primaryCode);
13721387
entry = procedure;
@@ -1406,8 +1421,6 @@ public boolean process(Person person, long time) {
14061421
if (assignToAttribute != null) {
14071422
person.attributes.put(assignToAttribute, procedure);
14081423
}
1409-
1410-
return super.process(person, time);
14111424
}
14121425
}
14131426

src/test/java/org/mitre/synthea/engine/StateTest.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -617,7 +617,10 @@ public void procedure_during_encounter() throws Exception {
617617
long nextStep = time + Utilities.convertTime("days", 7);
618618
assertTrue(appendectomy.process(person, nextStep));
619619

620-
HealthRecord.Procedure proc = person.record.encounters.get(0).procedures.get(0);
620+
List<HealthRecord.Procedure> procedures = person.record.encounters.get(0).procedures;
621+
assertEquals(1, procedures.size());
622+
623+
HealthRecord.Procedure proc = procedures.get(0);
621624
Code code = proc.codes.get(0);
622625

623626
assertEquals("6025007", code.code);

0 commit comments

Comments
 (0)