Search in sources :

Example 6 with CanonicalResource

use of org.hl7.fhir.r4b.model.CanonicalResource in project kindling by HL7.

the class Regenerator method generateSearchParameter.

private CanonicalResource generateSearchParameter(String root, ResourceDefn r, Profile p, SearchParameter sp) throws IOException {
    File fn = new File(Utilities.path(root, sp.fhirType().toLowerCase() + "-profile-" + sp.getId() + ".gen.xml"));
    new XmlParser().setOutputStyle(OutputStyle.PRETTY).compose(new FileOutputStream(fn), sp);
    fn.setLastModified(r.getTimestamp());
    return sp;
}
Also used : XmlParser(org.hl7.fhir.r5.formats.XmlParser) FileOutputStream(java.io.FileOutputStream) File(java.io.File)

Example 7 with CanonicalResource

use of org.hl7.fhir.r4b.model.CanonicalResource in project org.hl7.fhir.core by hapifhir.

the class R5ToR5Loader method loadBundle.

@Override
public Bundle loadBundle(InputStream stream, boolean isJson) throws FHIRException, IOException {
    Resource r5 = null;
    if (isJson)
        r5 = new JsonParser().parse(stream);
    else
        r5 = new XmlParser().parse(stream);
    Bundle b;
    if (r5 instanceof Bundle)
        b = (Bundle) r5;
    else {
        b = new Bundle();
        b.setId(UUID.randomUUID().toString().toLowerCase());
        b.setType(BundleType.COLLECTION);
        b.addEntry().setResource(r5).setFullUrl(r5 instanceof CanonicalResource ? ((CanonicalResource) r5).getUrl() : null);
    }
    for (CodeSystem cs : cslist) {
        BundleEntryComponent be = b.addEntry();
        be.setFullUrl(cs.getUrl());
        be.setResource(cs);
    }
    if (killPrimitives) {
        List<BundleEntryComponent> remove = new ArrayList<BundleEntryComponent>();
        for (BundleEntryComponent be : b.getEntry()) {
            if (be.hasResource() && be.getResource() instanceof StructureDefinition) {
                StructureDefinition sd = (StructureDefinition) be.getResource();
                if (sd.getKind() == StructureDefinitionKind.PRIMITIVETYPE)
                    remove.add(be);
            }
        }
        b.getEntry().removeAll(remove);
    }
    if (patchUrls) {
        for (BundleEntryComponent be : b.getEntry()) {
            if (be.hasResource() && be.getResource() instanceof StructureDefinition) {
                StructureDefinition sd = (StructureDefinition) be.getResource();
                sd.setUrl(sd.getUrl().replace(URL_BASE, URL_R4));
                sd.addExtension().setUrl(URL_ELEMENT_DEF_NAMESPACE).setValue(new UriType(URL_BASE));
                for (ElementDefinition ed : sd.getSnapshot().getElement()) patchUrl(ed);
                for (ElementDefinition ed : sd.getDifferential().getElement()) patchUrl(ed);
            }
        }
    }
    return b;
}
Also used : XmlParser(org.hl7.fhir.r5.formats.XmlParser) BundleEntryComponent(org.hl7.fhir.r5.model.Bundle.BundleEntryComponent) ArrayList(java.util.ArrayList) JsonParser(org.hl7.fhir.r5.formats.JsonParser)

Example 8 with CanonicalResource

use of org.hl7.fhir.r4b.model.CanonicalResource in project org.hl7.fhir.core by hapifhir.

the class TerminologyClientR5 method read.

@Override
public CanonicalResource read(String type, String id) {
    Class<Resource> t;
    try {
        // todo: do we have to deal with any resource renaming? Use cases are limited...
        t = (Class<Resource>) Class.forName("org.hl7.fhir.r5.model." + type);
    } catch (ClassNotFoundException e) {
        throw new FHIRException("Unable to fetch resources of type " + type + " in R5");
    }
    org.hl7.fhir.r5.model.Resource r5 = client.read(t, id);
    if (r5 != null) {
        throw new FHIRException("Unable to convert resource " + Utilities.pathURL(getAddress(), type, id) + " to R5 (internal representation)");
    }
    if (!(r5 instanceof CanonicalResource)) {
        throw new FHIRException("Unable to convert resource " + Utilities.pathURL(getAddress(), type, id) + " to R5 canonical resource (internal representation)");
    }
    return (CanonicalResource) r5;
}
Also used : org.hl7.fhir.r5.model(org.hl7.fhir.r5.model) FHIRException(org.hl7.fhir.exceptions.FHIRException)

Example 9 with CanonicalResource

use of org.hl7.fhir.r4b.model.CanonicalResource in project org.hl7.fhir.core by hapifhir.

the class TerminologyClientR2 method read.

