use of org.hl7.fhir.r4b.context.IWorkerContext in project org.hl7.fhir.core by hapifhir.
the class Tester method main.
public static void main(String[] args) throws Exception {
IWorkerContext context = new SimpleWorkerContext.SimpleWorkerContextBuilder().fromPack(Utilities.path("C:\\work\\org.hl7.fhir\\build\\publish", "validation-min.xml.zip"));
int t = 0;
int ok = 0;
for (String f : new File("C:\\work\\org.hl7.fhir\\build\\publish").list()) {
if (f.endsWith(".xml") && !f.endsWith(".canonical.xml") && !f.contains("profile") && !f.contains("questionnaire") && new File("C:\\work\\org.hl7.fhir\\build\\publish\\" + Utilities.changeFileExt(f, ".ttl")).exists()) {
// if (f.equals("account-questionnaire.xml")) {
System.out.print("convert " + f);
// Manager.convert(context, new FileInputStream("C:\\work\\org.hl7.fhir\\build\\publish\\"+f), FhirFormat.XML,
// new FileOutputStream("C:\\work\\org.hl7.fhir\\build\\publish\\"+Utilities.changeFileExt(f, ".mm.json")), FhirFormat.JSON, OutputStyle.PRETTY);
// String src = normalise(TextFile.fileToString("C:\\work\\org.hl7.fhir\\build\\publish\\"+Utilities.changeFileExt(f, ".mm.json")));
// String tgt = normalise(TextFile.fileToString("C:\\work\\org.hl7.fhir\\build\\publish\\"+Utilities.changeFileExt(f, ".json")));
Element e = Manager.parseSingle(context, new FileInputStream("C:\\work\\org.hl7.fhir\\build\\publish\\" + f), FhirFormat.XML);
Manager.compose(context, e, new FileOutputStream("C:\\work\\org.hl7.fhir\\build\\publish\\" + Utilities.changeFileExt(f, ".mm.ttl")), FhirFormat.TURTLE, OutputStyle.PRETTY, null);
Manager.compose(context, e, new FileOutputStream(Utilities.path("[tmp]", "resource.xml")), FhirFormat.XML, OutputStyle.PRETTY, null);
String src = TextFile.fileToString("C:\\work\\org.hl7.fhir\\build\\publish\\" + Utilities.changeFileExt(f, ".mm.ttl"));
String tgt = TextFile.fileToString("C:\\work\\org.hl7.fhir\\build\\publish\\" + Utilities.changeFileExt(f, ".ttl"));
t++;
if (src.equals(tgt)) {
System.out.println(".. ok");
ok++;
} else
System.out.println(".. fail");
}
// }
}
System.out.println("done - " + Integer.toString(t) + " files, " + Integer.toString(ok) + " ok");
}
use of org.hl7.fhir.r4b.context.IWorkerContext in project org.hl7.fhir.core by hapifhir.
the class ResourceUtilities method representDataElementCollection.
public static String representDataElementCollection(IWorkerContext context, Bundle bundle, boolean profileLink, String linkBase) {
StringBuilder b = new StringBuilder();
DataElement common = showDECHeader(b, bundle);
b.append("<table class=\"grid\">\r\n");
List<String> cols = chooseColumns(bundle, common, b, profileLink);
for (BundleEntryComponent e : bundle.getEntry()) {
DataElement de = (DataElement) e.getResource();
renderDE(de, cols, b, profileLink, linkBase);
}
b.append("</table>\r\n");
return b.toString();
}
use of org.hl7.fhir.r4b.context.IWorkerContext in project org.hl7.fhir.core by hapifhir.
the class CSVWriter method processElement.
/* private void findMapKeys(StructureDefinition def, List<StructureDefinitionMappingComponent> maps, IWorkerContext context) {
maps.addAll(def.getMapping());
if (def.getBaseDefinition()!=null) {
StructureDefinition base = context.fetchResource(StructureDefinition.class, def.getBaseDefinition());
findMapKeys(base, maps, context);
}
}*/
public void processElement(ElementDefinition ed) throws Exception {
CSVLine line = new CSVLine();
lines.add(line);
line.addString(ed.getId());
line.addString(ed.getPath());
line.addString(ed.getSliceName());
line.addString(itemList(ed.getAlias()));
line.addString(ed.getLabel());
line.addValue(ed.getMin());
line.addValue(ed.getMax());
line.addString(ed.getMustSupport() ? "Y" : "");
line.addString(ed.getIsModifier() ? "Y" : "");
line.addString(ed.getIsSummary() ? "Y" : "");
line.addString(itemList(ed.getType()));
line.addString(ed.getShort());
line.addString(ed.getDefinition());
line.addString(ed.getComment());
line.addString(ed.getRequirements());
line.addString(ed.getDefaultValue() != null ? renderType(ed.getDefaultValue()) : "");
line.addString(ed.getMeaningWhenMissing());
line.addString(ed.hasFixed() ? renderType(ed.getFixed()) : "");
line.addString(ed.hasPattern() ? renderType(ed.getPattern()) : "");
// todo...?
line.addString(ed.hasExample() ? renderType(ed.getExample().get(0).getValue()) : "");
line.addString(ed.hasMinValue() ? renderType(ed.getMinValue()) : "");
line.addString(ed.hasMaxValue() ? renderType(ed.getMaxValue()) : "");
line.addValue((ed.hasMaxLength() ? Integer.toString(ed.getMaxLength()) : ""));
if (ed.hasBinding()) {
line.addString(ed.getBinding().getStrength() != null ? ed.getBinding().getStrength().toCode() : "");
line.addString(ed.getBinding().getDescription());
if (ed.getBinding().getValueSet() == null)
line.addString("");
else
line.addString(ed.getBinding().getValueSet());
} else {
line.addValue("");
line.addValue("");
line.addValue("");
}
line.addString(itemList(ed.getCode()));
if (ed.hasSlicing()) {
line.addString(itemList(ed.getSlicing().getDiscriminator()));
line.addString(ed.getSlicing().getDescription());
line.addBoolean(ed.getSlicing().getOrdered());
line.addString(ed.getSlicing().getRules() != null ? ed.getSlicing().getRules().toCode() : "");
} else {
line.addValue("");
line.addValue("");
line.addValue("");
}
if (ed.getBase() != null) {
line.addString(ed.getBase().getPath());
line.addValue(ed.getBase().getMin());
line.addValue(ed.getBase().getMax());
} else {
line.addValue("");
line.addValue("");
line.addValue("");
}
line.addString(itemList(ed.getCondition()));
line.addString(itemList(ed.getConstraint()));
for (StructureDefinitionMappingComponent mapKey : def.getMapping()) {
for (ElementDefinitionMappingComponent map : ed.getMapping()) {
if (map.getIdentity().equals(mapKey.getIdentity()))
line.addString(map.getMap());
}
}
}
use of org.hl7.fhir.r4b.context.IWorkerContext in project org.hl7.fhir.core by hapifhir.
the class TestingUtilities method getWorkerContext.
public static IWorkerContext getWorkerContext(String version) {
FilesystemPackageCacheManager pcm;
try {
pcm = new FilesystemPackageCacheManager(true, ToolsVersion.TOOLS_VERSION);
IWorkerContext fcontext = getWorkerContext(pcm.loadPackage(VersionUtilities.packageForVersion(version), version));
fcontext.setUcumService(new UcumEssenceService(TestingUtilities.loadTestResourceStream("ucum", "ucum-essence.xml")));
fcontext.setExpansionProfile(new Parameters());
if (!fcontext.hasPackage("hl7.terminology", null)) {
NpmPackage utg = new FilesystemPackageCacheManager(true, ToolsVersion.TOOLS_VERSION).loadPackage("hl7.terminology");
System.out.println("Loading THO: " + utg.name() + "#" + utg.version());
fcontext.loadFromPackage(utg, new TestPackageLoader(new String[] { "CodeSystem", "ValueSet" }));
}
return fcontext;
} catch (Exception e) {
e.printStackTrace();
throw new Error(e);
}
}
use of org.hl7.fhir.r4b.context.IWorkerContext in project org.hl7.fhir.core by hapifhir.
the class UtilitiesXTests method context.
public static IWorkerContext context(String version) {
if (fcontexts == null) {
fcontexts = new HashMap<>();
}
if (!fcontexts.containsKey(version)) {
FilesystemPackageCacheManager pcm;
try {
pcm = new FilesystemPackageCacheManager(true, ToolsVersion.TOOLS_VERSION);
IWorkerContext fcontext = TestingUtilities.getWorkerContext(pcm.loadPackage(VersionUtilities.packageForVersion(version), version), loaderForVersion(version));
fcontext.setUcumService(new UcumEssenceService(UtilitiesXTests.loadTestResourceStream("ucum", "ucum-essence.xml")));
fcontext.setExpansionProfile(new Parameters());
fcontexts.put(version, fcontext);
} catch (Exception e) {
throw new Error(e);
}
}
return fcontexts.get(version);
}
Aggregations