Search in sources :

Example 21 with ResourceType

use of org.hl7.fhir.r4.model.Enumerations.ResourceType in project org.hl7.fhir.core by hapifhir.

the class JsonParser method compose.

public void compose(Element e, JsonCreator json) throws Exception {
    this.json = json;
    json.beginObject();
    prop("resourceType", e.getType(), linkResolver == null ? null : linkResolver.resolveProperty(e.getProperty()));
    Set<String> done = new HashSet<String>();
    for (Element child : e.getChildren()) {
        compose(e.getName(), e, done, child);
    }
    json.endObject();
    json.finish();
}
Also used : JsonElement(com.google.gson.JsonElement) SpecialElement(org.hl7.fhir.dstu3.elementmodel.Element.SpecialElement) HashSet(java.util.HashSet)

Example 22 with ResourceType

use of org.hl7.fhir.r4.model.Enumerations.ResourceType in project org.hl7.fhir.core by hapifhir.

the class JsonParser method compose.

@Override
public void compose(Element e, OutputStream stream, OutputStyle style, String identity) throws FHIRException, IOException {
    OutputStreamWriter osw = new OutputStreamWriter(stream, "UTF-8");
    if (style == OutputStyle.CANONICAL)
        json = new JsonCreatorCanonical(osw);
    else
        json = new JsonCreatorGson(osw);
    json.setIndent(style == OutputStyle.PRETTY ? "  " : "");
    json.beginObject();
    prop("resourceType", e.getType(), null);
    Set<String> done = new HashSet<String>();
    for (Element child : e.getChildren()) {
        compose(e.getName(), e, done, child);
    }
    json.endObject();
    json.finish();
    osw.flush();
}
Also used : JsonCreatorGson(org.hl7.fhir.dstu3.formats.JsonCreatorGson) JsonCreatorCanonical(org.hl7.fhir.dstu3.formats.JsonCreatorCanonical) JsonElement(com.google.gson.JsonElement) SpecialElement(org.hl7.fhir.dstu3.elementmodel.Element.SpecialElement) OutputStreamWriter(java.io.OutputStreamWriter) HashSet(java.util.HashSet)

Example 23 with ResourceType

use of org.hl7.fhir.r4.model.Enumerations.ResourceType in project org.hl7.fhir.core by hapifhir.

the class JsonParser method parseResource.

private void parseResource(String npath, JsonObject res, Element parent, Property elementProperty) throws DefinitionException, FHIRFormatError {
    JsonElement rt = res.get("resourceType");
    if (rt == null) {
        logError(line(res), col(res), npath, IssueType.INVALID, "Unable to find resourceType property", IssueSeverity.FATAL);
    } else {
        String name = rt.getAsString();
        StructureDefinition sd = context.fetchTypeDefinition(name);
        if (sd == null)
            throw new FHIRFormatError("Contained resource does not appear to be a FHIR resource (unknown name '" + name + "')");
        parent.updateProperty(new Property(context, sd.getSnapshot().getElement().get(0), sd), SpecialElement.fromProperty(parent.getProperty()), elementProperty);
        parent.setType(name);
        parseChildren(npath, res, parent, true);
    }
}
Also used : StructureDefinition(org.hl7.fhir.dstu3.model.StructureDefinition) JsonElement(com.google.gson.JsonElement) FHIRFormatError(org.hl7.fhir.exceptions.FHIRFormatError)

Example 24 with ResourceType

use of org.hl7.fhir.r4.model.Enumerations.ResourceType in project org.hl7.fhir.core by hapifhir.

the class JsonLDParser method compose.

@Override
public void compose(Element e, OutputStream stream, OutputStyle style, String base) throws Exception {
    this.base = base;
    OutputStreamWriter osw = new OutputStreamWriter(stream, "UTF-8");
    if (style == OutputStyle.CANONICAL)
        json = new JsonCreatorCanonical(osw);
    else
        json = new JsonCreatorGson(osw);
    json.setIndent(style == OutputStyle.PRETTY ? "  " : "");
    json.beginObject();
    prop("@context", "http://hl7.org/fhir/jsonld/" + e.getType());
    prop("resourceType", e.getType());
    Set<String> done = new HashSet<String>();
    for (Element child : e.getChildren()) {
        compose(e.getName(), e, done, child);
    }
    json.endObject();
    json.finish();
    osw.flush();
}
Also used : JsonCreatorGson(org.hl7.fhir.dstu2016may.formats.JsonCreatorGson) JsonCreatorCanonical(org.hl7.fhir.dstu2016may.formats.JsonCreatorCanonical) OutputStreamWriter(java.io.OutputStreamWriter) HashSet(java.util.HashSet)

Example 25 with ResourceType

use of org.hl7.fhir.r4.model.Enumerations.ResourceType in project org.hl7.fhir.core by hapifhir.

the class JsonParser method parse.

public Element parse(JsonObject object) throws Exception {
    JsonElement rt = object.get("resourceType");
    if (rt == null) {
        logError(line(object), col(object), "$", IssueType.INVALID, "Unable to find resourceType property", IssueSeverity.FATAL);
        return null;
    } else {
        String name = rt.getAsString();
        String path = "/" + name;
        StructureDefinition sd = getDefinition(line(object), col(object), name);
        if (sd == null)
            return null;
        Element result = new Element(name, new Property(context, sd.getSnapshot().getElement().get(0), sd));
        checkObject(object, path);
        result.markLocation(line(object), col(object));
        result.setType(name);
        parseChildren(path, object, result, true);
        result.numberChildren();
        return result;
    }
}
Also used : StructureDefinition(org.hl7.fhir.dstu2016may.model.StructureDefinition) JsonElement(com.google.gson.JsonElement) SpecialElement(org.hl7.fhir.dstu2016may.metamodel.Element.SpecialElement) JsonElement(com.google.gson.JsonElement)

Aggregations

JsonElement (com.google.gson.JsonElement)33 HashSet (java.util.HashSet)26 Bundle (org.hl7.fhir.r4.model.Bundle)24 ResourceType (org.hl7.fhir.r4.model.Enumerations.ResourceType)21 Test (org.junit.Test)20 Nonnull (javax.annotation.Nonnull)18 ArrayList (java.util.ArrayList)15 IBaseResource (org.hl7.fhir.instance.model.api.IBaseResource)10 FhirContext (ca.uhn.fhir.context.FhirContext)9 File (java.io.File)9 Row (org.apache.spark.sql.Row)9 IdType (org.hl7.fhir.dstu3.model.IdType)9 BundleEntryComponent (org.hl7.fhir.r4.model.Bundle.BundleEntryComponent)9 JsonObject (com.google.gson.JsonObject)8 Test (org.junit.jupiter.api.Test)8 MockHttpServletResponse (org.springframework.mock.web.MockHttpServletResponse)8 IOException (java.io.IOException)7 List (java.util.List)7 Bundle (org.hl7.fhir.dstu3.model.Bundle)7 Resource (org.hl7.fhir.r4.model.Resource)7