@Override
public CanonicalResource read(String type, String id) {
    Class<Resource> t;
    try {
        // todo: do we have to deal with any resource renaming? Use cases are limited...
        t = (Class<Resource>) Class.forName("org.hl7.fhir.dstu2.model." + type);
    } catch (ClassNotFoundException e) {
        throw new FHIRException("Unable to fetch resources of type " + type + " in R2");
    }
    org.hl7.fhir.dstu2.model.Resource r2 = client.read(t, id);
    if (r2 == null) {
        throw new FHIRException("Unable to fetch resource " + Utilities.pathURL(getAddress(), type, id));
    }
    org.hl7.fhir.r5.model.Resource r5 = VersionConvertorFactory_10_50.convertResource(r2);
    if (r5 != null) {
        throw new FHIRException("Unable to convert resource " + Utilities.pathURL(getAddress(), type, id) + " to R5 (internal representation)");
    }
    if (!(r5 instanceof CanonicalResource)) {
        throw new FHIRException("Unable to convert resource " + Utilities.pathURL(getAddress(), type, id) + " to R5 canonical resource (internal representation)");
    }
    return (CanonicalResource) r5;
}
Also used : Resource(org.hl7.fhir.dstu2.model.Resource) Resource(org.hl7.fhir.dstu2.model.Resource) org.hl7.fhir.r5.model(org.hl7.fhir.r5.model) FHIRException(org.hl7.fhir.exceptions.FHIRException)

Example 10 with CanonicalResource

use of org.hl7.fhir.r4b.model.CanonicalResource in project org.hl7.fhir.core by hapifhir.

the class R2ToR5Loader method loadBundle.

@Override
public Bundle loadBundle(InputStream stream, boolean isJson) throws FHIRException, IOException {
    Resource r2 = null;
    if (isJson)
        r2 = new JsonParser().parse(stream);
    else
        r2 = new XmlParser().parse(stream);
    org.hl7.fhir.r5.model.Resource r5 = VersionConvertorFactory_10_50.convertResource(r2, advisor);
    Bundle b;
    if (r5 instanceof Bundle) {
        b = (Bundle) r5;
    } else {
        b = new Bundle();
        b.setId(UUID.randomUUID().toString().toLowerCase());
        b.setType(BundleType.COLLECTION);
        b.addEntry().setResource(r5).setFullUrl(r5 instanceof CanonicalResource ? ((CanonicalResource) r5).getUrl() : null);
    }
    // Add any code systems defined as part of processing value sets to the end of the converted Bundle
    for (CodeSystem cs : advisor.getCslist()) {
        BundleEntryComponent be = b.addEntry();
        be.setFullUrl(cs.getUrl());
        be.setResource(cs);
    }
    advisor.getCslist().clear();
    if (killPrimitives) {
        List<BundleEntryComponent> remove = new ArrayList<BundleEntryComponent>();
        for (BundleEntryComponent be : b.getEntry()) {
            if (be.hasResource() && be.getResource() instanceof StructureDefinition) {
                StructureDefinition sd = (StructureDefinition) be.getResource();
                if (sd.getKind() == StructureDefinitionKind.PRIMITIVETYPE)
                    remove.add(be);
            }
        }
        b.getEntry().removeAll(remove);
    }
    if (patchUrls) {
        for (BundleEntryComponent be : b.getEntry()) {
            if (be.hasResource() && be.getResource() instanceof StructureDefinition) {
                StructureDefinition sd = (StructureDefinition) be.getResource();
                sd.setUrl(sd.getUrl().replace(URL_BASE, URL_DSTU2));
                sd.addExtension().setUrl(URL_ELEMENT_DEF_NAMESPACE).setValue(new UriType(URL_BASE));
            }
        }
    }
    return b;
}
Also used : XmlParser(org.hl7.fhir.dstu2.formats.XmlParser) Resource(org.hl7.fhir.dstu2.model.Resource) ArrayList(java.util.ArrayList) BundleEntryComponent(org.hl7.fhir.r5.model.Bundle.BundleEntryComponent) org.hl7.fhir.r5.model(org.hl7.fhir.r5.model) JsonParser(org.hl7.fhir.dstu2.formats.JsonParser)

Aggregations

FHIRException (org.hl7.fhir.exceptions.FHIRException)20 CanonicalResource (org.hl7.fhir.r5.model.CanonicalResource)19 ArrayList (java.util.ArrayList)17 File (java.io.File)11 CanonicalResource (org.hl7.fhir.r4b.model.CanonicalResource)10 StructureDefinition (org.hl7.fhir.r5.model.StructureDefinition)10 XmlParser (org.hl7.fhir.r5.formats.XmlParser)9 org.hl7.fhir.r5.model (org.hl7.fhir.r5.model)9 BundleEntryComponent (org.hl7.fhir.r5.model.Bundle.BundleEntryComponent)9 FileOutputStream (java.io.FileOutputStream)8 IOException (java.io.IOException)8 DefinitionException (org.hl7.fhir.exceptions.DefinitionException)8 CodeSystem (org.hl7.fhir.r5.model.CodeSystem)8 Resource (org.hl7.fhir.r5.model.Resource)8 ValueSet (org.hl7.fhir.r5.model.ValueSet)8 FileNotFoundException (java.io.FileNotFoundException)7 Resource (org.hl7.fhir.r4b.model.Resource)7 CodeSystem (org.hl7.fhir.r4b.model.CodeSystem)5 SearchParameter (org.hl7.fhir.r5.model.SearchParameter)5 FileInputStream (java.io.FileInputStream)4