当前位置: 首页>>代码示例>>Java>>正文


Java FhirContext.newValidator方法代码示例

本文整理汇总了Java中ca.uhn.fhir.context.FhirContext.newValidator方法的典型用法代码示例。如果您正苦于以下问题:Java FhirContext.newValidator方法的具体用法?Java FhirContext.newValidator怎么用?Java FhirContext.newValidator使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在ca.uhn.fhir.context.FhirContext的用法示例。


在下文中一共展示了FhirContext.newValidator方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: testFHIRExport

import ca.uhn.fhir.context.FhirContext; //导入方法依赖的package包/类
@Test
public void testFHIRExport() throws Exception {
  FhirContext ctx = FhirContext.forDstu3();
  FhirValidator validator = ctx.newValidator();
  validator.setValidateAgainstStandardSchema(true);
  validator.setValidateAgainstStandardSchematron(true);

  File tempOutputFolder = tempFolder.newFolder();
  Config.set("exporter.baseDirectory", tempOutputFolder.toString());
  Config.set("exporter.hospital.fhir.export", "true");
  Hospital.loadHospitals();
  assertNotNull(Hospital.getHospitalList());
  assertFalse(Hospital.getHospitalList().isEmpty());

  Hospital.getHospitalList().get(0).incrementEncounters(EncounterType.WELLNESS.toString(), 0);
  HospitalExporter.export(0L);

  File expectedExportFolder = tempOutputFolder.toPath().resolve("fhir").toFile();
  assertTrue(expectedExportFolder.exists() && expectedExportFolder.isDirectory());

  File expectedExportFile = expectedExportFolder.toPath().resolve("hospitalInformation0.json")
      .toFile();
  assertTrue(expectedExportFile.exists() && expectedExportFile.isFile());

  FileReader fileReader = new FileReader(expectedExportFile.getPath());
  BufferedReader bufferedReader = new BufferedReader(fileReader);
  StringBuilder fhirJson = new StringBuilder();
  String line = null;
  while ((line = bufferedReader.readLine()) != null) {
    fhirJson.append(line);
  }
  bufferedReader.close();
  IBaseResource resource = ctx.newJsonParser().parseResource(fhirJson.toString());
  ValidationResult result = validator.validateWithResult(resource);
  if (result.isSuccessful() == false) {
    for (SingleValidationMessage message : result.getMessages()) {
      System.out.println(message.getSeverity().toString() + ": " + message.getMessage());
    }
  }
  assertTrue(result.isSuccessful());
}
 
开发者ID:synthetichealth,项目名称:synthea_java,代码行数:42,代码来源:HospitalExporterTest.java

示例2: testFHIRDSTU2Export

import ca.uhn.fhir.context.FhirContext; //导入方法依赖的package包/类
@Test
public void testFHIRDSTU2Export() throws Exception {
  FhirContext ctx = FhirContext.forDstu2();
  FhirValidator validator = ctx.newValidator();
  validator.setValidateAgainstStandardSchema(true);
  validator.setValidateAgainstStandardSchematron(true);

  File tempOutputFolder = tempFolder.newFolder();
  Config.set("exporter.baseDirectory", tempOutputFolder.toString());
  Config.set("exporter.hospital.fhir_dstu2.export", "true");
  Hospital.loadHospitals();
  assertNotNull(Hospital.getHospitalList());
  assertFalse(Hospital.getHospitalList().isEmpty());

  Hospital.getHospitalList().get(0).incrementEncounters(EncounterType.WELLNESS.toString(), 0);
  HospitalDSTU2Exporter.export(0L);

  File expectedExportFolder = tempOutputFolder.toPath().resolve("fhir_dstu2").toFile();
  assertTrue(expectedExportFolder.exists() && expectedExportFolder.isDirectory());

  File expectedExportFile = expectedExportFolder.toPath().resolve("hospitalInformation0.json")
      .toFile();
  assertTrue(expectedExportFile.exists() && expectedExportFile.isFile());

  FileReader fileReader = new FileReader(expectedExportFile.getPath());
  BufferedReader bufferedReader = new BufferedReader(fileReader);
  StringBuilder fhirJson = new StringBuilder();
  String line = null;
  while ((line = bufferedReader.readLine()) != null) {
    fhirJson.append(line);
  }
  bufferedReader.close();
  IBaseResource resource = ctx.newJsonParser().parseResource(fhirJson.toString());
  ValidationResult result = validator.validateWithResult(resource);
  if (result.isSuccessful() == false) {
    for (SingleValidationMessage message : result.getMessages()) {
      System.out.println(message.getSeverity().toString() + ": " + message.getMessage());
    }
  }
  assertTrue(result.isSuccessful());
}
 
开发者ID:synthetichealth,项目名称:synthea_java,代码行数:42,代码来源:HospitalDSTU2ExporterTest.java

示例3: testFHIRDSTU2Export

