-
Notifications
You must be signed in to change notification settings - Fork 4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Adding Latest visit date and Correct TX Curr #50
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,40 +12,73 @@ | |
|
||
@Component | ||
public class GetTxCurr { | ||
|
||
private final GetDatePatientBecameIIT getDatePatientBecameIIT; | ||
|
||
private final GetInterruptedInTreatment getInterruptedInTreatment; | ||
|
||
private final GetTxCurrQueries getTxCurrQueries; | ||
|
||
public GetTxCurr(GetInterruptedInTreatment getInterruptedInTreatment, GetTxCurrQueries getTxCurrQueries) { | ||
this.getInterruptedInTreatment = getInterruptedInTreatment; | ||
this.getTxCurrQueries = getTxCurrQueries; | ||
public GetTxCurr(GetDatePatientBecameIIT getDatePatientBecameIIT) { | ||
this.getDatePatientBecameIIT = getDatePatientBecameIIT; | ||
} | ||
|
||
public List<GetTxNew.PatientEnrollmentData> getTxCurrPatients(Date startDate, Date endDate) { | ||
HashSet<Patient> allPatientsSet = getTxCurrQueries.getTxCurr(startDate, endDate); | ||
|
||
// Remove all deceased, IIT, and transferred-out patients | ||
HashSet<Patient> deceasedPatients = getDeceasedPatientsByDateRange(startDate, endDate); | ||
HashSet<Patient> transferredOutPatients = getTransferredOutClients(startDate, endDate); | ||
HashSet<Patient> iitPatients = getInterruptedInTreatment.getIit(startDate, endDate); | ||
|
||
allPatientsSet.removeAll(deceasedPatients); | ||
allPatientsSet.removeAll(transferredOutPatients); | ||
allPatientsSet.removeAll(iitPatients); | ||
|
||
// Convert patients to PatientEnrollmentData format | ||
List<GetTxNew.PatientEnrollmentData> result = new ArrayList<>(); | ||
for (Patient patient : allPatientsSet) { | ||
Obs enrollmentObs = getEnrollmentObsForPatient(patient); | ||
if (enrollmentObs != null) { | ||
result.add(new GetTxNew.PatientEnrollmentData(patient, enrollmentObs.getValueDate())); | ||
// Fetch enrollment dates and patient data | ||
List<Obs> enrollmentDateObs = Context.getObsService().getObservations(null, null, | ||
Collections.singletonList(Context.getConceptService().getConceptByUuid(DATE_OF_ENROLLMENT_UUID)), null, null, | ||
null, null, null, null, null, null, false); | ||
|
||
Set<Integer> uniquePatientIds = new HashSet<>(); | ||
List<GetTxNew.PatientEnrollmentData> filteredClients = new ArrayList<>(); | ||
|
||
for (Obs obs : enrollmentDateObs) { | ||
Date enrollmentDate = obs.getValueDate(); | ||
Person person = obs.getPerson(); | ||
|
||
// Check if the person is a patient and add if they haven't been added before | ||
if (enrollmentDate != null && person.isPatient() && uniquePatientIds.add(person.getId())) { | ||
Patient patient = Context.getPatientService().getPatient(person.getId()); | ||
|
||
// Retrieve death, transfer out, IIT, and RTT dates | ||
Date deathDate = getDeathDate(patient); | ||
Date transferOutDate = getTransferredOutDate(patient); | ||
Date iitDate = getDatePatientBecameIIT.getIitDateForPatient(patient); | ||
Date rttDate = getReturnedToTreatmentDate(patient); | ||
|
||
// Determine the earliest exclusion date | ||
Date exclusionDate = null; | ||
if (deathDate != null) | ||
exclusionDate = deathDate; | ||
if (transferOutDate != null) | ||
exclusionDate = (exclusionDate == null || transferOutDate.before(exclusionDate)) ? transferOutDate | ||
: exclusionDate; | ||
if (iitDate != null) | ||
exclusionDate = (exclusionDate == null || iitDate.before(exclusionDate)) ? iitDate : exclusionDate; | ||
|
||
// Adjust exclusion logic to consider RTT date | ||
if (exclusionDate != null) { | ||
if (exclusionDate.before(endDate) && exclusionDate.after(enrollmentDate)) { | ||
// If RTT date exists and is after exclusion, re-include patient from RTT onward | ||
if (rttDate != null && !rttDate.after(endDate)) { | ||
GetTxNew.PatientEnrollmentData patientData = new GetTxNew.PatientEnrollmentData(patient, | ||
rttDate); | ||
filteredClients.add(patientData); | ||
System.out.println("Including Patient: " + patient.getPersonName().getFullName() | ||
+ " due to return to treatment date: " + rttDate); | ||
continue; | ||
} | ||
System.out.println("Excluding Patient: " + patient.getPersonName().getFullName() | ||
+ " due to exclusion date: " + exclusionDate); | ||
Comment on lines
+67
to
+68
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Avoid logging patient names to prevent PII leakage Logging patient names can lead to exposure of sensitive personal information and violate privacy regulations. Replace Apply this diff to remove patient names from logs and use a logging framework: - System.out.println("Excluding Patient: " + patient.getPersonName().getFullName()
- + " due to exclusion date: " + exclusionDate);
+ logger.info("Excluding patient due to exclusion date: " + exclusionDate);
|
||
continue; | ||
} | ||
} | ||
|
||
// Add patient if the enrollment date is within the query range | ||
if (!enrollmentDate.after(endDate)) { | ||
GetTxNew.PatientEnrollmentData patientData = new GetTxNew.PatientEnrollmentData(patient, enrollmentDate); | ||
filteredClients.add(patientData); | ||
} | ||
} | ||
} | ||
|
||
// Remove duplicates and return the final list | ||
return new ArrayList<>(new LinkedHashSet<>(result)); | ||
|
||
|
||
return filteredClients; | ||
} | ||
|
||
private Obs getEnrollmentObsForPatient(Patient patient) { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Avoid logging patient names to prevent PII leakage
Logging patient names can lead to exposure of sensitive personal information and violate privacy regulations. Replace
System.out.println
statements with proper logging and avoid including personal identifiers.Apply this diff to remove patient names from logs and use a logging framework:
Ensure that a logging framework like SLF4J is used and properly configured: