Emacs X12 Mode

Brief history

In 1978, The American National Standards Institute (ANSI) chartered a Accredited Standard Committee (ASC) X12. This committee’s objective was “…to develop uniform standards for inter-industry electronic interchange of business transactions”.

The result was an example of the “design by committee” – a set of EDI (electronic data interchange) standards now known as X12 – more than 300 specifications published so far. The next most exciting bureaucratic organization in the world, naturally, could not stay away for long and in 1986, the United Nations Economic Commission for Europe (UN/ECE) adopted UN/EDIFACT (United Nations Electronic Data Interchange for Administration, Commerce and Transport), which is roughly the same thing as ANSI’s X12.

Both standards should be long dead by now, but X12 has made its way into government regulations and, therefore, is mandated for use in government-regulated industries. The United States’ health care is one of these. The http://www.x12.org contains a broader and prouder overview of the whole thing.

Why X12-mode

The raw X12 message looks like this:

ISA*03*ABRA      *01*PASSWORD  *ZZ*ABRACADABRA    *ZZ*SECRET         *040115
*1144*U*00401*000003421*0*T*:~GS*HB*RGP4530*FJRIDNKLEKSJDFL*20040115*114427*
473829384*004010X059~ST*278*1000~BHT*0083*49*WYCKJHSLXBWF*20030529*1653*18~H
L*1**20*1~NM1*X3*2*TEST*****PI*PYRCD**~HL*2*1*21*1~NM1*1P*1*Provider*Request
ing*B***46*taxID2**~REF*ZH*P2**~PRV*PC*ZZ*SPECIALITY1**SC1*~HL*3*2*22*1~HI*B
F:9993*BF:9998*BF:0132*********~NM1*IL*1*LastName*FirstName*M*Mr.*II*MI*MEM
ID-01**~REF*EJ*PAT ACCT NUM~DMG*D8*19650113*M******~HL*4*3*PA*1~NM1*DN*1*Pro
vider*Referring*T*Dr.**46*REF TAX ID**~REF*ZH*163459281**~N3*Referring Provi
der Address*Suite 100~N4*Chicago*IL*60606***~PRV*AT*ZZ*REFERRING SPECIALTY**
SC2*~HL*5*4*19*1~NM1*SJ*1*Provider*Service*T*Dr.**46*SERV TAX ID*~REF*ZH*163
459281**~N3*Service Provider Address*Suite 200~N4*Chicago*IL*60606***~PRV*PE
*ZZ*SERVICE SPECIALTY**SC3*~HL*6*5*SS*0~TRN*2*TRACE NUM*ORIG CMPNY*~UM*SC*I*
1*11:B*****r*~HCR*A1*REFERRAL NUMBER**~REF*BB*PREV CERT NUM**~DTP*472*RD8*20
030101-20030630~DTP*102*D8*20030101~DTP*036*D8*20030630~DTP*007*D8*20030101~
DTP*881*D8*20030202~HSD*VS*3******~SE*37*1000~GE*1*001127092~IEA*1*001123616
~

In case you are wondering – it is a Health Care Services Review Response, ASC X12N 278 (004010X059). Theoretically, human beings are not supposed to see any of this, but practically most of the people working in EDI in general and health care IT specifically have to make sense of and/or edit this gooblegook directly.

We at APP Design, Inc. suffered long enough to think of a solution. Feeling sympathetic to our brethren in the EDI industry we decided to provide our solution – the X12 editing mode – free of charge, as a service to the suffering EDI community – to ease the pain somewhat. The mode requires the use of a GNU Emacs editor, which is distributed by the Free Software Foundation, again – free of charge. The mode is provided under the terms of GNU General Public License (also known as GPL) and WITHOUT ANY WARRANTY, without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

Under this editing mode, the above example looks either like this (in its original, but colorized mode):

ISA*03*ABRA_____*01*PASSWORD__*ZZ*ABRACADABRA____*ZZ*SECRET_________*040115
*1144*U*00401*000003421*0*T*:~GS*HB*RGP4530*FJRIDNKLEKSJDFL*20040115*114427*
473829384*004010X059~ST*278*1000~BHT*0083*49*WYCKJHSLXBWF*20030529*1653*18~H
L*1**20*1~NM1*X3*2*TEST*****PI*PYRCD**~HL*2*1*21*1~NM1*1P*1*Provider*Request
ing*B***46*taxID2**~REF*ZH*P2**~PRV*PC*ZZ*SPECIALITY1**SC1*~HL*3*2*22*1~HI*B
F:9993*BF:9998*BF:0132*********~NM1*IL*1*LastName*FirstName*M*Mr.*II*MI*MEM 
ID-01**~REF*EJ*PAT_ACCT_NUM~DMG*D8*19650113*M******~HL*4*3*PA*1~NM1*DN*1*Pro
vider*Referring*T*Dr.**46*REF_TAX_ID**~REF*ZH*163459281**~N3*Referring_Provi
der Address*Suite 100~N4*Chicago*IL*60606***~PRV*AT*ZZ*REFERRING_SPECIALTY**
SC2*~HL*5*4*19*1~NM1*SJ*1*Provider*Service*T*Dr.**46*SERV_TAX_ID*~REF*ZH*163
459281**~N3*Service_Provider_Address*Suite_200~N4*Chicago*IL*60606***~PRV*PE
*ZZ*SERVICE_SPECIALTY**SC3*~HL*6*5*SS*0~TRN*2*TRACE_NUM*ORIG_CMPNY*~UM*SC*I*
1*11:B*****r*~HCR*A1*REFERRAL_NUMBER**~REF*BB*PREV_CERT_NUM**~DTP*472*RD8*20
030101-20030630~DTP*102*D8*20030101~DTP*036*D8*20030630~DTP*007*D8*20030101~
DTP*881*D8*20030202~HSD*VS*3******~SE*37*1000~GE*1*001127092~IEA*1*001123616
~

