Skip to content

Commit 61874d5

Browse files
authored
Merge branch 'hapifhir:master' into update_packages
2 parents 74a2be2 + d2087c5 commit 61874d5

File tree

39 files changed

+2649
-512
lines changed

39 files changed

+2649
-512
lines changed

hapi-fhir-base/src/main/java/ca/uhn/fhir/util/FhirPatchBuilder.java

Lines changed: 434 additions & 0 deletions
Large diffs are not rendered by default.

hapi-fhir-base/src/main/java/ca/uhn/fhir/util/FhirTerser.java

Lines changed: 60 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1475,33 +1475,27 @@ public boolean acceptUndeclaredExtension(
14751475
}
14761476

14771477
/**
1478-
* Clear all content on a resource
1478+
* Clear all content on an element
1479+
*
1480+
* @return Returns <code>true</code> if any content was actually cleared
1481+
* @since 8.6.0
14791482
*/
1480-
public void clear(IBaseResource theInput) {
1481-
visit(theInput, new IModelVisitor2() {
1482-
@Override
1483-
public boolean acceptElement(
1484-
IBase theElement,
1485-
List<IBase> theContainingElementPath,
1486-
List<BaseRuntimeChildDefinition> theChildDefinitionPath,
1487-
List<BaseRuntimeElementDefinition<?>> theElementDefinitionPath) {
1488-
if (theElement instanceof IPrimitiveType) {
1489-
((IPrimitiveType) theElement).setValueAsString(null);
1490-
}
1491-
return true;
1492-
}
1483+
public boolean clear(IBase theInput) {
1484+
ClearingModelVisitor visitor = new ClearingModelVisitor();
1485+
visit(theInput, visitor);
1486+
return visitor.myFoundContent;
1487+
}
14931488

1494-
@Override
1495-
public boolean acceptUndeclaredExtension(
1496-
IBaseExtension<?, ?> theNextExt,
1497-
List<IBase> theContainingElementPath,
1498-
List<BaseRuntimeChildDefinition> theChildDefinitionPath,
1499-
List<BaseRuntimeElementDefinition<?>> theElementDefinitionPath) {
1500-
theNextExt.setUrl(null);
1501-
theNextExt.setValue(null);
1502-
return true;
1503-
}
1504-
});
1489+
/**
1490+
* Clear all content on a resource.
1491+
*
1492+
* @return Returns <code>true</code> if any content was actually cleared
1493+
* @see #clear(IBase) This method is a synonym for {@link #clear(IBase)}, provided for historical reasons.
1494+
*/
1495+
public boolean clear(IBaseResource theInput) {
1496+
ClearingModelVisitor visitor = new ClearingModelVisitor();
1497+
visit(theInput, visitor);
1498+
return visitor.myFoundContent;
15051499
}
15061500

15071501
private void containResourcesForEncoding(ContainedResources theContained, IBaseResource theResource) {
@@ -2003,4 +1997,45 @@ public IIdType getPreviouslyContainedResourceId(IBaseResource theResource) {
20031997
return null;
20041998
}
20051999
}
2000+
2001+
private static class ClearingModelVisitor implements IModelVisitor2 {
2002+
2003+
private boolean myFoundContent;
2004+
2005+
@Override
2006+
public boolean acceptElement(
2007+
IBase theElement,
2008+
List<IBase> theContainingElementPath,
2009+
List<BaseRuntimeChildDefinition> theChildDefinitionPath,
2010+
List<BaseRuntimeElementDefinition<?>> theElementDefinitionPath) {
2011+
if (theElement instanceof IPrimitiveType<?> type) {
2012+
if (type.getValueAsString() != null) {
2013+
myFoundContent = true;
2014+
type.setValueAsString(null);
2015+
}
2016+
}
2017+
return true;
2018+
}
2019+
2020+
@Override
2021+
public boolean acceptUndeclaredExtension(
2022+
IBaseExtension<?, ?> theNextExt,
2023+
List<IBase> theContainingElementPath,
2024+
List<BaseRuntimeChildDefinition> theChildDefinitionPath,
2025+
List<BaseRuntimeElementDefinition<?>> theElementDefinitionPath) {
2026+
if (theNextExt.getUrl() != null) {
2027+
theNextExt.setUrl(null);
2028+
myFoundContent = true;
2029+
}
2030+
if (theNextExt.getValue() != null) {
2031+
myFoundContent = true;
2032+
theNextExt.setValue(null);
2033+
}
2034+
if (!theNextExt.getExtension().isEmpty()) {
2035+
theNextExt.getExtension().clear();
2036+
myFoundContent = true;
2037+
}
2038+
return true;
2039+
}
2040+
}
20062041
}

