public void ExtractDeductibleTransactions_MultipleDeductibleCTDOneCTGDeductibleOneNoCTG_DeductibleReturned() { Dictionary<string, string> fundedDeductibles = new Dictionary<string, string>(); fundedDeductibles.Add("A", "Deductible01"); fundedDeductibles.Add("B", "Deductible02"); Dictionary<string, string> fundedDeductiblePolicies = new Dictionary<string, string>(); fundedDeductiblePolicies.Add("Deductible01", "Policy1"); fundedDeductiblePolicies.Add("Deductible02", "Policy2"); string XmlClaim = @"<?xml version='1.0' encoding='utf-16'?> <ClaimHeader xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xmlns:xsd='http://www.w3.org/2001/XMLSchema' xmlns='http://www.xchanging.com/Xiap/Claims/Data/XML/2011/9'> <ClaimTransactionHeaders> </ClaimTransactionHeaders> </ClaimHeader>"; XmlDocument document = new XmlDocument(); XmlElement xmlNode = null; xmlNode = document.CreateElement("Claims"); XmlDocument doc = new XmlDocument(); doc.LoadXml(XmlClaim); XmlNode newNode = document.ImportNode(doc.DocumentElement, true); xmlNode.AppendChild(newNode); XiapClaim.ClaimTransactionHeader cth = new XiapClaim.ClaimTransactionHeader(); List<XiapClaim.ClaimTransactionGroup> ctgs = new List<XiapClaim.ClaimTransactionGroup>(); XiapClaim.ClaimTransactionGroup ctg1 = new XiapClaim.ClaimTransactionGroup(); ctg1.ClaimTransactionGroupID = 1; ctgs.Add(ctg1); List<XiapClaim.ClaimTransactionDetail> ctds1 = new List<XiapClaim.ClaimTransactionDetail>(); XiapClaim.ClaimTransactionDetail ctd2 = new XiapClaim.ClaimTransactionDetail(); ctd2.ClaimTransactionDetailID = 2; ctd2.MovementType = "B"; ctds1.Add(ctd2); XiapClaim.ClaimTransactionDetail ctd4 = new XiapClaim.ClaimTransactionDetail(); ctd4.ClaimTransactionDetailID = 4; ctd4.MovementType = "C"; ctds1.Add(ctd4); ctg1.ClaimTransactionDetails = ctds1.ToArray(); XiapClaim.ClaimTransactionGroup ctg2 = new XiapClaim.ClaimTransactionGroup(); ctg2.ClaimTransactionGroupID = 2; ctgs.Add(ctg2); List<XiapClaim.ClaimTransactionDetail> ctds2 = new List<XiapClaim.ClaimTransactionDetail>(); XiapClaim.ClaimTransactionDetail ctd6 = new XiapClaim.ClaimTransactionDetail(); ctd6.ClaimTransactionDetailID = 5; ctd6.MovementType = "B"; ctds2.Add(ctd6); ctg2.ClaimTransactionDetails = ctds2.ToArray(); cth.ClaimTransactionGroups = ctgs.ToArray(); XmlNode deductibles = ClaimTransferDataTransform.ExtractDeductibleTransactions(cth, fundedDeductibles, fundedDeductiblePolicies, liabClaimProduct, -1); Assert.IsNotNull(deductibles); XmlNamespaceManager nsmgr = new XmlNamespaceManager(document.NameTable); nsmgr.AddNamespace("XIAP", "http://www.xchanging.com/Xiap/Claims/Data/XML/2011/9"); XmlNode subNode = deductibles.SelectSingleNode("Deductible01"); Assert.IsNotNull(subNode); XmlAttribute attribute = subNode.Attributes["PolicyReference"]; Assert.AreEqual("Policy1", attribute.Value); XmlNodeList details = subNode.SelectNodes("descendant::XIAP:ClaimTransactionDetail", nsmgr); Assert.AreEqual(0, details.Count); subNode = deductibles.SelectSingleNode("Deductible02"); Assert.IsNotNull(subNode); attribute = subNode.Attributes["PolicyReference"]; Assert.AreEqual("Policy2", attribute.Value); details = subNode.SelectNodes("descendant::XIAP:ClaimTransactionDetail", nsmgr); Assert.AreEqual(2, details.Count); foreach (XmlNode detail in details) { XmlNode temp = detail.SelectSingleNode("XIAP:MovementType", nsmgr); Assert.IsNotNull(temp); Assert.AreEqual("B", temp.InnerText); } }
/// <summary> /// Returns the claim data detailed in the input parameters as an XML object /// with the deductibles as a separate block at the bottom. /// </summary> /// <param name="parameters">dictionary collection</param> /// <returns>xml element</returns> public XmlElement GetData(IDictionary<string, object> parameters) { if (_Logger.IsInfoEnabled) { _Logger.Info("ClaimTransferDataCollection.GetData"); } ArgumentCheck.ArgumentNullCheck(parameters, "parameters"); // Get the values from the passed in parameters dictionary string reference = (string)parameters[ReferenceArgument]; string detailReference = (string)parameters[DetailReferenceArgument]; long claimTransactionHeaderID; long.TryParse(detailReference, out claimTransactionHeaderID); DateTime dateTime = (DateTime)parameters[DateTimeArgument]; if (_Logger.IsInfoEnabled) { _Logger.Info(string.Format("Loading claim {0}", reference)); } // Load the XML claim targetClaim from the claim reference parameter XiapClaim.ClaimHeader targetClaim = LoadClaim(reference); // Then load the claim details on the target claim targetClaim.ClaimDetails = ClaimTransferDataTransform.FilterClaimDetails(targetClaim); Dictionary<string, string> fundedDeductibles = new Dictionary<string, string>(); Dictionary<string, string> fundedDeductiblePolicies = new Dictionary<string, string>(); List<long> policyGenericDataTypeVersions; string riskProductCode = null; XiapClaim.ClaimTransactionHeader cth = new XiapClaim.ClaimTransactionHeader(); // If there are ClaimTransactionHeaders on the claim we loaded, filter them down to only the one matching the CTH Id passed in. if (targetClaim.ClaimTransactionHeaders != null) { targetClaim.ClaimTransactionHeaders = targetClaim.ClaimTransactionHeaders.Where(a => a.ClaimTransactionHeaderID == claimTransactionHeaderID).ToArray(); } // Restructure the Claim Transaction Details to rollup non funded deductible payments and reserves cth = targetClaim.ClaimTransactionHeaders.FirstOrDefault(); using (MetadataEntities entities = MetadataEntitiesFactory.GetMetadataEntities()) { riskProductCode = ClaimTransferDataTransform.GetRiskProductCode(entities, targetClaim.ClaimProductVersionID); // Generic data type Code = "AND4" and gdt.CustomCode02 = "Deductible Type 02" policyGenericDataTypeVersions = (from gdt in entities.GenericDataType join gdtv in entities.GenericDataTypeVersion on gdt.Code equals gdtv.GenericDataType.Code where gdt.CustomCode02 == "P" select gdtv.GenericDataTypeVersionID).ToList(); // iF there are Funded Deductible types against the Policy for our Product // collect all the funded deductible policies entered against the claim. if (targetClaim.GenericDataSetID != null && policyGenericDataTypeVersions.Count > 0) { fundedDeductiblePolicies = GetFundedDeductiblePolicies(targetClaim.GenericDataSetID.Value, policyGenericDataTypeVersions); } if (fundedDeductiblePolicies.Count() == 0) { if (_Logger.IsInfoEnabled) { _Logger.Info(string.Format("No deductible policy references on claim {0}", targetClaim.ClaimReference)); } } // If we have a claim transaction header and it has a valid source get the funded deductible movment types from Claim Transactoin Header if (cth != null && cth.ClaimTransactionSource != null) { fundedDeductibles = GetFundedDeductibleMovementTypes(entities, (long)targetClaim.ClaimProductVersionID, riskProductCode, targetClaim.UWHeaderExternalReference, fundedDeductiblePolicies, cth); } if (fundedDeductibles.Count == 0) { if (_Logger.IsInfoEnabled) { _Logger.Info(string.Format("No deductible movements on claim {0}", targetClaim.ClaimReference)); } } } XmlNode deductibles = null; // Decode the claim transaction details on each Claim Transaction group on the Claim Transaction Header, // for the funded deductible movement types stored previously. if (cth != null) { foreach (XiapClaim.ClaimTransactionGroup ctg in cth.ClaimTransactionGroups) { ctg.ClaimTransactionDetails = ClaimTransferDataTransform.ConstructTransactiondetails(cth, ctg, fundedDeductibles); } } // Create the deductibles XML node of claim transaction details from the Claim Transaction Header deductibles = ClaimTransferDataTransform.ExtractDeductibleTransactions(cth, fundedDeductibles, fundedDeductiblePolicies, riskProductCode, targetClaim.ClaimHeaderID); // Remove any claim transaction detail from the risk claim if it is funded or has a zero movement amount if (cth != null) { cth = RemoveFundedAndNetZeroTransactions(fundedDeductibles, cth); // if there is no claim transaction details in a group then remove the claim transaction group cth.ClaimTransactionGroups = cth.ClaimTransactionGroups.Where(ctg => ctg.ClaimTransactionDetails.Count() > 0).ToArray(); // if claim transaction header has no claim transaction group, replace it with a blank, new Claim Transaction Header if (cth.ClaimTransactionGroups.Count() == 0) { cth = new XiapClaim.ClaimTransactionHeader(); } } if (_Logger.IsInfoEnabled) { _Logger.Info(string.Format("Serializing claim {0}", targetClaim.ClaimReference)); } // Serialise the claim. XmlSerializer serializer = new XmlSerializer(typeof(XiapClaim.ClaimHeader)); StringWriter sw = new StringWriter(); serializer.Serialize(sw, targetClaim); string XmlClaim = sw.ToString(); // Create a new document to add this claim to XmlDocument document = new XmlDocument(); XmlElement xmlNode = null; // Create the claim xml and add it to the document xmlNode = document.CreateElement("Claims"); XmlDocument doc = new XmlDocument(); doc.LoadXml(XmlClaim); XmlNode newNode = document.ImportNode(doc.DocumentElement, true); xmlNode.AppendChild(newNode); if (deductibles != null) { // If we have a deductibles XML, add this to the XML document too. newNode = document.ImportNode(deductibles, true); xmlNode.AppendChild(newNode); } return xmlNode; }