Example #1
0
        public ImplementationGuideGenerator(IObjectRepository tdb, int implementationGuideId, IEnumerable <int> templateIds)
        {
            this._tdb = tdb;
            this.implementationGuide = tdb.ImplementationGuides.Single(y => y.Id == implementationGuideId);
            this.schema = this.implementationGuide.ImplementationGuideType.GetSimpleSchema();

            this.igSettings = new IGSettingsManager(this._tdb, implementationGuideId);

            this.templates = (from tid in templateIds
                              join t in tdb.Templates on tid equals t.Id
                              select t).Distinct().ToList();
            this.templateRelationships = (from tr in this._tdb.ViewTemplateRelationships
                                          join tid in templateIds on tr.ParentTemplateId equals tid
                                          where templateIds.Contains(tr.ChildTemplateId)
                                          select tr)
                                         .Union(from tr in this._tdb.ViewTemplateRelationships
                                                join tid in templateIds on tr.ChildTemplateId equals tid
                                                where templateIds.Contains(tr.ParentTemplateId)
                                                select tr)
                                         .ToList();
            this.constraintReferences = (from t in this.templates
                                         join tc in this._tdb.TemplateConstraints on t.Id equals tc.TemplateId
                                         join tcr in this._tdb.TemplateConstraintReferences on tc.Id equals tcr.TemplateConstraintId
                                         join rt in this._tdb.Templates on tcr.ReferenceIdentifier equals rt.Oid
                                         select new ConstraintReference()
            {
                TemplateConstraintId = tc.Id,
                Name = rt.Name,
                Identifier = rt.Oid,
                Bookmark = rt.Bookmark,
                IncludedInIG = this.templates.Contains(rt)
            }).ToList();

            this.retiredStatus = PublishStatus.GetRetiredStatus(this._tdb);
        }
Example #2
0
        public void TestSimplifiedSchema_eMeasure()
        {
            SimpleSchema cdaSchema = SimpleSchema.CreateSimpleSchema(
                Trifolia.Shared.Helper.GetIGSimplifiedSchemaLocation(
                    new ImplementationGuideType()
            {
                Name           = "CDA",
                SchemaLocation = "CDA.xsd"
            }));

            cdaSchema = cdaSchema.GetSchemaFromContext("Observation");

            var foundClassCodeAttr = cdaSchema.Children.SingleOrDefault(y => y.Name == "classCode" && y.IsAttribute);

            Assert.IsNotNull(foundClassCodeAttr);

            var foundCode = cdaSchema.Children.SingleOrDefault(y => y.Name == "code" && !y.IsAttribute);

            Assert.IsNotNull(foundCode);

            var foundValue = cdaSchema.Children.SingleOrDefault(y => y.Name == "value" && !y.IsAttribute);

            Assert.IsNotNull(foundValue);

            var foundEntryRelationship = cdaSchema.Children.SingleOrDefault(y => y.Name == "entryRelationship" && !y.IsAttribute);

            Assert.IsNotNull(foundEntryRelationship);

            var foundObservation = foundEntryRelationship.Children.SingleOrDefault(y => y.Name == "observation" && !y.IsAttribute);

            Assert.IsNotNull(foundObservation);

            Assert.IsNotNull(cdaSchema);
        }
Example #3
0
        public byte[] Export(DB.IObjectRepository tdb, SimpleSchema schema, ExportFormats format, IGSettingsManager igSettings, List <string> categories, List <DB.Template> templates, bool includeVocabulary, bool returnJson = true)
        {
            var uri = HttpContext.Current != null && HttpContext.Current.Request != null ? HttpContext.Current.Request.Url : new Uri(AppSettings.DefaultBaseUrl);

            switch (format)
            {
            case ExportFormats.FHIR_Bundle:
                ImplementationGuideExporter      exporter = new ImplementationGuideExporter(tdb, schema, uri.Scheme, uri.Authority);
                fhir_dstu2.Hl7.Fhir.Model.Bundle bundle   = exporter.GetImplementationGuides(include: "ImplementationGuide:resource", implementationGuideId: igSettings.ImplementationGuideId);
                return(ConvertToBytes(fhir_dstu2.Hl7.Fhir.Serialization.FhirSerializer.SerializeResourceToXml(bundle)));

            case ExportFormats.Native_XML:
                NativeExporter proprietaryExporter = new NativeExporter(tdb, templates, igSettings, true, categories);

                if (returnJson)
                {
                    return(ConvertToBytes(proprietaryExporter.GenerateJSONExport()));
                }
                else
                {
                    return(ConvertToBytes(proprietaryExporter.GenerateXMLExport()));
                }

            case ExportFormats.Templates_DSTU_XML:
                DecorExporter decorExporter = new DecorExporter(templates, tdb, igSettings.ImplementationGuideId);
                return(ConvertToBytes(decorExporter.GenerateXML()));

            default:
                throw new Exception("Invalid export format for the specified implementation guide type");
            }
        }
