fix up R5 paths that are wrong in Extensions package

This commit is contained in:
Grahame Grieve 2023-03-29 15:05:50 +11:00
parent d82bec0f90
commit 25d7affba4
1 changed files with 9 additions and 36 deletions

View File

@ -4,6 +4,7 @@ import org.hl7.fhir.r5.context.IWorkerContext;
import org.hl7.fhir.r5.model.CanonicalResource;
import org.hl7.fhir.r5.model.ElementDefinition;
import org.hl7.fhir.r5.model.Enumerations.BindingStrength;
import org.hl7.fhir.r5.model.StructureDefinition.TypeDerivationRule;
import org.hl7.fhir.r5.model.StructureDefinition;
public class R5Hacker {
@ -16,50 +17,22 @@ public class R5Hacker {
private static void fixSD(StructureDefinition sd) {
if ("5.0.0-ballot".equals(sd.getVersion()) && "ElementDefinition".equals(sd.getType())) {
if (sd.getDerivation() == TypeDerivationRule.CONSTRAINT) {
for (ElementDefinition ed : sd.getDifferential().getElement()) {
hackEDR5BallotError(ed);
fix(ed);
}
for (ElementDefinition ed : sd.getSnapshot().getElement()) {
hackEDR5BallotError(ed);
fix(ed);
}
}
if ("5.0.0-ballot".equals(sd.getVersion()) && "Base".equals(sd.getType())) {
for (ElementDefinition ed : sd.getDifferential().getElement()) {
hackBaseR5BallotError(ed);
}
for (ElementDefinition ed : sd.getSnapshot().getElement()) {
hackBaseR5BallotError(ed);
}
}
if ("5.0.0-ballot".equals(sd.getVersion()) && "Bundle".equals(sd.getType())) {
for (ElementDefinition ed : sd.getDifferential().getElement()) {
hackBundleR5BallotError(ed);
}
for (ElementDefinition ed : sd.getSnapshot().getElement()) {
hackBundleR5BallotError(ed);
}
}
if ("5.0.0-ballot".equals(sd.getVersion()) && "http://hl7.org/fhir/StructureDefinition/elementdefinition-defaulttype".equals(sd.getUrl())) {
sd.getContextFirstRep().setExpression("ElementDefinition");
}
}
private static void hackBaseR5BallotError(ElementDefinition ed) {
ed.getConstraint().clear();
}
private static void hackBundleR5BallotError(ElementDefinition ed) {
if (ed.getPath().equals("Bundle.link.relation")) {
ToolingExtensions.removeExtension(ed.getBinding(), ToolingExtensions.EXT_BINDING_NAME);
}
}
private static void hackEDR5BallotError(ElementDefinition ed) {
if (ed.getPath().equals("ElementDefinition.type.code")) {
ed.getBinding().setStrength(BindingStrength.EXTENSIBLE);
}
private static void fix(ElementDefinition ed) {
if (ed.hasDefinition()) {
ed.setDefinition(ed.getDefinition().replace("http://hl7.org/fhir/5.0.0-snapshot3/", "http://hl7.org/fhir/R5/"));
}
}