Пример #1
0
        public EventContext(DvDateTime startTime, DvDateTime endTime,
                            DvCodedText setting, string location, PartyIdentified healthCareFacility,
                            ItemStructure otherContext, Participation[] participations) : this()
        {
            Check.Require(startTime != null, "start_time must not be null");
            Check.Require(setting != null, "setting must not be null");

            this.startTime          = startTime;
            this.endTime            = endTime;
            this.setting            = setting;
            this.location           = location;
            this.healthCareFacility = healthCareFacility;
            this.otherContext       = otherContext;
            if (this.otherContext != null)
            {
                this.otherContext.Parent = this;
            }
            if (participations != null)
            {
                this.participations = new OpenEhr.AssumedTypes.List <Participation>(participations);
            }

            SetAttributeDictionary();
            this.CheckInvariants();
        }
Пример #2
0
        public bool Contains(string nodeId, DvText name)
        {
            Check.Invariant(identifiedLocatables != null, "identifiedLocatables must not be null");

            Check.Require(!string.IsNullOrEmpty(nodeId), "nodeId must not be null or empty");
            Check.Require(name != null, "name must not be null");

            LocatableBindingListView <T> namedLocatables = null;

            if (identifiedLocatables.ContainsKey(nodeId))
            {
                namedLocatables = identifiedLocatables[nodeId];
            }

            bool result = false;

            if (namedLocatables != null)
            {
                DvCodedText codedName = name as DvCodedText;
                if (codedName == null)
                {
                    result = namedLocatables.Contains(name.Value);
                }

                else
                {
                    CodePhrase definingCode = codedName.DefiningCode;
                    result = namedLocatables.Contains(definingCode.TerminologyId.Value, definingCode.CodeString);
                }
            }

            return(result);
        }
        private int Find(string nameTerminologyId, string nameCodeString)
        {
            Check.Require(!string.IsNullOrEmpty(nameCodeString), "nameCodeString must not be null or empty");

            for (int i = 0; i < this.Count; i++)
            {
                ILocatable item = this[i] as ILocatable;

                DvCodedText codeName = item.Name as DvCodedText;
                Check.Assert(codeName != null, "Item name must be coded name.");

                if (nameTerminologyId != null)
                {
                    if (codeName.DefiningCode.CodeString == nameCodeString &&
                        codeName.DefiningCode.TerminologyId.Value == nameTerminologyId)
                    {
                        return(i);
                    }
                }
                else // assume that the nameTerminologyId is local.
                {
                    if (codeName.DefiningCode.CodeString == nameCodeString)
                    {
                        return(i);
                    }
                }
            }
            return(-1); // not found
        }
Пример #4
0
        public Composition(DvText name, string archetypeNodeId, Support.Identification.UidBasedId uid,
                           Link[] links, Archetyped archetypeDetails, FeederAudit feederAudit,
                           CodePhrase language, CodePhrase territory, DvCodedText category, EventContext context,
                           Content.ContentItem[] content, PartyProxy composer) :
            base(name, archetypeNodeId, uid, links, archetypeDetails, feederAudit)
        {
            Check.Require(language != null, "language must not be null");
            Check.Require(territory != null, "territory must not be null");
            Check.Require(category != null, "category must not be null");
            Check.Require(composer != null, "composer must not be null");


            this.language  = language;
            this.territory = territory;
            this.category  = category;
            this.context   = context;
            if (this.context != null)
            {
                this.context.Parent = this;
            }
            if (content != null)
            {
                this.content = RmFactory.LocatableList <ContentItem>(this, content);
            }

            this.composer = composer;

            SetAttributeDictionary();
            this.CheckInvariants();
        }
Пример #5
0
        // CM: 15/02/08
        public DvState(DvCodedText value, bool isTerminal) :
            this()
        {
            this.Value      = value;
            this.IsTerminal = isTerminal;

            this.CheckInvariants();
        }
