Fix PatientIdPartitionInterceptor where patient ID has hashCode equal to Integer.MIN_VALUE. (#3275)

* Fix PatientIdPartitionInterceptor for case where patient ID has hashCode equal to Integer.MIN_VALUE

* Fix PatientIdPartitionInterceptor for case where patient ID has hashCode equal to Integer.MIN_VALUE

Co-authored-by: ianmarshall <ian@simpatico.ai>
This commit is contained in:
IanMMarshall 2022-01-06 15:00:33 +00:00 committed by GitHub
parent c38fdc4c42
commit 095b959917
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 23 additions and 1 deletions

View File

@ -0,0 +1,5 @@
---
type: fix
issue: 3275
title: "In rare cases where patient ID String happened to have hashCode equal to Integer.MIN_VALUE,
PatientIdPartitionInterceptor would generate an invalid partition ID. This has been fixed."

View File

@ -236,7 +236,7 @@ public class PatientIdPartitionInterceptor {
*/ */
@SuppressWarnings("unused") @SuppressWarnings("unused")
protected int providePartitionIdForPatientId(RequestDetails theRequestDetails, String theResourceIdPart) { protected int providePartitionIdForPatientId(RequestDetails theRequestDetails, String theResourceIdPart) {
return Math.abs(theResourceIdPart.hashCode()) % 15000; return Math.abs(theResourceIdPart.hashCode() % 15000);
} }
/** /**

View File

@ -91,6 +91,23 @@ public class PatientIdPartitionInterceptorTest extends BaseJpaR4SystemTest {
}); });
} }
/**
* This is an edge case where a client assigned ID has a Java hashCode equal to Integer.MIN_VALUE.
*/
@Test
public void testCreatePatient_polygenelubricants() {
Patient patient = new Patient();
patient.setId("Patient/polygenelubricants");
patient.setActive(true);
DaoMethodOutcome update = myPatientDao.update(patient);
runInTransaction(() -> {
ResourceTable pt = myResourceTableDao.findAll().iterator().next();
assertEquals("polygenelubricants", pt.getIdDt().getIdPart());
assertEquals(8648, pt.getPartitionId().getPartitionId());
});
}
@Test @Test
public void testCreatePatient_NonClientAssignedId() { public void testCreatePatient_NonClientAssignedId() {
Patient patient = new Patient(); Patient patient = new Patient();