Search in sources :

Example 46 with Account

use of org.hl7.fhir.dstu3.model.Account in project BridgeServer2 by Sage-Bionetworks.

the class CRCControllerTest method postAppointmentUpdated.

@Test
public void postAppointmentUpdated() throws Exception {
    when(mockRequest.getHeader(AUTHORIZATION)).thenReturn(AUTHORIZATION_HEADER_VALUE);
    when(mockAccountService.authenticate(any(), any())).thenReturn(account);
    when(mockAccountService.getAccount(ACCOUNT_ID)).thenReturn(Optional.of(account));
    mockGetLocation(LOCATION_JSON);
    // mockGetGeocoding();
    DateRangeResourceList<? extends ReportData> results = new DateRangeResourceList<>(ImmutableList.of(ReportData.create()));
    doReturn(results).when(mockReportService).getParticipantReport(APP_ID, TEST_USER_ID, APPOINTMENT_REPORT, HEALTH_CODE, JAN1, JAN2);
    Appointment appointment = new Appointment();
    appointment.setStatus(BOOKED);
    // add a wrong participant to verify we go through them all and look for ours
    addAppointmentParticipantComponent(appointment, LOCATION_NS + "foo");
    addAppointmentSageId(appointment, TEST_USER_ID);
    String json = FHIR_CONTEXT.newJsonParser().encodeResourceToString(appointment);
    mockRequestBody(mockRequest, json);
    ResponseEntity<StatusMessage> retValue = controller.postAppointment();
    assertEquals(retValue.getBody().getMessage(), "Appointment updated (status = booked).");
    assertEquals(retValue.getStatusCodeValue(), 200);
    assertTrue(account.getDataGroups().contains("tests_scheduled"));
    verify(controller).addLocation(any(), eq(account), eq("foo"));
    verify(controller).post("http://testServer/location/_search", account, "id=\"foo\"");
    verify(mockHealthDataService).submitHealthData(eq(APP_ID), participantCaptor.capture(), dataCaptor.capture());
    HealthDataSubmission healthData = dataCaptor.getValue();
    assertEquals(healthData.getAppVersion(), "v1");
    assertEquals(healthData.getCreatedOn(), TIMESTAMP);
    assertEquals(healthData.getMetadata().toString(), "{\"type\":\"" + APPOINTMENT_REPORT + "\"}");
    assertEquals(healthData.getData().toString(), APPOINTMENT_JSON_FULLY_RESOLVED);
}
Also used : Appointment(org.hl7.fhir.dstu3.model.Appointment) HealthDataSubmission(org.sagebionetworks.bridge.models.healthdata.HealthDataSubmission) DateRangeResourceList(org.sagebionetworks.bridge.models.DateRangeResourceList) StatusMessage(org.sagebionetworks.bridge.models.StatusMessage) Test(org.testng.annotations.Test)

Example 47 with Account

use of org.hl7.fhir.dstu3.model.Account in project BridgeServer2 by Sage-Bionetworks.

the class CRCController method postAppointment.

@PutMapping("/v1/cuimc/appointments")
public ResponseEntity<StatusMessage> postAppointment() {
    App app = httpBasicAuthentication();
    IParser parser = FHIR_CONTEXT.newJsonParser();
    JsonNode data = parseJson(JsonNode.class);
    Appointment appointment = parser.parseResource(Appointment.class, data.toString());
    String userId = findUserId(appointment);
    // They send appointment when it is booked, cancelled, or (rarely) enteredinerror.
    AccountStates state = TESTS_SCHEDULED;
    String apptStatus = data.get("status").asText();
    if ("entered-in-error".equals(apptStatus)) {
        deleteReportAndUpdateState(app, userId);
        return ResponseEntity.ok(new StatusMessage("Appointment deleted."));
    } else if ("cancelled".equals(apptStatus)) {
        state = TESTS_CANCELLED;
    }
    // Columbia wants us to call back to them to get information about the location.
    // And UI team wants geocoding of location to render a map.
    String locationString = findLocation(appointment);
    if (locationString != null) {
        AccountId accountId = parseAccountId(app.getIdentifier(), userId);
        Account account = accountService.getAccount(accountId).orElseThrow(() -> new EntityNotFoundException(Account.class));
        addLocation(data, account, locationString);
    }
    int status = writeReportAndUpdateState(app, userId, data, APPOINTMENT_REPORT, state, true);
    if (status == 200) {
        return ResponseEntity.ok(new StatusMessage("Appointment updated (status = " + apptStatus + ")."));
    }
    return ResponseEntity.created(URI.create("/v1/cuimc/appointments/" + userId)).body(new StatusMessage("Appointment created (status = " + apptStatus + ")."));
}
Also used : App(org.sagebionetworks.bridge.models.apps.App) Appointment(org.hl7.fhir.dstu3.model.Appointment) Account(org.sagebionetworks.bridge.models.accounts.Account) BridgeUtils.parseAccountId(org.sagebionetworks.bridge.BridgeUtils.parseAccountId) AccountId(org.sagebionetworks.bridge.models.accounts.AccountId) JsonNode(com.fasterxml.jackson.databind.JsonNode) EntityNotFoundException(org.sagebionetworks.bridge.exceptions.EntityNotFoundException) 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 48 with Account

use of org.hl7.fhir.dstu3.model.Account in project BridgeServer2 by Sage-Bionetworks.

the class CRCController method put.

