53. EPMO Open Source Coordination Office Redaction File Detail Report

Produced by Araxis Merge on 6/5/2018 10:24:15 AM Central Daylight Time. See www.araxis.com for information about Merge. This report uses XHTML and CSS2, and is best viewed with a modern standards-compliant browser. For optimum results when printing this report, use landscape orientation and enable printing of background images and colours in your browser.

53.1 Files compared

# Location File Last Modified
1 patch_205_build_9.zip\Java\VistaImagingDataSourceProvider\main\src\java\gov\va\med\imaging\vistaimagingdatasource\dicom\importer OrderDAO.java Wed May 30 14:35:28 2018 UTC
2 patch_205_build_9.zip\Java\VistaImagingDataSourceProvider\main\src\java\gov\va\med\imaging\vistaimagingdatasource\dicom\importer OrderDAO.java Mon Jun 4 20:45:48 2018 UTC

53.2 Comparison summary

Description Between
Files 1 and 2
Text Blocks Lines
Unchanged 2 1564
Changed 1 2
Inserted 0 0
Removed 0 0

53.3 Comparison options

Whitespace
Character case Differences in character case are significant
Line endings Differences in line endings (CR and LF characters) are ignored
CR/LF characters Not shown in the comparison detail

53.4 Active regular expressions

No regular expressions were active.

