3.7.2. Create a custom implementation for exporting data to FHIR
All custom implementations for exporting data to a FHIR instance must implement the net.geoprism.registry.etl.fhir.FhirDataPopulator interface.
package com.terraframe.demo;
import java.util.LinkedList;
import java.util.List;
import org.commongeoregistry.adapter.constants.GeometryType;
import org.hl7.fhir.r4.model.Bundle;
import org.hl7.fhir.r4.model.CodeableConcept;
import org.hl7.fhir.r4.model.Coding;
import org.hl7.fhir.r4.model.Location;
import org.hl7.fhir.r4.model.Organization;
import com.google.gson.JsonArray;
import com.google.gson.JsonObject;
import com.runwaysdk.business.Business;
import net.geoprism.registry.MasterList;
import net.geoprism.registry.MasterListVersion;
import net.geoprism.registry.etl.fhir.AbstractFhirDataPopulator;
import net.geoprism.registry.etl.fhir.Facility;
import net.geoprism.registry.etl.fhir.FhirDataPopulator;
import net.geoprism.registry.etl.fhir.FhirExportContext;
import net.geoprism.registry.model.ServerGeoObjectType;
import net.geoprism.registry.model.ServerHierarchyType;
public class DemoFhirDataPopulator extends AbstractFhirDataPopulator implements FhirDataPopulator
{
private List<ServerHierarchyType> hierarchies;
public DemoFhirDataPopulator()
{
super();
this.hierarchies = new LinkedList<ServerHierarchyType>();
}
@Override
public String getLabel()
{
return "Demo Export Implementation";
}
@Override
public void configure(FhirExportContext context, MasterListVersion version, boolean resolveIds)
{
super.configure(context, version, resolveIds);
MasterList list = version.getMasterlist();
JsonArray hierarchies = list.getHierarchiesAsJson();
for (int i = 0; i < hierarchies.size(); i++)
{
JsonObject hierarchy = hierarchies.get(i).getAsJsonObject();
String hCode = hierarchy.get("code").getAsString();
List<String> pCodes = list.getParentCodes(hierarchy);
if (pCodes.size() > 0)
{
this.hierarchies.add(ServerHierarchyType.get(hCode));
}
}
}
@Override
public void populate(Business row, Facility facility)
{
super.populate(row, facility);
ServerGeoObjectType type = this.getList().getGeoObjectType();
String label = type.getLabel().getValue();
String system = this.getContext().getSystem();
CodeableConcept concept = new CodeableConcept().setText(label).addCoding(new Coding(system, type.getCode(), label));
Location location = facility.getLocation();
location.addType(concept);
location.getMeta().addProfile("http://ihe.net/fhir/StructureDefinition/IHE.mCSD.Location");
Organization organization = facility.getOrganization();
organization.addType(concept);
organization.getMeta().addProfile("http://ihe.net/fhir/StructureDefinition/IHE.mCSD.Organization");
if (type.getGeometryType().equals(GeometryType.MULTIPOINT))
{
location.getMeta().addProfile("http://ihe.net/fhir/StructureDefinition/IHE.mCSD.FacilityLocation");
location.addType(new CodeableConcept().addCoding(new Coding("urn:ietf:rfc:3986", "urn:ihe:iti:mcsd:2019:facility", "Facility")));
organization.getMeta().addProfile("http://ihe.net/fhir/StructureDefinition/IHE.mCSD.FacilityOrganization");
organization.addType(new CodeableConcept().addCoding(new Coding("urn:ietf:rfc:3986", "urn:ihe:iti:mcsd:2019:facility", "Facility")));
}
else
{
location.getMeta().addProfile("http://ihe.net/fhir/StructureDefinition/IHE.mCSD.JurisdictionLocation");
location.addType(new CodeableConcept().addCoding(new Coding("urn:ietf:rfc:3986", "urn:ihe:iti:mcsd:2019:jurisdiction", "Jurisdiction")));
organization.getMeta().addProfile("http://ihe.net/fhir/StructureDefinition/IHE.mCSD.JurisdictionsOrganization");
organization.addType(new CodeableConcept().addCoding(new Coding("urn:ietf:rfc:3986", "urn:ihe:iti:mcsd:2019:jurisdiction", "Jurisdiction")));
}
for (ServerHierarchyType hierarchy : this.hierarchies)
{
this.addHierarchyExtension(row, facility, hierarchy);
}
}
@Override
public void createExtraResources(Business row, Bundle bundle, Facility facility)
{
}
@Override
public void finish(Bundle bundle)
{
}
}
Previous3.7.1. Maven project setupNext3.7.3. Create a custom implementation for importing data from FHIR to GeoPrism Registry
Last updated