use of org.hl7.fhir.dstu3.model.Account in project BridgeServer2 by Sage-Bionetworks.
the class CRCControllerTest method createPatientWithEmailUnverified.
@Test
public void createPatientWithEmailUnverified() {
Account account = Account.create();
account.setEmail(EMAIL);
account.setEmailVerified(false);
account.setPhone(PHONE);
account.setPhoneVerified(true);
Patient patient = controller.createPatient(account);
assertEquals(patient.getTelecom().size(), 1);
assertEquals(patient.getTelecom().get(0).getSystem(), ContactPointSystem.SMS);
}
use of org.hl7.fhir.dstu3.model.Account in project BridgeServer2 by Sage-Bionetworks.
the class CRCControllerTest method postAppointmentMistakeRollsBackAccount.
@Test
public void postAppointmentMistakeRollsBackAccount() 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));
Appointment appointment = new Appointment();
appointment.setStatus(ENTEREDINERROR);
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 deleted.");
assertEquals(retValue.getStatusCodeValue(), 200);
assertTrue(account.getDataGroups().contains("selected"));
verify(mockAccountService).updateAccount(account);
verify(mockReportService).deleteParticipantReportRecord(APP_ID, TEST_USER_ID, APPOINTMENT_REPORT, JAN1.toString(), HEALTH_CODE);
}
use of org.hl7.fhir.dstu3.model.Account in project BridgeServer2 by Sage-Bionetworks.
the class CRCControllerTest method createPatientWithMaleGender.
@Test
public void createPatientWithMaleGender() {
Account account = Account.create();
account.setAttributes(ImmutableMap.of("gender", "MALE"));
Patient patient = controller.createPatient(account);
assertEquals(patient.getGender(), AdministrativeGender.MALE);
}
use of org.hl7.fhir.dstu3.model.Account in project BridgeServer2 by Sage-Bionetworks.
the class CRCControllerTest method postAppointmentCancelled.
@Test
public void postAppointmentCancelled() 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(CANCELLED);
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 = cancelled).");
assertEquals(retValue.getStatusCodeValue(), 200);
assertTrue(account.getDataGroups().contains("tests_cancelled"));
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_CANCELLED);
}
use of org.hl7.fhir.dstu3.model.Account in project BridgeServer2 by Sage-Bionetworks.
the class CRCControllerTest method addAppointmentSageId.
// @Test
// public void createLabOrderOK() throws Exception {
// mockExternalService(200, "OK");
// // no errors
// controller.createLabOrder(account);
//
// // Currently in production we are also using the test values
// verify(controller).put(eq("http://testServer/userId"), any(), any());
// }
//
// @Test
// public void createLabOrderOKInTest() throws Exception {
// account.setDataGroups(ImmutableSet.of(TEST_USER_GROUP));
// mockExternalService(200, "OK");
// // no errors
// controller.createLabOrder(account);
//
// verify(controller).put(eq("http://testServer/userId"), any(), any());
// }
//
// @Test
// public void createLabOrderCreated() throws Exception {
// mockExternalService(201, "Created");
// // no errors
// controller.createLabOrder(account);
// }
//
// @Test(expectedExceptions = BridgeServiceException.class,
// expectedExceptionsMessageRegExp = "Internal Service Error")
// public void createLabOrderBadRequest() throws Exception {
// mockExternalService(400, "Bad Request");
// controller.createLabOrder(account);
// }
//
// @Test(expectedExceptions = BridgeServiceException.class)
// public void createLabOrderInternalServerError() throws Exception {
// mockExternalService(500, "Internal Server Error");
// controller.createLabOrder(account);
// }
//
// @Test(expectedExceptions = BridgeServiceException.class)
// public void createLabOrderServiceUnavailable() throws Exception {
// mockExternalService(503, "Service Unavailable");
// controller.createLabOrder(account);
// }
//
// @Test(expectedExceptions = BridgeServiceException.class)
// public void createLabOrderIOException() throws Exception {
// doThrow(new IOException()).when(controller).put(any(), any(), any());
// controller.createLabOrder(account);
// }
// private void mockExternalService(int statusCode, String statusReason) throws Exception {
// StatusLine statusLine = new BasicStatusLine(new ProtocolVersion("HTTP", 1, 2), statusCode, statusReason);
// HttpResponse response = new BasicHttpResponse(statusLine);
// doReturn(response).when(controller).put(any(), any(), any());
// }
private void addAppointmentSageId(Appointment appointment, String value) {
AppointmentParticipantComponent comp = new AppointmentParticipantComponent();
Identifier id = new Identifier();
id.setSystem(USER_ID_VALUE_NS);
id.setValue(value);
Reference ref = new Reference();
ref.setIdentifier(id);
comp.setActor(ref);
appointment.addParticipant(comp);
}
Aggregations