use of com.vividsolutions.jts.io.geojson.GeoJsonWriter in project geoprism-registry by terraframe.
the class ListTypeFhirExporter method createFacility.
private Facility createFacility(Business row, Identifier identifier) {
String code = row.getValue(DefaultAttribute.CODE.getName());
Organization org = new Organization();
org.setId(new IdType(org.getResourceType().name(), code));
org.setName(row.getValue(DefaultAttribute.DISPLAY_LABEL.getName() + ListTypeVersion.DEFAULT_LOCALE));
org.addIdentifier(identifier);
Location location = new Location();
location.setId(new IdType(location.getResourceType().name(), code));
location.setName(row.getValue(DefaultAttribute.DISPLAY_LABEL.getName() + ListTypeVersion.DEFAULT_LOCALE));
location.setManagingOrganization(new Reference(org.getIdElement()));
location.addIdentifier(identifier);
Geometry geometry = row.getObjectValue(RegistryConstants.GEOMETRY_ATTRIBUTE_NAME);
if (geometry != null) {
Point centroid = geometry.getCentroid();
GeoJsonWriter writer = new GeoJsonWriter();
String geojson = writer.write(geometry);
Encoder encoder = Base64.getEncoder();
// Create a location
Attachment attachment = new Attachment();
attachment.setContentType("application/json");
attachment.setDataElement(new Base64BinaryType(encoder.encodeToString(geojson.getBytes())));
attachment.setTitle("Geojson");
Extension extension = new Extension("http://hl7.org/fhir/StructureDefinition/location-boundary-geojson");
extension.setValue(attachment);
location.setPosition(new LocationPositionComponent(new DecimalType(centroid.getX()), new DecimalType(centroid.getY())));
location.addExtension(extension);
}
return new Facility(org, location);
}
Aggregations