Skip to content

Commit

Permalink
Process Archetypes properly as both IG input and output + remove ig-r…
Browse files Browse the repository at this point in the history
…4.json
  • Loading branch information
Grahame Grieve committed Jan 6, 2025
1 parent 682a590 commit 1b9d4f7
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -79,16 +79,22 @@ public static class ProcessedArchetype {
private StructureDefinition sd;
private Bundle bnd;
private String source;
protected ProcessedArchetype(String source, Archetype archetype, Bundle bnd, StructureDefinition sd) {
private String sourceName;

protected ProcessedArchetype(String source,String sourceName, Archetype archetype, Bundle bnd, StructureDefinition sd) {
super();
this.source = source;
this.sourceName = sourceName;
this.archetype = archetype;
this.sd = sd;
this.bnd = bnd;
}
public String getSource() {
return source;
}
public String getSourceName() {
return sourceName;
}
public Archetype getArchetype() {
return archetype;
}
Expand Down Expand Up @@ -216,7 +222,7 @@ public ProcessedArchetype importArchetype(InputStream stream, String name) throw
List<ElementDefinition> defns = sd.getDifferential().getElement();
processDefinition(defns, null, defn, baseType, null, baseType, defn.getNodeId());

return new ProcessedArchetype(new String(cnt), archetype, bnd, sd);
return new ProcessedArchetype(new String(cnt), name, archetype, bnd, sd);
}

private Archetype load20(InputStream stream) throws ADLParseException, IOException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -216,9 +216,7 @@ private void processValidatorPack(File f) throws IOException {
String destFile = dest != null ? dest : Utilities.path(Utilities.getDirectoryForFile(f.getAbsolutePath()), "package.tgz");
String url = Utilities.noString(website) ? canonical : website;
NPMPackageGenerator npm = new NPMPackageGenerator(destFile, canonical, url, PackageType.IG, ig, new Date(), false);
ByteArrayOutputStream bs = new ByteArrayOutputStream();
new JsonParser().setOutputStyle(OutputStyle.NORMAL).compose(bs, ig);
npm.addFile(Category.OTHER, "ig-r4.jsonX", bs.toByteArray());


npm.addFile(Category.RESOURCE, "ImplementationGuide-"+ig.getId()+".json", compose(ig, version));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5697,9 +5697,10 @@ private boolean loadBundle(String name, boolean needToBuild, FetchedFile igf, St
}

private boolean loadArchetype(FetchedFile f, String cause) throws Exception {
ProcessedArchetype pa = new ArchetypeImporter(context, igpkp.getCanonical()).importArchetype(f.getSource(), f.getName());
ProcessedArchetype pa = new ArchetypeImporter(context, igpkp.getCanonical()).importArchetype(f.getSource(), new File(f.getStatedPath()).getName());
Bundle bnd = pa.getBnd();
pa.getSd().setUserData(UserDataNames.archetype, pa.getSource());
pa.getSd().setUserData(UserDataNames.archetypeSource, pa.getSource());
pa.getSd().setUserData(UserDataNames.archetypeName, pa.getSourceName());

f.setBundle(new FetchedResource(f.getName()+" (bundle)"));
f.setBundleType(FetchedBundleType.NATIVE);
Expand Down Expand Up @@ -8415,11 +8416,7 @@ private void updateImplementationGuide() throws Exception {
}
r.setResource(publishedIg);
r.setElement(convertToElement(r, publishedIg));

ByteArrayOutputStream bs = new ByteArrayOutputStream();
new org.hl7.fhir.r4.formats.JsonParser().compose(bs, VersionConvertorFactory_40_50.convertResource(publishedIg));
npm.addFile(Category.OTHER, "ig-r4.jsonX", bs.toByteArray());


for (ImplementationGuideDefinitionResourceComponent res : publishedIg.getDefinition().getResource()) {
FetchedResource rt = null;
for (FetchedFile tf : fileList) {
Expand Down Expand Up @@ -12411,7 +12408,10 @@ private byte[] saveNativeResourceOutputs(FetchedFile f, FetchedResource r) throw
Element eNN = element;
jp.compose(element, bsj, OutputStyle.NORMAL, igpkp.getCanonical());
if (!r.isCustomResource()) {
npm.addFile(isExample(f,r ) ? Category.EXAMPLE : Category.RESOURCE, element.fhirType()+"-"+r.getId()+".json", bsj.toByteArray());
npm.addFile(isExample(f,r ) ? Category.EXAMPLE : Category.RESOURCE, element.fhirType()+"-"+r.getId()+".json", bsj.toByteArray());
if (r.getResource() != null && r.getResource().hasUserData(UserDataNames.archetypeSource)) {
npm.addFile(Category.ADL, r.getResource().getUserString(UserDataNames.archetypeName), r.getResource().getUserString(UserDataNames.archetypeSource).getBytes(StandardCharsets.UTF_8));
}
} else if ("StructureDefinition".equals(r.fhirType())) {
npm.addFile(Category.RESOURCE, element.fhirType()+"-"+r.getId()+".json", bsj.toByteArray());
StructureDefinition sdt = (StructureDefinition) r.getResource().copy();
Expand Down Expand Up @@ -13248,7 +13248,7 @@ private void generateOutputsStructureDefinition(FetchedFile f, FetchedResource r
fragment("StructureDefinition-"+prefixForContainer+sd.getId()+"-eview"+langSfx, sdr.eview(igpkp.getDefinitionsName(r), otherFilesRun, tabbedSnapshots, StructureDefinitionRendererMode.SUMMARY, false), f.getOutputNames(), r, vars, null, start, "eview", "StructureDefinition");
fragment("StructureDefinition-"+prefixForContainer+sd.getId()+"-eview-all"+langSfx, sdr.eview(igpkp.getDefinitionsName(r), otherFilesRun, tabbedSnapshots, StructureDefinitionRendererMode.SUMMARY, true), f.getOutputNames(), r, vars, null, start, "eview", "StructureDefinition");
}
if (igpkp.wantGen(r, "adl") && sd.hasUserData(UserDataNames.archetype)) {
if (igpkp.wantGen(r, "adl") && sd.hasUserData(UserDataNames.archetypeSource)) {
long start = System.currentTimeMillis();
fragment("StructureDefinition-"+prefixForContainer+sd.getId()+"-adl"+langSfx, sdr.adl(), f.getOutputNames(), r, vars, null, start, "adl", "StructureDefinition");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -467,8 +467,6 @@ private void processFileSame(NPMPackageGenerator gen, String folder, String file
// System.out.println("** Exclude "+res.fhirType()+"/"+res.getId()+" from same version");
}
}
} else if (filename.equals("ig-r4.json") || filename.equals("ig-r4.jsonX")) {
gen.addFile(folder, filename, updateIGR4(content, ver, pver));
} else if (filename.equals("spec.internals")) {
gen.addFile(folder, filename, updateSpecInternals(content, ver, pver));
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2569,6 +2569,6 @@ public String experimentalWarning() {
}

public String adl() {
return "<pre><code>"+Utilities.escapeXml(sd.getUserString(UserDataNames.archetype))+"</code></pre>";
return "<pre><code>"+Utilities.escapeXml(sd.getUserString(UserDataNames.archetypeSource))+"</code></pre>";
}
}

0 comments on commit 1b9d4f7

Please sign in to comment.