Dotasek oe r4r5structuremapconversion (#775)
* Fix exception R5 to R4 of StructureMap #771 * Fix typo * Enhance conversion from r5 to r4 + add failing test for r4 to r5 * WIP Convert R4 variable to R5 parameter and try to get correct dataType * Clean up rough-work test * Move static methods to FHIRPathConstant class Co-authored-by: dotasek <david.otasek@smilecdr.com>
This commit is contained in:
parent
6328230f9f
commit
a7354f999e
|
@ -8,8 +8,11 @@ import org.hl7.fhir.convertors.conv40_50.datatypes40_50.metadata40_50.UsageConte
|
||||||
import org.hl7.fhir.convertors.conv40_50.datatypes40_50.primitive40_50.*;
|
import org.hl7.fhir.convertors.conv40_50.datatypes40_50.primitive40_50.*;
|
||||||
import org.hl7.fhir.exceptions.FHIRException;
|
import org.hl7.fhir.exceptions.FHIRException;
|
||||||
import org.hl7.fhir.r4.model.StructureMap.StructureMapGroupTypeMode;
|
import org.hl7.fhir.r4.model.StructureMap.StructureMapGroupTypeMode;
|
||||||
import org.hl7.fhir.r5.model.StringType;
|
import org.hl7.fhir.r4.utils.ToolingExtensions;
|
||||||
|
import org.hl7.fhir.r5.model.*;
|
||||||
import org.hl7.fhir.r5.model.StructureMap.StructureMapGroupRuleTargetParameterComponent;
|
import org.hl7.fhir.r5.model.StructureMap.StructureMapGroupRuleTargetParameterComponent;
|
||||||
|
import org.hl7.fhir.r5.utils.FHIRPathConstant;
|
||||||
|
import org.hl7.fhir.utilities.Utilities;
|
||||||
|
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
|
@ -752,6 +755,7 @@ public class StructureMap40_50 {
|
||||||
return tgt;
|
return tgt;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//DIRTY
|
||||||
public static org.hl7.fhir.r5.model.StructureMap.StructureMapGroupRuleTargetParameterComponent convertStructureMapGroupRuleTargetParameterComponent(org.hl7.fhir.r4.model.StructureMap.StructureMapGroupRuleTargetParameterComponent src) throws FHIRException {
|
public static org.hl7.fhir.r5.model.StructureMap.StructureMapGroupRuleTargetParameterComponent convertStructureMapGroupRuleTargetParameterComponent(org.hl7.fhir.r4.model.StructureMap.StructureMapGroupRuleTargetParameterComponent src) throws FHIRException {
|
||||||
if (src == null)
|
if (src == null)
|
||||||
return null;
|
return null;
|
||||||
|
@ -762,6 +766,7 @@ public class StructureMap40_50 {
|
||||||
return tgt;
|
return tgt;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public static org.hl7.fhir.r4.model.StructureMap.StructureMapGroupRuleTargetParameterComponent convertStructureMapGroupRuleTargetParameterComponent(org.hl7.fhir.r5.model.StructureMap.StructureMapGroupRuleTargetParameterComponent src) throws FHIRException {
|
public static org.hl7.fhir.r4.model.StructureMap.StructureMapGroupRuleTargetParameterComponent convertStructureMapGroupRuleTargetParameterComponent(org.hl7.fhir.r5.model.StructureMap.StructureMapGroupRuleTargetParameterComponent src) throws FHIRException {
|
||||||
if (src == null)
|
if (src == null)
|
||||||
return null;
|
return null;
|
||||||
|
@ -772,6 +777,7 @@ public class StructureMap40_50 {
|
||||||
return tgt;
|
return tgt;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//DIRTY
|
||||||
public static org.hl7.fhir.r5.model.StructureMap.StructureMapGroupRuleDependentComponent convertStructureMapGroupRuleDependentComponent(org.hl7.fhir.r4.model.StructureMap.StructureMapGroupRuleDependentComponent src) throws FHIRException {
|
public static org.hl7.fhir.r5.model.StructureMap.StructureMapGroupRuleDependentComponent convertStructureMapGroupRuleDependentComponent(org.hl7.fhir.r4.model.StructureMap.StructureMapGroupRuleDependentComponent src) throws FHIRException {
|
||||||
if (src == null)
|
if (src == null)
|
||||||
return null;
|
return null;
|
||||||
|
@ -779,10 +785,54 @@ public class StructureMap40_50 {
|
||||||
ConversionContext40_50.INSTANCE.getVersionConvertor_40_50().copyElement(src, tgt);
|
ConversionContext40_50.INSTANCE.getVersionConvertor_40_50().copyElement(src, tgt);
|
||||||
if (src.hasName())
|
if (src.hasName())
|
||||||
tgt.setNameElement(Id40_50.convertId(src.getNameElement()));
|
tgt.setNameElement(Id40_50.convertId(src.getNameElement()));
|
||||||
for (org.hl7.fhir.r4.model.StringType t : src.getVariable()) tgt.addParameter().setValue(String40_50.convertString(t));
|
for (org.hl7.fhir.r4.model.StringType t : src.getVariable()) tgt.addParameter().setValue(convertVariableStringToParameterDataType(t));
|
||||||
return tgt;
|
return tgt;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static org.hl7.fhir.r5.model.DataType convertVariableStringToParameterDataType(org.hl7.fhir.r4.model.StringType it) {
|
||||||
|
org.hl7.fhir.r4.model.Extension originalElementType = it.getExtensionByUrl(ToolingExtensions.EXT_ORIGINAL_ELEMENT_TYPE);
|
||||||
|
|
||||||
|
return originalElementType != null ? convertVariableStringToParameterDataType(it, originalElementType) : convertVariableStringToGuessedParameterDataType(it);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static org.hl7.fhir.r5.model.DataType convertVariableStringToParameterDataType(org.hl7.fhir.r4.model.StringType it, org.hl7.fhir.r4.model.Extension originalElementType) {
|
||||||
|
if (!(originalElementType.getValue() instanceof org.hl7.fhir.r4.model.UrlType)) {
|
||||||
|
throw new FHIRException("");
|
||||||
|
}
|
||||||
|
org.hl7.fhir.r4.model.UrlType url = (org.hl7.fhir.r4.model.UrlType)originalElementType.getValue();
|
||||||
|
switch (url.getValueAsString()) {
|
||||||
|
case "id" : return it.hasValue() ? new org.hl7.fhir.r5.model.IdType(it.getValueAsString()) : new org.hl7.fhir.r5.model.IdType();
|
||||||
|
case "string" : return it.hasValue() ? new org.hl7.fhir.r5.model.StringType(it.getValueAsString()) : new org.hl7.fhir.r5.model.StringType();
|
||||||
|
case "integer" : return it.hasValue() ? new org.hl7.fhir.r5.model.IntegerType(it.getValueAsString()) : new org.hl7.fhir.r5.model.IntegerType();
|
||||||
|
case "decimal" : return it.hasValue() ? new org.hl7.fhir.r5.model.DecimalType(it.getValueAsString()) : new org.hl7.fhir.r5.model.DecimalType();
|
||||||
|
case "boolean" : return it.hasValue() ? new org.hl7.fhir.r5.model.BooleanType(it.getValueAsString()) : new org.hl7.fhir.r5.model.BooleanType();
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static org.hl7.fhir.r5.model.DataType convertVariableStringToGuessedParameterDataType(org.hl7.fhir.r4.model.StringType it) {
|
||||||
|
final String stringValue = it.asStringValue();
|
||||||
|
if (!FHIRPathConstant.isFHIRPathConstant(stringValue)) {
|
||||||
|
return new IdType(stringValue);
|
||||||
|
} else if (FHIRPathConstant.isFHIRPathStringConstant(stringValue))
|
||||||
|
return new StringType(stringValue);
|
||||||
|
else {
|
||||||
|
return convertVariableStringToGuessedParameterConstantType(stringValue);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static DataType convertVariableStringToGuessedParameterConstantType(String stringValue) {
|
||||||
|
if (Utilities.isInteger(stringValue))
|
||||||
|
return new IntegerType(stringValue);
|
||||||
|
else if (Utilities.isDecimal(stringValue, false))
|
||||||
|
return new DecimalType(stringValue);
|
||||||
|
else if (Utilities.existsInList(stringValue, "true", "false"))
|
||||||
|
return new BooleanType(stringValue.equals("true"));
|
||||||
|
else
|
||||||
|
return new StringType(stringValue);
|
||||||
|
}
|
||||||
|
|
||||||
|
//DIRTY
|
||||||
public static org.hl7.fhir.r4.model.StructureMap.StructureMapGroupRuleDependentComponent convertStructureMapGroupRuleDependentComponent(org.hl7.fhir.r5.model.StructureMap.StructureMapGroupRuleDependentComponent src) throws FHIRException {
|
public static org.hl7.fhir.r4.model.StructureMap.StructureMapGroupRuleDependentComponent convertStructureMapGroupRuleDependentComponent(org.hl7.fhir.r5.model.StructureMap.StructureMapGroupRuleDependentComponent src) throws FHIRException {
|
||||||
if (src == null)
|
if (src == null)
|
||||||
return null;
|
return null;
|
||||||
|
@ -790,7 +840,32 @@ public class StructureMap40_50 {
|
||||||
ConversionContext40_50.INSTANCE.getVersionConvertor_40_50().copyElement(src, tgt);
|
ConversionContext40_50.INSTANCE.getVersionConvertor_40_50().copyElement(src, tgt);
|
||||||
if (src.hasName())
|
if (src.hasName())
|
||||||
tgt.setNameElement(Id40_50.convertId(src.getNameElement()));
|
tgt.setNameElement(Id40_50.convertId(src.getNameElement()));
|
||||||
for (StructureMapGroupRuleTargetParameterComponent t : src.getParameter()) tgt.getVariable().add(String40_50.convertString(t.getValueStringType()));
|
for (StructureMapGroupRuleTargetParameterComponent t : src.getParameter()) {
|
||||||
|
tgt.getVariable().add(convertStructureMapGroupRuleTargetParameterComponentToString(t));
|
||||||
|
}
|
||||||
|
return tgt;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static org.hl7.fhir.r4.model.StringType convertStructureMapGroupRuleTargetParameterComponentToString(StructureMapGroupRuleTargetParameterComponent src) {
|
||||||
|
org.hl7.fhir.r4.model.StringType tgt = new org.hl7.fhir.r4.model.StringType();
|
||||||
|
org.hl7.fhir.instance.model.api.IPrimitiveType primitiveType;
|
||||||
|
if (src.hasValueIdType()) {
|
||||||
|
primitiveType = src.getValueIdType();
|
||||||
|
} else if (src.hasValueStringType()) {
|
||||||
|
primitiveType = src.getValueStringType();
|
||||||
|
} else if (src.hasValueIntegerType()) {
|
||||||
|
primitiveType = src.getValueIntegerType();
|
||||||
|
} else if (src.hasValueDecimalType()) {
|
||||||
|
primitiveType = src.getValueDecimalType();
|
||||||
|
} else if (src.hasValueBooleanType()) {
|
||||||
|
primitiveType = src.getValueBooleanType();
|
||||||
|
} else {
|
||||||
|
throw new FHIRException("Unrecognized primitive type");
|
||||||
|
}
|
||||||
|
tgt.setValueAsString(primitiveType.getValueAsString());
|
||||||
|
ToolingExtensions.addUrlExtension(tgt, ToolingExtensions.EXT_ORIGINAL_ELEMENT_TYPE, primitiveType.fhirType());
|
||||||
|
|
||||||
|
ConversionContext40_50.INSTANCE.getVersionConvertor_40_50().copyElement(src, tgt);
|
||||||
return tgt;
|
return tgt;
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -1,14 +1,38 @@
|
||||||
package org.hl7.fhir.convertors;
|
package org.hl7.fhir.convertors;
|
||||||
|
|
||||||
import org.hl7.fhir.convertors.factory.VersionConvertorFactory_40_50;
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
import org.hl7.fhir.r4.formats.JsonParser;
|
import static org.junit.jupiter.api.Assertions.assertNull;
|
||||||
import org.hl7.fhir.r5.model.Resource;
|
import static org.mockito.Mockito.mock;
|
||||||
import org.junit.jupiter.api.Test;
|
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
|
|
||||||
class Convertor_Factory_40_50Test {
|
import org.hl7.fhir.convertors.factory.VersionConvertorFactory_40_50;
|
||||||
|
|
||||||
|
import org.hl7.fhir.r4.formats.JsonParser;
|
||||||
|
import org.hl7.fhir.r4.utils.ToolingExtensions;
|
||||||
|
import org.hl7.fhir.r5.context.SimpleWorkerContext;
|
||||||
|
|
||||||
|
import org.hl7.fhir.r5.model.*;
|
||||||
|
import org.hl7.fhir.r5.test.utils.TestingUtilities;
|
||||||
|
|
||||||
|
import org.hl7.fhir.r5.utils.structuremap.StructureMapUtilities;
|
||||||
|
import org.hl7.fhir.utilities.npm.FilesystemPackageCacheManager;
|
||||||
|
import org.hl7.fhir.utilities.npm.ToolsVersion;
|
||||||
|
import org.junit.jupiter.api.BeforeAll;
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
|
class Convertor_Factory_40_50Test {
|
||||||
|
|
||||||
|
static private SimpleWorkerContext context;
|
||||||
|
|
||||||
|
@BeforeAll
|
||||||
|
static public void setUp() throws Exception {
|
||||||
|
FilesystemPackageCacheManager pcm = new FilesystemPackageCacheManager(true, ToolsVersion.TOOLS_VERSION);
|
||||||
|
context = TestingUtilities.getWorkerContext(pcm.loadPackage("hl7.fhir.r4.core", "4.0.1"));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void convertResource() throws IOException {
|
void convertResource() throws IOException {
|
||||||
JsonParser r4parser = new JsonParser();
|
JsonParser r4parser = new JsonParser();
|
||||||
|
@ -28,4 +52,68 @@ class Convertor_Factory_40_50Test {
|
||||||
Resource account_r5 = VersionConvertorFactory_40_50.convertResource(bundle_r4);
|
Resource account_r5 = VersionConvertorFactory_40_50.convertResource(bundle_r4);
|
||||||
System.out.println(r5parser.composeString(account_r5));
|
System.out.println(r5parser.composeString(account_r5));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static final String CONTENT = "map \"http://example.org/qr2patgender\" = \"qr2patgender\"\n"+
|
||||||
|
"uses \"http://hl7.org/fhir/StructureDefinition/QuestionnaireResponse\" alias QuestionnaireResponse as source\n"+
|
||||||
|
"uses \"http://hl7.org/fhir/StructureDefinition/Patient\" alias Patient as target\n"+
|
||||||
|
"group QuestionnaireResponse(source src : QuestionnaireResponse, target tgt : Patient) {\n"+
|
||||||
|
" src.item as item -> tgt as patient then item(item, patient);\n"+
|
||||||
|
"}\n"+
|
||||||
|
"group item(source src, target tgt : Patient) {\n"+
|
||||||
|
" src.item as item where linkId.value in ('patient.sex') -> tgt.gender = (item.answer.valueString);\n"+
|
||||||
|
"}\n";
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testBidirectionalStructureMapConversion() {
|
||||||
|
|
||||||
|
StructureMapUtilities smu5 = new StructureMapUtilities(context, mock(org.hl7.fhir.r5.utils.structuremap.ITransformerServices.class));
|
||||||
|
org.hl7.fhir.r5.model.StructureMap mapR5 = smu5.parse(CONTENT, "map");
|
||||||
|
|
||||||
|
assertEquals("tgt", mapR5.getGroup().get(0).getRule().get(0).getTarget().get(0).getParameter().get(0).getValueIdType().getValue());
|
||||||
|
assertEquals("item.answer.valueString", mapR5.getGroup().get(1).getRule().get(0).getTarget().get(0).getParameter().get(0).getValueStringType().getValue());
|
||||||
|
assertEquals("item", mapR5.getGroup().get(0).getRule().get(0).getDependent().get(0).getParameter().get(0).getValueIdType().getValueAsString());
|
||||||
|
assertEquals("patient", mapR5.getGroup().get(0).getRule().get(0).getDependent().get(0).getParameter().get(1).getValueIdType().getValueAsString());
|
||||||
|
|
||||||
|
|
||||||
|
org.hl7.fhir.r4.model.StructureMap mapR4 = (org.hl7.fhir.r4.model.StructureMap) VersionConvertorFactory_40_50.convertResource(mapR5);
|
||||||
|
assertEquals("tgt", mapR4.getGroup().get(0).getRule().get(0).getTarget().get(0).getParameter().get(0).getValueIdType().getValue());
|
||||||
|
assertEquals("item.answer.valueString", mapR4.getGroup().get(1).getRule().get(0).getTarget().get(0).getParameter().get(0).getValueStringType().getValue());
|
||||||
|
assertEquals("item", mapR4.getGroup().get(0).getRule().get(0).getDependent().get(0).getVariable().get(0).getValueAsString());
|
||||||
|
assertEquals("patient", mapR4.getGroup().get(0).getRule().get(0).getDependent().get(0).getVariable().get(1).getValueAsString());
|
||||||
|
|
||||||
|
assertEquals("url", mapR4.getGroup().get(0).getRule().get(0).getDependent().get(0).getVariable().get(0).getExtensionByUrl(ToolingExtensions.EXT_ORIGINAL_ELEMENT_TYPE).getValue().fhirType());
|
||||||
|
assertEquals("url", mapR4.getGroup().get(0).getRule().get(0).getDependent().get(0).getVariable().get(1).getExtensionByUrl(ToolingExtensions.EXT_ORIGINAL_ELEMENT_TYPE).getValue().fhirType());
|
||||||
|
|
||||||
|
assertEquals("id", ((org.hl7.fhir.r4.model.UrlType)mapR4.getGroup().get(0).getRule().get(0).getDependent().get(0).getVariable().get(0).getExtensionByUrl(ToolingExtensions.EXT_ORIGINAL_ELEMENT_TYPE).getValue()).getValueAsString());
|
||||||
|
assertEquals("id", ((org.hl7.fhir.r4.model.UrlType)mapR4.getGroup().get(0).getRule().get(0).getDependent().get(0).getVariable().get(1).getExtensionByUrl(ToolingExtensions.EXT_ORIGINAL_ELEMENT_TYPE).getValue()).getValueAsString());
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
StructureMap mapR5Back = (StructureMap) VersionConvertorFactory_40_50.convertResource(mapR4);
|
||||||
|
assertEquals("tgt", mapR5Back.getGroup().get(0).getRule().get(0).getTarget().get(0).getParameter().get(0).getValueIdType().getValue());
|
||||||
|
assertEquals("item.answer.valueString", mapR5Back.getGroup().get(1).getRule().get(0).getTarget().get(0).getParameter().get(0).getValueStringType().getValue());
|
||||||
|
assertEquals("item", mapR5Back.getGroup().get(0).getRule().get(0).getDependent().get(0).getParameter().get(0).getValueIdType().getValueAsString());
|
||||||
|
assertEquals("patient", mapR5Back.getGroup().get(0).getRule().get(0).getDependent().get(0).getParameter().get(1).getValueIdType().getValueAsString());
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testR4ToR5StructureMapConversion() {
|
||||||
|
org.hl7.fhir.r4.utils.StructureMapUtilities smu5 = new org.hl7.fhir.r4.utils.StructureMapUtilities(mock(org.hl7.fhir.r4.context.SimpleWorkerContext.class), mock(org.hl7.fhir.r4.utils.StructureMapUtilities.ITransformerServices.class));
|
||||||
|
org.hl7.fhir.r4.model.StructureMap mapR4 = smu5.parse(CONTENT, "map");
|
||||||
|
|
||||||
|
assertEquals("tgt", mapR4.getGroup().get(0).getRule().get(0).getTarget().get(0).getParameter().get(0).getValueIdType().getValue());
|
||||||
|
assertEquals("item.answer.valueString", mapR4.getGroup().get(1).getRule().get(0).getTarget().get(0).getParameter().get(0).getValueStringType().getValue());
|
||||||
|
assertEquals("item", mapR4.getGroup().get(0).getRule().get(0).getDependent().get(0).getVariable().get(0).getValueAsString());
|
||||||
|
assertEquals("patient", mapR4.getGroup().get(0).getRule().get(0).getDependent().get(0).getVariable().get(1).getValueAsString());
|
||||||
|
|
||||||
|
StructureMap mapR5 = (StructureMap) VersionConvertorFactory_40_50.convertResource(mapR4);
|
||||||
|
assertEquals("tgt", mapR5.getGroup().get(0).getRule().get(0).getTarget().get(0).getParameter().get(0).getValueIdType().getValue());
|
||||||
|
assertEquals("item.answer.valueString", mapR5.getGroup().get(1).getRule().get(0).getTarget().get(0).getParameter().get(0).getValueStringType().getValue());
|
||||||
|
assertEquals("item", mapR5.getGroup().get(0).getRule().get(0).getDependent().get(0).getParameter().get(0).getValueIdType().getValueAsString());
|
||||||
|
assertEquals("patient", mapR5.getGroup().get(0).getRule().get(0).getDependent().get(0).getParameter().get(1).getValueIdType().getValueAsString());
|
||||||
|
|
||||||
|
assertNull(mapR5.getGroup().get(0).getRule().get(0).getDependent().get(0).getParameter().get(0).getExtensionByUrl(ToolingExtensions.EXT_ORIGINAL_ELEMENT_TYPE));
|
||||||
|
assertNull(mapR5.getGroup().get(0).getRule().get(0).getDependent().get(0).getParameter().get(1).getExtensionByUrl(ToolingExtensions.EXT_ORIGINAL_ELEMENT_TYPE));
|
||||||
|
}
|
||||||
}
|
}
|
|
@ -1,33 +1,33 @@
|
||||||
package org.hl7.fhir.r4.utils;
|
package org.hl7.fhir.r4.utils;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Copyright (c) 2011+, HL7, Inc.
|
Copyright (c) 2011+, HL7, Inc.
|
||||||
All rights reserved.
|
All rights reserved.
|
||||||
|
|
||||||
Redistribution and use in source and binary forms, with or without modification,
|
Redistribution and use in source and binary forms, with or without modification,
|
||||||
are permitted provided that the following conditions are met:
|
are permitted provided that the following conditions are met:
|
||||||
|
|
||||||
* Redistributions of source code must retain the above copyright notice, this
|
* Redistributions of source code must retain the above copyright notice, this
|
||||||
list of conditions and the following disclaimer.
|
list of conditions and the following disclaimer.
|
||||||
* Redistributions in binary form must reproduce the above copyright notice,
|
* Redistributions in binary form must reproduce the above copyright notice,
|
||||||
this list of conditions and the following disclaimer in the documentation
|
this list of conditions and the following disclaimer in the documentation
|
||||||
and/or other materials provided with the distribution.
|
and/or other materials provided with the distribution.
|
||||||
* Neither the name of HL7 nor the names of its contributors may be used to
|
* Neither the name of HL7 nor the names of its contributors may be used to
|
||||||
endorse or promote products derived from this software without specific
|
endorse or promote products derived from this software without specific
|
||||||
prior written permission.
|
prior written permission.
|
||||||
|
|
||||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||||
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||||
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
||||||
IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
|
IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
|
||||||
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
||||||
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||||
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||||
WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||||
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||||
POSSIBILITY OF SUCH DAMAGE.
|
POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -69,28 +69,11 @@ import java.util.Map;
|
||||||
import org.apache.commons.lang3.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
import org.fhir.ucum.Utilities;
|
import org.fhir.ucum.Utilities;
|
||||||
import org.hl7.fhir.exceptions.FHIRException;
|
import org.hl7.fhir.exceptions.FHIRException;
|
||||||
import org.hl7.fhir.r4.model.BooleanType;
|
import org.hl7.fhir.r4.model.*;
|
||||||
import org.hl7.fhir.r4.model.CanonicalType;
|
|
||||||
import org.hl7.fhir.r4.model.CodeSystem.ConceptDefinitionComponent;
|
import org.hl7.fhir.r4.model.CodeSystem.ConceptDefinitionComponent;
|
||||||
import org.hl7.fhir.r4.model.CodeType;
|
|
||||||
import org.hl7.fhir.r4.model.CodeableConcept;
|
|
||||||
import org.hl7.fhir.r4.model.Coding;
|
|
||||||
import org.hl7.fhir.r4.model.DomainResource;
|
|
||||||
import org.hl7.fhir.r4.model.Element;
|
|
||||||
import org.hl7.fhir.r4.model.ElementDefinition;
|
|
||||||
import org.hl7.fhir.r4.model.Extension;
|
|
||||||
import org.hl7.fhir.r4.model.ExtensionHelper;
|
|
||||||
import org.hl7.fhir.r4.model.Factory;
|
|
||||||
import org.hl7.fhir.r4.model.Identifier;
|
|
||||||
import org.hl7.fhir.r4.model.IntegerType;
|
|
||||||
import org.hl7.fhir.r4.model.MarkdownType;
|
|
||||||
import org.hl7.fhir.r4.model.OperationOutcome.OperationOutcomeIssueComponent;
|
import org.hl7.fhir.r4.model.OperationOutcome.OperationOutcomeIssueComponent;
|
||||||
import org.hl7.fhir.r4.model.PrimitiveType;
|
|
||||||
import org.hl7.fhir.r4.model.Questionnaire.QuestionnaireItemComponent;
|
import org.hl7.fhir.r4.model.Questionnaire.QuestionnaireItemComponent;
|
||||||
import org.hl7.fhir.r4.model.Questionnaire.QuestionnaireItemType;
|
import org.hl7.fhir.r4.model.Questionnaire.QuestionnaireItemType;
|
||||||
import org.hl7.fhir.r4.model.StringType;
|
|
||||||
import org.hl7.fhir.r4.model.Type;
|
|
||||||
import org.hl7.fhir.r4.model.UriType;
|
|
||||||
import org.hl7.fhir.r4.model.ValueSet.ConceptReferenceComponent;
|
import org.hl7.fhir.r4.model.ValueSet.ConceptReferenceComponent;
|
||||||
import org.hl7.fhir.r4.model.ValueSet.ConceptSetComponent;
|
import org.hl7.fhir.r4.model.ValueSet.ConceptSetComponent;
|
||||||
import org.hl7.fhir.utilities.StandardsStatus;
|
import org.hl7.fhir.utilities.StandardsStatus;
|
||||||
|
@ -174,6 +157,10 @@ public class ToolingExtensions {
|
||||||
public static final String EXT_XML_TYPE = "http://hl7.org/fhir/StructureDefinition/structuredefinition-xml-type";
|
public static final String EXT_XML_TYPE = "http://hl7.org/fhir/StructureDefinition/structuredefinition-xml-type";
|
||||||
public static final String EXT_JSON_TYPE = "http://hl7.org/fhir/StructureDefinition/structuredefinition-json-type";
|
public static final String EXT_JSON_TYPE = "http://hl7.org/fhir/StructureDefinition/structuredefinition-json-type";
|
||||||
|
|
||||||
|
public static final String EXT_ORIGINAL_ITEM_TYPE = "http://hl7.org/fhir/tools/StructureDefinition/original-item-type";
|
||||||
|
public static final String EXT_ORIGINAL_ELEMENT_TYPE = "http://hl7.org/fhir/tools/StructureDefinition/original-item-type";
|
||||||
|
|
||||||
|
|
||||||
// specific extension helpers
|
// specific extension helpers
|
||||||
|
|
||||||
public static Extension makeIssueSource(Source source) {
|
public static Extension makeIssueSource(Source source) {
|
||||||
|
@ -244,6 +231,14 @@ public class ToolingExtensions {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void addUrlExtension(Element e, String url, String value) {
|
||||||
|
Extension ex = getExtension(e, url);
|
||||||
|
if (ex != null)
|
||||||
|
ex.setValue(new UrlType(value));
|
||||||
|
else
|
||||||
|
e.getExtension().add(Factory.newExtension(url, new UrlType(value), true));
|
||||||
|
}
|
||||||
|
|
||||||
public static void addUriExtension(Element e, String url, String uri) {
|
public static void addUriExtension(Element e, String url, String uri) {
|
||||||
Extension ex = getExtension(e, url);
|
Extension ex = getExtension(e, url);
|
||||||
if (ex != null)
|
if (ex != null)
|
||||||
|
|
|
@ -4428,7 +4428,7 @@ public String toString() {
|
||||||
* Parameter value - variable or literal.
|
* Parameter value - variable or literal.
|
||||||
*/
|
*/
|
||||||
@Child(name = "value", type = {IdType.class, StringType.class, BooleanType.class, IntegerType.class, DecimalType.class, DateType.class, TimeType.class, DateTimeType.class}, order=1, min=1, max=1, modifier=false, summary=true)
|
@Child(name = "value", type = {IdType.class, StringType.class, BooleanType.class, IntegerType.class, DecimalType.class, DateType.class, TimeType.class, DateTimeType.class}, order=1, min=1, max=1, modifier=false, summary=true)
|
||||||
@Description(shortDefinition="Parameter value - variable or literal", formalDefinition="Parameter value - variable or literal." )
|
@Description(shortDefinition="-", formalDefinition="Parameter value - variable or literal." )
|
||||||
protected DataType value;
|
protected DataType value;
|
||||||
|
|
||||||
private static final long serialVersionUID = -1135414639L;
|
private static final long serialVersionUID = -1135414639L;
|
||||||
|
|
|
@ -7,34 +7,34 @@ import java.util.StringJoiner;
|
||||||
import org.apache.poi.xssf.model.Comments;
|
import org.apache.poi.xssf.model.Comments;
|
||||||
import org.hl7.fhir.exceptions.FHIRException;
|
import org.hl7.fhir.exceptions.FHIRException;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Copyright (c) 2011+, HL7, Inc.
|
Copyright (c) 2011+, HL7, Inc.
|
||||||
All rights reserved.
|
All rights reserved.
|
||||||
|
|
||||||
Redistribution and use in source and binary forms, with or without modification,
|
Redistribution and use in source and binary forms, with or without modification,
|
||||||
are permitted provided that the following conditions are met:
|
are permitted provided that the following conditions are met:
|
||||||
|
|
||||||
* Redistributions of source code must retain the above copyright notice, this
|
* Redistributions of source code must retain the above copyright notice, this
|
||||||
list of conditions and the following disclaimer.
|
list of conditions and the following disclaimer.
|
||||||
* Redistributions in binary form must reproduce the above copyright notice,
|
* Redistributions in binary form must reproduce the above copyright notice,
|
||||||
this list of conditions and the following disclaimer in the documentation
|
this list of conditions and the following disclaimer in the documentation
|
||||||
and/or other materials provided with the distribution.
|
and/or other materials provided with the distribution.
|
||||||
* Neither the name of HL7 nor the names of its contributors may be used to
|
* Neither the name of HL7 nor the names of its contributors may be used to
|
||||||
endorse or promote products derived from this software without specific
|
endorse or promote products derived from this software without specific
|
||||||
prior written permission.
|
prior written permission.
|
||||||
|
|
||||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||||
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||||
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
||||||
IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
|
IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
|
||||||
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
||||||
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||||
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||||
WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||||
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||||
POSSIBILITY OF SUCH DAMAGE.
|
POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -97,17 +97,15 @@ public class FHIRLexer {
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isConstant() {
|
public boolean isConstant() {
|
||||||
return !Utilities.noString(current) && ((current.charAt(0) == '\'' || current.charAt(0) == '"') || current.charAt(0) == '@' || current.charAt(0) == '%' ||
|
return FHIRPathConstant.isFHIRPathConstant(current);
|
||||||
current.charAt(0) == '-' || current.charAt(0) == '+' || (current.charAt(0) >= '0' && current.charAt(0) <= '9') ||
|
|
||||||
current.equals("true") || current.equals("false") || current.equals("{}"));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isFixedName() {
|
public boolean isFixedName() {
|
||||||
return current != null && (current.charAt(0) == '`');
|
return FHIRPathConstant.isFHIRPathFixedName(current);
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isStringConstant() {
|
public boolean isStringConstant() {
|
||||||
return current.charAt(0) == '\'' || current.charAt(0) == '"' || current.charAt(0) == '`';
|
return FHIRPathConstant.isFHIRPathStringConstant(current);
|
||||||
}
|
}
|
||||||
|
|
||||||
public String take() throws FHIRLexerException {
|
public String take() throws FHIRLexerException {
|
||||||
|
@ -201,7 +199,7 @@ public class FHIRLexer {
|
||||||
cursor++;
|
cursor++;
|
||||||
if (cursor < source.length() && (source.charAt(cursor) == '/')) {
|
if (cursor < source.length() && (source.charAt(cursor) == '/')) {
|
||||||
// this is en error - should already have been skipped
|
// this is en error - should already have been skipped
|
||||||
error("This shoudn't happen?");
|
error("This shouldn't happen?");
|
||||||
}
|
}
|
||||||
current = source.substring(currentStart, cursor);
|
current = source.substring(currentStart, cursor);
|
||||||
} else if (ch == '$') {
|
} else if (ch == '$') {
|
||||||
|
|
|
@ -0,0 +1,20 @@
|
||||||
|
package org.hl7.fhir.r5.utils;
|
||||||
|
|
||||||
|
import org.hl7.fhir.utilities.Utilities;
|
||||||
|
|
||||||
|
public class FHIRPathConstant {
|
||||||
|
|
||||||
|
public static boolean isFHIRPathConstant(String string) {
|
||||||
|
return !Utilities.noString(string) && ((string.charAt(0) == '\'' || string.charAt(0) == '"') || string.charAt(0) == '@' || string.charAt(0) == '%' ||
|
||||||
|
string.charAt(0) == '-' || string.charAt(0) == '+' || (string.charAt(0) >= '0' && string.charAt(0) <= '9') ||
|
||||||
|
string.equals("true") || string.equals("false") || string.equals("{}"));
|
||||||
|
}
|
||||||
|
|
||||||
|
public static boolean isFHIRPathFixedName(String string) {
|
||||||
|
return string != null && (string.charAt(0) == '`');
|
||||||
|
}
|
||||||
|
|
||||||
|
public static boolean isFHIRPathStringConstant(String string) {
|
||||||
|
return string.charAt(0) == '\'' || string.charAt(0) == '"' || string.charAt(0) == '`';
|
||||||
|
}
|
||||||
|
}
|
|
@ -104,7 +104,6 @@ public class Utilities {
|
||||||
return inf.pluralize(word);
|
return inf.pluralize(word);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public static boolean isInteger(String string) {
|
public static boolean isInteger(String string) {
|
||||||
if (isBlank(string)) {
|
if (isBlank(string)) {
|
||||||
return false;
|
return false;
|
||||||
|
|
Loading…
Reference in New Issue