internal static BaseSegment CreateResponseMshSegment(this Message message, string messageType = MessageHelper.ACK) { List <string?> newValues = new List <string?>() //SegmentHelper.MSH, message.GetDelimiters()--these first two fields are handled in parse fields below { message.GetReceivingApplication(), message.GetReceivingFacility(), message.GetSendingApplication(), message.GetSendingFacility(), //flip applications and facilities message.GetMessageDateTime()?.FormatDate(message.Encoding), string.Empty /*security*/, messageType, message.GetMessageControlId(), message.GetProcessingId(), message.GetVersionId(), string.Empty /*sequence number*/, string.Empty /*continuation pointer*/, string.Empty /*acceptacktype*/, string.Empty /*appacktype*/, message.GetCountryCode(), message.GetCharacterSet(), message.GetPrincipalLanguage() }; return(SegmentHelper.CreateSegment(message.Encoding, SegmentHelper.MSH, FieldHelper.ParseFields(newValues, message.Encoding, true, false, false))); }
/// <summary> /// Builds an ACK or NACK message for this message /// </summary> /// <param name="code">ack code like AA, AR, AE</param> /// <param name="errMsg">error message to be sent with NACK -- infers that this is a NACK</param> /// <returns>An ACK or NACK message if success, otherwise null</returns> private static Result <Message> CreateAckorNackMessage(this Message message, string?code = null, string?nackErrorMessage = null) { BaseSegment msh = MshMessageHelper.CreateResponseMshSegment(message); string responseCode = code ?? (string.IsNullOrWhiteSpace(nackErrorMessage) ? (message.GetAcceptAckType() ?? AA) : AE);//is acceptacktype a good default? List <BaseField> fields = FieldHelper.ParseFields(new string?[] { responseCode, message.GetMessageControlId() ?? string.Empty, nackErrorMessage }, message.Encoding, false, false); BaseSegment msa = SegmentHelper.CreateSegment(message.Encoding, MessageHelper.MSA, fields); return(CreateMessageFromSegmentCollections(new List <SegmentCollection> { new SegmentCollection(msh.Name, 1, new List <BaseSegment> { msh }), new SegmentCollection(msa.Name, 2, new List <BaseSegment> { msa }) })); }