use of org.hl7.fhir.r4.model.Location in project metacat by Netflix.
the class S3ConnectorTableService method update.
@Override
public void update(@Nonnull final ConnectorRequestContext context, @Nonnull final TableInfo tableInfo) {
log.debug("Start: Update table {}", tableInfo.getName());
final QualifiedName tableName = tableInfo.getName();
final Table table = tableDao.getBySourceDatabaseTableName(catalogName, tableName.getDatabaseName(), tableName.getTableName());
if (table == null) {
throw new TableNotFoundException(tableName);
}
// we can update the fields, the uri, or the full serde
final Location newLocation = infoConverter.toLocation(tableInfo);
Location location = table.getLocation();
if (location == null) {
location = new Location();
location.setTable(table);
table.setLocation(location);
}
if (newLocation.getUri() != null) {
location.setUri(newLocation.getUri());
}
final Info newInfo = newLocation.getInfo();
if (newInfo != null) {
final Info info = location.getInfo();
if (info == null) {
location.setInfo(newInfo);
newInfo.setLocation(location);
} else {
if (newInfo.getInputFormat() != null) {
info.setInputFormat(newInfo.getInputFormat());
}
if (newInfo.getOutputFormat() != null) {
info.setOutputFormat(newInfo.getOutputFormat());
}
if (newInfo.getOwner() != null) {
info.setOwner(newInfo.getOwner());
}
if (newInfo.getSerializationLib() != null) {
info.setSerializationLib(newInfo.getSerializationLib());
}
if (newInfo.getParameters() != null && !newInfo.getParameters().isEmpty()) {
info.setParameters(newInfo.getParameters());
}
}
}
final Schema newSchema = newLocation.getSchema();
if (newSchema != null) {
final List<Field> newFields = newSchema.getFields();
if (newFields != null && !newFields.isEmpty()) {
final Schema schema = location.getSchema();
if (schema == null) {
location.setSchema(newSchema);
newSchema.setLocation(location);
} else {
final List<Field> fields = schema.getFields();
if (fields.isEmpty()) {
newFields.forEach(field -> {
field.setSchema(schema);
fields.add(field);
});
} else {
for (int i = 0; i < newFields.size(); i++) {
final Field newField = newFields.get(i);
newField.setPos(i);
newField.setSchema(schema);
if (newField.getType() == null) {
newField.setType(newField.getSourceType());
}
}
schema.setFields(null);
fieldDao.delete(fields);
tableDao.save(table, true);
schema.setFields(newFields);
}
}
}
}
log.debug("End: Update table {}", tableInfo.getName());
}
use of org.hl7.fhir.r4.model.Location in project metacat by Netflix.
the class S3ConnectorInfoConverter method toFields.
private List<FieldInfo> toFields(final Table table) {
List<FieldInfo> result = Lists.newArrayList();
final Location location = table.getLocation();
if (location != null) {
final Schema schema = location.getSchema();
if (schema != null) {
result = schema.getFields().stream().sorted(Comparator.comparing(Field::getPos)).map(this::toFieldInfo).collect(Collectors.toList());
}
}
return result;
}
use of org.hl7.fhir.r4.model.Location in project metacat by Netflix.
the class S3ConnectorInfoConverter method toAuditInfo.
/**
* Creates audit info from s3 table info.
* @param table table info
* @return audit info
*/
public AuditInfo toAuditInfo(final Table table) {
final AuditInfo result = AuditInfo.builder().createdDate(table.getCreatedDate()).lastModifiedDate(table.getLastUpdatedDate()).build();
final Location location = table.getLocation();
if (location != null) {
final Info info = location.getInfo();
if (info != null) {
result.setCreatedBy(info.getOwner());
result.setLastModifiedBy(info.getOwner());
}
}
return result;
}
use of org.hl7.fhir.r4.model.Location in project metacat by Netflix.
the class S3ConnectorInfoConverter method toLocation.
/**
* Creates location.
* @param tableInfo table info
* @return location
*/
public Location toLocation(final TableInfo tableInfo) {
final Location location = fromStorageInfo(tableInfo.getSerde());
final Schema schema = new Schema();
schema.setLocation(location);
schema.setFields(toFields(tableInfo, schema));
location.setSchema(schema);
return location;
}
use of org.hl7.fhir.r4.model.Location in project gpconnect-demonstrator by nhsconnect.
the class AppointmentResourceProvider method appointmentResourceConverterToAppointmentDetail.
/**
* fhir resource Appointment to AppointmentDetail
*
* @param appointment Resource
* @return populated AppointmentDetail
*/
private AppointmentDetail appointmentResourceConverterToAppointmentDetail(Appointment appointment) {
appointmentValidation.validateAppointmentExtensions(appointment.getExtension());
if (appointmentValidation.appointmentDescriptionTooLong(appointment)) {
throwUnprocessableEntity422_InvalidResourceException("Appointment description cannot be greater then " + APPOINTMENT_DESCRIPTION_LENGTH + " characters");
}
AppointmentDetail appointmentDetail = new AppointmentDetail();
Long id = appointment.getIdElement().getIdPartAsLong();
appointmentDetail.setId(id);
appointmentDetail.setLastUpdated(getLastUpdated(appointment.getMeta().getLastUpdated()));
List<Extension> cnlExtension = appointment.getExtensionsByUrl(SystemURL.SD_EXTENSION_GPC_APPOINTMENT_CANCELLATION_REASON);
if (cnlExtension != null && !cnlExtension.isEmpty()) {
IBaseDatatype value = cnlExtension.get(0).getValue();
if (null == value) {
throwInvalidRequest400_BadRequestException("Cancellation reason missing.");
}
appointmentDetail.setCancellationReason(value.toString());
}
appointmentDetail.setStatus(appointment.getStatus().toString().toLowerCase(Locale.UK));
appointmentDetail.setMinutesDuration(appointment.getMinutesDuration());
appointmentDetail.setPriority(appointment.getPriority());
appointmentDetail.setStartDateTime(appointment.getStart());
appointmentDetail.setEndDateTime(appointment.getEnd());
List<Long> slotIds = new ArrayList<>();
for (Reference slotReference : appointment.getSlot()) {
// #200 check slots for absolute references
checkReferenceIsRelative(slotReference.getReference());
try {
String here = slotReference.getReference().substring("Slot/".length());
Long slotId = new Long(here);
slotIds.add(slotId);
} catch (NumberFormatException ex) {
throwUnprocessableEntity422_InvalidResourceException(String.format("The slot reference value data type for %s is not valid.", slotReference.getReference()));
}
}
appointmentDetail.setSlotIds(slotIds);
if (appointmentValidation.appointmentCommentTooLong(appointment)) {
throwUnprocessableEntity422_InvalidResourceException("Appointment comment cannot be greater than " + APPOINTMENT_COMMENT_LENGTH + " characters");
}
appointmentDetail.setComment(appointment.getComment());
appointmentDetail.setDescription(appointment.getDescription());
for (AppointmentParticipantComponent participant : appointment.getParticipant()) {
if (participant.getActor() != null) {
String participantReference = participant.getActor().getReference();
String actorIdString = participantReference.substring(participantReference.lastIndexOf("/") + 1);
Long actorId;
if (actorIdString.equals("null")) {
actorId = null;
} else {
actorId = Long.valueOf(actorIdString);
}
if (participantReference.contains("Patient/")) {
appointmentDetail.setPatientId(actorId);
} else if (participantReference.contains("Practitioner/")) {
appointmentDetail.setPractitionerId(actorId);
} else if (participantReference.contains("Location/")) {
appointmentDetail.setLocationId(actorId);
}
} else {
throwUnprocessableEntity422_InvalidResourceException("Participant Actor cannot be null");
}
}
if (appointment.getCreated() != null) {
Date created = appointment.getCreated();
appointmentDetail.setCreated(created);
}
// #200 check extensions for absolute references
List<Extension> extensions = appointment.getExtension();
for (Extension extension : extensions) {
try {
Reference reference = (Reference) extension.getValue();
if (reference != null) {
checkReferenceIsRelative(reference.getReference());
}
} catch (ClassCastException ex) {
}
}
List<Resource> contained = appointment.getContained();
if (contained != null && !contained.isEmpty()) {
Resource org = contained.get(0);
Organization bookingOrgRes = (Organization) org;
BookingOrgDetail bookingOrgDetail = new BookingOrgDetail();
appointmentValidation.validateBookingOrganizationValuesArePresent(bookingOrgRes);
bookingOrgDetail.setName(bookingOrgRes.getName());
// #198 add system and optional use type. Pick system phone if > 1 and available otherwise use the one supplied
Iterator<ContactPoint> iter = bookingOrgRes.getTelecom().iterator();
ContactPoint telecom = bookingOrgRes.getTelecomFirstRep();
while (iter.hasNext()) {
ContactPoint thisTelecom = iter.next();
if (thisTelecom.getSystem() == ContactPoint.ContactPointSystem.PHONE) {
telecom = thisTelecom;
break;
}
}
bookingOrgDetail.setTelephone(telecom.getValue());
bookingOrgDetail.setSystem(telecom.getSystem().toString());
if (telecom.getUse() != null && !telecom.getUse().toString().trim().isEmpty()) {
bookingOrgDetail.setUsetype(telecom.getUse().toString());
}
if (!bookingOrgRes.getIdentifier().isEmpty()) {
bookingOrgDetail.setOrgCode(bookingOrgRes.getIdentifierFirstRep().getValue());
String system = bookingOrgRes.getIdentifierFirstRep().getSystem();
// check that organization identifier system is https://fhir.nhs.uk/Id/ods-organization-code
if (system != null && !system.trim().isEmpty()) {
if (!system.equals(ID_ODS_ORGANIZATION_CODE)) {
throwUnprocessableEntity422_InvalidResourceException("Appointment organisation identifier system must be an ODS code!");
}
} else {
throwUnprocessableEntity422_InvalidResourceException("Appointment organisation identifier system must be populated!");
}
}
bookingOrgDetail.setAppointmentDetail(appointmentDetail);
appointmentDetail.setBookingOrganization(bookingOrgDetail);
// 1.2.7
appointmentDetail.setServiceCategory(appointment.getServiceCategory().getText());
appointmentDetail.setServiceType(appointment.getServiceTypeFirstRep().getText());
}
return appointmentDetail;
}
Aggregations