or this (split by segments):

ISA*03*ABRA_____*01*PASSWORD__*ZZ*ABRACADABRA____*ZZ*SECRET_________
*040115*1144*U*00401*000003421*0*T*:~
GS*HB*RGP4530*FJRIDNKLEKSJDFL*20040115*114427*473829384*004010X059~
ST*278*1000~
BHT*0083*49*WYCKJHSLXBWF*20030529*1653*18~
HL*1**20*1~NM1*X3*2*TEST*****PI*PYRCD**~
HL*2*1*21*1~NM1*1P*1*Provider*Requesting*B***46*taxID2**~
REF*ZH*P2**~
PRV*PC*ZZ*SPECIALITY1**SC1*~
HL*3*2*22*1~HI*BF:9993*BF:9998*BF:0132*********~
NM1*IL*1*LastName*FirstName*M*Mr.*II*MI*MEM_ID-01**~
REF*EJ*PAT_ACCT_NUM~
DMG*D8*19650113*M******~
HL*4*3*PA*1~
NM1*DN*1*Provider*Referring*T*Dr.**46*REF_TAX_ID**~
REF*ZH*163459281**~
N3*Referring_Provider Address*Suite 100~
N4*Chicago*IL*60606***~
PRV*AT*ZZ*REFERRING_SPECIALTY**SC2*~
HL*5*4*19*1~
NM1*SJ*1*Provider*Service*T*Dr.**46*SERV_TAX_ID*~
REF*ZH*163459281**~
N3*Service_Provider_Address*Suite_200~
N4*Chicago*IL*60606***~
PRV*PE*ZZ*SERVICE_SPECIALTY**SC3*~
HL*6*5*SS*0~
TRN*2*TRACE_NUM*ORIG_CMPNY*~
UM*SC*I*1*11:B*****r*~
HCR*A1*REFERRAL_NUMBER**~
REF*BB*PREV_CERT_NUM**~DTP*472*RD8*20030101-20030630~
DTP*102*D8*20030101~
DTP*036*D8*20030630~DTP*007*D8*20030101~
DTP*881*D8*20030202~
HSD*VS*3******~
SE*37*1000~
GE*1*001127092~
IEA*1*001123616~

What does x12-mode do

Either view is easier to navigate – visually, emotionally, or by keystrokes. To summarize, the mode will provide the following functionality for you:

  1. Colorize segment names and delimiters.
  2. Define navigation by fields (called “data elements” in X12 argot).
  3. Define navigation by segments.
  4. Split an X12 message to be presented as one segment per line (or “break” it) – it is easier to read this way.
  5. Combine segments together into one big string (or, “glue” it) – it is usually the way the messages are transmitted.
  6. Visualize blank space in the message. It’s particurlaly useful for the fixed length fields and for spotting un-printable characters that got into the message accidentally.

The following operations are defined in the x12-mode:

Operation Mapping Usually bound to Comment
x12-field-forward forward-sexp ESC C-f Other commands on ‘sexp’ will work too: ‘kill-sexp’, ‘mark-sexp’,
‘backward-kill-sexp’, etc.
x12-field-backward backward-sexp ESC C-b
forward-segment forward-sentence ESC e Other sentence-oriented commands will also work.
backward-segment backward-sentence ESC a
x12-glue No native Emacs equivalent Custom bound to ESC C-x g
x12-break Custom bound to ESC C-x b

Delimiters for the X12 message can be customized in the mode’s own customization group Emacs/Data/x12.

Installation

Installation is easy: you need to download and install the file x12-mode.el (or its compiled version x12-mode.elc) anywhere on the load-path. To find out
what the path is use the following command:

M-: (print load-path)

Typically, it is something like this in the Windows system:

(
"c:/util/emacs-21.2/site-lisp" "C:/util/emacs-21.2/../site-lisp"
"C:/util/emacs-21.2/lisp" "c:/util/emacs-21.2/lisp/toolbar"
...
"C:/util/emacs-21.2/leim" "~/lisp"
)

The last place – your home “lisp” directory will be the most appropriate. The usual code in your .emacs file will make the mode automatic for all *.x12 files:

(require 'x12-mode)
   (setq auto-mode-alist (cons '("\\.[xX]12\\'" . x12-mode) auto-mode-alist))

 

Download and Participate

The whole project is hosted at the Source Forge: http://sourceforge.net/projects/x12-mode/, you can download the x12-mode from there. You are also invited to participate in further development, the site contains the most current to-do list.

Your financial support of the SourceForge.net organization will be greatly appreciated.

You can also request volunteers’ support, log feature requests, and, if anything else fails, submit a bug report.