Beispiel #1
0
        private static MohawkCollege.EHR.gpmr.COR.SubSystem Parse(Package p)
        {
            MohawkCollege.EHR.gpmr.COR.SubSystem package = new MohawkCollege.EHR.gpmr.COR.SubSystem();

            // Set the derivation property
            package.DerivedFrom = p;

            // Set the name of the system to either "RIM" of the package we are parsing is a rim
            // artifact, or the naming convention sd_Air
            package.Name = p.PackageLocation.Artifact == ArtifactKind.RIM ? "RIM" : p.PackageLocation.ToString(MifCompiler.NAME_FORMAT);

            // Set the realm
            //package.Realm = p.PackageLocation.Realm;

            // Set the sort key
            package.SortKey = p.SortKey;

            // Set copyright information
            package.Documentation = new MohawkCollege.EHR.gpmr.COR.Documentation();

            if (p.Header.Copyright != null)
            {
                package.Documentation.Copyright = string.Format("(C) {0}, {1}", p.Header.Copyright.Year, p.Header.Copyright.Owner);
            }

            // set business names
            if (p.BusinessName != null && p.BusinessName.Count > 0)
            {
                foreach (BusinessName bn in p.BusinessName)
                {
                    if (bn.Language == MifCompiler.Language || bn.Language == "")
                    {
                        package.BusinessName = bn.Name;
                    }
                }
            }
            else
            {
                package.BusinessName = p.Title;
            }

            return(package);
        }
Beispiel #2
0
        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);
        }
Beispiel #3
0
        private static MohawkCollege.EHR.gpmr.COR.SubSystem Parse(Package p)
        {

            MohawkCollege.EHR.gpmr.COR.SubSystem package = new MohawkCollege.EHR.gpmr.COR.SubSystem();

            // Set the derivation property
            package.DerivedFrom = p;

            // Set the name of the system to either "RIM" of the package we are parsing is a rim
            // artifact, or the naming convention sd_Air 
            package.Name = p.PackageLocation.Artifact == ArtifactKind.RIM ? "RIM" : p.PackageLocation.ToString(MifCompiler.NAME_FORMAT);

            // Set the realm
            //package.Realm = p.PackageLocation.Realm;

            // Set the sort key
            package.SortKey = p.SortKey;
            
            // Set copyright information
            package.Documentation = new MohawkCollege.EHR.gpmr.COR.Documentation();

            if (p.Header.Copyright != null)
                package.Documentation.Copyright = string.Format("(C) {0}, {1}", p.Header.Copyright.Year, p.Header.Copyright.Owner);

            // set business names
            if (p.BusinessName != null && p.BusinessName.Count > 0)
            {
                foreach (BusinessName bn in p.BusinessName)
                    if (bn.Language == MifCompiler.Language || bn.Language == "")
                        package.BusinessName = bn.Name;
            }
            else
                package.BusinessName = p.Title;

            return package;
        }
