use of org.hl7.elm.r1.IndexOf in project org.hl7.fhir.core by hapifhir.
the class ProfileUtilities method getChildList.
public List<ElementDefinition> getChildList(StructureDefinition profile, String path, String id, boolean diff, boolean refs) {
List<ElementDefinition> res = new ArrayList<ElementDefinition>();
boolean capturing = id == null;
if (id == null && !path.contains("."))
capturing = true;
List<ElementDefinition> list = diff ? profile.getDifferential().getElement() : profile.getSnapshot().getElement();
for (ElementDefinition e : list) {
if (e == null)
throw new Error(context.formatMessage(I18nConstants.ELEMENT__NULL_, profile.getUrl()));
if (e.getId() == null)
throw new Error(context.formatMessage(I18nConstants.ELEMENT_ID__NULL__ON_, e.toString(), profile.getUrl()));
if (!capturing && id != null && e.getId().equals(id)) {
capturing = true;
}
// If our element is a slice, stop capturing children as soon as we see the next slice
if (capturing && e.hasId() && id != null && !e.getId().equals(id) && e.getPath().equals(path))
break;
if (capturing) {
String p = e.getPath();
if (refs && !Utilities.noString(e.getContentReference()) && path.startsWith(p)) {
if (path.length() > p.length()) {
return getChildList(profile, e.getContentReference() + "." + path.substring(p.length() + 1), null, diff);
} else if (e.getContentReference().startsWith("#")) {
return getChildList(profile, e.getContentReference().substring(1), null, diff);
} else if (e.getContentReference().contains("#")) {
String url = e.getContentReference().substring(0, e.getContentReference().indexOf("#"));
StructureDefinition sd = context.fetchResource(StructureDefinition.class, url);
if (sd == null) {
throw new DefinitionException("Unable to find Structure " + url);
}
return getChildList(sd, e.getContentReference().substring(e.getContentReference().indexOf("#") + 1), null, diff);
} else {
return getChildList(profile, e.getContentReference(), null, diff);
}
} else if (p.startsWith(path + ".") && !p.equals(path)) {
String tail = p.substring(path.length() + 1);
if (!tail.contains(".")) {
res.add(e);
}
}
}
}
return res;
}
use of org.hl7.elm.r1.IndexOf in project org.hl7.fhir.core by hapifhir.
the class ProfileUtilities method closeChildren.
private void closeChildren(StructureDefinition base, ElementDefinition edb, StructureDefinition derived, ElementDefinition edm) {
String path = edb.getPath() + ".";
int baseStart = base.getSnapshot().getElement().indexOf(edb);
int baseEnd = findEnd(base.getSnapshot().getElement(), edb, baseStart + 1);
int diffStart = derived.getDifferential().getElement().indexOf(edm);
int diffEnd = findEnd(derived.getDifferential().getElement(), edm, diffStart + 1);
for (int cBase = baseStart; cBase < baseEnd; cBase++) {
ElementDefinition edBase = base.getSnapshot().getElement().get(cBase);
if (isImmediateChild(edBase, edb)) {
ElementDefinition edMatch = getMatchInDerived(edBase, derived.getDifferential().getElement(), diffStart, diffEnd);
if (edMatch == null) {
ElementDefinition edd = derived.getDifferential().addElement();
edd.setPath(edBase.getPath());
edd.setMax("0");
} else {
closeChildren(base, edBase, derived, edMatch);
}
}
}
}
use of org.hl7.elm.r1.IndexOf in project org.hl7.fhir.core by hapifhir.
the class ProfileUtilities method extensionIsComplex.
private boolean extensionIsComplex(String value) {
if (value.contains("#")) {
StructureDefinition ext = context.fetchResource(StructureDefinition.class, value.substring(0, value.indexOf("#")));
if (ext == null)
return false;
String tail = value.substring(value.indexOf("#") + 1);
ElementDefinition ed = null;
for (ElementDefinition ted : ext.getSnapshot().getElement()) {
if (tail.equals(ted.getSliceName())) {
ed = ted;
break;
}
}
if (ed == null)
return false;
int i = ext.getSnapshot().getElement().indexOf(ed);
int j = i + 1;
while (j < ext.getSnapshot().getElement().size() && !ext.getSnapshot().getElement().get(j).getPath().equals(ed.getPath())) j++;
return j - i > 5;
} else {
StructureDefinition ext = context.fetchResource(StructureDefinition.class, value);
return ext != null && ext.getSnapshot().getElement().size() > 5;
}
}
use of org.hl7.elm.r1.IndexOf in project org.hl7.fhir.core by hapifhir.
the class R3TEchnicalCorrectionProcessor method execute.
private void execute(String src, String packageRoot) throws FileNotFoundException, IOException {
System.out.println("Loading resources from " + src);
List<Resource> resources = new ArrayList<>();
Map<String, Resource> definitions = new HashMap<>();
for (File f : new File(src).listFiles()) {
if (f.getName().endsWith(".xml") && !(f.getName().endsWith("warnings.xml") || f.getName().endsWith(".diff.xml"))) {
try {
Resource r = new XmlParser().parse(new FileInputStream(f));
if (f.getName().contains("canonical")) {
resources.add(r);
}
if (Utilities.existsInList(f.getName(), "conceptmaps.xml", "dataelements.xml", "extension-definitions.xml", "profiles-others.xml", "profiles-resources.xml", "profiles-types.xml", "search-parameters.xml", "v2-tables.xml", "v3-codesystems.xml", "valuesets.xml")) {
definitions.put(f.getName(), r);
}
r.setUserData("path", f.getName().substring(0, f.getName().indexOf(".")));
// FileUtils.copyFile(f, new File(f.getAbsolutePath()+"1"));
// FileUtils.copyFile(f, new File(f.getAbsolutePath()+"2"));
} catch (Exception e) {
System.out.println("Unable to load " + f.getName() + ": " + e.getMessage());
}
}
if (f.getName().endsWith(".json") && !(f.getName().endsWith("schema.json") || f.getName().endsWith(".diff.json"))) {
try {
// new JsonParser().parse(new FileInputStream(f));
// FileUtils.copyFile(f, new File(f.getAbsolutePath()+"1"));
// FileUtils.copyFile(f, new File(f.getAbsolutePath()+"2"));
} catch (Exception e) {
System.out.println("Unable to load " + f.getName() + ": " + e.getMessage());
}
}
}
System.out.println(Integer.toString(resources.size()) + " resources");
System.out.println(Integer.toString(definitions.size()) + " resources");
produceExamplesXml(resources, src);
produceDefinitionsXml(definitions, src);
produceExamplesJson(resources, src);
produceDefinitionsJson(definitions, src);
for (Resource r : definitions.values()) {
if (r instanceof Bundle) {
Bundle bnd = (Bundle) r;
for (BundleEntryComponent be : bnd.getEntry()) {
resources.add(be.getResource());
}
}
}
extractToPackageMaster(resources, packageRoot);
System.out.println("Done");
}
use of org.hl7.elm.r1.IndexOf in project org.hl7.fhir.core by hapifhir.
the class ProfileUtilities method getChildList.
public List<ElementDefinition> getChildList(StructureDefinition profile, String path, String id, boolean diff, boolean refs) {
List<ElementDefinition> res = new ArrayList<ElementDefinition>();
boolean capturing = id == null;
if (id == null && !path.contains("."))
capturing = true;
List<ElementDefinition> list = diff ? profile.getDifferential().getElement() : profile.getSnapshot().getElement();
for (ElementDefinition e : list) {
if (e == null)
throw new Error(context.formatMessage(I18nConstants.ELEMENT__NULL_, profile.getUrl()));
if (e.getId() == null)
throw new Error(context.formatMessage(I18nConstants.ELEMENT_ID__NULL__ON_, e.toString(), profile.getUrl()));
if (!capturing && id != null && e.getId().equals(id)) {
capturing = true;
}
// If our element is a slice, stop capturing children as soon as we see the next slice
if (capturing && e.hasId() && id != null && !e.getId().equals(id) && e.getPath().equals(path))
break;
if (capturing) {
String p = e.getPath();
if (refs && !Utilities.noString(e.getContentReference()) && path.startsWith(p)) {
if (path.length() > p.length()) {
return getChildList(profile, e.getContentReference() + "." + path.substring(p.length() + 1), null, diff);
} else if (e.getContentReference().startsWith("#")) {
return getChildList(profile, e.getContentReference().substring(1), null, diff);
} else if (e.getContentReference().contains("#")) {
String url = e.getContentReference().substring(0, e.getContentReference().indexOf("#"));
StructureDefinition sd = context.fetchResource(StructureDefinition.class, url);
if (sd == null) {
throw new DefinitionException("Unable to find Structure " + url);
}
return getChildList(sd, e.getContentReference().substring(e.getContentReference().indexOf("#") + 1), null, diff);
} else {
return getChildList(profile, e.getContentReference(), null, diff);
}
} else if (p.startsWith(path + ".") && !p.equals(path)) {
String tail = p.substring(path.length() + 1);
if (!tail.contains(".")) {
res.add(e);
}
}
}
}
return res;
}
Aggregations