1 | #!/usr/bin/perl -w
|
---|
2 | #this program converts a csv file of patient data to wikitext format
|
---|
3 | #
|
---|
4 | #this software is copyright George Lilly 2010 and is available as GPL
|
---|
5 | #its home is https://trac.opensourcevista.net/browser/hData/trunk/test-patients
|
---|
6 | #
|
---|
7 | #purpose: convert csv file to wikitext
|
---|
8 | #Second part of a chain of conversions which will create
|
---|
9 | #hData versions of the test patients. Also generate wiki-formatted versions
|
---|
10 | #to put on VistAPedia.
|
---|
11 | #
|
---|
12 | my($intbl) = "none";
|
---|
13 | sub endtbl {
|
---|
14 | print "\|\}\n";
|
---|
15 | }
|
---|
16 | sub dotr {
|
---|
17 | print "\|----\n";
|
---|
18 | }
|
---|
19 | sub doetr {
|
---|
20 | print "\|----\n";
|
---|
21 | }
|
---|
22 | sub spancol {
|
---|
23 | my $tit = shift ;
|
---|
24 | my $cols = shift;
|
---|
25 | print "\{\| border=\"1\"\|\n";
|
---|
26 | print "\!colspan=\"$cols\"\|$tit\n";
|
---|
27 | }
|
---|
28 | sub docol {
|
---|
29 | my $tit = shift ;
|
---|
30 | print "\!scope\=\"col\"\|$tit\n";
|
---|
31 | }
|
---|
32 | sub dorow {
|
---|
33 | my $tit = shift ;
|
---|
34 | print "\|$tit\n";
|
---|
35 | }
|
---|
36 |
|
---|
37 |
|
---|
38 | while(<STDIN>)
|
---|
39 | {
|
---|
40 | my($line) = $_;
|
---|
41 | chomp($line);
|
---|
42 | $line =~ s/ $//g;
|
---|
43 | if (($line =~ m/^Patient/)&&($line !~ m/Summary/)) {
|
---|
44 | if ($intbl !~ "none") { endtbl; }
|
---|
45 | spancol("Patient",6);
|
---|
46 | # print "$line\n";
|
---|
47 | $intbl = "Patient";
|
---|
48 | }
|
---|
49 | elsif (($intbl =~ "Patient")&&($line =~ m/^Name/)) {
|
---|
50 | dotr;
|
---|
51 | $_ = $line;
|
---|
52 | push @cols, split(/\|/);
|
---|
53 | docol($_) for @cols ;
|
---|
54 | doetr;
|
---|
55 | @cols = ();
|
---|
56 | }
|
---|
57 | elsif ($line =~ m/^Problem List/) {
|
---|
58 | if ($intbl !~ "none") { endtbl; }
|
---|
59 | spancol("Problem List",6);
|
---|
60 | # print "$line\n";
|
---|
61 | $intbl = "Problem List";
|
---|
62 | }
|
---|
63 | elsif (($intbl =~ "Problem List")&&($line =~ m/^Type/)) {
|
---|
64 | dotr;
|
---|
65 | $_ = $line;
|
---|
66 | push @cols, split(/\|/);
|
---|
67 | docol($_) for @cols ;
|
---|
68 | doetr;
|
---|
69 | @cols = ();
|
---|
70 | }
|
---|
71 | elsif ($line =~ m/^Medication List/) {
|
---|
72 | if ($intbl !~ "none") { endtbl; }
|
---|
73 | spancol("Medication List",10);
|
---|
74 | # print "$line\n";
|
---|
75 | $intbl = "Medication List";
|
---|
76 | }
|
---|
77 | elsif (($intbl =~ "Medication List")&&($line =~ m/^RxNorm/)) {
|
---|
78 | dotr;
|
---|
79 | $_ = $line;
|
---|
80 | push @cols, split(/\|/);
|
---|
81 | docol($_) for @cols ;
|
---|
82 | doetr;
|
---|
83 | @cols = ();
|
---|
84 | }
|
---|
85 | elsif ($line =~ m/^Medication Allergy List/) {
|
---|
86 | if ($intbl !~ "none") { endtbl; }
|
---|
87 | spancol("Medication Allergy List",5);
|
---|
88 | # print "$line\n";
|
---|
89 | $intbl = "Medication Allergy List";
|
---|
90 | }
|
---|
91 | elsif (($intbl =~ "Medication Allergy List")&&($line =~ m/^Type/)) {
|
---|
92 | dotr;
|
---|
93 | $_ = $line;
|
---|
94 | push @cols, split(/\|/);
|
---|
95 | docol($_) for @cols ;
|
---|
96 | doetr;
|
---|
97 | @cols = ();
|
---|
98 | }
|
---|
99 | elsif ($line =~ m/^Diagnostic Test Results/) {
|
---|
100 | if ($intbl !~ "none") { endtbl; }
|
---|
101 | spancol("Diagnostic Test Results",5);
|
---|
102 | # print "$line\n";
|
---|
103 | $intbl = "Diagnostic Test Results";
|
---|
104 | }
|
---|
105 | elsif (($intbl =~ "Diagnostic Test Results")&&($line =~ m/^Type/)) {
|
---|
106 | dotr;
|
---|
107 | $_ = $line;
|
---|
108 | push @cols, split(/\|/);
|
---|
109 | docol($_) for @cols ;
|
---|
110 | doetr;
|
---|
111 | @cols = ();
|
---|
112 | }
|
---|
113 | elsif ($line =~ m/^Procedure List/) {
|
---|
114 | if ($intbl !~ "none") { endtbl; }
|
---|
115 | spancol("Procedure List",5);
|
---|
116 | # print "$line\n";
|
---|
117 | $intbl = "Procedure List";
|
---|
118 | }
|
---|
119 | elsif (($intbl =~ "Procedure List")&&($line =~ m/^Type/)) {
|
---|
120 | dotr;
|
---|
121 | $_ = $line;
|
---|
122 | push @cols, split(/\|/);
|
---|
123 | docol($_) for @cols ;
|
---|
124 | doetr;
|
---|
125 | @cols = ();
|
---|
126 | }
|
---|
127 | elsif (($intbl !~ "none")&&($line =~ m/\|/)) {
|
---|
128 | $_ = $line;
|
---|
129 | push @rows, split(/\|/);
|
---|
130 | dorow($_) for @rows ;
|
---|
131 | doetr;
|
---|
132 | @rows = ();
|
---|
133 | }
|
---|
134 | else {
|
---|
135 | if ($intbl !~ "none") { endtbl; }
|
---|
136 | print "$line\n";
|
---|
137 | $intbl = "none";
|
---|
138 | }
|
---|
139 | }
|
---|