Giter Club home page Giter Club logo

dzero's Introduction

DZero

DZero is a robust and easy-to-use NCPDP Telecommunications Standard Version D.0 Message parser and serializer.

🍊Battle Tested at Instacart

Installation

Add this to your gemfile:

gem 'dzero'

And then run bundle install.

Features

  • βœ… Complete field mapping for all 26 D.0 Segment types.
    • This means you can access field values by a simple name instead of it's 2-character identifier. (ex: claim_segment[:fill_number] instead of claim_segment['D3'])
  • βœ… Parse D.0 Requests or Responses with ease.
    • ex: DZero::Transmissions::Request.parse(your_raw_string)
  • βœ… Build D.0 Requests or Responses with ease.
    • ex: DZero::Transmissions::Request.new(...) (see Building below)
  • βœ… Supports multiple transaction groups
    • ex: request.transaction_groups[2].claim_segment
  • βœ… Serialize a D.0 message to JSON
    • ex: request.to_json

Usage

Parsing and Manipulating

Parsing

require 'dzero'

request = DZero::Transmissions::Request.parse(raw_message_string)

The above snippet will return a new instance of DZero::Transmissions::Request.

Reading the header

pp request.header
# =>
# {:bin_number=>"999999",
#  :version=>"D0",
#  :transaction_code=>"B1",
#  :processor_control_number=>"",
#  :transaction_count=>"1",
#  :service_provider_id_qualifier=>"01",
#  :service_provider_id=>"1111111111",
#  :date_of_service=>"20181106",
#  :software=>""}

Reading a single segment

request.transmission_group.patient_segment
# => #<DZero::Segments::Patient>

request.transmission_group.insurance_segment
# => #<DZero::Segments::Insurance>

request.transaction_groups.first.claim_segment
# => #<DZero::Segments::Claim>

request.transaction_groups[2].claim_segment
# => #<DZero::Segments::Claim>

Reading a field in a segment

Fields of a segment can be accessed via the [] method, which takes either a symbol or a string.

segment = request.transaction_groups.first.claim_segment
# => #<DZero::Segments::Claim>
segment[:segment_identification]
# => "07"
segment["AM"]
# => "07"
segment[:quantity_dispensed]
# => "2000"
segment["E7"]
# => "2000"

Modifying a field in a segment

Fields of a segment can be accessed via the [] method, which takes either a symbol or a string. If a segment or field does not yet exist when it is attempted to be accessed, it will be created and added to the message.

segment = request.transaction_groups.first.claim_segment
segment[:quantity_dispensed]
# => "2000"
segment[:quantity_dispensed] = "9990"
# => "9990"
segment["E7"]
# => "9990"
segment["E7"] = "5555"
# => "5555"
segment[:quantity_dispensed]
# => "5555"

Serializing to json

Request, Response, TransmissionGroup, TransactionGroup, and Segment all have to_json methods.

request.to_json

to_json takes two options:

  • :readable - if this is true, symbols will be used for the fields of a segment, instead of the field identifiers.
  • :key_group_by_segment_sym - if this is true, groups will be objects instead of arrays of objects. A group object will be keyed by the segment identifiers it contains.

Building

For messages with a single transaction group, you can pass segments in with the segments argument. DZero will automatically filter the segments into the correct locations (either the transmission_group or the first transaction_group)

require 'dzero'

request = DZero::Transmissions::Request.new({
  header: {
    :bin_number=>"999999",
    :version=>"D0",
    :transaction_code=>"B1",
    :processor_control_number=>"",
    :transaction_count=>"1",
    :service_provider_id_qualifier=>"01",
    :service_provider_id=>"1111111111",
    :date_of_service=>"20181106",
    :software=>""
  },
  segments: [
    DZero::Segments::Patient.build({
      patient_first_name: 'AUSTIN',
      patient_last_name: 'PIVARNIK',
      patient_phone_number: '5555555555',
    })
  ]
})

For more control over the structure of the message, you can manually construct the transmission_group and the transaction_group.

require 'dzero'

