public static string getValueByPosition(HL7Message message, SegmentType segmentType, string position, int segmentOrder = NEG_ONE) { string[] positionMap; // if there is a period, we are looking through multiple values if (position.Contains(PERIOD)) { positionMap = position.Split(PERIOD); } else { // we are only interested in a field data positionMap = new string[ONE]; positionMap[ZERO] = position; } // associates the field no to the mapped value below int fieldNo = ZERO; int componentNo = ZERO; int subComponentNo = ZERO; int repetitionNo = ZERO; // gets the length (and determines the case) based on the map (3.1.1.1) int mapCount = (position != BLANK) ? positionMap.Length : ZERO; switch (mapCount) { case 1: // map fields fieldNo = Convert.ToInt32(positionMap[FIELD_ELEMENT]); // return value in text only return(Field.getFieldByPos(message, segmentType, fieldNo, segmentOrder).value); case 2: // map fields fieldNo = Convert.ToInt32(positionMap[FIELD_ELEMENT]); componentNo = Convert.ToInt32(positionMap[COMPONENT_ELEMENT]); // set classes Field c2f = Field.getFieldByPos(message, segmentType, fieldNo); // return value in text only return(Component.getComponentByPos(c2f, componentNo).value); case 3: // map fields fieldNo = Convert.ToInt32(positionMap[FIELD_ELEMENT]); componentNo = Convert.ToInt32(positionMap[COMPONENT_ELEMENT]); subComponentNo = Convert.ToInt32(positionMap[SUB_COMPONENT_ELEMENT]); // set classes Field c3f = Field.getFieldByPos(message, segmentType, fieldNo); Component c3c = Component.getComponentByPos(c3f, componentNo); // return value in text only return(SubComponent.getSubComponentByPos(c3c, subComponentNo).value); case 4: // map fields fieldNo = Convert.ToInt32(positionMap[FIELD_ELEMENT]); componentNo = Convert.ToInt32(positionMap[COMPONENT_ELEMENT]); subComponentNo = Convert.ToInt32(positionMap[SUB_COMPONENT_ELEMENT]); repetitionNo = Convert.ToInt32(positionMap[REPETITION_ELEMENT]); // set classes Field c4f = Field.getFieldByPos(message, segmentType, fieldNo); Component c4c = Component.getComponentByPos(c4f, componentNo); SubComponent c4sc = SubComponent.getSubComponentByPos(c4c, subComponentNo); // return value in text only return(Repetition.getRepetitionByPos(c4sc, repetitionNo).value); default: // cant' find it return(BLANK); } }