use of org.hl7.fhir.r5.utils.GraphQLSchemaGenerator.FHIROperationType in project kindling by HL7.
the class Publisher method produceSpecification.
// private List<Element> xPathQuery(String path, Element e) throws Exception {
// NamespaceContext context = new NamespaceContextMap("f",
// "http://hl7.org/fhir", "h", "http://www.w3.org/1999/xhtml", "a", );
//
// XPathFactory factory = XPathFactory.newInstance();
// XPath xpath = factory.newXPath();
// xpath.setNamespaceContext(context);
// XPathExpression expression= xpath.compile(path);
// NodeList resultNodes = (NodeList)expression.evaluate(e,
// XPathConstants.NODESET);
// List<Element> result = new ArrayList<Element>();
// for (int i = 0; i < resultNodes.getLength(); i++) {
// result.add((Element) resultNodes.item(i));
// }
// return result;
// }
private void produceSpecification() throws Exception {
page.setNavigation(new Navigation());
page.getNavigation().parse(page.getFolders().srcDir + "navigation.xml");
processCDA();
page.log("Generate RDF", LogMessageType.Process);
processRDF();
page.log("Produce Schemas", LogMessageType.Process);
new SchemaGenerator().generate(page.getDefinitions(), page.getIni(), page.getFolders().tmpResDir, page.getFolders().xsdDir + "codegen" + File.separator, page.getFolders().dstDir, page.getFolders().srcDir, page.getVersion().toCode(), Config.DATE_FORMAT().format(page.getGenDate().getTime()), true, page.getWorkerContext());
new SchemaGenerator().generate(page.getDefinitions(), page.getIni(), page.getFolders().tmpResDir, page.getFolders().xsdDir, page.getFolders().dstDir, page.getFolders().srcDir, page.getVersion().toCode(), Config.DATE_FORMAT().format(page.getGenDate().getTime()), false, page.getWorkerContext());
new org.hl7.fhir.definitions.generators.specification.json.SchemaGenerator().generate(page.getDefinitions(), page.getIni(), page.getFolders().tmpResDir, page.getFolders().xsdDir, page.getFolders().dstDir, page.getFolders().srcDir, page.getVersion().toCode(), Config.DATE_FORMAT().format(page.getGenDate().getTime()), page.getWorkerContext());
new org.hl7.fhir.definitions.generators.specification.json.JsonLDDefinitionsGenerator().generate(page.getDefinitions(), page.getIni(), page.getFolders().tmpResDir, page.getFolders().dstDir, page.getFolders().srcDir, page.getVersion(), Config.DATE_FORMAT().format(page.getGenDate().getTime()), page.getWorkerContext());
List<StructureDefinition> list = new ArrayList<StructureDefinition>();
for (StructureDefinition sd : page.getWorkerContext().allStructures()) {
if (sd.getDerivation() == TypeDerivationRule.SPECIALIZATION)
list.add(sd);
}
ShExGenerator shgen = new ShExGenerator(page.getWorkerContext());
shgen.completeModel = true;
shgen.withComments = false;
TextFile.stringToFile(shgen.generate(HTMLLinkPolicy.NONE, list), page.getFolders().dstDir + "fhir.shex", false);
new XVerPathsGenerator(page.getDefinitions(), Utilities.path(page.getFolders().dstDir, "xver-paths-" + Constants.VERSION_MM + ".json"), Utilities.path(page.getFolders().rootDir, "tools", "history", "release4", "xver-paths-4.0.json")).execute();
GraphQLSchemaGenerator gql = new GraphQLSchemaGenerator(page.getWorkerContext(), page.getVersion().toCode());
gql.generateTypes(new FileOutputStream(Utilities.path(page.getFolders().dstDir, "types.graphql")));
Set<String> names = new HashSet<String>();
for (StructureDefinition sd : page.getWorkerContext().allStructures()) {
if (sd.getKind() == StructureDefinitionKind.RESOURCE && sd.getAbstract() == false && sd.getDerivation() == TypeDerivationRule.SPECIALIZATION && !names.contains(sd.getUrl())) {
String filename = Utilities.path(page.getFolders().dstDir, sd.getName().toLowerCase() + ".graphql");
names.add(sd.getUrl());
List<SearchParameter> splist = new ArrayList<SearchParameter>();
ResourceDefn rd = page.getDefinitions().getResourceByName(sd.getName());
while (rd != null) {
for (String n : sorted(rd.getSearchParams().keySet())) {
SearchParameterDefn spd = rd.getSearchParams().get(n);
if (spd.getResource() == null)
buildSearchDefinition(rd, spd);
splist.add(spd.getResource());
}
rd = "Base".equals(rd.getRoot().typeCode()) || rd.getRoot().getTypes().isEmpty() ? null : page.getDefinitions().getResourceByName(rd.getRoot().typeCode());
}
EnumSet<FHIROperationType> ops = EnumSet.of(FHIROperationType.READ, FHIROperationType.SEARCH, FHIROperationType.CREATE, FHIROperationType.UPDATE, FHIROperationType.DELETE);
gql.generateResource(new FileOutputStream(filename), sd, splist, ops);
}
}
TextFile.stringToFile(page.genBackboneElementsJson(), Utilities.path(page.getFolders().dstDir, "backbone-elements.json"));
TextFile.stringToFile(page.genChoiceElementsJson(), Utilities.path(page.getFolders().dstDir, "choice-elements.json"));
page.log("Produce Schematrons", LogMessageType.Process);
for (String rname : page.getDefinitions().sortedResourceNames()) {
ResourceDefn r = page.getDefinitions().getResources().get(rname);
String n = r.getName().toLowerCase();
SchematronGenerator sch = new SchematronGenerator(page);
sch.generate(new FileOutputStream(page.getFolders().dstDir + n + ".sch"), r, page.getDefinitions());
}
ResourceDefn r = page.getDefinitions().getBaseResources().get("Parameters");
String n = r.getName().toLowerCase();
SchematronGenerator sch = new SchematronGenerator(page);
sch.generate(new FileOutputStream(page.getFolders().dstDir + n + ".sch"), r, page.getDefinitions());
SchematronGenerator sg = new SchematronGenerator(page);
sg.generate(new FileOutputStream(page.getFolders().dstDir + "fhir-invariants.sch"), page.getDefinitions());
produceSchemaZip();
page.log("Load R4 Definitions", LogMessageType.Process);
loadR4Definitions();
page.log("Produce Content", LogMessageType.Process);
produceSpec();
if (buildFlags.get("all")) {
if (web) {
generateRedirects();
}
}
page.clean();
}
use of org.hl7.fhir.r5.utils.GraphQLSchemaGenerator.FHIROperationType in project org.hl7.fhir.core by hapifhir.
the class GraphQLSchemaGenerator method generateType.
private void generateType(Map<String, String> existingTypeNames, Writer writer, StructureDefinition sd, EnumSet<FHIROperationType> operations) throws IOException {
if (sd.getAbstract()) {
return;
}
if (operations.contains(FHIROperationType.READ) || operations.contains(FHIROperationType.SEARCH)) {
List<StringBuilder> list = new ArrayList<>();
StringBuilder b = new StringBuilder();
list.add(b);
b.append("type ");
b.append(sd.getName());
b.append(" {\r\n");
ElementDefinition ed = sd.getSnapshot().getElementFirstRep();
generateProperties(existingTypeNames, list, b, sd.getName(), sd, ed, "type", "");
b.append("}");
b.append("\r\n");
b.append("\r\n");
for (StringBuilder bs : list) {
writer.write(bs.toString());
}
list.clear();
}
if (operations.contains(FHIROperationType.CREATE) || operations.contains(FHIROperationType.UPDATE)) {
List<StringBuilder> list = new ArrayList<>();
StringBuilder b = new StringBuilder();
list.add(b);
b.append("input ");
b.append(sd.getName());
b.append("Input {\r\n");
ElementDefinition ed = sd.getSnapshot().getElementFirstRep();
generateProperties(existingTypeNames, list, b, sd.getName(), sd, ed, "input", "Input");
b.append("}");
b.append("\r\n");
b.append("\r\n");
for (StringBuilder bs : list) {
writer.write(bs.toString());
}
}
}
use of org.hl7.fhir.r5.utils.GraphQLSchemaGenerator.FHIROperationType in project org.hl7.fhir.core by hapifhir.
the class GraphQLSchemaGenerator method generateTypes.
public void generateTypes(Writer writer, EnumSet<FHIROperationType> operations) throws IOException {
Map<String, StructureDefinition> pl = new HashMap<>();
Map<String, StructureDefinition> tl = new HashMap<>();
Map<String, String> existingTypeNames = new HashMap<>();
for (StructureDefinition sd : context.allStructures()) {
if (sd.getKind() == StructureDefinitionKind.PRIMITIVETYPE && sd.getDerivation() == TypeDerivationRule.SPECIALIZATION) {
pl.put(sd.getName(), sd);
}
if (sd.getKind() == StructureDefinitionKind.COMPLEXTYPE && sd.getDerivation() == TypeDerivationRule.SPECIALIZATION) {
tl.put(sd.getName(), sd);
}
}
writer.write("# FHIR GraphQL Schema. Version " + version + "\r\n\r\n");
writer.write("# FHIR Defined Primitive types\r\n");
for (String n : sorted(pl.keySet())) generatePrimitive(writer, pl.get(n));
writer.write("\r\n");
writer.write("# FHIR Defined Search Parameter Types\r\n");
for (SearchParamType dir : SearchParamType.values()) {
if (pl.containsKey(dir.toCode())) {
// Don't double create String and URI
continue;
}
if (dir != SearchParamType.NULL)
generateSearchParamType(writer, dir.toCode());
}
writer.write("\r\n");
generateElementBase(writer, operations);
for (String n : sorted(tl.keySet())) {
generateType(existingTypeNames, writer, tl.get(n), operations);
}
}
Aggregations