private Model.Composite GetComposite(KeyValuePair <string, List <int> > item) { Model.Composite oComposite = new Model.Composite(); oComposite.Code = item.Key; foreach (var index in item.Value) { XName target = String.Format("{0}.{1}.{2}", item.Key, index.ToString(), "CONTENT"); XElement CompDetail = (from x in CompositeElementList where (string)x.Attribute(HL7v2Xsd.Attributes.Name) == target select x).Single(); Model.CompositeItem oSchemaBase = BuildSingleComposite(CompDetail); oComposite.CompositeItem.Add(index, oSchemaBase); } return(oComposite); }
private Model.CompositeItem BuildSingleComposite(XElement CompDetail) { string DataTypeCode = CompDetail.Element(HL7v2Xsd.Elements.Annotation).Element(HL7v2Xsd.Elements.Appinfo).Element(HL7v2Xsd.Elements.Type).Value; string DataTypeDescription = CompDetail.Element(HL7v2Xsd.Elements.Annotation).Element(HL7v2Xsd.Elements.Appinfo).Element(HL7v2Xsd.Elements.LongName).Value; string DataTypeTable = string.Empty; if (CompDetail.Element(HL7v2Xsd.Elements.Annotation).Element(HL7v2Xsd.Elements.Appinfo).Element(HL7v2Xsd.Elements.Table) != null) { DataTypeTable = CompDetail.Element(HL7v2Xsd.Elements.Annotation).Element(HL7v2Xsd.Elements.Appinfo).Element(HL7v2Xsd.Elements.Table).Value; } Model.DataTypeBase oDataTypeBase = DataTypeList.SingleOrDefault(x => x.Code == DataTypeCode); if (oDataTypeBase != null) { Model.CompositeItem oComponent = new Model.CompositeItem(); oComponent.Description = DataTypeDescription; oComponent.Type = oDataTypeBase; oComponent.Hl7TableIndex = 0; SetHl7Table(DataTypeTable, oComponent); return(oComponent); } else { oDataTypeBase = DataTypeList.SingleOrDefault(x => x.Code == DataTypeCode); if (oDataTypeBase != null) { Model.CompositeItem oComponent = new Model.CompositeItem(); oComponent.Description = DataTypeDescription; oComponent.Type = oDataTypeBase; oComponent.Hl7TableIndex = 0; SetHl7Table(DataTypeTable, oComponent); return(oComponent); } else { //if the sub data type is not in the primitives or the current composite lists then it has not been resolved as yet //and must be a composite as all primitives are resolved at this point. There for we lookup this new composite //and resolve it then continue on as planed. KeyValuePair <string, List <int> > oSingleCompositeIndexList = CompositeIndexList.Single(x => x.Key == DataTypeCode); DataTypeList.Add(GetComposite(oSingleCompositeIndexList)); oDataTypeBase = DataTypeList.SingleOrDefault(x => x.Code == DataTypeCode); Model.CompositeItem oComponent = new Model.CompositeItem(); oComponent.Description = DataTypeDescription; oComponent.Type = oDataTypeBase; oComponent.Hl7TableIndex = 0; SetHl7Table(DataTypeTable, oComponent); return(oComponent); } } }
private static void SetHl7Table(string DataTypeTable, Model.CompositeItem oComponent) { if (DataTypeTable != String.Empty) { try { if (DataTypeTable.Substring(0, 3) != "HL7") { throw new Exception("A data type references a table that is not prefixed with HL7, what is this table. Ref found was: " + DataTypeTable); } oComponent.Hl7TableIndex = Convert.ToInt32(DataTypeTable.Substring(3, (DataTypeTable.Length - 3))); } catch (Exception exec) { throw new Exception("A HL7 Table reference was not an integer in the XML schema files. Found: " + DataTypeTable, exec); } } }