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() { public String toString() {
ToStringBuilder b = new ToStringBuilder(this, ToStringStyle.SHORT_PREFIX_STYLE); ToStringBuilder b = new ToStringBuilder(this, ToStringStyle.SHORT_PREFIX_STYLE);
if (myLocationCol != null || myLocationLine != null) { if (myLocationCol != null || myLocationLine != null) {
b.append("myLocationCol", myLocationCol); b.append("col", myLocationCol);
b.append("myLocationRow", myLocationLine); b.append("row", myLocationLine);
} }
if (myLocationString != null) { if (myLocationString != null) {
b.append("myLocationString", myLocationString); b.append("locationString", myLocationString);
} }
b.append("myMessage", myMessage); b.append("message", myMessage);
if (mySeverity != null) { if (mySeverity != null) {
b.append("mySeverity", mySeverity.getCode()); b.append("severity", mySeverity.getCode());
} }
return b.toString(); 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; import static org.apache.commons.lang3.StringUtils.isNotBlank;
public class ValidationDataUploader extends BaseCommand { 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 static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(ValidationDataUploader.class);
private ArrayList<IIdType> myExcludes = new ArrayList<>(); private ArrayList<IIdType> myExcludes = new ArrayList<>();
@ -354,9 +353,10 @@ public class ValidationDataUploader extends BaseCommand {
ourLog.info("Finished uploading ValueSets"); ourLog.info("Finished uploading ValueSets");
uploadDstu3Profiles(theCtx, client, "profiles-resources"); uploadDstu3Profiles(theCtx, client, "profile/profiles-resources");
uploadDstu3Profiles(theCtx, client, "profiles-types"); uploadDstu3Profiles(theCtx, client, "profile/profiles-types");
uploadDstu3Profiles(theCtx, client, "profiles-others"); uploadDstu3Profiles(theCtx, client, "profile/profiles-others");
uploadDstu3Profiles(theCtx, client, "extension/extension-definitions");
ourLog.info("Finished uploading ValueSets"); ourLog.info("Finished uploading ValueSets");
@ -446,9 +446,10 @@ public class ValidationDataUploader extends BaseCommand {
ourLog.info("Finished uploading ValueSets"); ourLog.info("Finished uploading ValueSets");
uploadR4Profiles(theCtx, client, "profiles-resources"); uploadR4Profiles(theCtx, client, "profile/profiles-resources");
uploadR4Profiles(theCtx, client, "profiles-types"); uploadR4Profiles(theCtx, client, "profile/profiles-types");
uploadR4Profiles(theCtx, client, "profiles-others"); uploadR4Profiles(theCtx, client, "profile/profiles-others");
uploadR4Profiles(theCtx, client, "extension/extension-definitions");
ourLog.info("Finished uploading ValueSets"); ourLog.info("Finished uploading ValueSets");
@ -457,14 +458,14 @@ public class ValidationDataUploader extends BaseCommand {
ourLog.info("Finished uploading definitions to server (took {} ms)", delay); 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 total;
int count; int count;
org.hl7.fhir.dstu3.model.Bundle bundle; org.hl7.fhir.dstu3.model.Bundle bundle;
ourLog.info("Uploading " + name); ourLog.info("Uploading " + theName);
String vsContents; String vsContents;
try { 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) { } catch (IOException e) {
throw new CommandFailureException(e.toString()); throw new CommandFailureException(e.toString());
} }
@ -498,7 +499,7 @@ public class ValidationDataUploader extends BaseCommand {
continue; 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(); client.update().resource(next).execute();
count++; count++;

View File

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