【发布时间】:2018-04-07 01:53:12
【问题描述】:
我正在用 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;
【问题讨论】:
-
你是从base64解码的吗?
-
还没有,因为我无法访问 obx.GetObservationValue(0).Data。当我设置断点但无法分配 base64 值 string/var 时,我可以看到它。使用 var,obx.GetObservationValue(0).Data 显示为一个对象。
-
您的意思是尝试解码变量 pdfFile 时出错?
-
查看任何对象的属性,它看起来就像是您拥有的基础对象。指定了
TypeName属性,您可能需要将其强制转换为该类型才能为您提供所需的属性。ED在我看来可能意味着电子文档。检查是否有一个ED可以转换到的类。假设您没有将Data视为可访问属性。 -
我没有收到任何错误。当它到达断点时,我看到了附加的图像(鼠标悬停在 pdffile 上)。我需要将 Data = "JVBERi0xLjYKJdP0zOEKMSAwIG9iago8PAovQ3JlYXRvcihUZWxlcmlrI..." 保存到字符串中。