Search in sources :

Example 1 with Account

use of org.hl7.fhir.dstu3.model.Account in project BridgeServer2 by Sage-Bionetworks.

the class CRCController method post.

// HttpResponse get(String url, Account account) throws IOException {
// Request request = Request.Get(url);
// request = addAuthorizationHeader(request, account);
// return request.execute().returnResponse();
// }
HttpResponse post(String url, Account account, String body) throws IOException {
    Request request = Request.Post(url).bodyString(body, APPLICATION_FORM_URLENCODED);
    request = addAuthorizationHeader(request, account);
    return request.execute().returnResponse();
}
Also used : ProcedureRequest(org.hl7.fhir.dstu3.model.ProcedureRequest) Request(org.apache.http.client.fluent.Request)

Example 2 with Account

use of org.hl7.fhir.dstu3.model.Account in project BridgeServer2 by Sage-Bionetworks.

the class CRCController method createPatient.

Patient createPatient(Account account) {
    Patient patient = new Patient();
    patient.setActive(true);
    patient.setId(account.getId());
    Identifier identifier = new Identifier();
    identifier.setValue(account.getId());
    identifier.setSystem(USER_ID_VALUE_NS);
    patient.addIdentifier(identifier);
    Coding coding = new Coding();
    coding.setSystem("source");
    coding.setCode("sage");
    Meta meta = new Meta();
    meta.setTag(ImmutableList.of(coding));
    patient.setMeta(meta);
    HumanName name = new HumanName();
    if (isNotBlank(account.getFirstName())) {
        name.addGiven(account.getFirstName());
    }
    if (isNotBlank(account.getLastName())) {
        name.setFamily(account.getLastName());
    }
    patient.addName(name);
    Map<String, String> atts = account.getAttributes();
    if (isNotBlank(atts.get("gender"))) {
        if ("female".equalsIgnoreCase(atts.get("gender"))) {
            patient.setGender(AdministrativeGender.FEMALE);
        } else if ("male".equalsIgnoreCase(atts.get("gender"))) {
            patient.setGender(AdministrativeGender.MALE);
        } else {
            patient.setGender(AdministrativeGender.OTHER);
        }
    } else {
        patient.setGender(AdministrativeGender.UNKNOWN);
    }
    if (isNotBlank(atts.get("dob"))) {
        LocalDate localDate = LocalDate.parse(atts.get("dob"));
        patient.setBirthDate(localDate.toDate());
    }
    Address address = new Address();
    if (isNotBlank(atts.get("address1"))) {
        address.addLine(atts.get("address1"));
    }
    if (isNotBlank(atts.get("address2"))) {
        address.addLine(atts.get("address2"));
    }
    if (isNotBlank(atts.get("city"))) {
        address.setCity(atts.get("city"));
    }
    if (isNotBlank(atts.get("state"))) {
        address.setState(atts.get("state"));
    } else {
        address.setState("NY");
    }
    if (isNotBlank(atts.get("zip_code"))) {
        address.setPostalCode(atts.get("zip_code"));
    }
    patient.addAddress(address);
    if (isNotBlank(atts.get("home_phone"))) {
        ContactPoint contact = new ContactPoint();
        contact.setSystem(ContactPointSystem.PHONE);
        contact.setValue(atts.get("home_phone"));
        patient.addTelecom(contact);
    }
    if (account.getPhone() != null && TRUE.equals(account.getPhoneVerified())) {
        ContactPoint contact = new ContactPoint();
        contact.setSystem(ContactPointSystem.SMS);
        contact.setValue(account.getPhone().getNumber());
        patient.addTelecom(contact);
    }
    if (account.getEmail() != null && TRUE.equals(account.getEmailVerified())) {
        ContactPoint contact = new ContactPoint();
        contact.setSystem(ContactPointSystem.EMAIL);
        contact.setValue(account.getEmail());
        patient.addTelecom(contact);
    }
    Reference ref = new Reference("CUZUCK");
    ref.setDisplay("COVID Recovery Corps");
    ContactComponent contact = new ContactComponent();
    contact.setOrganization(ref);
    patient.addContact(contact);
    return patient;
}
Also used : Meta(org.hl7.fhir.dstu3.model.Meta) HumanName(org.hl7.fhir.dstu3.model.HumanName) ContactPoint(org.hl7.fhir.dstu3.model.ContactPoint) Identifier(org.hl7.fhir.dstu3.model.Identifier) Address(org.hl7.fhir.dstu3.model.Address) Coding(org.hl7.fhir.dstu3.model.Coding) Reference(org.hl7.fhir.dstu3.model.Reference) ContactComponent(org.hl7.fhir.dstu3.model.Patient.ContactComponent) Patient(org.hl7.fhir.dstu3.model.Patient) LocalDate(org.joda.time.LocalDate)

Example 3 with Account

