从HL7中提取PDF

时间:2017-10-25 20:26:45

标签: c# pdf hl7 nhapi

我正在用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;

图片:Can't access Data item in object

将其作为ED(封装数据)对象投射后:After casting it as ED object

2 个答案:

答案 0 :(得分:2)

只需关闭原始屏幕截图,您就可以执行以下操作:

CREATE OR REPLACE PROCEDURE amp_CheckVideos
(
  v_json IN NVARCHAR2 DEFAULT NULL ,
  v_Ids IN TVP_AMP_METADATA,
  v_tags IN TVP_AMP_METADATA,
  v_newVideos IN TVP_AMP_VIDEOS
) is 
begin

答案 1 :(得分:2)

        ED embeddedPDF = (ED)obx.GetObservationValue(0).Data;

        if (embeddedPDF != null)
        {
           var bytes = Convert.FromBase64String(embeddedPDF.Data.Value);
           File.WriteAllBytes("SomeFileName.pdf", bytes);
        }

非常感谢大家。