kdar / health

A library for marshaling and unmarshaling various EDI formats (NCPDP, EDIFACT, ...) and CCDs in Go.
MIT License
67 stars 20 forks source link

hl7x/gen: source of 2.3 not from gen? #11

Open kardianos opened 7 years ago

kardianos commented 7 years ago

Are the files in hl7x/2.3 folder hand generated? It looks like they are machine generated, but the "gen" program isn't complete enough to generate them.

Clarification as to the hl7x/2.3 package would be appreciated.

kdar commented 7 years ago

Sorry about that! I didn't have time to actually finish creating the generator (because of a deadline). You are correct in that the files are generated (sort of), but I did it in a very hacky way.

I used the code from this ruby repository: https://github.com/niquola/health_seven and the script below:

#!/bin/bash

input=$(cat; echo x)
input=${input%x}

printf %s "$input" |perl -p -e 's/module\sHealthSeven::V(.*?)/package hl7v$1/' | \
  perl -p -e 's/class\s(.*?)\s.*/type $1 struct {/' | \
  perl -0777 -pe 's/end.*\nend.*/}/m' | \
  perl -pe 's/Array\[(.*?)\]/[]$1/g' | \
  perl -pe 's/, / /g' | \
  perl -pe 's/#/\/\//g' | \
  perl -pe 's/position:(.*)/`position:$1`/g' | \
  perl -pe 's/: /:/g' | \
  perl -pe 's/:true/:"true"/g' | \
  perl -pe 's/ multiple:".*?"//g' | \
  perl -pe 's/attribute :([^\s]+)/$1/' | \
  perl -pe 's/^  ([a-zA-Z])/  \U$1/' | \
  perl -pe 's/_([a-z])/\U$1/g'

So for example, running https://github.com/niquola/health_seven/blob/master/lib/health_seven/2.3/datatypes/ce.rb through convert.sh generates this:

package hl7v2_3
type Ce struct {
  // identifier
  Identifier Id `position:"CE.1"`
  // text
  Text St `position:"CE.2"`
  // name of coding system
  NameOfCodingSystem St `position:"CE.3"`
  // alternate identifier
  AlternateIdentifier Id `position:"CE.4"`
  // alternate text
  AlternateText St `position:"CE.5"`
  // name of alternate coding system
  NameOfAlternateCodingSystem St `position:"CE.6"`
}

I then cleaned up whatever was wrong and the types manually (although I could have done type conversions in the script). So you can see why I didn't make this public... heh