Search in sources :

Example 41 with Account

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

Example 42 with Account

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

Example 43 with Account

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

Example 44 with Account

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);
}
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 45 with Account

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);
}
Also used : AppointmentParticipantComponent(org.hl7.fhir.dstu3.model.Appointment.AppointmentParticipantComponent) Identifier(org.hl7.fhir.dstu3.model.Identifier) Reference(org.hl7.fhir.dstu3.model.Reference)

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