Exemple #1
0
        internal static MohawkCollege.EHR.gpmr.COR.Class Parse(ClassBase cls, string vocabularyBindingRealm, ClassRepository cr, Dictionary <string, Package> derivationSuppliers)
        {
            // Return value
            MohawkCollege.EHR.gpmr.COR.Class retVal = new MohawkCollege.EHR.gpmr.COR.Class();

            // Name of the class
            retVal.Name = cls.Name;

            // Identify where this class came from
            retVal.DerivedFrom = cls;

            // Set the business name
            foreach (BusinessName bn in cls.BusinessName)
            {
                if (bn.Language == MifCompiler.Language || bn.Language == null)
                {
                    retVal.BusinessName = bn.Name;
                }
            }

            // Set the documentation & Copyright
            retVal.Documentation = new MohawkCollege.EHR.gpmr.COR.Documentation();
            if (cls.Annotations != null)
            {
                retVal.Documentation = DocumentationParser.Parse(cls.Annotations.Documentation);
            }
            if (cls.Container.Header.Copyright != null)
            {
                retVal.Documentation.Copyright = string.Format("Copyright (C){0}, {1}", cls.Container.Header.Copyright.Year,
                                                               cls.Container.Header.Copyright.Owner);
            }

            // Set abstractiveness of the class
            retVal.IsAbstract = cls.IsAbstract;

            // Sort the properties and add them to the class
            cls.Attribute.Sort(new ClassAttribute.Comparator());
            retVal.Content = new List <ClassContent>();
            foreach (ClassAttribute ca in cls.Attribute)
            {
                if (ca.Conformance == ConformanceKind.NotPermitted)
                {
                    continue;
                }
                MohawkCollege.EHR.gpmr.COR.Property prp = PropertyParser.Parse(ca, vocabularyBindingRealm, cr, derivationSuppliers);
                prp.Container = retVal;
                retVal.AddContent(prp);
            }

            // Set sort key
            retVal.SortKey = cls.SortKey;

            // Return
            return(retVal);
        }
