|
3 | 3 | import ca.uhn.fhir.context.FhirContext;
|
4 | 4 | import ca.uhn.fhir.context.support.DefaultProfileValidationSupport;
|
5 | 5 | import ca.uhn.fhir.context.support.IValidationSupport;
|
| 6 | +import ca.uhn.fhir.context.support.IValidationSupport.CodeValidationIssue; |
| 7 | +import ca.uhn.fhir.context.support.IValidationSupport.CodeValidationIssueCode; |
| 8 | +import ca.uhn.fhir.context.support.IValidationSupport.CodeValidationIssueCoding; |
| 9 | +import ca.uhn.fhir.context.support.IValidationSupport.CodeValidationResult; |
| 10 | +import ca.uhn.fhir.context.support.IValidationSupport.IssueSeverity; |
6 | 11 | import ca.uhn.fhir.context.support.ValidationSupportContext;
|
7 | 12 | import ca.uhn.fhir.fhirpath.BaseValidationTestWithInlineMocks;
|
8 | 13 | import org.hl7.fhir.r4.model.StructureDefinition;
|
| 14 | +import org.hl7.fhir.r5.model.Coding; |
9 | 15 | import org.hl7.fhir.r5.model.PackageInformation;
|
10 | 16 | import org.hl7.fhir.r5.model.Resource;
|
11 | 17 | import org.hl7.fhir.r5.model.ValueSet;
|
| 18 | +import org.hl7.fhir.r5.terminologies.utilities.ValidationResult; |
12 | 19 | import org.hl7.fhir.utilities.validation.ValidationOptions;
|
13 | 20 | import org.junit.jupiter.api.Test;
|
14 | 21 |
|
| 22 | +import java.util.ArrayList; |
15 | 23 | import java.util.List;
|
| 24 | +import java.util.concurrent.ForkJoinPool; |
| 25 | +import java.util.concurrent.ForkJoinTask; |
16 | 26 |
|
17 | 27 | import static org.assertj.core.api.Assertions.assertThat;
|
18 | 28 | import static org.junit.jupiter.api.Assertions.assertThrows;
|
@@ -109,6 +119,45 @@ public void validateCode_codeNotInValueSet_doesNotResolveSystem() {
|
109 | 119 | verify(myValidationSupport, never()).validateCode(any(), any(), any(), any(), any(), any());
|
110 | 120 | }
|
111 | 121 |
|
| 122 | + @Test |
| 123 | + public void validateCode_codeNotInValueSet_codeNotInSystem_concurrent() { |
| 124 | + // setup |
| 125 | + setupValidation(); |
| 126 | + |
| 127 | + String system = "http://codesystems.com/system"; |
| 128 | + String badCode = "code3"; |
| 129 | + |
| 130 | + CodeValidationResult codeInValuesetValResult = new CodeValidationResult().setCode(badCode).setCodeSystemName(system).setMessage("Bad code in VS"); |
| 131 | + when(myValidationSupport.validateCodeInValueSet(any(), any(), eq(system), eq(badCode), any(), any())).thenReturn(codeInValuesetValResult); |
| 132 | + |
| 133 | + // We expect this code validation result as an additional result on the validation, if code is in value set |
| 134 | + String issueMessage = "Code not in here!"; |
| 135 | + CodeValidationIssue codeValidationIssue = new CodeValidationIssue(issueMessage, IssueSeverity.ERROR, CodeValidationIssueCode.NOT_FOUND, CodeValidationIssueCoding.NOT_FOUND); |
| 136 | + CodeValidationResult codeValResult = new CodeValidationResult().setMessage("Bad code in CS").setCode(badCode).setCodeSystemName(system).setSeverity(IssueSeverity.ERROR).addIssue(codeValidationIssue); |
| 137 | + when(myValidationSupport.validateCode(any(), any(), eq("http://codesystems.com/system"), eq(badCode) , any(), eq(null))).thenReturn(codeValResult); |
| 138 | + |
| 139 | + ForkJoinPool pool = ForkJoinPool.commonPool(); |
| 140 | + List<ForkJoinTask<?>> futures = new ArrayList<>(); |
| 141 | + for(int i=0; i<1000; i++) { |
| 142 | + ForkJoinTask<?> f = pool.submit(() -> { |
| 143 | + org.hl7.fhir.r5.model.ValueSet valueSet = new ValueSet(); |
| 144 | + valueSet.getCompose().addInclude().setSystem(system).addConcept().setCode("code0"); |
| 145 | + valueSet.getCompose().addInclude().setSystem("http://codesystems.com/system2").addConcept().setCode("code2"); |
| 146 | + |
| 147 | + ValidationResult result = myWorkerContextWrapper.validateCode(new ValidationOptions(), new Coding(system, badCode, ""), valueSet); |
| 148 | + |
| 149 | + // here we check if the additional code validation result was added |
| 150 | + assertThat(result.getIssues()).hasSize(1); |
| 151 | + assertThat(result.getIssues().get(0).getDiagnostics()).isEqualTo(issueMessage); |
| 152 | + }); |
| 153 | + futures.add(f); |
| 154 | + } |
| 155 | + // test if there was no assertion exception for any invocation |
| 156 | + for(ForkJoinTask<?> f : futures) { |
| 157 | + f.join(); |
| 158 | + } |
| 159 | + } |
| 160 | + |
112 | 161 | @Test
|
113 | 162 | public void isPrimitive_primitive() {
|
114 | 163 | // setup
|
|
0 commit comments