-
Notifications
You must be signed in to change notification settings - Fork 2
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
DDP-6484 test boston manual orders #215
Open
zyme
wants to merge
4
commits into
develop
Choose a base branch
from
DDP-6484_TestBostonManualOrders
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
134 changes: 134 additions & 0 deletions
134
src/main/java/org/broadinstitute/dsm/model/birch/RegisterBirchOrderCLI.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,134 @@ | ||
package org.broadinstitute.dsm.model.birch; | ||
|
||
import java.sql.Connection; | ||
import java.sql.SQLException; | ||
import java.time.Instant; | ||
import java.time.LocalDateTime; | ||
import java.time.ZoneId; | ||
import java.time.format.DateTimeFormatter; | ||
import java.util.Map; | ||
import java.util.Scanner; | ||
|
||
import com.google.gson.Gson; | ||
import com.google.gson.JsonObject; | ||
import com.google.gson.JsonParser; | ||
import com.typesafe.config.Config; | ||
import com.typesafe.config.ConfigFactory; | ||
import org.apache.commons.dbcp2.PoolableConnection; | ||
import org.apache.commons.dbcp2.PoolingDataSource; | ||
import org.broadinstitute.ddp.db.TransactionWrapper; | ||
import org.broadinstitute.dsm.careevolve.Authentication; | ||
import org.broadinstitute.dsm.careevolve.Covid19OrderRegistrar; | ||
import org.broadinstitute.dsm.careevolve.OrderResponse; | ||
import org.broadinstitute.dsm.careevolve.Patient; | ||
import org.broadinstitute.dsm.careevolve.Provider; | ||
import org.broadinstitute.dsm.cf.CFUtil; | ||
import org.broadinstitute.dsm.db.DDPInstance; | ||
import org.broadinstitute.dsm.db.DdpKit; | ||
import org.broadinstitute.dsm.statics.ApplicationConfigConstants; | ||
import org.broadinstitute.dsm.statics.DBConstants; | ||
import org.broadinstitute.dsm.util.ElasticSearchUtil; | ||
import org.elasticsearch.client.RestHighLevelClient; | ||
|
||
/** | ||
* CLI utility for manually placing orders in CareEvolve (and birch) | ||
* in response to BQMS tickets for kits that have been returned | ||
* without UPS shipping info. | ||
*/ | ||
public class RegisterBirchOrderCLI { | ||
|
||
private static final String USAGE = "args in order are hruid, kitLabel, externalOrderNumber, and collectionTime\n" + | ||
"for example java -Dconfig.file=... RegisterBirchOrderCLI P1234 TBOS-123 12345678910111213 06/30/2020 15:34\n" + | ||
"Make sure you are on a broad network\n"; | ||
public static final String DATE_FORMAT = "MM/dd/yyyy HH:mm"; | ||
|
||
|
||
public static void main(String[] args) { | ||
try { | ||
if (args == null || args.length == 0 || ("-h".equals(args[0]))) { | ||
System.out.println(USAGE); | ||
System.exit(0); | ||
} | ||
String participantHruid = args[0]; // user.hruid | ||
String kitLabel = args[1]; // ddp_kit.kit_label | ||
String externalOrderNumber = args[2]; // ddp_kit_request.external_order_number | ||
/** {@link DATE_FORMAT} */ | ||
String collectionTime = args[3]; | ||
|
||
Instant collectionDate = null; | ||
|
||
collectionDate = LocalDateTime.parse(collectionTime, DateTimeFormatter.ofPattern(DATE_FORMAT)) | ||
.atZone(ZoneId.of("America/New_York")) | ||
.toInstant(); | ||
|
||
Config cfg = ConfigFactory.load(); | ||
|
||
System.out.println("About to order " + kitLabel + " for participant " + participantHruid + " with collection time " + collectionTime + " and order number " + externalOrderNumber +". Ctrl-c to abort..."); | ||
System.out.print("Continue? [y/N] "); | ||
Scanner scanner = new Scanner(System.in); | ||
String input = scanner.nextLine().trim(); | ||
if (!"y".equalsIgnoreCase(input) && !"yes".equalsIgnoreCase(input)) { | ||
return; | ||
} | ||
|
||
TransactionWrapper.init(2, cfg.getString("portal.dbUrl"), cfg, true); | ||
|
||
PoolingDataSource<PoolableConnection> dataSource = CFUtil.createDataSource(5, cfg.getString("portal.dbUrl")); | ||
|
||
String careEvolveAccount = cfg.getString(ApplicationConfigConstants.CARE_EVOLVE_ACCOUNT); | ||
String careEvolveSubscriberKey = cfg.getString(ApplicationConfigConstants.CARE_EVOLVE_SUBSCRIBER_KEY); | ||
String careEvolveServiceKey = cfg.getString(ApplicationConfigConstants.CARE_EVOLVE_SERVICE_KEY); | ||
String careEvolveOrderEndpoint = cfg.getString(ApplicationConfigConstants.CARE_EVOLVE_ORDER_ENDPOINT); | ||
Authentication auth = new Authentication(careEvolveSubscriberKey, careEvolveServiceKey); | ||
Provider provider = new Provider(cfg.getString(ApplicationConfigConstants.CARE_EVOLVE_PROVIDER_FIRSTNAME), | ||
cfg.getString(ApplicationConfigConstants.CARE_EVOLVE_PROVIDER_LAST_NAME), | ||
cfg.getString(ApplicationConfigConstants.CARE_EVOLVE_PROVIDER_NPI)); | ||
|
||
|
||
DDPInstance ddpInstance = TransactionWrapper.inTransaction(conn -> DDPInstance.getDDPInstanceWithRole("testboston", DBConstants.HAS_KIT_REQUEST_ENDPOINTS)); | ||
|
||
String esUrl = cfg.getString(ApplicationConfigConstants.ES_URL); | ||
String esUsername = cfg.getString(ApplicationConfigConstants.ES_USERNAME); | ||
String esPassword = cfg.getString(ApplicationConfigConstants.ES_PASSWORD); | ||
RestHighLevelClient esClient = null; | ||
|
||
try { | ||
esClient = ElasticSearchUtil.getClientForElasticsearchCloud(esUrl, esUsername, esPassword); | ||
} catch(Exception e) { | ||
throw new RuntimeException("Could not get es client--are you on the VPN?", e); | ||
} | ||
|
||
Covid19OrderRegistrar orderRegistrar = new Covid19OrderRegistrar(careEvolveOrderEndpoint, careEvolveAccount, provider, 0, 0); | ||
|
||
Map<String, Map<String, Object>> esData = ElasticSearchUtil.getSingleParticipantFromES(ddpInstance.getName(), ddpInstance.getParticipantIndexES(), esClient, participantHruid); | ||
|
||
if (esData.size() == 1) { | ||
JsonObject participantJsonData = new JsonParser().parse(new Gson().toJson(esData.values().iterator().next())).getAsJsonObject(); | ||
Patient cePatient = Covid19OrderRegistrar.fromElasticData(participantJsonData); | ||
System.out.println(cePatient); | ||
|
||
OrderResponse orderResponse = orderRegistrar.orderTest(auth, cePatient, kitLabel, externalOrderNumber, collectionDate); | ||
|
||
if (orderResponse.hasError()) { | ||
throw new RuntimeException("Error placing order: " + orderResponse.getHandle() + " " + orderResponse.getError()); | ||
} else { | ||
System.out.println("Placed order for " + kitLabel); | ||
} | ||
try (Connection conn = dataSource.getConnection()) { | ||
DdpKit.updateCEOrdered(dataSource.getConnection(), true, kitLabel); | ||
conn.commit(); | ||
} catch (SQLException e) { | ||
throw new RuntimeException("Could not update order status. You may need to manually update DSM to mark ce_ordered", e); | ||
} | ||
} else { | ||
throw new RuntimeException("Could not find es data for " + participantHruid); | ||
} | ||
} catch(Exception e) { | ||
System.err.println(e.getMessage()); | ||
e.printStackTrace(); | ||
} | ||
finally { | ||
System.exit(0); | ||
} | ||
} | ||
} |
103 changes: 0 additions & 103 deletions
103
src/test/java/org/broadinstitute/dsm/careevolve/Covid19OrderRegistrarTest.java
This file was deleted.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
@yufengwng your suggestion worked once I updated this from
hh
toHH
(I've been putting in hours as 0-23).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.
Noted! And it's helpful that the "usage" string shows an example of
15:34
hinting at 24-hr format!