Credit for #946 and add extensions to the CLI uploader

This commit is contained in:
James Agnew 2018-05-16 19:32:12 -04:00
parent 423cb8f2c1
commit 4fd868afae
4 changed files with 37 additions and 26 deletions

View File

@ -109,15 +109,15 @@ public class SingleValidationMessage {
public String toString() {
ToStringBuilder b = new ToStringBuilder(this, ToStringStyle.SHORT_PREFIX_STYLE);
if (myLocationCol != null || myLocationLine != null) {
b.append("myLocationCol", myLocationCol);
b.append("myLocationRow", myLocationLine);
b.append("col", myLocationCol);
b.append("row", myLocationLine);
}
if (myLocationString != null) {
b.append("myLocationString", myLocationString);
b.append("locationString", myLocationString);
}
b.append("myMessage", myMessage);
b.append("message", myMessage);
if (mySeverity != null) {
b.append("mySeverity", mySeverity.getCode());
b.append("severity", mySeverity.getCode());
}
return b.toString();
}

View File

@ -53,7 +53,6 @@ import static org.apache.commons.lang3.StringUtils.isBlank;
import static org.apache.commons.lang3.StringUtils.isNotBlank;
public class ValidationDataUploader extends BaseCommand {
// TODO: Don't use qualified names for loggers in HAPI CLI.
private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(ValidationDataUploader.class);
private ArrayList<IIdType> myExcludes = new ArrayList<>();
@ -354,9 +353,10 @@ public class ValidationDataUploader extends BaseCommand {
ourLog.info("Finished uploading ValueSets");
uploadDstu3Profiles(theCtx, client, "profiles-resources");
uploadDstu3Profiles(theCtx, client, "profiles-types");
uploadDstu3Profiles(theCtx, client, "profiles-others");
uploadDstu3Profiles(theCtx, client, "profile/profiles-resources");
uploadDstu3Profiles(theCtx, client, "profile/profiles-types");
uploadDstu3Profiles(theCtx, client, "profile/profiles-others");
uploadDstu3Profiles(theCtx, client, "extension/extension-definitions");
ourLog.info("Finished uploading ValueSets");
@ -446,9 +446,10 @@ public class ValidationDataUploader extends BaseCommand {
ourLog.info("Finished uploading ValueSets");
uploadR4Profiles(theCtx, client, "profiles-resources");
uploadR4Profiles(theCtx, client, "profiles-types");
uploadR4Profiles(theCtx, client, "profiles-others");
uploadR4Profiles(theCtx, client, "profile/profiles-resources");
uploadR4Profiles(theCtx, client, "profile/profiles-types");
uploadR4Profiles(theCtx, client, "profile/profiles-others");
uploadR4Profiles(theCtx, client, "extension/extension-definitions");
ourLog.info("Finished uploading ValueSets");
@ -457,14 +458,14 @@ public class ValidationDataUploader extends BaseCommand {
ourLog.info("Finished uploading definitions to server (took {} ms)", delay);
}
private void uploadDstu3Profiles(FhirContext ctx, IGenericClient client, String name) throws CommandFailureException {
private void uploadDstu3Profiles(FhirContext ctx, IGenericClient client, String theName) throws CommandFailureException {
int total;
int count;
org.hl7.fhir.dstu3.model.Bundle bundle;
ourLog.info("Uploading " + name);
ourLog.info("Uploading " + theName);
String vsContents;
try {
vsContents = IOUtils.toString(ValidationDataUploader.class.getResourceAsStream("/org/hl7/fhir/dstu3/model/profile/" + name + ".xml"), "UTF-8");
vsContents = IOUtils.toString(ValidationDataUploader.class.getResourceAsStream("/org/hl7/fhir/dstu3/model/" + theName + ".xml"), "UTF-8");
} catch (IOException e) {
throw new CommandFailureException(e.toString());
}
@ -498,7 +499,7 @@ public class ValidationDataUploader extends BaseCommand {
continue;
}
ourLog.info("Uploading {} StructureDefinition {}/{} : {}", new Object[] {name, count, total, next.getIdElement().getValue()});
ourLog.info("Uploading {} StructureDefinition {}/{} : {}", new Object[] {theName, count, total, next.getIdElement().getValue()});
client.update().resource(next).execute();
count++;

View File

@ -38,6 +38,7 @@ import org.mockito.stubbing.Answer;
import java.io.IOException;
import java.io.InputStream;
import java.util.*;
import java.util.stream.Collectors;
import java.util.zip.GZIPInputStream;
import static org.hamcrest.Matchers.*;
@ -412,6 +413,7 @@ public class FhirInstanceValidatorR4Test {
}
@Test
@Ignore
public void testValidateBuiltInProfiles() throws Exception {
org.hl7.fhir.r4.model.Bundle bundle;
String name = "profiles-resources";
@ -438,21 +440,23 @@ public class FhirInstanceValidatorR4Test {
ourLog.trace(ourCtx.newXmlParser().setPrettyPrint(true).encodeResourceToString(next));
ValidationResult output = myVal.validateWithResult(next);
List<SingleValidationMessage> errors = logResultsAndReturnNonInformationalOnes(output);
List<SingleValidationMessage> results = logResultsAndReturnAll(output);
// // This isn't a validator problem but a definition problem.. it should get fixed at some point and
// // we can remove this
// if (next.getId().equalsIgnoreCase("http://hl7.org/fhir/OperationDefinition/StructureDefinition-generate")) {
// assertEquals(1, errors.size());
// assertEquals("A search type can only be specified for parameters of type string [searchType implies type = 'string']", errors.get(0).getMessage());
// continue;
// }
// This isn't a validator problem but a definition problem.. it should get fixed at some point and
// we can remove this. Tracker #17207 was filed about this
// https://gforge.hl7.org/gf/project/fhir/tracker/?action=TrackerItemEdit&tracker_item_id=17207
if (next.getId().equalsIgnoreCase("http://hl7.org/fhir/OperationDefinition/StructureDefinition-snapshot")) {
assertEquals(1, errors.size());
assertEquals("A search type can only be specified for parameters of type string [searchType.exists() implies type = 'string']", errors.get(0).getMessage());
assertEquals(1, results.size());
assertEquals("A search type can only be specified for parameters of type string [searchType.exists() implies type = 'string']", results.get(0).getMessage());
continue;
}
List<SingleValidationMessage> errors = results
.stream()
.filter(t -> t.getSeverity() != ResultSeverityEnum.INFORMATION)
.collect(Collectors.toList());
assertThat("Failed to validate " + i.getFullUrl() + " - " + errors, errors, empty());
}

View File

@ -172,6 +172,12 @@
invocation at the type level as being at the instance level if the method
indicated that the IdParam parameter was optional. This has been fixed.
</action>
<action type="add">
StructureDefinitions for the FHIR standard extensions have been added to the
hapi-fhir-validation-resources-XXXX modules. Thanks to Patrick Werner for the
pull request! These have also been added to the list of definitions uploaded
by the CLI "upload-definitions" command.
</action>
</release>
<release version="3.3.0" date="2018-03-29">
<action type="add">