import ca.uhn.fhir.context.FhirContext; //导入方法依赖的package包/类
@Test
public void testFHIRDSTU2Export() throws Exception {
  Config.set("exporter.baseDirectory", tempFolder.newFolder().toString());
  
  FhirContext ctx = FhirContext.forDstu2();
  IParser parser = ctx.newJsonParser().setPrettyPrint(true);

  FhirValidator validator = ctx.newValidator();
  validator.setValidateAgainstStandardSchema(true);
  validator.setValidateAgainstStandardSchematron(true);

  List<String> validationErrors = new ArrayList<String>();

  int numberOfPeople = 10;
  Generator generator = new Generator(numberOfPeople);
  for (int i = 0; i < numberOfPeople; i++) {
    int x = validationErrors.size();
    TestHelper.exportOff();
    Person person = generator.generatePerson(i);
    Config.set("exporter.fhir_dstu2.export", "true");
    String fhirJson = FhirDstu2.convertToFHIR(person, System.currentTimeMillis());
    IBaseResource resource = ctx.newJsonParser().parseResource(fhirJson);
    ValidationResult result = validator.validateWithResult(resource);
    if (result.isSuccessful() == false) {
      // If the validation failed, let's crack open the Bundle and validate
      // each individual entry.resource to get context-sensitive error
      // messages...
      Bundle bundle = parser.parseResource(Bundle.class, fhirJson);
      for (Entry entry : bundle.getEntry()) {
        ValidationResult eresult = validator.validateWithResult(entry.getResource());
        if (eresult.isSuccessful() == false) {
          for (SingleValidationMessage emessage : eresult.getMessages()) {
            System.out.println(parser.encodeResourceToString(entry.getResource()));
            System.out.println("ERROR: " + emessage.getMessage());
            validationErrors.add(emessage.getMessage());
          }
        }
        
      }
    }
    int y = validationErrors.size();
    if (x != y) {
      Exporter.export(person, System.currentTimeMillis());
    }
  }

  assertEquals(0, validationErrors.size());
}
 
开发者ID:synthetichealth,项目名称:synthea_java,代码行数:49,代码来源:FHIRDSTU2ExporterTest.java

示例4: testFHIRExport

import ca.uhn.fhir.context.FhirContext; //导入方法依赖的package包/类
@Test
public void testFHIRExport() throws Exception {
  Config.set("exporter.baseDirectory", tempFolder.newFolder().toString());
  
  FhirContext ctx = FhirContext.forDstu3();
  IParser parser = ctx.newJsonParser().setPrettyPrint(true);

  FhirValidator validator = ctx.newValidator();
  validator.setValidateAgainstStandardSchema(true);
  validator.setValidateAgainstStandardSchematron(true);

  List<String> validationErrors = new ArrayList<String>();

  int numberOfPeople = 10;
  Generator generator = new Generator(numberOfPeople);
  for (int i = 0; i < numberOfPeople; i++) {
    int x = validationErrors.size();
    TestHelper.exportOff();
    Person person = generator.generatePerson(i);
    Config.set("exporter.fhir.export", "true");
    String fhirJson = FhirStu3.convertToFHIR(person, System.currentTimeMillis());
    IBaseResource resource = ctx.newJsonParser().parseResource(fhirJson);
    ValidationResult result = validator.validateWithResult(resource);
    if (result.isSuccessful() == false) {
      // If the validation failed, let's crack open the Bundle and validate
      // each individual entry.resource to get context-sensitive error
      // messages...
      Bundle bundle = parser.parseResource(Bundle.class, fhirJson);
      for (BundleEntryComponent entry : bundle.getEntry()) {
        ValidationResult eresult = validator.validateWithResult(entry.getResource());
        if (eresult.isSuccessful() == false) {
          for (SingleValidationMessage emessage : eresult.getMessages()) {
            if (emessage.getSeverity() == ResultSeverityEnum.ERROR
                || emessage.getSeverity() == ResultSeverityEnum.FATAL) {
              boolean valid = false;
              /*
               * There are a few bugs in the FHIR schematron files that are distributed with HAPI
               * 3.0.0 (these are fixed in the latest `master` branch), specifically with XPath
               * expressions.
               *
               * Two of these bugs are related to the FHIR Invariant rules obs-7 and con-4, which
               * have XPath expressions that incorrectly raise errors on validation.
               */
              if (emessage.getMessage().contains("Message=obs-7")) {
                /*
                 * The obs-7 invariant basically says that Observations should have values, unless
                 * they are made of components. This test replaces an invalid XPath expression
                 * that was causing correct instances to fail validation.
                 */
                valid = validateObs7((Observation) entry.getResource());
              } else if (emessage.getMessage().contains("Message=con-4")) {
                /*
                 * The con-4 invariant says "If condition is abated, then clinicalStatus must be
                 * either inactive, resolved, or remission" which is very clear and sensical.
                 * However, the XPath expression does not evaluate correctly for valid instances,
                 * so we must manually validate.
                 */
                valid = validateCon4((Condition) entry.getResource());
              }
              if (!valid) {
                System.out.println(parser.encodeResourceToString(entry.getResource()));
                System.out.println("ERROR: " + emessage.getMessage());
                validationErrors.add(emessage.getMessage());
              }
            }
          }
        }
      }
    }
    int y = validationErrors.size();
    if (x != y) {
      Exporter.export(person, System.currentTimeMillis());
    }
  }

  assertEquals(0, validationErrors.size());
}
 
开发者ID:synthetichealth,项目名称:synthea_java,代码行数:78,代码来源:FHIRExporterTest.java


注:本文中的ca.uhn.fhir.context.FhirContext.newValidator方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。