Пример #6
0
        protected override void AddItem(T item)
        {
            Check.Require(this.parent != null || item.Parent != null,
                          "item of type Pathable must have Parent attribute set when list parent not set");

            Check.Invariant(identifiedLocatables != null, "identifiedLocatables must not be null");

            Locatable locatable = item as Locatable;

            Check.Assert(item != null, "item must not be null");

            if (item.Parent == null)
            {
                item.Parent = this.parent;
            }

            else if (this.parent == null)
            {
                this.parent = item.Parent;
            }

            else if (!Object.ReferenceEquals(item.Parent, this.parent))
            {
                throw new ApplicationException("item parent must have same parent as other items");
            }

            NamedLocatableList <T> namedLocatables;

            if (identifiedLocatables.ContainsKey(item.ArchetypeNodeId))
            {
                namedLocatables = identifiedLocatables[item.ArchetypeNodeId];
            }
            else
            {
                namedLocatables = new NamedLocatableList <T>();
                identifiedLocatables.Add(item.ArchetypeNodeId, namedLocatables);
            }

            DvCodedText codedName = item.Name as DvCodedText;

            if (codedName != null)
            {
                if (namedLocatables.Contains(codedName.DefiningCode.TerminologyId.Value, codedName.DefiningCode.CodeString))
                {
                    throw new ApplicationException(string.Format("locatable ({0}) name ({1}) already existing in the namedLocatable list.",
                                                                 item.ArchetypeNodeId, codedName.ToString()));
                }
            }
            else if (namedLocatables.Contains(item.Name.Value))
            {
                throw new ApplicationException(string.Format("locatable ({0}) name ({1}) already existing in this namedLocatable list",
                                                             item.ArchetypeNodeId, item.Name.Value));
            }

            namedLocatables.Add(item);

            base.AddItem(item);
        }
Пример #7
0
        public PartyRelated(string name, List <DvIdentifier> identifiers, DvCodedText relationship,
                            PartyRef externalRef)
        {
            Check.Require(relationship != null, "relationship must not be null");

            this.relationship = relationship;

            SetBaseData(name, identifiers, externalRef);
        }
Пример #8
0
        public Element(DvText name, string archetypeNodeId, Support.Identification.UidBasedId uid,
                       Link[] links, Archetyped archetypeDetails, FeederAudit feederAudit,
                       DataValue value, DvCodedText nullFlavour)
            : base(name, archetypeNodeId, uid, links, archetypeDetails, feederAudit)
        {
            this.value       = value;
            this.nullFlavour = nullFlavour;

            SetAttributeDictionary();
            CheckInvariants();
        }
Пример #9
0
        protected override void ReadXmlBase(System.Xml.XmlReader reader)
        {
            base.ReadXmlBase(reader);

            // read for the attributes in this local class
            Check.Assert(reader.LocalName == "uid", "Expected LocalName as uid rather than " + reader.LocalName);
            this.uid = new OpenEhr.RM.Support.Identification.ObjectVersionId();
            this.uid.ReadXml(reader);

            if (reader.LocalName == "data")
            {
                string dataType = reader.GetAttribute("type", RmXmlSerializer.XsiNamespace);

                OpenEhr.RM.Common.Archetyped.Impl.Locatable locatableData =
                    OpenEhr.RM.Common.Archetyped.Impl.Locatable.GetLocatableObjectByType(dataType);
                locatableData.ReadXml(reader);
                this.data = locatableData as T;
            }

            if (reader.LocalName == "preceding_version_uid")
            {
                this.precedingVersionUid = new OpenEhr.RM.Support.Identification.ObjectVersionId();
                this.precedingVersionUid.ReadXml(reader);
            }

            if (reader.LocalName == "other_input_version_uids")
            {
                this.otherInputVersionUids = new AssumedTypes.Set <ObjectVersionId>();
                do
                {
                    ObjectVersionId objectVersionId = new ObjectVersionId();
                    objectVersionId.ReadXml(reader);

                    this.otherInputVersionUids.Add(objectVersionId);
                } while (reader.LocalName == "other_input_version_uids");
            }

            if (reader.LocalName == "attestations")
            {
                this.attestations = new OpenEhr.AssumedTypes.List <OpenEhr.RM.Common.Generic.Attestation>();
                do
                {
                    Generic.Attestation a = new OpenEhr.RM.Common.Generic.Attestation();
                    a.ReadXml(reader);

                    this.attestations.Add(a);
                } while (reader.LocalName == "attestations");
            }

            Check.Assert(reader.LocalName == "lifecycle_state",
                         "Expected LocalName is lifecycle_state not " + reader.LocalName);
            this.lifecycleState = new OpenEhr.RM.DataTypes.Text.DvCodedText();
            this.lifecycleState.ReadXml(reader);
        }
