コード例 #1
0
  private void loadGlobalConceptDomains() throws Exception {
    logger.log("Load Concept Domains", LogMessageType.Process);

    BindingsParser parser =
        new BindingsParser(
            new CSFileInputStream(new CSFile(termDir + "bindings.xml")),
            termDir + "bindings.xml",
            srcDir,
            registry);
    List<BindingSpecification> cds = parser.parse();

    for (BindingSpecification cd : cds) {
      definitions.getBindings().put(cd.getName(), cd);
      definitions.getCommonBindings().add(cd);
    }

    for (BindingSpecification cd : definitions.getBindings().values()) {
      if (cd.getBinding() == BindingSpecification.Binding.CodeList) {
        if (!parser.loadCodes(cd)) {
          File file = new CSFile(termDir + cd.getReference().substring(1) + ".csv");
          if (!file.exists())
            throw new Exception(
                "code source file not found for " + cd.getName() + ": " + file.getAbsolutePath());
          CodeListParser cparser = new CodeListParser(new CSFileInputStream(file));
          cparser.parse(cd.getCodes());
          cparser.close();
        }
      }
      if (cd.getBinding() == Binding.ValueSet && !Utilities.noString(cd.getReference())) {
        if (cd.getReference().startsWith("http://hl7.org/fhir")) {
          // ok, it's a reference to a value set defined within this build. Since it's an absolute
          // reference, it's into the base infrastructure. That's not loaded yet, so we will try
          // to resolve it later
        } else if (new File(Utilities.appendSlash(termDir) + cd.getReference() + ".xml").exists()) {
          XmlParser p = new XmlParser();
          FileInputStream input =
              new FileInputStream(Utilities.appendSlash(termDir) + cd.getReference() + ".xml");
          cd.setReferredValueSet((ValueSet) p.parse(input));
        } else if (new File(Utilities.appendSlash(termDir) + cd.getReference() + ".json")
            .exists()) {
          JsonParser p = new JsonParser();
          FileInputStream input =
              new FileInputStream(Utilities.appendSlash(termDir) + cd.getReference() + ".json");
          cd.setReferredValueSet((ValueSet) p.parse(input));
        } else
          throw new Exception(
              "Unable to find source for "
                  + cd.getReference()
                  + " ("
                  + Utilities.appendSlash(termDir)
                  + cd.getReference()
                  + ".xml/json)");
      }
    }
  }
