fix issue with validating fixed values for primitive elements
This commit is contained in:
parent
4e4885dc7d
commit
032b81a38e
|
@ -1,6 +1,13 @@
|
|||
Version Conversion:
|
||||
* add test for Observation conversion from 10 to 40
|
||||
* add procedures conversion form dstu2 to r4
|
||||
* add medication conversion from dstu2 to r4
|
||||
* add copy of extension field for Enumeration fieldtype by Resource.copy
|
||||
* minor fixes in code generators for R4B
|
||||
* add default value to Medication Request during conversion from dstu2 to r4
|
||||
* fix R2B/R5 ElementDefinition.type.code conversion
|
||||
|
||||
Other:
|
||||
* minor fixes in code generators for R4B
|
||||
* Fix null pointer exception in validator validating language codes
|
||||
* fix issue with validating fixed values for primitive elements
|
||||
* add utility to unzip file
|
||||
|
|
|
@ -50,6 +50,7 @@ import java.nio.channels.FileChannel;
|
|||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
import java.nio.file.StandardCopyOption;
|
||||
import java.time.Duration;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
|
@ -60,6 +61,8 @@ import java.util.List;
|
|||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.zip.ZipEntry;
|
||||
import java.util.zip.ZipInputStream;
|
||||
|
||||
import static org.apache.commons.lang3.StringUtils.isBlank;
|
||||
|
||||
|
@ -1398,5 +1401,49 @@ public class Utilities {
|
|||
return res;
|
||||
}
|
||||
|
||||
public static void unzip(InputStream zip, Path target) throws IOException {
|
||||
try (ZipInputStream zis = new ZipInputStream(zip)) {
|
||||
ZipEntry zipEntry = zis.getNextEntry();
|
||||
while (zipEntry != null) {
|
||||
boolean isDirectory = false;
|
||||
if (zipEntry.getName().endsWith("/") || zipEntry.getName().endsWith("\\")) {
|
||||
isDirectory = true;
|
||||
}
|
||||
Path newPath = zipSlipProtect(zipEntry, target);
|
||||
if (isDirectory) {
|
||||
Files.createDirectories(newPath);
|
||||
} else {
|
||||
if (newPath.getParent() != null) {
|
||||
if (Files.notExists(newPath.getParent())) {
|
||||
Files.createDirectories(newPath.getParent());
|
||||
}
|
||||
}
|
||||
Files.copy(zis, newPath, StandardCopyOption.REPLACE_EXISTING);
|
||||
}
|
||||
zipEntry = zis.getNextEntry();
|
||||
}
|
||||
zis.closeEntry();
|
||||
}
|
||||
}
|
||||
|
||||
private static Path zipSlipProtect(ZipEntry zipEntry, Path targetDir)
|
||||
throws IOException {
|
||||
|
||||
// test zip slip vulnerability
|
||||
// Path targetDirResolved = targetDir.resolve("../../" + zipEntry.getName());
|
||||
|
||||
Path targetDirResolved = targetDir.resolve(zipEntry.getName());
|
||||
|
||||
// make sure normalized file still has targetDir as its prefix
|
||||
// else throws exception
|
||||
Path normalizePath = targetDirResolved.normalize();
|
||||
if (!normalizePath.startsWith(targetDir)) {
|
||||
throw new IOException("Bad zip entry: " + zipEntry.getName());
|
||||
}
|
||||
|
||||
return normalizePath;
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
|
@ -125,7 +125,16 @@ public class StructureDefinitionValidator extends BaseValidator {
|
|||
if (hasMustSupportExtension(type)) {
|
||||
typeMustSupport = true;
|
||||
}
|
||||
typeCodes.add(type.getChildValue("code"));
|
||||
String tc = type.getChildValue("code");
|
||||
if (type.hasExtension("http://hl7.org/fhir/StructureDefinition/structuredefinition-fhir-type")) {
|
||||
tc = type.getExtensionValue("http://hl7.org/fhir/StructureDefinition/structuredefinition-fhir-type").primitiveValue();
|
||||
}
|
||||
if (Utilities.noString(tc) && type.hasChild("code")) {
|
||||
if (type.getNamedChild("code").hasExtension("http://hl7.org/fhir/StructureDefinition/structuredefinition-json-type")) {
|
||||
tc = "*";
|
||||
}
|
||||
}
|
||||
typeCodes.add(tc);
|
||||
// check the stated profile - must be a constraint on the type
|
||||
if (snapshot || sd != null) {
|
||||
validateElementType(errors, type, stack.push(type, -1, null, null), sd, element.getChildValue("path"));
|
||||
|
@ -148,27 +157,19 @@ public class StructureDefinitionValidator extends BaseValidator {
|
|||
}
|
||||
// in a snapshot, we validate that fixedValue, pattern, and defaultValue, if present, are all of the right type
|
||||
if (snapshot && element.getIdBase().contains(".")) {
|
||||
if (rule(errors, IssueType.EXCEPTION, stack.getLiteralPath(), !typeCodes.isEmpty() || element.hasChild("contentReference"), I18nConstants.SD_NO_TYPES_OR_CONTENTREF, element.getIdBase())) {
|
||||
/*
|
||||
TODO Grahame, this is breaking the ig publisher for implementers
|
||||
https://chat.fhir.org/#narrow/stream/215610-shorthand/topic/The.20element.20Extension.2Eurl.20has.20a.20fixed.20of.20type.20uri
|
||||
https://chat.fhir.org/#narrow/stream/179252-IG-creation/topic/BUG.3A.20The.20element.20Extension.2Eurl.20has.20a.20fixed.20of.20type.20uri
|
||||
https://github.com/HL7/fhir-ig-publisher/issues/240
|
||||
This was brought up to Wayne, so I'm commenting it out for now. When you get back we can discuss how to
|
||||
put the changes back in.
|
||||
*/
|
||||
// Element v = element.getNamedChild("defaultValue");
|
||||
// if (v != null) {
|
||||
// rule(errors, IssueType.EXCEPTION, stack.push(v, -1, null, null).getLiteralPath(), typeCodes.contains(v.fhirType()), I18nConstants.SD_VALUE_TYPE_IILEGAL, element.getIdBase(), "defaultValue", v.fhirType(), typeCodes);
|
||||
// }
|
||||
// v = element.getNamedChild("fixed");
|
||||
// if (v != null) {
|
||||
// rule(errors, IssueType.EXCEPTION, stack.push(v, -1, null, null).getLiteralPath(), typeCodes.contains(v.fhirType()), I18nConstants.SD_VALUE_TYPE_IILEGAL, element.getIdBase(), "fixed", v.fhirType(), typeCodes);
|
||||
// }
|
||||
// v = element.getNamedChild("pattern");
|
||||
// if (v != null) {
|
||||
// rule(errors, IssueType.EXCEPTION, stack.push(v, -1, null, null).getLiteralPath(), typeCodes.contains(v.fhirType()), I18nConstants.SD_VALUE_TYPE_IILEGAL, element.getIdBase(), "pattern", v.fhirType(), typeCodes);
|
||||
// }
|
||||
if (rule(errors, IssueType.EXCEPTION, stack.getLiteralPath(), !typeCodes.isEmpty() || element.hasChild("contentReference"), I18nConstants.SD_NO_TYPES_OR_CONTENTREF, element.getIdBase())) {
|
||||
Element v = element.getNamedChild("defaultValue");
|
||||
if (v != null) {
|
||||
rule(errors, IssueType.EXCEPTION, stack.push(v, -1, null, null).getLiteralPath(), typeCodes.contains(v.fhirType()), I18nConstants.SD_VALUE_TYPE_IILEGAL, element.getIdBase(), "defaultValue", v.fhirType(), typeCodes);
|
||||
}
|
||||
v = element.getNamedChild("fixed");
|
||||
if (v != null) {
|
||||
rule(errors, IssueType.EXCEPTION, stack.push(v, -1, null, null).getLiteralPath(), typeCodes.contains(v.fhirType()), I18nConstants.SD_VALUE_TYPE_IILEGAL, element.getIdBase(), "fixed", v.fhirType(), typeCodes);
|
||||
}
|
||||
v = element.getNamedChild("pattern");
|
||||
if (v != null) {
|
||||
rule(errors, IssueType.EXCEPTION, stack.push(v, -1, null, null).getLiteralPath(), typeCodes.contains(v.fhirType()), I18nConstants.SD_VALUE_TYPE_IILEGAL, element.getIdBase(), "pattern", v.fhirType(), typeCodes);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue