home *** CD-ROM | disk | FTP | other *** search
/ Oakland CPM Archive / oakcpm.iso / sigm / sigmv071.ark / DATA.PAS < prev    next >
Pascal/Delphi Source File  |  1984-04-29  |  27KB  |  1,294 lines

  1.  
  2.  
  3. program xdata;{$P+}
  4. {$c-,m-,f-}
  5. label 1;
  6. const
  7. defaultpad = '                                                           ';
  8. male = true;
  9. female = false;
  10.  
  11. type
  12. id = array[1..6] of char;
  13. calendar = array [1..2] of char;
  14. date_of_test = record
  15.         month:calendar;
  16.         day:calendar;
  17.         year:calendar
  18.         end;
  19. lab_data = record
  20.     name: array [1..30] of char;
  21.     chart_number:id;
  22.     date: date_of_test;  
  23.     sex:boolean;
  24.     weight: real;
  25.     height: real;
  26.     surface_area: real;
  27.     chronological_age: real;
  28.     bone_age: real;
  29.     height_age:real;
  30.     percent_overweight_for_height:real;
  31.     total_body_water: real;
  32.     values:array[1..18,1..14] of real;
  33.     pad:array[1..59] of char;
  34.     end;
  35.  
  36. byte = 0..255;
  37. $string0 = string 0;
  38. $string255 = string 255;
  39. $string80 = string 80;
  40. $string14 = string 14;
  41. $string4 = string 4;
  42. f = file of lab_data;
  43. axis_label = array[1..4] of char;
  44.  
  45. var
  46. filename:$string14;
  47. norms,data:lab_data;
  48. num_values, peak_time,time,results,x,y,i:byte;
  49. fin:f;
  50. average,max,min,sum:real;
  51. normal_value_flag, error, terminate, continue,escape:boolean;
  52. rec:integer;
  53. strvalue:$string80;
  54. x_axis_label,y_axis_label: array[1..14] of axis_label;
  55.  
  56.  
  57. {************************* init labels for axis *************************}
  58. procedure initialize;
  59. var
  60. i:byte;
  61. begin
  62. x_axis_label[1]:= '-30 ';
  63. x_axis_label[2]:= '-1  ';
  64. x_axis_label[3]:= '15  ';
  65. x_axis_label[4]:= '30  ';
  66. x_axis_label[5]:= '45  ';
  67. x_axis_label[6]:= '60  ';
  68. x_axis_label[7]:= '90  ';
  69. x_axis_label[8]:= '120 ';
  70. x_axis_label[9]:= '150 ';
  71. x_axis_label[10]:= '180 ';
  72. x_axis_label[11]:= '210 ';
  73. x_axis_label[12]:= '240 ';
  74. x_axis_label[13]:= '300 ';
  75. x_axis_label[14]:= '360 ';
  76.  
  77. y_axis_label[1]:= 'BS  ';
  78. y_axis_label[2]:= 'IRI ';
  79. y_axis_label[3]:= 'GH  ';
  80. y_axis_label[4]:= 'LH  ';
  81. y_axis_label[5]:= 'FSH ';
  82. y_axis_label[6]:= 'F   ';
  83. y_axis_label[7]:= 'PRL ';
  84. y_axis_label[8]:= 'TSH ';
  85. y_axis_label[9]:= 'T   ';
  86. y_axis_label[10]:= 'DS  ';
  87. y_axis_label[11]:= 'ACTH';
  88. y_axis_label[12]:= 'T4  ';
  89. y_axis_label[13]:= 'TBG ';
  90. y_axis_label[14]:= 'TT3 ';
  91.  
  92. end;
  93.  
  94.  
  95. procedure setlength (var x:$string0; y:integer);external;
  96. function length (x:$string255):integer; external;
  97. procedure keyin(var cix:char);external;
  98.  
  99.  
  100. procedure clear_screen;
  101. begin
  102. write (chr(27),'*',chr(0),chr(0),chr(0),chr(0));
  103. end;
  104.  
  105. procedure erase_lines(starting_line,number_of_lines:byte);
  106. const
  107. blanks = '                                        ';
  108. var
  109. i:byte;
  110.  
  111. begin
  112. for i:= 1 to number_of_lines do
  113.     begin
  114.     write(chr(27),'=',chr(starting_line + 31),chr(32),blanks,blanks);
  115.     starting_line:= starting_line + 1;
  116.     end;
  117. end;
  118.  
  119. procedure move_cursor(x,y:byte);
  120. begin
  121. write(chr(27),'=',chr(y+31),chr(x+31));
  122. end;
  123.  
  124. procedure prompt (x,y,length:byte; p:$string80;
  125.               protected_field_desired:boolean);
  126.  
  127. var
  128. underline:string 80;
  129. i:byte;
  130. begin
  131. setlength(underline,0);
  132. for i:= 1 to length do append (underline,'_');
  133. if protected_field_desired = false then
  134.     write(chr(27),'=',chr(y+31),chr(x+31),p,underline)
  135.     else
  136.     write(chr(27),'=',chr(y+31),chr(x+31),chr(27),')',p,
  137.         underline,chr(27),'(');
  138. end;
  139.  
  140. function query(x,y:byte; message:$string80):boolean;  {ask y/n question}
  141. var 
  142. answer:char;
  143. begin
  144. repeat
  145. move_cursor(x,y);
  146. write(message);
  147. keyin(answer);
  148. until answer in ['y','n','Y','N'];
  149. query:= ((answer = 'y') or (answer = 'Y'));
  150. erase_lines(y,1);
  151. end;
  152.  
  153. function strtoreal (str:$string80):real;
  154. label 1;
  155.  
  156. var
  157. decval,sign,val:real;
  158. decimal,error:boolean;
  159. l,i,len:integer;
  160.  
  161. begin
  162. val:=0.0;
  163. decval:=0.0;
  164. len:=length(str);
  165. l:=len;
  166. error:=false;
  167. decimal:=false;
  168. i:=1;
  169. sign:= 1.0;
  170.  
  171. if len = 0 then
  172.     begin
  173.     error:= true;
  174.     goto 1;
  175.     end;
  176.  
  177. while (decimal = false) and (i < len + 1 ) do
  178. begin
  179.     case str[i] of
  180.     '-': sign:= -1.0;
  181.     '.': decimal:= true;
  182.     '0','1','2','3','4','5','6','7','8','9':
  183.         val:=(val*10) + (ord(str[i]) - 48);
  184.     end;
  185. i:= i+ 1;
  186. end;
  187.  
  188. while (decimal) and (l > i-1) do
  189.     begin
  190.         if str[l] in ['0'..'9'] then
  191.         decval:= (decval*0.1) + ((ord(str[l])-48)*0.1);
  192.         l:=l-1;
  193.     end;
  194. 1:
  195. strtoreal:=sign*(decval+val);
  196. end;
  197.  
  198. function input_data (x,y,len:byte; alphanumeric:boolean;
  199.                  maximum_value,minimum_value:real):$string80;
  200.  
  201. label 1;
  202. var
  203. data:$string80;
  204. realdata:real;
  205. i:byte;
  206.  
  207. procedure correct(x,y:byte);
  208. var 
  209. i,a,b:byte;
  210. begin
  211.     erase_lines(1,1);
  212.     write(chr(7));
  213.     move_cursor(1,1);
  214.     
  215.     if (length(data)> len) then write ('TERM TOO LONG');
  216.  
  217.     if (alphanumeric = false) and
  218.     ((realdata > maximum_value) or (realdata < minimum_value)) then
  219.     write ('VALUE OUT OF RANGE');
  220.  
  221.     move_cursor(x,y);
  222.     write(' ');
  223.     a:=x;
  224.     b:=y;
  225.  
  226.     for i:= 1 to length(data) do
  227.     begin
  228.         move_cursor(a,b);
  229.         write (' ');
  230.         a:= a + 1;
  231.     end;
  232.  
  233.     move_cursor(x,y);
  234.     write('_');
  235.     a:=x;
  236.     b:=y;
  237.     for i:= 1 to (len-1) do
  238.         begin
  239.         move_cursor(a,b);
  240.         write('_');
  241.         a:= a+ 1;
  242.         end;
  243.     move_cursor(x,y);
  244.     read(data);
  245.     realdata:=strtoreal(data);
  246.     erase_lines(1,1);
  247.  
  248. end;
  249.  
  250.  
  251. begin
  252. move_cursor(x,y);
  253. read(data);
  254. if (length(data) > 0) and (ord(data[1]) <> 27) then
  255.         realdata:=strtoreal(data) else goto 1;
  256.  
  257. while (length(data) > len) or ((alphanumeric = false) and
  258.     ((realdata > maximum_value) or (realdata < minimum_value)))
  259.                 do correct(x,y);
  260.  
  261. 1:  if length(data) = 0 then data:= '-999';
  262.  
  263. if length(data) < len then for i:= length(data) to len do append(data,' ');
  264. input_data:=data;
  265. end;
  266.  
  267.  
  268. function ucase (x:$string80):$string80;
  269. label 1;
  270. var
  271. i,len,ascii:integer;
  272. ucasex:$string80;
  273.  
  274. begin
  275. setlength(ucasex,0);
  276. len:=length(x);
  277. if (len = 0) or (len > 4) then goto 1;
  278. for i:= 1 to len do
  279.     if (ord(x[i]) > 96) and (ord(x[i]) < 123) then
  280.     append(ucasex,chr(ord(x[i])-32)) else
  281.     append(ucasex,x[i]);
  282. ucase:=ucasex;
  283. 1:
  284.   end;
  285.  
  286.  
  287. procedure calculate(current_number_of_records:integer);
  288. var
  289. i,thm,hm,o,t,h,th:byte;
  290. begin
  291. o:=0;
  292. t:=0;
  293. h:=0;
  294. thm:=0;
  295. hm:=0;
  296. th:=current_number_of_records div 1000;
  297. thm:= current_number_of_records mod 1000;
  298. h:= thm div 100;
  299. hm:= thm mod 100;
  300. t:= hm div 10;
  301. o:= hm mod 10;
  302.  
  303. with  data do
  304. begin
  305. chart_number[1]:= '0';
  306. chart_number[2]:= '0';
  307. chart_number[3]:= chr(th + 48);
  308. chart_number[4]:= chr(h + 48);
  309. chart_number[5]:= chr(t + 48);
  310. chart_number[6]:= chr(o + 48);
  311.  
  312. end;
  313. end;
  314.  
  315.  
  316. procedure create_first_record;
  317. var
  318. j,i:byte;
  319. number:integer;
  320.  
  321. begin
  322. rewrite(filename,fin);
  323. with data do
  324.     begin
  325.     name:='                              ';
  326.     chart_number:='000001';
  327.     date.month:='00';
  328.     date.day:='00';
  329.     date.year:='00';
  330.     sex:=true;
  331.     weight:= 0.0;
  332.     height:= 0.0;
  333.     surface_area:=0.0;
  334.     chronological_age:=0.0;
  335.     bone_age:= 0.0;
  336.     height_age:=0.0;
  337.     percent_overweight_for_height:=0.0;
  338.     total_body_water:= 0.0;
  339.     pad:=defaultpad;
  340.     for i:= 1 to 18 do
  341.         for j:= 1 to 14 do values[i,j]:= -999.0;
  342.     write(fin:1,data);
  343.     end;
  344. end;
  345.  
  346.  
  347. function number_records(filenam:$string14):integer;
  348. label 1;
  349. var
  350. num:integer;
  351. i:byte;
  352.  
  353. begin
  354. num:= 0;
  355. reset (filename,fin);
  356. if eof(fin) then
  357.     begin
  358.     create_first_record;
  359.     num:= 1;
  360.     goto 1;
  361.     end;
  362. with data do
  363. begin
  364. read(fin:1,data);
  365. for i:= 1 to 6 do num:= num*10 + ord(chart_number[i])-48;
  366. end;
  367. 1: number_records:= num;
  368. end;
  369.  
  370.  
  371.  
  372. procedure axis(pass:byte);
  373. var
  374. i:byte;
  375.  
  376. begin
  377. writeln('     ');{DEBUG delay...terminal does not seem to respond fast enough}
  378. for i:= 6 to 19 do
  379.     begin
  380.     move_cursor(1,i);
  381.     write(x_axis_label[i-5]:4);
  382.     end;
  383. if pass <> 2 then
  384.     begin
  385.     prompt(1,21,0,'max',false);
  386.     prompt(1,22,0,'min',false);
  387.     prompt(1,23,0,'ave',false);
  388.     prompt(1,24,0,'peak',false);
  389.     end;
  390.  
  391. move_cursor(3,3);
  392. write('chart number: ',data.chart_number:6,'Name: ':10,data.name:30);
  393.  
  394. case pass of
  395. 1:        move_cursor(9,5);
  396. 3:    move_cursor(1,5);
  397. else:   move_cursor(6,5);
  398. end;
  399.  
  400. if pass = 3 then write ('TIME     PATIENT   NORMAL (AVE)   DEVIATION') else
  401. for i:= 1 to 14 do
  402.     write(y_axis_label[i]:5);
  403. end;
  404.  
  405.  
  406. procedure get_chart_number;
  407. label 1;
  408. var
  409. xchart_number:id;
  410. xname:array[1..30] of char;
  411. numrecs,i:integer;
  412. number:$string80;
  413. cno,found:boolean;
  414. ch:char;
  415.  
  416. begin
  417. cno:=false;
  418. clear_screen;
  419. move_cursor(1,8);
  420. write('Enter ''NORMAL'' if you wish to display or alter normal values.');
  421. prompt(1,10,6,'Enter either the patient''s name or chart number: ',false);
  422. number:= input_data(50,10,30,true,0.0,0.0);
  423. writeln;
  424. writeln('One moment, please.');
  425. if (ord(number[1]) > 47) and (ord(number[1]) < 58) then
  426.     begin
  427.     cno:= true;
  428.     for i:= 1 to 6 do xchart_number[i]:= number[i];
  429.     end;
  430. if cno = false then 
  431.     begin
  432.     for i:= 1 to 30 do
  433.     xname[i]:=number[i];
  434.     end;
  435.  
  436. reset(filename,fin);
  437. numrecs:=number_records(filename);
  438. i:=0;
  439. normal_value_flag:= false;
  440. error:= false;
  441. with data do
  442. begin
  443. if (xname = 'NORMAL                        ')
  444. or (xname = 'normal                        ') then
  445.     begin
  446.     normal_value_flag:= true;
  447.     read(fin:1,data);
  448.     norms.values:=data.values;
  449.     rec:=1;
  450.     goto 1;
  451.     end;
  452.  
  453. repeat
  454. i:= i+1;
  455. read(fin:i,data);
  456. case cno of
  457. true:if xchart_number = data.chart_number then found:= true else found:= false;
  458. false:if xname = data.name then found:=true else found:= false;
  459. end; {of case}
  460. until (found) or (i = numrecs);
  461. if found then rec:= i else error:= true;
  462.  
  463. 1:end;
  464. if error then
  465.     begin
  466.     clear_screen;
  467.     move_cursor(1,10);
  468.     if cno then writeln('Chart number not found !') else 
  469.                 writeln('Name not found !');
  470.     writeln;
  471.     writeln('Enter any character to continue.');
  472.     keyin(ch);
  473.     end;
  474. clear_screen;
  475. end;
  476.  
  477.  
  478.  
  479. procedure display_values(normal_value_flag, displayed_for_correction:boolean);
  480. var
  481. x,y,i:byte;
  482. continue:char;
  483.  
  484. begin
  485. clear_screen;
  486. escape:=false;
  487. writeln('      '); {DEBUG for terminal delay}
  488. axis(1);
  489. if normal_value_flag then
  490.     begin
  491.     move_cursor(3,3);
  492.     write('NORMAL VALUES');
  493.     end;
  494. x:= 7;
  495. y:= 6;
  496. for time:= 1 to 18 do
  497.     begin
  498.     for results:= 1 to 14 do
  499.         begin
  500.         move_cursor(x,y);
  501.         if abs(data.values[time,results]) <> 999.0 then
  502.             write(data.values[time,results]:4:1)  else
  503.             write('    '); {4 spaces}
  504.         x:= x + 5;
  505.         end;
  506.     y:= y + 1;
  507.     if y = 20 then y:= 21;
  508.     x:= 7;
  509.     end;
  510. if displayed_for_correction = false then
  511.     begin
  512.     move_cursor(1,1);
  513.     write('Enter any character to continue or ''ESC'' to return to menu.');
  514.     keyin(continue);
  515.     if ord(continue) = 27 then escape:= true;
  516.     end;
  517. end;
  518.  
  519.  
  520.  
  521. procedure print(desire_hardcopy:boolean);
  522.  
  523. label 1,2;
  524. var
  525. i:integer;
  526. continue:char;
  527. recursive,all,more:boolean;
  528.  
  529. procedure hardcopy(normal_value_flag:boolean);
  530. var
  531. counter,j:byte;
  532. output:text;
  533.  
  534. begin
  535. rewrite('lst:',output);
  536.  
  537. if recursive = false then
  538. begin
  539. write('Prepare printer, then enter any character to initiate listing. ');
  540. keyin(continue);
  541. clear_screen;
  542. writeln('Now printing results.');
  543. end;
  544.  
  545. write(output,chr(12));
  546. for counter:= 1 to 3 do writeln(output);
  547. with data do
  548. begin
  549.  
  550. if normal_value_flag then chart_number:= 'NORMAL';
  551. writeln(output,'chart_number: ',chart_number, ' Name: ',name);
  552. writeln(output);
  553. write(output,'    '); {4 spaces}
  554. for counter:= 1 to 14 do write(output,y_axis_label[counter]:8);
  555. writeln(output);
  556.  
  557. for counter:= 1 to 18 do
  558.     begin
  559.     if counter < 15 then write(output,x_axis_label[counter]:4,' ') else
  560.         case counter of
  561.         15: write(output,'max  ');
  562.         16: write(output,'min  ');
  563.         17: write(output,'ave  ');
  564.         18: write(output,'peak ');
  565.         end;
  566.  
  567. for j:= 1 to 14 do
  568.     if abs(values[counter,j]) = 999.0 then
  569.         write(output,' ':8) else
  570.         write(output,values[counter,j]:8:1);
  571.  
  572.     writeln(output);
  573.     writeln(output);
  574.     end;
  575.  
  576. end;
  577. end;
  578.  
  579. begin   {of procedure print}
  580. reset(filename,fin);
  581. if eof(fin) then
  582.     begin
  583.     writeln('NO FILE PRESENT!');
  584.     writeln;
  585.     write('Enter any character to continue. ');
  586.     keyin(continue);
  587.     goto 1;
  588.     end;
  589.  
  590. clear_screen;
  591. all:= query(1,10,'Do you wish to display all results for ALL patients? y/n ');
  592.  
  593. case all of
  594. false:    begin
  595.     repeat
  596.     get_chart_number;
  597.     
  598.     case desire_hardcopy of
  599.     true:    if error = false then hardcopy(normal_value_flag) else
  600.                       erase_lines(10,3);
  601.     false:  if error = false then display_values(false,false) else
  602.                           erase_lines(10,3);
  603.     end;
  604. if (error) or (escape) then goto 1;  {goto menu if record not found or done}
  605.  
  606. error:=false;
  607. erase_lines(1,1);
  608. more:=query(1,1,'Do you wish to display data for another patient? y/n  ');
  609.     until more  = false;
  610.     end;
  611.  
  612. true:    begin
  613.     rec:= number_records(filename);
  614.     recursive:=false;
  615.     for i:= 1 to rec do
  616.         begin
  617.         escape:= false;
  618.         read(fin:i,data);
  619.             case desire_hardcopy of
  620.             true: if i= 1 then hardcopy(true) else hardcopy(false);
  621.             false: if i= 1 then display_values(true,false) else
  622.                             display_values(false,false);
  623.             end;
  624.         recursive:= true;
  625.         if escape then goto 1;
  626.         end;
  627.     end;
  628. end;    {of case}
  629. 1:
  630. end;
  631.  
  632.  
  633. procedure values_calculation;
  634.  
  635. begin
  636. with data do 
  637. begin
  638.  
  639. for results:= 1 to 14 do
  640. begin
  641. max:= values[1,results];
  642. peak_time:= 1;
  643.  
  644. if values[1,results] = -999.0 then
  645.     begin
  646.     sum:= 0.0;
  647.     num_values:= 0;
  648.     min:=999.0;
  649.     end;
  650.  
  651. if values[1,results] > -999.0 then
  652.     begin
  653.     sum:= values[1,results] ;
  654.     num_values:= 1;
  655.     min:= values[1,results];
  656.     end;
  657.  
  658.     for time := 2 to 14 do
  659.     begin
  660.     if max < values[time,results] then
  661.         begin
  662.         max:= values[time,results];
  663.         peak_time:= time;
  664.         end;
  665.     
  666.     if (values[time,results] > -999.0) and (min > values[time,results])
  667.                 then min:= values[time,results];
  668.  
  669.     if values[time,results] > -999.0 then
  670.             begin
  671.             sum:= sum + values[time,results] ;
  672.             num_values:= num_values + 1;
  673.             end;
  674.     end;
  675.  
  676. average:= sum/num_values;
  677. values[15,results]:= max;
  678. values[16,results]:= min;
  679. if average = 0.0 then values[17,results]:= -999.0 else
  680.               values[17,results]:= average;
  681.  
  682. case peak_time of 
  683. 1: values[18,results]:= -30.0;
  684. 2: values[18,results]:= -1.0;
  685. 3: values[18,results]:= 15.0;
  686. 4: values[18,results]:= 30.0;
  687. 5: values[18,results]:= 45.0;
  688. 6: values[18,results]:= 60.0;
  689. 7: values[18,results]:= 90.0;
  690. 8: values[18,results]:= 120.0;
  691. 9: values[18,results]:= 150.0;
  692. 10: values[18,results]:= 180.0;
  693. 11: values[18,results]:= 210.0;
  694. 12: values[18,results]:= 240.0;
  695. 13: values[18,results]:= 300.0;
  696. 14: values[18,results]:= 360.0;
  697. end;
  698.  
  699. if average = 0.0 then values[18,results]:= -999.0;
  700. end;
  701.  
  702.  
  703. y:=21;
  704. prompt(1,21,0,'max',false);
  705. prompt(1,22,0,'min',false);
  706. prompt(1,23,0,'ave',false);
  707. prompt(1,24,0,'peak',false);
  708. for time:= 1 to 4 do
  709.     begin
  710.     for results:= 1 to 14 do
  711.         begin 
  712.         move_cursor(results*5+2,y);
  713.         if (abs(values[time+14,results]) = 999.0) then
  714.             write('    ') else
  715.             write(values[time+14,results]:4:1);
  716.         end;
  717.     y:= y+ 1;
  718.     end;
  719. end; {of with data}
  720. end;
  721.  
  722.  
  723.  
  724. procedure mistake (shift_over_x_axis_flag:boolean);
  725. label 1,2;
  726. var
  727. strtime,strtest:$string80;
  728. xtime,xtest: axis_label;
  729. matrix,shift,i,j,time,test:byte;
  730. found,finished:boolean;
  731.  
  732. begin
  733. finished:= false;
  734. repeat
  735. erase_lines(1,1);
  736. move_cursor(1,1);
  737. write('Enter test and time of incorrect data, e.g. BS <cr> 30 <cr> ');
  738. 1: strtest:= input_data(65,1,4,true,0.0,0.0);
  739.     if strtest[1] = chr(27) then
  740.         begin
  741.         finished:= true;
  742.         goto 2;
  743.         end;
  744.     strtest:= ucase(strtest);
  745.     strtime:= input_data(75,1,4,true,0.0,0.0);
  746.     
  747.     for i:= 1 to 4 do
  748.         begin
  749.         xtime[i]:= strtime[i];
  750.         xtest[i]:= strtest[i];
  751.         end;
  752. erase_lines(1,1);
  753.  
  754. time:= 255;
  755. test:= 255;
  756. matrix:= 1;
  757. found:= false;
  758. repeat
  759. if xtest = y_axis_label[matrix] then
  760.         begin
  761.         found:= true;
  762.         test:= matrix;
  763.         end;
  764. matrix:= matrix + 1;
  765. until (found) or (matrix > 14);
  766.  
  767. matrix:= 1;
  768. found:= false;
  769. repeat
  770. if xtime = x_axis_label[matrix] then
  771.         begin
  772.         found:= true;
  773.         time:= matrix;
  774.         end;
  775. matrix:= matrix + 1;
  776. until (found) or (matrix > 14);
  777.  
  778. if time = 255 then
  779.     begin
  780.     erase_lines(1,1);
  781.     move_cursor(1,1);
  782. write('You have entered an invalid time, please reenter test & time: ');
  783.     goto 1;
  784.     end;
  785.  
  786. if test = 255 then
  787.     begin
  788.     erase_lines(1,1);
  789.     move_cursor(1,1);
  790. write('You have entered an invalid test, please reenter test & time: ');
  791.     goto 1;
  792.     end;
  793.  
  794. if shift_over_x_axis_flag then shift:= 4 else shift:= 2;
  795.  
  796. prompt(test*5+shift,time+5,0,'     ',false);
  797. strvalue:= input_data(test*5+shift,time+5,4,false,9999.0,0.0);
  798. if strvalue = '-999' then
  799.     data.values[time,test]:= -999.0 else
  800.     data.values[time,test]:= strtoreal(strvalue);
  801.  
  802. 2: until finished;
  803. erase_lines(1,1);
  804. values_calculation;
  805. end;
  806.  
  807.  
  808. procedure update_first_record (number_recs:integer);
  809. begin
  810. reset(filename,fin);
  811. with data do
  812. begin
  813.     read(fin:1,data);
  814.     calculate(number_recs);
  815.     data.name:='                              ';{DEBUG}
  816.     write(fin:1,data);
  817.     end;
  818. end;
  819.  
  820.  
  821.  
  822. procedure get_vital_statistics;
  823. var
  824. xname,xchartnumber,xheight,xweight,xage,xboneage,xheightage:$string80;
  825. xmonth,xday,xyear:$string80;
  826. correction,i:byte;
  827. correct:boolean;
  828. wrong,xsex:char;
  829.  
  830.  
  831. procedure get_patient_data (entry:byte);  {this procedure internal to above}
  832. begin
  833. case entry of
  834. 1:    begin
  835.     prompt(1,2,30,'{1} Name: ',false);
  836.     xname:= input_data(10,2,30,true,0.0,0.0);
  837.     xname:=ucase(xname);
  838.     end;
  839. 2:    begin
  840.     prompt(50,2,6,'{2} Chart Number: ',false);
  841.     xchartnumber:= input_data(67,2,6,true,0.0,0.0);
  842.     end;
  843. 3:    begin
  844.     repeat
  845.     move_cursor(1,4);
  846.     write('{3} Sex (m/f) ');
  847.     read(xsex);
  848.     until xsex in ['m','f','M','F'];
  849.     end;
  850. 4:    begin
  851.     prompt(20,4,0,'{4} Height (cm): ',false);
  852.     xheight:= input_data(41,4,5,false,200.0,0.0);
  853.     end;
  854. 5:     begin
  855.     prompt(50,4,0,'{5} Weight (kg): ',false);
  856.     xweight:= input_data(71,4,5,false,300.0,0.0);
  857.     end;
  858. 6:    begin
  859.     prompt(1,6,0,'{6} Age (yr.mo): ',false);
  860.     xage:= input_data(20,6,5,false,30.0,0.1);
  861.     end;
  862. 7:    begin
  863.     prompt(30,6,0,'{7} Bone Age (yr.mo): ',false);
  864.     xboneage:= input_data(52,6,4,false,20.0,0.0);
  865.     end;
  866. 8:    begin
  867.     prompt(1,8,0,'{8} Height Age (yr.mo): ',false);
  868.     xheightage:= input_data(25,8,4,false,20.0,0.0);
  869.     end;
  870. 9:    begin
  871.     prompt(1,10,2,'{9} date: ',false);
  872.     prompt(13,10,0,'/',false);
  873.     prompt(16,10,0,'/',false);
  874.     xmonth:= input_data(10,10,2,true,0.0,0.0);
  875.     xday:= input_data(14,10,2,true,0.0,0.0);
  876.     xyear:= input_data(17,10,2,true,0.0,0.0);
  877.     end;
  878. end; {of case}
  879. end; {of procedure}
  880.  
  881.  
  882. begin
  883. clear_screen;
  884. writeln;
  885. prompt(1,2,0,'{1} Name: ',false);
  886. prompt(50,2,0,'{2} Chart Number: ',false);
  887. prompt(1,4,0,'{3} Sex (m/f): ',false);
  888. prompt(20,4,0,'{4} Height (cm):',false);
  889. prompt(50,4,0,'{5} Weight (kg):',false);
  890. prompt(1,6,0,'{6} Age (yr.mo):',false);
  891. prompt(30,6,0,'{7} Bone Age (yr.mo):',false);
  892. prompt(1,8,0,'{8} Height Age (yr.mo):',false);
  893. prompt(1,10,0,'{9} date: ',false);
  894. prompt(13,10,0,'/',false);
  895. prompt(16,10,0,'/',false);
  896.  
  897. for i:= 1 to 9 do get_patient_data(i);
  898. repeat
  899. correct:= query(1,15,'Is information correct as entered? y/n');
  900. if correct = false then
  901.     begin
  902.     repeat
  903.     erase_lines(15,1);
  904.     move_cursor(1,15);
  905.     write('Enter number corresponding to incorrect data: ');
  906.     keyin(wrong);
  907.     correction:= ord(wrong) - 48;
  908.     until correction in [1..9];
  909.     erase_lines(15,1);
  910.     get_patient_data(correction);
  911.     end;
  912. until correct;
  913. with data do
  914. begin
  915. for i:= 1 to 30 do name[i]:= xname[i];
  916. for i:= 1 to 6  do chart_number[i]:= xchartnumber[i];
  917. if xsex in ['m','M'] then sex:= male else sex:= female;
  918. height:= strtoreal(xheight);
  919. weight:= strtoreal(xweight);
  920. chronological_age:= strtoreal(xage);
  921. bone_age:=strtoreal(xboneage);
  922. height_age:=strtoreal(xheightage);
  923. for i:= 1 to 2 do 
  924.     begin
  925.     date.month[i]:=xmonth[i];
  926.     date.day[i]:= xday[i];
  927.     date.year[i]:= xyear[i];
  928.     end;
  929. {calc_percent_overweight_for_height;}
  930. surface_area:=exp((0.425*ln(weight)) + (0.725*ln(height)) + 4.274);
  931.  
  932.         {S.A.= weight^.425 * height^.725 * 71.84  according to}
  933.             {DuBois & DuBois Arch Int Med 17:863 (1916)}
  934.         
  935. percent_overweight_for_height:=0.0;
  936. total_body_water:= -10.313 + 0.252*weight + 0.154*(height);
  937. end; {of with data}
  938.  
  939. end; {of procedure}
  940.  
  941.  
  942. procedure get_data(flag:byte);
  943. label 1;
  944. var
  945. rec:integer;
  946. esc,num:byte;
  947.  
  948. begin
  949. reset(filename,fin);
  950. if eof(fin) then create_first_record;
  951. rec:= number_records(filename) + 1;
  952. repeat
  953. with data do
  954. begin
  955. pad:= defaultpad;
  956.  
  957. if flag > 0 then get_vital_statistics;
  958.  
  959. clear_screen;
  960. writeln;
  961. move_cursor(1,1);
  962. if flag = 0 then write('   Enter NORMAL laboratory values: ') else
  963.              write('   Enter patient''s laboratory values: ');
  964. axis(0);
  965. x:= 7;
  966. y:= 6;
  967. for results:= 1 to 14 do
  968.     begin
  969.         time:= 1;
  970.         while (time < 15) do
  971.         begin
  972.         strvalue:= input_data(x,y,4,false,9999.0,0.0);
  973.         case ord(strvalue[1]) of
  974.         27:    begin
  975.             for esc:= time to 14 do 
  976.                 values[time,results]:= -999.0;
  977.             time:= 15;
  978.             end;
  979.         else:  begin
  980.             if strvalue = '-999' then
  981.             values[time,results]:= -999.0 else
  982.             values[time,results]:= strtoreal(strvalue);
  983.             time:= time + 1;
  984.             y:= y+ 1;
  985.             end;
  986.         end; {of case}
  987.         end; {of while}
  988. x:= x+ 5;
  989. y:= 6;
  990. end;
  991.  
  992. continue:= query(1,1,'Is information correct as entered? y/n ');
  993. if continue = false then mistake(false);
  994.  
  995. values_calculation;
  996. case flag of 
  997. 0: write(fin:1,data);
  998. else: write(fin:rec,data);
  999. end;
  1000.  
  1001. if flag = 0 then continue:= false else
  1002.     continue:= query(1,1,'Do you wish to add another record? y/n ');
  1003. if continue then rec:= rec + 1;
  1004. end; {of with data}
  1005. until continue = false;
  1006. if flag > 0 then update_first_record(rec);
  1007. end;
  1008.  
  1009.  
  1010. procedure set_normal_values;
  1011. begin
  1012. get_data(0);
  1013. end;
  1014.  
  1015.  
  1016. procedure get_normal_values;
  1017. begin
  1018. reset(filename,fin);
  1019. read(fin:1,norms);
  1020. end;
  1021.  
  1022.  
  1023. procedure print_individual_test_results (desire_hardcopy:boolean);
  1024. label 1;
  1025. var
  1026. x,y:byte;
  1027. test,continue:char;
  1028. output:text;
  1029.  
  1030.  
  1031. procedure choose_test;
  1032. begin
  1033.     clear_screen;
  1034.     writeln;
  1035.     writeln('A-  BLOOD SUGAR');
  1036.     writeln('B-  INSULIN');
  1037.     writeln('C-  GROWTH HORMONE');
  1038.     writeln('D-  LH');
  1039.     writeln('E-  FSH');
  1040.     writeln('F-  CORTISOL');
  1041.     writeln('G-  PROLACTIN');
  1042.     writeln('H-  TSH');
  1043.     writeln('I-  TESTOSTERONE');
  1044.     writeln('J-  DS');
  1045.     writeln('K-  ACTH');
  1046.     writeln('L-  T4');
  1047.     writeln('M-  TBGI');
  1048.     writeln('N-  TT3');
  1049.     writeln('O-  display values for a different patient');
  1050.     writeln('P-  return to the menu');
  1051.     writeln;
  1052.     write('Please enter the letter corresponding to the test: ');
  1053.     repeat
  1054.     move_cursor(61,19);
  1055.     keyin(test);
  1056.     if (ord(test) > 96) and (ord(test) < 123) then
  1057.         test:= chr(ord(test)-32);
  1058.     write(test);
  1059.     until test in ['A'..'P'];
  1060.     results:= ord(test)-64;
  1061.     clear_screen;
  1062. end;
  1063.  
  1064. begin
  1065. reset(filename,fin);
  1066. if eof(fin) then
  1067.     begin
  1068.     error:= true;
  1069.     goto 1;
  1070.     end;
  1071. if desire_hardcopy then rewrite('lst:',output);
  1072.  
  1073. get_chart_number;
  1074. if normal_value_flag = false then get_normal_values;
  1075. choose_test;
  1076. while results < 16 do
  1077. begin
  1078.  
  1079. if results = 15 then
  1080.     begin
  1081.     get_chart_number;
  1082.     choose_test;
  1083.     end;
  1084. if desire_hardcopy = false then axis(3) else
  1085.     begin
  1086.     clear_screen;
  1087. write('Prepare printer, then enter any character to initiate printing.');
  1088.     keyin(continue);
  1089.     erase_lines(1,1);
  1090.     writeln;
  1091.     write('Now printing results.');
  1092.     end;
  1093. with data do
  1094. begin
  1095.  
  1096. if desire_hardcopy = false then
  1097.     begin
  1098.     move_cursor(20,3);
  1099.     write(y_axis_label[results]);
  1100.     end;
  1101. if desire_hardcopy then
  1102.     begin
  1103.     write(output,chr(12));
  1104.     for x:= 1 to 3 do writeln(output);
  1105.     if normal_value_flag then chart_number:= 'NORMAL';
  1106.     write(output,'chart number: ',chart_number, y_axis_label[results]:15);
  1107.     writeln(output);
  1108.     write(output,'PATIENT':20,'NORMAL (AVE)':22, 'DEVIATION':15);
  1109.     writeln(output);
  1110.     end;
  1111.  
  1112. y:= 6;
  1113. for time:= 1 to 18 do
  1114.  begin
  1115.     case desire_hardcopy of
  1116. false:    begin
  1117.     move_cursor(10,y);
  1118.     if (normal_value_flag) or (abs(values[time,results]) = 999.0) then
  1119.         write('    ') else
  1120.         write(values[time,results]:4:1);    
  1121.     move_cursor(20,y);
  1122.     if (abs(norms.values[time,results]) = 999.0) then
  1123.         write('    ') else
  1124.         write(norms.values[time,results]:4:1);    
  1125.     move_cursor(35,y);
  1126.     if (abs(values[time,results]) = 999.0) or (normal_value_flag) or
  1127.         (abs(norms.values[time,results]) = 999.0) then
  1128.         write('    ') else
  1129.     if values[time,results] < norms.values[time,results] then
  1130.         write('LOW') else
  1131.     if values[time,results] > norms.values[time,results] then
  1132.         write('HIGH') else write('     ');
  1133.     if y = 19 then y:= y + 2 else y:= y + 1;
  1134.     end;
  1135.  
  1136. true:    begin
  1137.     if time < 15 then write (output,x_axis_label[time]) else
  1138.     case time of
  1139.     15: write(output,'max ');
  1140.     16: write(output,'min ');
  1141.     17: write(output,'ave ');
  1142.     18: write(output,'peak');
  1143.     end;
  1144.  
  1145.     if (abs(values[time,results]) = 999.0) or (normal_value_flag) then
  1146.         write(output,' ':15) else
  1147.         write(output,values[time,results]:15:1);
  1148.  
  1149.     if (abs(norms.values[time,results]) = 999.0) then
  1150.         write(output,' ':15) else
  1151.         write(output,norms.values[time,results]:15:1);
  1152.  
  1153.     if (abs(values[time,results]) = 999.0) or (normal_value_flag) or
  1154.        (abs(norms.values[time,results]) = 999.0) then
  1155.         write(output,' ':15) else
  1156.         if values[time,results] < norms.values[time,results] then
  1157.         write(output,'LOW':15) else
  1158.     if values[time,results] > norms.values[time,results] then
  1159.         write(output,'HIGH':15) else write(output,' ':15);
  1160.  
  1161. writeln(output);
  1162. end;
  1163. end;
  1164.  
  1165. end; {of time}
  1166. move_cursor(1,1);
  1167. write('Enter any character to continue ');
  1168. keyin(continue);
  1169. choose_test;
  1170. end; 
  1171. end;
  1172. 1:
  1173. end;
  1174.  
  1175.  
  1176.  
  1177. procedure correction;
  1178. label 1;
  1179. var
  1180. i:integer;
  1181. ch:char;
  1182. continue:boolean;
  1183.  
  1184. begin
  1185. clear_screen;
  1186. reset(filename,fin);
  1187. if eof(fin) then
  1188.     begin
  1189.     move_cursor(1,10);
  1190.     writeln('File not found!');
  1191.     writeln('Enter any character to continue.');
  1192.     keyin(ch);
  1193.     goto 1;
  1194.     end;
  1195.  
  1196. continue:= true;
  1197. repeat
  1198. get_chart_number;
  1199. if error = false then
  1200.     begin
  1201.     display_values(normal_value_flag,true);
  1202.     mistake(true);
  1203.     write(fin:rec,data);
  1204.     end;
  1205. continue:= query(1,1,'Do you wish to correct another patient''s record? y/n ');
  1206. until continue = false;
  1207.  
  1208. 1:
  1209. end;
  1210.  
  1211.  
  1212. procedure get_filename;
  1213. var
  1214. newfile:boolean;
  1215.  
  1216. begin
  1217. clear_screen;
  1218. writeln;
  1219. writeln('Enter name of patient data file as:      drive:name.extension ');
  1220. writeln;
  1221. writeln('Drive is either ''A'' or ''B''  .');
  1222. writeln('Name may be up to 14 letters.   ');
  1223. writeln('Extention may be up to 3 letters.');
  1224. move_cursor(10,10);
  1225. write('---->   ');
  1226. read(filename);
  1227.  
  1228. reset(filename,fin);
  1229. if eof(fin) then
  1230.     begin
  1231.     prompt(10,15,0,'A file by that name is NOT FOUND. ',false);
  1232.     newfile:= query(10,16,'Is this a new file?    y/n');
  1233.     if newfile then rewrite(filename,fin) else get_filename;
  1234.     end;
  1235. end;
  1236.  
  1237.  
  1238.  
  1239.  
  1240. procedure menu;
  1241. var
  1242. ch:char;
  1243.  
  1244. begin
  1245. error:= false;
  1246. clear_screen;
  1247. writeln;
  1248. writeln('Choose one of the following: ');
  1249. writeln;
  1250. writeln('1-  Establish or set the normal values');
  1251. writeln('2-  Add patient results to file');
  1252. writeln('3-  Display on terminal selected test results for a patient');
  1253. writeln('4-  Print selected test results for a patient');
  1254. writeln('5-  Display on terminal all results for a patient');
  1255. writeln('6-  Print all results for a patient');
  1256. writeln('7-  Correct selected values or results for a patient''s record');
  1257. writeln;
  1258. writeln('8-  CHANGE NAME OF PATIENT DATA FILE');
  1259. writeln('0-  EXIT program');
  1260. writeln;
  1261. write('Your selection please:  ');
  1262. repeat
  1263. move_cursor(25,15);
  1264. keyin(ch);
  1265. write(ch);
  1266. until ch in ['0'..'8'];
  1267. case ch of
  1268. '1': set_normal_value;
  1269. '2': get_data(1);
  1270. '3': print_individual_test_results(false);
  1271. '4': print_individual_test_results(true);
  1272. '5': print(false);
  1273. '6': print(true);
  1274. '7': correction;
  1275. '8': get_filename;
  1276. '0': terminate:= true;
  1277. end;
  1278.  
  1279. end;
  1280.  
  1281.  
  1282.  
  1283.  
  1284. {**************************** main program *****************************}
  1285.  
  1286. begin
  1287. initialize;
  1288. terminate:= false;
  1289. get_filename;
  1290. repeat
  1291. menu;
  1292. until terminate ;
  1293. end.
  1294.