Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
kardianos opened this issue Feb 27, 2017 · 1 comment
Open

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

kardianos opened this issue Feb 27, 2017 · 1 comment

Comments

@kardianos
Copy link

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
Copy link
Owner

kdar commented Feb 27, 2017

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants