本文整理汇总了Java中ca.uhn.fhir.validation.ValidationResult类的典型用法代码示例。如果您正苦于以下问题:Java ValidationResult类的具体用法?Java ValidationResult怎么用?Java ValidationResult使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ValidationResult类属于ca.uhn.fhir.validation包,在下文中一共展示了ValidationResult类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: validateResource
import ca.uhn.fhir.validation.ValidationResult; //导入依赖的package包/类
private void validateResource(Resource resource) {
ValidationResult result = validator.validateWithResult(resource);
// Show the issues
// Colour values https://github.com/yonchu/shell-color-pallet/blob/master/color16
for (SingleValidationMessage next : result.getMessages()) {
switch (next.getSeverity())
{
case ERROR:
fail("FHIR Validation ERROR - "+ next.getMessage());
break;
case WARNING:
//fail("FHIR Validation WARNING - "+ next.getMessage());
System.out.println( (char)27 + "[34mWARNING" + (char)27 + "[0m" + " - " + next.getLocationString() + " - " + next.getMessage());
break;
case INFORMATION:
System.out.println( (char)27 + "[34mINFORMATION" + (char)27 + "[0m" + " - " + next.getLocationString() + " - " + next.getMessage());
break;
default:
System.out.println(" Next issue " + next.getSeverity() + " - " + next.getLocationString() + " - " + next.getMessage());
}
}
}
示例2: publishFhirConsentToHie
import ca.uhn.fhir.validation.ValidationResult; //导入依赖的package包/类
@Override
public void publishFhirConsentToHie(Consent fhirConsent) {
//validate the resource
ValidationResult validationResult = fhirValidator.validateWithResult(fhirConsent);
logger.debug("validationResult.isSuccessful(): " + validationResult.isSuccessful());
//throw format error if the validation is not successful
if (!validationResult.isSuccessful()) {
throw new FHIRFormatErrorException("Consent Validation is not successful" + validationResult.getMessages());
}
/*
Use the client to store a new consent resource instance
Invoke the server create method (and send pretty-printed JSON
encoding to the server
instead of the default which is non-pretty printed XML)
invoke Consent service
*/
fhirClient.create().resource(fhirConsent).execute();
}
示例3: validateFhirRequest
import ca.uhn.fhir.validation.ValidationResult; //导入依赖的package包/类
private FhirValidationResult validateFhirRequest(Contents contents) {
FhirValidationResult result = new FhirValidationResult();
FhirValidator validator = fhirContext.newValidator();
IParser parser = newParser(contents.contentType);
IBaseResource resource = parser.parseResource(contents.content);
ValidationResult vr = validator.validateWithResult(resource);
if (vr.isSuccessful()) {
result.passed = true;
} else {
result.passed = false;
result.operationOutcome = vr.toOperationOutcome();
}
return result;
}
示例4: main
import ca.uhn.fhir.validation.ValidationResult; //导入依赖的package包/类
public static void main(String[] args) {
String input = "<Encounter xmlns=\"http://hl7.org/fhir\"></Encounter>";
// Create a new validator
FhirContext ctx = FhirContext.forDstu3();
FhirValidator validator = ctx.newValidator();
// Did we succeed?
ValidationResult result = validator.validateWithResult(input);
System.out.println("Success: " + result.isSuccessful());
// What was the result
OperationOutcome outcome = (OperationOutcome) result.toOperationOutcome();
IParser parser = ctx.newXmlParser().setPrettyPrint(true);
System.out.println(parser.encodeResourceToString(outcome));
}
示例5: main
import ca.uhn.fhir.validation.ValidationResult; //导入依赖的package包/类
public static void main(String[] args) {
// Create an incomplete encounter (status is required)
Encounter enc = new Encounter();
enc.addIdentifier().setSystem("http://acme.org/encNums").setValue("12345");
// Create a new validator
FhirContext ctx = FhirContext.forDstu3();
FhirValidator validator = ctx.newValidator();
// Did we succeed?
ValidationResult result = validator.validateWithResult(enc);
System.out.println("Success: " + result.isSuccessful());
// What was the result
OperationOutcome outcome = (OperationOutcome) result.toOperationOutcome();
IParser parser = ctx.newXmlParser().setPrettyPrint(true);
System.out.println(parser.encodeResourceToString(outcome));
}
示例6: testDateParsesWithInvalidPrecision
import ca.uhn.fhir.validation.ValidationResult; //导入依赖的package包/类
/**
* Test for #57
*/
@Test
public void testDateParsesWithInvalidPrecision() {
Condition c = new Condition();
c.setDateAsserted(new DateDt());
c.getDateAsserted().setValueAsString("2001-01-02T11:13:33");
assertEquals(TemporalPrecisionEnum.SECOND, c.getDateAsserted().getPrecision());
String encoded = ourCtx.newXmlParser().encodeResourceToString(c);
Assert.assertThat(encoded, Matchers.containsString("value=\"2001-01-02T11:13:33\""));
c = ourCtx.newXmlParser().parseResource(Condition.class, encoded);
assertEquals("2001-01-02T11:13:33", c.getDateAsserted().getValueAsString());
assertEquals(TemporalPrecisionEnum.SECOND, c.getDateAsserted().getPrecision());
ValidationResult outcome = ourCtx.newValidator().validateWithResult(c);
String outcomeStr = ourCtx.newJsonParser().setPrettyPrint(true).encodeResourceToString(outcome.getOperationOutcome());
ourLog.info(outcomeStr);
assertThat(outcomeStr, containsString("date-primitive"));
}
示例7: main
import ca.uhn.fhir.validation.ValidationResult; //导入依赖的package包/类
public static void main(String[] args) {
// Create an encounter with an invalid status and no class
Encounter enc = new Encounter();
enc.getStatus().setValueAsString("invalid_status");
// Create a new validator
FhirContext ctx = new FhirContext();
FhirValidator validator = ctx.newValidator();
// Did we succeed?
ValidationResult result = validator.validateWithResult(enc);
System.out.println("Success: " + result.isSuccessful());
// What was the result
OperationOutcome outcome = result.getOperationOutcome();
IParser parser = ctx.newXmlParser().setPrettyPrint(true);
System.out.println(parser.encodeResourceToString(outcome));
}
示例8: testValidateGeneratedStatement
import ca.uhn.fhir.validation.ValidationResult; //导入依赖的package包/类
@Test
public void testValidateGeneratedStatement() throws Exception {
RestfulServer rs = new RestfulServer(ourCtx);
rs.setProviders(new MultiOptionalProvider());
ServerCapabilityStatementProvider sc = new ServerCapabilityStatementProvider(rs);
rs.setServerConformanceProvider(sc);
rs.init(createServletConfig());
CapabilityStatement conformance = sc.getServerConformance(createHttpServletRequest());
ourLog.info(ourCtx.newXmlParser().setPrettyPrint(true).encodeResourceToString(conformance));
ValidationResult result = ourCtx.newValidator().validateWithResult(conformance);
assertTrue(result.getMessages().toString(), result.isSuccessful());
}
示例9: testDateParsesWithInvalidPrecision
import ca.uhn.fhir.validation.ValidationResult; //导入依赖的package包/类
/**
* Test for #57
*/
@Test
public void testDateParsesWithInvalidPrecision() {
Goal c = new Goal();
c.setStatusDateElement(new DateType());
c.getStatusDateElement().setValueAsString("2001-01-02T11:13:33");
assertEquals(TemporalPrecisionEnum.SECOND, c.getStatusDateElement().getPrecision());
String encoded = ourCtx.newXmlParser().encodeResourceToString(c);
Assert.assertThat(encoded, Matchers.containsString("value=\"2001-01-02T11:13:33\""));
c = ourCtx.newXmlParser().parseResource(Goal.class, encoded);
assertEquals("2001-01-02T11:13:33", c.getStatusDateElement().getValueAsString());
assertEquals(TemporalPrecisionEnum.SECOND, c.getStatusDateElement().getPrecision());
ValidationResult outcome = ourCtx.newValidator().validateWithResult(c);
String outcomeStr = ourCtx.newJsonParser().setPrettyPrint(true).encodeResourceToString(outcome.toOperationOutcome());
ourLog.info(outcomeStr);
assertThat(outcomeStr, containsString("date-primitive"));
}
示例10: testValidateCustomStructure
import ca.uhn.fhir.validation.ValidationResult; //导入依赖的package包/类
@Test
public void testValidateCustomStructure() throws Exception {
FooMessageHeader.FooMessageSourceComponent source = new FooMessageHeader.FooMessageSourceComponent();
source.getMessageHeaderApplicationId().setValue("APPID");
source.setName("NAME");
source.setEndpoint("http://foo");
FooMessageHeader header = new FooMessageHeader();
header.setTimestamp(new Date());
header.getEvent().setSystem("http://system").setCode("value");
header.setSource(source);
FhirValidator val = ourCtx.newValidator();
val.setValidateAgainstStandardSchema(true);
val.setValidateAgainstStandardSchematron(true);
ValidationResult result = val.validateWithResult(header);
ourLog.info(ourCtx.newXmlParser().setPrettyPrint(true).encodeResourceToString(result.toOperationOutcome()));
assertTrue(result.isSuccessful());
}
示例11: testValidateResourceWithValuesetExpansionBad
import ca.uhn.fhir.validation.ValidationResult; //导入依赖的package包/类
@Test
public void testValidateResourceWithValuesetExpansionBad() {
Patient patient = new Patient();
patient.addIdentifier().setSystem("http://example.com/").setValue("12345").getType().addCoding().setSystem("http://example.com/foo/bar").setCode("bar");
ValidationResult output = myVal.validateWithResult(patient);
List<SingleValidationMessage> all = logResultsAndReturnAll(output);
assertEquals(1, all.size());
assertEquals("Patient.identifier.type", all.get(0).getLocationString());
assertEquals(
"None of the codes provided are in the value set http://hl7.org/fhir/ValueSet/identifier-type (http://hl7.org/fhir/ValueSet/identifier-type, and a code should come from this value set unless it has no suitable code) (codes = http://example.com/foo/bar#bar)",
all.get(0).getMessage());
assertEquals(ResultSeverityEnum.WARNING, all.get(0).getSeverity());
}
示例12: incomingRequestPostProcessed
import ca.uhn.fhir.validation.ValidationResult; //导入依赖的package包/类
@Override
public boolean incomingRequestPostProcessed(RequestDetails theRequestDetails, HttpServletRequest theRequest, HttpServletResponse theResponse) throws AuthenticationException {
EncodingEnum encoding = RestfulServerUtils.determineRequestEncodingNoDefault(theRequestDetails);
if (encoding == null) {
ourLog.trace("Incoming request does not appear to be FHIR, not going to validate");
return true;
}
Charset charset = ResourceParameter.determineRequestCharset(theRequestDetails);
String requestText = new String(theRequestDetails.loadRequestContents(), charset);
if (isBlank(requestText)) {
ourLog.trace("Incoming request does not have a body");
return true;
}
ValidationResult validationResult = validate(requestText, theRequestDetails);
// The JPA server will use this
theRequestDetails.getUserData().put(REQUEST_VALIDATION_RESULT, validationResult);
return true;
}
示例13: outgoingResponse
import ca.uhn.fhir.validation.ValidationResult; //导入依赖的package包/类
@Override
public boolean outgoingResponse(RequestDetails theRequestDetails, IBaseResource theResponseObject) {
if (myAddValidationResultsToResponseOperationOutcome) {
if (theResponseObject instanceof IBaseOperationOutcome) {
IBaseOperationOutcome oo = (IBaseOperationOutcome) theResponseObject;
if (theRequestDetails != null) {
ValidationResult validationResult = (ValidationResult) theRequestDetails.getUserData().get(RequestValidatingInterceptor.REQUEST_VALIDATION_RESULT);
if (validationResult != null) {
validationResult.populateOperationOutcome(oo);
}
}
}
}
return true;
}
示例14: testValidateBigRawJsonResource
import ca.uhn.fhir.validation.ValidationResult; //导入依赖的package包/类
@Test
public void testValidateBigRawJsonResource() throws Exception {
InputStream stream = FhirInstanceValidatorDstu3Test.class.getResourceAsStream("/conformance.json.gz");
stream = new GZIPInputStream(stream);
String input = IOUtils.toString(stream);
long start = System.currentTimeMillis();
ValidationResult output = null;
int passes = 1;
for (int i = 0; i < passes; i++) {
ourLog.info("Pass {}", i + 1);
output = myVal.validateWithResult(input);
}
long delay = System.currentTimeMillis() - start;
long per = delay / passes;
logResultsAndReturnAll(output);
ourLog.info("Took {} ms -- {}ms / pass", delay, per);
}
示例15: testValidateRawJsonResourceBadAttributes
import ca.uhn.fhir.validation.ValidationResult; //导入依赖的package包/类
@Test
public void testValidateRawJsonResourceBadAttributes() {
//@formatter:off
String input =
"{" +
"\"resourceType\":\"Patient\"," +
"\"id\":\"123\"," +
"\"foo\":\"123\"" +
"}";
//@formatter:on
ValidationResult output = myVal.validateWithResult(input);
assertEquals(output.toString(), 1, output.getMessages().size());
ourLog.info(output.getMessages().get(0).getLocationString());
ourLog.info(output.getMessages().get(0).getMessage());
assertEquals("/Patient", output.getMessages().get(0).getLocationString());
assertEquals("Unrecognised property '@foo'", output.getMessages().get(0).getMessage());
}