hapi-fhir-base/src/main/java/ca/uhn/fhir/util/ParametersUtil.java

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,19 @@ public static Optional<Integer> getParameterPartValueAsInteger(
234234
.map(t -> (Integer) t);
235235
}
236236

237+
/**
238+
* @since 8.6.0
239+
*/
240+
public static Optional<Boolean> getParameterPartValueAsBoolean(
241+
FhirContext theCtx, IBase theParameter, String theParameterName) {
242+
return getParameterPartValue(theCtx, theParameter, theParameterName)
243+
.filter(t -> IPrimitiveType.class.isAssignableFrom(t.getClass()))
244+
.map(t -> (IPrimitiveType<?>) t)
245+
.map(IPrimitiveType::getValue)
246+
.filter(t -> Boolean.class.isAssignableFrom(t.getClass()))
247+
.map(t -> (Boolean) t);
248+
}
249+
237250
private static <T> List<T> extractNamedParameterValues(
238251
FhirContext theCtx,
239252
IBaseParameters theParameters,
@@ -481,8 +494,11 @@ public static void addPartUrl(FhirContext theContext, IBase theParameter, String
481494
addPart(theContext, theParameter, theName, value);
482495
}
483496

484-
public static void addPartBoolean(FhirContext theContext, IBase theParameter, String theName, Boolean theValue) {
485-
addPart(theContext, theParameter, theName, theContext.newPrimitiveBoolean(theValue));
497+
/**
498+
* @return Returns the added part
499+
*/
500+
public static IBase addPartBoolean(FhirContext theContext, IBase theParameter, String theName, Boolean theValue) {
501+
return addPart(theContext, theParameter, theName, theContext.newPrimitiveBoolean(theValue));
486502
}
487503

488504
public static void addPartDecimal(FhirContext theContext, IBase theParameter, String theName, Double theValue) {

hapi-fhir-base/src/main/java/ca/uhn/fhir/util/UrlUtil.java

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -33,12 +33,12 @@
3333
import org.apache.commons.lang3.StringUtils;
3434
import org.hl7.fhir.instance.model.api.IPrimitiveType;
3535

36-
import java.io.UnsupportedEncodingException;
3736
import java.net.MalformedURLException;
3837
import java.net.URI;
3938
import java.net.URISyntaxException;
4039
import java.net.URL;
4140
import java.net.URLDecoder;
41+
import java.nio.charset.StandardCharsets;
4242
import java.nio.file.Path;
4343
import java.nio.file.Paths;
4444
import java.util.ArrayList;
@@ -559,13 +559,7 @@ public static String unescape(String theString) {
559559
for (int i = 0; i < theString.length(); i++) {
560560
char nextChar = theString.charAt(i);
561561
if (nextChar == '%' || (nextChar == '+' && shouldEscapePlus)) {
562-
try {
563-
// Yes it would be nice to not use a string "UTF-8" but the equivalent
564-
// method that takes Charset is JDK10+ only... sigh....
565-
return URLDecoder.decode(theString, "UTF-8");
566-
} catch (UnsupportedEncodingException e) {
567-
throw new Error(Msg.code(1743) + "UTF-8 not supported, this shouldn't happen", e);
568-
}
562+
return URLDecoder.decode(theString, StandardCharsets.UTF_8);
569563
}
570564
}
571565
return theString;

hapi-fhir-converter/src/main/java/ca/uhn/hapi/converters/canonical/VersionCanonicalizer.java

Lines changed: 40 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -132,8 +132,6 @@ public VersionCanonicalizer(FhirContext theTargetContext) {
132132
}
133133
}
134134

135-
@SuppressWarnings({"EnhancedSwitchMigration"})
136-
137135
/**
138136
* Canonical version: R5
139137
*/
@@ -315,6 +313,10 @@ public SubscriptionTopic subscriptionTopicToCanonical(IBaseResource theResource)
315313
return SubscriptionTopicCanonicalizer.canonicalizeTopic(myContext, theResource);
316314
}
317315

316+
public IBaseResource conceptMapFromCanonical(ConceptMap theConceptMap) {
317+
return myStrategy.conceptMapFromCanonical(theConceptMap);
318+
}
319+
318320
private interface IStrategy {
319321

320322
CapabilityStatement capabilityStatementToCanonical(IBaseResource theCapabilityStatement);
@@ -333,6 +335,8 @@ private interface IStrategy {
333335

334336
ConceptMap conceptMapToCanonical(IBaseResource theConceptMap);
335337

338+
IBaseResource conceptMapFromCanonical(ConceptMap theConceptMap);
339+
336340
SearchParameter searchParameterToCanonical(IBaseResource theSearchParameter);
337341

338342
IBaseParameters parametersFromCanonical(Parameters theParameters);
@@ -465,6 +469,13 @@ public ConceptMap conceptMapToCanonical(IBaseResource theConceptMap) {
465469
return (ConceptMap) VersionConvertorFactory_10_40.convertResource(reencoded, ADVISOR_10_40);
466470
}
467471

472+
@Override
473+
public IBaseResource conceptMapFromCanonical(ConceptMap theConceptMap) {
474+
Resource codeSystemDstu2Hl7Org =
475+
VersionConvertorFactory_10_40.convertResource(theConceptMap, ADVISOR_10_40);
476+
return reencodeFromHl7Org(codeSystemDstu2Hl7Org);
477+
}
478+
468479
@Override
469480
public SearchParameter searchParameterToCanonical(IBaseResource theSearchParameter) {
470481
org.hl7.fhir.dstu2.model.SearchParameter reencoded =
@@ -620,6 +631,11 @@ public ConceptMap conceptMapToCanonical(IBaseResource theConceptMap) {
620631
(org.hl7.fhir.dstu2016may.model.Resource) theConceptMap, ADVISOR_14_40);
621632
}
622633

634+
@Override
635+
public IBaseResource conceptMapFromCanonical(ConceptMap theConceptMap) {
636+
return VersionConvertorFactory_14_40.convertResource(theConceptMap, ADVISOR_14_40);
637+
}
638+
623639
@Override
624640
public SearchParameter searchParameterToCanonical(IBaseResource theSearchParameter) {
625641
return (SearchParameter) VersionConvertorFactory_14_50.convertResource(
@@ -729,6 +745,11 @@ public ConceptMap conceptMapToCanonical(IBaseResource theConceptMap) {
729745
(org.hl7.fhir.dstu3.model.Resource) theConceptMap, ADVISOR_30_40);
730746
}
731747

748+
@Override
749+
public IBaseResource conceptMapFromCanonical(ConceptMap theConceptMap) {
750+
return VersionConvertorFactory_30_40.convertResource(theConceptMap, ADVISOR_30_40);
751+
}
752+
732753
@Override
733754
public SearchParameter searchParameterToCanonical(IBaseResource theSearchParameter) {
734755
return (SearchParameter) VersionConvertorFactory_30_50.convertResource(
@@ -832,6 +853,11 @@ public ConceptMap conceptMapToCanonical(IBaseResource theConceptMap) {
832853
return (ConceptMap) theConceptMap;
833854
}
834855

856+
@Override
857+
public IBaseResource conceptMapFromCanonical(ConceptMap theConceptMap) {
858+
return theConceptMap;
859+
}
860+
835861
@Override
836862
public SearchParameter searchParameterToCanonical(IBaseResource theSearchParameter) {
837863
return (SearchParameter) VersionConvertorFactory_40_50.convertResource(
@@ -957,6 +983,13 @@ public ConceptMap conceptMapToCanonical(IBaseResource theConceptMap) {
957983
return (ConceptMap) VersionConvertorFactory_40_50.convertResource(conceptMapR5, ADVISOR_40_50);
958984
}
959985

986+
@Override
987+
public IBaseResource conceptMapFromCanonical(ConceptMap theConceptMap) {
988+
org.hl7.fhir.r5.model.ConceptMap conceptMapR5 = (org.hl7.fhir.r5.model.ConceptMap)
989+
VersionConvertorFactory_40_50.convertResource(theConceptMap, ADVISOR_40_50);
990+
return VersionConvertorFactory_43_50.convertResource(conceptMapR5, ADVISOR_43_50);
991+
}
992+
960993
@Override
961994
public SearchParameter searchParameterToCanonical(IBaseResource theSearchParameter) {
962995
return (SearchParameter) VersionConvertorFactory_43_50.convertResource(
@@ -1069,6 +1102,11 @@ public ConceptMap conceptMapToCanonical(IBaseResource theConceptMap) {
10691102
(org.hl7.fhir.r5.model.ConceptMap) theConceptMap, ADVISOR_40_50);
10701103
}
10711104

1105+
@Override
1106+
public IBaseResource conceptMapFromCanonical(ConceptMap theConceptMap) {
1107+
return VersionConvertorFactory_40_50.convertResource(theConceptMap, ADVISOR_40_50);
1108+
}
1109+
10721110
@Override
10731111
public SearchParameter searchParameterToCanonical(IBaseResource theSearchParameter) {
10741112
return (SearchParameter) theSearchParameter;
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
type: fix
3+
issue: 7210
4+
jira: SMILE-9866
5+
title: "Previously, bulk exports were not using the resource whitelist nor the search parameter
6+
enable/disable patterns. This has been fixed."
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
type: add
3+
issue: 7275
4+
title: "A new utility class called FhirPatchBuilder has been added. This class can be used to
5+
programmatically generate FHIR Patch documents. See [FHIR Patch](https://smilecdr.com/docs/fhir_standard/fhir_patch.html) for
6+
examples on how to use this class."
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
---
2+
type: fix
3+
issue: 7275
4+
title: "A number of new test cases and fixes have been added to the HAPI FHIR FHIRPath Patch engine:
5+
<ul>
6+
<li>
7+
Replace and Delete operations containing FHIRPath expressions where the final element was
8+
a filter (such as <code>Observation.code.coding.where(system='http://loinc.org')</code>)
9+
would fail if the system URL contained a dot character.
10+
</li>
11+
<li>
12+
Insert operations can now add an extension to an anonymous element, as shown in the
13+
FHIR specification
14+
<a href=\"https://hl7.org/fhir/fhirpatch.html#extension\">Extension Example</a>.
15+
</li>
16+
</ul>"
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
type: add
3+
issue: 7275
4+
title: "A HAPI FHIR extension to the FHIR Patch specification has been added, which permits the
5+
**delete** operation to find and delete multiple elements matching a single FHIRPath expression.
6+
See [Deleting Multiple Elements](https://smilecdr.com/docs/fhir_standard/fhir_patch.html#multi-delete) for
7+
examples on how to use this feature."
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
type: add
3+
issue: 7276
4+
title: "Two new operations have been added to the JPA server called `ConceptMap/$hapi.fhir.add-mapping`
5+
and `ConceptMap/$hapi.fhir.remove-mapping`. These operations can be used to add or remove individual
6+
entries within a ConceptMap resource."

0 commit comments

Comments
 (0)