Exemplo n.º 1
0
        /// <summary>
        /// Finds an element with a given attribute value.
        /// </summary>
        /// <param name="element">The element.</param>
        /// <param name="attribute">The attribute.</param>
        /// <param name="value">The value.</param>
        /// <returns></returns>
        public bool FindElementWithAttributeValue(string element, string attribute, string value)
        {
            if (GetType().GetField(element) == null || GetType().GetField(attribute) == null)
            {
                return(false);
            }
            var ELEMENT = GetType().GetField(element).GetValue(this);

            var ATTRIBUTE = GetType().GetField(attribute).GetValue(this);

            if (string.IsNullOrEmpty(ELEMENT?.ToString()))
            {
                return(false);
            }

            if (string.IsNullOrEmpty(ATTRIBUTE?.ToString()))
            {
                return(false);
            }

            var res = OdmXmlDoc.Descendants(ELEMENT.ToString())
                      .FirstOrDefault(el => el.Attribute(ATTRIBUTE.ToString()) != null &&
                                      el.Attribute(ATTRIBUTE.ToString())?.Value == value);

            return(res != null);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Begin parsing the records, building up a context object
        /// </summary>
        public override void Start()
        {
            //Loop through each clinical data element
            foreach (var cData in OdmXmlDoc.Descendants(E_CLINICAL_DATA))
            {
                //reset ref state
                REF_STATE = AUDIT_REF_STATE;

                //Establish context object
                Context = new Context(
                    cData.Attribute(A_STUDY_OID).Value,
                    cData.Attribute(A_AUDIT_SUBCATEGORY_NAME).Value,
                    TryInt(cData.Attribute(A_METADATA_VERSION_OID).Value));

                //Subject Data
                var subjectData = GetElementsFrom(cData, E_SUBJECT_DATA);

                //SiteRef Data
                var siteRef = GetElementsFrom(cData, E_SITEREF_DATA);

                if (subjectData != null)
                {
                    Context.Subject = new Subject(
                        GetAttributeValueFrom(subjectData, A_SUBJECT_KEY),
                        GetAttributeValueFrom(subjectData, A_SUBJECT_NAME),
                        GetAttributeValueFrom(subjectData, A_SUBJECT_STATUS),
                        GetAttributeValueFrom(subjectData, A_TRANSACTION_TYPE),
                        GetAttributeValueFrom(subjectData, A_mdsol_SUBJECT_KEY_TYPE),
                        GetAttributeValueFrom(siteRef, A_LOCATION_OID)
                        );
                }

                // Study Event Data
                var studyEventData = GetElementsFrom(cData, E_STUDYEVENT_DATA);

                if (studyEventData != null)
                {
                    Context.StudyEvent = new StudyEvent(
                        GetAttributeValueFrom(studyEventData, A_STUDYEVENT_OID),
                        GetAttributeValueFrom(studyEventData, A_STUDYEVENT_REPEAT_KEY),
                        GetAttributeValueFrom(studyEventData, A_TRANSACTION_TYPE),
                        GetAttributeValueFrom(studyEventData, A_INSTANCE_NAME),
                        GetAttributeValueFrom(studyEventData, A_INSTANCE_OVERDUE),
                        TryInt(GetAttributeValueFrom(studyEventData, A_INSTANCE_ID))
                        );
                }

                //User Ref data
                var userRefData = cData.Descendants().FirstOrDefault(x => x.Name == E_USER_REF);

                if (userRefData != null)
                {
                    var ctxt = AuditOrSignatureElement();
                    ctxt.UserOID = userRefData.Attribute(A_USER_OID) == null ? "" : userRefData.Attribute(A_USER_OID).Value;
                }

                //Source ID data
                var sourceId = TryInt(cData.Descendants().FirstOrDefault(x => x.Name == E_SOURCE_ID).Value);
                Context.AuditRecord.SourceID = sourceId;
                LastSourceID = sourceId;

                //DateTimeStamp data
                var dtStamp = cData.Descendants().FirstOrDefault(x => x.Name == E_DATE_TIME_STAMP);
                if (dtStamp != null)
                {
                    AuditOrSignatureElement().DateTimeStamp = DateTime.Parse(dtStamp.Value);
                }

                //Reason for Change data
                var reasonForChange = cData.Descendants().FirstOrDefault(x => x.Name == E_REASON_FOR_CHANGE);
                if (reasonForChange != null)
                {
                    Context.AuditRecord.ReasonForChange = reasonForChange.Value;
                }

                // Location Ref Data
                var locationRefData = cData.Descendants().FirstOrDefault(x => x.Name == E_LOCATION_REF);

                if (locationRefData != null)
                {
                    AuditOrSignatureElement().LocationOID = locationRefData.Attribute(A_LOCATION_OID) == null ? "" : locationRefData.Attribute(A_LOCATION_OID).Value;
                }

                //Form Data
                var formData = cData.Descendants().FirstOrDefault(x => x.Name == E_FORM_DATA);

                if (formData != null)
                {
                    Context.Form = new Form(
                        GetAttributeValueFrom(formData, A_FORM_OID),
                        TryInt(GetAttributeValueFrom(formData, A_FORM_REPEAT_KEY)),
                        GetAttributeValueFrom(formData, A_TRANSACTION_TYPE),
                        GetAttributeValueFrom(formData, A_DATAPAGE_NAME),
                        TryInt(GetAttributeValueFrom(formData, A_DATAPAGE_ID))
                        );
                }

                //ItemGroup Data
                var itemGroupData = cData.Descendants().FirstOrDefault(x => x.Name == E_ITEM_GROUP_DATA);

                if (itemGroupData != null)
                {
                    Context.ItemGroup = new ItemGroup(
                        GetAttributeValueFrom(itemGroupData, A_ITEMGROUP_OID),
                        TryInt(GetAttributeValueFrom(itemGroupData, A_ITEMGROUP_REPEAT_KEY)),
                        GetAttributeValueFrom(itemGroupData, A_TRANSACTION_TYPE),
                        TryInt(GetAttributeValueFrom(itemGroupData, A_RECORD_ID))
                        );
                }

                //Item Data
                var itemData = cData.Descendants().FirstOrDefault(x => x.Name == E_ITEM_DATA);

                if (itemData != null)
                {
                    //MeasurementUnitRef
                    var measurementUnitData =
                        itemData.Descendants().FirstOrDefault(x => x.Name == E_MEASUREMENT_UNIT_REF);

                    var mmtUnitOid = measurementUnitData != null?GetAttributeValueFrom(measurementUnitData, A_MEASUREMENT_UNIT_OID) : "";

                    Context.Item = new Item(
                        GetAttributeValueFrom(itemData, A_ITEM_OID),
                        GetAttributeValueFrom(itemData, A_VALUE),
                        TrueOrFalse(itemData.Attribute(A_FREEZE)),
                        TrueOrFalse(itemData.Attribute(A_VERIFY)),
                        TrueOrFalse(itemData.Attribute(A_LOCK)),
                        GetAttributeValueFrom(itemData, A_TRANSACTION_TYPE),
                        mmtUnitOid
                        );
                }

                // Query Data
                var queryData = GetElementsFrom(cData, E_QUERY);

                if (queryData != null)
                {
                    Context.Query = new Query(
                        TryInt(GetAttributeValueFrom(queryData, A_QUERY_REPEAT_KEY)),
                        GetAttributeValueFrom(queryData, A_STATUS),
                        GetAttributeValueFrom(queryData, A_RESPONSE),
                        GetAttributeValueFrom(queryData, A_RECIPIENT),
                        GetAttributeValueFrom(queryData, A_VALUE)
                        );
                }

                // Protocol Deviation Data
                var pDevData = GetElementsFrom(cData, E_PROTOCOL_DEVIATION);

                if (pDevData != null)
                {
                    Context.ProtocolDeviation = new ProtocolDeviation(
                        TryInt(GetAttributeValueFrom(pDevData, A_PROTCOL_DEVIATION_REPEAT_KEY)),
                        GetAttributeValueFrom(pDevData, A_CODE),
                        GetAttributeValueFrom(pDevData, A_CLASS),
                        GetAttributeValueFrom(pDevData, A_STATUS),
                        GetAttributeValueFrom(pDevData, A_VALUE),
                        GetAttributeValueFrom(pDevData, A_TRANSACTION_TYPE)

                        );
                }

                //Review Data
                var reviewData = GetElementsFrom(cData, E_REVIEW);
                if (reviewData != null)
                {
                    Context.Review = new Review(
                        GetAttributeValueFrom(reviewData, A_GROUP_NAME),
                        TrueOrFalse(reviewData.Attribute(A_REVIEWED))
                        );
                }

                //Comment Data

                var commentData = GetElementsFrom(cData, E_COMMENT);
                if (commentData != null)
                {
                    Context.Comment = new Comment(
                        TryInt(GetAttributeValueFrom(commentData, A_COMMENT_REPEAT_KEY)),
                        GetAttributeValueFrom(commentData, A_VALUE),
                        GetAttributeValueFrom(commentData, A_TRANSACTION_TYPE)
                        );
                }

                //Signature Data
                var sigData = GetElementsFrom(cData, E_SIGNATURE);
                if (sigData != null)
                {
                    REF_STATE = SIGNATURE_REF_STATE;
                }

                //Signature Ref Data
                var sigRefData = GetElementsFrom(cData, E_SIGNATURE_REF);
                if (sigRefData != null)
                {
                    Context.Signature.OID = GetAttributeValueFrom(sigRefData, A_SIGNATURE_OID);
                }

                //Raise event for each context element built
                OnContextBuilt(Context);
            }
        }