Search in sources :

Example 6 with FHIRVersion

use of org.hl7.fhir.r5.model.Enumerations.FHIRVersion in project ab2d by CMSgov.

the class FhirUtils method addMbiIdsToEobs.

public static void addMbiIdsToEobs(IBaseResource eob, CoverageSummary patient, FhirVersion version) {
    if (eob == null) {
        return;
    }
    // Add extesions only if beneficiary id is present and known to memberships
    Long benId = EobUtils.getPatientId(eob);
    if (benId != null && patient != null) {
        Identifiers identifiers = patient.getIdentifiers();
        // Add each mbi to each eob
        if (identifiers.getCurrentMbi() != null) {
            IBase currentMbiExtension = ExtensionUtils.createMbiExtension(identifiers.getCurrentMbi(), true, version);
            ExtensionUtils.addExtension(eob, currentMbiExtension, version);
        }
        for (String mbi : identifiers.getHistoricMbis()) {
            IBase mbiExtension = ExtensionUtils.createMbiExtension(mbi, false, version);
            ExtensionUtils.addExtension(eob, mbiExtension, version);
        }
    }
}
Also used : Identifiers(gov.cms.ab2d.coverage.model.Identifiers) IBase(org.hl7.fhir.instance.model.api.IBase)

Example 7 with FHIRVersion

use of org.hl7.fhir.r5.model.Enumerations.FHIRVersion in project ab2d by CMSgov.

the class PatientClaimsProcessorImpl method writeOutResource.

@Trace(metricName = "EOBWriteToFile", dispatcher = true)
private String writeOutResource(FhirVersion version, ProgressTrackerUpdate update, List<IBaseResource> eobs, ClaimsStream stream) {
    IParser parser = version.getJsonParser().setPrettyPrint(false);
    if (eobs == null) {
        log.debug("ignoring empty results because pulling eobs failed");
        return null;
    }
    if (eobs.isEmpty()) {
        return null;
    }
    int eobsWritten = 0;
    int eobsError = 0;
    update.incPatientsWithEobsCount();
    update.addEobFetchedCount(eobs.size());
    StringBuilder errorPayload = new StringBuilder();
    for (IBaseResource resource : eobs) {
        try {
            stream.write(parser.encodeResourceToString(resource) + System.lineSeparator());
            eobsWritten++;
        } catch (Exception ex) {
            log.warn("Encountered exception while processing job resources: {}", ex.getClass());
            String errMsg = ExceptionUtils.getRootCauseMessage(ex);
            IBaseResource operationOutcome = version.getErrorOutcome(errMsg);
            errorPayload.append(parser.encodeResourceToString(operationOutcome)).append(System.lineSeparator());
            eobsError++;
        }
    }
    update.addEobProcessedCount(eobsWritten);
    if (eobsError != 0) {
        return errorPayload.toString();
    }
    return errorPayload.toString();
}
Also used : IBaseResource(org.hl7.fhir.instance.model.api.IBaseResource) ParseException(java.text.ParseException) IOException(java.io.IOException) IParser(ca.uhn.fhir.parser.IParser) Trace(com.newrelic.api.agent.Trace)

Example 8 with FHIRVersion

use of org.hl7.fhir.r5.model.Enumerations.FHIRVersion in project org.hl7.fhir.core by hapifhir.

the class ExtensionDefinitionGenerator method loadSource.

private List<StructureDefinition> loadSource() throws IOException, FHIRException {
    List<StructureDefinition> list = new ArrayList<>();
    FilesystemPackageCacheManager pcm = new FilesystemPackageCacheManager(true, ToolsVersion.TOOLS_VERSION);
    NpmPackage npm = pcm.loadPackage("hl7.fhir.core", sourceVersion.toCode());
    if (sourceVersion == FHIRVersion._4_0_0)
        context = SimpleWorkerContext.fromPackage(npm);
    else if (sourceVersion == FHIRVersion._3_0_1)
        context = SimpleWorkerContext.fromPackage(npm, new R3ToR4Loader());
    else if (sourceVersion == FHIRVersion._1_4_0)
        context = SimpleWorkerContext.fromPackage(npm, new R2016MayToR4Loader());
    else if (sourceVersion == FHIRVersion._1_0_2)
        context = SimpleWorkerContext.fromPackage(npm, new R2ToR4Loader());
    pu = new ProfileUtilities(context, null, null);
    for (String fn : npm.listResources("StructureDefinition")) {
        list.add((StructureDefinition) loadResource(npm.load("package", fn), sourceVersion));
    }
    for (StructureDefinition sd : list) if (sd.getName().equals("Extension")) {
        extbase = sd;
        extv = extbase.getSnapshot().getElement().get(extbase.getSnapshot().getElement().size() - 1);
    }
    return list;
}
Also used : FilesystemPackageCacheManager(org.hl7.fhir.utilities.npm.FilesystemPackageCacheManager) StructureDefinition(org.hl7.fhir.r4.model.StructureDefinition) NpmPackage(org.hl7.fhir.utilities.npm.NpmPackage) R2ToR4Loader(org.hl7.fhir.convertors.loaders.loaderR4.R2ToR4Loader) ProfileUtilities(org.hl7.fhir.r4.conformance.ProfileUtilities) R3ToR4Loader(org.hl7.fhir.convertors.loaders.loaderR4.R3ToR4Loader) R2016MayToR4Loader(org.hl7.fhir.convertors.loaders.loaderR4.R2016MayToR4Loader)