53.5 Comparison detail

  1   /**
  2    * 
  3     Package:  MAG - Vis tA Imaging
  4     WARNING:  Per VHA D irective 2 004-038, t his routin e should n ot be modi fied.
  5     Date Cre ated: Nov,  2009
  6     Site Nam e:  Washin gton OI Fi eld Office , Silver S pring, MD
  7       Developer:     PII
  8     Descript ion: DICOM  Study cac he manager . Maintain s the cach e of study  instances
  9                                and  expires o ld studies  after 15  minutes. 
  10  
  11           ;;  +-------- ---------- ---------- ---------- ---------- ---------- ---------- +
  12           ;;  Property  of the US  Government .
  13           ;;  No permis sion to co py or redi stribute t his softwa re is give n.
  14           ;;  Use of un released v ersions of  this soft ware requi res the us er
  15           ;;   to execu te a writt en test ag reement wi th the Vis tA Imaging
  16           ;;   Developm ent Office  of the De partment o f Veterans  Affairs,
  17           ;;   telephon e (301) 73 4-0100.
  18           ;;
  19           ;;  The Food  and Drug A dministrat ion classi fies this  software a s
  20           ;;  a Class I I medical  device.  A s such, it  may not b e changed
  21           ;;  in any wa y.  Modifi cations to  this soft ware may r esult in a n
  22           ;;  adulterat ed medical  device un der 21CFR8 20, the us e of which
  23           ;;  is consid ered to be  a violati on of US F ederal Sta tutes.
  24           ;;  +-------- ---------- ---------- ---------- ---------- ---------- ---------- +
  25  
  26    */
  27  
  28   package go v.va.med.i maging.vis taimagingd atasource. dicom.impo rter;
  29  
  30   import gov .va.med.im aging.core .interface s.exceptio ns.Connect ionExcepti on;
  31   import gov .va.med.im aging.core .interface s.exceptio ns.MethodE xception;
  32   import gov .va.med.im aging.exch ange.busin ess.Patien t;
  33   import gov .va.med.im aging.exch ange.busin ess.dicom. importer.D iagnosticC ode;
  34   import gov .va.med.im aging.exch ange.busin ess.dicom. importer.O rder;
  35   import gov .va.med.im aging.exch ange.busin ess.dicom. importer.O rderFilter ;
  36   import gov .va.med.im aging.exch ange.busin ess.dicom. importer.O rderingPro vider;
  37   import gov .va.med.im aging.exch ange.busin ess.dicom. importer.P rocedure;
  38   import gov .va.med.im aging.exch ange.busin ess.dicom. importer.P rocedureMo difier;
  39   import gov .va.med.im aging.exch ange.busin ess.dicom. importer.R econciliat ion;
  40   import gov .va.med.im aging.exch ange.busin ess.dicom. importer.S econdaryDi agnosticCo de;
  41   import gov .va.med.im aging.exch ange.busin ess.dicom. importer.S eries;
  42   import gov .va.med.im aging.exch ange.busin ess.dicom. importer.S tatusChang eDetails;
  43   import gov .va.med.im aging.exch ange.busin ess.dicom. importer.S tudy;
  44   import gov .va.med.im aging.exch ange.busin ess.storag e.StorageS erverConfi guration;
  45   import gov .va.med.im aging.exch ange.busin ess.storag e.exceptio ns.Creatio nException ;
  46   import gov .va.med.im aging.exch ange.busin ess.storag e.exceptio ns.Retriev alExceptio n;
  47   import gov .va.med.im aging.url. vista.Stri ngUtils;
  48   import gov .va.med.im aging.url. vista.Vist aQuery;
  49   import gov .va.med.im aging.vist aimagingda tasource.c ommon.Vist aSessionFa ctory;
  50  
  51   import jav a.text.Par seExceptio n;
  52   import jav a.text.Sim pleDateFor mat;
  53   import jav a.util.Arr ayList;
  54   import jav a.util.Cal endar;
  55   import jav a.util.Dat e;
  56   import jav a.util.Has hMap;
  57   import jav a.util.Lin kedHashMap ;
  58   import jav a.util.Lis t;
  59  
  60   import org .apache.lo gging.log4 j.LogManag er;
  61   import org .apache.lo gging.log4 j.Logger;
  62  
  63   import sun .font.Crea tedFontTra cker;
  64  
  65   public cla ss OrderDA O extends  BaseImport erDAO<Orde r>
  66   {
  67           pr ivate stat ic final S tring UNRE GISTERED =  "";
  68           pr ivate stat ic final S tring EXAM INED = "EX AMINED";
  69           pr ivate stat ic final S tring COMP LETE = "CO MPLETE";
  70           pr ivate stat ic final S tring WAIT ING_FOR_EX AM = "WAIT ING FOR EX AM";
  71  
  72           pr otected Lo gger radio logyRPCLog ger = LogM anager.get Logger("Ra diologyRPC ");
  73  
  74           pr ivate stat ic String  GET_PATIEN T_ORDERS =  "MAGV GET  PAT ORDER S";
  75           pr ivate stat ic String  CREATE_RAD IOLOGY_ORD ER = "MAGV  RAD EXAM  ORDER";
  76           pr ivate stat ic String  REGISTER_O RDER = "MA GV RAD EXA M REGISTER ";
  77           pr ivate stat ic String  STATUS_EXA MINED = "M AGV RAD ST AT EXAMINE D";
  78           pr ivate stat ic String  STATUS_EXA M_COMPLETE  = "MAGV R AD STAT CO MPLETE";
  79           //
  80           //  Construct or
  81           //
  82           pu blic Order DAO(){}
  83           pu blic Order DAO(VistaS essionFact ory sessio nFactory)
  84           {
  85                    this .setSessio nFactory(s essionFact ory);
  86           }
  87           
  88           //
  89           //  Retrieve  By Criteri a methods
  90           //
  91           @O verride
  92           pu blic Vista Query gene rateFindBy CriteriaQu ery(Object  criteria)  
  93           {
  94                    Orde rFilter fi lter = (Or derFilter) criteria;
  95                    Vist aQuery vm  = new Vist aQuery(GET _PATIENT_O RDERS);
  96                    vm.a ddParamete r(VistaQue ry.LITERAL , filter.g etDfn());
  97                    vm.a ddParamete r(VistaQue ry.LITERAL , "D");
  98                    vm.a ddParamete r(VistaQue ry.LITERAL , "v");
  99                    vm.a ddParamete r(VistaQue ry.LITERAL , "V");
  100                    vm.a ddParamete r(VistaQue ry.LITERAL , filter.g etOrderTyp e());
  101                    vm.a ddParamete r(VistaQue ry.LITERAL , "0101190 0");
  102                    vm.a ddParamete r(VistaQue ry.LITERAL , today()) ;
  103                    retu rn vm;
  104           }
  105  
  106           @O verride
  107           pu blic List< Order> tra nslateFind ByCriteria (Object cr iteria, St ring resul t) throws  RetrievalE xception
  108           {
  109                    Orde rFilter fi lter = (Or derFilter) criteria;
  110                    
  111                    if ( filter.get OrderType( ).equalsIg noreCase(" RAD"))
  112                    {
  113                             return  translate RadiologyO rders(resu lt);         
  114                    }
  115                    else
  116                    {
  117                             return  translate NonRadiolo gyOrders(r esult);      
  118                    }
  119           }
  120           
  121           pr ivate List <Order> tr anslateRad iologyOrde rs(String  result)
  122                             throws  Retrieval Exception  {
  123                    // C reate the  OrderingLo cation lis t
  124                    List <Order> or ders = new  ArrayList <Order>();
  125                    
  126                    // S plit the r esult into  lines
  127                    Stri ng[] lines  = StringU tils.Split (result, L INE_SEPARA TOR);
  128  
  129                    Stri ng[] statu sFields =  StringUtil s.Split(li nes[0], St ringUtils. BACKTICK);
  130                    if ( !"0".equal s(statusFi elds[0]))
  131                    {
  132                             throw  new Retrie valExcepti on(statusF ields[1]);
  133                    }
  134                    else
  135                    {
  136                             // Par se the res ults
  137                             for (i nt i=1; i< lines.leng th; i++)
  138                             {
  139                                      // deter mine the e xamination sIEN
  140                                      
  141                                      String[]  fields =  StringUtil s.Split(li nes[i], St ringUtils. STICK);
  142                                      Order or der = new  Order();
  143                                      order.se tSpecialty (fields[0] );
  144                                      order.se tOrderDate (fields[2] );
  145                                      order.se tOrderReas on(fields[ 3]);
  146                                      order.se tLocation( fields[4]) ;
  147                                      order.se tExamDate( fields[5]) ;
  148                                      order.se tAccession Number(fie lds[6]);
  149                                      order.se tExamStatu s(fields[7 ]);
  150                                      order.se tProcedure Id(getNull ableInt(fi elds[8]));
  151                                      order.se tProcedure Name(field s[9]);
  152                                      order.se tCaseNumbe r(fields[1 0]);
  153                                      order.se tRegistere dExamsIen( fields[11] );
  154                                      order.se tId(Intege r.parseInt (fields[12 ]));
  155                                      order.se tExaminati onsIen(get NullableIn t(fields[1 3]));
  156                                      order.se tOrderingP roviderIen (getNullab leInt(fiel ds[14]));
  157                                      order.se tOrderingL ocationIen (getNullab leInt(fiel ds[15]));
  158                                      
  159                                      // Attac h procedur e modifier s, if any
  160                                      List<Pro cedureModi fier> modi fiers = pa rseProcedu reModifier s(fields[1 6]);
  161                                      order.se tProcedure Modifiers( modifiers) ;
  162                                      
  163                                      order.se tCreditMet hod(fields [17]);
  164                                      order.se tVistaGene ratedStudy Uid(fields [18]);
  165  
  166                                      // Apply  a filter  to only al low orders  with exam  statuses  valid for  import
  167                                      if (isVa lidStatusF orImport(o rder.getEx amStatus() , order.ge tCreditMet hod()))
  168                                      {
  169                                               orders.add (order);
  170                                      }
  171                             }
  172                    }
  173  
  174                    retu rn orders;
  175           }
  176           
  177           //  Determine s whether  an order i s in a val id status  for import
  178           pr ivate bool ean isVali dStatusFor Import(Str ing examSt atus, Stri ng creditM ethod) 
  179           {
  180                    // C lean up th e exam sta tus for co mparison
  181                    exam Status = e xamStatus. trim().toU pperCase() ;
  182                    
  183                    // D etermine w hether or  not this i s a no-cre dit exam
  184                    Stri ng normali zedCreditM ethod = cr editMethod .toUpperCa se().repla ce(" ", "" );
  185                    bool ean isNoCr edit = nor malizedCre ditMethod. equals("NO CREDIT");
  186                    
  187                    // V alid statu ses for im porter are  no status  (UNREGIST ERED), WAI TING FOR E XAM, or EX AMINED,
  188                    // a s well as  COMPLETE e xams which  are No Cr edit. Any  other stat uses, such  as CANCEL LED, 
  189                    // C OMPLETE wi th other c redit meth ods, etc w ill be fil tered out.
  190                    if ( examStatus .equals(UN REGISTERED ) || 
  191                             examSt atus.equal s(WAITING_ FOR_EXAM)  || 
  192                             examSt atus.equal s(EXAMINED ) ||
  193                             (examS tatus.equa ls(COMPLET E) && isNo Credit))
  194                    {
  195                             return  true;
  196                    }
  197                    else
  198                    {
  199                             return  false;
  200                    }
  201           }
  202           
  203           pr ivate List <Order> tr anslateNon RadiologyO rders(Stri ng result)  throws Re trievalExc eption 
  204           {
  205                    // C reate the  OrderingLo cation lis t
  206                    List <Order> or ders = new  ArrayList <Order>();
  207                    
  208                    // S plit the r esult into  lines
  209                    Stri ng[] lines  = StringU tils.Split (result, L INE_SEPARA TOR);
  210                    
  211                    Stri ng[] statu sFields =  StringUtil s.Split(li nes[0], St ringUtils. BACKTICK);
  212                    if ( !"0".equal s(statusFi elds[0]))
  213                    {
  214                             throw  new Retrie valExcepti on(statusF ields[1]);
  215                    }
  216                    else
  217                    {
  218                             // Par se the res ults
  219                             for (i nt i=1; i< lines.leng th; i++)
  220                             {
  221                                      // deter mine the e xamination sIEN
  222                                      
  223                                      String[]  fields =  StringUtil s.Split(li nes[i], St ringUtils. STICK);
  224                                      Order or der = new  Order();
  225  
  226                                      order.se tSpecialty (fields[0] );
  227                                      order.se tOrderDate (fields[2] );
  228                                      order.se tOrderReas on(fields[ 3]);
  229                                      order.se tLocation( fields[4]) ;
  230                                      order.se tExamDate( fields[5]) ;
  231                                      order.se tAccession Number(fie lds[6]);
  232                                      order.se tExamStatu s(fields[7 ]);
  233                                      order.se tId(Intege r.parseInt (fields[8] ));
  234                                      order.se tProcedure Name(field s[9]);
  235                                      order.se tCaseNumbe r(fields[1 0]);
  236                                      
  237                                      Procedur e procedur e = new Pr ocedure();
  238                                      procedur e.setId(0) ;
  239                                      procedur e.setName( fields[9]) ;
  240                                      
  241                                      order.se tProcedure (procedure );
  242                                      
  243                                      // Attac h procedur e modifier s, if any
  244                                      //List<P rocedureMo difier> mo difiers =  parseProce dureModifi ers(fields [11]);
  245                                      //order. setProcedu reModifier s(modifier s);
  246                                      
  247                                      
  248                                      orders.a dd(order);
  249                    
  250   //                                 0 … Orde rType={CON }
  251   //                                 1 … Pati entDFN
  252   //                                 2 … Requ estDate
  253   //                                 3 … {}
  254   //                                 4 … {}
  255   //                                 5 … {}
  256   //                                 6 … Acce ssionNumbe r =SiteNum ber_”-GMR- “_CaseNumb er
  257   //                                 7 … Orde rStatus
  258   //                                 8 … Cons ultOrderDF N (enry in  Consult/S tatus File  (#123)
  259   //                                 9… Consu ltTitle
  260   //                                 10… Clin icalProced ure
  261  
  262                             }
  263                    }
  264                    
  265                    retu rn orders;
  266           }
  267  
  268           pr ivate int  getNullabl eInt(Strin g stringVa lue) 
  269           {
  270                    int  intValue =  -1;
  271                    if ( stringValu e != null  && !string Value.trim ().equals( UNREGISTER ED))
  272                    {
  273                             try
  274                             {
  275                                      intValue  = Integer .parseInt( stringValu e);
  276                             }
  277                             catch( Exception  e)
  278                             {
  279                                      logger.d ebug("Coul dn't parse  integer v alue from  string: "  + stringVa lue);
  280                             }
  281                    }
  282                    retu rn intValu e;
  283           }
  284  
  285           //
  286           //  Create Or der
  287           //
  288           pu blic Order  createRad iologyOrde r(Reconcil iation rec onciliatio n) throws  MethodExce ption, Con nectionExc eption
  289           {
  290                    Pati ent patien t = reconc iliation.g etPatient( );
  291                    Stud y study =  reconcilia tion.getSt udy();
  292                    Orde r order =  reconcilia tion.getOr der();
  293                    
  294                    Hash Map<String , String>  clinicalHi storyData  = getClini calHistory Data(study );
  295                    // l og the par ameter val ues
  296                    Stri ngBuilder  builder =  new String Builder();
  297                    buil der.append ("Create O rder (" +  CREATE_RAD IOLOGY_ORD ER + ") Pa rameters\n ");
  298                    buil der.append ("-------- ---------- ---------- ---------- -------\n" );
  299                    buil der.append ("Patient  DFN: " + p atient.get Dfn() + "\ n");
  300                    buil der.append ("Imaging  Location I EN: " + or der.getPro cedure().g etImagingL ocationId( ) + "\n");
  301                    buil der.append ("Procedur e and Modi fier IENs:  " + getPr ocedureAnd Modifiers( order) + " \n");
  302                    buil der.append ("Study Da te: " + st udy.getStu dyDate() +  "\n");
  303                    buil der.append (UNREGISTE RED + "S\n ");
  304                    buil der.append ("Ordering  Location  IEN: " + o rder.getOr deringLoca tion().get Id() + "\n ");
  305                    buil der.append ("Ordering  Provider  IEN: " + o rder.getOr deringProv ider().get Id() + "\n ");
  306                    buil der.append ("Reason:  " + "Exam  imported f rom outsid e\n");
  307                    buil der.append ("Clinical  History D ata:\n");
  308                    
  309                    int  lineNum =  1;
  310                    for  (String hi stLine : c linicalHis toryData.v alues())
  311                    {
  312                             builde r.append("   " + line Num++ + ":  " + histL ine + "\n" );
  313                    }
  314                    logg er.info(bu ilder.toSt ring());
  315                    radi ologyRPCLo gger.info( builder.to String());
  316                    
  317                    // C all the RP C
  318                    Vist aQuery vm  = new Vist aQuery(CRE ATE_RADIOL OGY_ORDER) ;
  319                    vm.a ddParamete r(VistaQue ry.LITERAL , patient. getDfn());
  320                    vm.a ddParamete r(VistaQue ry.LITERAL , Integer. toString(o rder.getPr ocedure(). getImaging LocationId ()));
  321                    vm.a ddParamete r(VistaQue ry.LITERAL , getProce dureAndMod ifiers(ord er));
  322                    vm.a ddParamete r(VistaQue ry.LITERAL , study.ge tStudyDate ());
  323                    vm.a ddParamete r(VistaQue ry.LITERAL , "S");
  324                    vm.a ddParamete r(VistaQue ry.LITERAL , Integer. toString(o rder.getOr deringLoca tion().get Id()));
  325                    vm.a ddParamete r(VistaQue ry.LITERAL , Integer. toString(o rder.getOr deringProv ider().get Id()));
  326                    vm.a ddParamete r(VistaQue ry.LITERAL , "Exam im ported fro m outside" );
  327                    vm.a ddParamete r(VistaQue ry.LIST, c linicalHis toryData);
  328                    
  329                    Stri ng result  = executeR PC(vm);
  330                    
  331                    radi ologyRPCLo gger.info( "Create Or der Result s\n------- ---------- ---------- ---------- --------\n " + result );
  332                    retu rn transla teCreate(r econciliat ion.getOrd er(), resu lt);
  333           }
  334           
  335           pr ivate Hash Map<String , String>  getClinica lHistoryDa ta(Study s tudy) 
  336           {
  337                    Hash Map<String , String>  hm = new L inkedHashM ap<String,  String>() ;
  338                    
  339                    // G et the for mated date  of birth
  340                    Simp leDateForm at formatt er = new S impleDateF ormat("MMM  dd, yyyy" );
  341                    Stri ng formatt edBirthDat e = UNREGI STERED;
  342  
  343                    try
  344                    {
  345                             format tedBirthDa te = forma tter.forma t(study.ge tPatient() .getDob()) ;
  346                    }
  347                    catc h (Excepti on e)
  348                    {
  349                             logger .warn("Cou ldn't form at birthda te: " + st udy.getPat ient().get Dob());
  350                    }
  351                    
  352                    // G et the for matted Stu dy Date
  353                    Stri ng formatt edStudyDat e = getFor mattedStud yDate(stud y.getStudy Date());
  354                    Stri ng formatt edStudyTim e = getFor mattedStud yTime(stud y.getStudy Time());
  355                    
  356                    hm.p ut("1", "C LINHIST^1^  *** Origi nal Data f or Importe d Study ** *");
  357                    hm.p ut("2", "C LINHIST^2^         Pa tient Name : " + stud y.getPatie nt().getPa tientName( ));
  358                    hm.p ut("3", "C LINHIST^3^            Patient ID : " + stud y.getPatie nt().getSs n());
  359                    hm.p ut("4", "C LINHIST^4^            Birth Date : " + form attedBirth Date  + "           "  
  360                                      + "Sex:  " + study. getPatient ().getPati entSex().t oDicomStri ng());
  361                    
  362                    hm.p ut("5", "C LINHIST^5^          A ccession # : " + stud y.getAcces sionNumber ());
  363                    hm.p ut("6", "C LINHIST^6^            Study Date : " + form attedStudy Date 
  364                                      + "           " + " Study Time : " + form attedStudy Time);
  365                    
  366                    hm.p ut("7", "C LINHIST^7^    Study D escription : " + stud y.getDescr iption());
  367                    hm.p ut("8", "C LINHIST^8^  Referring  Physician : " + stud y.getRefer ringPhysic ian());
  368                    
  369                    int  counter =  9;
  370  
  371                    // G et a list  of strings  containin g series d ata
  372                    List <String> s eriesData  = getClini calHistory DataForSer ies(study) ;
  373                    
  374                    // A dd the ser ies data t o the hash map
  375                    for  (String li ne : serie sData)
  376                    {
  377                             hm.put (Integer.t oString(co unter), "C LINHIST^"  + counter  + "^ " + l ine);
  378                             counte r++;
  379                    }
  380  
  381                    retu rn hm;
  382           }
  383           
  384           pr ivate Stri ng getForm attedStudy Date(Strin g dateStri ng) 
  385           {
  386                    // D efault to  the unform atted stri ng, in cas e we can't  parse it  correctly
  387                    Stri ng formatt edStudyDat e = dateSt ring;
  388                    
  389                    try
  390                    {
  391                             Simple DateFormat  formatter  = new Sim pleDateFor mat("yyyyM Mdd");
  392                             Date s tudyDate =  formatter .parse(dat eString);
  393                             format ter = new  SimpleDate Format("MM /dd/yy");
  394                             format tedStudyDa te = forma tter.forma t(studyDat e);
  395                    }
  396                    catc h (ParseEx ception e)
  397                    {
  398                             logger .error(e);
  399                    }
  400                    
  401                    retu rn formatt edStudyDat e;
  402           }
  403           
  404           pr ivate Stri ng getForm attedStudy Time(Strin g timeStri ng) 
  405           {
  406                    // D efault to  the unform atted stri ng, in cas e we can't  parse it  correctly
  407                    Stri ng formatt edStudyTim e = timeSt ring;
  408                    
  409                    // I f the time  is empty,  set it to  one secon d after mi dnight...
  410                    if ( timeString  == null | | timeStri ng.equals( UNREGISTER ED))
  411                    {
  412                             timeSt ring = "00 0001";
  413                    }
  414                    
  415                    try
  416                    {
  417                             Simple DateFormat  formatter  = new Sim pleDateFor mat("hhmms s");
  418                             Date s tudyTime =  formatter .parse(tim eString);
  419                             format ter = new  SimpleDate Format("hh :mm:ss");
  420                             format tedStudyTi me = forma tter.forma t(studyTim e);
  421                    }
  422                    catc h (ParseEx ception e)
  423                    {
  424                             logger .error(e);
  425                    }
  426                    
  427                    retu rn formatt edStudyTim e;
  428           }
  429  
  430           pr ivate List <String> g etClinical HistoryDat aForSeries (Study stu dy) 
  431           {
  432                    // F irst, see  if all the  facilitie s are the  same
  433                    bool ean allAcq uistionInf oEqual = t rue;
  434                    
  435                    Stri ng facilit y = UNREGI STERED;
  436                    Stri ng institu tionAddres s = UNREGI STERED;
  437                    for  (int i = 0 ; i < stud y.getSerie s().size() ; i++)
  438                    {
  439                             // Get  the curre nt study
  440                             Series  series =  study.getS eries().ge t(i);
  441                             
  442                             // Fir st time th rough, ini tialize fa cility and  address.  Subsequent  times, se e if they  change
  443                             if (i= =0)
  444                             {
  445                                      facility  = series. getFacilit y() + "";
  446                                      institut ionAddress  = series. getInstitu tionAddres s() + "";
  447                             }
  448                             else
  449                             {
  450                                      facility  = facilit y + "";
  451                                      if (!fac ility.equa ls(series. getFacilit y() + ""))
  452                                      {
  453                                               allAcquist ionInfoEqu al = false ;
  454                                      }
  455                                      
  456                                      institut ionAddress  = institu tionAddres s + "";
  457                                      if (!ins titutionAd dress.equa ls(series. getInstitu tionAddres s() + ""))
  458                                      {
  459                                               allAcquist ionInfoEqu al = false ;
  460                                      }
  461                             }
  462                    }
  463  
  464                    // C reate the  line items  for each  series
  465                    List <String> s eriesDataL ist = new  ArrayList< String>();
  466                    for  (int i = 1 ; i <= stu dy.getSeri es().size( ); i++)
  467                    {
  468                             Series  series =  study.getS eries().ge t(i-1);
  469                             
  470                             // Sta rt with an  empty str ing
  471                             String  text = UN REGISTERED ;
  472                             
  473                             // If  the number  of series  is less t han 10, in dent by on e space
  474                             if (i  < 10)
  475                                      text +=  " ";
  476                             
  477                             // Add  the image  count for  the serie s
  478                             text + = "Series  " + i + ":  " + serie s.getSopIn stances(). size() + "  " + serie s.getModal ity() + "  file";
  479                             
  480                             // Add  an 's' to  'file' un less the n umber of i mages is 1 ...
  481                             if (se ries.getSo pInstances ().size()  != 1)
  482                                      text +=  "s";
  483                             
  484                             // If  we have a  series des cription,  add it...
  485                             String  descripti on = serie s.getSerie sDescripti on();
  486                             if (de scription  != null &&  !descript ion.trim() .equals(UN REGISTERED ))
  487                             {
  488                                      text +=  ", descrip tion: " +  series.get SeriesDesc ription();
  489                             }
  490                             
  491                             series DataList.a dd(text);
  492                             
  493                    }
  494                    
  495                    // A dd the acq uisition l ocation an d address  if it's th e same on  all series , and not  null 
  496                    // o r empty
  497                    if ( allAcquist ionInfoEqu al && faci lity != nu ll && !fac ility.trim ().equals( UNREGISTER ED))
  498                    {
  499                             String  text = "A cquisition  site: " +  facility;
  500                             
  501                             if (in stitutionA ddress !=  null && !i nstitution Address.tr im().equal s(UNREGIST ERED))
  502                             {
  503                                      text +=  "    Addre ss: " + in stitutionA ddress;
  504                             }
  505                             
  506                             series DataList.a dd(text);
  507                    }
  508                    
  509                    retu rn seriesD ataList;
  510           }
  511           
  512           pr ivate Stri ng getProc edureAndMo difiers(Or der order)  
  513           {
  514                    // A dd the pro cedure IEN
  515                    Stri ng result  = Integer. toString(o rder.getPr ocedure(). getId());
  516                    
  517                    // I f there ar e any modi fiers, add  them
  518                    if ( order.getP rocedureMo difiers()  != null &&  order.get ProcedureM odifiers() .size() >  0)
  519                    {
  520                             for (P rocedureMo difier mod ifier : or der.getPro cedureModi fiers())
  521                             {
  522                                      result + = "^" + mo difier.get Id();
  523                             }
  524                    }
  525                    
  526                    retu rn result;
  527                    
  528           }
  529           
  530           //
  531           //  Translate  create...  
  532           //
  533           pu blic Order  translate Create(Ord er order,  String res ult) throw s Creation Exception
  534           {
  535                    // S plit the r esult into  lines
  536                    Stri ng[] lines  = StringU tils.Split (result, L INE_SEPARA TOR);
  537  
  538                    if ( !lines[0]. startsWith ("-"))
  539                    {
  540                             // The  first lin e did not  start with  a minus s ign, so th ere was no  error. Pa rse the 
  541                             // IEN  into an i nt and set  it on the  order
  542                             int or derId = In teger.pars eInt(lines [0]);
  543                             order. setId(orde rId);
  544                    }
  545                    else
  546                    {
  547                             // The re was an  error. Thr ow the ent ire result  as the ex ception me ssage
  548                             throw  new Creati onExceptio n(result);
  549                    }
  550  
  551                    retu rn order;
  552  
  553           }
  554           
  555           //
  556           //  Register  Order
  557           //
  558           pu blic Order  registerO rder(Recon ciliation  reconcilia tion, int  hospitalLo cationId)  throws Met hodExcepti on, Connec tionExcept ion
  559           {
  560                    Stud y study =  reconcilia tion.getSt udy();
  561                    Orde r order =  reconcilia tion.getOr der();
  562                    
  563                    int  orderingLo cationId =  order.get OrderingLo cationIen( );
  564  
  565                    // l og the par ameter val ues
  566                    Stri ngBuilder  builder =  new String Builder();
  567                    buil der.append ("Register  Order ("  + REGISTER _ORDER + " ) Paramete rs\n");
  568                    buil der.append ("-------- ---------- ---------- -----\n");
  569                    buil der.append ("Order IE N: " + ord er.getId()  + "\n");
  570                    buil der.append ("Study Da te and Tim e: " + get StudyDateT ime(study)  + "\n");
  571                    buil der.append ("Flags:\n ");
  572                    buil der.append (" 1:" + " PRINCLIN^^ " + hospit alLocation Id + "\n") ;
  573                    buil der.append (" 2:" + " FLAGS^^D\n ");
  574                    logg er.info(bu ilder.toSt ring());
  575                    radi ologyRPCLo gger.info( builder.to String());
  576                    
  577                    Vist aQuery vm  = new Vist aQuery(REG ISTER_ORDE R);
  578                    vm.a ddParamete r(VistaQue ry.LITERAL , Integer. toString(o rder.getId ()));
  579                    vm.a ddParamete r(VistaQue ry.LITERAL , getStudy DateTime(s tudy));
  580                    
  581                    Hash Map<String , String>  hm = new L inkedHashM ap<String,  String>() ;
  582                    hm.p ut("1", (" PRINCLIN^^ " + hospit alLocation Id));
  583                    hm.p ut("2", "F LAGS^^D");
  584                    
  585                    vm.a ddParamete r(VistaQue ry.LIST, h m);
  586                    Stri ng result  = executeR PC(vm);
  587                              
  588                    radi ologyRPCLo gger.info( "Register  Order Resu lts\n----- ---------- ---------- ---------- ---------- \n" + resu lt);
  589                    retu rn transla teRegister Order(orde r, result) ;
  590           }
  591           
  592           pr ivate Stri ng getStud yDateTime( Study stud y) 
  593           {
  594                    Stri ng studyTi me = study .getStudyT ime();
  595                    
  596                    if ( studyTime  == null ||  studyTime .trim().eq uals(UNREG ISTERED))
  597                    {
  598                             // If  the study  time is nu ll or empt y, set it  to one sec ond after  midnight
  599                             studyT ime = "000 001";
  600                    }
  601                    else
  602                    {
  603                             // Att empt to sp lit on the  . delimit ing millis econds. Us e the firs t piece af ter
  604                             // the  split
  605                             String [] timePar ts = Strin gUtils.Spl it(studyTi me, ".");
  606                             studyT ime = time Parts[0];
  607                             
  608                             // If  the study  time after  splitting  is empty  or all zer os, 
  609                             // set  it to one  second af ter midnig ht
  610                             if (st udyTime.eq uals(UNREG ISTERED) | | studyTim e.equals(" 0") ||
  611                                               studyTime. equals("00 ") || stud yTime.equa ls("000")  ||
  612                                               studyTime. equals("00 00") || st udyTime.eq uals("0000 0") ||
  613                                      studyTim e.equals(" 000000"))
  614                             {
  615                                      studyTim e = "00000 1";
  616                             }
  617                    }
  618                    
  619                    retu rn study.g etStudyDat e() + stud yTime;
  620           }
  621           
  622           pu blic Order  translate RegisterOr der(Order  order, Str ing result ) throws M ethodExcep tion
  623           {
  624                    // S plit the r esult into  lines
  625                    Stri ng[] lines  = StringU tils.Split (result, L INE_SEPARA TOR);
  626  
  627                    Stri ng[] statu sFields =  StringUtil s.Split(li nes[0], St ringUtils. BACKTICK);
  628                    
  629                    // I f there we re errors,  throw an  exception
  630                    if ( !"0".equal s(statusFi elds[0]))
  631                    {
  632                             throw  new Method Exception( result);
  633                    }
  634  
  635                    // O therwise,  parse out  the data f rom the re sult line. ..
  636                    // S ample succ essful ret urn:
  637                    // 0 `1
  638                    // 1 211|688949 6.9998|1|3 44|050311- 344|201105 030001-050 0
  639                    
  640                    Stri ng[] field s = String Utils.Spli t(lines[1] , StringUt ils.STICK) ;
  641                    orde r.setRegis teredExams Ien(fields [1]);
  642                    orde r.setExami nationsIen (Integer.p arseInt(fi elds[2]));
  643                    orde r.setAcces sionNumber (fields[4] );
  644                    orde r.setExamD ate(fields [5]);
  645  
  646                    retu rn order;
  647           }
  648  
  649           //
  650           //  set order  to Examin ed
  651           //
  652           pu blic Order  setOrderE xamined(Re conciliati on reconci liation, S tring tech nicianDuz,  String pl aceId) thr ows Method Exception,  Connectio nException
  653           {
  654                    Stud y study =  reconcilia tion.getSt udy();
  655                    Orde r order =  reconcilia tion.getOr der();
  656                    Pati ent patien t = reconc iliation.g etPatient( );
  657                    
  658                    // l og the par ameter val ues
  659                    Stri ngBuilder  builder =  new String Builder();
  660                    buil der.append ("Set Orde r Examined  (" + STAT US_EXAMINE D + ") Par ameters\n" );
  661                    buil der.append ("-------- ---------- ---------- ---------- -------\n" );
  662                    buil der.append ("Patient  DFN: " + p atient.get Dfn() + "\ n");
  663                    buil der.append ("Register ed Exams I EN: " + or der.getReg isteredExa msIen() +  "\n");
  664                    buil der.append ("Examinat ions IEN:  " + order. getExamina tionsIen()  + "\n");
  665                    buil der.append ("Technici an DUZ: "  + technici anDuz + "\ n");
  666                    buil der.append ("Division  Number" +  placeId +  "\n");
  667                    buil der.append ("Imaging  Type Id: "  + order.g etProcedur e().getIma gingTypeId () + "\n") ;
  668                    logg er.info(bu ilder.toSt ring());
  669                    radi ologyRPCLo gger.info( builder.to String());
  670  
  671                    Vist aQuery vm  = new Vist aQuery(STA TUS_EXAMIN ED); 
  672                    vm.a ddParamete r(VistaQue ry.LITERAL , patient. getDfn());
  673                    vm.a ddParamete r(VistaQue ry.LITERAL , order.ge tRegistere dExamsIen( ));
  674                    vm.a ddParamete r(VistaQue ry.LITERAL , Integer. toString(o rder.getEx aminations Ien()));
  675                    vm.a ddParamete r(VistaQue ry.LITERAL , technici anDuz);
  676                    vm.a ddParamete r(VistaQue ry.LITERAL , placeId) ;
  677                    vm.a ddParamete r(VistaQue ry.LITERAL , Integer. toString(o rder.getPr ocedure(). getImaging TypeId())) ;
  678  
  679  
  680                    Stri ng result  = executeR PC(vm);
  681                    radi ologyRPCLo gger.info( "Set Order  Examined  Results\n- ---------- ---------- ---------- ---------- ----\n" +  result);
  682                    retu rn transla teSetOrder Examined(o rder, resu lt);
  683           }
  684           
  685           pu blic Order  translate SetOrderEx amined(Ord er order,  String res ult) throw s MethodEx ception
  686           {
  687                    // S plit the r esult into  lines
  688                    Stri ng[] lines  = StringU tils.Split (result, L INE_SEPARA TOR);
  689  
  690                    Stri ng[] statu sFields =  StringUtil s.Split(li nes[0], St ringUtils. BACKTICK);
  691                    if ( !"0".equal s(statusFi elds[0]))
  692                    {
  693                             throw  new Method Exception( result);
  694                    }
  695  
  696                    retu rn order;
  697           }
  698  
  699           //
  700           //  set order  to Exam C omplete
  701           //
  702           pu blic Order  setOrderE xamComplet e(Reconcil iation rec onciliatio n, String  technician Duz, Strin g placeId)  throws Me thodExcept ion, Conne ctionExcep tion
  703           {
  704                    Stud y study =  reconcilia tion.getSt udy();
  705                    Orde r order =  reconcilia tion.getOr der();
  706                    Pati ent patien t = reconc iliation.g etPatient( );
  707                    
  708                    Stri ng standar dReportNum ber = "";
  709                    Stri ng primary Diagnostic CodeId = " "; 
  710                    List <Secondary Diagnostic Code> seco ndaryDiagn osticCodes  = null; 
  711                    
  712                    // G et the sta tus change  details,  if availab le
  713                    Stat usChangeDe tails stat usChangeDe tails = or der.getSta tusChangeD etails(); 
  714                    
  715                    if ( statusChan geDetails  != null)
  716                    {
  717                             // Get  the Stand ard Report  Number
  718                             standa rdReportNu mber = sta tusChangeD etails.get StandardRe portNumber () + "";
  719  
  720                             // Get  the prima ry diagnos tic code I D, if avai lable
  721                             Diagno sticCode p rimaryDiag nosticCode  = statusC hangeDetai ls.getPrim aryDiagnos ticCode();
  722                             if (pr imaryDiagn osticCode  != null)
  723                             {
  724                                      primaryD iagnosticC odeId = In teger.toSt ring(prima ryDiagnost icCode.get Id());
  725                             }
  726                             
  727                             // Get  the list  of seconda ry diagnos tic codes,  if availa ble
  728                             second aryDiagnos ticCodes =  statusCha ngeDetails .getSecond aryDiagnos ticCodes() ;
  729                    }
  730                    
  731                    Vist aQuery vm  = new Vist aQuery(STA TUS_EXAM_C OMPLETE); 
  732                    vm.a ddParamete r(VistaQue ry.LITERAL , patient. getDfn());
  733                    vm.a ddParamete r(VistaQue ry.LITERAL , order.ge tRegistere dExamsIen( ));
  734                    vm.a ddParamete r(VistaQue ry.LITERAL , Integer. toString(o rder.getEx aminations Ien()));
  735                    vm.a ddParamete r(VistaQue ry.LITERAL , technici anDuz);
  736                    vm.a ddParamete r(VistaQue ry.LITERAL , placeId) ;
  737                    vm.a ddParamete r(VistaQue ry.LITERAL , Integer. toString(o rder.getPr ocedure(). getImaging TypeId())) ;
  738                    vm.a ddParamete r(VistaQue ry.LITERAL , standard ReportNumb er + "");
  739                    vm.a ddParamete r(VistaQue ry.LITERAL , primaryD iagnosticC odeId + "" );
  740           
  741                    // A dd the lis t of secon dary diagn ostic code s, if any
  742                    Hash Map <Strin g, String>  hm = new  HashMap <S tring, Str ing>();
  743                    if ( secondaryD iagnosticC odes != nu ll && seco ndaryDiagn osticCodes .size() >  0)
  744                    {
  745                             int co unter=0;
  746                             for (S econdaryDi agnosticCo de diagnos ticCode :  order.getS tatusChang eDetails() .getSecond aryDiagnos ticCodes() )
  747                             {
  748                                      hm.put(I nteger.toS tring(coun ter), Inte ger.toStri ng(diagnos ticCode.ge tId()));
  749                                      counter+ +;
  750                             }
  751                    }                 
  752                    vm.a ddParamete r(VistaQue ry.LIST, h m);
  753  
  754                    Stri ng result  = executeR PC(vm);
  755                    
  756                    radi ologyRPCLo gger.info( "Set Order  Exam Comp lete Resul ts\n------ ---------- ---------- ---------- ---------\ n" + resul t);
  757                    retu rn transla teSetOrder ExamComple te(order,  result);
  758           }
  759           
  760           pu blic Order  translate SetOrderEx amComplete (Order ord er, String  result) t hrows Meth odExceptio n
  761           {
  762                    // S plit the r esult into  lines
  763                    Stri ng[] lines  = StringU tils.Split (result, L INE_SEPARA TOR);
  764  
  765                    Stri ng[] statu sFields =  StringUtil s.Split(li nes[0], St ringUtils. BACKTICK);
  766                    if ( !"0".equal s(statusFi elds[0]))
  767                    {
  768                             throw  new Method Exception( result);
  769                    }
  770  
  771                    retu rn order;
  772           }
  773  
  774           pr ivate stat ic String  today()
  775           {
  776                    Stri ng DATE_FO RMAT_TODAY  = "MMddyy yy";
  777  
  778                    Cale ndar cal =  Calendar. getInstanc e();
  779                    Simp leDateForm at sdf = n ew SimpleD ateFormat( DATE_FORMA T_TODAY);
  780                    retu rn sdf.for mat(cal.ge tTime());
  781           }
  782  
  783   }