Search in sources :

Example 1 with StatusMessage

use of org.sagebionetworks.bridge.models.StatusMessage in project BridgeServer2 by Sage-Bionetworks.

the class CRCController method updateParticipant.

@PostMapping("/v1/cuimc/participants/{userId}/laborders")
public StatusMessage updateParticipant(@PathVariable String userId) {
    App app = httpBasicAuthentication();
    AccountId accountId = parseAccountId(app.getIdentifier(), userId);
    Account account = accountService.getAccount(accountId).orElseThrow(() -> new EntityNotFoundException(Account.class));
    if (account == null) {
        throw new EntityNotFoundException(Account.class);
    }
    updateState(account, SELECTED);
    accountService.updateAccount(account);
    return new StatusMessage("Participant updated.");
}
Also used : App(org.sagebionetworks.bridge.models.apps.App) Account(org.sagebionetworks.bridge.models.accounts.Account) BridgeUtils.parseAccountId(org.sagebionetworks.bridge.BridgeUtils.parseAccountId) AccountId(org.sagebionetworks.bridge.models.accounts.AccountId) EntityNotFoundException(org.sagebionetworks.bridge.exceptions.EntityNotFoundException) StatusMessage(org.sagebionetworks.bridge.models.StatusMessage) PostMapping(org.springframework.web.bind.annotation.PostMapping)

Example 2 with StatusMessage

use of org.sagebionetworks.bridge.models.StatusMessage in project BridgeServer2 by Sage-Bionetworks.

the class CRCController method postProcedureRequest.

@PutMapping("/v1/cuimc/procedurerequests")
public ResponseEntity<StatusMessage> postProcedureRequest() {
    App app = httpBasicAuthentication();
    IParser parser = FHIR_CONTEXT.newJsonParser();
    JsonNode data = parseJson(JsonNode.class);
    ProcedureRequest procedure = parser.parseResource(ProcedureRequest.class, data.toString());
    String userId = findUserId(procedure.getSubject());
    int status = writeReportAndUpdateState(app, userId, data, PROCEDURE_REPORT, AccountStates.TESTS_COLLECTED, true);
    if (status == 200) {
        return ResponseEntity.ok(new StatusMessage("ProcedureRequest updated."));
    }
    return ResponseEntity.created(URI.create("/v1/cuimc/procedurerequests/" + userId)).body(new StatusMessage("ProcedureRequest created."));
}
Also used : App(org.sagebionetworks.bridge.models.apps.App) ProcedureRequest(org.hl7.fhir.dstu3.model.ProcedureRequest) JsonNode(com.fasterxml.jackson.databind.JsonNode) ContactPoint(org.hl7.fhir.dstu3.model.ContactPoint) IParser(ca.uhn.fhir.parser.IParser) StatusMessage(org.sagebionetworks.bridge.models.StatusMessage) PutMapping(org.springframework.web.bind.annotation.PutMapping)

Example 3 with StatusMessage

use of org.sagebionetworks.bridge.models.StatusMessage in project BridgeServer2 by Sage-Bionetworks.

the class CRCController method internalLabShipmentRequest.

ResponseEntity<StatusMessage> internalLabShipmentRequest(App app, AccountId accountId) {
    Account account = accountService.getAccount(accountId).orElseThrow(() -> new EntityNotFoundException(Account.class));
    if (account.getDataGroups().contains(SHIP_TESTS_REQUESTED.name().toLowerCase())) {
        throw new LimitExceededException("Limited to one active shipment request.");
    }
    boolean isTestUser = account.getDataGroups().contains(TEST_USER_GROUP);
    LOG.info("Lab shipment requested for {} participant", isTestUser ? "test" : "non-test");
    LocalDate date = LocalDate.now();
    Order.ShippingInfo.Address address = validateAndGetAddress(account);
    String orderNumber = account.getId() + "_" + date;
    Order o = new Order(isTestUser, orderNumber, account.getId(), date, new Order.ShippingInfo(address, GBF_TEST_KIT_SHIP_METHOD), new Order.LineItem(GBF_TEST_KIT_PART_NUMBER, 1));
    gbfOrderService.placeOrder(o, isTestUser);
    JsonNode node = JsonNodeFactory.instance.objectNode().put(SHIPMENT_REPORT_KEY_ORDER_ID, orderNumber);
    // participants will not have Org Sponsored Studies in RequestContext, so for lab shipment reports, don't set study IDs
    writeReportAndUpdateState(app, account.getId(), node, SHIPMENT_REPORT, SHIP_TESTS_REQUESTED, false);
    return ResponseEntity.accepted().body(new StatusMessage(isTestUser ? "Test" : "Non-test" + " shipment requested."));
}
Also used : Order(org.sagebionetworks.bridge.models.crc.gbf.external.Order) Account(org.sagebionetworks.bridge.models.accounts.Account) JsonNode(com.fasterxml.jackson.databind.JsonNode) EntityNotFoundException(org.sagebionetworks.bridge.exceptions.EntityNotFoundException) LocalDate(org.joda.time.LocalDate) StatusMessage(org.sagebionetworks.bridge.models.StatusMessage) LimitExceededException(org.sagebionetworks.bridge.exceptions.LimitExceededException)

