use of org.hl7.fhir.utilities.npm.NpmPackage in project kindling by HL7.
the class PageProcessor method setDefinitions.
public void setDefinitions(Definitions definitions) throws Exception {
this.definitions = definitions;
breadCrumbManager.setDefinitions(definitions);
TerminologyClient client;
try {
client = new TerminologyClientR5(tsServer);
client.setTimeout(60000);
} catch (Exception e) {
System.out.println("Warning @ PageProcessor client initialize: " + e.getLocalizedMessage());
client = null;
}
workerContext = new BuildWorkerContext(definitions, client, definitions.getCodeSystems(), definitions.getValuesets(), conceptMaps, profiles, guides, folders.rootDir);
workerContext.setDefinitions(definitions);
workerContext.setLogger(this);
workerContext.setAllowLoadingDuplicates(true);
log("Load UTG Terminology", LogMessageType.Process);
NpmPackage utg = new FilesystemPackageCacheManager(true, ToolsVersion.TOOLS_VERSION).loadPackage("hl7.terminology");
workerContext.loadFromPackage(utg, new R4ToR5Loader(BuildWorkerContext.defaultTypesToLoad(), new UTGLoader(utg.version())));
log("Load Terminology Cache from " + Utilities.path(folders.rootDir, "vscache"), LogMessageType.Process);
workerContext.initTS(Utilities.path(folders.rootDir, "vscache"));
log(" .. loaded", LogMessageType.Process);
vsValidator = new ValueSetValidator(workerContext, definitions.getVsFixups(), definitions.getStyleExemptions());
breadCrumbManager.setContext(workerContext);
}
use of org.hl7.fhir.utilities.npm.NpmPackage in project kindling by HL7.
the class BuildWorkerContext method loadFromPackageInt.
public int loadFromPackageInt(NpmPackage pi, IContextResourceLoader loader, String... types) throws FileNotFoundException, IOException, FHIRException {
int t = 0;
System.out.println("Load Package " + pi.name() + "#" + pi.version());
if (loadedPackages.contains(pi.id() + "#" + pi.version())) {
return 0;
}
loadedPackages.add(pi.id() + "#" + pi.version());
if ((types == null || types.length == 0) && loader != null) {
types = loader.getTypes();
}
for (PackageResourceInformation pri : pi.listIndexedResources(types)) {
try {
registerResourceFromPackage(new PackageResourceLoader(pri, loader), new PackageVersion(pi.id(), pi.version()));
t++;
} catch (FHIRException e) {
throw new FHIRException(formatMessage(I18nConstants.ERROR_READING__FROM_PACKAGE__, pri.getFilename(), pi.name(), pi.version(), e.getMessage()), e);
}
}
for (String s : pi.list("other")) {
binaries.put(s, TextFile.streamToBytes(pi.load("other", s)));
}
if (version == null) {
version = pi.version();
}
return t;
}
use of org.hl7.fhir.utilities.npm.NpmPackage in project org.hl7.fhir.core by hapifhir.
the class ExtensionDefinitionGenerator method loadSource.
private List<StructureDefinition> loadSource() throws IOException, FHIRException {
List<StructureDefinition> list = new ArrayList<>();
FilesystemPackageCacheManager pcm = new FilesystemPackageCacheManager(true, ToolsVersion.TOOLS_VERSION);
NpmPackage npm = pcm.loadPackage("hl7.fhir.core", sourceVersion.toCode());
if (sourceVersion == FHIRVersion._4_0_0)
context = SimpleWorkerContext.fromPackage(npm);
else if (sourceVersion == FHIRVersion._3_0_1)
context = SimpleWorkerContext.fromPackage(npm, new R3ToR4Loader());
else if (sourceVersion == FHIRVersion._1_4_0)
context = SimpleWorkerContext.fromPackage(npm, new R2016MayToR4Loader());
else if (sourceVersion == FHIRVersion._1_0_2)
context = SimpleWorkerContext.fromPackage(npm, new R2ToR4Loader());
pu = new ProfileUtilities(context, null, null);
for (String fn : npm.listResources("StructureDefinition")) {
list.add((StructureDefinition) loadResource(npm.load("package", fn), sourceVersion));
}
for (StructureDefinition sd : list) if (sd.getName().equals("Extension")) {
extbase = sd;
extv = extbase.getSnapshot().getElement().get(extbase.getSnapshot().getElement().size() - 1);
}
return list;
}
use of org.hl7.fhir.utilities.npm.NpmPackage in project org.hl7.fhir.core by hapifhir.
the class XMLPackageConvertor method process.
private void process(File folder) throws IOException {
for (File f : folder.listFiles()) {
if (f.isDirectory()) {
process(f);
} else {
if (f.getName().endsWith(".tgz")) {
System.out.println("Package " + f.getAbsolutePath());
NpmPackage p = NpmPackage.fromPackage(new FileInputStream(f));
if (p.getNpm().has("dependencies")) {
JsonObject dep = p.getNpm().getAsJsonObject("dependencies");
if (dep.entrySet().isEmpty()) {
System.out.println(" Dependencies: none");
} else {
System.out.println(" Dependencies:");
for (Entry<String, JsonElement> e : dep.entrySet()) {
System.out.println(" " + e.getKey() + ": " + e.getValue().getAsString());
}
}
} else {
System.out.println(" Dependencies: n/a");
}
}
}
}
}
use of org.hl7.fhir.utilities.npm.NpmPackage in project org.hl7.fhir.core by hapifhir.
the class JavaCoreGenerator method genClass.
public void genClass(String version, String dest, Date date, Configuration config, String jid, NpmPackage npm, Definitions master, JavaParserJsonGenerator jgen, JavaParserXmlGenerator xgen, JavaParserRdfGenerator rgen, StructureDefinition sd) throws Exception, IOException, UnsupportedEncodingException, FileNotFoundException {
String name = javaName(sd.getName());
System.out.println(" .. " + name);
Analyser jca = new Analyser(master, config, version);
Analysis analysis = jca.analyse(sd);
String fn = Utilities.path(dest, "src", "main", "java", "org", "hl7", "fhir", jid, "model", name + ".java");
JavaResourceGenerator gen = new JavaResourceGenerator(new FileOutputStream(fn), master, config, date, npm.version(), jid);
gen.generate(analysis);
gen.close();
jgen.seeClass(analysis);
xgen.seeClass(analysis);
rgen.seeClass(analysis);
}
Aggregations