Exemple #2
0
        internal static CommonTypeReference Parse(CommonModelElement cme, ClassRepository memberOf)
        {
            CommonTypeReference retVal = new CommonTypeReference();

            retVal.Name    = cme.Name;
            retVal.SortKey = cme.SortKey;

            // Annotations
            if (cme.Annotations != null)
            {
                retVal.Documentation = DocumentationParser.Parse(cme.Annotations.Documentation);
            }

            retVal.DerivedFrom = cme;

            // Create a type reference
            retVal.Class = new TypeReference();

            // Entry Class specified?
            if (cme.EntryClass == null)
            {
                // Need to find it
                Package p = (Package)cme.Container.MemberOfRepository.Find(cme.BoundStaticModel);
                if (p is GlobalStaticModel && (p as GlobalStaticModel).OwnedEntryPoint.Count > 0)
                {
                    cme.EntryClass      = new SpecializationClass();
                    cme.EntryClass.Name = (p as GlobalStaticModel).OwnedEntryPoint[0].ClassName;
                }
                else if (p != null)
                {
                    throw new InvalidOperationException(string.Format("Can't determine the entry point for '{0}'!", p.PackageLocation.ToString(MifCompiler.NAME_FORMAT)));
                }
                else
                {
                    return(null); // Can't find the package
                }
            }

            retVal.Class.Name = string.Format("{0}.{1}", cme.BoundStaticModel.ToString(MifCompiler.NAME_FORMAT), cme.EntryClass.Name);

            // Pseudo Heiarchy to get back to the class repository
            retVal.MemberOf       = memberOf;
            retVal.Class.MemberOf = memberOf;

            // Classifier code
            retVal.ClassifierCode = cme.SupplierStructuralDomain.Code.Code;

            // Notify complete
            retVal.FireParsed();

            // Now return
            return(retVal);
        }
        /// <summary>
        /// Parse a COR state that belongs to a state machine from a MIF 2.0 state
        /// </summary>
        private static MohawkCollege.EHR.gpmr.COR.State Parse(MohawkCollege.EHR.HL7v3.MIF.MIF20.State st)
        {
            State retVal = new State();

            if (st.Annotations != null)
            {
                retVal.Documentation = DocumentationParser.Parse(st.Annotations.Documentation);
            }
            retVal.Name            = st.Name;
            retVal.ParentStateName = st.ParentStateName;
            //retVal.ChildStates = new Dictionary<string, State>();

            return(retVal);
        }
        public static MohawkCollege.EHR.gpmr.COR.SubSystem Parse(GlobalStaticModel p)
        {
            MohawkCollege.EHR.gpmr.COR.SubSystem retVal = Parse(p as Package);

            // Backup copyright
            string copy = retVal.Documentation.Copyright;

            // Parse documentation
            if (p.Annotations != null)
            {
                retVal.Documentation = DocumentationParser.Parse(p.Annotations.Documentation);
            }
            else
            {
                retVal.Documentation = new MohawkCollege.EHR.gpmr.COR.Documentation();
            }

            retVal.Documentation.Copyright = copy;

            UpdateLegalInfo(retVal.Documentation, p.Header);

            // TODO: AppInfo here

            // Business name of the entry point overrides the business name of the subsystem
            if (retVal.BusinessName == null && p.OwnedEntryPoint != null && p.OwnedEntryPoint[0].BusinessName != null)
            {
                foreach (BusinessName bn in p.OwnedEntryPoint[0].BusinessName)
                {
                    if (bn.Language == MifCompiler.Language || bn.Language == "")
                    {
                        retVal.BusinessName = bn.Name;
                    }
                }
            }

            // Fire parsed event. This will trigger any class repositories in the current app domain
            // to add the feature to their repository
            retVal.FireParsed();

            return(retVal);
        }
        /// <summary>
        /// Parses a StaticModelClassTemplateParameter into a COR type parameter
        /// </summary>
        /// <param name="parm">The static mode template parameter to parse from the MIF</param>
        /// <returns>The compiled type parameter</returns>
        internal static TypeParameter Parse(StaticModelClassTemplateParameter parm)
        {
            TypeParameter retVal = parm.Interface == null ? new TypeParameter() : (TypeParameter)TypeReferenceParser.Parse(parm.Interface);

            // Documentation
            if (parm.Annotations != null)
            {
                retVal.Documentation = DocumentationParser.Parse(parm.Annotations.Documentation);
            }

            // Name of the parameter
            retVal.ParameterName = parm.Name;

            // Business name
            foreach (BusinessName bn in parm.BusinessName ?? new List <BusinessName>())
            {
                if (bn.Language == MifCompiler.Language || bn.Language == null)
                {
                    retVal.BusinessName = bn.Name;
                }
            }

            return(retVal);
        }