use of org.hl7.fhir.dstu3.model.Account in project BridgeServer2 by Sage-Bionetworks.

the class CRCController method addLocation.

/**
 * This is a nice-to-have addition of address information for the location given by an
 * ID in the appointment record. Do not fail the request if this fails, but log enough
 * to troubleshoot if the issue is on our side.
 */
void addLocation(JsonNode node, Account account, String locationId) {
    String cuimcEnv = (account.getDataGroups().contains(TEST_USER_GROUP)) ? "test" : "prod";
    String cuimcUrl = "cuimc." + cuimcEnv + ".location.url";
    String url = bridgeConfig.get(cuimcUrl);
    String reqBody = "id=\"" + locationId + "\"";
    try {
        HttpResponse response = post(url, account, reqBody);
        String resBody = IOUtils.toString(response.getEntity().getContent(), StandardCharsets.UTF_8.name());
        int statusCode = response.getStatusLine().getStatusCode();
        if (statusCode != 200 && statusCode != 201) {
            logWarningMessage(locationId, statusCode, resBody);
            return;
        }
        JsonNode bundleJson = BridgeObjectMapper.get().readTree(resBody);
        if (!bundleJson.has("entry") || ((ArrayNode) bundleJson.get("entry")).size() == 0) {
            logWarningMessage(locationId, statusCode, resBody);
            return;
        }
        JsonNode resJson = bundleJson.get("entry").get(0).get("resource");
        if (resJson == null) {
            logWarningMessage(locationId, statusCode, resBody);
            return;
        }
        JsonNode telecom = resJson.get("telecom");
        JsonNode address = resJson.get("address");
        ArrayNode participants = (ArrayNode) node.get("participant");
        if (participants != null) {
            for (int i = 0; i < participants.size(); i++) {
                JsonNode child = participants.get(i);
                ObjectNode actor = (ObjectNode) child.get("actor");
                if (actor != null && actor.has("reference")) {
                    String ref = actor.get("reference").textValue();
                    if (ref.startsWith("Location")) {
                        if (telecom != null) {
                            actor.set("telecom", telecom);
                        }
                        if (address != null) {
                            actor.set("address", address);
                        // addGeocodingInformation(actor);
                        }
                        break;
                    }
                }
            }
        }
    } catch (IOException e) {
        LOG.warn("Error retrieving location, id = " + locationId, e);
        return;
    }
    LOG.info("Location added to appointment record for user " + account.getId());
}
Also used : ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) HttpResponse(org.apache.http.HttpResponse) JsonNode(com.fasterxml.jackson.databind.JsonNode) ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode) IOException(java.io.IOException) ContactPoint(org.hl7.fhir.dstu3.model.ContactPoint)

Example 4 with Account

use of org.hl7.fhir.dstu3.model.Account in project BridgeServer2 by Sage-Bionetworks.

the class CRCControllerTest method createEmptyPatient.

@Test
public void createEmptyPatient() {
    Patient patient = controller.createPatient(account);
    assertEquals(patient.getGender().name(), "UNKNOWN");
    // I'm defaulting this because I don't see the client submitting it in the UI, so
    // I'm anticipating it won't be there, but eventually we'll have to collect state.
    assertEquals(patient.getAddress().get(0).getState(), "NY");
    assertTrue(patient.getActive());
}
Also used : Patient(org.hl7.fhir.dstu3.model.Patient) Test(org.testng.annotations.Test)

Example 5 with Account

use of org.hl7.fhir.dstu3.model.Account in project BridgeServer2 by Sage-Bionetworks.

the class CRCControllerTest method placeOrderForHealthCode.