Example #4
0
        public string Export(DB.IObjectRepository tdb, SimpleSchema schema, ExportFormats format, IGSettingsManager igSettings, List <string> categories, List <DB.Template> templates, bool includeVocabulary, bool returnJson = true)
        {
            switch (format)
            {
            case ExportFormats.FHIR:
                string export = FHIRExporter.GenerateExport(tdb, templates, igSettings, categories, includeVocabulary);

                if (returnJson)
                {
                    fhir_dstu1.Hl7.Fhir.Model.Bundle bundle = fhir_dstu1.Hl7.Fhir.Serialization.FhirParser.ParseBundleFromXml(export);
                    export = fhir_dstu1.Hl7.Fhir.Serialization.FhirSerializer.SerializeBundleToJson(bundle);
                }

                return(export);

            case ExportFormats.Proprietary:
                NativeExporter proprietaryExporter = new NativeExporter(tdb, templates, igSettings, true, categories);
                return(proprietaryExporter.GenerateXMLExport());

            case ExportFormats.TemplatesDSTU:
                DecorExporter decorExporter = new DecorExporter(templates, tdb, igSettings.ImplementationGuideId);
                return(decorExporter.GenerateXML());

            case ExportFormats.Snapshot:

            default:
                throw new Exception("Invalid export format for the specified implementation guide type");
            }
        }
Example #5
0
        public void MyTestInitialize()
        {
            this.cdaSchema = SimpleSchema.CreateSimpleSchema(Trifolia.Shared.Helper.GetIGSimplifiedSchemaLocation(
                                                                 new ImplementationGuideType()
            {
                Name           = "CDA",
                SchemaLocation = "CDA.xsd"
            }));

            this.eMeasureSchema = SimpleSchema.CreateSimpleSchema(Trifolia.Shared.Helper.GetIGSimplifiedSchemaLocation(
                                                                      new ImplementationGuideType()
            {
                Name           = "eMeasure",
                SchemaLocation = "schemas/EMeasure.xsd"
            }));

            this.fhirSchema = SimpleSchema.CreateSimpleSchema(Trifolia.Shared.Helper.GetIGSimplifiedSchemaLocation(
                                                                  new ImplementationGuideType()
            {
                Name           = MockObjectRepository.DEFAULT_FHIR_DSTU1_IG_TYPE_NAME,
                SchemaLocation = "fhir-all.xsd"
            }));

            Assert.IsNotNull(this.eMeasureSchema);
            Assert.IsNotNull(this.cdaSchema);
            Assert.IsNotNull(this.fhirSchema);
        }
Example #6
0
        public void Setup()
        {
            this.tdb.InitializeCDARepository();

            this.ig         = this.tdb.FindOrAddImplementationGuide(this.tdb.FindImplementationGuideType("CDA"), "Test IG");
            this.mainSchema = this.tdb.FindImplementationGuideType("CDA").GetSimpleSchema();
        }
 protected AssertionLineBuilder(IObjectRepository tdb, ImplementationGuideType igType, SimpleSchema igTypeSchema, string prefix)
 {
     this._igTypeSchema = igTypeSchema;
     this._tdb          = tdb;
     this._prefix       = prefix;
     this._igType       = igType;
 }
