fix structure map validation issues around type

This commit is contained in:
Grahame Grieve 2023-03-07 20:58:51 +11:00
parent bbc3cd5121
commit 6bf26255ab
5 changed files with 72 additions and 8 deletions

View File

@ -629,6 +629,26 @@ public class ToolingExtensions {
resource.getExtension().add(new Extension(uri).setValue(new UriType(value)));
}
public static void setUrlExtension(DomainResource resource, String uri, String value) {
if (Utilities.noString(value))
return;
Extension ext = getExtension(resource, uri);
if (ext != null)
ext.setValue(new UrlType(value));
else
resource.getExtension().add(new Extension(uri).setValue(new UrlType(value)));
}
public static void setUrlExtension(Element resource, String uri, String value) {
if (Utilities.noString(value))
return;
Extension ext = getExtension(resource, uri);
if (ext != null)
ext.setValue(new UrlType(value));
else
resource.getExtension().add(new Extension(uri).setValue(new UrlType(value)));
}
public static void setCodeExtension(DomainResource resource, String uri, String value) {
if (Utilities.noString(value))
return;

View File

@ -883,9 +883,9 @@ SM_TARGET_TRANSLATE_BINDING_VS_TARGET = The target variable refers to an unknown
SM_TARGET_TRANSLATE_BINDING_VSE_TARGET = There was an error expanding the target value set, so this concept map can''t be checked: ''{0}''
SM_TARGET_TRANSLATE_BINDING_TARGET_WRONG = The map produces one or more codes that the target value set does not include: {0}
CONCEPTMAP_GROUP_SOURCE_MISSING = No Source Code System, so the source codes cannot be checked
CONCEPTMAP_GROUP_SOURCE_UNKNOWN = Unknown Source Code System, so the source codes cannot be checked
CONCEPTMAP_GROUP_SOURCE_UNKNOWN = Unknown Source Code System {0}, so the source codes cannot be checked
CONCEPTMAP_GROUP_TARGET_MISSING = No Target Code System, so the source codes cannot be checked
CONCEPTMAP_GROUP_TARGET_UNKNOWN = Unknown Target Code System, so the source codes cannot be checked
CONCEPTMAP_GROUP_TARGET_UNKNOWN = Unknown Target Code System {0}, so the target codes cannot be checked
CONCEPTMAP_GROUP_SOURCE_CODE_INVALID = The source code ''{0}'' is not valid in the code system {1}
CONCEPTMAP_GROUP_SOURCE_DISPLAY_INVALID = The source display ''{0}'' is not valid. Possible codes {1}
CONCEPTMAP_GROUP_TARGET_CODE_INVALID =The target code ''{0}'' is not valid in the code system {1}

View File

@ -240,6 +240,31 @@ class UtilitiesTest {
Assertions.assertEquals("# %", Utilities.trimWS("# %"));
Assertions.assertEquals("", Utilities.trimWS("\u0009\n\u000B\u000C\r\u0020\u0085\u00A0\u1680\u2000\u2001\u2002\u2003\u2004\u2005\u2006\u2007\u2008\u2009\u200A\u2028\u2029\u202F\u205F\u3000"));
}
@Test
@DisplayName("regex tests")
void testRegex() {
Assertions.assertFalse("".matches(".+"));
Assertions.assertTrue(".".matches(".+"));
Assertions.assertTrue(" t ".matches(".+"));
Assertions.assertTrue(" ".matches(".+"));
Assertions.assertFalse("".matches("^.+$"));
Assertions.assertTrue(".".matches("^.+$"));
Assertions.assertTrue(" t ".matches("^.+$"));
Assertions.assertTrue(" ".matches("^.+$"));
Assertions.assertFalse("".matches("[\\s\\S]+"));
Assertions.assertTrue(".".matches("[\\s\\S]+"));
Assertions.assertTrue(" t ".matches("[\\s\\S]+"));
Assertions.assertTrue(" ".matches("[\\s\\S]+"));
Assertions.assertFalse("".matches("^[\\s\\S]+$"));
Assertions.assertTrue(".".matches("^[\\s\\S]+$"));
Assertions.assertTrue(" t ".matches("^[\\s\\S]+$"));
Assertions.assertTrue(" ".matches("^[\\s\\S]+$"));
Assertions.assertTrue("Example Requirements Set 2".matches("^[\\s\\S]+$"));
Assertions.assertTrue("\u0009\n\u000B\u000C\r\u0020\u0085\u00A0\u1680\u2000\u2001\u2002\u2003\u2004\u2005\u2006\u2007\u2008\u2009\u200A\u2028\u2029\u202F\u205F\u3000".matches("^[\\s\\S]+$"));
Assertions.assertFalse("\u0009\n\u000B\u000C\r\u0020\u0085\u00A0\u1680\u2000\u2001\u2002\u2003\u2004\u2005\u2006\u2007\u2008\u2009\u200A\u2028\u2029\u202F\u205F\u3000".matches(".+"));
Assertions.assertFalse("\u0009\n\u000B\u000C\r\u0020\u0085\u00A0\u1680\u2000\u2001\u2002\u2003\u2004\u2005\u2006\u2007\u2008\u2009\u200A\u2028\u2029\u202F\u205F\u3000".matches("^.+$"));
}
}