Example 9 with FHIRVersion

use of org.hl7.fhir.r5.model.Enumerations.FHIRVersion in project org.hl7.fhir.core by hapifhir.

the class ExtensionDefinitionGenerator method loadResource.

private Resource loadResource(InputStream inputStream, FHIRVersion v) throws IOException, FHIRException {
    if (v == FHIRVersion._3_0_1) {
        org.hl7.fhir.dstu3.model.Resource res = new org.hl7.fhir.dstu3.formats.JsonParser().parse(inputStream);
        return VersionConvertorFactory_30_40.convertResource(res, new BaseAdvisor_30_40(false));
    } else if (v == FHIRVersion._1_4_0) {
        org.hl7.fhir.dstu2016may.model.Resource res = new org.hl7.fhir.dstu2016may.formats.JsonParser().parse(inputStream);
        return VersionConvertorFactory_14_40.convertResource(res);
    } else if (v == FHIRVersion._1_0_2) {
        org.hl7.fhir.dstu2.model.Resource res = new org.hl7.fhir.dstu2.formats.JsonParser().parse(inputStream);
        BaseAdvisor_10_40 advisor = new IGR2ConvertorAdvisor();
        return VersionConvertorFactory_10_40.convertResource(res, advisor);
    } else if (v == FHIRVersion._4_0_0) {
        return new JsonParser().parse(inputStream);
    } else
        throw new Error("Unsupported version " + v);
}
Also used : Resource(org.hl7.fhir.r4.model.Resource) IGR2ConvertorAdvisor(org.hl7.fhir.convertors.misc.IGR2ConvertorAdvisor) BaseAdvisor_10_40(org.hl7.fhir.convertors.advisors.impl.BaseAdvisor_10_40) BaseAdvisor_30_40(org.hl7.fhir.convertors.advisors.impl.BaseAdvisor_30_40) JsonParser(org.hl7.fhir.r4.formats.JsonParser)

Example 10 with FHIRVersion

use of org.hl7.fhir.r5.model.Enumerations.FHIRVersion in project org.hl7.fhir.core by hapifhir.

the class RdfParser method composeCapabilityStatement.