Exemple #6
0
        /// <summary>
        /// Parse the specified stub as a common model element reference
        /// </summary>
        internal static CommonTypeReference Parse(StubDefinition stub, ClassRepository classRepository)
        {
            CommonTypeReference retVal = new CommonTypeReference();

            // Create the return value basic parameters
            retVal.Name    = stub.Name;
            retVal.SortKey = stub.SortKey;

            if (stub.Annotations != null)
            {
                retVal.Documentation = DocumentationParser.Parse(stub.Annotations.Documentation);
            }

            retVal.DerivedFrom = stub;

            if (stub.SupplierStructuralDomain != null && stub.SupplierStructuralDomain.Code != null)
            {
                retVal.ClassifierCode = stub.SupplierStructuralDomain.Code.Code;
            }

            retVal.Class = new TypeReference();

            // Return value class binding
            if (stub.TypeStaticModel != null)
            {
                Package p = (Package)stub.Container.MemberOfRepository.Find(stub.TypeStaticModel);
                if (p is GlobalStaticModel && (p as GlobalStaticModel).OwnedEntryPoint.Count > 0)
                {
                    string entryClassName = stub.EntryClass;

                    if (entryClassName == null)
                    {
                        throw new InvalidOperationException(string.Format("Package '{1}' points to a valid model with more than one entry point, however no entryClass was specified ", stub.TypeStaticModel.ToString(MifCompiler.NAME_FORMAT)));
                    }

                    // Did we find the class with an entry point?
                    var search     = (p as GlobalStaticModel).OwnedClass.Find(o => o.Choice is MohawkCollege.EHR.HL7v3.MIF.MIF20.StaticModel.Flat.Class && (o.Choice as MohawkCollege.EHR.HL7v3.MIF.MIF20.StaticModel.Flat.Class).Name == entryClassName);
                    var entryClass = search.Choice as MohawkCollege.EHR.HL7v3.MIF.MIF20.StaticModel.Flat.Class;

                    // Entry class is not null
                    if (entryClass == null)
                    {
                        throw new InvalidOperationException(string.Format("Can't find entry class '{0}' in package '{1}', or entry class is not a class", entryClassName, stub.TypeStaticModel.ToString(MifCompiler.NAME_FORMAT)));
                    }

                    retVal.Class.Name = string.Format("{0}.{1}", stub.TypeStaticModel.ToString(MifCompiler.NAME_FORMAT), entryClass.Name);
                }
                else if (p is GlobalStaticModel && (p as GlobalStaticModel).OwnedEntryPoint.Count == 1)
                {
                    retVal.Class.Name = string.Format("{0}.{1}", stub.TypeStaticModel.ToString(MifCompiler.NAME_FORMAT), (p as GlobalStaticModel).OwnedEntryPoint[0].Name);
                }
                else if (p != null)
                {
                    throw new InvalidOperationException(string.Format("Can't find static model '{0}'!", p.PackageLocation.ToString(MifCompiler.NAME_FORMAT)));
                }
                else
                {
                    return(null); // Can't find the package
                }
            }

            // Pseudo Heiarchy to get back to the class repository
            retVal.MemberOf       = classRepository;
            retVal.Class.MemberOf = classRepository;

            // Notify complete
            retVal.FireParsed();

            // Now return
            return(retVal);
        }
