protected ElementDefn getRootDefinition() {
   ElementDefn el = null;
   ResourceDefn resource = definitions.getResources().get(name);
   resource = (resource == null) ? definitions.getBaseResources().get(name) : resource;
   if (resource != null) {
     el = resource.getRoot();
   } else {
     el = definitions.getInfrastructure().get(name);
     el = (el == null) ? definitions.getTypes().get(name) : el;
     el = (el == null) ? definitions.getStructures().get(name) : el;
   }
   return el;
 }
  private ResourceDefn loadResource(String n, Map<String, ResourceDefn> map, boolean sandbox)
      throws Exception {
    String src = sandbox ? sndBoxDir : srcDir;
    File spreadsheet =
        new CSFile(
            (sandbox ? sndBoxDir : srcDir) + n + File.separatorChar + n + "-spreadsheet.xml");
    if (!spreadsheet.exists())
      spreadsheet =
          new CSFile((sandbox ? sndBoxDir : srcDir) + n + File.separatorChar + n + "-def.xml");

    SpreadsheetParser sparser =
        new SpreadsheetParser(
            new CSFileInputStream(spreadsheet),
            spreadsheet.getName(),
            definitions,
            src,
            logger,
            registry);
    ResourceDefn root;
    try {
      root = sparser.parseResource();
    } catch (Exception e) {
      throw new Exception("Error Parsing Resource " + n + ": " + e.getMessage(), e);
    }

    root.setSandbox(sandbox);
    for (EventDefn e : sparser.getEvents()) processEvent(e, root.getRoot());

    // EK: Commented this out, seems double with next statement, since
    // loadResource()
    // is always called with definitions.getResources in its map argument.
    // definitions.getResources().put(root.getName(), root);
    if (map != null) {
      map.put(root.getName(), root);
      definitions
          .getKnownResources()
          .put(root.getName(), new DefinedCode(root.getName(), root.getRoot().getDefinition(), n));
    }
    root.setStatus(ini.getStringProperty("status", n));
    return root;
  }
Exemplo n.º 3
0
 private void gen(ResourceDefn rd) throws Exception {
   Section section = section(rd.getName());
   ElementDefn t = rd.getRoot();
   if (t.getTypes().isEmpty()) section.triple("fhir:" + t.getName(), "a", "rdfs:Class");
   else section.triple("fhir:" + t.getName(), "rdfs:subClassOf", processType(t.typeCode()));
   section.comment("fhir:" + t.getName(), rd.getDefinition());
   if (!Utilities.noString(t.getW5()))
     section.triple(
         "fhir:" + t.getName(), "fhir:w5", complex().predicate("a", "fhir:w5\\#" + t.getW5()));
   processMappings(section, "fhir:" + rd.getName(), rd.getRoot());
   for (ElementDefn e : t.getElements()) {
     if (e.getName().endsWith("[x]")) {
       String cn = e.getName().substring(0, e.getName().length() - 3);
       section.triple("fhir:" + t.getName() + "." + cn, "a", "rdf:Property");
       section.comment("fhir:" + t.getName() + "." + cn, e.getDefinition());
       processMappings(section, "fhir:" + t.getName() + "." + cn, e);
       for (TypeRef tr : e.typeCode().equals("*") ? getAnyTypes() : e.getTypes()) {
         String en = cn + Utilities.capitalize(tr.getName());
         section.triple(
             "fhir:" + t.getName() + "." + en,
             "rdfs:subPropertyOf",
             "fhir:" + t.getName() + "." + cn);
         section.triple("fhir:" + t.getName() + "." + en, "rdfs:domain", "fhir:" + rd.getName());
         genRange(section, t.getName(), en, e, tr, false);
       }
     } else {
       section.triple("fhir:" + t.getName() + "." + e.getName(), "a", "rdf:Property");
       section.comment("fhir:" + t.getName() + "." + e.getName(), e.getDefinition());
       section.triple(
           "fhir:" + t.getName() + "." + e.getName(), "rdfs:domain", "fhir:" + rd.getName());
       processMappings(section, "fhir:" + t.getName() + "." + e.getName(), e);
       genRange(
           section,
           t.getName(),
           e.getName(),
           e,
           e.getTypes().isEmpty() ? null : e.getTypes().get(0),
           false);
     }
   }
   processAnonTypes();
 }
  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));
      }
    }
  }