HttpResponse put(String url, String bodyJson, Account account) throws IOException {
    Request request = Request.Put(url).bodyString(bodyJson, APPLICATION_JSON);
    request = addAuthorizationHeader(request, account);
    return request.execute().returnResponse();
}
Also used : ProcedureRequest(org.hl7.fhir.dstu3.model.ProcedureRequest) Request(org.apache.http.client.fluent.Request)

Example 49 with Account

use of org.hl7.fhir.dstu3.model.Account in project BridgeServer2 by Sage-Bionetworks.

the class CRCController method writeReportAndUpdateState.

private int writeReportAndUpdateState(App app, String userId, JsonNode data, String reportName, AccountStates state, boolean useCallerStudyIds) {
    String appId = RequestContext.get().getCallerAppId();
    AccountId accountId = AccountId.forId(appId, userId);
    Account account = accountService.getAccount(accountId).orElseThrow(() -> new EntityNotFoundException(Account.class));
    updateState(account, state);
    accountService.updateAccount(account);
    try {
        ObjectNode metadata = JsonNodeFactory.instance.objectNode();
        metadata.put("type", reportName);
        StudyParticipant participant = participantService.getParticipant(app, account, false);
        HealthDataSubmission healthData = new HealthDataSubmission.Builder().withAppVersion("v1").withCreatedOn(getTimestamp()).withMetadata(metadata).withData(data).withPhoneInfo(getUserAgent()).build();
        healthDataService.submitHealthData(appId, participant, healthData);
    } catch (IOException | UploadValidationException e) {
        throw new BridgeServiceException(e);
    }
    Set<String> callerStudyIds = useCallerStudyIds ? RequestContext.get().getOrgSponsoredStudies() : ImmutableSet.of();
    ReportData report = ReportData.create();
    report.setDate(JAN1.toString());
    report.setData(data);
    report.setStudyIds(callerStudyIds);
    DateRangeResourceList<? extends ReportData> results = reportService.getParticipantReport(appId, userId, reportName, account.getHealthCode(), JAN1, JAN2);
    int status = (results.getItems().isEmpty()) ? 201 : 200;
    reportService.saveParticipantReport(appId, userId, reportName, account.getHealthCode(), report);
    return status;
}
Also used : Account(org.sagebionetworks.bridge.models.accounts.Account) BridgeUtils.parseAccountId(org.sagebionetworks.bridge.BridgeUtils.parseAccountId) AccountId(org.sagebionetworks.bridge.models.accounts.AccountId) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) BridgeServiceException(org.sagebionetworks.bridge.exceptions.BridgeServiceException) EntityNotFoundException(org.sagebionetworks.bridge.exceptions.EntityNotFoundException) StudyParticipant(org.sagebionetworks.bridge.models.accounts.StudyParticipant) IOException(java.io.IOException) ContactPoint(org.hl7.fhir.dstu3.model.ContactPoint) HealthDataSubmission(org.sagebionetworks.bridge.models.healthdata.HealthDataSubmission) UploadValidationException(org.sagebionetworks.bridge.upload.UploadValidationException) ReportData(org.sagebionetworks.bridge.models.reports.ReportData)

Example 50 with Account

use of org.hl7.fhir.dstu3.model.Account in project project_internship by phamthao8383.

the class UserServlet method logInUser.

private void logInUser(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    response.setContentType("text/html;charset=UTF8");
    String userAccount = request.getParameter("account");
    String passWord = request.getParameter("password");
    Account account = accountService.CheckLogIn(userAccount, passWord);
    User user = userService.getUserAccount(userAccount);
    if (account.getUsername() != null) {
        // Khởi tạo session
        HttpSession session = request.getSession();
        // Thiết lập giá trị trong session
        session.setAttribute("account", account);
        session.setAttribute("user", user);
        System.out.println(account);
        // response.sendRedirect("/index.jsp");
        HomeServlet homeServlet = new HomeServlet();
        homeServlet.getMaxPoint(request, response);
        homeServlet.getMemberNumber(request, response);
        homeServlet.getNewMember(request, response);
        RequestDispatcher dispatcher = getServletContext().getRequestDispatcher("/index.jsp");
        dispatcher.forward(request, response);
    } else // Thất bại thì quay ve lại trang login
    {
        request.setAttribute("sai", 1);
        goLogin(request, response);
    }
}
Also used : Account(model.Account) User(model.User) HandleString(util.HandleString) RequestDispatcher(javax.servlet.RequestDispatcher)

Aggregations

Test (org.testng.annotations.Test)17 Patient (org.hl7.fhir.dstu3.model.Patient)10 ArrayList (java.util.ArrayList)8 Appointment (org.hl7.fhir.dstu3.model.Appointment)8 Account (org.sagebionetworks.bridge.models.accounts.Account)8 Complex (org.hl7.fhir.r4.utils.formats.Turtle.Complex)7 StatusMessage (org.sagebionetworks.bridge.models.StatusMessage)7 IOException (java.io.IOException)6 DateRangeResourceList (org.sagebionetworks.bridge.models.DateRangeResourceList)6 Account (com.google.api.services.adsense.v2.model.Account)5 JsonElement (com.google.gson.JsonElement)5 ProcedureRequest (org.hl7.fhir.dstu3.model.ProcedureRequest)5 Complex (org.hl7.fhir.dstu3.utils.formats.Turtle.Complex)5 HealthDataSubmission (org.sagebionetworks.bridge.models.healthdata.HealthDataSubmission)5 Account (Model.Account)4 File (java.io.File)4 FileInputStream (java.io.FileInputStream)4 FileOutputStream (java.io.FileOutputStream)4 Account (model.Account)4 ContactPoint (org.hl7.fhir.dstu3.model.ContactPoint)4