Exemple #7
0
        internal static Property Parse(ClassAttribute clsa, String vocabBindingRealm, ClassRepository cr, Dictionary <string, Package> derivationSuppliers)
        {
            // TODO: Support EnumerationValue stuff
            Property retVal = new Property();

            // Name (and busines names)
            retVal.Name = clsa.Name;
            foreach (BusinessName bn in clsa.BusinessName)
            {
                if (bn.Language == MifCompiler.Language || bn.Language == null)
                {
                    retVal.BusinessName = bn.Name;
                }
            }

            // Documentation
            if (clsa.Annotations != null)
            {
                retVal.Documentation = DocumentationParser.Parse(clsa.Annotations.Documentation);
            }

            // Conformance
            retVal.Conformance = clsa.IsMandatory ? ClassContent.ConformanceKind.Mandatory : clsa.Conformance == ConformanceKind.Required ? ClassContent.ConformanceKind.Required :
                                 ClassContent.ConformanceKind.Optional;

            if (retVal.Conformance != Property.ConformanceKind.Mandatory && clsa.MinimumMultiplicity == "1")
            {
                retVal.Conformance = Property.ConformanceKind.Populated;
            }

            // Min / Max occurs
            if (retVal.Conformance == MohawkCollege.EHR.gpmr.COR.Property.ConformanceKind.Mandatory)
            {
                retVal.MinOccurs = "1";
            }
            else
            {
                retVal.MinOccurs = clsa.MinimumMultiplicity;
            }
            retVal.MaxOccurs = clsa.MaximumMultiplicity == "-1" ? "*" : clsa.MaximumMultiplicity;
            retVal.MaxLength = clsa.MaximumLength;
            retVal.MinLength = clsa.MinimumLength;

            // Structural or non?
            retVal.PropertyType = clsa.IsImmutable ? Property.PropertyTypes.Structural : Property.PropertyTypes.NonStructural;

            // Default value
            retVal.DefaultValue = clsa.DefaultValue;
            retVal.Initializor  = clsa.DefaultFrom == DefaultDeterminerKind.ITS ? Property.InitializorTypes.ITS :
                                  clsa.DefaultFrom == DefaultDeterminerKind.Realm ? Property.InitializorTypes.Realm :
                                  clsa.DefaultFrom == DefaultDeterminerKind.ReferencingAttribute ? Property.InitializorTypes.ReferencedAttributes : Property.InitializorTypes.DefaultValue;

            if (clsa.DerivedFrom != null)
            {
                retVal.Realization = new List <ClassContent>();
                foreach (var dei in clsa.DerivedFrom)
                {
                    MohawkCollege.EHR.gpmr.COR.Feature ss = null;
                    Package derivationPkg = null;
                    if (!derivationSuppliers.TryGetValue(dei.StaticModelDerivationId, out derivationPkg) || derivationPkg == null)
                    {
                        continue;
                    }

                    // Has the package been compiled?
                    if (!cr.TryGetValue(string.Format("{0}", derivationPkg.PackageLocation.Artifact == ArtifactKind.RIM ? "RIM" : derivationPkg.PackageLocation.ToString(MifCompiler.NAME_FORMAT)), out ss))
                    {
                        // Attempt to parse
                        PackageParser.Parse(derivationPkg.PackageLocation.ToString(MifCompiler.NAME_FORMAT), derivationPkg.MemberOfRepository, cr);
                        // Ditch if still can't find
                        if (!cr.TryGetValue(string.Format("{0}", derivationPkg.PackageLocation.Artifact == ArtifactKind.RIM ? "RIM" : derivationPkg.PackageLocation.ToString(MifCompiler.NAME_FORMAT)), out ss))
                        {
                            System.Diagnostics.Trace.WriteLine(String.Format("Can't find derivation class '{0}' for association '{1}' (derivation supplier {2})", dei.ClassName, dei.AttributeName, dei.StaticModelDerivationId), "warn");
                        }
                    }

                    // Feature was found
                    var f = (ss as MohawkCollege.EHR.gpmr.COR.SubSystem).FindClass(dei.ClassName);
                    if (f != null)
                    {
                        ClassContent cc = f.GetFullContent().Find(o => o.Name == dei.AttributeName);
                        retVal.Realization.Add(cc);
                    }
                    else
                    {
                        System.Diagnostics.Trace.WriteLine(String.Format("Can't find derivation class '{0}' for association '{1}' (derivation supplier {2})", dei.ClassName, dei.AttributeName, dei.StaticModelDerivationId), "warn");
                    }
                }
            }

            // Derived from
            retVal.DerivedFrom = clsa;

            // Fixed Value
            retVal.FixedValue = clsa.FixedValue;

            // Sort key
            retVal.SortKey = clsa.SortKey;

            // Datatype
            retVal.Type = TypeReferenceParser.Parse(clsa.Type);

            // Update Modes
            retVal.UpdateMode = clsa.UpdateModeDefault.ToString();
            if (clsa.UpdateModesAllowed != null)
            {
                retVal.AllowedUpdateModes = new List <string>();
                foreach (string s in clsa.UpdateModesAllowed.Split(','))
                {
                    retVal.AllowedUpdateModes.Add(s);
                }
            }

            // Supplier domains
            if (clsa.Vocabulary != null)
            {
                if (clsa.Vocabulary.Code != null && !String.IsNullOrEmpty(clsa.Vocabulary.Code.Code)) // Fixed code
                {
                    retVal.FixedValue = string.Format("{0}", clsa.Vocabulary.Code.Code);
                }

                // JF: If the code system is identified, then bind
                if (clsa.Vocabulary.Code != null && !String.IsNullOrEmpty(clsa.Vocabulary.Code.CodeSystemName)) // Very odd thing that is present in UV mifs
                {
                    Trace.WriteLine(String.Format("'{0}' is specified as fixed code's code system, however no fixed code is present. Assuming this is a bound code system instead", "assumption"));
                    retVal.SupplierDomain = cr.Find(o => o is CodeSystem && (o as CodeSystem).Name.Equals(clsa.Vocabulary.Code.CodeSystemName)) as Enumeration;
                    if (retVal.SupplierDomain == null)
                    {
                        Trace.WriteLine(String.Format("'{0}' could not be bound to '{1}' as the code system was not found", clsa.Name, clsa.Vocabulary.Code.CodeSystemName), "warn");
                    }
                }
                if (clsa.Vocabulary.ConceptDomain != null)
                {
                    retVal.SupplierDomain = cr.Find(o => o is ConceptDomain && (o as ConceptDomain).Name.Equals(clsa.Vocabulary.ConceptDomain.Name)) as Enumeration;
                    if (retVal.SupplierDomain == null && MifCompiler.hostContext.Mode == Pipeline.OperationModeType.Quirks)
                    {
                        retVal.SupplierDomain = cr.Find(o => o is Enumeration && o.Name.Equals(clsa.Vocabulary.ConceptDomain.Name)) as Enumeration;
                        if (retVal.SupplierDomain != null)
                        {
                            Trace.WriteLine(String.Format("'{0}' couldn't be bound to concept domain '{1}', '{2}' with name '{1}' was located, so the binding was changed", clsa.Name, clsa.Vocabulary.ConceptDomain.Name, retVal.SupplierDomain.EnumerationType), "quirks");
                        }
                    }
                    if (retVal.SupplierDomain == null)
                    {
                        Trace.WriteLine(String.Format("'{0}' could not be bound to '{1}' as the concept domain was not found", clsa.Name, clsa.Vocabulary.ConceptDomain.Name), "warn");
                    }
                }
                if (clsa.Vocabulary.ValueSet != null)
                {
                    retVal.SupplierDomain = cr.Find(o => o is ValueSet && (o as ValueSet).Name.Equals(clsa.Vocabulary.ValueSet.Name)) as Enumeration;
                    if (retVal.SupplierDomain == null)
                    {
                        Trace.WriteLine(String.Format("'{0}' could not be bound to '{1}' as the value set was not found", clsa.Name, clsa.Vocabulary.ValueSet.Name), "warn");
                    }

                    if (!String.IsNullOrEmpty(clsa.Vocabulary.ValueSet.RootCode))
                    {
                        bool shouldFix = false;
                        if (retVal.SupplierDomain != null)
                        {
                            var enumLiteral = retVal.SupplierDomain.Literals.Find(o => o.Name == clsa.Vocabulary.ValueSet.RootCode);
                            shouldFix = enumLiteral != null && enumLiteral.RelatedCodes != null && enumLiteral.RelatedCodes.Count == 0;
                        }
                        if (shouldFix)
                        {
                            retVal.FixedValue = String.Format("{0}", clsa.Vocabulary.ValueSet.RootCode);
                        }
                    }
                }

                // Supplier strength(s)
                if (clsa.Vocabulary.ValueSet != null)
                {
                    retVal.SupplierStrength = clsa.Vocabulary.ValueSet.CodingStrength == CodingStrengthKind.CNE ? (Property.CodingStrengthKind?)Property.CodingStrengthKind.CodedNoExtensions:
                                              clsa.Vocabulary.ValueSet.CodingStrength == CodingStrengthKind.CWE ? (Property.CodingStrengthKind?)Property.CodingStrengthKind.CodedNoExtensions : null;
                }

                // Supplier domain strength
                if (retVal.SupplierDomain != null)
                {
                    if (defaultCodingStrengths.ContainsKey(retVal.SupplierDomain.Name ?? "") && !retVal.SupplierStrength.HasValue)
                    {
                        retVal.SupplierStrength = defaultCodingStrengths[retVal.SupplierDomain.Name];
                    }
                    else
                    {
                        retVal.SupplierStrength = Property.CodingStrengthKind.CodedNoExtensions;
                        System.Diagnostics.Trace.WriteLine(string.Format("No vocabulary value set on property {0}! Defaulting to CNE for supplier strength", retVal.Name), "assumption");
                    }
                }
            }

            return(retVal);
        }