Пример #10
0
        public T this[string nodeId, DvText name]
        {
            get
            {
                Check.Invariant(identifiedLocatables != null, "identifiedLocatables must not be null");

                Check.Require(!string.IsNullOrEmpty(nodeId), "nodeId must not be null or empty");
                Check.Require(name != null, "name must not be null");

                Check.Assert(Contains(nodeId, name), "Set must contain item with specified name");  // precondition, but more efficient in release

                LocatableBindingListView <T> namedLocatables = null;
                if (identifiedLocatables.ContainsKey(nodeId))
                {
                    namedLocatables = identifiedLocatables[nodeId];
                }

                T result = null;
                if (namedLocatables != null)
                {
                    DvCodedText codedName = name as DvCodedText;
                    if (codedName == null)
                    {
                        string nameValue = name.Value;
                        if (namedLocatables.Contains(nameValue))
                        {
                            result = namedLocatables[nameValue];
                        }
                    }
                    else
                    {
                        string nameTerminologyId = codedName.DefiningCode.TerminologyId.Value;
                        string nameCodeString    = codedName.DefiningCode.CodeString;
                        if (namedLocatables.Contains(nameTerminologyId, nameCodeString))
                        {
                            result = namedLocatables[nameTerminologyId, nameCodeString];
                        }
                    }
                }
                Check.Ensure(result != null, "result must not be null");
                return(result);
            }
        }
Пример #11
0
        protected override void ReadXmlBase(System.Xml.XmlReader reader)
        {
            base.ReadXmlBase(reader);

            DesignByContract.Check.Assert(reader.LocalName == "width",
                                          "Expected local name is width not " + reader.LocalName);
            this.width = new DvDuration();
            this.width.ReadXml(reader);

            if (reader.LocalName == "sample_count")
            {
                this.SampleCount = reader.ReadElementContentAsInt("sample_count", RmXmlSerializer.OpenEhrNamespace);
                reader.MoveToContent();
            }

            DesignByContract.Check.Assert(reader.LocalName == "math_function",
                                          "Expected local name is math_function not " + reader.LocalName);
            this.mathFunction = new DvCodedText();
            this.mathFunction.ReadXml(reader);
        }
Пример #12
0
        internal static bool ValidValueTermDef(DvCodedText dvCodedText, CAttribute cAttribute, ITerminologyService terminologyService)
        {
            string value = string.Empty;
            if (dvCodedText.DefiningCode.TerminologyId.Value == OpenEhrTerminologyIdentifiers.TerminologyIdOpenehr)

                value = OpenEhrTermDefTerm(dvCodedText.DefiningCode.CodeString, terminologyService);

            else if (dvCodedText.DefiningCode.TerminologyId.Value == "local")
                value = LocalTermDefText(dvCodedText.DefiningCode.CodeString, cAttribute);

            if (!string.IsNullOrEmpty(value)
                && !string.IsNullOrEmpty(dvCodedText.Value)
                && value != dvCodedText.Value)
            {
                return false;
            }
            if (!string.IsNullOrEmpty(value) && string.IsNullOrEmpty(dvCodedText.Value))
                dvCodedText.Value = value;

            return true;
        }
Пример #13
0
        bool ILocatableList.Contains(string nodeId, string terminologyId, string codeString)
        {
            Check.Invariant(identifiedLocatables != null, "identifiedLocatables must not be null");

            Check.Require(!string.IsNullOrEmpty(nodeId), "nodeId must not be null or empty.");
            Check.Require(!string.IsNullOrEmpty(codeString), "codeString must not be null or empty.");

            if (((ILocatableList)this).Contains(nodeId))
            {
                List <T> namedLocatableList
                    = this.identifiedLocatables[nodeId];

                for (int i = 0; i < namedLocatableList.Count; i++)
                {
                    Locatable locatable = namedLocatableList[i];

                    DvCodedText codedName = locatable.Name as DvCodedText;
                    Check.Assert(codedName != null, "locatable name must be type of DvCodedText.");

                    if (terminologyId != null)
                    {
                        if (codedName.DefiningCode.CodeString == codeString &&
                            codedName.DefiningCode.TerminologyId.Value == terminologyId)
                        {
                            return(true);
                        }
                    }
                    else
                    {
                        if (codedName.DefiningCode.CodeString == codeString)
                        {
                            return(true);
                        }
                    }
                }
            }
            return(false);
        }
Пример #14
0
        public IntervalEvent(DvText name, string archetypeNodeId, Support.Identification.UidBasedId uid,
                             Link[] links, Archetyped archetypeDetails, FeederAudit feederAudit,
                             DvDateTime time, T data,
                             ItemStructure.ItemStructure state, DvDuration width,
                             int?sampleCount, DvCodedText mathFunction)
            : base(name, archetypeNodeId, uid, links, archetypeDetails, feederAudit, time, data, state)
        {
            Check.Require(width != null, "width must not be null");
            Check.Require(mathFunction != null, "math_function must not be null");

            this.width = width;

            if (sampleCount != null)
            {
                this.sampleCount    = (int)sampleCount;
                this.sampleCountSet = true;
            }

            this.mathFunction = mathFunction;

            SetAttributeDictionary();
            CheckInvariants();
        }
