簡體   English   中英

從HL7提取PDF

[英]Extract PDF from HL7

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

圖片: 無法訪問對象中的數據項

將其強制轉換為ED(封裝數據)對象后: 將其投射為ED對象后

只需關閉原始屏幕截圖,您就可以執行以下操作:

var ed = axc.Data as ED;
if (ed != null)
{
    var bytes = Convert.FromBase64String(ed.Data);
    File.WriteAllBytes("SomeFileName.pdf", bytes);
}
        ED embeddedPDF = (ED)obx.GetObservationValue(0).Data;

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

非常感謝大家。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM