Search in sources :

Example 41 with DomainResource

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

the class R3TEchnicalCorrectionProcessor method extractToPackageMaster.

private void extractToPackageMaster(List<Resource> list, String root) throws IOException, FHIRFormatError {
    System.out.println("Updating Packages Master");
    String corePath = Utilities.path(root, "hl7.fhir.r3.core", "package");
    String examplesPath = Utilities.path(root, "hl7.fhir.r3.examples", "package");
    String elementsPath = Utilities.path(root, "hl7.fhir.r3.elements", "package");
    int coreTotal = new File(corePath).list().length - 1;
    int examplesTotal = new File(examplesPath).list().length - 1;
    int elementsTotal = new File(elementsPath).list().length - 1;
    int coreCount = 0;
    int examplesCount = 0;
    int elementsCount = 0;
    for (Resource r : list) {
        String n = r.fhirType() + "-" + r.getId() + ".json";
        FileOutputStream dst = null;
        if (n.startsWith("DataElement-")) {
            elementsCount++;
            dst = new FileOutputStream(Utilities.path(elementsPath, n));
            new JsonParser().setOutputStyle(OutputStyle.NORMAL).compose(dst, r);
        } else {
            dst = new FileOutputStream(Utilities.path(examplesPath, n));
            new JsonParser().setOutputStyle(OutputStyle.NORMAL).compose(dst, r);
            examplesCount++;
            if (isCoreResource(r.fhirType())) {
                coreCount++;
                DomainResource dr = (DomainResource) r;
                dr.setText(null);
                new JsonParser().setOutputStyle(OutputStyle.NORMAL).compose(new FileOutputStream(Utilities.path(corePath, n)), r);
            }
        }
    }
    System.out.println("  Core @ " + corePath + ": Replaced " + coreCount + " of " + coreTotal);
    System.out.println("  Examples @ " + examplesPath + ": Replaced " + examplesCount + " of " + examplesTotal);
    System.out.println("  Elements @ " + elementsPath + ": Replaced " + elementsCount + " of " + elementsTotal);
}
Also used : DomainResource(org.hl7.fhir.dstu3.model.DomainResource) FileOutputStream(java.io.FileOutputStream) Resource(org.hl7.fhir.dstu3.model.Resource) DomainResource(org.hl7.fhir.dstu3.model.DomainResource) File(java.io.File) JsonParser(org.hl7.fhir.dstu3.formats.JsonParser)

Example 42 with DomainResource

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

the class GraphQLEngineTests method lookup.

@Override
public ReferenceResolution lookup(Object appInfo, IBaseResource context, IBaseReference reference) throws FHIRException {
    try {
        if (reference.getReferenceElement().isLocal()) {
            if (!(context instanceof DomainResource))
                return null;
            for (Resource r : ((DomainResource) context).getContained()) {
                if (('#' + r.getId()).equals(reference.getReferenceElement().getValue())) {
                    return new ReferenceResolution(context, r);
                }
            }
        } else {
            String[] parts = reference.getReferenceElement().getValue().split("/");
            String filename = TestingUtilities.resourceNameToFile(parts[0].toLowerCase() + '-' + parts[1].toLowerCase() + ".xml");
            if (new File(filename).exists())
                return new ReferenceResolution(null, new XmlParser().parse(new FileInputStream(filename)));
        }
        return null;
    } catch (Exception e) {
        throw new FHIRException(e);
    }
}
Also used : XmlParser(org.hl7.fhir.r4.formats.XmlParser) DomainResource(org.hl7.fhir.r4.model.DomainResource) IBaseResource(org.hl7.fhir.instance.model.api.IBaseResource) Resource(org.hl7.fhir.r4.model.Resource) DomainResource(org.hl7.fhir.r4.model.DomainResource) File(java.io.File) TextFile(org.hl7.fhir.utilities.TextFile) FHIRException(org.hl7.fhir.exceptions.FHIRException) FileInputStream(java.io.FileInputStream) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) SAXException(org.xml.sax.SAXException) FHIRException(org.hl7.fhir.exceptions.FHIRException)

Example 43 with DomainResource

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

the class NarrativeGeneratorTests method process.

private void process(String path) throws FileNotFoundException, IOException, XmlPullParserException, EOperationOutcome, FHIRException {
    XmlParser p = new XmlParser();
    DomainResource r = (DomainResource) p.parse(new FileInputStream(path));
    gen.generate(r, null);
    FileOutputStream s = new FileOutputStream(TestingUtilities.resourceNameToFile("gen", "gen.xml"));
    new XmlParser().compose(s, r, true);
    s.close();
}
Also used : XmlParser(org.hl7.fhir.r4.formats.XmlParser) DomainResource(org.hl7.fhir.r4.model.DomainResource) FileOutputStream(java.io.FileOutputStream) FileInputStream(java.io.FileInputStream)

Example 44 with DomainResource

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

the class XmlParserBase method parseDomainResourceContained.

protected DomainResource parseDomainResourceContained(XmlPullParser xpp) throws IOException, FHIRFormatError, XmlPullParserException {
    next(xpp);
    int eventType = nextNoWhitespace(xpp);
    if (eventType == XmlPullParser.START_TAG) {
        DomainResource dr = (DomainResource) parseResource(xpp);
        nextNoWhitespace(xpp);
        next(xpp);
        return dr;
    } else {
        unknownContent(xpp);
        return null;
    }
}
Also used : DomainResource(org.hl7.fhir.r4b.model.DomainResource)

Example 45 with DomainResource

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

the class DomainResource method copyValues.

public void copyValues(DomainResource dst) {
    super.copyValues(dst);
    dst.text = text == null ? null : text.copy();
    if (contained != null) {
        dst.contained = new ArrayList<Resource>();
        for (Resource i : contained) dst.contained.add(i.copy());
    }
    ;
    if (extension != null) {
        dst.extension = new ArrayList<Extension>();
        for (Extension i : extension) dst.extension.add(i.copy());
    }
    ;
    if (modifierExtension != null) {
        dst.modifierExtension = new ArrayList<Extension>();
        for (Extension i : modifierExtension) dst.modifierExtension.add(i.copy());
    }
    ;
}
Also used : IDomainResource(org.hl7.fhir.instance.model.api.IDomainResource)

Aggregations

XhtmlNode (org.hl7.fhir.utilities.xhtml.XhtmlNode)24 FHIRException (org.hl7.fhir.exceptions.FHIRException)22 DomainResource (org.hl7.fhir.r4.model.DomainResource)21 DefinitionException (org.hl7.fhir.exceptions.DefinitionException)16 IOException (java.io.IOException)15 DomainResource (org.hl7.fhir.dstu3.model.DomainResource)15 FileOutputStream (java.io.FileOutputStream)12 ArrayList (java.util.ArrayList)11 CommaSeparatedStringBuilder (org.hl7.fhir.utilities.CommaSeparatedStringBuilder)11 Test (org.junit.jupiter.api.Test)11 Resource (org.hl7.fhir.r4.model.Resource)10 IBaseResource (org.hl7.fhir.instance.model.api.IBaseResource)9 FileNotFoundException (java.io.FileNotFoundException)8 List (java.util.List)8 NotImplementedException (org.apache.commons.lang3.NotImplementedException)8 StructureDefinition (org.hl7.fhir.r5.model.StructureDefinition)8 SystemRequestDetails (ca.uhn.fhir.jpa.partition.SystemRequestDetails)7 File (java.io.File)7 ElementDefn (org.hl7.fhir.definitions.model.ElementDefn)7 RestIntegrationTest (org.opencds.cqf.ruler.test.RestIntegrationTest)7