Example #8
0
        public ConstraintParser(IObjectRepository tdb,
                                IConstraint constraint,
                                ImplementationGuideType igType,
                                SimpleSchema igTypeSchema,
                                IEnumerable <Template> allTemplates,
                                string valueSetFile = "voc.xml",
                                VocabularyOutputType vocabularyOutputType = VocabularyOutputType.Default)
        {
            this.tdb          = tdb;
            this.constraint   = constraint;
            this.valueSetFile = valueSetFile;
            this.igType       = igType;
            this.igTypeSchema = igTypeSchema;
            this.allTemplates = allTemplates;
            this.igTypePlugin = igType.GetPlugin();

            if (!string.IsNullOrEmpty(this.constraint.Cardinality))
            {
                this.constraintCardinalityType = CardinalityParser.Parse(this.constraint.Cardinality);
            }

            if (!string.IsNullOrEmpty(this.constraint.Conformance))
            {
                this.constraintConformanceType = ConformanceParser.Parse(this.constraint.Conformance);
            }

            this.prefix = igType.SchemaPrefix;

            this.vocabularyOutputType = vocabularyOutputType;
        }
        public void Setup()
        {
            this.tdb.InitializeCDARepository();

            this.ig         = this.tdb.FindOrCreateImplementationGuide(this.tdb.FindImplementationGuideType(Constants.IGTypeNames.CDA), "Test IG");
            this.mainSchema = this.tdb.FindImplementationGuideType(Constants.IGTypeNames.CDA).GetSimpleSchema();
        }
Example #10
0
        public IEnumerable <SchemaNode> GetSchemaNodes(int implementationGuideId, string parentType = null, bool includeAttributes = true)
        {
            if (!CheckPoint.Instance.GrantViewImplementationGuide(implementationGuideId))
            {
                throw new AuthorizationException("You do not have permission to view this implementation guide");
            }

            ImplementationGuide ig     = this.tdb.ImplementationGuides.Single(y => y.Id == implementationGuideId);
            SimpleSchema        schema = SimplifiedSchemaContext.GetSimplifiedSchema(HttpContext.Current.Application, ig.ImplementationGuideType);
            List <SimpleSchema.SchemaObject> children;

            if (!string.IsNullOrEmpty(parentType))
            {
                schema   = schema.GetSchemaFromContext(parentType);
                children = schema.Children;
            }
            else
            {
                children = schema.Children[0].Children;
            }

            var ret = (from s in children
                       where includeAttributes || !s.IsAttribute
                       select new SchemaNode()
            {
                Context = s.IsAttribute ? "@" + s.Name : s.Name,
                Conformance = s.Conformance,
                Cardinality = s.Cardinality,
                DataType = s.DataType,
                HasChildren = s.Children.Where(y => includeAttributes || !y.IsAttribute).Count() > 0
            });

            return(ret);
        }
Example #11
0
        public List <ValidationResult> ValidateTemplate(int templateId)
        {
            Template     template = this.tdb.Templates.Single(y => y.Id == templateId);
            SimpleSchema igSchema = template.OwningImplementationGuide.ImplementationGuideType.GetSimpleSchema();

            return(ValidateTemplate(template, igSchema));
        }
Example #12
0
        public void MyTestInitialize()
        {
            this.cdaSchema = SimpleSchema.CreateSimpleSchema(Trifolia.Shared.Helper.GetIGSimplifiedSchemaLocation(
                                                                 new ImplementationGuideType()
            {
                Name           = Constants.IGTypeNames.CDA,
                SchemaLocation = Constants.IGTypeSchemaLocations.CDA
            }));

            this.eMeasureSchema = SimpleSchema.CreateSimpleSchema(Trifolia.Shared.Helper.GetIGSimplifiedSchemaLocation(
                                                                      new ImplementationGuideType()
            {
                Name           = Constants.IGTypeNames.EMEASURE,
                SchemaLocation = "schemas/EMeasure.xsd"
            }));

            this.hqmfSchema = SimpleSchema.CreateSimpleSchema(Trifolia.Shared.Helper.GetIGSimplifiedSchemaLocation(
                                                                  new ImplementationGuideType()
            {
                Name           = Constants.IGTypeNames.HQMF,
                SchemaLocation = "schemas/EMeasure.xsd"
            }));

            Assert.IsNotNull(this.eMeasureSchema);
            Assert.IsNotNull(this.cdaSchema);
            Assert.IsNotNull(this.hqmfSchema);
        }
 /// <summary>
 /// Initializes a new instance of ImplementationGuideExporter
 /// </summary>
 /// <param name="tdb">Reference to the database</param>
 /// <param name="scheme">The server url's scheme</param>
 /// <param name="authority">The server url's authority</param>
 public ImplementationGuideExporter(IObjectRepository tdb, SimpleSchema schema, string scheme, string authority)
 {
     this.tdb       = tdb;
     this.scheme    = scheme;
     this.authority = authority;
     this.schema    = schema;
     this.implementationGuideType = LatestHelper.GetImplementationGuideType(this.tdb, true);
 }
        public void Setup()
        {
            this.tdb = new MockObjectRepository();
            this.tdb.InitializeCDARepository();

            this.igType       = this.tdb.FindImplementationGuideType(Constants.IGTypeNames.CDA);
            this.igTypeSchema = this.igType.GetSimpleSchema();
        }
