本文整理汇总了C#中ISegment.GetField方法的典型用法代码示例。如果您正苦于以下问题:C# ISegment.GetField方法的具体用法?C# ISegment.GetField怎么用?C# ISegment.GetField使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ISegment
的用法示例。
在下文中一共展示了ISegment.GetField方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: copy
/// <summary> Copies contents from the source segment to the destination segment. This
/// method calls copy(Type, Type) on each repetition of each field (see additional
/// behavioural description there). An attempt is made to copy each repetition of
/// each field in the source segment, regardless of whether the corresponding
/// destination field is repeating or even exists.
/// </summary>
/// <param name="from">the segment from which data are copied
/// </param>
/// <param name="to">the segment into which data are copied
/// </param>
public static void copy(ISegment from, ISegment to)
{
int n = from.NumFields();
for (int i = 1; i <= n; i++)
{
IType[] reps = from.GetField(i);
for (int j = 0; j < reps.Length; j++)
{
copy(reps[j], to.GetField(i, j));
}
}
}
示例2: fixOBX5
/// <summary> Sets the data type of field 5 in the given OBX segment to the value of OBX-2. The argument
/// is a Segment as opposed to a particular OBX because it is meant to work with any version.
/// </summary>
public static void fixOBX5(ISegment segment, IModelClassFactory factory)
{
try
{
//get unqualified class name
IPrimitive obx2 = (IPrimitive) segment.GetField(2, 0);
foreach (IType repetition in segment.GetField(5))
{
Varies v = (Varies) repetition;
if (obx2.Value == null)
{
if (v.Data != null)
{
if (!(v.Data is IPrimitive) || ((IPrimitive) v.Data).Value != null)
{
throw new HL7Exception(
"OBX-5 is valued, but OBX-2 is not. A datatype for OBX-5 must be specified using OBX-2.",
HL7Exception.REQUIRED_FIELD_MISSING);
}
}
}
else
{
Type c = factory.GetTypeClass(obx2.Value, segment.Message.Version);
v.Data = (IType) c.GetConstructor(new [] {typeof (IMessage), typeof(String)}).Invoke(new Object[] {v.Message, v.Description});
}
}
}
catch (HL7Exception e)
{
throw e;
}
catch (Exception e)
{
throw new HL7Exception(e.GetType().FullName + " trying to set data type of OBX-5",
HL7Exception.APPLICATION_INTERNAL_ERROR, e);
}
}
示例3: Encode
public static String Encode(ISegment source, EncodingCharacters encodingChars)
{
StringBuilder result = new StringBuilder();
result.Append(source.GetStructureName());
result.Append(encodingChars.FieldSeparator);
//start at field 2 for MSH segment because field 1 is the field delimiter
int startAt = 1;
if (IsDelimDefSegment(source.GetStructureName()))
startAt = 2;
//loop through fields; for every field delimit any repetitions and add field delimiter after ...
int numFields = source.NumFields();
for (int i = startAt; i <= numFields; i++)
{
try
{
IType[] reps = source.GetField(i);
for (int j = 0; j < reps.Length; j++)
{
String fieldText = Encode(reps[j], encodingChars);
//if this is MSH-2, then it shouldn't be escaped, so unescape it again
if (IsDelimDefSegment(source.GetStructureName()) && i == 2)
fieldText = Escape.unescape(fieldText, encodingChars);
result.Append(fieldText);
if (j < reps.Length - 1)
result.Append(encodingChars.RepetitionSeparator);
}
}
catch (HL7Exception e)
{
log.Error("Error while encoding segment: ", e);
}
result.Append(encodingChars.FieldSeparator);
}
//strip trailing delimiters ...
return StripExtraDelimiters(result.ToString(), encodingChars.FieldSeparator);
}
示例4: Parse
/// <summary> Parses a segment string and populates the given Segment object. Unexpected fields are
/// added as Varies' at the end of the segment.
///
/// </summary>
/// <throws> HL7Exception if the given string does not contain the </throws>
/// <summary> given segment or if the string is not encoded properly
/// </summary>
public virtual void Parse(ISegment destination, String segment, EncodingCharacters encodingChars)
{
int fieldOffset = 0;
if (IsDelimDefSegment(destination.GetStructureName()))
{
fieldOffset = 1;
//set field 1 to fourth character of string
Terser.Set(destination, 1, 0, 1, 1, Convert.ToString(encodingChars.FieldSeparator));
}
String[] fields = Split(segment, Convert.ToString(encodingChars.FieldSeparator));
for (int i = 1; i < fields.Length; i++)
{
String[] reps = Split(fields[i], Convert.ToString(encodingChars.RepetitionSeparator));
if (log.DebugEnabled)
{
log.Debug(reps.Length + "reps delimited by: " + encodingChars.RepetitionSeparator);
}
//MSH-2 will get split incorrectly so we have to fudge it ...
bool isMSH2 = IsDelimDefSegment(destination.GetStructureName()) && i + fieldOffset == 2;
if (isMSH2)
{
reps = new String[1];
reps[0] = fields[i];
}
for (int j = 0; j < reps.Length; j++)
{
try
{
StringBuilder statusMessage = new StringBuilder("Parsing field ");
statusMessage.Append(i + fieldOffset);
statusMessage.Append(" repetition ");
statusMessage.Append(j);
log.Debug(statusMessage.ToString());
IType field = destination.GetField(i + fieldOffset, j);
if (isMSH2)
{
Terser.getPrimitive(field, 1, 1).Value = reps[j];
}
else
{
Parse(field, reps[j], encodingChars);
}
}
catch (HL7Exception e)
{
//set the field location and throw again ...
e.FieldPosition = i + fieldOffset;
e.SegmentRepetition = MessageIterator.getIndex(destination.ParentStructure, destination).rep;
e.SegmentName = destination.GetStructureName();
throw;
}
}
}
//set data type of OBX-5
if (destination.GetType().FullName.IndexOf("OBX") >= 0)
{
Varies.fixOBX5(destination, Factory);
}
}
示例5: populate
/// <summary> Populates the given error segment with information from this Exception.</summary>
public virtual void populate(ISegment errorSegment)
{
//make sure it's an ERR
if (!errorSegment.GetStructureName().Equals("ERR"))
throw new HL7Exception("Can only populate an ERR segment with an exception -- got: " + errorSegment.GetType().FullName);
int rep = errorSegment.GetField(1).Length; //append after existing reps
if (this.SegmentName != null)
Terser.Set(errorSegment, 1, rep, 1, 1, this.SegmentName);
if (this.SegmentRepetition >= 0)
Terser.Set(errorSegment, 1, rep, 2, 1, System.Convert.ToString(this.SegmentRepetition));
if (this.FieldPosition >= 0)
Terser.Set(errorSegment, 1, rep, 3, 1, System.Convert.ToString(this.FieldPosition));
Terser.Set(errorSegment, 1, rep, 4, 1, System.Convert.ToString(this.errCode));
Terser.Set(errorSegment, 1, rep, 4, 3, "hl70357");
Terser.Set(errorSegment, 1, rep, 4, 5, this.Message);
//try to get error condition text
try
{
System.String desc = TableRepository.Instance.getDescription(357, System.Convert.ToString(this.errCode));
Terser.Set(errorSegment, 1, rep, 4, 2, desc);
}
catch (LookupException e)
{
ourLog.Debug("Warning: LookupException getting error condition text (are we connected to a TableRepository?)", e);
}
}
示例6: getPrimitive
/// <summary> Returns the Primitive object at the given location.</summary>
private static IPrimitive getPrimitive(ISegment segment, int field, int rep, int component, int subcomponent)
{
IType type = segment.GetField(field, rep);
return getPrimitive(type, component, subcomponent);
}
示例7: Encode
/// <summary> Populates the given Element with data from the given Segment, by inserting
/// Elements corresponding to the Segment's fields, their components, etc. Returns
/// true if there is at least one data value in the segment.
/// </summary>
public virtual bool Encode(ISegment segmentObject, XmlElement segmentElement)
{
bool hasValue = false;
int n = segmentObject.NumFields();
for (int i = 1; i <= n; i++)
{
String name = MakeElementName(segmentObject, i);
IType[] reps = segmentObject.GetField(i);
for (int j = 0; j < reps.Length; j++)
{
XmlElement newNode = segmentElement.OwnerDocument.CreateElement(name);
bool componentHasValue = Encode(reps[j], newNode);
if (componentHasValue)
{
try
{
segmentElement.AppendChild(newNode);
}
catch (Exception e)
{
throw new HL7Exception("DOMException encoding Segment: ", HL7Exception.APPLICATION_INTERNAL_ERROR, e);
}
hasValue = true;
}
}
}
return hasValue;
}
示例8: ParseReps
private void ParseReps(ISegment segmentObject, XmlElement segmentElement, String fieldName, int fieldNum)
{
XmlNodeList reps = segmentElement.GetElementsByTagName(fieldName);
for (int i = 0; i < reps.Count; i++)
{
Parse(segmentObject.GetField(fieldNum, i), (XmlElement) reps.Item(i));
}
}
示例9: fixOBX5
/// <summary> Sets the data type of field 5 in the given OBX segment to the value of OBX-2. The argument
/// is a Segment as opposed to a particular OBX because it is meant to work with any version.
/// </summary>
public static void fixOBX5(ISegment segment, IModelClassFactory factory)
{
try
{
//get unqualified class name
IPrimitive obx2 = (IPrimitive)segment.GetField(2, 0);
Varies v = (Varies)segment.GetField(5, 0);
if (obx2.Value == null)
{
if (v.Data != null)
{
if (!(v.Data is IPrimitive) || ((IPrimitive)v.Data).Value != null)
{
throw new HL7Exception("OBX-5 is valued, but OBX-2 is not. A datatype for OBX-5 must be specified using OBX-2.", HL7Exception.REQUIRED_FIELD_MISSING);
}
}
}
else
{
//set class
System.Type c = factory.GetTypeClass(obx2.Value, segment.Message.Version);
// Class c = NHapi.Base.Parser.ParserBase.findClass(obx2.getValue(),
// segment.getMessage().getVersion(),
// "datatype");
v.Data = (IType)c.GetConstructor(new System.Type[] { typeof(IMessage) }).Invoke(new System.Object[] { v.Message });
}
}
catch (HL7Exception e)
{
throw e;
}
catch (System.Exception e)
{
throw new HL7Exception(e.GetType().FullName + " trying to set data type of OBX-5", HL7Exception.APPLICATION_INTERNAL_ERROR, e);
}
}