Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
## Synthetic data generator

**Version 2.6**

- Fixed issue in DOLC that would produce tumors with vital status 0 (dead) and DX date later than DOLC.

**Version 2.5**

- Updated dependencies.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
package com.imsweb.datagenerator.naaccr.rule.tumor;

import java.time.LocalDate;
import java.util.Arrays;
import java.util.List;
import java.util.Map;

import com.imsweb.datagenerator.naaccr.NaaccrDataGeneratorOptions;
import com.imsweb.datagenerator.naaccr.NaaccrDataGeneratorTumorRule;
import com.imsweb.naaccrxml.entity.AbstractEntity;
import com.imsweb.naaccrxml.entity.Patient;
import com.imsweb.naaccrxml.entity.Tumor;

Expand All @@ -29,9 +31,23 @@ public List<String> getRequiredProperties() {
@Override
public void execute(Tumor tumor, Patient patient, NaaccrDataGeneratorOptions options, Map<String, Object> context) {

// for now this is set to the DX date (they are assigned in order, so the DOLC will end up being the last one)
setValue(patient, "dateOfLastContactYear", tumor.getItemValue("dateOfDiagnosisYear"));
setValue(patient, "dateOfLastContactMonth", tumor.getItemValue("dateOfDiagnosisMonth"));
setValue(patient, "dateOfLastContactDay", tumor.getItemValue("dateOfDiagnosisDay"));
LocalDate diagnosisDate = getDate(tumor, "dateOfDiagnosis");
LocalDate lastContactDate = getDate(patient, "dateOfLastContact");

// Diagnosis dates are not guaranteed to be generated in chronological order, so retain the latest one.
if (diagnosisDate != null && (lastContactDate == null || diagnosisDate.isAfter(lastContactDate))) {
setValue(patient, "dateOfLastContactYear", tumor.getItemValue("dateOfDiagnosisYear"));
setValue(patient, "dateOfLastContactMonth", tumor.getItemValue("dateOfDiagnosisMonth"));
setValue(patient, "dateOfLastContactDay", tumor.getItemValue("dateOfDiagnosisDay"));
}
}

private LocalDate getDate(AbstractEntity entity, String property) {
String year = entity.getItemValue(property + "Year");
String month = entity.getItemValue(property + "Month");
String day = entity.getItemValue(property + "Day");
if (year == null || month == null || day == null)
return null;
return LocalDate.of(Integer.parseInt(year), Integer.parseInt(month), Integer.parseInt(day));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,26 @@ public void testExecute() {
Assert.assertEquals("04", patient.getItemValue("dateOfLastContactDay"));

}

@Test
public void testDeadPatientWithOutOfOrderDiagnosisDates() {
Patient patient = new Patient();
patient.addItem(new Item("vitalStatus", "0"));

Tumor laterTumor = new Tumor();
laterTumor.addItem(new Item("dateOfDiagnosisYear", "2006"));
laterTumor.addItem(new Item("dateOfDiagnosisMonth", "08"));
laterTumor.addItem(new Item("dateOfDiagnosisDay", "05"));
_rule.execute(laterTumor, patient, null, new HashMap<>());

Tumor earlierTumor = new Tumor();
earlierTumor.addItem(new Item("dateOfDiagnosisYear", "2005"));
earlierTumor.addItem(new Item("dateOfDiagnosisMonth", "07"));
earlierTumor.addItem(new Item("dateOfDiagnosisDay", "04"));
_rule.execute(earlierTumor, patient, null, new HashMap<>());

Assert.assertEquals("2006", patient.getItemValue("dateOfLastContactYear"));
Assert.assertEquals("08", patient.getItemValue("dateOfLastContactMonth"));
Assert.assertEquals("05", patient.getItemValue("dateOfLastContactDay"));
}
}
Loading