#!/bin/ksh
#
# display the series list for a single patient id
#
# input arguments:
#     image directory
#     patient/exam DICOM directory (such as p29030/e29031)
#     id (such as 1816)
#
# output sent to "sort -n" and then redirected to a text file such as:
#     dicom_serieslist
#
# KLP
# 5/31/06
#
SeriesNumber="0020,0011"
SeriesDescription="0008,103e"
here=$PWD
imagedir=$1
edir=$2
id=$3
cd $imagedir
sdir=`ls $edir`
for series in $sdir
do
    f1=`ls $edir/$series/*.1`
    line=`$here/dcmdump $f1 +P $SeriesNumber +E`
    sno=`echo $line | tr '[' '\011' | tr ']' '\011' | cut -f2`
    line=`$here/dcmdump $f1 +P $SeriesDescription +E`
# quote $line variable to keep all spaces
    descr=`echo "$line" | tr '[' '\011' | tr ']' '\011' | tr ' ' '_' | cut -f2`
    nimg=`ls -1 $edir/$series/i* | wc -l`
    if (test $sno -lt 10000)
        then
        echo $id $sno $descr $nimg $edir/$series | awk '{printf "%05ld  %04ld %-43.43s %4ld %-65.65s\n", $1, $2, $3, $4, $5}'
    else
        echo $id $sno $descr $nimg $edir/$series | awk '{printf "%05ld %05ld %-43.43s %4ld %-65.65s\n", $1, $2, $3, $4, $5}'
    fi
done
cd $here