Example #15
0
        public IHttpActionResult UpdateStructureDefinition(
            [FromBody] StructureDefinition strucDef,
            [FromUri] string bookmark)
        {
            Template existingTemplate = this.tdb.Templates.SingleOrDefault(y => y.Bookmark.ToLower().Trim() == bookmark.ToLower().Trim());

            // Make sure the profile exists
            if (existingTemplate == null)
            {
                return(CreateErrorResponse(App_GlobalResources.TrifoliaLang.TemplateNotFoundMessageFormat));
            }

            if (!CheckPoint.Instance.GrantEditTemplate(existingTemplate.Id))
            {
                throw new UnauthorizedAccessException();
            }

            var uri = HttpContext.Current != null && HttpContext.Current.Request != null ? HttpContext.Current.Request.Url : new Uri(AppSettings.DefaultBaseUrl);
            StructureDefinitionImporter importer = new StructureDefinitionImporter(this.tdb, uri.Scheme, uri.Authority);
            StructureDefinitionExporter exporter = new StructureDefinitionExporter(this.tdb, uri.Scheme, uri.Authority);

            Template updatedTemplate;

            try
            {
                User author = CheckPoint.Instance.GetUser(this.tdb);
                updatedTemplate = importer.Convert(strucDef, existingTemplate, author);
            }
            catch (Exception ex)
            {
                return(CreateErrorResponse(ex.Message, OperationOutcome.IssueType.Exception));
            }

            if (existingTemplate == null)
            {
                this.tdb.Templates.Add(updatedTemplate);
            }

            this.tdb.SaveChanges();

            string location = string.Format("{0}://{1}/api/FHIR3/StructureDefinition/{2}",
                                            this.Request.RequestUri.Scheme,
                                            this.Request.RequestUri.Authority,
                                            updatedTemplate.Id);

            Dictionary <string, string> headers = new Dictionary <string, string>();

            headers.Add("Location", location);

            SimpleSchema schema = SimplifiedSchemaContext.GetSimplifiedSchema(HttpContext.Current, updatedTemplate.ImplementationGuideType);

            schema = schema.GetSchemaFromContext(updatedTemplate.PrimaryContextType);

            StructureDefinition updatedStrucDef = exporter.Convert(updatedTemplate, schema);

            return(Content <Resource>((existingTemplate == null ? HttpStatusCode.Created : HttpStatusCode.OK), updatedStrucDef, headers));
        }
