#!/bin/sh

# disable filename globbing

BASE=`pwd`
APPLDIR=$BASE/appl
DATADIR=$BASE/data
PATH=$PATH:$BASE/ihd/bin:.
export PATH APPLDIR DATADIR
isapr=./tmp/isapr
perso=./tmp/perso
profs=./tmp/profs
./appl/sh/isapr |
awk -F"^" ' function trail(txt) { while (substr(txt,length(txt),1)==" ") txt=substr(txt,1,length(txt)-1); return (txt) }
{
for (i=1;i<NF;i++) printf "%s^",trail($i)
print trail($i)
} ' - >$isapr
./appl/sh/perso |
awk -F"^" ' function trail(txt) { while (substr(txt,length(txt),1)==" ") txt=substr(txt,1,length(txt)-1); return (txt) }
{
for (i=1;i<NF;i++) printf "%s^",trail($i)
print trail($i)
} ' - >$perso
./appl/sh/profs |
awk -F"^" ' function trail(txt) { while (substr(txt,length(txt),1)==" ") txt=substr(txt,1,length(txt)-1); return (txt) }
{
for (i=1;i<NF;i++) printf "%s^",trail($i)
print trail($i)
} ' - >$profs

# |  1 H00 codigo 02 00   0 | 2 H01 identi 50 00   2 | 3 H02 insumo 02 50  52 |
# |  4 H03 medica 02 50  54 | 5 H04 copago 30 00  56 | 6 H05 texto  512 15  86 |

#  7 D00 profes  2   51 |  8 D01 modal   2   52 |  9 D02 frecue  2   01 | 
# 10 D03 observ  128 00 | 
{
awk -F"^" ' BEGIN { print "var sesio = new Array()\n" }
{
	print "sesio[\""$1$8$7"\"]=\""$9"\""
	x[$1]=1
} ' $isapr
awk -F"^" ' BEGIN { print "\nvar profs = new Array()\n" }
{
	printf "profs[\"%2.2s%s\"]=\"%s\"\n",$11,$1,$2
	x[$1]=1
} ' $perso
awk -F"^" ' BEGIN { print "\nvar prest = new Array()\n" }
{
	printf "prest[\"%s\"]=\"%s\"\n",$1,$2
	x[$1]=1
} ' $profs
} > ../js/datos.js
exit
==> tmp/perso <==
14.030.562-6^Patricio Carvajal^Patricio^Carvajal^^^^^^^04|Psicólogo^00|OPEN^
14.593.649-7^Ailyn Basaez^Ailyn^Basaez^^^^^^^03|Kinesiólogo^00|OPEN^
15.035.545-1^Sebastian Torrejon^Sebastian^Torrejon^^^^^^^03|Kinesiólogo^00|OPEN^
15.916.217-6^Natalia Fuentes^Natalia^Fuentes^^^^^^^01|Médico^00|OPEN^
16.035.875-0^Lilian Bello^Lilian^Bello^^^^^^^04|Psicólogo^00|OPEN^
16.203.285-2^Elizabeth Correa^Elizabeth^Correa^^^^^^^01|Médico^00|OPEN^
16.621.429-7^Sandra Maulen^Sandra^Maulen^^^^^^^02|Enfermera^00|OPEN^
16.839.527-2^Ernesto Reyes^Ernesto^Reyes^^^^^^^01|Médico^00|OPEN^
17.142.186-1^Caroline Villena^Caroline^Villena^^^^^^^04|Psicólogo^00|OPEN^
17.401.563-5^Paola Cornejo^Paola^Cornejo^^^^^^^02|Enfermera^00|OPEN^

==> tmp/profs <==
01^Médico^
02^Enfermera^
03^Kinesiólogo^
04^Psicólogo^
05^Nutricionista^
06^TENS^
