Skip to content

Commit

Permalink
Merge pull request #1913 from hapifhir/2025-02-gg-fix-slice-processing
Browse files Browse the repository at this point in the history
2025 02 gg fix slice processing
  • Loading branch information
grahamegrieve authored Feb 26, 2025
2 parents 0bd2606 + 292f5e3 commit e862f23
Show file tree
Hide file tree
Showing 14 changed files with 335 additions and 41 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import org.hl7.fhir.r5.model.ElementDefinition.DiscriminatorType;
import org.hl7.fhir.r5.model.ElementDefinition.SlicingRules;
import org.hl7.fhir.r5.model.ElementDefinition.TypeRefComponent;
import org.hl7.fhir.r5.model.StringType;
import org.hl7.fhir.r5.model.StructureDefinition.StructureDefinitionContextComponent;
import org.hl7.fhir.r5.model.StructureDefinition.StructureDefinitionKind;
import org.hl7.fhir.r5.model.StructureDefinition.TypeDerivationRule;
Expand Down Expand Up @@ -132,9 +133,12 @@ public StructureDefinition convert(StructureDefinition sd, List<ConversionMessag
if (type == null) {
throw new DefinitionException("unable to find definition for "+tr.getCode());
}
log.add(new ConversionMessage("Replace the type "+tr.getCode()+" with a set of extensions for the content of the type", false));
log.add(new ConversionMessage("Replace the type "+tr.getCode()+" with a set of extensions for the content of the type along with the _datatype extension", false));
int insPoint = sd.getDifferential().getElement().indexOf(lastExt);
int offset = 1;

// a slice extension for _datatype
offset = addDatatypeSlice(sd, offset, insPoint, lastExt, tr.getCode());

// now, a slice extension for each thing in the data type differential
for (ElementDefinition ted : type.getDifferential().getElement()) {
Expand Down Expand Up @@ -209,6 +213,32 @@ public StructureDefinition convert(StructureDefinition sd, List<ConversionMessag
return sd;
}

private int addDatatypeSlice(StructureDefinition sd, int offset, int insPoint, ElementDefinition base, String type) {
ElementDefinition ned = new ElementDefinition(base.getPath());
ned.setSliceName("_datatype");
ned.setShort("DataType name '"+type+"' from "+VersionUtilities.getNameForVersion(sCtxt.getVersion()));
ned.setDefinition(ned.getShort());
ned.setMin(1);
ned.setMax("1");
ned.addType().setCode("Extension").addProfile("http://hl7.org/fhir/StructureDefinition/_datatype");
offset = addDiffElement(sd, insPoint, offset, ned);
// // set the extensions to 0
// ElementDefinition need = new ElementDefinition(base.getPath()+".extension");
// need.setMax("0");
// offset = addDiffElement(sd, insPoint, offset, need);
// // fix the url
// ned = new ElementDefinition(base.getPath()+".url");
// ned.setFixed(new UriType("http://hl7.org/fhir/StructureDefinition/_datatype"));
// offset = addDiffElement(sd, insPoint, offset, ned);
// set the value
ned = new ElementDefinition(base.getPath()+".value[x]");
ned.setMin(1);
offset = addDiffElement(sd, insPoint, offset, ned);
ned.addType().setCode("string");
ned.setFixed(new StringType(type));
return offset;
}

private int addDiffElement(StructureDefinition sd, int insPoint, int offset, ElementDefinition ned) {
sd.getDifferential().getElement().add(insPoint+offset, ned);
offset++;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1338,12 +1338,12 @@ else if (isDataType(combined))
nc = sdrRight.genElementNameCell(gen, combined.getRight().getDef(), "??", true, corePath, prefix, root, false, false, combined.getRight().getSrc(), typesRow, row, false, ext, used , ref, sName, null);
}
if (combined.hasLeft()) {
frame(sdrLeft.genElementCells(new RenderingStatus(), gen, combined.getLeft().getDef(), "??", true, corePath, prefix, root, false, false, combined.getLeft().getSrc(), typesRow, row, true, ext, used , ref, sName, nc, false, false, sdrLeft.getContext(), children.size() > 0, defPath, anchorPrefix, new ArrayList<ElementDefinition>(), null), leftColor);
frame(sdrLeft.genElementCells(new RenderingStatus(), gen, combined.getLeft().getDef(), "??", true, corePath, prefix, root, false, false, combined.getLeft().getSrc(), typesRow, row, true, ext, used , ref, nc, false, false, sdrLeft.getContext(), children.size() > 0, defPath, anchorPrefix, new ArrayList<ElementDefinition>(), null), leftColor);
} else {
frame(spacers(row, 4, gen), leftColor);
}
if (combined.hasRight()) {
frame(sdrRight.genElementCells(new RenderingStatus(), gen, combined.getRight().getDef(), "??", true, corePath, prefix, root, false, false, combined.getRight().getSrc(), typesRow, row, true, ext, used, ref, sName, nc, false, false, sdrRight.getContext(), children.size() > 0, defPath, anchorPrefix, new ArrayList<ElementDefinition>(), null), rightColor);
frame(sdrRight.genElementCells(new RenderingStatus(), gen, combined.getRight().getDef(), "??", true, corePath, prefix, root, false, false, combined.getRight().getSrc(), typesRow, row, true, ext, used, ref, nc, false, false, sdrRight.getContext(), children.size() > 0, defPath, anchorPrefix, new ArrayList<ElementDefinition>(), null), rightColor);
} else {
frame(spacers(row, 4, gen), rightColor);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1175,7 +1175,16 @@ private void processPathWithSlicedBaseDefault(ElementDefinition currentBase, Str
for (ElementDefinition baseItem : baseMatches)
if (baseItem.getSliceName().equals(diffItem.getSliceName()))
throw new DefinitionException(profileUtilities.getContext().formatMessage(I18nConstants.NAMED_ITEMS_ARE_OUT_OF_ORDER_IN_THE_SLICE));
outcome = profileUtilities.updateURLs(getUrl(), getWebUrl(), currentBase.copy(), true);

String id = diffItem.getId();
String lid = profileUtilities.tail(id);
ElementDefinition template = currentBase;
if (lid.contains("/")) {
profileUtilities.generateIds(getResult().getElement(), getUrl(), getSourceStructureDefinition().getType(), getSourceStructureDefinition());
String baseId = id.substring(0, id.length() - lid.length()) + lid.substring(0, lid.indexOf("/")); // this is wrong if there's more than one reslice (todo: one thing at a time)
template = profileUtilities.getById(getResult().getElement(), baseId);
}
outcome = profileUtilities.updateURLs(getUrl(), getWebUrl(), template.copy(), true);
// outcome = updateURLs(url, diffItem.copy());
outcome.setPath(profileUtilities.fixedPathDest(getContextPathTarget(), outcome.getPath(), getRedirector(), getContextPathSource()));
profileUtilities.updateFromBase(outcome, currentBase, getSourceStructureDefinition().getUrl());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7043,7 +7043,21 @@ private ConceptDefinitionComponent getDefinitionByCode(List<ConceptDefinitionCom
}
return null;
}


public boolean supplements(CodeSystem cs) {
if (!hasSupplements()) {
return false;
} else if (getSupplements().contains("|")) {
return getSupplements().equals(cs.getVersionedUrl());

} else {
return getSupplements().equals(cs.getUrl());
}
}

// end addition


}

Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,6 @@ public String buildSummary(ResourceWrapper res) throws UnsupportedEncodingExcept
if (profile == null)
return "unknown resource type " +res.fhirType();
else {
boolean firstElement = true;
boolean last = false;
List<ResourceWrapper> children = res.children();
ContextUtilities cu = res.getContextUtilities();
for (ResourceWrapper p : children) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -919,7 +919,7 @@ protected XhtmlNode renderResourceTechDetails(ResourceWrapper r, XhtmlNode x, St
ResourceWrapper lastUpdated = meta == null ? null : meta.child("lastUpdated");
ResourceWrapper source = meta == null ? null : meta.child("source");

if (lang != null || versionId != null || lastUpdated != null || ir != null || source != null) {
if (lang != null || versionId != null || lastUpdated != null || ir != null || source != null || meta != null) {
XhtmlNode div = x.div().style("display: inline-block").style("background-color: #d9e0e7").style("padding: 6px")
.style("margin: 4px").style("border: 1px solid #8da1b4")
.style("border-radius: 5px").style("line-height: 60%");
Expand Down Expand Up @@ -1507,4 +1507,4 @@ protected void addContained(RenderingStatus status, XhtmlNode x, List<ResourceWr
}
}

}
};
Original file line number Diff line number Diff line change
Expand Up @@ -384,7 +384,8 @@ public String display(StructureDefinition sd) {
public static final String RIM_MAPPING = "http://hl7.org/v3";
public static final String v2_MAPPING = "http://hl7.org/v2";
public static final String LOINC_MAPPING = "http://loinc.org";
public static final String SNOMED_MAPPING = "http://snomed.info";
public static final String SNOMED_MAPPING = "http://snomed.info";
private static final boolean PREFIX_SLICES = true;

private final boolean ADD_REFERENCE_TO_TABLE = true;

Expand Down Expand Up @@ -819,10 +820,15 @@ else if (element.hasSliceName())
}
UnusedTracker used = new UnusedTracker();
String ref = defPath == null ? null : defPath + element.getId();
String sName = tail(element.getPath());
if (element.hasSliceName()) {
sName = sName +":"+element.getSliceName();
}
String sName = null;
if (PREFIX_SLICES) {
sName = tail(element.getPath());
if (element.hasSliceName()) {
sName = sName + ":" + element.getSliceName();
}
} else {
sName = element.hasSliceName() ? element.getSliceName() : tail(element.getPath());
}
used.used = true;
if (logicalModel) {
if (element.hasRepresentation(PropertyRepresentation.XMLATTR)) {
Expand All @@ -843,7 +849,7 @@ else if (element.hasSliceName())
genElementObligations(gen, element, columns, row, corePath, profile);
break;
case SUMMARY:
genElementCells(status, gen, element, profileBaseFileName, snapshot, corePath, imagePath, root, logicalModel, allInvariants, profile, typesRow, row, hasDef, ext, used, ref, sName, nc, mustSupport, true, rc, children.size() > 0, defPath, anchorPrefix, all, res);
genElementCells(status, gen, element, profileBaseFileName, snapshot, corePath, imagePath, root, logicalModel, allInvariants, profile, typesRow, row, hasDef, ext, used, ref, nc, mustSupport, true, rc, children.size() > 0, defPath, anchorPrefix, all, res);
break;
}
if (element.hasSlicing()) {
Expand Down Expand Up @@ -1132,7 +1138,7 @@ public Cell genElementNameCell(HierarchicalTableGenerator gen, ElementDefinition

public List<Cell> genElementCells(RenderingStatus status, HierarchicalTableGenerator gen, ElementDefinition element, String profileBaseFileName, boolean snapshot, String corePath,
String imagePath, boolean root, boolean logicalModel, boolean allInvariants, StructureDefinition profile, Row typesRow, Row row, boolean hasDef,
boolean ext, UnusedTracker used, String ref, String sName, Cell nameCell, boolean mustSupport, boolean allowSubRows, RenderingContext rc, boolean walksIntoThis, String defPath, String anchorPrefix, List<ElementDefinition> inScopeElements, ResourceWrapper resource) throws IOException {
boolean ext, UnusedTracker used, String ref, Cell nameCell, boolean mustSupport, boolean allowSubRows, RenderingContext rc, boolean walksIntoThis, String defPath, String anchorPrefix, List<ElementDefinition> inScopeElements, ResourceWrapper resource) throws IOException {
List<Cell> res = new ArrayList<>();
Cell gc = gen.new Cell();
row.getCells().add(gc);
Expand Down Expand Up @@ -1178,7 +1184,7 @@ public List<Cell> genElementCells(RenderingStatus status, HierarchicalTableGener
res.add(generateDescription(status, gen, row, element, (ElementDefinition) element.getUserData(UserDataNames.SNAPSHOT_DERIVATION_POINTER), used.used, profile == null ? "" : profile.getUrl(), eurl, profile, corePath, imagePath, root, logicalModel, allInvariants, snapshot, mustSupport, allowSubRows, rc, inScopeElements, resource));
} else {
String name = element.hasSliceName() ? element.getSliceName() : urltail(eurl);
nameCell.getPieces().get(0).setText(name);
// disable 26-02-2025 GDG - this just makes things inconsistent, and why do this? nameCell.getPieces().get(0).setText(name);
// left.getPieces().get(0).setReference((String) extDefn.getExtensionStructure().getTag("filename"));
nameCell.getPieces().get(0).setHint((context.formatPhrase(RenderingContext.STRUC_DEF_EX_URL, extDefn.getUrl())));
res.add(genCardinality(gen, element, row, hasDef, used, extDefn.getElement()));
Expand Down
4 changes: 2 additions & 2 deletions org.hl7.fhir.utilities/src/main/resources/Messages.properties
Original file line number Diff line number Diff line change
Expand Up @@ -273,8 +273,8 @@ FHIRPATH_DECIMAL_ONLY = Error evaluating FHIRPath expression: The function {0} c
FHIRPATH_DISCRIMINATOR_BAD_NAME = Invalid function name {0}() in discriminator
FHIRPATH_DISCRIMINATOR_BAD_SYNTAX_CONST = Invalid expression syntax in discriminator (const)
FHIRPATH_DISCRIMINATOR_BAD_SYNTAX_GROUP = Invalid expression syntax in discriminator (group ''{0}'')
FHIRPATH_DISCRIMINATOR_CANT_FIND = Unable to resolve discriminator in definitions: {0} in profile {1} on element {2}, looking in profile {3}
FHIRPATH_DISCRIMINATOR_CANT_FIND_EXTENSION = Unable to resolve discriminator {0} on {2} found in the definitions because the extension {1} wasn''t found in the profile {3}
FHIRPATH_DISCRIMINATOR_CANT_FIND = Unable to resolve discriminator in definitions: ''{0}'' in profile ''{1}'' on element ''{2}'', looking in profile ''{3}''
FHIRPATH_DISCRIMINATOR_CANT_FIND_EXTENSION = Unable to resolve discriminator ''{0}'' on ''{2}'' found in the definitions because the extension ''{1}'' wasn''t found in the profile ''{3}''
FHIRPATH_DISCRIMINATOR_MULTIPLE_PROFILES_one =
FHIRPATH_DISCRIMINATOR_MULTIPLE_PROFILES_other = Error in discriminator at {1}: no children, {0} type profiles
FHIRPATH_DISCRIMINATOR_MULTIPLE_TYPES_one =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWIS
import org.hl7.fhir.utilities.Utilities;
import org.hl7.fhir.utilities.VersionUtilities;
import org.hl7.fhir.utilities.http.ManagedWebAccess;
import org.hl7.fhir.utilities.http.ManagedWebAccess.WebAccessPolicy;
import org.hl7.fhir.utilities.settings.FhirSettings;
import org.hl7.fhir.validation.cli.model.CliContext;
import org.hl7.fhir.validation.cli.services.ValidationService;
Expand Down Expand Up @@ -99,6 +100,8 @@ WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWIS
*/
public class ValidatorCli {

private static final String NO_WEB_ACCESS = "http.disabled";

public static final String HTTP_PROXY_HOST = "http.proxyHost";
public static final String HTTP_PROXY_PORT = "http.proxyPort";

Expand All @@ -112,7 +115,7 @@ public class ValidatorCli {
public static final String JAVA_USE_SYSTEM_PROXIES = "java.net.useSystemProxies";

private final static ValidationService validationService = new ValidationService();

protected ValidationService myValidationService;

final List<CliTask> cliTasks;
Expand Down Expand Up @@ -226,6 +229,9 @@ public static void main(String[] args) throws Exception {

private static void setJavaSystemProxyParamsFromParams(String[] args) {

if (Params.hasParam(args, NO_WEB_ACCESS)) {
ManagedWebAccess.setAccessPolicy(WebAccessPolicy.PROHIBITED);
}
setJavaSystemProxyHostFromParams(args, Params.PROXY, HTTP_PROXY_HOST, HTTP_PROXY_PORT);
setJavaSystemProxyHostFromParams(args, Params.HTTPS_PROXY, HTTPS_PROXY_HOST, HTTPS_PROXY_PORT);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ public void executeTask(ValidationService validationService, ValidationEngine va
}
IWorkerContext ctxt = validationEngine.getContext();
PackageReGenerator ep = new PackageReGenerator().setContext(ctxt).setScope(scope);
ep.setNpmId(cliContext.getPackageName());
for (String s : cliContext.getIgs()) {
ep.addPackage(s);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -346,7 +346,9 @@ else if (args[i].equals(HTML_OUTPUT)) {
cliContext.setMode(EngineMode.VERSION);
} else if (args[i].equals(PACKAGE_NAME)) {
cliContext.setPackageName(args[++i]);
cliContext.setMode(EngineMode.CODEGEN);
if (!hasParam(args, "-re-package")) {
cliContext.setMode(EngineMode.CODEGEN);
}
} else if (args[i].equals(TX_PACK)) {
cliContext.setMode(EngineMode.RE_PACKAGE);
String pn = args[++i];
Expand Down
Loading

0 comments on commit e862f23

Please sign in to comment.