use of org.hl7.fhir.r4.model.Reference in project hl7v2-fhir-converter by LinuxForHealth.
the class HL7MessageModel method convert.
@Override
public Bundle convert(Message message, MessageEngine engine) {
Preconditions.checkArgument(message != null, "Input Hl7 message cannot be null");
Preconditions.checkArgument(engine != null, "MessageEngine cannot be null");
HL7DataExtractor hl7DTE = new HL7DataExtractor(message);
HL7MessageData dataSource = new HL7MessageData(hl7DTE);
Bundle bundle = null;
// NOTE: We have seen PHI in these exception messages.
try {
bundle = engine.transform(dataSource, this.getResources(), new HashMap<>());
// Bundle is passed by reference and may be modified
deduplicate(bundle);
engine.getFHIRContext().validate(bundle);
} catch (Exception e) {
// Print stack class and trace without the error message.
handleException(e);
}
return bundle;
}
use of org.hl7.fhir.r4.model.Reference in project hl7v2-fhir-converter by LinuxForHealth.
the class HL7MessageModel method deduplicate.
// General deduplication utility. Currently only Organizations.
// Bundle is passed by reference and may be modified
private void deduplicate(Bundle bundle) {
List<BundleEntryComponent> entries = bundle.getEntry();
Iterator<BundleEntryComponent> i = entries.iterator();
while (i.hasNext()) {
// Safe traversal for removal
BundleEntryComponent entry = i.next();
// Currently only looking for duplicate Organizations, because their Urls and Id's are created from org data.
if (entry.getFullUrl().startsWith("Organization/") && duplicateFound(entry, entries)) {
// Safe removal
i.remove();
}
}
}
use of org.hl7.fhir.r4.model.Reference 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.r4.model.Reference 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.r4.model.Reference in project cqf-ruler by DBCG.
the class CompositionSectionComponentBuilder method initializeDstu2_1.
@Override
protected void initializeDstu2_1(T theResource) {
super.initializeDstu2_1(theResource);
org.hl7.fhir.dstu2016may.model.Composition.SectionComponent section = (org.hl7.fhir.dstu2016may.model.Composition.SectionComponent) theResource;
section.setTitle(myTitle).setId(getId());
getEntries().forEach(entry -> section.addEntry(new Reference(entry)));
if (myText != null) {
Narrative narrative = new Narrative();
narrative.setStatusAsString(myText.getStatus());
narrative.setDivAsString(myText.getText());
section.setText(narrative);
}
// no focus
}
Aggregations