private static ChoHL7Message CreateInstance(ChoHL7Configuration configuration) { ChoHL7MessageType mt = configuration.MessageType; ChoHL7Version version = configuration.Version; ChoHL7Message msg = null; string messageTypeName = "ChoETL.HL7.Model.{0}.{1}".FormatString(version.ToString(), mt.ToString()); if (!ChoHL7MessageCache.Instance.HL7MessageDict.ContainsKey(messageTypeName)) { throw new ChoHL7Exception("Can't find '{0}' HL7 Message type.".FormatString(messageTypeName)); } msg = CreateInstance(ChoHL7MessageCache.Instance.HL7MessageDict[messageTypeName]) as ChoHL7Message; msg.Version = version; msg.MessageType = mt; return(msg); }
internal void Validate(string line) { if (line.IsNullOrWhiteSpace()) { throw new ChoHL7Exception("Empty line found."); } if (!line.StartsWith("MSH")) { throw new ChoHL7Exception("Missing Message Header (MSH) record."); } if (line.Length <= 3 || line[3] == ChoCharEx.NUL) { throw new ChoHL7Exception("Missing or NULL Field Separator found."); } else { FieldSeparator = line[3]; } if (FieldSeparator.ToString().IsAlphaNumeric()) { throw new ChoHL7Exception("Invalid '{0}' field separator found.".FormatString(FieldSeparator)); } if (line.Length <= 8) { throw new ChoHL7Exception("Missing encoding characters."); } else { var encodingChars = line.Substring(4, 4); if (encodingChars != @"^~\&") { throw new ChoHL7Exception("Invalid encoding characters found."); } if (encodingChars.Where(c => c == ChoCharEx.NUL).Any()) { throw new ChoHL7Exception("NULL encoding characters found."); } } string[] fields = line.Split(FieldSeparator); if (fields.Length < 11 || fields[11].IsNullOrWhiteSpace()) { throw new ChoHL7Exception("Missing version."); } string versionTxt = fields[11]; var v = versionTxt.ToEnum(typeof(ChoHL7Version)); if (v == null) { throw new ChoHL7Exception("'{0}' version not supported.".FormatString(versionTxt)); } if (LoadWithVersion == null) { Version = (ChoHL7Version)v; ChoETLLog.Info("Version found in message: {0}".FormatString(Version)); } else { ChoETLLog.Info("Version found in message: {0}".FormatString((ChoHL7Version)v)); Version = LoadWithVersion.Value; ChoETLLog.Info("But loading message with version: {0}".FormatString(Version)); } if (fields[8].IsNullOrWhiteSpace()) { throw new ChoHL7Exception("Missing Message Type."); } string mtText = fields[8]; var mtEnumTxt = mtText.ToEnum(typeof(ChoHL7MessageType)); if (mtEnumTxt == null) { throw new ChoHL7Exception("'{0}' Message Type not supported.".FormatString(mtText)); } if (LoadWithMessageType == null) { MessageType = (ChoHL7MessageType)mtEnumTxt; ChoETLLog.Info("MessageType found in message: {0}".FormatString(MessageType)); } else { ChoETLLog.Info("MessageType found in message: {0}".FormatString((ChoHL7MessageType)mtEnumTxt)); MessageType = LoadWithMessageType.Value; ChoETLLog.Info("But loading message with MessageType: {0}".FormatString(MessageType)); } }