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);
}
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 + ")."));
}
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();
}
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;
}
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);
}
}
Aggregations