Example #16
0
        private static (Endpoint endpoint, IEnumerable <ISchema> schemas) ReturnsRealEndpoint()
        {
            var numberSchema = new SimpleSchema(SchemaType.Number);
            var stringSchema = new SimpleSchema(SchemaType.String);

            var responseSchema = new ClassSchema(
                Response,
                new Dictionary <string, ISchema>
            {
                { StringKey, stringSchema }
            },
                new List <string>()
                );

            var requestSchema = new ClassSchema(
                Request,
                new Dictionary <string, ISchema>
            {
                { NumberKey, numberSchema },
                { StringKey, stringSchema },
            }, new List <string>()
                );

            var endpoint = new Endpoint(
                OperationId, Path,
                EndpointType.Get,
                new HashSet <IParameter>
            {
                new Parameter(
                    "parameter",
                    ParameterType.Header,
                    stringSchema,
                    false,
                    false,
                    false
                    )
            },
                new RequestBody(
                    new Dictionary <string, ISchema>
            {
                { ApplicationJson, requestSchema },
            },
                    true),
                new[]
            {
                new HttpResponse(
                    200,
                    new Response(new Dictionary <string, ISchema>
                {
                    { ApplicationJson, responseSchema }
                })),
            });

            return(endpoint, new List <ISchema>
            {
                numberSchema, stringSchema, requestSchema, responseSchema
            });
        public IHttpActionResult CreateStructureDefinition(
            [FromBody] StructureDefinition strucDef)
        {
            if (!string.IsNullOrEmpty(strucDef.Id))
            {
                OperationOutcome error = new OperationOutcome();
                error.Issue.Add(new OperationOutcome.IssueComponent()
                {
                    Severity    = OperationOutcome.IssueSeverity.Error,
                    Diagnostics = App_GlobalResources.TrifoliaLang.CreateFHIR2TemplateFailedDuplicateId
                });
                return(Content <OperationOutcome>(HttpStatusCode.BadRequest, error));
            }

            var foundProfile = this.tdb.Templates.SingleOrDefault(y => y.Oid == strucDef.Url);

            if (foundProfile != null)
            {
                OperationOutcome oo = new OperationOutcome()
                {
                    Issue = new List <OperationOutcome.IssueComponent> {
                        new OperationOutcome.IssueComponent()
                        {
                            Severity    = OperationOutcome.IssueSeverity.Error,
                            Code        = OperationOutcome.IssueType.Duplicate,
                            Diagnostics = "A StructureDefinition with the same url already exists. To update, use PUT."
                        }
                    }
                };

                return(Content <OperationOutcome>(HttpStatusCode.Created, oo));
            }

            var template = CreateTemplate(strucDef);

            this.tdb.SaveChanges();

            string location = string.Format("{0}://{1}/api/FHIR3/StructureDefinition/{2}",
                                            this.Request.RequestUri.Scheme,
                                            this.Request.RequestUri.Authority,
                                            template.Id);

            Dictionary <string, string> headers = new Dictionary <string, string>();

            headers.Add("Location", location);

            var uri = HttpContext.Current != null && HttpContext.Current.Request != null ? HttpContext.Current.Request.Url : new Uri(AppSettings.DefaultBaseUrl);
            StructureDefinitionExporter exporter = new StructureDefinitionExporter(this.tdb, uri.Scheme, uri.Authority);
            SimpleSchema schema = SimplifiedSchemaContext.GetSimplifiedSchema(HttpContext.Current, template.ImplementationGuideType);

            schema = schema.GetSchemaFromContext(template.PrimaryContextType);

            StructureDefinition newStrucDef = exporter.Convert(template, schema);

            return(Content <StructureDefinition>(HttpStatusCode.Created, newStrucDef, headers));
        }
        public IHttpActionResult GetTemplate(
            [FromUri] string templateId,
            [FromUri(Name = "_summary")] SummaryType?summary = null)
        {
            Template template = this.tdb.Templates.SingleOrDefault(y => y.Oid == this.Request.RequestUri.AbsoluteUri || y.Id.ToString() == templateId);

            // Return an operation outcome indicating that the profile was not found
            if (template == null)
            {
                OperationOutcome oo = new OperationOutcome();
                oo.Issue.Add(new OperationOutcome.OperationOutcomeIssueComponent()
                {
                    Severity    = OperationOutcome.IssueSeverity.Fatal,
                    Diagnostics = "Profile was not found"
                });

                return(Content <OperationOutcome>(HttpStatusCode.NotFound, oo));
            }

            // Redirect the user to the Trifolia web interface if an acceptable format is text/html, and no format or summary was specified
            if (Request.Headers.Accept.Any(y => y.MediaType == "text/html") && summary == null)
            {
                Dictionary <string, string> headers = new Dictionary <string, string>();
                headers.Add("Location", Request.RequestUri.Scheme + "://" + Request.RequestUri.Authority + "/TemplateManagement/View/Id/" + template.Id);

                OperationOutcome redirectOutcome = new OperationOutcome();
                redirectOutcome.Issue.Add(new OperationOutcome.OperationOutcomeIssueComponent()
                {
                    Severity    = OperationOutcome.IssueSeverity.Information,
                    Diagnostics = "Detecting browser-based request, redirecting to Trifolia web interface."
                });

                return(Content <OperationOutcome>(HttpStatusCode.Redirect, redirectOutcome, headers));
            }

            if (template.TemplateType.ImplementationGuideType != this.implementationGuideType)
            {
                throw new FormatException(App_GlobalResources.TrifoliaLang.TemplateNotFHIRSTU3);
            }

            if (!CheckPoint.Instance.GrantViewTemplate(template.Id))
            {
                throw new UnauthorizedAccessException();
            }

            var uri = HttpContext.Current != null && HttpContext.Current.Request != null ? HttpContext.Current.Request.Url : new Uri(AppSettings.DefaultBaseUrl);
            StructureDefinitionExporter exporter = new StructureDefinitionExporter(this.tdb, uri.Scheme, uri.Authority);
            SimpleSchema schema = SimplifiedSchemaContext.GetSimplifiedSchema(HttpContext.Current, template.ImplementationGuideType);

            schema = schema.GetSchemaFromContext(template.PrimaryContextType);

            StructureDefinition strucDef = exporter.Convert(template, schema, summary);

            return(Content <StructureDefinition>(HttpStatusCode.OK, strucDef));
        }
Example #19
0
        public BuildExporter(IObjectRepository tdb, int implementationGuideId, IEnumerable <Template> templates = null)
        {
            this.tdb = tdb;

            this.ig        = this.tdb.ImplementationGuides.SingleOrDefault(y => y.Id == implementationGuideId);
            this.templates = templates ?? this.ig.GetRecursiveTemplates(this.tdb);

            this.schema          = this.ig.ImplementationGuideType.GetSimpleSchema();
            this.igName          = this.ig.Name.Replace(" ", "_");
            this.controlFileName = this.igName + ".json";
        }
        public GreenTransformGenerator(IObjectRepository tdb, Dictionary <int, int> greenTemplates, long templateId)
            : this(tdb)
        {
            this.rootTemplate    = tdb.Templates.Single(y => y.Id == templateId);
            this.greenTemplates  = greenTemplates;
            this.schemaNamespace = this.rootTemplate.ImplementationGuideType.SchemaURI;
            this.simpleSchema    =
                SimpleSchema.CreateSimpleSchema(
                    Helper.GetIGSimplifiedSchemaLocation(this.rootTemplate.ImplementationGuideType));

            TransformHelper.InitializeTransform(this.transformDoc, this.schemaNamespace);
        }
Example #21
0
        public void GetSchemaFromContext()
        {
            SimpleSchema observationSchema = this.cdaSchema.GetSchemaFromContext("Observation");

            Assert.IsNotNull(observationSchema, "Expected GetSchemaFromContext to return a non-null value for Observation.");
            Assert.AreNotEqual(0, observationSchema.Children, "Expected the returned schema to have children.");

            List <SimpleSchema.SchemaObject> observationIds = observationSchema.Children.Where(y => y.Name == "id" && y.IsAttribute == false).ToList();

            Assert.AreNotEqual(0, observationIds.Count, "Expected the returned schema to have a child id element.");
            Assert.AreEqual(1, observationIds.Count, "Expected the returned schema to have only one child id element.");
        }
        public HttpResponseMessage GetImplementationGuide(
            int implementationGuideId,
            [FromUri(Name = "_format")] string format = null,
            [FromUri(Name = "_summary")] fhir_stu3.Hl7.Fhir.Rest.SummaryType?summary = null)
        {
            var          uri = HttpContext.Current != null && HttpContext.Current.Request != null ? HttpContext.Current.Request.Url : new Uri(AppSettings.DefaultBaseUrl);
            var          implementationGuide = this.tdb.ImplementationGuides.Single(y => y.Id == implementationGuideId);
            SimpleSchema schema = SimplifiedSchemaContext.GetSimplifiedSchema(HttpContext.Current.Application, implementationGuide.ImplementationGuideType);
            ImplementationGuideExporter exporter = new ImplementationGuideExporter(this.tdb, schema, uri.Scheme, uri.Authority);
            FhirImplementationGuide     response = exporter.Convert(implementationGuide, summary);

            return(Shared.GetResponseMessage(this.Request, format, response));
        }
Example #23
0
        public TemplateContextBuilder(IObjectRepository tdb, ImplementationGuideType igType, SimpleSchema igTypeSchema, string prefix = null)
        {
            this.tdb          = tdb;
            this.igType       = igType;
            this.plugin       = this.igType.GetPlugin();
            this.igTypeSchema = igTypeSchema;
            this.prefix       = !string.IsNullOrEmpty(prefix) ? prefix : igType.SchemaPrefix;

            if (!string.IsNullOrEmpty(this.prefix) && this.prefix.EndsWith(":"))
            {
                this.prefix = this.prefix.Substring(0, this.prefix.Length - 1);
            }
        }
Example #24
0
        public virtual List <ValidationResult> ValidateTemplate(Template template, SimpleSchema igSchema, IEnumerable <Template> allContainedTemplates = null)
        {
            SimpleSchema templateSchema = template.GetSchema(igSchema);

            List <ValidationResult> results = new List <ValidationResult>();

            var igType = template.ImplementationGuideType;

            if (igType.SchemaURI == ImplementationGuideType.FHIR_NS)
            {
                if (!template.IsIdentifierURL())
                {
                    results.Add(ValidationResult.CreateResult(ValidationLevels.Error, "FHIR profiles should use HTTP(S) identifiers."));
                }

                if (template.Oid.IndexOf("_") >= 0)
                {
                    results.Add(ValidationResult.CreateResult(ValidationLevels.Warning, "FHIR profile's long identifier should use - (dash) instead of _ (underscore)"));
                }

                if (template.Bookmark.IndexOf("_") >= 0)
                {
                    results.Add(ValidationResult.CreateResult(ValidationLevels.Warning, "FHIR profile's short identifier should use - (dash) instead of _ (underscore)"));
                }

                if (template.IsIdentifierURL() && !template.Oid.EndsWith(template.Bookmark))
                {
                    results.Add(ValidationResult.CreateResult(ValidationLevels.Error, "FHIR profile's long identifier should end with the short identifier"));
                }
            }

            XmlDocument    tempDoc        = new XmlDocument();
            XPathNavigator xpathNavigator = tempDoc.CreateNavigator();

            if (templateSchema == null)
            {
                results.Add(
                    ValidationResult.CreateResult(ValidationLevels.Error, "Template context is not found within the schema"));
            }
            else
            {
                List <TemplateConstraint> rootConstraints = template.ChildConstraints.Where(y => y.ParentConstraintId == null).ToList();
                rootConstraints.ForEach(y =>
                {
                    // The first child in the schema is the complex type itself
                    ValidateTemplateConstraint(template, xpathNavigator, results, templateSchema, templateSchema.Children, y, allContainedTemplates);
                });
            }

            return(results);
        }
        public HttpResponseMessage GetImplementationGuides(
            [FromUri(Name = "_format")] string format = null,
            [FromUri(Name = "_summary")] fhir_stu3.Hl7.Fhir.Rest.SummaryType?summary = null,
            [FromUri(Name = "_include")] string include       = null,
            [FromUri(Name = "_id")] int?implementationGuideId = null,
            [FromUri(Name = "name")] string name = null)
        {
            var          uri    = HttpContext.Current != null && HttpContext.Current.Request != null ? HttpContext.Current.Request.Url : new Uri(AppSettings.DefaultBaseUrl);
            SimpleSchema schema = SimplifiedSchemaContext.GetSimplifiedSchema(HttpContext.Current.Application, this.implementationGuideType);
            ImplementationGuideExporter exporter = new ImplementationGuideExporter(this.tdb, schema, uri.Scheme, uri.Authority);
            var bundle = exporter.GetImplementationGuides(summary, include, implementationGuideId, name);

            return(Shared.GetResponseMessage(this.Request, format, bundle));
        }
Example #26
0
        public void TestObservationDataTypes()
        {
            SimpleSchema observationSchema = this.cdaSchema.GetSchemaFromContext("Observation");
            var          children          = observationSchema.Children;

            Assert.AreEqual(children[0].Name, "nullFlavor");
            Assert.AreEqual(children[0].IsAttribute, true);
            Assert.AreEqual(children[1].Name, "classCode");
            Assert.AreEqual(children[1].IsAttribute, true);
            Assert.AreEqual(children[2].Name, "moodCode");
            Assert.AreEqual(children[2].IsAttribute, true);
            Assert.AreEqual(children[3].Name, "negationInd");
            Assert.AreEqual(children[3].IsAttribute, true);
            Assert.AreEqual(children[4].Name, "realmCode");
            Assert.AreEqual(children[4].IsAttribute, false);
            Assert.AreEqual(children[5].Name, "typeId");
            Assert.AreEqual(children[5].IsAttribute, false);
            Assert.AreEqual(children[6].Name, "templateId");
            Assert.AreEqual(children[6].IsAttribute, false);
            Assert.AreEqual(children[7].Name, "id");
            Assert.AreEqual(children[7].IsAttribute, false);
            Assert.AreEqual(children[8].Name, "code");
            Assert.AreEqual(children[8].IsAttribute, false);
            Assert.AreEqual(children[9].Name, "derivationExpr");
            Assert.AreEqual(children[10].Name, "text");
            Assert.AreEqual(children[11].Name, "statusCode");
            Assert.AreEqual(children[12].Name, "effectiveTime");
            Assert.AreEqual(children[13].Name, "priorityCode");
            Assert.AreEqual(children[14].Name, "repeatNumber");
            Assert.AreEqual(children[15].Name, "languageCode");
            Assert.AreEqual(children[16].Name, "value");
            Assert.AreEqual(children[17].Name, "interpretationCode");
            Assert.AreEqual(children[18].Name, "methodCode");
            Assert.AreEqual(children[18].DataType, "CE");
            Assert.AreEqual(children[19].Name, "targetSiteCode");
            Assert.AreEqual(children[19].DataType, "CD");
            Assert.AreEqual(children[20].Name, "subject");
            Assert.AreEqual(children[21].Name, "specimen");
            Assert.AreEqual(children[22].Name, "performer");
            Assert.AreEqual(children[23].Name, "author");
            Assert.AreEqual(children[24].Name, "informant");
            Assert.AreEqual(children[25].Name, "participant");
            Assert.AreEqual(children[26].Name, "entryRelationship");
            Assert.AreEqual(children[27].Name, "reference");
            Assert.AreEqual(children[28].Name, "precondition");
            Assert.AreEqual(children[29].Name, "sdtc:precondition2");
            Assert.AreEqual(children[30].Name, "referenceRange");
            Assert.AreEqual(children[31].Name, "sdtc:inFulfillmentOf1");
        }
Example #27
0
        public void AssertStaticSimple()
        {
            var env    = new ConsoleEnvironment(0, verbose: true);
            var schema = new SimpleSchema(env,
                                          P("hello", TextType.Instance),
                                          P("my", new VectorType(NumberType.I8, 5)),
                                          P("friend", new KeyType(DataKind.U4, 0, 3)));
            var view = new EmptyDataView(env, schema);

            view.AssertStatic(env, c => (
                                  my: c.I8.Vector,
                                  friend: c.KeyU4.NoValue.Scalar,
                                  hello: c.Text.Scalar
                                  ));
        }
Example #28
0
        public BuildExporter(IObjectRepository tdb, int implementationGuideId, IEnumerable <Template> templates = null, bool jsonFormat = false)
        {
            this.tdb = tdb;

            this.ig           = this.tdb.ImplementationGuides.SingleOrDefault(y => y.Id == implementationGuideId);
            this.igTypePlugin = this.ig.ImplementationGuideType.GetPlugin();
            this.templates    = templates ?? this.ig.GetRecursiveTemplates(this.tdb);

            this.schema          = this.ig.ImplementationGuideType.GetSimpleSchema();
            this.igName          = this.ig.Name.Replace(" ", "_");
            this.controlFileName = "ig.json";
            this.JsonFormat      = jsonFormat;

            this.dataExamples = new DataExamples();
        }
Example #29
0
        public static SimpleSchema GetSimplifiedSchema(HttpApplicationState application, ImplementationGuideType igType)
        {
            if (application != null && application[igType.Name] != null)
            {
                return((SimpleSchema)application[igType.Name]);
            }

            SimpleSchema newSimplifiedSchema =
                SimpleSchema.CreateSimpleSchema(Trifolia.Shared.Helper.GetIGSimplifiedSchemaLocation(igType));

            if (application != null)
            {
                application.Add(igType.Name, newSimplifiedSchema);
            }

            return(newSimplifiedSchema);
        }
Example #30
0
        protected override void ProcessRecord()
        {
            ImplementationGuide ig         = this.tdb.ImplementationGuides.Single(y => y.Id == this.ImplementationGuideId);
            SimpleSchema        schema     = ig.ImplementationGuideType.GetSimpleSchema();
            IGSettingsManager   igSettings = new IGSettingsManager(this.tdb, ig.Id);
            var    templates = ig.GetRecursiveTemplates(this.tdb);
            string export    = ig.ImplementationGuideType.GetPlugin().Export(this.tdb, schema, this.Format, igSettings, null, templates, this.IncludeVocab, this.ReturnJson);

            if (!string.IsNullOrEmpty(this.OutputFileName))
            {
                File.WriteAllText(this.OutputFileName, export);
            }
            else
            {
                this.WriteObject(export);
            }
        }