use of org.hl7.fhir.utilities.graphql.Package in project org.hl7.fhir.core by hapifhir.
the class PackageValidator method execute.
private void execute() throws IOException {
FilesystemPackageCacheManager pcm = new FilesystemPackageCacheManager(true, ToolsVersion.TOOLS_VERSION);
CachingPackageClient pc = new CachingPackageClient(PackageClient.PRIMARY_SERVER);
for (PackageInfo t : pc.search(null, null, null, false)) {
System.out.println("Check Package " + t.getId());
List<PackageInfo> vl = pc.getVersions(t.getId());
PackageInfo v = vl.get(vl.size() - 1);
System.out.println(" v" + v.getVersion());
try {
NpmPackage pi = pcm.loadPackage(v.getId(), v.getVersion());
if (VersionUtilities.isR4Ver(pi.fhirVersion()) || VersionUtilities.isR3Ver(pi.fhirVersion()) || VersionUtilities.isR2Ver(pi.fhirVersion())) {
for (String n : pi.list("package")) {
if (n.endsWith(".json") && !n.equals("ig-r4.json")) {
InputStream s = pi.load("package", n);
try {
parseResource(s, pi.fhirVersion());
} catch (Exception e) {
System.out.println(" error parsing " + n + " for " + pi.fhirVersion() + ": " + e.getMessage());
}
}
}
} else {
System.out.println(" Unsupported FHIR version " + pi.fhirVersion());
}
} catch (Exception e) {
System.out.println(" Error - no FHIR version");
}
}
}
use of org.hl7.fhir.utilities.graphql.Package in project org.hl7.fhir.core by hapifhir.
the class UtilitiesXTests method loadTestResource.
public static String loadTestResource(String... paths) throws IOException {
if (new File("../../fhir-test-cases").exists() && isTryToLoadFromFileSystem()) {
String n = Utilities.path(System.getProperty("user.dir"), "..", "..", "fhir-test-cases", Utilities.path(paths));
// ok, we'll resolve this locally
return TextFile.fileToString(new File(n));
} else {
// resolve from the package
String contents;
String classpath = ("/org/hl7/fhir/testcases/" + Utilities.pathURL(paths));
try (InputStream inputStream = UtilitiesXTests.class.getResourceAsStream(classpath)) {
if (inputStream == null) {
throw new IOException("Can't find file on classpath: " + classpath);
}
contents = IOUtils.toString(inputStream, java.nio.charset.StandardCharsets.UTF_8);
}
return contents;
}
}
use of org.hl7.fhir.utilities.graphql.Package in project org.hl7.fhir.core by hapifhir.
the class PackageVisitor method getAllPackages.
private Set<String> getAllPackages() throws IOException, ParserConfigurationException, SAXException {
Set<String> list = new HashSet<>();
for (PackageInfo i : pc.search(null, null, null, false)) {
list.add(i.getId());
}
JsonObject json = JsonTrackingParser.fetchJson("https://raw.githubusercontent.com/FHIR/ig-registry/master/fhir-ig-list.json");
for (JsonObject ig : JSONUtil.objects(json, "guides")) {
list.add(JSONUtil.str(ig, "npm-name"));
}
json = JsonTrackingParser.fetchJson("https://raw.githubusercontent.com/FHIR/ig-registry/master/package-feeds.json");
for (JsonObject feed : JSONUtil.objects(json, "feeds")) {
processFeed(list, JSONUtil.str(feed, "url"));
}
return list;
}
use of org.hl7.fhir.utilities.graphql.Package in project org.hl7.fhir.core by hapifhir.
the class PackageVisitor method processPackage.
private void processPackage(String pid, String v) throws IOException {
NpmPackage npm = null;
String fv = null;
try {
npm = pcm.loadPackage(pid, v);
fv = npm.fhirVersion();
} catch (Throwable e) {
System.out.println("Unable to process: " + pid + "#" + v + ": " + e.getMessage());
}
int c = 0;
if (fv != null && (versions.isEmpty() || versions.contains(fv))) {
for (String type : resourceTypes) {
for (String s : npm.listResources(type)) {
c++;
processor.processResource(pid + "#" + v, fv, type, TextFile.streamToBytes(npm.load("package", s)));
}
}
}
System.out.println("Processed: " + pid + "#" + v + ": " + c + " resources");
}
use of org.hl7.fhir.utilities.graphql.Package in project org.hl7.fhir.core by hapifhir.
the class NPMPackageGenerator method buildPackageJson.
private void buildPackageJson(String canonical, PackageType kind, String web, Date date, ImplementationGuide ig, List<String> fhirVersion, boolean notForPublication) throws FHIRException, IOException {
String dtHuman = new SimpleDateFormat("EEE, MMM d, yyyy HH:mmZ", new Locale("en", "US")).format(date);
String dt = new SimpleDateFormat("yyyyMMddHHmmss").format(date);
CommaSeparatedStringBuilder b = new CommaSeparatedStringBuilder();
if (!ig.hasPackageId()) {
b.append("packageId");
}
if (!ig.hasVersion()) {
b.append("version");
}
if (!ig.hasFhirVersion()) {
b.append("fhirVersion");
}
if (!ig.hasLicense()) {
b.append("license");
}
for (ImplementationGuideDependsOnComponent d : ig.getDependsOn()) {
if (!d.hasVersion()) {
b.append("dependsOn.version(" + d.getUri() + ")");
}
}
JsonObject npm = new JsonObject();
npm.addProperty("name", ig.getPackageId());
npm.addProperty("version", ig.getVersion());
igVersion = ig.getVersion();
npm.addProperty("tools-version", ToolsVersion.TOOLS_VERSION);
npm.addProperty("type", kind.getCode());
npm.addProperty("date", dt);
if (ig.hasLicense()) {
npm.addProperty("license", ig.getLicense().toCode());
}
npm.addProperty("canonical", canonical);
if (notForPublication) {
npm.addProperty("notForPublication", true);
}
npm.addProperty("url", web);
if (ig.hasTitle()) {
npm.addProperty("title", ig.getTitle());
}
if (ig.hasDescription()) {
npm.addProperty("description", ig.getDescription() + " (built " + dtHuman + timezone() + ")");
}
JsonArray vl = new JsonArray();
npm.add("fhirVersions", vl);
for (String v : fhirVersion) {
vl.add(new JsonPrimitive(v));
}
if (kind != PackageType.CORE) {
JsonObject dep = new JsonObject();
npm.add("dependencies", dep);
for (String v : fhirVersion) {
String vp = packageForVersion(v);
if (vp != null) {
dep.addProperty(vp, v);
}
}
for (ImplementationGuideDependsOnComponent d : ig.getDependsOn()) {
dep.addProperty(d.getPackageId(), d.getVersion());
}
}
if (ig.hasPublisher()) {
npm.addProperty("author", ig.getPublisher());
}
JsonArray m = new JsonArray();
for (ContactDetail t : ig.getContact()) {
String email = email(t.getTelecom());
String url = url(t.getTelecom());
if (t.hasName() & (email != null || url != null)) {
JsonObject md = new JsonObject();
m.add(md);
md.addProperty("name", t.getName());
if (email != null)
md.addProperty("email", email);
if (url != null)
md.addProperty("url", url);
}
}
if (m.size() > 0)
npm.add("maintainers", m);
if (ig.getManifest().hasRendering())
npm.addProperty("homepage", ig.getManifest().getRendering());
JsonObject dir = new JsonObject();
npm.add("directories", dir);
dir.addProperty("lib", "package");
dir.addProperty("example", "example");
Gson gson = new GsonBuilder().setPrettyPrinting().create();
String json = gson.toJson(npm);
try {
addFile(Category.RESOURCE, "package.json", json.getBytes("UTF-8"));
} catch (UnsupportedEncodingException e) {
}
packageJ = npm;
packageManifest = new JsonObject();
packageManifest.addProperty("version", ig.getVersion());
packageManifest.addProperty("fhirVersion", fhirVersion.toString());
packageManifest.addProperty("date", dt);
packageManifest.addProperty("name", ig.getPackageId());
}
Aggregations