Beispiel #4
0
        /// <summary>
        /// Apply the delta against the sub-system
        /// </summary>
        private void ApplyDelta(SubSystem subSystem, ClassDeltaData delta)
        {

            Class corClass = subSystem.OwnedClasses.Find(o => o.Name == delta.Name) as Class;

            // Core class was not found
            if (corClass == null)
            {
                Trace.WriteLine(String.Format("Delta: Can't find '{0}' in sub-system '{1}', skipping...", delta.Name, subSystem.Name), "error");
                return;
            }
            else if (corClass.Annotations.Exists(o => o is CodeCombineAnnotation))
                throw new InvalidOperationException("It appears optimizations have already been performed on this set of classes. Will not continue...");
            
            // Let everyone know
            Trace.WriteLine(String.Format("Delta: Applying constraints for '{0}.{1}'", subSystem.Name, corClass.Name), "debug");
                        
            // Apply constraints
            foreach (var constraint in delta.Constraint)
                ApplyConstraint(corClass, constraint);

            // Apply sub-deltas
            if (delta.Deltas != null)
            {
                foreach (var deltaData in delta.Deltas)
                {
                    // Find the feature that is in the delta
                    Feature ftr = corClass.Content.Find(o => o.Name == deltaData.Value.Name);
                    if (ftr == null)
                    {
                        Trace.WriteLine(String.Format("Delta: Can't find property '{0}' in class '{1}.{2}', skipping...", deltaData.Value.Name,
                            subSystem.Name, corClass.Name), "error");
                        continue;
                    }
                    ApplyDelta(ftr as ClassContent, deltaData.Value);
                }
            }
        }
        public virtual void Compile()
        {
            string modelName = staticModel.PackageLocation.ToString(MifCompiler.NAME_FORMAT);

            System.Diagnostics.Trace.WriteLine(string.Format("Compiling static model package '{0}'...", modelName), "debug");

            // Check if the package has already been "compiled"
            if (ClassRepository.ContainsKey(staticModel.PackageLocation.ToString(MifCompiler.NAME_FORMAT)))
            {
                return; // Already compiled
            }
            // Create a COR namespace or package area based on the static model
            MohawkCollege.EHR.gpmr.Pipeline.Compiler.Mif20.Parsers.SubsystemParser.Parse(staticModel);

            // Static Model Derivation Suppliers
            Dictionary <string, Package> derivationSuppliers = new Dictionary <string, Package>();

            foreach (StaticModelDerivation smd in staticModel.DerivedFrom)
            {
                derivationSuppliers.Add(smd.StaticModelDerivationId, this.repository.Find(smd.TargetStaticModel) as Package);
            }

            // Compile owned entry points first
            foreach (var ep in staticModel.OwnedEntryPoint)
            {
                var cls = staticModel.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 == ep.ClassName);
                if (cls != null)
                {
                    ProcessClassElement(cls, derivationSuppliers);
                }
            }

            // Compile all contained classes in the package
            foreach (ClassElement c in staticModel.OwnedClass)
            {
                ProcessClassElement(c, derivationSuppliers);
            }

            // Get a ref to the current sub-system
            MohawkCollege.EHR.gpmr.COR.SubSystem ss = (ClassRepository[staticModel.PackageLocation.Artifact == ArtifactKind.RIM ? "RIM" : staticModel.PackageLocation.ToString(MifCompiler.NAME_FORMAT)]
                                                       as MohawkCollege.EHR.gpmr.COR.SubSystem);

            // Compile all contained associations
            foreach (Association a in staticModel.OwnedAssociation)
            {
                ParseAssociation(a, derivationSuppliers);
            }

            // Process entry points
            foreach (EntryPoint ep in staticModel.OwnedEntryPoint)
            {
                // Find the class
                MohawkCollege.EHR.gpmr.COR.Class cls = ss.FindClass(ep.ClassName);

                // The ProcStack keeps track of the properties the CascadeGenerics is
                // processing so that we don't get a stack overflow
                Stack <string> procStack = new Stack <string>();
                // Process any generic providers that need to be cascaded down to child properties
                // This is required for interactions to function properly.
                CascadeGenerics(cls, procStack);

                // Assign as the ep
                if (ss.EntryPoint == null)
                {
                    ss.EntryPoint = new List <MohawkCollege.EHR.gpmr.COR.Class>();                       // Have to do this here so we don't have E/P array with 0 elements
                }
                ss.EntryPoint.Add(cls);
            }
        }
