Search in sources :

Example 6 with Account

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);
}
Also used : Appointment(org.hl7.fhir.dstu3.model.Appointment) Account(org.sagebionetworks.bridge.models.accounts.Account) HealthDataSubmission(org.sagebionetworks.bridge.models.healthdata.HealthDataSubmission) ReportData(org.sagebionetworks.bridge.models.reports.ReportData) SignIn(org.sagebionetworks.bridge.models.accounts.SignIn) DateRangeResourceList(org.sagebionetworks.bridge.models.DateRangeResourceList) StatusMessage(org.sagebionetworks.bridge.models.StatusMessage) Test(org.testng.annotations.Test)

Example 7 with Account

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();
}
Also used : Identifier(org.hl7.fhir.dstu3.model.Identifier) ProcedureRequest(org.hl7.fhir.dstu3.model.ProcedureRequest) Test(org.testng.annotations.Test)

Example 8 with Account

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");
}
Also used : Address(org.hl7.fhir.dstu3.model.Address) Patient(org.hl7.fhir.dstu3.model.Patient) Test(org.testng.annotations.Test)

Example 9 with Account

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);
}
Also used : Account(org.sagebionetworks.bridge.models.accounts.Account) Patient(org.hl7.fhir.dstu3.model.Patient) Test(org.testng.annotations.Test)

Example 10 with Account

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();
}
Also used : Identifier(org.hl7.fhir.dstu3.model.Identifier) Observation(org.hl7.fhir.dstu3.model.Observation) Test(org.testng.annotations.Test)

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