Search in sources :

Example 71 with ORGANIZATION

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));
}
Also used : NUMStructureDefinition(de.difuture.uds.odm2fhir.fhir.util.NUMStructureDefinition) Getter(lombok.Getter) Consent(org.hl7.fhir.r4.model.Consent) Identifier(org.hl7.fhir.r4.model.Identifier) CodeableConcept(org.hl7.fhir.r4.model.CodeableConcept) Reference(org.hl7.fhir.r4.model.Reference) ENVIRONMENT(de.difuture.uds.odm2fhir.util.EnvironmentProvider.ENVIRONMENT) ReflectionUtils.invokeMethod(org.springframework.util.ReflectionUtils.invokeMethod) IdentifierHelper.getIdentifierAssigner(de.difuture.uds.odm2fhir.fhir.util.IdentifierHelper.getIdentifierAssigner) ORGANIZATION(org.hl7.fhir.r4.model.codesystems.ResourceTypes.ORGANIZATION) PATIENT(org.hl7.fhir.r4.model.codesystems.ResourceTypes.PATIENT) Meta(org.hl7.fhir.r4.model.Meta) Patient(org.hl7.fhir.r4.model.Patient) MR(org.hl7.fhir.r4.model.codesystems.V3Hl7PublishingDomain.MR) IdentifierHelper.getIdentifierSystem(de.difuture.uds.odm2fhir.fhir.util.IdentifierHelper.getIdentifierSystem) ReflectionUtils.findMethod(org.springframework.util.ReflectionUtils.findMethod) SubjectData(de.difuture.uds.odm2fhir.odm.model.SubjectData) DomainResource(org.hl7.fhir.r4.model.DomainResource) String.format(java.lang.String.format) Organization(org.hl7.fhir.r4.model.Organization) Immunization(org.hl7.fhir.r4.model.Immunization) Stream(java.util.stream.Stream) DigestUtils.sha256Hex(org.apache.commons.codec.digest.DigestUtils.sha256Hex) Coding(org.hl7.fhir.r4.model.Coding) StringUtils.equalsAny(org.apache.commons.lang3.StringUtils.equalsAny) IDENTIFIER_TYPE_CODES(de.difuture.uds.odm2fhir.fhir.util.CommonCodeSystem.IDENTIFIER_TYPE_CODES) Meta(org.hl7.fhir.r4.model.Meta) Identifier(org.hl7.fhir.r4.model.Identifier) Organization(org.hl7.fhir.r4.model.Organization) Coding(org.hl7.fhir.r4.model.Coding) Reference(org.hl7.fhir.r4.model.Reference) Patient(org.hl7.fhir.r4.model.Patient) CodeableConcept(org.hl7.fhir.r4.model.CodeableConcept)

Example 72 with ORGANIZATION

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;
}
Also used : Organization(org.hl7.fhir.r4.model.Organization) IGenericClient(ca.uhn.fhir.rest.client.api.IGenericClient) IBaseBundle(org.hl7.fhir.instance.model.api.IBaseBundle) IBaseResource(org.hl7.fhir.instance.model.api.IBaseResource) IIdType(org.hl7.fhir.instance.model.api.IIdType)

Example 73 with ORGANIZATION

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);
            }
        }
    }
}
Also used : Locale(java.util.Locale) Organization(org.hl7.fhir.r4.model.Organization) Location(org.hl7.fhir.r4.model.Location)

Example 74 with ORGANIZATION

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);
            }
        }
    }
}
Also used : CloseableHttpClient(org.apache.http.impl.client.CloseableHttpClient) FhirContext(ca.uhn.fhir.context.FhirContext) Organization(org.hl7.fhir.r4.model.Organization) IGenericClient(ca.uhn.fhir.rest.client.api.IGenericClient) HttpClientBuilder(org.apache.http.impl.client.HttpClientBuilder) IOException(java.io.IOException) ProgrammingErrorException(com.runwaysdk.dataaccess.ProgrammingErrorException) PoolingHttpClientConnectionManager(org.apache.http.impl.conn.PoolingHttpClientConnectionManager) BufferedReader(java.io.BufferedReader) StringReader(java.io.StringReader) Binary(org.hl7.fhir.r4.model.Binary) IBaseResource(org.hl7.fhir.instance.model.api.IBaseResource) IParser(ca.uhn.fhir.parser.IParser) IIdType(org.hl7.fhir.instance.model.api.IIdType) Location(org.hl7.fhir.r4.model.Location)

Example 75 with ORGANIZATION

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);
            }
        }
    }
}
Also used : Organization(org.hl7.fhir.r4.model.Organization) FhirPathR4(org.hl7.fhir.r4.hapi.fluentpath.FhirPathR4) ProgrammingErrorException(com.runwaysdk.dataaccess.ProgrammingErrorException) ProgrammingErrorException(com.runwaysdk.dataaccess.ProgrammingErrorException) Location(org.hl7.fhir.r4.model.Location)

Aggregations

Test (org.junit.jupiter.api.Test)101 Organization (org.hl7.fhir.dstu3.model.Organization)90 Organization (org.hl7.fhir.r4.model.Organization)69 BundleEntryComponent (org.hl7.fhir.r4.model.Bundle.BundleEntryComponent)41 Resource (org.hl7.fhir.r4.model.Resource)38 ArrayList (java.util.ArrayList)34 List (java.util.List)33 Reference (org.hl7.fhir.r4.model.Reference)33 Identifier (org.hl7.fhir.r4.model.Identifier)30 Bundle (org.hl7.fhir.dstu3.model.Bundle)27 UUID (java.util.UUID)26 IGenericClient (ca.uhn.fhir.rest.client.api.IGenericClient)25 Patient (org.hl7.fhir.r4.model.Patient)25 IdType (org.hl7.fhir.dstu3.model.IdType)24 Bundle (org.hl7.fhir.r4.model.Bundle)24 Coding (org.hl7.fhir.r4.model.Coding)24 CodeableConcept (org.hl7.fhir.r4.model.CodeableConcept)19 ContactPoint (org.hl7.fhir.r4.model.ContactPoint)17 Reference (org.hl7.fhir.dstu3.model.Reference)16 IBaseResource (org.hl7.fhir.instance.model.api.IBaseResource)16