Пример #15
0
        public override bool ValidValue(object dataValue)
        {
            Check.Require(dataValue != null, string.Format(CommonStrings.XMustNotBeNull, "dataValue"));
            IRmType rmType = dataValue as IRmType;

            Check.Require(rmType != null, string.Format(AmValidationStrings.ValueMustImplementIRmType, dataValue.GetType().ToString()));

            bool result = true;

            rmType.Constraint = this;

            if (!IsSameRmType(rmType))
            {
                result = false;
                ValidationContext.AcceptValidationError(this, string.Format(AmValidationStrings.IncorrectRmType, RmTypeName, rmType.GetRmTypeName()));
            }

            if (!result || !AnyAllowed())
            {
                OpenEhr.RM.Common.Archetyped.Impl.Locatable locatable = dataValue as OpenEhr.RM.Common.Archetyped.Impl.Locatable;

                if (locatable != null)
                {
                    ValidationUtility.PopulateLocatableAttributes(this, locatable);

                    if (Parent != null && ArchetypeNodeId != locatable.ArchetypeNodeId)
                    {
                        result = false;
                        ValidationContext.AcceptValidationError(this, string.Format(AmValidationStrings.IncorrectNodeId, ArchetypeNodeId, locatable.ArchetypeNodeId));
                    }
                }

                System.ComponentModel.PropertyDescriptorCollection propertyDescriptorCollection = System.ComponentModel.TypeDescriptor.GetProperties(dataValue);

                if (Attributes != null)
                {
                    foreach (CAttribute cAttribute in Attributes)
                    {
                        object attributeObject = null;
                        string attributeName   = RmFactory.GetOpenEhrV1RmName(cAttribute.RmAttributeName);
                        System.ComponentModel.PropertyDescriptor property = propertyDescriptorCollection.Find(attributeName, true);

                        // if the attributeName is not a class property, it must be a class function.
                        if (property == null)
                        {
                            System.Reflection.MethodInfo method = dataValue.GetType().GetMethod(attributeName);

                            if (method == null)
                            {
                                result = false;
                                ValidationContext.AcceptValidationError(this, string.Format(AmValidationStrings.UnexpectedAttributeX, attributeName));
                                continue;
                            }
                            else
                            {
                                attributeObject = method.Invoke(dataValue, null);
                            }
                        }
                        else
                        {
                            attributeObject = property.GetValue(dataValue);
                        }

                        if (attributeObject == null)
                        {
                            if (cAttribute.Existence.Lower > 0)
                            {
                                result = false;
                                ValidationContext.AcceptValidationError(this, string.Format(AmValidationStrings.TmExpectedConstraintMissing, cAttribute.RmAttributeName));
                            }
                        }
                        else if (cAttribute.Existence.Upper == 0)
                        {
                            result = false;
                            ValidationContext.AcceptValidationError(this, string.Format(AmValidationStrings.TmForbiddenConstraint, cAttribute.RmAttributeName));
                        }
                        else if (!cAttribute.ValidValue(attributeObject))
                        {
                            result = false;
                        }
                        else
                        {
                            DvCodedText codedText = dataValue as DvCodedText;

                            if (codedText != null && cAttribute.RmAttributeName == "defining_code")
                            {
                                // validate the code string before validating the coded value
                                if (codedText.DefiningCode.TerminologyId.Value == "local")
                                {
                                    CObject        parentObject   = cAttribute.parent;
                                    CArchetypeRoot cArchetypeRoot = ValidationUtility.GetCArchetypeRoot(parentObject);

                                    if (!cArchetypeRoot.TermDefinitions.HasKey(codedText.DefiningCode.CodeString))
                                    {
                                        result = false;
                                        string code = codedText.DefiningCode == null ? "" : codedText.DefiningCode.CodeString;
                                        ValidationContext.AcceptValidationError(this, string.Format("code {0} is not existing archetype term", code));
                                    }
                                }
                                if (result && !ValidationUtility.ValidValueTermDef(codedText, cAttribute, ValidationContext.TerminologyService))
                                {
                                    result = false;
                                    string code = codedText.DefiningCode == null ? "" : codedText.DefiningCode.CodeString;
                                    ValidationContext.AcceptValidationError(this, string.Format(AmValidationStrings.TextValueXInvalidForCodeY, codedText.Value, code));
                                }
                            }
                        }
                    }
                }
            }

            return(result);
        }