我正在用 C# 编写一个程序,它将解析 HL7 消息并将数据写入文本文件。HL7 还包含一个 base64 格式的嵌入式 PDF。我也必须解码base64编码的pdf。
string fileLocation = @"hl7file.hl7";
var message = File.ReadAllText(fileLocation);
PipeParser parser = new PipeParser();
IMessage m = parser.Parse(message);//str message will contain your HL7 Message
ADT_A03 adtA02 = m as ADT_A03;
ORU_R01 oru = m as ORU_R01;
ORU_R01_PATIENT patient = oru.GetPATIENT_RESULT().PATIENT;
ORU_R01_ORDER_OBSERVATION orderObservation = oru.GetPATIENT_RESULT().GetORDER_OBSERVATION();
OBR obr = orderObservation.OBR;
PID pid = patient.PID;
string PatientId = pid.GetPatientIdentifierList(0).IDNumber.ToString();
ORU_R01_OBSERVATION observation = orderObservation.GetOBSERVATION(0);
OBX obx = observation.OBX;
var pdfFile = obx.GetObservationValue(0).data;
Dictionary<string, string> hl7Data = new Dictionary<string, string>();
hl7Data.Add("Patient ID", PatientId = pid.GetPatientIdentifierList(0).IDNumber.ToString());
hl7Data.Add("Last_Name", pid.GetPatientName(0).FamilyName.Surname.Value);
hl7Data.Add("First_Name", pid.GetPatientName(0).GivenName.Value);
hl7Data.Add("DOB", pid.DateTimeOfBirth.Time.ToString());
hl7Data.Add("Sex", pid.AdministrativeSex.Value);
hl7Data.Add("Address", pid.GetPatientAddress(0).StreetAddress.StreetOrMailingAddress.Value);
hl7Data.Add("City", pid.GetPatientAddress(0).City.Value);
hl7Data.Add("State", pid.GetPatientAddress(0).StateOrProvince.Value);
hl7Data.Add("Zip_Code", pid.GetPatientAddress(0).ZipOrPostalCode.Value);
hl7Data.Add("Signature_Required", obr.PriorityOBR.Value);
hl7Data.Add("Referring_Physician_Last_Name", obr.GetOrderingProvider(0).FamilyName.Surname.Value);
hl7Data.Add("Referring_Physician_First_Name", obr.GetOrderingProvider(0).GivenName.Value);
hl7Data.Add("NPI", obr.GetOrderingProvider(0).IdentifierTypeCode.Value);
hl7Data.Add("Observation_Date", obr.ObservationDateTime.Time.ToString());
hl7Data.Add("File_Type", obr.UniversalServiceIdentifier.Identifier.Value);
hl7Data.Add("File_Description", obr.UniversalServiceIdentifier.Text.Value);
using (StreamWriter file = new StreamWriter(@"C:\Users\samin.khan\Desktop\myfile.txt"))
{
foreach (var entry in hl7Data)
{
file.WriteLine("{0}: {1}", entry.Key, entry.Value);
}
}
因此 var pdfFile = obx.GetObservationValue(0).data 行以 base64 格式显示 PDF,但我无法访问数据。我可以清楚地看到 pdffile 对象内的 pdf 值,但无法访问它。请检查图片附件。
如何访问 PDF 数据?
使用:
using NHapi.Base.Parser;
using NHapi.Model.V25.Datatype;
using NHapi.Model.V25.Message;
using NHapi.Model.V25.Group;
using NHapi.Model.V25.Segment;
using NHapi.Base.Model;