Search in sources :

Example 1 with GeoJsonWriter

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);
}
Also used : GeoJsonWriter(com.vividsolutions.jts.io.geojson.GeoJsonWriter) Organization(org.hl7.fhir.r4.model.Organization) Reference(org.hl7.fhir.r4.model.Reference) Attachment(org.hl7.fhir.r4.model.Attachment) Point(com.vividsolutions.jts.geom.Point) IdType(org.hl7.fhir.r4.model.IdType) Geometry(com.vividsolutions.jts.geom.Geometry) Extension(org.hl7.fhir.r4.model.Extension) LocationPositionComponent(org.hl7.fhir.r4.model.Location.LocationPositionComponent) Encoder(java.util.Base64.Encoder) DecimalType(org.hl7.fhir.r4.model.DecimalType) Base64BinaryType(org.hl7.fhir.r4.model.Base64BinaryType) Location(org.hl7.fhir.r4.model.Location)

Aggregations

Geometry (com.vividsolutions.jts.geom.Geometry)1 Point (com.vividsolutions.jts.geom.Point)1 GeoJsonWriter (com.vividsolutions.jts.io.geojson.GeoJsonWriter)1 Encoder (java.util.Base64.Encoder)1 Attachment (org.hl7.fhir.r4.model.Attachment)1 Base64BinaryType (org.hl7.fhir.r4.model.Base64BinaryType)1 DecimalType (org.hl7.fhir.r4.model.DecimalType)1 Extension (org.hl7.fhir.r4.model.Extension)1 IdType (org.hl7.fhir.r4.model.IdType)1 Location (org.hl7.fhir.r4.model.Location)1 LocationPositionComponent (org.hl7.fhir.r4.model.Location.LocationPositionComponent)1 Organization (org.hl7.fhir.r4.model.Organization)1 Reference (org.hl7.fhir.r4.model.Reference)1