Skip to content

Commit d656e75

Browse files
Issue #2834 - address review comments
Signed-off-by: Mike Schroeder <mschroed@us.ibm.com>
1 parent 07d8917 commit d656e75

File tree

3 files changed

+40
-39
lines changed

3 files changed

+40
-39
lines changed

docs/src/pages/guides/FHIRServerUsersGuide.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ layout: post
33
title: IBM FHIR Server User's Guide
44
description: IBM FHIR Server User's Guide
55
Copyright: years 2017, 2021
6-
lastupdated: "2021-10-20"
6+
lastupdated: "2021-10-21"
77
permalink: /FHIRServerUsersGuide/
88
---
99

@@ -801,10 +801,10 @@ For example, you can configure a set of FHIRPath Constraints to run for resource
801801

802802
The following configuration parameters can be used to specify rules relating to the set of profiles that are specified in a resource's `meta.profile` element:
803803
* `fhirServer/resources/<resourceType>/profiles/atLeastOne` - this configuration parameter is used to specify a set of profiles, at least one of which a resource must claim conformance to and be successfully validated against in order to be persisted to the FHIR server.
804-
* `fhirServer/resources/<resourceType>/profiles/notAllowed`- this configuration parameter is used to specify a set of profiles to which a resource is *not allowed* to claim conformance and be successfully validated against in order to be persisted to the FHIR server.
804+
* `fhirServer/resources/<resourceType>/profiles/notAllowed`- this configuration parameter is used to specify a set of profiles to which a resource is *not allowed* to claim conformance.
805805
* `fhirServer/resources/<resourceType>/profiles/allowUnknown`- this configuration parameter is used to indicate whether a warning or an error is issued if a profile specified in a resource's `meta.profile`element is not loaded in the FHIR server. The default value is `true`, meaning unknown profiles are allowed to be specified. The profile will be ignored and just a warning will be returned. If set to `false`, this means unknown profiles are not allowed to be specified. An error will be returned and resource validation will fail.
806806

807-
Before calling the FHIR validator to validate a resource against the set of profiles specified in its `meta.profile` element that it is claiming conformance to, the following pre-validation will be done for that set of profiles based on the configuration parameters listed above:
807+
Before calling the FHIR validator to validate a resource against the set of profiles specified in its `meta.profile` element that it is claiming conformance to, the following pre-validation will be performed for that set of profiles based on the configuration parameters listed above:
808808
1. If the `fhirServer/resources/<resourceType>/profiles/notAllowed` configuration parameter is set to a non-empty list, an error will be returned for any specified profile that is in the list, and validation will fail.
809809
2. If the `fhirServer/resources/<resourceType>/profiles/allowUnknown` configuration parameter is set to `false`, an error will be returned for any specified profile that is not loaded in the FHIR server, and validation will fail.
810810
3. If the `fhirServer/resources/<resourceType>/profiles/atLeastOne` configuration parameter is set to a non-empty list, an error will be returned if none of the specified profiles is in the list, and validation will fail.

fhir-server/src/main/java/com/ibm/fhir/server/util/FHIRRestHelper.java

