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();
}
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;
}
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());
}
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());
}
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()));
}
Aggregations