Exemplo n.º 1
0
        /// <summary>
        /// Creates a new instance of Sample
        /// </summary>
        /// <param name="labReportXml">Must be a EN:LabReport XML element from the XMLSampling schema</param>
        /// <param name="sampleNamespace">The value of the EN namespace as defined in the XMLSampling schema</param>
        /// <param name="labReportXml">The EN:LabReport element of which this sample is a part. This will be used for reconstructing the XML file later.</param>
        public Sample(XElement labReportXml, XNamespace sampleNamespace, string filename)
        {
            initSample();
            XmlNamespace               = sampleNamespace;
            this.XmlFilename           = filename;
            this.XmlParseDate          = DateTime.Now;
            this.LabIdentificationXml  = (from sam in labReportXml.Descendants(sampleNamespace + "LabIdentification") select sam).SingleOrDefault();
            LabIdentificationXmlString = LabIdentificationXml.ToString();
            this.SampleXml             = (from sam in labReportXml.Descendants(sampleNamespace + "Sample") select sam).SingleOrDefault();
            SampleXmlString            = SampleXml.ToString();
            var element = (from sam in SampleXml.Descendants(sampleNamespace + "LabSampleIdentifier") select sam).SingleOrDefault();

            if (element != null && !string.IsNullOrWhiteSpace(element.Value))
            {
                this.LabSampleIdentifier = element.Value;
            }
            element = (from sam in LabIdentificationXml.Descendants(sampleNamespace + "LabAccreditationIdentifier") select sam).SingleOrDefault();
            if (element != null && !string.IsNullOrWhiteSpace(element.Value))
            {
                this.LabAccredidationIdentifier = element.Value;
            }
            element = (from sam in SampleXml.Descendants(sampleNamespace + "PWSIdentifier") select sam).SingleOrDefault();
            if (element != null && !string.IsNullOrWhiteSpace(element.Value))
            {
                this.PWSIdentifier = element.Value;
            }
            element = (from sam in SampleXml.Descendants(sampleNamespace + "PWSFacilityIdentifier") select sam).SingleOrDefault();
            if (element != null && !string.IsNullOrWhiteSpace(element.Value))
            {
                this.PWSFacilityIdentifier = element.Value;
            }
            element = (from sam in SampleXml.Descendants(sampleNamespace + "SampleRuleCode") select sam).SingleOrDefault();
            if (element != null && !string.IsNullOrWhiteSpace(element.Value))
            {
                this.SampleRuleCode = element.Value;
            }
            element = (from sam in SampleXml.Descendants(sampleNamespace + "SampleMonitoringTypeCode") select sam).SingleOrDefault();
            if (element != null && !string.IsNullOrWhiteSpace(element.Value))
            {
                this.SampleMonitoringTypeCode = element.Value;
            }
            element = (from sam in SampleXml.Descendants(sampleNamespace + "SampleCollectionEndDate") select sam).SingleOrDefault();
            if (element != null && !string.IsNullOrWhiteSpace(element.Value))
            {
                this.SampleCollectionEndDate = Convert.ToDateTime(element.Value);
                _hasCollectionDate           = true;
            }
            element = (from sam in SampleXml.Descendants(sampleNamespace + "SampleCollectionEndTime") select sam).SingleOrDefault();
            if (element != null && !string.IsNullOrWhiteSpace(element.Value) && this.SampleCollectionEndDate != new DateTime(0))
            {
                this.SampleCollectionEndDate = ((DateTime)this.SampleCollectionEndDate).Add(TimeSpan.Parse(element.Value));
                DateTime testForZeroTime = DateTime.MinValue;
                testForZeroTime = testForZeroTime.Add(TimeSpan.Parse(element.Value));
                if (testForZeroTime.Equals(DateTime.MinValue))
                {
                    _hasCollectionTime = false;
                }
                else
                {
                    _hasCollectionTime = true;
                }
            }
            element = (from sam in SampleXml.Descendants(sampleNamespace + "SampleVolume") select sam).SingleOrDefault();
            if (element != null && !string.IsNullOrWhiteSpace(element.Value))
            {
                this.SampleVolume = Convert.ToDouble(element.Value);
            }
            element = (from sam in SampleXml.Descendants(sampleNamespace + "SampleLocationIdentifier") select sam).SingleOrDefault();
            if (element != null && !string.IsNullOrWhiteSpace(element.Value))
            {
                this.SampleLocationIdentifier = element.Value;
            }
            element = (from sam in SampleXml.Descendants(sampleNamespace + "SampleLocationCollectionAddress") select sam).SingleOrDefault();
            if (element != null && !string.IsNullOrWhiteSpace(element.Value))
            {
                this.SampleLocationCollectionAddress = element.Value;
            }
            element = (from sam in SampleXml.Descendants(sampleNamespace + "SampleCollector") select sam).SingleOrDefault();
            if (element != null && !string.IsNullOrWhiteSpace(element.Value))
            {
                this.SampleCollector = element.Value;
                _hasCollectorName    = true;
            }
            element = (from sam in SampleXml.Descendants(sampleNamespace + "SampleLaboratoryReceiptDate") select sam).SingleOrDefault();
            if (element != null && !string.IsNullOrWhiteSpace(element.Value))
            {
                this.SampleLaboratoryReceiptDate = Convert.ToDateTime(element.Value);
                _hasLabReceiptDate = true;
            }
            element = (from sam in SampleXml.Descendants(sampleNamespace + "LabSampleCompositeDate") select sam).SingleOrDefault();
            if (element != null && !string.IsNullOrWhiteSpace(element.Value))
            {
                this.LabSampleCompositeDate = Convert.ToDateTime(element.Value);
                _isCompositeSample          = true;
            }
            element = (from sam in SampleXml.Descendants(sampleNamespace + "Comments") select sam).SingleOrDefault();
            if (element != null && !string.IsNullOrWhiteSpace(element.Value))
            {
                string comments = element.Value;
                if (comments.Contains("Reporting Lab"))
                {
                    string labId = comments.Substring(comments.LastIndexOf(" ") + 1);
                    this.SubmittingLabIdentifier = labId;
                }
            }
            HandleFedTypeAndMonitoringType();
        }