+8-8
Original file line numberDiff line numberDiff line change
@@ -2561,10 +2561,10 @@ public int doReindexSingle(OperationOutcome.Builder operationOutcomeResult, Inst
25612561
* @throws FHIRValidationException
25622562
*/
25632563
private List<Issue> validateResource(Resource resource) throws FHIRValidationException {
2564-
List<String> atLeastOneProfiles = new ArrayList<>();
2565-
List<String> atLeastOneProfilesWithoutVersion = new ArrayList<>();
2566-
List<String> notAllowedProfiles = new ArrayList<>();
2567-
List<String> notAllowedProfilesWithoutVersion = new ArrayList<>();
2564+
Set<String> atLeastOneProfiles = new HashSet<>();
2565+
Set<String> atLeastOneProfilesWithoutVersion = new HashSet<>();
2566+
Set<String> notAllowedProfiles = new HashSet<>();
2567+
Set<String> notAllowedProfilesWithoutVersion = new HashSet<>();
25682568
boolean allowUnknown;
25692569

25702570
// Retrieve the profile configuration
@@ -2580,13 +2580,13 @@ private List<Issue> validateResource(Resource resource) throws FHIRValidationExc
25802580
FHIRConfigHelper.getStringListProperty(resourceSpecificProfileConfigPath.toString() +
25812581
FHIRConfiguration.PROPERTY_FIELD_RESOURCES_PROFILES_AT_LEAST_ONE);
25822582
if (resourceSpecificAtLeastOneProfiles != null) {
2583-
atLeastOneProfiles = resourceSpecificAtLeastOneProfiles;
2583+
atLeastOneProfiles.addAll(resourceSpecificAtLeastOneProfiles);
25842584
} else {
25852585
List<String> defaultAtLeastOneProfiles =
25862586
FHIRConfigHelper.getStringListProperty(defaultProfileConfigPath.toString() +
25872587
FHIRConfiguration.PROPERTY_FIELD_RESOURCES_PROFILES_AT_LEAST_ONE);
25882588
if (defaultAtLeastOneProfiles != null) {
2589-
atLeastOneProfiles = defaultAtLeastOneProfiles;
2589+
atLeastOneProfiles.addAll(defaultAtLeastOneProfiles);
25902590
}
25912591
}
25922592

@@ -2606,13 +2606,13 @@ private List<Issue> validateResource(Resource resource) throws FHIRValidationExc
26062606
FHIRConfigHelper.getStringListProperty(resourceSpecificProfileConfigPath.toString() +
26072607
FHIRConfiguration.PROPERTY_FIELD_RESOURCES_PROFILES_NOT_ALLOWED);
26082608
if (resourceSpecificNotAllowedProfiles != null) {
2609-
notAllowedProfiles = resourceSpecificNotAllowedProfiles;
2609+
notAllowedProfiles.addAll(resourceSpecificNotAllowedProfiles);
26102610
} else {
26112611
List<String> defaultNotAllowedProfiles =
26122612
FHIRConfigHelper.getStringListProperty(defaultProfileConfigPath.toString() +
26132613
FHIRConfiguration.PROPERTY_FIELD_RESOURCES_PROFILES_NOT_ALLOWED);
26142614
if (defaultNotAllowedProfiles != null) {
2615-
notAllowedProfiles = defaultNotAllowedProfiles;
2615+
notAllowedProfiles.addAll(defaultNotAllowedProfiles);
26162616
}
26172617
}
26182618

fhir-server/src/test/java/com/ibm/fhir/server/test/ProfileValidationConfigTest.java

+29-28
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
import static com.ibm.fhir.model.type.String.string;
99
import static org.testng.Assert.assertEquals;
10+
import static org.testng.Assert.assertTrue;
1011
import static org.testng.Assert.fail;
1112

1213
import java.util.List;
@@ -119,8 +120,8 @@ public void testCreateWithNoProfileSpecified() throws Exception {
119120
// Validate results
120121
List<Issue> issues = e.getIssues();
121122
assertEquals(issues.size(), 1);
122-
assertEquals(issues.get(0).getDetails().getText().getValue(),
123-
"A required profile was not specified. Resources of type 'Patient' must declare conformance to at least one of the following profiles: [profile1, profile2|1, profile3]");
123+
assertTrue(issues.get(0).getDetails().getText().getValue().startsWith(
124+
"A required profile was not specified. Resources of type 'Patient' must declare conformance to at least one of the following profiles: ["));
124125
assertEquals(issues.get(0).getSeverity(), IssueSeverity.ERROR);
125126
assertEquals(issues.get(0).getCode(), IssueType.BUSINESS_RULE);
126127
}
@@ -154,8 +155,8 @@ public void testCreateWithNonRequiredProfileSpecified() throws Exception {
154155
// Validate results
155156
List<Issue> issues = e.getIssues();
156157
assertEquals(issues.size(), 1);
157-
assertEquals(issues.get(0).getDetails().getText().getValue(),
158-
"A required profile was not specified. Resources of type 'Patient' must declare conformance to at least one of the following profiles: [profile1, profile2|1, profile3]");
158+
assertTrue(issues.get(0).getDetails().getText().getValue().startsWith(
159+
"A required profile was not specified. Resources of type 'Patient' must declare conformance to at least one of the following profiles: ["));
159160
assertEquals(issues.get(0).getSeverity(), IssueSeverity.ERROR);
160161
assertEquals(issues.get(0).getCode(), IssueType.BUSINESS_RULE);
161162
}
@@ -189,8 +190,8 @@ public void testCreateWithRequiredProfileSpecifiedButNoVersion() throws Exceptio
189190
// Validate results
190191
List<Issue> issues = e.getIssues();
191192
assertEquals(issues.size(), 1);
192-
assertEquals(issues.get(0).getDetails().getText().getValue(),
193-
"A required profile was not specified. Resources of type 'Patient' must declare conformance to at least one of the following profiles: [profile1, profile2|1, profile3]");
193+
assertTrue(issues.get(0).getDetails().getText().getValue().startsWith(
194+
"A required profile was not specified. Resources of type 'Patient' must declare conformance to at least one of the following profiles: ["));
194195
assertEquals(issues.get(0).getSeverity(), IssueSeverity.ERROR);
195196
assertEquals(issues.get(0).getCode(), IssueType.BUSINESS_RULE);
196197
}
@@ -514,8 +515,8 @@ public void testUpdateWithNoProfileSpecified() throws Exception {
514515
// Validate results
515516
List<Issue> issues = e.getIssues();
516517
assertEquals(issues.size(), 1);
517-
assertEquals(issues.get(0).getDetails().getText().getValue(),
518-
"A required profile was not specified. Resources of type 'Patient' must declare conformance to at least one of the following profiles: [profile1, profile2|1, profile3]");
518+
assertTrue(issues.get(0).getDetails().getText().getValue().startsWith(
519+
"A required profile was not specified. Resources of type 'Patient' must declare conformance to at least one of the following profiles: ["));
519520
assertEquals(issues.get(0).getSeverity(), IssueSeverity.ERROR);
520521
assertEquals(issues.get(0).getCode(), IssueType.BUSINESS_RULE);
521522
}
@@ -550,8 +551,8 @@ public void testUpdateWithNonRequiredProfileSpecified() throws Exception {
550551
// Validate results
551552
List<Issue> issues = e.getIssues();
552553
assertEquals(issues.size(), 1);
553-
assertEquals(issues.get(0).getDetails().getText().getValue(),
554-
"A required profile was not specified. Resources of type 'Patient' must declare conformance to at least one of the following profiles: [profile1, profile2|1, profile3]");
554+
assertTrue(issues.get(0).getDetails().getText().getValue().startsWith(
555+
"A required profile was not specified. Resources of type 'Patient' must declare conformance to at least one of the following profiles: ["));
555556
assertEquals(issues.get(0).getSeverity(), IssueSeverity.ERROR);
556557
assertEquals(issues.get(0).getCode(), IssueType.BUSINESS_RULE);
557558
}
@@ -666,8 +667,8 @@ public void testBundleWithNoProfileSpecified() throws Exception {
666667
assertEquals(issues.get(0).getDetails().getText().getValue(), "One or more errors were encountered while validating a 'transaction' request bundle.");
667668
assertEquals(issues.get(0).getSeverity(), IssueSeverity.FATAL);
668669
assertEquals(issues.get(0).getCode(), IssueType.INVALID);
669-
assertEquals(issues.get(1).getDetails().getText().getValue(),
670-
"A required profile was not specified. Resources of type 'Patient' must declare conformance to at least one of the following profiles: [profile1, profile2|1, profile3]");
670+
assertTrue(issues.get(1).getDetails().getText().getValue().startsWith(
671+
"A required profile was not specified. Resources of type 'Patient' must declare conformance to at least one of the following profiles: ["));
671672
assertEquals(issues.get(1).getSeverity(), IssueSeverity.ERROR);
672673
assertEquals(issues.get(1).getCode(), IssueType.BUSINESS_RULE);
673674
}
@@ -719,8 +720,8 @@ public void testBundleWithNonRequiredProfileSpecified() throws Exception {
719720
assertEquals(issues.get(0).getDetails().getText().getValue(), "One or more errors were encountered while validating a 'transaction' request bundle.");
720721
assertEquals(issues.get(0).getSeverity(), IssueSeverity.FATAL);
721722
assertEquals(issues.get(0).getCode(), IssueType.INVALID);
722-
assertEquals(issues.get(1).getDetails().getText().getValue(),
723-
"A required profile was not specified. Resources of type 'Patient' must declare conformance to at least one of the following profiles: [profile1, profile2|1, profile3]");
723+
assertTrue(issues.get(1).getDetails().getText().getValue().startsWith(
724+
"A required profile was not specified. Resources of type 'Patient' must declare conformance to at least one of the following profiles: ["));
724725
assertEquals(issues.get(1).getSeverity(), IssueSeverity.ERROR);
725726
assertEquals(issues.get(1).getCode(), IssueType.BUSINESS_RULE);
726727
}
@@ -852,8 +853,8 @@ public void testCreateWithNonAllowedProfileSpecified() throws Exception {
852853
// Validate results
853854
List<Issue> issues = e.getIssues();
854855
assertEquals(issues.size(), 1);
855-
assertEquals(issues.get(0).getDetails().getText().getValue(),
856-
"A profile was specified which is not allowed. Resources of type 'CarePlan' are not allowed to declare conformance to any of the following profiles: [profile8, profile6|1]");
856+
assertTrue(issues.get(0).getDetails().getText().getValue().startsWith(
857+
"A profile was specified which is not allowed. Resources of type 'CarePlan' are not allowed to declare conformance to any of the following profiles: ["));
857858
assertEquals(issues.get(0).getSeverity(), IssueSeverity.ERROR);
858859
assertEquals(issues.get(0).getCode(), IssueType.BUSINESS_RULE);
859860
}
@@ -889,8 +890,8 @@ public void testCreateWithNonAllowedVersionedProfileSpecified() throws Exception
889890
// Validate results
890891
List<Issue> issues = e.getIssues();
891892
assertEquals(issues.size(), 1);
892-
assertEquals(issues.get(0).getDetails().getText().getValue(),
893-
"A profile was specified which is not allowed. Resources of type 'CarePlan' are not allowed to declare conformance to any of the following profiles: [profile8, profile6|1]");
893+
assertTrue(issues.get(0).getDetails().getText().getValue().startsWith(
894+
"A profile was specified which is not allowed. Resources of type 'CarePlan' are not allowed to declare conformance to any of the following profiles: ["));
894895
assertEquals(issues.get(0).getSeverity(), IssueSeverity.ERROR);
895896
assertEquals(issues.get(0).getCode(), IssueType.BUSINESS_RULE);
896897
}
@@ -1019,8 +1020,8 @@ public void testUpdateWithNonAllowedProfileSpecified() throws Exception {
10191020
// Validate results
10201021
List<Issue> issues = e.getIssues();
10211022
assertEquals(issues.size(), 1);
1022-
assertEquals(issues.get(0).getDetails().getText().getValue(),
1023-
"A profile was specified which is not allowed. Resources of type 'CarePlan' are not allowed to declare conformance to any of the following profiles: [profile8, profile6|1]");
1023+
assertTrue(issues.get(0).getDetails().getText().getValue().startsWith(
1024+
"A profile was specified which is not allowed. Resources of type 'CarePlan' are not allowed to declare conformance to any of the following profiles: ["));
10241025
assertEquals(issues.get(0).getSeverity(), IssueSeverity.ERROR);
10251026
assertEquals(issues.get(0).getCode(), IssueType.BUSINESS_RULE);
10261027
}
@@ -1057,8 +1058,8 @@ public void testUpdateWithNonAllowedVersionedProfileSpecified() throws Exception
10571058
// Validate results
10581059
List<Issue> issues = e.getIssues();
10591060
assertEquals(issues.size(), 1);
1060-
assertEquals(issues.get(0).getDetails().getText().getValue(),
1061-
"A profile was specified which is not allowed. Resources of type 'CarePlan' are not allowed to declare conformance to any of the following profiles: [profile8, profile6|1]");
1061+
assertTrue(issues.get(0).getDetails().getText().getValue().startsWith(
1062+
"A profile was specified which is not allowed. Resources of type 'CarePlan' are not allowed to declare conformance to any of the following profiles: ["));
10621063
assertEquals(issues.get(0).getSeverity(), IssueSeverity.ERROR);
10631064
assertEquals(issues.get(0).getCode(), IssueType.BUSINESS_RULE);
10641065
}
@@ -1207,8 +1208,8 @@ public void testBundleWithNonAllowedProfileSpecified() throws Exception {
12071208
assertEquals(issues.get(0).getDetails().getText().getValue(), "One or more errors were encountered while validating a 'transaction' request bundle.");
12081209
assertEquals(issues.get(0).getSeverity(), IssueSeverity.FATAL);
12091210
assertEquals(issues.get(0).getCode(), IssueType.INVALID);
1210-
assertEquals(issues.get(1).getDetails().getText().getValue(),
1211-
"A profile was specified which is not allowed. Resources of type 'CarePlan' are not allowed to declare conformance to any of the following profiles: [profile8, profile6|1]");
1211+
assertTrue(issues.get(1).getDetails().getText().getValue().startsWith(
1212+
"A profile was specified which is not allowed. Resources of type 'CarePlan' are not allowed to declare conformance to any of the following profiles: ["));
12121213
assertEquals(issues.get(1).getSeverity(), IssueSeverity.ERROR);
12131214
assertEquals(issues.get(1).getCode(), IssueType.BUSINESS_RULE);
12141215
}
@@ -1262,8 +1263,8 @@ public void testBundleWithNonAllowedVersionedProfileSpecified() throws Exception
12621263
assertEquals(issues.get(0).getDetails().getText().getValue(), "One or more errors were encountered while validating a 'transaction' request bundle.");
12631264
assertEquals(issues.get(0).getSeverity(), IssueSeverity.FATAL);
12641265
assertEquals(issues.get(0).getCode(), IssueType.INVALID);
1265-
assertEquals(issues.get(1).getDetails().getText().getValue(),
1266-
"A profile was specified which is not allowed. Resources of type 'CarePlan' are not allowed to declare conformance to any of the following profiles: [profile8, profile6|1]");
1266+
assertTrue(issues.get(1).getDetails().getText().getValue().startsWith(
1267+
"A profile was specified which is not allowed. Resources of type 'CarePlan' are not allowed to declare conformance to any of the following profiles: ["));
12671268
assertEquals(issues.get(1).getSeverity(), IssueSeverity.ERROR);
12681269
assertEquals(issues.get(1).getCode(), IssueType.BUSINESS_RULE);
12691270
}
@@ -1445,8 +1446,8 @@ public void testCreateWithNonAllowedNonRequiredProfileSpecified() throws Excepti
14451446
"A profile was specified which is not allowed. Resources of type 'Patient' are not allowed to declare conformance to any of the following profiles: [profile5]");
14461447
assertEquals(issues.get(0).getSeverity(), IssueSeverity.ERROR);
14471448
assertEquals(issues.get(0).getCode(), IssueType.BUSINESS_RULE);
1448-
assertEquals(issues.get(1).getDetails().getText().getValue(),
1449-
"A required profile was not specified. Resources of type 'Patient' must declare conformance to at least one of the following profiles: [profile1, profile2|1, profile3]");
1449+
assertTrue(issues.get(1).getDetails().getText().getValue().startsWith(
1450+
"A required profile was not specified. Resources of type 'Patient' must declare conformance to at least one of the following profiles: ["));
14501451
assertEquals(issues.get(1).getSeverity(), IssueSeverity.ERROR);
14511452
assertEquals(issues.get(1).getCode(), IssueType.BUSINESS_RULE);
14521453
}

0 commit comments

Comments
 (0)