コード例 #2
0
  public void parse(Calendar genDate, String version) throws Exception {
    logger.log("Loading", LogMessageType.Process);

    eCoreParseResults = DefinitionsImpl.build(genDate.getTime(), version);

    loadGlobalConceptDomains();
    eCoreParseResults
        .getBinding()
        .addAll(
            sortBindings(
                BindingConverter.buildBindingsFromFhirModel(
                    definitions.getBindings().values(), null)));

    loadPrimitives();

    eCoreParseResults
        .getPrimitive()
        .addAll(
            PrimitiveConverter.buildPrimitiveTypesFromFhirModel(
                definitions.getPrimitives().values()));

    for (String n : ini.getPropertyNames("removed-resources"))
      definitions.getDeletedResources().add(n);

    for (String n : ini.getPropertyNames("types")) loadCompositeType(n, definitions.getTypes());
    for (String n : ini.getPropertyNames("structures"))
      loadCompositeType(n, definitions.getStructures());

    String[] shared = ini.getPropertyNames("shared");
    if (shared != null)
      for (String n : shared)
        definitions.getShared().add(loadCompositeType(n, definitions.getStructures()));

    for (String n : ini.getPropertyNames("infrastructure"))
      loadCompositeType(n, definitions.getInfrastructure());

    List<TypeDefn> allFhirComposites = new ArrayList<TypeDefn>();

    allFhirComposites.add(CompositeTypeConverter.buildElementBaseType());

    allFhirComposites.addAll(
        PrimitiveConverter.buildCompositeTypesForPrimitives(eCoreParseResults.getPrimitive()));

    allFhirComposites.addAll(
        CompositeTypeConverter.buildCompositeTypesFromFhirModel(
            definitions.getTypes().values(), null));

    allFhirComposites.addAll(
        CompositeTypeConverter.buildCompositeTypesFromFhirModel(
            definitions.getStructures().values(), null));

    List<CompositeTypeDefn> infra =
        CompositeTypeConverter.buildCompositeTypesFromFhirModel(
            definitions.getInfrastructure().values(), null);
    for (CompositeTypeDefn composite : infra) composite.setInfrastructure(true);
    allFhirComposites.addAll(infra);

    allFhirComposites.addAll(
        ConstrainedTypeConverter.buildConstrainedTypesFromFhirModel(
            definitions.getConstraints().values(), definitions.getConstraintInvariants()));

    eCoreParseResults.getType().addAll(sortTypes(allFhirComposites));

    for (String n : ini.getPropertyNames("resources"))
      loadResource(n, definitions.getResources(), false);

    ResourceDefn baseResource = loadResource("resource", null, false);
    baseResource.setAbstract(true);
    definitions.setBaseResource(baseResource);

    loadCompartments();
    loadStatusCodes();

    org.hl7.fhir.definitions.ecore.fhir.ResourceDefn eCoreBaseResource =
        CompositeTypeConverter.buildResourceFromFhirModel(baseResource, null);
    eCoreBaseResource.getElement().add(CompositeTypeConverter.buildInternalIdElement());
    eCoreParseResults.getType().add(eCoreBaseResource);

    eCoreParseResults
        .getType()
        .addAll(
            sortTypes(
                CompositeTypeConverter.buildResourcesFromFhirModel(
                    definitions.getResources().values())));

    eCoreParseResults.getType().add(CompositeTypeConverter.buildBinaryResourceDefn());

    for (String n : ini.getPropertyNames("svg"))
      definitions.getDiagrams().put(n, ini.getStringProperty("svg", n));

    if (ini.getPropertyNames("future-resources") != null)
      for (String n : ini.getPropertyNames("future-resources")) {
        DefinedCode cd =
            new DefinedCode(ini.getStringProperty("future-resources", n), "Yet to be defined", n);
        definitions.getKnownResources().put(n, cd);

        ResourceDefn futureResource = new ResourceDefn();
        futureResource.setName(cd.getCode());
        futureResource.setDefinition("Future resource " + cd.getCode() + ". As yet undefined.");
        futureResource.setForFutureUse(true);
        definitions.getFutureResources().put(cd.getCode(), futureResource);
      }

    eCoreParseResults
        .getType()
        .addAll(
            CompositeTypeConverter.buildResourcesFromFhirModel(
                definitions.getFutureResources().values()));

    eCoreParseResults
        .getEvent()
        .addAll(EventConverter.buildEventsFromFhirModel(definitions.getEvents().values()));

    // As a second pass, resolve typerefs to the types
    fixTypeRefs(eCoreParseResults);

    eCoreParseResults
        .getBinding()
        .add(BindingConverter.buildResourceTypeBinding(eCoreParseResults));

    for (String n : ini.getPropertyNames("special-resources"))
      definitions.getAggregationEndpoints().add(n);

    String[] pn = ini.getPropertyNames("valuesets");
    if (pn != null)
      for (String n : pn) {
        loadValueSet(n);
      }
    for (String n : ini.getPropertyNames("profiles")) {
      loadProfile(n, definitions.getProfiles());
    }

    for (ResourceDefn r : definitions.getResources().values()) {
      for (RegisteredProfile p : r.getProfiles()) {
        SpreadsheetParser sparser =
            new SpreadsheetParser(
                new CSFileInputStream(p.getFilepath()),
                p.getName(),
                definitions,
                srcDir,
                logger,
                registry);
        sparser.setFolder(Utilities.getDirectoryForFile(p.getFilepath()));
        p.setProfile(sparser.parseProfile(definitions));
      }
    }
  }