Rails POST request to Practice Fusion API

本文关键字:Fusion API Practice to POST request Rails | 更新日期: 2023-09-27 18:05:04

我正在使用Practice Fusion API来接收待处理的订单。我正试图编写一个POST请求,以确认在GET请求期间收到的下载订单。一旦Practice Fusion收到POST请求,挂起的订单将被删除。

我正在使用的宝石:

rest客户端

simple_hl7——用于hl7解析

这是我的工作GET请求:

def download_pf_orders
  download_count = 0
  uri = "#{PF_TEST_PENDING_API_URL}"
  rest_resource = RestClient::Resource.new(uri, PF_TEST_USERNAME, PF_TEST_PASSWORD)
  begin
    response = rest_resource.get(accept: 'application/json')
    json = JSON.parse(response)
    json.each do |data|
      sequence = data['SequenceNumber']
      puts "### Last Sequence Number: #{sequence}"
      PfOrder.create(
        sequence_number: data['SequenceNumber'],
        message_guid: data['MessageGuid'],
        hl7_document: data['Hl7Document']
        )
      download_count += 1
    end
  rescue => e
    puts "### Status Code: #{e.response.code} ###"
  end
  puts "### Downloaded Orders: #{download_count} ###"
end

以下是Practice Fusion概述的POST请求标准:

HL7 ACK消息示例

给定一个检索到的订单消息,其中包含以下MSH段:

要看更多有关憩苑

| ^ ~ ', | PracticeFusion | ClientID | | | 20130930225002 + 0000 | | OML ^ O21 ^ OML_O21 | a783a5 d7-c9b2-42e9-abb1-a1b473079512 P | | 2.5.1 | | | AL | NE | | | | | ELINCS_MT-OML-1_1.0

期望的HL7 ACK消息将包含以下MSH和MSA段:

要看更多有关憩苑

| ^ ~ ', | PracticeFusion | VendorCode | | ClientID | 20130930225002 + 0000 | | ACK ^ ELINCS ^P ACK_ELINCS | MessageControlID | | 2.5.1 ||||||||| ELINCS_MT-ACK-1_1.0

MSA | CA | a783a5d7-c9b2-42e9-abb1-a1b473079512

***正如上面示例订单和确认消息中的颜色协调所示,您的ACK逻辑应该填充MSH-6使用的MSH-4 Client ID值确认的Client ID关联的订单,以及使用控件ID的sa -2值MSH-10的订单信息。

***在确认消息的MSH-4中填充的"供应商代码"值是由Practice Fusion分配的唯一值。请联系此值的实现资源(如果以前没有)被提供。

下面是一些提供的c#示例代码来完成此操作:

/// <summary>
/// Post an HL7 Order Acknowledgement message back to PracticeFusion to signal
acceptance...
/// </summary>
static void AcknowledgeOrder(string hl7AckMessage)
{
  var request = (HttpWebRequest)
  WebRequest.Create(ConfigurationManager.AppSettings["OrderAcknowledgementUri"]);
  request.PreAuthenticate = true;
  request.Credentials = new
  NetworkCredential(ConfigurationManager.AppSettings["PF.ApiUserName"],
   ConfigurationManager.AppSettings["PF.ApiPassword"]);
  request.Method = WebRequestMethods.Http.Post;
  request.ContentType = "application/x-www-form-urlencoded";
  using (var writer = new StreamWriter(request.GetRequestStream()))
  {
   writer.Write(hl7AckMessage);
 }
}

Rails POST request to Practice Fusion API

我明白了。此方法将成功POST回,但仍然需要考虑订单是否已成功发布。

def acknowledge_pf_order
  hl7_message = PfOrder.all
  hl7_message.each do |msg|
    clean_msg = msg.hl7_document.gsub(/'r/, '')
    msh_segment = clean_msg.gsub(MSH)
    msh_segment.each do |seg|
      parsed_msh = SimpleHL7::Message.parse(seg)
      parsed_msh.msh[4] = 'yourVendorCode'
      parsed_msh.msh[6] = 'yourClientID'
      parsed_msh.msh[9][1] = 'ACK'
      parsed_msh.msh[9][2] = 'ELINCS'
      parsed_msh.msh[9][3] = 'ACK_ELINCS'
      parsed_msh.msh[21] = 'ELINCS_MT-ACK-1_1.0'
      message_id = parsed_msh.msh[10]
      ack_message = parsed_msh.to_hl7
      msa_segment = "'nMSA|CA|#{message_id.to_s}"
      payload = ack_message << msa_segment
      uri = "#{PF_TEST_ACK_API_URL}"
      rest_resource = RestClient::Resource.new(uri, PF_TEST_USERNAME, PF_TEST_PASSWORD)
      begin
        response = rest_resource.post payload, content_type: 'text/plain'
        puts "### POST Status Code: #{response.code} ###"
      rescue Exception => e
        puts "### POST Status Code: #{e.response.code} ###"
      end
    end
  end
end