Skip to content

Commit

Permalink
PEPPER-294 made sure all uploaded kits get the same ddpParticipantId …
Browse files Browse the repository at this point in the history
…(all legacy or all pepper)
  • Loading branch information
pegahtah committed May 30, 2024
1 parent b34f9dd commit 622f913
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1858,6 +1858,27 @@ public static String getCollaboratorSampleId(int kitTypeId, String participantCo
}
}

public static String getParticipantIdFromLegacyKit(DDPInstance ddpInstance, String shortId, String collaboratorParticipantId) {
Profile profile = new ElasticSearchService().getParticipantProfileByShortID(shortId, ddpInstance.getParticipantIndexES());
if (profile == null) {
throw new DsmInternalError("Could not find profile for shortId " + shortId);
}
if (StringUtils.isBlank(profile.getLegacyAltPid())) {
return null;
}
if (isLegacyCollaboratorParticipantId(collaboratorParticipantId, profile.getLegacyShortId())) {
List<KitRequestShipping> legacyKits = kitRequestDao.getKitRequestsForCollaboratorParticipantId(collaboratorParticipantId);
if (!legacyKits.isEmpty()) {
return legacyKits.get(0).getDdpParticipantId();
}
}
return null;
}

private static boolean isLegacyCollaboratorParticipantId(String collaboratorParticipantId, String legacyShortId) {
return StringUtils.isNotBlank(collaboratorParticipantId) && collaboratorParticipantId.contains("_" + legacyShortId);
}

public Boolean getError() {
if (Objects.isNull(error)) {
return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -234,9 +234,9 @@ private void uploadKit(@NonNull DDPInstance ddpInstance, @NonNull KitType kitTyp
String participantLegacyAltPid = "";
String collaboratorParticipantId = "";
//if kit has ddpParticipantId use that (RGP!) and
//For any studies that do not have participants the search will fail and error so
//For any studies that do not have participants the search will fail and error, so
//we check if ddpInstance.getParticipantIndexES() != null
if (StringUtils.isNotBlank((ddpInstance.getParticipantIndexES())) && StringUtils.isBlank(kit.getParticipantId())) {
if (ddpInstance.hasEsIndex() && StringUtils.isBlank(kit.getParticipantId())) {
ElasticSearchParticipantDto participantByShortId =
elasticSearch.getParticipantById(ddpInstance.getParticipantIndexES(), kit.getShortId());
participantGuid = participantByShortId.getProfile().map(Profile::getGuid).orElse("");
Expand Down Expand Up @@ -292,7 +292,7 @@ private void uploadKit(@NonNull DDPInstance ddpInstance, @NonNull KitType kitTyp
orderKits.add(kit);
}
} else {
//all cmi ddps are currently using this!
//all cmi studies are currently using this!
handleNormalKit(conn, ddpInstance, kitType, kit, kitRequestSettings, easyPostUtil, userIdRequest, kitTypeName,
collaboratorParticipantId, errorMessage, uploadAnyway, duplicateKitList, orderKits, specialKitList, behavior,
externalOrderNumber, uploadReason, carrier);
Expand Down Expand Up @@ -403,8 +403,15 @@ private void addKitRequest(Connection conn, String kitTypeName, KitRequestSettin

//If there is a participant change the participantID to the ID of the existing
//participant
if (StringUtils.isNotBlank((ddpInstance.getParticipantIndexES()))) {
participantID = kit.getParticipantId().trim();
if (ddpInstance.hasEsIndex()) {
//check if there are previous kits with the legacy participant id
String participantIdOfLegacyKit = KitRequestShipping.getParticipantIdFromLegacyKit(ddpInstance, participantID,
collaboratorParticipantId);
if (participantIdOfLegacyKit != null) {
participantID = participantIdOfLegacyKit;
} else {
participantID = kit.getParticipantId().trim();
}
}

KitRequestShipping.writeRequest(ddpInstance.getDdpInstanceId(), shippingId, kitTypeId, participantID,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ public class KitRequestShippingTest extends DbAndElasticBaseTest {
private static DDPInstance ddpInstance;
private static DDPInstanceDao ddpInstanceDao = new DDPInstanceDao();
private static String legacyParticipantGuid = "DDP_PT_ID_1";
private static String legacyAltpid;
private static ParticipantDto legacyParticipant;
private static String notLegacyParticipantGuid = "DDP_PT_ID_2";
private static ParticipantDto notLegacyParticipant;
Expand All @@ -56,6 +57,7 @@ public static void doFirst() {
legacyParticipant = legacyParticipantPair.getLeft();
participants.add(legacyParticipant);
legacyParticipantGuid = legacyParticipant.getRequiredDdpParticipantId();
legacyAltpid = legacyParticipantPair.getRight();

Profile profile = new Profile();
profile.setHruid(notLegacyParticipantShortId);
Expand Down Expand Up @@ -134,9 +136,9 @@ public void testLegacyKitUpload() {
Assert.assertEquals(collaboratorParticipantId, nextCollaboratorParticipantId);
Assert.assertEquals(collaboratorSampleId, nextCollaboratorSampleId);

//now check when legacy participant has a kit with legacy id
//now check when legacy participant has a kit with legacy id and legacy altpid
KitRequestShipping kitRequestShipping = KitRequestShipping.builder()
.withDdpParticipantId(legacyParticipant.getRequiredDdpParticipantId())
.withDdpParticipantId(legacyAltpid)
.withBspCollaboratorParticipantId(legacyCollaboratorParticipantId)
.withBspCollaboratorSampleId(legacyCollaboratorSampleId)
.withKitTypeName("SALIVA")
Expand All @@ -153,6 +155,10 @@ public void testLegacyKitUpload() {

Assert.assertEquals(legacyCollaboratorParticipantId, nextCollaboratorParticipantId);
Assert.assertEquals(expectedNextCollaboratorSampleId, nextCollaboratorSampleId);

//test what the participant id will be for this
String kitParticipantId = KitRequestShipping.getParticipantIdFromLegacyKit(ddpInstance, shortId, nextCollaboratorParticipantId);
Assert.assertEquals(legacyAltpid, kitParticipantId);
return null;
});
}
Expand Down

0 comments on commit 622f913

Please sign in to comment.