use of org.hl7.fhir.dstu3.model.Account in project BridgeServer2 by Sage-Bionetworks.
the class CRCControllerTest method postAppointmentCreated.
@Test
public void postAppointmentCreated() 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());
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/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 created (status = booked).");
assertEquals(retValue.getStatusCodeValue(), 201);
verify(mockAccountService).authenticate(eq(app), signInCaptor.capture());
SignIn capturedSignIn = signInCaptor.getValue();
assertEquals(capturedSignIn.getAppId(), APP_ID);
assertEquals(capturedSignIn.getExternalId(), CUIMC_USERNAME);
assertEquals(capturedSignIn.getPassword(), "dummy-password");
verify(mockReportService).saveParticipantReport(eq(APP_ID), eq(TEST_USER_ID), eq(APPOINTMENT_REPORT), eq(HEALTH_CODE), reportCaptor.capture());
ReportData capturedReport = reportCaptor.getValue();
assertEquals(capturedReport.getDate(), "1970-01-01");
verifyParticipant(capturedReport.getData());
assertEquals(capturedReport.getStudyIds(), USER_STUDY_IDS);
verify(mockAccountService).updateAccount(accountCaptor.capture());
Account capturedAcct = accountCaptor.getValue();
assertEquals(capturedAcct.getDataGroups(), makeSetOf(CRCController.AccountStates.TESTS_SCHEDULED, "group1"));
assertEquals(capturedAcct.getAttributes().get(TIMESTAMP_FIELD), TIMESTAMP.toString());
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 CRCControllerTest method procedureWrongIdentifier.
@Test(expectedExceptions = BadRequestException.class, expectedExceptionsMessageRegExp = "Could not find Bridge user ID.")
public void procedureWrongIdentifier() 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));
Identifier identifier = new Identifier();
identifier.setSystem("wrong-system");
identifier.setValue(TEST_USER_ID);
ProcedureRequest procedure = new ProcedureRequest();
procedure.addIdentifier(identifier);
String json = FHIR_CONTEXT.newJsonParser().encodeResourceToString(procedure);
mockRequestBody(mockRequest, json);
controller.postProcedureRequest();
}
use of org.hl7.fhir.dstu3.model.Account in project BridgeServer2 by Sage-Bionetworks.
the class CRCControllerTest method createPatient.
@Test
public void createPatient() {
account.setId("userId");
account.setFirstName("Test");
account.setLastName("User");
account.setEmail(EMAIL);
account.setEmailVerified(true);
account.setPhone(PHONE);
account.setPhoneVerified(true);
account.setAttributes(new ImmutableMap.Builder<String, String>().put("address1", "123 Sesame Street").put("address2", "Apt. 6").put("city", "Seattle").put("dob", "1980-08-10").put("gender", "female").put("state", "WA").put("zip_code", "10001").put("home_phone", PHONE.getNumber()).build());
Patient patient = controller.createPatient(account);
assertTrue(patient.getActive());
assertEquals(patient.getIdentifier().get(0).getValue(), TEST_USER_ID);
assertEquals(patient.getIdentifier().get(0).getSystem(), USER_ID_VALUE_NS);
assertEquals(patient.getName().get(0).getGivenAsSingleString(), "Test");
assertEquals(patient.getName().get(0).getFamily(), "User");
assertEquals(patient.getMeta().getTag().get(0).getSystem(), "source");
assertEquals(patient.getMeta().getTag().get(0).getCode(), "sage");
assertEquals(patient.getGender().name(), "FEMALE");
assertEquals(LocalDate.fromDateFields(patient.getBirthDate()).toString(), "1980-08-10");
assertEquals(patient.getTelecom().get(0).getValue(), PHONE.getNumber());
assertEquals(patient.getTelecom().get(0).getSystem().name(), "PHONE");
assertEquals(patient.getTelecom().get(1).getValue(), PHONE.getNumber());
assertEquals(patient.getTelecom().get(1).getSystem().name(), "SMS");
assertEquals(patient.getTelecom().get(2).getValue(), EMAIL);
assertEquals(patient.getTelecom().get(2).getSystem().name(), "EMAIL");
Address address = patient.getAddress().get(0);
assertEquals(address.getLine().get(0).getValue(), "123 Sesame Street");
assertEquals(address.getLine().get(1).getValue(), "Apt. 6");
assertEquals(address.getCity(), "Seattle");
assertEquals(address.getState(), "WA");
assertEquals(address.getPostalCode(), "10001");
}
use of org.hl7.fhir.dstu3.model.Account in project BridgeServer2 by Sage-Bionetworks.
the class CRCControllerTest method createPatientWithPhoneUnverified.
@Test
public void createPatientWithPhoneUnverified() {
Account account = Account.create();
account.setEmail(EMAIL);
account.setEmailVerified(true);
account.setPhone(PHONE);
account.setPhoneVerified(false);
Patient patient = controller.createPatient(account);
assertEquals(patient.getTelecom().size(), 1);
assertEquals(patient.getTelecom().get(0).getSystem(), ContactPointSystem.EMAIL);
}
use of org.hl7.fhir.dstu3.model.Account in project BridgeServer2 by Sage-Bionetworks.
the class CRCControllerTest method operationWrongIdentifier.
@Test(expectedExceptions = BadRequestException.class, expectedExceptionsMessageRegExp = "Could not find Bridge user ID.")
public void operationWrongIdentifier() 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));
Identifier identifier = new Identifier();
identifier.setSystem("wrong-system");
identifier.setValue(TEST_USER_ID);
Observation observation = new Observation();
observation.addIdentifier(identifier);
String json = FHIR_CONTEXT.newJsonParser().encodeResourceToString(observation);
mockRequestBody(mockRequest, json);
controller.postObservation();
}
Aggregations