use of org.hl7.fhir.r4.model.codesystems.ResourceTypes.ORGANIZATION in project odm2fhir by num-codex.
the class Subject method map.
public Stream<DomainResource> map(SubjectData subjectData) {
var value = getIdentifierAssigner();
if (!ENVIRONMENT.containsProperty("debug")) {
value = sha256Hex(value);
}
var organizationIdentifier = new Identifier().setSystem(getIdentifierSystem(ORGANIZATION)).setValue(value);
var organization = (Organization) new Organization().setName(getIdentifierAssigner()).addIdentifier(organizationIdentifier).setId(sha256Hex(organizationIdentifier.getSystem() + organizationIdentifier.getValue()));
organizationReference = new Reference(format("%s/%s", ORGANIZATION.toCode(), organization.getId()));
value = subjectData.getSubjectKey();
if (!ENVIRONMENT.containsProperty("debug")) {
value = sha256Hex(value);
}
var patientIdentifier = new Identifier().setSystem(getIdentifierSystem(PATIENT)).setValue(value).setType(new CodeableConcept(new Coding().setSystem(IDENTIFIER_TYPE_CODES.getUrl()).setCode(MR.toCode()))).setAssigner(organizationReference);
patient = (Patient) new Patient().addIdentifier(patientIdentifier).setId(sha256Hex(patientIdentifier.getSystem() + patientIdentifier.getValue())).setMeta(new Meta().addProfile(NUMStructureDefinition.PATIENT.getUrl()));
patientReference = new Reference(format("%s/%s", PATIENT.toCode(), patient.getId()));
return Stream.concat(Stream.of(patient, organization), subjectData.getMergedStudyEventData().stream().flatMap(studyEventData -> new StudyEvent().map(this, studyEventData)).peek(this::setId).peek(this::setPatientSubject));
}
use of org.hl7.fhir.r4.model.codesystems.ResourceTypes.ORGANIZATION in project geoprism-registry by terraframe.
the class AbstractFhirDataPopulator method getLiteralIdentifier.
private String getLiteralIdentifier(String code) {
if (this.resolveIds) {
if (!this.identifiers.containsKey(code)) {
IGenericClient client = context.getClient();
IBaseBundle result = client.search().forResource(Organization.class).count(1).where(Organization.IDENTIFIER.exactly().systemAndValues(context.getSystem(), code)).execute();
List<IBaseResource> resources = BundleUtil.toListOfResources(client.getFhirContext(), result);
if (resources.size() > 0) {
IBaseResource resource = resources.get(0);
IIdType idElement = resource.getIdElement();
this.identifiers.put(code, idElement.getResourceType() + "/" + idElement.getIdPart());
}
}
return this.identifiers.get(code);
}
return "Organization/" + code;
}
use of org.hl7.fhir.r4.model.codesystems.ResourceTypes.ORGANIZATION in project geoprism-registry by terraframe.
the class BasicFhirDataPopulator method populate.
@Override
public void populate(Business row, Facility facility) {
Organization org = facility.getOrganization();
org.addAlias(row.getValue(DefaultAttribute.DISPLAY_LABEL.getName() + ListTypeVersion.DEFAULT_LOCALE));
Location location = facility.getLocation();
location.setMode(LocationMode.INSTANCE);
location.setStatus(LocationStatus.ACTIVE);
location.addAlias(row.getValue(DefaultAttribute.DISPLAY_LABEL.getName() + ListTypeVersion.DEFAULT_LOCALE));
Collection<Locale> locales = LocalizationFacade.getInstalledLocales();
for (Locale locale : locales) {
String attributeName = DefaultAttribute.DISPLAY_LABEL.getName() + locale.toString();
if (row.hasAttribute(attributeName)) {
String value = row.getValue(attributeName);
if (value != null) {
org.addAlias(value);
location.addAlias(value);
}
}
}
}
use of org.hl7.fhir.r4.model.codesystems.ResourceTypes.ORGANIZATION in project geoprism-registry by terraframe.
the class FhirBulkDataImporter method synchronize.
public void synchronize() {
PoolingHttpClientConnectionManager connectionManager = new PoolingHttpClientConnectionManager(5000, TimeUnit.MILLISECONDS);
HttpClientBuilder builder = HttpClientBuilder.create();
builder.setConnectionManager(connectionManager);
CloseableHttpClient myClient = builder.build();
FhirContext ctx = FhirContext.forR4();
String statusUrl = initiateBulkExport(myClient, ctx);
if (statusUrl != null) {
final List<String> outputs = getExportResults(myClient, statusUrl);
IGenericClient client = ctx.newRestfulGenericClient(this.system.getUrl());
for (String binaryUrl : outputs) {
Binary binary = client.fetchResourceFromUrl(Binary.class, binaryUrl);
String base64 = binary.getContentAsBase64();
byte[] result = Base64.getDecoder().decode(base64);
IParser parser = ctx.newJsonParser();
String message = new String(result);
try (BufferedReader reader = new BufferedReader(new StringReader(message))) {
String line = null;
while ((line = reader.readLine()) != null) {
IBaseResource resource = parser.parseResource(line);
IIdType id = resource.getIdElement();
String resourceType = id.getResourceType();
if (resourceType.equals(ResourceTypes.LOCATION.toCode())) {
Location location = (Location) resource;
this.processor.process(location);
} else if (resourceType.equals(ResourceTypes.ORGANIZATION.toCode())) {
Organization organization = (Organization) resource;
this.processor.process(organization);
}
}
} catch (IOException e) {
throw new ProgrammingErrorException(e);
}
}
}
}
use of org.hl7.fhir.r4.model.codesystems.ResourceTypes.ORGANIZATION in project geoprism-registry by terraframe.
the class FhirResourceImporter method process.
private void process(Bundle bundle) {
FhirPathR4 path = new FhirPathR4(FhirContext.forR4());
List<Location> locations = path.evaluate(bundle, "Bundle.entry.resource.ofType(Location)", Location.class);
for (Location location : locations) {
try {
handleLocation(location);
if (this.history != null) {
this.history.appLock();
this.history.setWorkProgress(count++);
this.history.setExportedRecords(exportCount++);
this.history.apply();
}
} catch (Exception e) {
if (this.history != null) {
this.recordExportError(e, this.history, location);
this.history.appLock();
this.history.setWorkProgress(count++);
this.history.apply();
} else {
throw new ProgrammingErrorException(e);
}
}
}
List<Organization> organizations = path.evaluate(bundle, "Bundle.entry.resource.ofType(Organization)", Organization.class);
for (Organization organization : organizations) {
try {
handleOrganization(organization);
if (this.history != null) {
this.history.appLock();
this.history.setWorkProgress(count++);
this.history.setExportedRecords(exportCount++);
this.history.apply();
}
} catch (Exception e) {
if (this.history != null) {
this.recordExportError(e, this.history, organization);
this.history.appLock();
this.history.setWorkProgress(count++);
this.history.apply();
} else {
throw new ProgrammingErrorException(e);
}
}
}
}
Aggregations