protected void composeCapabilityStatement(Complex parent, String parentType, String name, CapabilityStatement element, int index) {
    if (element == null)
        return;
    Complex t;
    if (Utilities.noString(parentType))
        t = parent;
    else {
        t = parent.predicate("fhir:" + parentType + '.' + name);
    }
    composeDomainResource(t, "CapabilityStatement", name, element, index);
    if (element.hasUrlElement())
        composeUri(t, "CapabilityStatement", "url", element.getUrlElement(), -1);
    if (element.hasVersionElement())
        composeString(t, "CapabilityStatement", "version", element.getVersionElement(), -1);
    if (element.hasNameElement())
        composeString(t, "CapabilityStatement", "name", element.getNameElement(), -1);
    if (element.hasTitleElement())
        composeString(t, "CapabilityStatement", "title", element.getTitleElement(), -1);
    if (element.hasStatusElement())
        composeEnum(t, "CapabilityStatement", "status", element.getStatusElement(), -1);
    if (element.hasExperimentalElement())
        composeBoolean(t, "CapabilityStatement", "experimental", element.getExperimentalElement(), -1);
    if (element.hasDateElement())
        composeDateTime(t, "CapabilityStatement", "date", element.getDateElement(), -1);
    if (element.hasPublisherElement())
        composeString(t, "CapabilityStatement", "publisher", element.getPublisherElement(), -1);
    for (int i = 0; i < element.getContact().size(); i++) composeContactDetail(t, "CapabilityStatement", "contact", element.getContact().get(i), i);
    if (element.hasDescriptionElement())
        composeMarkdown(t, "CapabilityStatement", "description", element.getDescriptionElement(), -1);
    for (int i = 0; i < element.getUseContext().size(); i++) composeUsageContext(t, "CapabilityStatement", "useContext", element.getUseContext().get(i), i);
    for (int i = 0; i < element.getJurisdiction().size(); i++) composeCodeableConcept(t, "CapabilityStatement", "jurisdiction", element.getJurisdiction().get(i), i);
    if (element.hasPurposeElement())
        composeMarkdown(t, "CapabilityStatement", "purpose", element.getPurposeElement(), -1);
    if (element.hasCopyrightElement())
        composeMarkdown(t, "CapabilityStatement", "copyright", element.getCopyrightElement(), -1);
    if (element.hasKindElement())
        composeEnum(t, "CapabilityStatement", "kind", element.getKindElement(), -1);
    for (int i = 0; i < element.getInstantiates().size(); i++) composeUri(t, "CapabilityStatement", "instantiates", element.getInstantiates().get(i), i);
    if (element.hasSoftware())
        composeCapabilityStatementCapabilityStatementSoftwareComponent(t, "CapabilityStatement", "software", element.getSoftware(), -1);
    if (element.hasImplementation())
        composeCapabilityStatementCapabilityStatementImplementationComponent(t, "CapabilityStatement", "implementation", element.getImplementation(), -1);
    if (element.hasFhirVersionElement())
        composeId(t, "CapabilityStatement", "fhirVersion", element.getFhirVersionElement(), -1);
    if (element.hasAcceptUnknownElement())
        composeEnum(t, "CapabilityStatement", "acceptUnknown", element.getAcceptUnknownElement(), -1);
    for (int i = 0; i < element.getFormat().size(); i++) composeCode(t, "CapabilityStatement", "format", element.getFormat().get(i), i);
    for (int i = 0; i < element.getPatchFormat().size(); i++) composeCode(t, "CapabilityStatement", "patchFormat", element.getPatchFormat().get(i), i);
    for (int i = 0; i < element.getImplementationGuide().size(); i++) composeUri(t, "CapabilityStatement", "implementationGuide", element.getImplementationGuide().get(i), i);
    for (int i = 0; i < element.getProfile().size(); i++) composeReference(t, "CapabilityStatement", "profile", element.getProfile().get(i), i);
    for (int i = 0; i < element.getRest().size(); i++) composeCapabilityStatementCapabilityStatementRestComponent(t, "CapabilityStatement", "rest", element.getRest().get(i), i);
    for (int i = 0; i < element.getMessaging().size(); i++) composeCapabilityStatementCapabilityStatementMessagingComponent(t, "CapabilityStatement", "messaging", element.getMessaging().get(i), i);
    for (int i = 0; i < element.getDocument().size(); i++) composeCapabilityStatementCapabilityStatementDocumentComponent(t, "CapabilityStatement", "document", element.getDocument().get(i), i);
}
Also used : Complex(org.hl7.fhir.dstu3.utils.formats.Turtle.Complex)

Aggregations

ArrayList (java.util.ArrayList)10 IBaseResource (org.hl7.fhir.instance.model.api.IBaseResource)9 JsonObject (com.google.gson.JsonObject)8 Date (java.util.Date)8 IOException (java.io.IOException)7 FhirContext (ca.uhn.fhir.context.FhirContext)6 JsonArray (com.google.gson.JsonArray)6 HashMap (java.util.HashMap)5 FhirVersionEnum (ca.uhn.fhir.context.FhirVersionEnum)4 IParser (ca.uhn.fhir.parser.IParser)4 Complex (org.hl7.fhir.r4.utils.formats.Turtle.Complex)4 CommaSeparatedStringBuilder (org.hl7.fhir.utilities.CommaSeparatedStringBuilder)4 JsonPrimitive (com.google.gson.JsonPrimitive)3 UnsupportedEncodingException (java.io.UnsupportedEncodingException)3 Complex (org.hl7.fhir.dstu2016may.formats.RdfGenerator.Complex)3 DefinitionException (org.hl7.fhir.exceptions.DefinitionException)3 FHIRException (org.hl7.fhir.exceptions.FHIRException)3 Bundle (org.hl7.fhir.r4.model.Bundle)3 StructureDefinition (org.hl7.fhir.r5.model.StructureDefinition)3 CascadingDeleteInterceptor (ca.uhn.fhir.jpa.interceptor.CascadingDeleteInterceptor)2