Example 4 with StatusMessage

use of org.sagebionetworks.bridge.models.StatusMessage in project BridgeServer2 by Sage-Bionetworks.

the class AppConfigElementsController method deleteElementRevision.

@DeleteMapping("/v3/appconfigs/elements/{id}/revisions/{revision}")
public StatusMessage deleteElementRevision(@PathVariable String id, @PathVariable String revision, @RequestParam(required = false) String physical) {
    UserSession session = getAuthenticatedSession(DEVELOPER);
    Long revisionLong = BridgeUtils.getLongOrDefault(revision, null);
    if (revisionLong == null) {
        throw new BadRequestException("Revision is not a valid revision number");
    }
    if ("true".equals(physical) && session.isInRole(ADMIN)) {
        service.deleteElementRevisionPermanently(session.getAppId(), id, revisionLong);
    } else {
        service.deleteElementRevision(session.getAppId(), id, revisionLong);
    }
    // App config elements are included in the app configs, so allow cache to update
    cacheProvider.removeSetOfCacheKeys(CacheKey.appConfigList(session.getAppId()));
    return new StatusMessage("App config element revision deleted.");
}
Also used : UserSession(org.sagebionetworks.bridge.models.accounts.UserSession) BadRequestException(org.sagebionetworks.bridge.exceptions.BadRequestException) StatusMessage(org.sagebionetworks.bridge.models.StatusMessage) DeleteMapping(org.springframework.web.bind.annotation.DeleteMapping)

Example 5 with StatusMessage

use of org.sagebionetworks.bridge.models.StatusMessage in project BridgeServer2 by Sage-Bionetworks.

the class AppConfigElementsController method deleteElementAllRevisions.

@DeleteMapping("/v3/appconfigs/elements/{id}")
public StatusMessage deleteElementAllRevisions(@PathVariable String id, @RequestParam(required = false) String physical) {
    UserSession session = getAuthenticatedSession(DEVELOPER);
    if ("true".equals(physical) && session.isInRole(ADMIN)) {
        service.deleteElementAllRevisionsPermanently(session.getAppId(), id);
    } else {
        service.deleteElementAllRevisions(session.getAppId(), id);
    }
    // App config elements are included in the app configs, so allow cache to update
    cacheProvider.removeSetOfCacheKeys(CacheKey.appConfigList(session.getAppId()));
    return new StatusMessage("App config element deleted.");
}
Also used : UserSession(org.sagebionetworks.bridge.models.accounts.UserSession) StatusMessage(org.sagebionetworks.bridge.models.StatusMessage) DeleteMapping(org.springframework.web.bind.annotation.DeleteMapping)

Aggregations

StatusMessage (org.sagebionetworks.bridge.models.StatusMessage)239 Test (org.testng.annotations.Test)168 UserSession (org.sagebionetworks.bridge.models.accounts.UserSession)58 PostMapping (org.springframework.web.bind.annotation.PostMapping)43 StudyParticipant (org.sagebionetworks.bridge.models.accounts.StudyParticipant)36 App (org.sagebionetworks.bridge.models.apps.App)28 ResponseStatus (org.springframework.web.bind.annotation.ResponseStatus)23 DeleteMapping (org.springframework.web.bind.annotation.DeleteMapping)22 Account (org.sagebionetworks.bridge.models.accounts.Account)21 ReportData (org.sagebionetworks.bridge.models.reports.ReportData)13 SignIn (org.sagebionetworks.bridge.models.accounts.SignIn)12 AccountId (org.sagebionetworks.bridge.models.accounts.AccountId)11 RequestContext (org.sagebionetworks.bridge.RequestContext)10 EntityNotFoundException (org.sagebionetworks.bridge.exceptions.EntityNotFoundException)10 DateRangeResourceList (org.sagebionetworks.bridge.models.DateRangeResourceList)10 JsonNode (com.fasterxml.jackson.databind.JsonNode)9 HealthDataSubmission (org.sagebionetworks.bridge.models.healthdata.HealthDataSubmission)9 Cookie (javax.servlet.http.Cookie)6 Appointment (org.hl7.fhir.dstu3.model.Appointment)6 NotificationMessage (org.sagebionetworks.bridge.models.notifications.NotificationMessage)6