use of org.hl7.fhir.r4.model.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();
}
use of org.hl7.fhir.r4.model.ResourceType in project org.hl7.fhir.core by hapifhir.
the class JsonParser method parse.
public Element parse(JsonObject object) throws FHIRException {
JsonElement rt = object.get("resourceType");
if (rt == null) {
logError(line(object), col(object), "$", IssueType.INVALID, context.formatMessage(I18nConstants.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, this.profileUtilities));
checkObject(object, path);
result.markLocation(line(object), col(object));
result.setType(name);
result.setPath(result.fhirType());
parseChildren(path, object, result, true);
result.numberChildren();
return result;
}
}
use of org.hl7.fhir.r4.model.ResourceType in project org.hl7.fhir.core by hapifhir.
the class NpmPackageIndexBuilder method seeFile.
public boolean seeFile(String name, byte[] content) {
if (name.endsWith(".json")) {
try {
JsonObject json = JsonTrackingParser.parseJson(content);
if (json.has("resourceType")) {
// ok we treat it as a resource
JsonObject fi = new JsonObject();
files.add(fi);
fi.addProperty("filename", name);
fi.addProperty("resourceType", json.get("resourceType").getAsString());
if (json.has("id") && json.get("id").isJsonPrimitive()) {
fi.addProperty("id", json.get("id").getAsString());
}
if (json.has("url") && json.get("url").isJsonPrimitive()) {
fi.addProperty("url", json.get("url").getAsString());
}
if (json.has("version") && json.get("version").isJsonPrimitive()) {
fi.addProperty("version", json.get("version").getAsString());
}
if (json.has("kind") && json.get("kind").isJsonPrimitive()) {
fi.addProperty("kind", json.get("kind").getAsString());
}
if (json.has("type") && json.get("type").isJsonPrimitive()) {
fi.addProperty("type", json.get("type").getAsString());
}
if (json.has("supplements") && json.get("supplements").isJsonPrimitive()) {
fi.addProperty("supplements", json.get("supplements").getAsString());
}
}
} catch (Exception e) {
System.out.println("Error parsing " + name + ": " + e.getMessage());
if (name.contains("openapi")) {
return false;
}
}
}
return true;
}
use of org.hl7.fhir.r4.model.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();
}
use of org.hl7.fhir.r4.model.ResourceType in project org.hl7.fhir.core by hapifhir.
the class JsonParser method composeList.
private void composeList(String path, List<Element> list) throws IOException {
// there will be at least one element
String name = list.get(0).getName();
boolean complex = true;
if (list.get(0).isPrimitive()) {
boolean prim = false;
complex = false;
for (Element item : list) {
if (item.hasValue())
prim = true;
if (item.hasChildren())
complex = true;
}
if (prim) {
openArray(name, linkResolver == null ? null : linkResolver.resolveProperty(list.get(0).getProperty()));
for (Element item : list) {
if (item.hasValue())
primitiveValue(null, item);
else
json.nullValue();
}
closeArray();
}
name = "_" + name;
}
if (complex) {
openArray(name, linkResolver == null ? null : linkResolver.resolveProperty(list.get(0).getProperty()));
for (Element item : list) {
if (item.hasChildren()) {
open(null, null);
if (item.getProperty().isResource()) {
prop("resourceType", item.getType(), linkResolver == null ? null : linkResolver.resolveType(item.getType()));
}
Set<String> done = new HashSet<String>();
for (Element child : item.getChildren()) {
compose(path + "." + name + "[]", item, done, child);
}
close();
} else
json.nullValue();
}
closeArray();
}
}
Aggregations