use of org.hl7.fhir.utilities.graphql.Package in project org.hl7.fhir.core by hapifhir.
the class JavaEnumerationsGenerator method generate.
public void generate() throws Exception {
write("package org.hl7.fhir." + jid + ".model;\r\n");
startMark(version, genDate);
write("\r\n");
write("import org.hl7.fhir.instance.model.api.*;\r\n");
write("import org.hl7.fhir.exceptions.FHIRException;\r\n");
write("\r\n");
write("public class Enumerations {\r\n");
write("\r\n");
write("// In here: \r\n");
Map<String, ValueSet> enums = scanForEnums();
List<String> names = new ArrayList<String>();
names.addAll(enums.keySet());
Collections.sort(names);
for (String n : names) {
ValueSet vs = enums.get(n);
write("// " + n + ": " + vs.getDescription());
if (vs.hasUserData("usages")) {
write(vs.getUserData("usages").toString());
} else {
write("?null?");
}
write("\r\n");
}
write("\r\n");
write("\r\n");
for (String n : names) {
ValueSet vs = enums.get(n);
generateEnum(n, (ValueSet) vs.getUserData("expansion"));
}
write("\r\n");
write("}\r\n");
write("\r\n");
flush();
}
use of org.hl7.fhir.utilities.graphql.Package in project org.hl7.fhir.core by hapifhir.
the class RdfParser method composeMedicationMedicationPackageComponent.
protected void composeMedicationMedicationPackageComponent(Complex parent, String parentType, String name, Medication.MedicationPackageComponent element, int index) {
if (element == null)
return;
Complex t;
if (Utilities.noString(parentType))
t = parent;
else {
t = parent.predicate("fhir:" + parentType + '.' + name);
}
composeBackboneElement(t, "package", name, element, index);
if (element.hasContainer())
composeCodeableConcept(t, "Medication", "container", element.getContainer(), -1);
for (int i = 0; i < element.getContent().size(); i++) composeMedicationMedicationPackageContentComponent(t, "Medication", "content", element.getContent().get(i), i);
}
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, String genDate, ImplementationGuide ig, List<String> fhirVersion) throws FHIRException, IOException {
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());
npm.addProperty("tools-version", ToolsVersion.TOOLS_VERSION);
npm.addProperty("type", kind.getCode());
if (ig.hasLicense())
npm.addProperty("license", ig.getLicense().toCode());
npm.addProperty("canonical", canonical);
npm.addProperty("url", web);
if (ig.hasTitle())
npm.addProperty("title", ig.getTitle());
if (ig.hasDescription())
npm.addProperty("description", ig.getDescription() + " (built " + genDate + timezone() + ")");
if (kind != PackageType.CORE) {
JsonObject dep = new JsonObject();
npm.add("dependencies", dep);
for (String v : fhirVersion) {
// TODO: fix for multiple versions
dep.addProperty("hl7.fhir.core", 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;
}
use of org.hl7.fhir.utilities.graphql.Package in project org.hl7.fhir.core by hapifhir.
the class NPMPackageGenerator method loadFiles.
public void loadFiles(String root, File dir, String... noload) throws IOException {
for (File f : dir.listFiles()) {
if (!Utilities.existsInList(f.getName(), noload)) {
if (f.isDirectory()) {
loadFiles(root, f);
} else {
String path = f.getAbsolutePath().substring(root.length() + 1);
byte[] content = TextFile.fileToBytes(f);
if (created.contains(path))
System.out.println("Duplicate package file " + path);
else {
created.add(path);
TarArchiveEntry entry = new TarArchiveEntry(path);
entry.setSize(content.length);
tar.putArchiveEntry(entry);
tar.write(content);
tar.closeArchiveEntry();
}
}
}
}
}
use of org.hl7.fhir.utilities.graphql.Package in project org.hl7.fhir.core by hapifhir.
the class SimpleWorkerContext method loadFromPackageInt.
public int loadFromPackageInt(NpmPackage pi, IContextResourceLoader loader, String... types) throws FileNotFoundException, IOException, FHIRException {
int t = 0;
if (progress) {
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();
}
if (VersionUtilities.isR2Ver(pi.fhirVersion()) || !pi.canLazyLoad()) {
// can't lazy load R2 because of valueset/codesystem implementation
if (types.length == 0) {
types = new String[] { "StructureDefinition", "ValueSet", "SearchParameter", "OperationDefinition", "Questionnaire", "ConceptMap", "StructureMap", "NamingSystem" };
}
for (String s : pi.listResources(types)) {
try {
loadDefinitionItem(s, pi.load("package", s), loader, null, new PackageVersion(pi.id(), pi.version()));
t++;
} catch (Exception e) {
throw new FHIRException(formatMessage(I18nConstants.ERROR_READING__FROM_PACKAGE__, s, pi.name(), pi.version(), e.getMessage()), e);
}
}
} else {
if (types.length == 0) {
types = new String[] { "StructureDefinition", "ValueSet", "CodeSystem", "SearchParameter", "OperationDefinition", "Questionnaire", "ConceptMap", "StructureMap", "NamingSystem", "Measures" };
}
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;
}
Aggregations