/// <summary> Returns the number of components in the given field, i.e. the /// number of standard components (e.g. 6 for CE) plus any extra components that /// have been added at runtime. This may vary by repetition, as different reps /// may have different extra components. /// </summary> /*public static int numComponents(Type field) throws HL7Exception { * return numComponents(seg.getField(field, rep)); * }*/ /// <summary> Returns the number of sub-components in the specified component, i.e. /// the number of standard sub-components (e.g. 6 for CE) plus any extra components that /// that have been added at runtime. /// </summary> /// <param name="component">numbered from 1 /// </param> public static int numSubComponents(model.Type type, int component) { int n = -1; if (component == 1 && typeof(Primitive).IsAssignableFrom(type.GetType())) { //note that getComponent(primitive, 1) below returns the primitive //itself -- if we do numComponents on it, we'll end up with the //number of components in the field, not the number of subcomponents n = 1; } else { model.Type comp = getComponent(type, component); n = numComponents(comp); } return(n); /* * //Type t = seg.getField(field, rep); * if (Varies.class.isAssignableFrom(type.getClass())) { * return numSubComponents(((Varies) type).getData(), component); * } else if (Primitive.class.isAssignableFrom(type.getClass()) && component == 1) { * n = 1; * } else if (Composite.class.isAssignableFrom(type.getClass()) && component <= numStandardComponents(t)) { * n = numComponents(((Composite) type).getComponent(component - 1)); * } else { //we're being asked about subcomponents of an extra component * n = numComponents(t.getExtraComponents().getComponent(component - numStandardComponents(t) - 1)); * } * return n; */ }
/// <summary> Attempts to extract a Primitive from the given type. If it's a composite, /// drills down through first components until a primitive is reached. /// </summary> private static Primitive getPrimitive(model.Type type) { Primitive p = null; if (typeof(Varies).IsAssignableFrom(type.GetType())) { p = getPrimitive(((Varies)type).Data); } else if (typeof(Composite).IsAssignableFrom(type.GetType())) { try { p = getPrimitive(((Composite)type).getComponent(0)); } catch (HL7Exception) { throw new System.ApplicationException("Internal error: HL7Exception thrown on Composite.getComponent(0)."); } } else if (type is Primitive) { p = (Primitive)type; } return(p); }
/// <summary> Copies data from the "from" Type into the "to" Type. Either Type may be /// a Primitive, Composite, or Varies. If a Varies is provided, the operation is /// performed on the result of calling its getData() method. A Primitive may be /// copied into a Composite, in which case the value is copied into the first /// component of the Composite. A Composite may be copied into a Primitive, /// in which case the first component is copied. Given Composites with different /// numbers of components, the first components are copied, up to the length /// of the smaller one. /// </summary> public static void copy(model.Type from, model.Type to) { for (int i = 1; i <= Terser.numComponents(from); i++) { for (int j = 1; j <= Terser.numSubComponents(from, i); j++) { System.String val = Terser.getPrimitive(from, i, j).Value; Terser.getPrimitive(to, i, j).Value = val; } } }
public Car(model.Type type, string brand, Producer producer, int year, int hp, string color, decimal price, Person owner) { this.Type = type; this.Brand = brand; this.Producer = producer; this.Year = year; this.HP = hp; this.Color = color; this.Price = price; this.Owner = owner; }
/// <summary> Returns the number of components in the given type, i.e. the /// number of standard components (e.g. 6 for CE) plus any extra components that /// have been added at runtime. /// </summary> public static int numComponents(model.Type type) { if (typeof(Varies).IsAssignableFrom(type.GetType())) { return(numComponents(((Varies)type).Data)); } else { return(numStandardComponents(type) + type.ExtraComponents.numComponents()); } }
/// <summary> Returns the component (or sub-component, as the case may be) at the given /// index. If it does not exist, it is added as an "extra component". /// If comp > 1 is requested from a Varies with GenericPrimitive data, the /// data is set to GenericComposite (this avoids the creation of a chain of /// ExtraComponents on GenericPrimitives). /// Components are numbered from 1. /// </summary> private static ca.uhn.hl7v2.model.Type getComponent(model.Type type, int comp) { model.Type ret = null; if (typeof(Varies).IsAssignableFrom(type.GetType())) { Varies v = (Varies)type; try { if (comp > 1 && typeof(GenericPrimitive).IsAssignableFrom(v.Data.GetType())) { v.Data = new GenericComposite(v.Message); } } catch (DataTypeException de) { //UPGRADE_TODO: The equivalent in .NET for method 'java.lang.Throwable.getMessage' may return a different value. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1043'" System.String message = "Unexpected exception copying data to generic composite: " + de.Message; log.error(message, de); throw new System.ApplicationException(message); } ret = getComponent(v.Data, comp); } else { if (typeof(Primitive).IsAssignableFrom(type.GetType()) && comp == 1) { ret = type; } else if (typeof(GenericComposite).IsAssignableFrom(type.GetType()) || (typeof(Composite).IsAssignableFrom(type.GetType()) && comp <= numStandardComponents(type))) { //note that GenericComposite can return components > number of standard components try { ret = ((Composite)type).getComponent(comp - 1); } catch (System.Exception e) { //TODO: This may not be the write exception type: Error() was originally thrown, but was not in project. throw new ApplicationException("Internal error: HL7Exception thrown on getComponent(x) where x < # standard components.", e); } } else { ret = type.ExtraComponents.getComponent(comp - numStandardComponents(type) - 1); } } return(ret); }
private static int numStandardComponents(model.Type t) { int n = 0; if (typeof(Varies).IsAssignableFrom(t.GetType())) { n = numStandardComponents(((Varies)t).Data); } else if (typeof(Composite).IsAssignableFrom(t.GetType())) { n = ((Composite)t).Components.Length; } else { n = 1; } return(n); }
public SportCar(model.Type type, string brand, Producer producer, int year, int hp, string color, decimal price, Person owner) : base(type, brand, producer, year, hp, color, price, owner) { }
/// <summary> Returns the Primitive object at the given location in the given field. /// It is intended that the given type be at the field level, although extra components /// will be added blindly if, for example, you provide a primitive subcomponent instead /// and specify component or subcomponent > 1 /// </summary> public static Primitive getPrimitive(model.Type type, int component, int subcomponent) { model.Type comp = getComponent(type, component); model.Type sub = getComponent(comp, subcomponent); return(getPrimitive(sub)); }
/// <summary> Returns the Primitive object at the given location.</summary> private static Primitive getPrimitive(Segment segment, int field, int rep, int component, int subcomponent) { model.Type type = segment.getField(field, rep); return(getPrimitive(type, component, subcomponent)); }