#!/usr/bin/perl
print "Content-type: text/html\n\n";
###
### JOHNS HOPKINS AUTOPSY ARCHIVE INFORMATION SYSTEM.
### THIS DOCUMENT HAS NO OFFICIAL STATUS.
###
### DISCLAIMER. United States Government Work,
### uncopyrighted, public-domain, DRAFT COPY ONLY.
### This document does not necessarily represent the views
### or policies of any United States Government agency.
### This document is provided "as is", without warranty of any kind,
### express or implied, including but not limited to the warranties
### of merchantability, fitness for a particular purpose and
### non-infringement. In no event shall the authors be liable
### for any claim, damages or other liability, whether in an
### action of contract, tort or otherwise, arising from, out of,
### or in connection with the document or the use or other dealings
### made with the document.
###
### CONTROL CHARACTERS AND CONSTANTS.
$carriagereturn=chr(13); $linefeed=chr(10); $bksp=chr(32);
$crlf=join('',$carriagereturn,$linefeed);
$crlfps="$crlf#"; $crlfpss="$crlf### ";
$crlfpsfv="$crlf#####"; $psfv="#####"; $upar=chr(94);
###
### OPEN JHAR REPORT FILE.
$nshowaut=0;
$jharrprt=">jharrprt.htm"; open(JHARRPRT,$jharrprt);
###
### PRINT HEADER.
$prln="<html><head><title>JHARIS: Johns Hopkins Autopsy aRchive, 6/2/2006.</title></head><body>";
print $prln; print JHARRPRT $prln;
$jharuprt="jharuprt.txt"; $sizeuprt= -s $jharuprt ;
$prln="\n<!-- Last modified: 6/2/2006, G. William Moore, MD, PhD.-->";
print $prln; print JHARRPRT $prln;
$prln="<h2><center>JHARIS: Johns Hopkins<br>Autopsy aRchive<br>Information System.";
print $prln; print JHARRPRT $prln;
$prln="\n<br><a href=\"http://www.netautopsy.org/gwmpmbio.htm\">G. William Moore, MD, PhD.</a>";
print $prln; print JHARRPRT $prln;
$prln="\n<br><a href=\"http://www.netautopsy.org/gmhpmbio.htm\">Grover M. Hutchins, MD.</a>";
print $prln; print JHARRPRT $prln;
$prln="\n<br>6/2/2006. "; print $prln; print JHARRPRT $prln;
$prln="</center></h2>"; print $prln; print JHARRPRT $prln;
$prln="<br><br><big><b>Program Source Code: <a href=\"http://www.netautopsy.org/jharis.cgi\">
http://www.netautopsy.org/jharis.cgi </a> ";
print $prln; print JHARRPRT $prln;
$prln="<br>Procedure Manual: <a href=\"http://www.netautopsy.org/jharispm.htm\">
http://www.netautopsy.org/jharispm.htm </a></b></big> ";
print $prln; print JHARRPRT $prln;
###
### ASK FOR SEARCH WORDS.
$nask=0; $nsearch=0; print "\n Enter up to twenty search words.";
print "\n Enter the least common search word first:";
while($nask<20){$nask++; print "\n Please enter search word ==> ";
$inputline=<STDIN>; chop($inputline); $linl=length($inputline);
$lcin=lc($inputline); if($linl>2){$nsearch++; $search[$nsearch]=$lcin;};
if($linl<3){$nask=99999;};};
###
### IF NO SEARCH WORDS ENTERED, JOB TERMINATED.
if($nsearch<1){$prln="\n NO SEARCH WORDS ENTERED. JOB TERMINATED.";
print $prln; print JHARRPRT $prln;
$prln="\n<br><hr> Last modified: 6/2/2006, G. William Moore, MD, PhD.";
print $prln; print JHARRPRT $prln;
$prln="\n <br></body></html>\n\n";
print $prln; print JHARRPRT $prln; close(JHARRPRT); exit;};
###
### ASK FOR SEARCH LINE DISTANCE.
$linedistmax=1000000;
if($nsearch>1){print "\n Enter search line distance ==> ";
$inputline=<STDIN>; chop($inputline); $linl=length($inputline);
if($linl>0){$linedistmax=$inputline-0+1;};};
$ldm=$linedistmax-1;
###
### LIST EXCLUDED CASES?
$showsw=0; print "\n List excluded cases? N ==> ";
$inputline=<STDIN>; chop($inputline); $linl=length($inputline);
$lcshow=lc($inputline); $sublcshow=substr($lcshow,0,1);
if($linl>0){if($sublcshow eq "y"){$showsw=1;};};
if($showsw>0){$prln="\n<br><b> Excluded cases listed. </b>";
print $prln; print JHARRPRT $prln;};
if($showsw<1){$prln="\n<br><b> Excluded cases not listed. </b>";
print $prln; print JHARRPRT $prln;};
###
### LIST SEARCH WORDS ENTERED.
if($nsearch>0){$prln="\n<br><big> Search words entered: <b>";
print $prln; print JHARRPRT $prln; $isearch=0;
while($isearch<$nsearch){$isearch++; $ucsearch=uc($search[$isearch]);
$prln=" $ucsearch "; print $prln; print JHARRPRT $prln;};
$prln="</b></big>"; print $prln; print JHARRPRT $prln;
if($nsearch>1){$prln="\n<br><b> Search line distance: $ldm </b>";
print $prln; print JHARRPRT $prln;};};
###
### ASK FOR EXCLUDED SEX.
print "\n Please enter EXCLUDED sex ==> "; $inputline=<STDIN>;
chop($inputline); $linl=length($inputline);
$lcin=lc($inputline); $frlcin=substr($lcin,0,1);
$exclsx="x"; if($frlcin eq "m"){$exclsx="m";};
if($frlcin eq "f"){$exclsx="f";};
if($exclsx eq "x"){$prln="\n<br><b> Both sexes are included. </b>";
print $prln; print JHARRPRT $prln;};
if($exclsx eq "m"){$prln="\n<br><b> Males are excluded. </b>";
print $prln; print JHARRPRT $prln;};
if($exclsx eq "f"){$prln="\n<br><b> Females are excluded. </b>";
print $prln; print JHARRPRT $prln;};
###
### ASK FOR EXCLUDED RACE.
print "\n Please enter EXCLUDED race (W,B) ==> "; $inputline=<STDIN>;
chop($inputline); $linl=length($inputline);
$lcin=lc($inputline); $frlcin=substr($lcin,0,1);
$exclrc="u"; if($frlcin eq "w"){$exclrc="w";};
if($frlcin eq "b"){$exclrc="b";};
if($exclrc eq "u"){$prln="\n<br><b> All races are included. </b>";
print $prln; print JHARRPRT $prln;};
if($exclrc eq "b"){$prln="\n<br><b> Blacks are excluded. </b>";
print $prln; print JHARRPRT $prln;};
if($exclrc eq "w"){$prln="\n<br><b> Whites are excluded. </b>";
print $prln; print JHARRPRT $prln;};
###
### ASK FOR EXCLUDED LOWER AGE.
$lowerage=-1;
print "\n Please enter EXCLUDED LOWER age in years ==> "; $inputline=<STDIN>;
chop($inputline); $linl=length($inputline);
if($linl>0){$lowerage=$inputline-0;};
$prln="\n<br><b> Excluded lower age in years: $lowerage.</b>";
print $prln; print JHARRPRT $prln;
###
### ASK FOR EXCLUDED UPPER AGE.
$upperage=200;
print "\n Please enter EXCLUDED UPPER age in years ==> "; $inputline=<STDIN>;
chop($inputline); $linl=length($inputline);
if($linl>0){$upperage=$inputline-0;};
$prln="\n<br><b> Excluded upper age in years: $upperage.</b>";
print $prln; print JHARRPRT $prln;
###
### ASK FOR EXCLUDED LOWER AUTOPSY NUMBER.
$loweraun=-1;
print "\n Please enter EXCLUDED LOWER autopsy number ==> ";
$inputline=<STDIN>; chop($inputline); $linl=length($inputline);
if($linl>0){$loweraun=$inputline-0;};
$prln="\n<br><b> Excluded lower autopsy number: $loweraun.</b>";
print $prln; print JHARRPRT $prln;
###
### ASK FOR EXCLUDED UPPER AUTOPSY NUMBER.
$upperaun=99999;
print "\n Please enter EXCLUDED UPPER autopsy number ==> ";
$inputline=<STDIN>; chop($inputline); $linl=length($inputline);
if($linl>0){$upperaun=$inputline-0;};
$prln="\n<br><b> Excluded upper autopsy number: $upperaun.</b>";
print $prln; print JHARRPRT $prln;
###
### INITIALIZE HIT ARRAY.
$iaunhit=-1; while($iaunhit<50001){$iaunhit++;
$aunhit[$iaunhit]=0; $thishit[$iaunhit]=0; $casepoint[$iaunhit]=0;};
###
### LOAD DEMOGRAPHICS.
print "\n Loading demographics....";
$jharkeyy="jharkeyy.txt"; $sizejhar= -s $jharkeyy ;
open(JHARKEYY,$jharkeyy); binmode JHARKEYY; seek(JHARKEYY,0,0);
$/=$crlf; $idemo=0; $mychunk=<JHARKEYY>; chop($mychunk);
while($idemo<59999){$idemo++; $mychunk=<JHARKEYY>; chop($mychunk);
@uparspl=split(/\^/,$mychunk); $nuparspl=@uparspl; $aun=$uparspl[3]-0;
if($aun<1){$idemo=999999;};
if($aun>0){$age[$aun]=$uparspl[4]-0; $sex[$aun]=lc($uparspl[6]);
$raceaun=lc($uparspl[5]); if($raceaun eq ""){$raceaun="u";};
$race[$aun]=$raceaun;};};
close(JHARKEYY);
###
### OPEN JHARINDX FILE.
$identifier=join('',$crlfpss,$search[1]); $searchchunk=$search[1];
$jharindx="jharindx.txt"; $sizejhar= -s $jharindx ;
open(JHARINDX,$jharindx); binmode JHARINDX; seek(JHARINDX,0,0);
$/=$identifier; $mychunk=<JHARINDX>; $tellmy=tell(JHARINDX);
###
### EXAMINE NEXT 300KB OF JHARINDX FILE FOR CASE NUMBERS.
seek(JHARINDX,$tellmy,0); read(JHARINDX,$scalar,300000);
@chkspl=split(/$crlfpss/,$scalar); $nchkspl=@chkspl; $ichkspl=-1;
while($ichkspl<$nchkspl){$ichkspl++; $linebase=$chkspl[$ichkspl];
@srchht=split(/$searchchunk/,$linebase); $nsrchht=@srchht;
@linspl=split(/$bksp/,$linebase); $nlinspl=@linspl; $jlinspl=0;
while($jlinspl<$nlinspl){$jlinspl++; $linepiece=$linspl[$jlinspl];
###
### COLLECT NEXT AUTOPSY NUMBER.
if($jlinspl<$nlinspl){$linenum=$linepiece-0;
if(($ichkspl<1)||($nsrchht>1)){$aunhit[$linenum]=1;};};
###
### STOP WHEN INDEX TERMS RUN OUT.
if(($ichkspl>1)&&($nsrchht<2)){$ichkspl=2*$nchkspl;};};};
###
### COUNT NUMBER OF HITS.
$nrhit=0; $iaunhit=0;
while($iaunhit<50001){$iaunhit++;
if($aunhit[$iaunhit]>0){$nrhit++; $aunhit[$iaunhit]=$nrhit;
$thishit[$nrhit]=$iaunhit;};};
###
### CLOSE JHARINDX FILE.
close(JHARINDX);
###
### HEADER FOR CASE NUMBERS.
$prln="\n<br><br><big><b>Raw Autopsy Numbers ($nrhit total): ";
print $prln; print JHARRPRT $prln;
$ithishit=0;
###
### LIST CASE NUMBERS.
while($ithishit<$nrhit){$ithishit++; $authishit=$thishit[$ithishit];
$prln=" $authishit "; print $prln; print JHARRPRT $prln;};
$prln="\n</b></big> "; print $prln; print JHARRPRT $prln;
###
### OPEN UPRIGHT FILE, $jharuprt="jharuprt.txt".
$jharuprt="jharuprt.txt"; $sizeuprt= -s $jharuprt;
open(JHARUPRT,$jharuprt); binmode JHARUPRT; seek(JHARUPRT,0,0);
$iseekr=0; $multseeknr=5;
###
### SKIP THROUGH UPRIGHT RILE IN CHUNKS OF 10KB.
while($iseekr<4300){$iseekr++; seek(JHARUPRT,$multseeknr,0);
read(JHARUPRT,$scalar,10150);
@uparspl=split(/$crlfpsfv/,$scalar); $nuparspl=@uparspl; $iuparspl=0;
while($iuparspl<($nuparspl-1)){$iuparspl++;
$uparspli=$uparspl[$iuparspl]; $lnuparspli=length($uparspli);
if($lnuparspli>10){$subi=substr($uparspli,0,5); $isub=$subi-0;
if($isub>0){$casepoint[$isub]=$multseeknr;};};};
$multseeknr=$multseeknr+10000;};
###
### ASSEMBLE AUTOPSY CASE HEADER.
seek(JHARUPRT,0,0); $irhit=0;
while($irhit<$nrhit){$irhit++; $iaunhit=$thishit[$irhit];
$aun=$iaunhit; $aunr=$iaunhit; $excludecase=0; $excldemo=0;
$multseeknr=$casepoint[$iaunhit]; $paun=100000+$iaunhit;
$qaun=substr($paun,1,5); $crlfpsfvqaun=join('',$crlfpsfv,$qaun);
$ithishit=$irhit; $icrspl=0;
###
### PRINT AUTOPSY NUMBER.
$prln1="\n<br><br><big><b> $irhit. Autopsy: $crlfpsfvqaun, ";
$ageaunr=$age[$aunr]; $sexaunr=$sex[$aunr]; $ucsexaunr=uc($sexaunr);
$raceaunr=$race[$aunr]; $ucraceaunr=uc($raceaunr);
###
### PRINT AUTOPSY AGE, RACE, SEX.
$prln2= "Age: $ageaunr, Race: $ucraceaunr, Sex: $ucsexaunr.";
###
### ERROR MESSAGES FOR EXCLUSION BY DEMOGRAPHICS.
###
### ERROR MESSAGE FOR LOWER BOUND AGE.
if($lowerage>$ageaunr){$prln3=" LOWER AGE EXCLUDED.";
$excludecase=1; $excldemo=1;};
###
### ERROR MESSAGE FOR UPPER BOUND AGE.
if($upperage<$ageaunr){$prln4=" UPPER AGE EXCLUDED.";
$excludecase=1; $excldemo=1;};
###
### ERROR MESSAGE FOR LOWER BOUND AUTOPSY NUMBER.
if($loweraun>$aunr){$prln5=" LOWER AUTOPSY NUMBER EXCLUDED.";
$excludecase=1; $excldemo=1;};
###
### ERROR MESSAGE FOR UPPER BOUND AUTOPSY NUMBER.
if($upperaun<$aunr){$prln6=" UPPER AUTOPSY NUMBER EXCLUDED.";
$excludecase=1; $excldemo=1;};
###
### ERROR MESSAGE FOR EXCLUDED SEX.
if($exclsx ne "x"){if($exclsx eq $sexaunr){$prln7=" SEX EXCLUDED.";
$excludecase=1; $excldemo=1;};};
###
### ERROR MESSAGE FOR EXCLUDED RACE.
if($exclrc ne "u"){if($exclrc eq $raceaunr){$prln8=" RACE EXCLUDED.";
$excludecase=1; $excldemo=1;};};
$prln9="</b></big>";
###
### SEEK HIT AUTOPSY CASE FROM UPRIGHT FILE.
seek(JHARUPRT,$multseeknr,0); read(JHARUPRT,$scalar,15000);
@xparspl=split(/$crlfpsfvqaun/,$scalar); $nxparspl=@uparspl; $ixparspl=0;
$thatcase=$xparspl[1]; @thatspl=split(/$crlfpsfv/,$thatcase);
$aurpt=$thatspl[0]; $lcaurpt=lc($aurpt);
###
### HIT ON CASE NUMBER.
@crspl=split(/$crlf/,$aurpt); $ncrspl=@crspl;
###
### INITIALIZE LINE NUMBER INDEX.
$icrspl=-1;
while($icrspl<$ncrspl){$icrspl++; $isearchw=0;
while($isearchw<$nsearch){$isearchw++;
$linhit[$icrspl][$isearchw]=0;};};
###
### ITERATE LINE-BY-LINE.
$icrspl=0;
while($icrspl<$ncrspl){$icrspl++; $crspli=$crspl[$icrspl];
$xcrspli=$crspli; $lccrspli=lc($crspli); $isearch=0;
###
### HIGHLIGHT SEARCH WORDS.
while($isearch<$nsearch){$isearch++; $search1=$search[$isearch];
@lnspl=split(/$search1/,$lccrspli); $nlnspl=@lnspl;
if($nlnspl>1){$xcrspli="<big><b>$crspli</b></big>";
$linhit[$icrspl][$isearch]=1;};};
###
### SET UP PRINT LINE.
$prlbl[$icrspl]="\n<br> $xcrspli ";};
###
### DETECT MISSING WORDS.
$exclmiss=0; $isearchw=0;
while($isearchw<$nsearch){$isearchw++; $icrspl=0; $scrspl=0;
while($icrspl<$ncrspl){$icrspl++;
if($linhit[$icrspl][$isearchw]==1){$scrspl++;};};
if($scrspl<1){$exclmiss=1;};};
if($exclmiss>0){$prlna="<big><b> MISSING WORD EXCLUDED.</b></big>";
$excludecase=1;};
###
### CALCULATE LINE DISTANCES.
$excldist=1; if($exclmiss<1){$linxz=0; $excldist=0;
if($nsearch>1){$excldist=1; $isearchw=0;
while($isearchw<$nsearch){$isearchw++; $linxi=999999; $icrspl=0;
while($icrspl<$ncrspl){$icrspl++;
if($linhit[$icrspl][$isearchw]==1){$jsearchw=$isearchw;
if($jsearchw<$nsearch){
while($jsearchw<$nsearch){$jsearchw++; $jcrspl=0;
while($jcrspl<$ncrspl){$jcrspl++;
if($linhit[$jcrspl][$jsearchw]==1){$dcrspl=$icrspl-$jcrspl;
if($dcrspl<0){$ecrspl=-$dcrspl; $dcrspl=$ecrspl;};
if($dcrspl<$linxi){$linxi=$dcrspl;};};};};
if($linxi>$linxz){$linxz=$linxi;};};};};};
if($linxz<$linedistmax){$excldist=0;};
if($excldist>0){$prlnb="<big><b> LINE DISTANCE EXCLUDED.</b></big>";
$excludecase=1;};};};
###
### PRINT UNEXCLUDED AUTOPSY, LINE-BY-LINE.
if($showsw>0){
print $prln1; print JHARRPRT $prln1;
print $prln2; print JHARRPRT $prln2;
if($lowerage>$ageaunr){
print $prln3; print JHARRPRT $prln3;};
if($upperage<$ageaunr){$prln4=" UPPER AGE EXCLUDED.";
print $prln4; print JHARRPRT $prln4;};
if($loweraun>$aunr){$prln5=" LOWER AUTOPSY NUMBER EXCLUDED.";
print $prln5; print JHARRPRT $prln5;};
if($upperaun<$aunr){$prln6=" UPPER AUTOPSY NUMBER EXCLUDED.";
print $prln6; print JHARRPRT $prln6;};
if($exclsx ne "x"){if($exclsx eq $sexaunr){$prln7=" SEX EXCLUDED.";
print $prln7; print JHARRPRT $prln7;};};
if($exclrc ne "u"){if($exclrc eq $raceaunr){$prln8=" RACE EXCLUDED.";
print $prln8; print JHARRPRT $prln8;};};
print $prln9; print JHARRPRT $prln9;
if($exclmiss>0){print $prlna; print JHARRPRT $prlna;};
if($excldist>0){print $prlnb; print JHARRPRT $prlnb;};};
if($excludecase<1){if($showsw<1){
print $prln1; print JHARRPRT $prln1;
print $prln2; print JHARRPRT $prln2;
print $prln9; print JHARRPRT $prln9;};
###
### NEXT INCLUDED AUTOPSY. PRINT INCLUSION COUNT.
$nshowaut++; $icrspl=0;
$prln=" <big><b> INCLUSION COUNT: $nshowaut </b></big> ";
print $prln; print JHARRPRT $prln;
###
### PRINT TEXT OF INCLUDED AUTOPSY REPORT.
while($icrspl<$ncrspl){$icrspl++; $crspli=$crspl[$icrspl];
$prln=$prlbl[$icrspl]; print $prln; print JHARRPRT $prln;};};};
###
### CLOSE JHARUPRT REPORT FILE.
close(JHARUPRT);
###
### END JOB.
$prln="\n<br><hr> Last modified: 6/2/2006, G. William Moore, MD, PhD.";
print $prln; print JHARRPRT $prln;
$prln="\n <br></body></html>\n\n";
print $prln; print JHARRPRT $prln;
close(JHARRPRT); exit;
JHARINDX ; GWMOORE - INPUT JHAR CASES;14MAY06 8:04AM
ENTRY S BK=" ",UA="^",PSG="#" ;
; INITIALIZE PUNCTUATIONS, BLANKS.
S PUNC="0123456789~`!@#$%^&*()_+-={}[]|\:;""'<,>.?/" ;
S BLNK=" " ;
; INITIALIZE UPPERCASE, LOWERCASE LETTERS.
S UC="ABCDEFGHIJKLMNOPQRSTUVWXYZ",LC="abcdefghijklmnopqrstuvwxyz" ;
S UCPC=UC_PUNC,LCBK=LC_BLNK ;
; INITIALIZE FILENAME, AUTOPSY NUMBER.
S FILENAME="jharuprt.txt",AUN=0 ;
; OPEN INPUT FILE, FILENAME="jharuprt.txt".
OPENF C 5 O 5:("FN":FILENAME,"FA":0) U 5 S $ZDS=0 ;
; READ THE NEXT LINE FROM INPUT FILE, jharuprt.txt.
READL U 5 R X U 0 S LINE=X S FSL=$E(LINE,1,1) ;
; IF THE FIRST LINE CONTAINS #, THEN UPDATE AUTOPSY NUMBER, AUN.
I (FSL=PSG) S AUN=+$E(LINE,6,10) U 0 W !,AUN G READL ;
; OTHERWISE, DROP TO LOWERCASE, AND CHANGE PUNCTUATION TO BLANKS.
S TRL=$TR(LINE,UCPC,LCBK) S LBK=$L(TRL,BK),IBK=0 ;
; EXAMINE EACH STRING BOUNDED BY BLANKS.
IBK S IBK=IBK+1 G:(IBK>LBK) READL S PBK=$P(TRL,BK,IBK),LPB=$L(PBK) ;
; DISCARD WORDS LESS THAN 3 LETTERS, DISCARD BARRIER WORDS.
G:(LPB<3) IBK G:$D(^JHARISBW(PBK)) IBK ;
; UPDATE INDEX GLOBAL, ^JHARINDX(PBK,AUN).
U 0 W BK,PBK S ^JHARINDX(PBK,AUN)="" G IBK ;
; EXECUTION COMPLETE ;
EXIT Q ;
JHAROUTP ; GWMOORE - OUTPUT JHAR CASES;14MAY06 8:05PM
ENTRY S BK=" ",UA="^",PSG="#",PSBK="### " ;
; INITIALIZE OUTPUT FILENAME, jharindx.txt.
S FILENAME="jharindx.txt",READO=-999999 ;
; OPEN OUTPUT FILE, FILENAME="jharindx.txt".
OPENF C 5 O 5:("FN":FILENAME,"FA":2) U 5 S $ZDS=0 ;
; READ NEXT INDEX WORD.
READO S READO=$O(^JHARINDX(READO)) G:(READO="") EXIT S READP=-999999 ;
U 5 W !,PSBK,READO,BK U 0 W !,PSBK,READO,BK ;
; READ NEXT AUTOPSY NUMBER FOR THAT INDEX WORD.
READP S READP=$O(^JHARINDX(READO,READP)) G:(READP="") READO ;
; WRITE INDEX WORD TO OUTPUT FILE.
U 5 W READP,BK ;
; EXECUTION COMPLETE ;
EXIT Q ;