Merge pull request #1734 from hapifhir/2024-09-gg-misc

2024 09 gg misc
This commit is contained in:
Grahame Grieve 2024-09-05 04:29:20 +08:00 committed by GitHub
commit 541e903d50
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
9 changed files with 116 additions and 86 deletions

View File

@ -3463,6 +3463,11 @@ public class ProfileUtilities {
public void sortDifferential(StructureDefinition base, StructureDefinition diff, String name, List<String> errors, boolean errorIfChanges) throws FHIRException { public void sortDifferential(StructureDefinition base, StructureDefinition diff, String name, List<String> errors, boolean errorIfChanges) throws FHIRException {
int index = 0;
for (ElementDefinition ed : diff.getDifferential().getElement()) {
ed.setUserData("ed.index", Integer.toString(index));
index++;
}
List<ElementDefinition> original = new ArrayList<>(); List<ElementDefinition> original = new ArrayList<>();
original.addAll(diff.getDifferential().getElement()); original.addAll(diff.getDifferential().getElement());
final List<ElementDefinition> diffList = diff.getDifferential().getElement(); final List<ElementDefinition> diffList = diff.getDifferential().getElement();
@ -3520,7 +3525,7 @@ public class ProfileUtilities {
ElementDefinition e = diffList.get(i); ElementDefinition e = diffList.get(i);
ElementDefinition n = newDiff.get(i); ElementDefinition n = newDiff.get(i);
if (!n.getPath().equals(e.getPath())) { if (!n.getPath().equals(e.getPath())) {
errors.add("The element "+e.getPath()+" is out of order (and maybe others after it)"); errors.add("The element "+(e.hasId() ? e.getId() : e.getPath())+" @diff["+e.getUserString("ed.index")+"] is out of order (and maybe others after it)");
return; return;
} }
} }

View File

@ -166,7 +166,9 @@ public class LanguageUtils {
} }
for (TranslationUnit t : translations) { for (TranslationUnit t : translations) {
if (!usedUnits.contains(t)) { if (!usedUnits.contains(t)) {
messages.add(new ValidationMessage(Source.Publisher, IssueType.INFORMATIONAL, t.getId(), "Unused '"+t.getLanguage()+"' translation '"+t.getSrcText()+"' -> '"+t.getTgtText()+"'", IssueSeverity.INFORMATION)); if (messages != null) {
messages.add(new ValidationMessage(Source.Publisher, IssueType.INFORMATIONAL, t.getId(), "Unused '"+t.getLanguage()+"' translation '"+t.getSrcText()+"' -> '"+t.getTgtText()+"'", IssueSeverity.INFORMATION));
}
} }
} }
return r; return r;
@ -182,7 +184,9 @@ public class LanguageUtils {
} }
for (TranslationUnit t : translations) { for (TranslationUnit t : translations) {
if (!usedUnits.contains(t)) { if (!usedUnits.contains(t)) {
messages.add(new ValidationMessage(Source.Publisher, IssueType.INFORMATIONAL, t.getId(), "Unused '"+t.getLanguage()+"' translation '"+t.getSrcText()+"' -> '"+t.getTgtText()+"'", IssueSeverity.INFORMATION)); if (messages != null) {
messages.add(new ValidationMessage(Source.Publisher, IssueType.INFORMATIONAL, t.getId(), "Unused '"+t.getLanguage()+"' translation '"+t.getSrcText()+"' -> '"+t.getTgtText()+"'", IssueSeverity.INFORMATION));
}
} }
} }
return r; return r;
@ -296,7 +300,9 @@ public class LanguageUtils {
} }
} }
} }
for (Element c : element.getChildren()) { List<Element> cl = new ArrayList<Element>();
cl.addAll(element.getChildren());
for (Element c : cl) {
if (!c.getName().equals("designation")) { if (!c.getName().equals("designation")) {
t = t + importFromTranslations(element, c, translations, usedUnits); t = t + importFromTranslations(element, c, translations, usedUnits);
} }

View File

@ -897,7 +897,7 @@ public class StructureDefinitionRenderer extends ResourceRenderer {
Row parent = null; Row parent = null;
if (child.hasSliceName()) { if (child.hasSliceName()) {
// ok, we're a slice // ok, we're a slice
if (slicer == null || !slicer.getId().equals(child.getPath())) { if (slicer == null || !noTail(slicer.getId()).equals(child.getPath())) {
parent = gen.new Row(); parent = gen.new Row();
String anchorE = child.getPath(); String anchorE = child.getPath();
anchorE = makeAnchorUnique(anchorE); anchorE = makeAnchorUnique(anchorE);
@ -906,7 +906,7 @@ public class StructureDefinitionRenderer extends ResourceRenderer {
parent.setColor(context.getProfileUtilities().getRowColor(child, isConstraintMode)); parent.setColor(context.getProfileUtilities().getRowColor(child, isConstraintMode));
parent.setLineColor(1); parent.setLineColor(1);
parent.setIcon("icon_slice.png", context.formatPhrase(RenderingContext.TEXT_ICON_SLICE)); parent.setIcon("icon_slice.png", context.formatPhrase(RenderingContext.TEXT_ICON_SLICE));
parent.getCells().add(gen.new Cell(null, null, "Slices for "+ child.getName(), "", null)); parent.getCells().add(gen.new Cell(null, null, context.formatPhrase(RenderingContext.STRUC_DEF_SLICE_FOR, child.getName()), "", null));
switch (context.getStructureMode()) { switch (context.getStructureMode()) {
case BINDINGS: case BINDINGS:
case OBLIGATIONS: case OBLIGATIONS:
@ -947,6 +947,16 @@ public class StructureDefinitionRenderer extends ResourceRenderer {
return slicingRow; return slicingRow;
} }
private String noTail(String id) {
if (id.contains(".")) {
String t = id.substring(id.lastIndexOf(".")+1);
if (Utilities.isInteger(t)) {
return id.substring(0, id.lastIndexOf("."));
}
}
return id;
}
private String makeAnchorUnique(String anchor) { private String makeAnchorUnique(String anchor) {
if (anchors.containsKey(anchor)) { if (anchors.containsKey(anchor)) {
int c = anchors.get(anchor)+1; int c = anchors.get(anchor)+1;
@ -1063,7 +1073,7 @@ public class StructureDefinitionRenderer extends ResourceRenderer {
hint = checkAdd(hint, !hasDef ? null : gt(element.getDefinitionElement())); hint = checkAdd(hint, !hasDef ? null : gt(element.getDefinitionElement()));
} }
if (element.hasSlicing() && slicesExist(elements, element)) { // some elements set up slicing but don't actually slice, so we don't augment the name if (element.hasSlicing() && slicesExist(elements, element)) { // some elements set up slicing but don't actually slice, so we don't augment the name
sName = context.formatPhrase(RenderingContext.STRUC_DEF_SLICE_FOR, sName); sName = context.formatPhrase(RenderingContext.STRUC_DEF_SLICE_FOR, sName);
} }
Cell left = gen.new Cell(null, ref, sName, hint, null); Cell left = gen.new Cell(null, ref, sName, hint, null);
row.getCells().add(left); row.getCells().add(left);

View File

@ -100,7 +100,8 @@ public class SpreadsheetGenerator {
if (name.length() > MAX_SENSITIVE_SHEET_NAME_LEN - 2) { if (name.length() > MAX_SENSITIVE_SHEET_NAME_LEN - 2) {
name = name.substring(0, MAX_SENSITIVE_SHEET_NAME_LEN - 2); name = name.substring(0, MAX_SENSITIVE_SHEET_NAME_LEN - 2);
} }
String s = fixSheetNameChars(name); name = fixSheetNameChars(name);
String s = name;
if (sheetNames.containsKey(s)) { if (sheetNames.containsKey(s)) {
int i = 1; int i = 1;
do { do {

View File

@ -1,25 +1,17 @@
package org.hl7.fhir.r5.renderers.spreadsheets; package org.hl7.fhir.r5.renderers.spreadsheets;
import java.io.FileOutputStream;
import java.io.IOException; import java.io.IOException;
import java.io.OutputStream;
import java.util.List; import java.util.List;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Sheet; import org.apache.poi.ss.usermodel.Sheet;
import org.hl7.fhir.exceptions.DefinitionException;
import org.hl7.fhir.r5.context.IWorkerContext; import org.hl7.fhir.r5.context.IWorkerContext;
import org.hl7.fhir.r5.context.SimpleWorkerContext;
import org.hl7.fhir.r5.model.CanonicalType; import org.hl7.fhir.r5.model.CanonicalType;
import org.hl7.fhir.r5.model.ElementDefinition;
import org.hl7.fhir.r5.model.ValueSet; import org.hl7.fhir.r5.model.ValueSet;
import org.hl7.fhir.r5.model.ValueSet.ConceptReferenceComponent; import org.hl7.fhir.r5.model.ValueSet.ConceptReferenceComponent;
import org.hl7.fhir.r5.model.ValueSet.ConceptSetComponent; import org.hl7.fhir.r5.model.ValueSet.ConceptSetComponent;
import org.hl7.fhir.r5.model.ValueSet.ConceptSetFilterComponent; import org.hl7.fhir.r5.model.ValueSet.ConceptSetFilterComponent;
import org.hl7.fhir.r5.model.ValueSet.ValueSetExpansionContainsComponent; import org.hl7.fhir.r5.model.ValueSet.ValueSetExpansionContainsComponent;
import org.hl7.fhir.r5.model.ValueSet.ValueSetExpansionParameterComponent; import org.hl7.fhir.r5.model.ValueSet.ValueSetExpansionParameterComponent;
import org.hl7.fhir.r5.model.StructureDefinition.StructureDefinitionMappingComponent;
import org.hl7.fhir.utilities.i18n.I18nConstants;
public class ValueSetSpreadsheetGenerator extends CanonicalSpreadsheetGenerator { public class ValueSetSpreadsheetGenerator extends CanonicalSpreadsheetGenerator {
@ -36,11 +28,12 @@ public class ValueSetSpreadsheetGenerator extends CanonicalSpreadsheetGenerator
System.out.println("no valueset!"); System.out.println("no valueset!");
} }
addValueSetMetadata(renderCanonicalResource(vs, false), vs); addValueSetMetadata(renderCanonicalResource(vs, false), vs);
int i = 0;
for (ConceptSetComponent inc : vs.getCompose().getInclude()) { for (ConceptSetComponent inc : vs.getCompose().getInclude()) {
genInclude(vs, inc, "Include"); genInclude(vs, inc, "Include", i++);
} }
for (ConceptSetComponent exc : vs.getCompose().getExclude()) { for (ConceptSetComponent exc : vs.getCompose().getExclude()) {
genInclude(vs, exc, "Exclude"); genInclude(vs, exc, "Exclude", i++);
} }
if (vs.hasExpansion()) { if (vs.hasExpansion()) {
if (vs.getExpansion().hasParameter()) { if (vs.getExpansion().hasParameter()) {
@ -82,11 +75,11 @@ public class ValueSetSpreadsheetGenerator extends CanonicalSpreadsheetGenerator
return value ? "" : "false"; return value ? "" : "false";
} }
private void genInclude(ValueSet vs, ConceptSetComponent inc, String mode) { private void genInclude(ValueSet vs, ConceptSetComponent inc, String mode, int count) {
if (inc.hasSystem()) { if (inc.hasSystem()) {
genIncludeSystem(vs, inc, mode); genIncludeSystem(vs, inc, mode, count);
} else { } else {
genIncludeValueSets(vs, inc, mode); genIncludeValueSets(vs, inc, mode, count);
} }
// String subname = inc.hasSystem() ? : "ValueSets"; // String subname = inc.hasSystem() ? : "ValueSets";
// //
@ -107,14 +100,14 @@ public class ValueSetSpreadsheetGenerator extends CanonicalSpreadsheetGenerator
// configureSheet(sheet, sd); // configureSheet(sheet, sd);
} }
private void genIncludeValueSets(ValueSet vs, ConceptSetComponent inc, String mode) { private void genIncludeValueSets(ValueSet vs, ConceptSetComponent inc, String mode, int count) {
Sheet sheet = makeSheet(mode+" ValueSets"); Sheet sheet = makeSheet(mode+" ValueSet #"+count);
addValueSets(sheet, inc.getValueSet()); addValueSets(sheet, inc.getValueSet());
configureSheet(sheet); configureSheet(sheet);
} }
private void genIncludeSystem(ValueSet vs, ConceptSetComponent inc, String mode) { private void genIncludeSystem(ValueSet vs, ConceptSetComponent inc, String mode, int count) {
Sheet sheet = makeSheet(mode+" from "+dr.displaySystem(inc.getSystem())); Sheet sheet = makeSheet(mode+" #"+count);
if (inc.hasValueSet()) { if (inc.hasValueSet()) {
addValueSets(sheet, inc.getValueSet()); addValueSets(sheet, inc.getValueSet());
} }

View File

@ -84,12 +84,12 @@ public class NarrativeGenerationTests {
@Override @Override
public String getLinkFor(String corePath, String typeSimple) { public String getLinkFor(String corePath, String typeSimple) {
throw new NotImplementedException(); return "http://test/link";
} }
@Override @Override
public BindingResolution resolveBinding(StructureDefinition def, ElementDefinitionBindingComponent binding, String path) throws FHIRException { public BindingResolution resolveBinding(StructureDefinition def, ElementDefinitionBindingComponent binding, String path) throws FHIRException {
throw new NotImplementedException(); return new BindingResolution("test", "http://test");
} }
@Override @Override
@ -102,7 +102,7 @@ public class NarrativeGenerationTests {
return new BindingResolution(vs.present(), "valueset-"+vs.getIdBase()+".html"); return new BindingResolution(vs.present(), "valueset-"+vs.getIdBase()+".html");
} }
} }
throw new NotImplementedException(); return new BindingResolution("test", "http://test/ns");
} }
@Override @Override
@ -120,7 +120,7 @@ public class NarrativeGenerationTests {
@Override @Override
public String getLinkForUrl(String corePath, String s) { public String getLinkForUrl(String corePath, String s) {
throw new NotImplementedException(); return "http://test/link/url";
} }
@Override @Override

View File

@ -30,61 +30,73 @@ public class PackageHacker {
private static boolean useSecureReferences = false; private static boolean useSecureReferences = false;
public static void main(String[] args) throws FileNotFoundException, IOException { public static void main(String[] args) throws FileNotFoundException, IOException {
new PackageHacker().massEdit(new File("/Users/grahamegrieve/web/hl7.org/fhir")); // new PackageHacker().massEdit(new File("/Users/grahamegrieve/web/hl7.org/fhir"));
// new PackageHacker().edit("/Users/grahamegrieve/web/hl7.org/fhir/us/vitals/2020Sep/package.tgz"); new PackageHacker().edit("/Users/grahamegrieve/web/hl7.org/fhir/6.0.0-ballot1/hl7.fhir.r6.core.tgz");
new PackageHacker().edit("/Users/grahamegrieve/web/hl7.org/fhir/6.0.0-ballot1/hl7.fhir.r6.corexml.tgz");
new PackageHacker().edit("/Users/grahamegrieve/web/hl7.org/fhir/6.0.0-ballot1/hl7.fhir.r6.examples.tgz");
new PackageHacker().edit("/Users/grahamegrieve/web/hl7.org/fhir/6.0.0-ballot1/hl7.fhir.r6.expansions.tgz");
new PackageHacker().edit("/Users/grahamegrieve/web/hl7.org/fhir/6.0.0-ballot1/hl7.fhir.r6.search.tgz");
new PackageHacker().edit("/Users/grahamegrieve/web/hl7.org/fhir/6.0.0-ballot2/hl7.fhir.r6.core.tgz");
new PackageHacker().edit("/Users/grahamegrieve/web/hl7.org/fhir/6.0.0-ballot2/hl7.fhir.r6.corexml.tgz");
new PackageHacker().edit("/Users/grahamegrieve/web/hl7.org/fhir/6.0.0-ballot2/hl7.fhir.r6.examples.tgz");
new PackageHacker().edit("/Users/grahamegrieve/web/hl7.org/fhir/6.0.0-ballot2/hl7.fhir.r6.expansions.tgz");
new PackageHacker().edit("/Users/grahamegrieve/web/hl7.org/fhir/6.0.0-ballot2/hl7.fhir.r6.search.tgz");
// new PackageHacker().edit(args[0]);
} }
private void massEdit(File dir) throws IOException { // private void massEdit(File dir) throws IOException {
System.out.println("process "+dir.getAbsolutePath()); // System.out.println("process "+dir.getAbsolutePath());
for (File f : dir.listFiles()) { // for (File f : dir.listFiles()) {
if (f.isDirectory()) { // if (f.isDirectory()) {
massEdit(f); // massEdit(f);
} else if (f.getName().equals("package.tgz")) { // } else if (f.getName().equals("package.tgz")) {
try { // try {
FileInputStream fs = ManagedFileAccess.inStream(f); // FileInputStream fs = ManagedFileAccess.inStream(f);
NpmPackage pck = NpmPackage.fromPackage(fs); // NpmPackage pck = NpmPackage.fromPackage(fs);
if ("fhir.core".equals(pck.getNpm().str("type"))) { // if ("fhir.core".equals(pck.getNpm().str("type"))) {
System.out.println("!!change "+f.getAbsolutePath()); // System.out.println("!!change "+f.getAbsolutePath());
pck.getNpm().remove("type"); // pck.getNpm().remove("type");
pck.getNpm().set("type", "Core"); // pck.getNpm().set("type", "Core");
FileOutputStream fso = ManagedFileAccess.outStream(f); // FileOutputStream fso = ManagedFileAccess.outStream(f);
try { // try {
pck.save(fso); // pck.save(fso);
} finally { // } finally {
fso.close(); // fso.close();
} // }
} // }
} catch (Exception e) { // } catch (Exception e) {
System.out.println("!!Error: "+e.getMessage()); // System.out.println("!!Error: "+e.getMessage());
} // }
} else if (f.getName().startsWith("hl7.fhir.r") && f.getName().endsWith(".examples.tgz")) { // } else if (f.getName().startsWith("hl7.fhir.r") && f.getName().endsWith(".examples.tgz")) {
try { // try {
FileInputStream fs = ManagedFileAccess.inStream(f); // FileInputStream fs = ManagedFileAccess.inStream(f);
NpmPackage pck = NpmPackage.fromPackage(fs); // NpmPackage pck = NpmPackage.fromPackage(fs);
if ("fhir.examples".equals(pck.getNpm().str("type"))) { // if ("fhir.examples".equals(pck.getNpm().str("type"))) {
System.out.println("!!change "+f.getAbsolutePath()); // System.out.println("!!change "+f.getAbsolutePath());
pck.getNpm().remove("type"); // pck.getNpm().remove("type");
pck.getNpm().set("type", "Examples"); // pck.getNpm().set("type", "Examples");
FileOutputStream fso = ManagedFileAccess.outStream(f); // FileOutputStream fso = ManagedFileAccess.outStream(f);
try { // try {
pck.save(fso); // pck.save(fso);
} finally { // } finally {
fso.close(); // fso.close();
} // }
} // }
} catch (Exception e) { // } catch (Exception e) {
System.out.println("!!Error: "+e.getMessage()); // System.out.println("!!Error: "+e.getMessage());
} // }
//
} // }
} // }
} // }
private void edit(String name) throws FileNotFoundException, IOException { private void edit(String name) throws FileNotFoundException, IOException {
File f = ManagedFileAccess.file(name); File f = ManagedFileAccess.file(name);
if (!f.exists()) if (!f.exists())
throw new Error("Unable to find "+f.getAbsolutePath()); throw new Error("Unable to find "+f.getAbsolutePath());
System.out.println("Loading Package "+f.getAbsolutePath());
NpmPackage pck = null; NpmPackage pck = null;
FileInputStream fs = ManagedFileAccess.inStream(f); FileInputStream fs = ManagedFileAccess.inStream(f);
try { try {
@ -95,15 +107,15 @@ public class PackageHacker {
System.out.println("Altering Package "+f.getAbsolutePath()); System.out.println("Altering Package "+f.getAbsolutePath());
System.out.println(nice(pck.getNpm())); System.out.println(nice(pck.getNpm()));
change(pck.getNpm()); if (change(pck.getNpm())) {
System.out.println("Revised Package"); System.out.println("Revised Package");
System.out.println("======================="); System.out.println("=======================");
System.out.println(nice(pck.getNpm())); System.out.println(nice(pck.getNpm()));
System.out.println("======================="); System.out.println("=======================");
System.out.print("save? y/n: "); // System.out.print("save? y/n: ");
int r = System.in.read(); // int r = System.in.read();
if (r == 'y') { // if (r == 'y') {
f.renameTo(ManagedFileAccess.file(Utilities.changeFileExt(name, ".tgz.bak"))); f.renameTo(ManagedFileAccess.file(Utilities.changeFileExt(name, ".tgz.bak")));
FileOutputStream fso = ManagedFileAccess.outStream(f); FileOutputStream fso = ManagedFileAccess.outStream(f);
try { try {
@ -111,7 +123,8 @@ public class PackageHacker {
} finally { } finally {
fso.close(); fso.close();
} }
} // }
}
} }
private void fixExampleContent(Map<String, byte[]> content) { private void fixExampleContent(Map<String, byte[]> content) {
@ -129,10 +142,13 @@ public class PackageHacker {
return JsonParser.compose(json, true); return JsonParser.compose(json, true);
} }
private void change(JsonObject npm) throws FileNotFoundException, IOException { private boolean change(JsonObject npm) throws FileNotFoundException, IOException {
// fixVersions(npm, ver); // fixVersions(npm, ver);
npm.remove("notForPublication"); if (npm.has("notForPublication")) {
npm.set("name", "hl7.fhir.us.vitals"); npm.remove("notForPublication");
return true;
}
return false;
} }
private void fixVersionInContent(Map<String, byte[]> content) { private void fixVersionInContent(Map<String, byte[]> content) {

View File

@ -560,7 +560,6 @@ public class HierarchicalTableGenerator {
} }
return b.toString(); return b.toString();
} }
} }
public class TableModel { public class TableModel {

View File

@ -21,7 +21,7 @@
<commons_compress_version>1.26.0</commons_compress_version> <commons_compress_version>1.26.0</commons_compress_version>
<guava_version>32.0.1-jre</guava_version> <guava_version>32.0.1-jre</guava_version>
<hapi_fhir_version>6.4.1</hapi_fhir_version> <hapi_fhir_version>6.4.1</hapi_fhir_version>
<validator_test_case_version>1.5.20</validator_test_case_version> <validator_test_case_version>1.5.21-SNAPSHOT</validator_test_case_version>
<jackson_version>2.17.0</jackson_version> <jackson_version>2.17.0</jackson_version>
<junit_jupiter_version>5.9.2</junit_jupiter_version> <junit_jupiter_version>5.9.2</junit_jupiter_version>
<junit_platform_launcher_version>1.8.2</junit_platform_launcher_version> <junit_platform_launcher_version>1.8.2</junit_platform_launcher_version>