@Test
public void placeOrderForHealthCode() {
    when(mockRequest.getHeader(AUTHORIZATION)).thenReturn(AUTHORIZATION_HEADER_VALUE);
    when(mockAccountService.authenticate(any(), any())).thenReturn(account);
    setupShippingAddress();
    ArgumentCaptor<AccountId> accountIdCaptor = ArgumentCaptor.forClass(AccountId.class);
    when(mockAccountService.getAccount(accountIdCaptor.capture())).thenReturn(Optional.of(account));
    DateRangeResourceList<? extends ReportData> results = new DateRangeResourceList<>(ImmutableList.of());
    doReturn(results).when(mockReportService).getParticipantReport(APP_ID, TEST_USER_ID, SHIPMENT_REPORT, HEALTH_CODE, JAN1, JAN2);
    controller.postLabShipmentRequest("healthcode:" + HEALTH_CODE);
    verify(mockAccountService).authenticate(any(), any());
    verify(mockAccountService, atLeastOnce()).getAccount(accountIdCaptor.capture());
    assertTrue(accountIdCaptor.getAllValues().stream().anyMatch(accountId -> accountId.getHealthCode().equals(HEALTH_CODE)));
    verify(mockReportService).saveParticipantReport(eq(APP_ID), eq(TEST_USER_ID), eq(SHIPMENT_REPORT), eq(HEALTH_CODE), reportCaptor.capture());
    verify(controller).internalLabShipmentRequest(any(), any());
    ReportData capturedReport = reportCaptor.getValue();
    String orderId = capturedReport.getData().get(SHIPMENT_REPORT_KEY_ORDER_ID).asText();
    assertTrue(orderId.startsWith(ACCOUNT_ID.getId()));
}
Also used : ILoggingEvent(ch.qos.logback.classic.spi.ILoggingEvent) ENTEREDINERROR(org.hl7.fhir.dstu3.model.Appointment.AppointmentStatus.ENTEREDINERROR) CANCELLED(org.hl7.fhir.dstu3.model.Appointment.AppointmentStatus.CANCELLED) SYN_USERNAME(org.sagebionetworks.bridge.spring.controllers.CRCController.SYN_USERNAME) Identifier(org.hl7.fhir.dstu3.model.Identifier) APPOINTMENT_REPORT(org.sagebionetworks.bridge.spring.controllers.CRCController.APPOINTMENT_REPORT) Test(org.testng.annotations.Test) RequestContext(org.sagebionetworks.bridge.RequestContext) AfterMethod(org.testng.annotations.AfterMethod) StatusLine(org.apache.http.StatusLine) EMAIL(org.sagebionetworks.bridge.TestConstants.EMAIL) MockitoAnnotations(org.mockito.MockitoAnnotations) CUIMC_USERNAME(org.sagebionetworks.bridge.spring.controllers.CRCController.CUIMC_USERNAME) NotAuthenticatedException(org.sagebionetworks.bridge.exceptions.NotAuthenticatedException) JsonNode(com.fasterxml.jackson.databind.JsonNode) RESEARCHER(org.sagebionetworks.bridge.Roles.RESEARCHER) Assert.assertFalse(org.testng.Assert.assertFalse) BOOKED(org.hl7.fhir.dstu3.model.Appointment.AppointmentStatus.BOOKED) TIMESTAMP_FIELD(org.sagebionetworks.bridge.spring.controllers.CRCController.TIMESTAMP_FIELD) Reference(org.hl7.fhir.dstu3.model.Reference) OBSERVATION_REPORT(org.sagebionetworks.bridge.spring.controllers.CRCController.OBSERVATION_REPORT) TestUtils.createJson(org.sagebionetworks.bridge.TestUtils.createJson) StatusMessage(org.sagebionetworks.bridge.models.StatusMessage) Set(java.util.Set) Account(org.sagebionetworks.bridge.models.accounts.Account) IOUtils(org.apache.commons.io.IOUtils) Order(org.sagebionetworks.bridge.models.crc.gbf.external.Order) Stream(java.util.stream.Stream) Logger(ch.qos.logback.classic.Logger) USER_STUDY_IDS(org.sagebionetworks.bridge.TestConstants.USER_STUDY_IDS) TestUtils.mockRequestBody(org.sagebionetworks.bridge.TestUtils.mockRequestBody) TEST_ORG_ID(org.sagebionetworks.bridge.TestConstants.TEST_ORG_ID) ContactPointSystem(org.hl7.fhir.dstu3.model.ContactPoint.ContactPointSystem) HealthDataSubmission(org.sagebionetworks.bridge.models.healthdata.HealthDataSubmission) SHIP_TESTS_REQUESTED(org.sagebionetworks.bridge.spring.controllers.CRCController.AccountStates.SHIP_TESTS_REQUESTED) SignIn(org.sagebionetworks.bridge.models.accounts.SignIn) SessionUpdateService(org.sagebionetworks.bridge.services.SessionUpdateService) AppointmentParticipantComponent(org.hl7.fhir.dstu3.model.Appointment.AppointmentParticipantComponent) IP_ADDRESS(org.sagebionetworks.bridge.TestConstants.IP_ADDRESS) Mock(org.mockito.Mock) PHONE(org.sagebionetworks.bridge.TestConstants.PHONE) GBFOrderService(org.sagebionetworks.bridge.services.GBFOrderService) AppointmentStatus(org.hl7.fhir.dstu3.model.Appointment.AppointmentStatus) Roles(org.sagebionetworks.bridge.Roles) BridgeObjectMapper(org.sagebionetworks.bridge.json.BridgeObjectMapper) HttpServletRequest(javax.servlet.http.HttpServletRequest) GBF_TEST_KIT_SHIP_METHOD(org.sagebionetworks.bridge.spring.controllers.CRCController.GBF_TEST_KIT_SHIP_METHOD) App(org.sagebionetworks.bridge.models.apps.App) PROCEDURE_REPORT(org.sagebionetworks.bridge.spring.controllers.CRCController.PROCEDURE_REPORT) LimitExceededException(org.sagebionetworks.bridge.exceptions.LimitExceededException) InjectMocks(org.mockito.InjectMocks) IOException(java.io.IOException) Observation(org.hl7.fhir.dstu3.model.Observation) SHIPMENT_REPORT(org.sagebionetworks.bridge.spring.controllers.CRCController.SHIPMENT_REPORT) SHIPMENT_REPORT_KEY_ORDER_ID(org.sagebionetworks.bridge.spring.controllers.CRCController.SHIPMENT_REPORT_KEY_ORDER_ID) Patient(org.hl7.fhir.dstu3.model.Patient) ProcedureRequest(org.hl7.fhir.dstu3.model.ProcedureRequest) HttpResponse(org.apache.http.HttpResponse) StudyParticipant(org.sagebionetworks.bridge.models.accounts.StudyParticipant) BadRequestException(org.sagebionetworks.bridge.exceptions.BadRequestException) AUTHORIZATION(com.google.common.net.HttpHeaders.AUTHORIZATION) LoggerFactory(org.slf4j.LoggerFactory) AccountId(org.sagebionetworks.bridge.models.accounts.AccountId) ReportData(org.sagebionetworks.bridge.models.reports.ReportData) LoggingEvent(ch.qos.logback.classic.spi.LoggingEvent) UserSession(org.sagebionetworks.bridge.models.accounts.UserSession) Spy(org.mockito.Spy) USER_AGENT(com.google.common.net.HttpHeaders.USER_AGENT) TestUtils(org.sagebionetworks.bridge.TestUtils) APP_ID(org.sagebionetworks.bridge.spring.controllers.CRCController.APP_ID) ImmutableSet(com.google.common.collect.ImmutableSet) Address(org.hl7.fhir.dstu3.model.Address) ImmutableMap(com.google.common.collect.ImmutableMap) TEST_USER_ID(org.sagebionetworks.bridge.TestConstants.TEST_USER_ID) HttpEntity(org.apache.http.HttpEntity) BeforeMethod(org.testng.annotations.BeforeMethod) USER_ID_VALUE_NS(org.sagebionetworks.bridge.spring.controllers.CRCController.USER_ID_VALUE_NS) Appointment(org.hl7.fhir.dstu3.model.Appointment) ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode) AppService(org.sagebionetworks.bridge.services.AppService) AdministrativeGender(org.hl7.fhir.dstu3.model.Enumerations.AdministrativeGender) AccountService(org.sagebionetworks.bridge.services.AccountService) Base64(java.util.Base64) ParticipantService(org.sagebionetworks.bridge.services.ParticipantService) Optional(java.util.Optional) BridgeUtils(org.sagebionetworks.bridge.BridgeUtils) Enrollment(org.sagebionetworks.bridge.models.studies.Enrollment) Assert.assertNull(org.testng.Assert.assertNull) Assert.assertEquals(org.testng.Assert.assertEquals) TestConstants(org.sagebionetworks.bridge.TestConstants) UTF_8(com.google.common.base.Charsets.UTF_8) Captor(org.mockito.Captor) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) DateRangeResourceList(org.sagebionetworks.bridge.models.DateRangeResourceList) ArgumentCaptor(org.mockito.ArgumentCaptor) ImmutableList(com.google.common.collect.ImmutableList) ReportService(org.sagebionetworks.bridge.services.ReportService) Appender(ch.qos.logback.core.Appender) BridgeConfig(org.sagebionetworks.bridge.config.BridgeConfig) IParser(ca.uhn.fhir.parser.IParser) InOrder(org.mockito.InOrder) Assert.fail(org.testng.Assert.fail) HttpServletResponse(javax.servlet.http.HttpServletResponse) ShippingConfirmations(org.sagebionetworks.bridge.models.crc.gbf.external.ShippingConfirmations) LocalDate(org.joda.time.LocalDate) Mockito(org.mockito.Mockito) HealthDataService(org.sagebionetworks.bridge.services.HealthDataService) Level(ch.qos.logback.classic.Level) TEST_USER_GROUP(org.sagebionetworks.bridge.BridgeConstants.TEST_USER_GROUP) TIMESTAMP(org.sagebionetworks.bridge.TestConstants.TIMESTAMP) FHIR_CONTEXT(org.sagebionetworks.bridge.spring.controllers.CRCController.FHIR_CONTEXT) Assert.assertTrue(org.testng.Assert.assertTrue) ResponseEntity(org.springframework.http.ResponseEntity) EntityNotFoundException(org.sagebionetworks.bridge.exceptions.EntityNotFoundException) AccountId(org.sagebionetworks.bridge.models.accounts.AccountId) ReportData(org.sagebionetworks.bridge.models.reports.ReportData) DateRangeResourceList(org.sagebionetworks.bridge.models.DateRangeResourceList) 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