Skip to content

Commit

Permalink
Merge branch 'develop' into pepper-1063
Browse files Browse the repository at this point in the history
  • Loading branch information
denniscunningham committed Aug 22, 2023
2 parents 93af431 + 593056f commit dd28e28
Show file tree
Hide file tree
Showing 32 changed files with 1,574 additions and 563 deletions.
4 changes: 2 additions & 2 deletions .circleci/main-config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ references:
tcell_config_file: &tcell_config_file
tcell_agent.config
ci_support_image: &ci_support_image
broadinstitute/study-server-build:2022-06-01A
broadinstitute/study-server-build:2023-03-28C
root_path: &root_path
/home/circleci
repo_path: &repo_path
Expand Down Expand Up @@ -48,7 +48,7 @@ references:
executors:
test-executor:
docker:
- image: broadinstitute/study-server-build:java-2022-06-01A
- image: broadinstitute/study-server-build:2023-03-28C
# start pubsub emulator
- image: broadinstitute/study-server-build:pubsub-1
- image: cimg/redis:5.0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@
import org.broadinstitute.dsm.jobs.PubSubLookUp;
import org.broadinstitute.dsm.log.SlackAppender;
import org.broadinstitute.dsm.model.nonpepperkit.NonPepperKitCreationService;
import org.broadinstitute.dsm.model.nonpepperkit.NonPepperStatusKitService;
import org.broadinstitute.dsm.pubsub.AntivirusScanningStatusListener;
import org.broadinstitute.dsm.pubsub.DSMtasksSubscription;
import org.broadinstitute.dsm.pubsub.MercuryOrderStatusListener;
Expand Down Expand Up @@ -98,7 +99,6 @@
import org.broadinstitute.dsm.route.FieldSettingsRoute;
import org.broadinstitute.dsm.route.FilterRoute;
import org.broadinstitute.dsm.route.InstitutionRoute;
import org.broadinstitute.dsm.route.JuniperShipKitRoute;
import org.broadinstitute.dsm.route.KitAuthorizationRoute;
import org.broadinstitute.dsm.route.KitDeactivationRoute;
import org.broadinstitute.dsm.route.KitDiscardRoute;
Expand Down Expand Up @@ -129,6 +129,8 @@
import org.broadinstitute.dsm.route.admin.UserRoute;
import org.broadinstitute.dsm.route.dashboard.NewDashboardRoute;
import org.broadinstitute.dsm.route.familymember.AddFamilyMemberRoute;
import org.broadinstitute.dsm.route.juniper.JuniperShipKitRoute;
import org.broadinstitute.dsm.route.juniper.StatusKitRoute;
import org.broadinstitute.dsm.route.kit.KitFinalScanRoute;
import org.broadinstitute.dsm.route.kit.KitInitialScanRoute;
import org.broadinstitute.dsm.route.kit.KitTrackingScanRoute;
Expand Down Expand Up @@ -589,8 +591,13 @@ protected void setupCustomRouting(@NonNull Config cfg) {
get(apiRoot + RoutePath.CLINICAL_KIT_ENDPOINT, new ClinicalKitsRoute(notificationUtil), new JsonTransformer());

if (!cfg.getBoolean("ui.production")) {
NonPepperKitCreationService nonPepperKitCreationService = new NonPepperKitCreationService();
post(apiRoot + RoutePath.SHIP_KIT_ENDPOINT, new JuniperShipKitRoute(nonPepperKitCreationService), new JsonTransformer());
post(apiRoot + RoutePath.SHIP_KIT_ENDPOINT, new JuniperShipKitRoute(), new JsonTransformer());

StatusKitRoute statusKitRoute = new StatusKitRoute();
get(apiRoot + RoutePath.KIT_STATUS_ENDPOINT_STUDY, statusKitRoute, new JsonTransformer());
get(apiRoot + RoutePath.KIT_STATUS_ENDPOINT_JUNIPER_KIT_ID, statusKitRoute, new JsonTransformer());
get(apiRoot + RoutePath.KIT_STATUS_ENDPOINT_PARTICIPANT_ID, statusKitRoute, new JsonTransformer());
post(apiRoot + RoutePath.KIT_STATUS_ENDPOINT_KIT_IDS, statusKitRoute, new JsonTransformer());
}

if (!cfg.getBoolean("ui.production")) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,13 @@ public class KitRequestShipping extends KitRequest implements HasDdpInstanceId {
+ "denial_reason = ?, authorized_by = ? WHERE kit.dsm_kit_request_id = ?";
private static final String MARK_ORDER_AS_TRANSMITTED =
"update ddp_kit_request set order_transmitted_at = ? where external_order_number = ?";

private static final String GET_COUNT_KITS_WITH_SAME_COLLABORATOR_SAMPLE_ID_AND_KIT_TYPE =
" SELECT count(*) kitRequestCount from ddp_kit_request where bsp_collaborator_sample_id REGEXP \"^%1\" and kit_type_id = ?";

private static final String GET_FOUND_IF_KIT_WITH_DDP_LABEL_ALREADY_EXISTS =
" select 1 from ddp_kit_request req where req.ddp_label = ? ";

private static final String QUEUE = "queue";
private static final String ERROR = "error";
private static final String SENT = "sent";
Expand Down Expand Up @@ -924,6 +931,8 @@ public static void addKitRequests(@NonNull String instanceId, @NonNull String ki
// called by
// 1. hourly job to add kit requests into db
// 2. kit upload
// 3. Juniper shipKit route
// BSP and Mercury dummy kit routes in non-prod
public static String writeRequest(@NonNull String instanceId, @NonNull String ddpKitRequestId, int kitTypeId,
@NonNull String ddpParticipantId, String bspCollaboratorParticipantId, String collaboratorSampleId,
@NonNull String createdBy, String addressIdTo, String errorMessage, String externalOrderNumber,
Expand Down Expand Up @@ -991,19 +1000,17 @@ public static String writeRequest(@NonNull String instanceId, @NonNull String dd

DDPInstanceDto ddpInstanceDto =
new DDPInstanceDao().getDDPInstanceByInstanceId(Integer.valueOf(ddpInstance.getDdpInstanceId())).orElseThrow();
// update ES only if it's a pepper study
// update ES only if it's a pepper study, not for Darwin's arc or Juniper studies
if (ddpInstanceDto.isESUpdatePossible()) {
try {
UpsertPainlessFacade.of(DBConstants.DDP_KIT_REQUEST_ALIAS, kitRequestShipping, ddpInstanceDto,
ESObjectConstants.DSM_KIT_REQUEST_ID, ESObjectConstants.DOC_ID,
Exportable.getParticipantGuid(ddpParticipantId, ddpInstance.getParticipantIndexES()),
new PutToNestedScriptBuilder()).export();
} catch (Exception e) {
//This error will trigger on studies with no participants, this skips
//the error log if that is the reason for the upsert failure.
logger.error(String.format("Error inserting newly created kit request shipping with dsm kit request id: %s in "
logger.error(String.format("Error inserting newly created kit request shipping with dsm kit request id: %s in "
+ "ElasticSearch", kitRequestShipping.getDsmKitRequestId()));
e.printStackTrace();
e.printStackTrace();
}
}

Expand Down Expand Up @@ -1271,8 +1278,7 @@ public static String generateBspSampleID(@NonNull Connection conn, String collab
}

public static int getKitCounter(@NonNull Connection conn, String collaboratorSampleId, int kitTypeId) {
String query = DSMConfig.getSqlFromConfig(ApplicationConfigConstants.GET_COUNT_KITS_WITH_SAME_COLLABORATOR_SAMPLE_ID_AND_KIT_TYPE)
.replace("%1", collaboratorSampleId);
String query = GET_COUNT_KITS_WITH_SAME_COLLABORATOR_SAMPLE_ID_AND_KIT_TYPE.replace("%1", collaboratorSampleId);
try (PreparedStatement stmt = conn.prepareStatement(query, ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_READ_ONLY)) {
stmt.setInt(1, kitTypeId);
try (ResultSet rs = stmt.executeQuery()) {
Expand All @@ -1294,8 +1300,7 @@ public static int getKitCounter(@NonNull Connection conn, String collaboratorSam
* and checking it against db if unique
*/
public static String generateDdpLabelID() {
return generateDdpLabelID(15,
DSMConfig.getSqlFromConfig(ApplicationConfigConstants.GET_FOUND_IF_KIT_WITH_DDP_LABEL_ALREADY_EXISTS));
return generateDdpLabelID(15, GET_FOUND_IF_KIT_WITH_DDP_LABEL_ALREADY_EXISTS);
}

public static String generateDdpLabelID(int length, String query) {
Expand Down Expand Up @@ -1355,7 +1360,7 @@ public static Address getToAddressId(@NonNull EasyPostUtil easyPostUtil, KitRequ
DDPParticipant participant, DDPInstanceDto ddpInstanceDto) throws Exception {
Address toAddress = null;
if (addressId == null && participant == null) { //if both are set to null then it is return label!
toAddress = easyPostUtil.createBroadAddress(kitRequestSettings.getReturnName(), kitRequestSettings.getReturnStreet1(),
toAddress = easyPostUtil.createAddressWithoutValidation(kitRequestSettings.getReturnName(), kitRequestSettings.getReturnStreet1(),
kitRequestSettings.getReturnStreet2(), kitRequestSettings.getReturnCity(), kitRequestSettings.getReturnZip(),
kitRequestSettings.getReturnState(), kitRequestSettings.getReturnCountry(), kitRequestSettings.getPhone());
} else {
Expand Down Expand Up @@ -1428,7 +1433,7 @@ public static Shipment getShipment(@NonNull EasyPostUtil easyPostUtil, String bi
if (kitType != null) {

Address returnAddress =
easyPostUtil.createBroadAddress(kitRequestSettings.getReturnName(), kitRequestSettings.getReturnStreet1(),
easyPostUtil.createAddressWithoutValidation(kitRequestSettings.getReturnName(), kitRequestSettings.getReturnStreet1(),
kitRequestSettings.getReturnStreet2(), kitRequestSettings.getReturnCity(), kitRequestSettings.getReturnZip(),
kitRequestSettings.getReturnState(), kitRequestSettings.getReturnCountry(), kitRequestSettings.getPhone());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,10 @@ public interface KitDao extends Dao<KitRequestShipping> {
Integer deleteKit(Long kitId);

Optional<KitRequestShipping> getKitByDdpLabel(String ddpLabel, String kitLabel);

Optional<List<KitRequestShipping>> getSubkitsByDdpLabel(String ddpLabel, String kitLabel);

List<KitRequestShipping> getKitsByHruid(String hruid);

Optional<ScanError> updateKitLabel(KitRequestShipping kitRequestShipping);

}
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,6 @@

public class KitDaoImpl implements KitDao {

private static final Logger logger = LoggerFactory.getLogger(KitDaoImpl.class);

public static final String SQL_SELECT_KIT_REQUEST =
"SELECT * FROM ( SELECT req.upload_reason, kt.kit_type_name, ddp_site.instance_name, ddp_site.ddp_instance_id, "
+ "ddp_site.base_url, ddp_site.auth0_token, ddp_site.billing_reference, "
Expand Down Expand Up @@ -56,7 +54,7 @@ public class KitDaoImpl implements KitDao {
public static final String KIT_BY_KIT_ID = " and kit.dsm_kit_id = ?";
public static final String KIT_BY_HRUID = " and bsp_collaborator_participant_id like ? AND not kit_complete <=> 1 "
+ "AND deactivated_date is null";

private static final Logger logger = LoggerFactory.getLogger(KitDaoImpl.class);
private static final String SQL_IS_BLOOD_KIT_QUERY = "SELECT kt.requires_insert_in_kit_tracking AS found "
+ "FROM ddp_kit_request request "
+ "LEFT JOIN kit_type kt on (kt.kit_type_id = request.kit_type_id) "
Expand Down Expand Up @@ -96,18 +94,20 @@ public class KitDaoImpl implements KitDao {
+ "LEFT JOIN ddp_kit_request_settings AS ks ON ks.kit_type_id = req.kit_type_id AND ks.ddp_instance_id = req.ddp_instance_id "
+ "WHERE req.ddp_label = ?";

private static final String SQL_GET_SUB_KIT_BY_DDP_LABEL = "SELECT req.ddp_kit_request_id, req.ddp_instance_id, req.ddp_kit_request_id, "
+ "req.kit_type_id, req.bsp_collaborator_participant_id, req.bsp_collaborator_sample_id, req.ddp_participant_id, "
+ "req.ddp_label, req.created_by, req.created_date, req.external_order_number, "
+ "req.external_order_date, req.external_order_status, req.external_response, req.upload_reason, "
+ "req.order_transmitted_at, req.dsm_kit_request_id, kit.kit_label, kit.dsm_kit_id,"
+ "kt.requires_insert_in_kit_tracking, kt.kit_type_name, track.tracking_id, ks.kit_label_prefix, ks.kit_label_length "
+ "FROM ddp_kit as kit "
+ "LEFT JOIN ddp_kit_request AS req ON req.dsm_kit_request_id = kit.dsm_kit_request_id "
+ "LEFT JOIN ddp_kit_tracking AS track ON track.kit_label = ?"
+ "LEFT JOIN kit_type AS kt ON kt.kit_type_id = req.kit_type_id "
+ "LEFT JOIN ddp_kit_request_settings AS ks ON ks.kit_type_id = req.kit_type_id AND ks.ddp_instance_id = req.ddp_instance_id "
+ "WHERE ( req.ddp_label = ? or ddp_label like ? )";
private static final String SQL_GET_SUB_KIT_BY_DDP_LABEL =
"SELECT req.ddp_kit_request_id, req.ddp_instance_id, req.ddp_kit_request_id, "
+ "req.kit_type_id, req.bsp_collaborator_participant_id, req.bsp_collaborator_sample_id, req.ddp_participant_id, "
+ "req.ddp_label, req.created_by, req.created_date, req.external_order_number, "
+ "req.external_order_date, req.external_order_status, req.external_response, req.upload_reason, "
+ "req.order_transmitted_at, req.dsm_kit_request_id, kit.kit_label, kit.dsm_kit_id,"
+ "kt.requires_insert_in_kit_tracking, kt.kit_type_name, track.tracking_id, ks.kit_label_prefix, ks.kit_label_length "
+ "FROM ddp_kit as kit "
+ "LEFT JOIN ddp_kit_request AS req ON req.dsm_kit_request_id = kit.dsm_kit_request_id "
+ "LEFT JOIN ddp_kit_tracking AS track ON track.kit_label = ?"
+ "LEFT JOIN kit_type AS kt ON kt.kit_type_id = req.kit_type_id "
+
"LEFT JOIN ddp_kit_request_settings AS ks ON ks.kit_type_id = req.kit_type_id AND ks.ddp_instance_id = req.ddp_instance_id "
+ "WHERE ( req.ddp_label = ? or ddp_label like ? )";

private static final String INSERT_KIT = "INSERT INTO "
+ "ddp_kit "
Expand Down Expand Up @@ -569,7 +569,7 @@ public Optional<ScanError> insertKitTracking(KitRequestShipping kitRequestShippi
return dbVals;
});
if (Objects.nonNull(results.resultValue)) {
result = Optional.ofNullable((ScanError)results.resultValue);
result = Optional.ofNullable((ScanError) results.resultValue);
}
return result;
}
Expand Down Expand Up @@ -666,4 +666,5 @@ public boolean hasKitReceived(Connection connection, String ddpParticipantId) {
}
return false;
}

}
Loading

0 comments on commit dd28e28

Please sign in to comment.