response = DZero::Transmissions::Response.new(
  header: {
    :bin_number=>"999999",
    :version=>"D0",
    :transaction_code=>"B1",
    :processor_control_number=>"",
    :transaction_count=>"1",
    :service_provider_id_qualifier=>"01",
    :service_provider_id=>"1111111111",
    :date_of_service=>"20181106",
    :software=>""
  },
  transmission_group: DZero::Transmissions::Groups::TransmissionGroup.new(
    segments: [
      DZero::Segments::ResponseMessage.build({
        message: "TEST MESSAGE"
      })
    ]
  ),
  transaction_groups: [
    DZero::Transmissions::Groups::TransactionGroup.new(
      segments: [
        DZero::Segments::ResponseStatus.build({
          response_status: "C"
        })
      ]
    ),
    DZero::Transmissions::Groups::TransactionGroup.new(
      segments: [
        DZero::Segments::ResponseStatus.build({
          response_status: "R"
        })
      ]
    )
  ]
)

Stringifying a message

To render an instance of Request or Response into a D.0 string, simply call #to_s on the instance.

request.to_s
# => "999999D0B1          1011111111111     20181106          \u001E\u001CAM01\u001CCAAUSTIN\u001CCBPIVARNIK\u001CCQ5555555555"

Serializing a message to JSON

request.to_json(readable: true, key_group_by_segment_sym: true)
# => {
#   "header": {
#     "bin_number": "999999",
#     "version": "D0",
#     "transaction_code": "B1",
#     "processor_control_number": "",
#     "transaction_count": "1",
#     "service_provider_id_qualifier": "01",
#     "service_provider_id": "9999999999",
#     "date_of_service": "11282018",
#     "software": ""
#   },
#   "transmission_group": {
#     "patient": {
#       "segment_identification": "01",
#       "patient_first_name": "AUSTIN",
#       "patient_last_name": "PIVARNIK",
#       "patient_street_address": "50 BEALE ST",
#       "patient_city": "SAN FRANCISCO",
#       "patient_state_or_province": "CA",
#       "patient_zip_postal_code": "94105",
#       "patient_phone_number": "5555555555"
#     }
#   },
#   "transaction_groups": [
#     {
#       "claim": {
#         "segment_identification": "07",
#         "prescription_reference_number_qualifier": "1",
#         "prescription_reference_number": "9999999999",
#         "product_service_id_qualifier": "03",
#         "product_service_id": "99999999999",
#         "quantity_dispensed": "2000",
#         "fill_number": "0",
#         "days_supply": "1",
#         "compound_code": "1",
#         "dispense_as_written_product_selection_code": "0",
#         "date_prescription_written": "20181025",
#         "number_of_refills_authorized": "99",
#         "prescription_origin_code": "1",
#         "unit_of_measure": "EA",
#         "level_of_service": "0",
#         "patient_assignment_indicator": "Y",
#         "pharmacy_service_type": "1"
#       },
#       "pricing": {
#         "segment_identification": "11",
#         "ingredient_cost_submitted": "A",
#         "dispensing_fee_submitted": "{",
#         "patient_paid_amount_submitted": "{",
#         "percentage_sales_tax_rate_submitted": "1750{",
#         "usual_and_customary_charge": "A",
#         "gross_amount_due": "A",
#         "basis_of_cost_determination": "01"
#       }
#     }
#   ]
# }

dzero's People

Contributors

apiv avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

dzero's Issues

Possible bug in segment_methods concern

First I want to thank you for taking the time to release this publicly. I have been using it to create test NCPDP D.0 messages.

I believe the code at the following line will always fail since the initializer of DZero::Transmissions::Groups::TransactionGroup does not expect a hash, but instead keyword args.

https://github.com/apiv/dzero/blob/master/lib/dzero/transmissions/concerns/segments_methods.rb#L61

If I change that line to the following it no longer fails

transaction_groups << ::DZero::Transmissions::Groups::TransactionGroup.new(segments: [])

To reproduce, I believe all you need to do is include any segment that is not Patient or Insurance in the transmission request segments(Pricing for example).

A similar error is in the README request construction example. The request initializer is expecting keyword args and not a hash.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.