View File

@ -160,6 +160,14 @@ public class StructureMapValidator extends BaseValidator {
public String getWorkingType() {
if (type != null) {
if (ed != null) {
for (TypeRefComponent td : ed.getType()) {
StructureDefinition sd = context.fetchTypeDefinition(td.getWorkingCode());
if (sd != null && sd.getType().equals(type)) {
return td.getWorkingCode();
}
}
}
return type;
}
if (ed != null && ed.getType().size() == 1) {
@ -558,7 +566,8 @@ public class StructureMapValidator extends BaseValidator {
private boolean hasType(ElementDefinition ed, String type) {
for (TypeRefComponent td : ed.getType()) {
if (type.equals(td.getWorkingCode())) {
StructureDefinition sd = context.fetchTypeDefinition(td.getWorkingCode());
if (sd != null && type.equals(sd.getType())) {
return true;
}
}
@ -802,12 +811,12 @@ public class StructureMapValidator extends BaseValidator {
// * there's a default type group for the type of the source type
// otherwise, we can't know the target type.
if (ruleInfo.getDefVariable() != null && "create".equals(transform) && params.isEmpty()) {
if (ruleInfo.getDefVariable() != null && Utilities.existsInList(transform, "create", "copy") && params.isEmpty()) {
VariableDefn v = variables.getVariable(ruleInfo.getDefVariable(), SOURCE);
if (v != null && v.getEd() != null && (v.getEd().getType().size() == 1 || v.getType() != null)) {
List<Element> dependents = rule.getChildrenByName("dependent");
if (dependents.size() == 1 && StructureMapUtilities.DEF_GROUP_NAME.equals(dependents.get(0).getChildValue("name"))) {
String type = v.getType() != null ? v.getType() : v.getEd().getTypeFirstRep().getWorkingCode();
String type = v.getType() != null ? getTypeFromDefn(v.getEd(), v.getType()) : v.getEd().getTypeFirstRep().getWorkingCode();
// now, we look for a default group.
// todo: look in this source
// now look through the inputs
@ -830,6 +839,16 @@ public class StructureMapValidator extends BaseValidator {
return null;
}
private String getTypeFromDefn(ElementDefinition ed, String type) {
for (TypeRefComponent td : ed.getType()) {
StructureDefinition sd = context.fetchTypeDefinition(td.getWorkingCode());
if (sd != null && type.equals(sd.getType())) {
return td.getWorkingCode();
}
}
return type;
}
private boolean sameTypes(String type1, String type2) {
if (type1 == null || type2 == null) {
return false;
@ -844,11 +863,11 @@ public class StructureMapValidator extends BaseValidator {
}
private String getTypeForGroupInput(StructureMap map, StructureMapGroupComponent grp, StructureMapGroupInputComponent input) {
String type = input.getType();
StructureMapModelMode mode = input.getMode() == StructureMapInputMode.SOURCE ? StructureMapModelMode.SOURCE : StructureMapModelMode.TARGET;
if (input == null) {
return null;
}
String type = input.getType();
StructureMapModelMode mode = input.getMode() == StructureMapInputMode.SOURCE ? StructureMapModelMode.SOURCE : StructureMapModelMode.TARGET;
for (StructureMapStructureComponent st : map.getStructure()) {
if (type.equals(st.getAlias()) && mode == st.getMode()) {
return st.getUrl();

View File

@ -135,7 +135,7 @@ public class FHIRPathExpressionFixer {
return "-?(0|[1-9][0-9]{0,17})(\\.[0-9]{1,17})?([eE](0|[+\\-]?[1-9][0-9]{0,9}))?";
}
if (regex.equals("[ \\r\\n\\t\\S]+")) {
return "^[\\s\\r\\n\\t\\S]+$";
return "^[\\s\\S]+$";
}
return regex;
}