Beispiel #6
0
        internal static MohawkCollege.EHR.gpmr.COR.Class Parse(ClassParameterInfo classInfo)
        {
            // Has this been processed?
            if (classInfo.CompilerRepository.ContainsKey(string.Format("{0}.{1}", classInfo.ScopedPackageName, classInfo.Class.Name)))
            {
                return(null);
            }

            // Get the vocabulary realm that this package is bound to
            string vocabularyRealm = classInfo.MifContainer is StaticModel && (classInfo.MifContainer as StaticModel).ImportedVocabularyModelPackage != null ? (classInfo.MifContainer as StaticModel).ImportedVocabularyModelPackage.Realm : null;

            // Parse the common (class base) portion of the classes
            MohawkCollege.EHR.gpmr.COR.Class retVal = Parse(classInfo.Class as ClassBase, vocabularyRealm, classInfo.CompilerRepository, classInfo.DerivationSuppliers);

            // Base class
            retVal.BaseClass = classInfo.EnforcedBaseClass;

            // Containing subsystem
            retVal.ContainerPackage = classInfo.CompilerRepository[classInfo.ScopedPackageName] as MohawkCollege.EHR.gpmr.COR.SubSystem;

            // Fire parsed event
            retVal.FireParsed();

            #region Specializations

            retVal.SpecializedBy = new List <TypeReference>();

            // Iterate through each child class and process where neccessary
            foreach (ClassGeneralization cg in (classInfo.Class as MohawkCollege.EHR.HL7v3.MIF.MIF20.StaticModel.Flat.Class).SpecializationChild)
            {
                TypeReference tr = new TypeReference();
                tr.Name     = string.Format("{0}.{1}", classInfo.ScopedPackageName, cg.ChildClassName); // Make a ref to the child class
                tr.MemberOf = classInfo.CompilerRepository;

                bool isCMET = false;
                // Get the child class
                if (classInfo.MifContainer is GlobalStaticModel)
                {
                    // Get the CMET reference from the MIF class hierarchy
                    ClassElement ce = (classInfo.MifContainer as GlobalStaticModel).OwnedClass.Find(delegate(ClassElement c)
                    {
                        if (c != null && c.Choice != null && c.Choice is CommonModelElementRef)
                        {
                            return((c.Choice as CommonModelElementRef).Name == cg.ChildClassName);
                        }
                        else
                        {
                            return(false);
                        }
                    });

                    string cmetName = ce != null ? (ce.Choice as CommonModelElementRef).CmetName ?? (ce.Choice as CommonModelElementRef).Name : "";

                    // Determine if the reference is a cmet and gathe t
                    isCMET = cmetName != null && ce != null && classInfo.CompilerRepository.ContainsKey(cmetName) &&
                             classInfo.CompilerRepository[cmetName] is CommonTypeReference;

                    if (isCMET) // A CMET was successfully resolved
                    {
                        tr = (classInfo.CompilerRepository[cmetName] as CommonTypeReference).Class;
                    }
                    else if (ce != null && MifCompiler.cmetBindings.ContainsKey(cmetName)) // A CMET was not resolved, but a binding exists!
                    {
                        string boundModel = MifCompiler.cmetBindings[cmetName];
                        MohawkCollege.EHR.gpmr.COR.Feature boundSubSystem = null;
                        if (classInfo.CompilerRepository.TryGetValue(boundModel, out boundSubSystem))
                        {
                            tr = (boundSubSystem as MohawkCollege.EHR.gpmr.COR.SubSystem).EntryPoint[0].CreateTypeReference();
                        }
                        else
                        {
                            PackageParser.Parse(boundModel, classInfo.MifContainer.MemberOfRepository, classInfo.CompilerRepository);
                        }
                    }
                    else if (ce != null) // MIF References a CMET but one was never processed? This is odd!
                    {
                        System.Diagnostics.Trace.WriteLine(string.Format("CMET '{0}' was never processed, therefore CommonModelElementRef can't be processed in file '{1}'", cmetName, classInfo.ScopedPackageName), "warn");
                        continue;
                    }
                }

                // The child class has not been processed yet
                if (!classInfo.CompilerRepository.ContainsKey(tr.Name))
                {
                    if (isCMET) // Explicit, have to process another model
                    {
                        PackageParser.ParseClassFromPackage(tr.Name, classInfo.MifContainer.MemberOfRepository, classInfo.CompilerRepository);
                        // Assign the base class
                        //if ((classInfo.CompilerRepository[tr.Name] as MohawkCollege.EHR.gpmr.COR.Class).BaseClass != null)
                        //    System.Diagnostics.Debugger.Break();
                    }
                    else
                    {
                        ClassParameterInfo parm2 = new ClassParameterInfo();
                        parm2.Class = (classInfo.MifContainer as StaticModel).OwnedClass.Find(o => (o.Choice is MohawkCollege.EHR.HL7v3.MIF.MIF20.StaticModel.Flat.Class && string.Format("{0}.{1}", classInfo.ScopedPackageName, (o.Choice as MohawkCollege.EHR.HL7v3.MIF.MIF20.StaticModel.Flat.Class).Name) == tr.Name)).Choice as ClassBase;
                        parm2.CompilerRepository  = classInfo.CompilerRepository;
                        parm2.DerivationSuppliers = classInfo.DerivationSuppliers;
                        parm2.MifContainer        = classInfo.MifContainer;
                        parm2.ScopedPackageName   = classInfo.ScopedPackageName;
                        parm2.EnforcedBaseClass   = retVal.CreateTypeReference();
                        ClassParser.Parse(parm2);
                    }
                }


                // Add to specialization list
                MohawkCollege.EHR.gpmr.COR.Feature f = null;
                if (classInfo.CompilerRepository.TryGetValue(tr.Name, out f))
                {
                    retVal.SpecializedBy.Add((f as MohawkCollege.EHR.gpmr.COR.Class).CreateTypeReference());
                    (f as MohawkCollege.EHR.gpmr.COR.Class).BaseClass = retVal.CreateTypeReference();
                }
                else
                {
                    Trace.WriteLine(String.Format("Cannot find base class '{0}' for '{1}'. Base class must exist before it can be specialized", tr.Name, retVal.Name), "error");
                }
            }


            #endregion

            // Assign Temporary Membership to the compiler class repository so the
            // locating of a structural member will succeed
            retVal.MemberOf = classInfo.CompilerRepository;

            // Is a classCode enforcement placed on this class?
            #region Supplier Structural Domain
            if (classInfo.Class.SupplierStructuralDomain != null && classInfo.Class.SupplierStructuralDomain.Code != null)
            {
                MohawkCollege.EHR.gpmr.COR.Property clsa = retVal.FindMember("classCode", false, MohawkCollege.EHR.gpmr.COR.Property.PropertyTypes.Structural);

                if (clsa == null)// Class code is derived... we need to override it
                {
                    clsa = retVal.FindMember("classCode", true, MohawkCollege.EHR.gpmr.COR.Property.PropertyTypes.Structural);
                    // Any class code defined?
                    if (clsa != null)
                    {
                        clsa = PropertyParser.Parse(clsa.DerivedFrom as ClassAttribute, vocabularyRealm, classInfo.CompilerRepository, classInfo.DerivationSuppliers);
                        retVal.AddContent(clsa);
                    }
                    else // Makes no sense, we have a class code enforcement but no class code?
                    {
                        if (MifCompiler.hostContext.Mode == Pipeline.OperationModeType.Quirks)
                        {
                            Trace.WriteLine(String.Format("Supplier domain is specified on class '{0}' which has class code. Since GPMR is in quirks mode, the classCode attribute will be created", retVal.Name), "quirks");
                            clsa              = new Property();
                            clsa.Name         = "classCode";
                            clsa.PropertyType = Property.PropertyTypes.Structural;
                            clsa.Conformance  = ClassContent.ConformanceKind.Mandatory;
                            retVal.AddContent(clsa);
                        }
                        else
                        {
                            throw new InvalidOperationException("Shouldn't be here. Supplier domain specified on a class with no classCode");
                        }
                    }
                }

                #region Now populate the code domain
                // Supplier domains
                if (classInfo.Class.SupplierStructuralDomain != null)
                {
                    var supplierStruct = classInfo.Class.SupplierStructuralDomain;

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

                    // JF: If the code system is identified, then bind
                    if (supplierStruct.Code != null && !String.IsNullOrEmpty(supplierStruct.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"));
                        clsa.SupplierDomain = classInfo.CompilerRepository.Find(o => o is CodeSystem && (o as CodeSystem).Name.Equals(supplierStruct.Code.CodeSystemName)) as Enumeration;
                        if (clsa.SupplierDomain == null)
                        {
                            Trace.WriteLine(String.Format("'{0}' could not be bound to '{1}' as the code system was not found", clsa.Name, supplierStruct.Code.CodeSystemName), "warn");
                        }
                    }
                    if (supplierStruct.ConceptDomain != null)
                    {
                        clsa.SupplierDomain = classInfo.CompilerRepository.Find(o => o is ConceptDomain && (o as ConceptDomain).Name.Equals(supplierStruct.ConceptDomain.Name)) as Enumeration;
                        if (clsa.SupplierDomain == null)
                        {
                            Trace.WriteLine(String.Format("'{0}' could not be bound to '{1}' as the concept domain was not found", clsa.Name, supplierStruct.ConceptDomain.Name), "warn");
                        }
                    }
                    if (supplierStruct.ValueSet != null)
                    {
                        clsa.SupplierDomain = classInfo.CompilerRepository.Find(o => o is ValueSet && (o as ValueSet).Name.Equals(supplierStruct.ValueSet.Name)) as Enumeration;
                        if (clsa.SupplierDomain == null)
                        {
                            Trace.WriteLine(String.Format("'{0}' could not be bound to '{1}' as the value set was not found", clsa.Name, supplierStruct.ValueSet.Name), "warn");
                        }

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

                    // Supplier strength(s)
                    if (supplierStruct.ValueSet != null)
                    {
                        clsa.SupplierStrength = supplierStruct.ValueSet.CodingStrength == CodingStrengthKind.CNE ? (Property.CodingStrengthKind?)Property.CodingStrengthKind.CodedNoExtensions:
                                                supplierStruct.ValueSet.CodingStrength == CodingStrengthKind.CWE ? (Property.CodingStrengthKind?)Property.CodingStrengthKind.CodedNoExtensions : null;
                    }
                    else
                    {
                        clsa.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");
                    }
                }



                //if (classInfo.Class.SupplierStructuralDomain.Code != null)
                //    clsa.FixedValue = string.Format("{0}{1}", classInfo.Class.SupplierStructuralDomain.Code.CodeSystem == null ? "" : classInfo.Class.SupplierStructuralDomain.Code.CodeSystem + ":", classInfo.Class.SupplierStructuralDomain.Code.Code);

                //if (classInfo.Class.SupplierStructuralDomain.ConceptDomain != null)
                //    clsa.SupplierDomain = classInfo.Class.SupplierStructuralDomain.ConceptDomain.Name;
                //if (classInfo.Class.SupplierStructuralDomain.ValueSet != null)
                //{
                //    clsa.SupplierStrength = classInfo.Class.SupplierStructuralDomain.ValueSet.CodingStrength == CodingStrengthKind.CNE ? (Property.CodingStrengthKind?)Property.CodingStrengthKind.CodedNoExtensions :
                //        classInfo.Class.SupplierStructuralDomain.ValueSet.CodingStrength == CodingStrengthKind.CWE ? (Property.CodingStrengthKind?)Property.CodingStrengthKind.CodedNoExtensions : null;
                //    clsa.SupplierDomainValueSet = classInfo.Class.SupplierStructuralDomain.ValueSet.Id;
                //}
                //else
                //{
                //    clsa.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");
                //}
                #endregion
            }
            #endregion

            // All specifications
            #region Specializations

            //if ((classInfo.Class as MohawkCollege.EHR.HL7v3.MIF.MIF20.StaticModel.Flat.Class).SpecializationChild != null && (classInfo.Class as MohawkCollege.EHR.HL7v3.MIF.MIF20.StaticModel.Flat.Class).SpecializationChild.Count > 0)
            //{
            //    retVal.SpecializedBy = new List<MohawkCollege.EHR.gpmr.COR.TypeReference>();
            //    foreach (ClassGeneralization cg in (classInfo.Class as MohawkCollege.EHR.HL7v3.MIF.MIF20.StaticModel.Flat.Class).SpecializationChild)
            //    {
            //        MohawkCollege.EHR.gpmr.COR.TypeReference specRef = new MohawkCollege.EHR.gpmr.COR.TypeReference();
            //        specRef.Name = string.Format("{0}.{1}", classInfo.ScopedPackageName, cg.ChildClassName);
            //        MohawkCollege.EHR.gpmr.COR.Property noProp = new MohawkCollege.EHR.gpmr.COR.Property();
            //        noProp.Container = retVal;
            //        specRef.Container = noProp;
            //        retVal.SpecializedBy.Add(specRef);
            //    }
            //}

            #endregion

            #region Behaviors

            // State machine on the class
            if (classInfo.Class.Behavior != null)
            {
                // Find the property that this state machine acts on

                Property stateProperty = retVal.FindMember(classInfo.Class.Behavior.SupplierStateAttributeName, false, Property.PropertyTypes.NonStructural | Property.PropertyTypes.Structural);

                stateProperty.StateMachine = StateMachineParser.Parse(classInfo.Class.Behavior);
            }

            #endregion

            #region Derivation Supplier
            if (classInfo.Class.DerivedFrom != null)
            {
                // Init retVal projection
                retVal.Realizations = new List <MohawkCollege.EHR.gpmr.COR.TypeReference>();

                // Iterate through each class this class is a projection of (is based on)
                foreach (ClassDerivation cd in classInfo.Class.DerivedFrom)
                {
                    try
                    {
                        // See if this class has been parsed
                        Package derivationPackage = null;
                        if (!classInfo.DerivationSuppliers.TryGetValue(cd.StaticModelDerivationId, out derivationPackage) || derivationPackage == null)
                        {
                            continue;
                        }

                        MohawkCollege.EHR.gpmr.COR.Feature ss = null;

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


                        // Attempt to parse
                        MohawkCollege.EHR.gpmr.COR.SubSystem supplierSubSystem = ss as MohawkCollege.EHR.gpmr.COR.SubSystem;

                        // Find the class
                        MohawkCollege.EHR.gpmr.COR.Class supplierClass = classInfo.CompilerRepository[string.Format("{0}.{1}", supplierSubSystem.Name, cd.ClassName)] as MohawkCollege.EHR.gpmr.COR.Class;

                        // Add a realization
                        retVal.Realizations.Add(supplierClass.CreateTypeReference());

                        // Now do some processing
                        foreach (ClassContent cc in supplierClass.Content)
                        {
                            ClassContent rcc = null;

                            // Find the class content we are talking about
                            if (cc is Property)
                            {
                                rcc = retVal.FindMember(cc.Name, true, (cc as MohawkCollege.EHR.gpmr.COR.Property).PropertyType);
                            }
                            else
                            {
                                ; //TODO: Clean up choices so they match the realization class. Not sure if this supposed to be done
                            }
                            // Correct Items
                            if (rcc != null)
                            {
                                if (MohawkCollege.EHR.gpmr.COR.Documentation.IsEmpty(rcc.Documentation))// Correct documentation
                                {
                                    rcc.Documentation = cc.Documentation;
                                }
                                // Removed: This was supposed to correct missing supplier domains from the RMIMs using the RIM data, however it does
                                // cause some issues.
                                //    if (rcc is MohawkCollege.EHR.gpmr.COR.Property && (rcc as MohawkCollege.EHR.gpmr.COR.Property).SupplierDomain == null &&
                                //        (cc as MohawkCollege.EHR.gpmr.COR.Property).SupplierDomain != null)
                                //    {
                                //        (rcc as MohawkCollege.EHR.gpmr.COR.Property).SupplierDomain = (cc as MohawkCollege.EHR.gpmr.COR.Property).SupplierDomain;
                                //        (rcc as MohawkCollege.EHR.gpmr.COR.Property).SupplierStrength = (cc as MohawkCollege.EHR.gpmr.COR.Property).SupplierStrength;
                                //    }
                            }
                        }
                    }
                    catch (Exception e)
                    {
                        System.Diagnostics.Trace.WriteLine(string.Format("Could not find derivation supplier information for {0}", retVal.Name), "warn");
                    }
                }
            }
            #endregion

            #region Correct Vocabulary

            // This is quite a problem, when a property is bound to a value set, and that value set
            // is merely a pointer to other value sets of data we need to correct the pointer
            foreach (var property in retVal.Content)
            {
                // If the content is a property and it has a supplier domain, try to find the supplier domain
                if (property is Property && (property as Property).SupplierDomain != null)
                {
                    // Now to correct the reference
                    if ((property as Property).SupplierDomain.EnumerationReference != null &&
                        (property as Property).SupplierDomain.EnumerationReference.Count == 1)
                    {
                        (property as Property).SupplierDomain = (property as Property).SupplierDomain.EnumerationReference[0];
                    }
                }
            }

            #endregion

            // Sort the class content
            retVal.Content.Sort(new ClassContent.Comparator());

            // Return
            return(retVal);
        }