290. EPMO Open Source Coordination Office Redaction File Detail Report

Produced by Araxis Merge on 4/5/2017 4:22:06 PM 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.

290.1 Files compared

# Location File Last Modified
1 C:\working_scrub\Unredacted\eHX Code Base\eHX_Bld2_Source Code_CIF_2017-02-14\NHIN_adapter\SpecProcessor\src\main\java\gov\va\ccd\components\impl MedicationsComponent.java Fri Feb 10 15:41:44 2017 UTC
2 eHX-CIF.zip\eHX-CIF\eHX Code Base\eHX_Bld2_Source Code_CIF_2017-02-14\NHIN_adapter\SpecProcessor\src\main\java\gov\va\ccd\components\impl MedicationsComponent.java Mon Apr 3 14:39:04 2017 UTC

290.2 Comparison summary

Description Between
Files 1 and 2
Text Blocks Lines
Unchanged 5 3050
Changed 4 10
Inserted 0 0
Removed 0 0

290.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

290.4 Active regular expressions

No regular expressions were active.

290.5 Comparison detail

  1   package go v.va.ccd.c omponents. impl;
  2  
  3   import gov .va.ccd.se rvice.util .Utils;
  4   import gov .va.ccd.se rvice.valu e.object.S ectionValu eObject;
  5   import gov .va.ccd.se rvice.valu e.objects. impl.ItemO bject;
  6   import gov .va.ccd.se rvice.valu e.objects. impl.Medic ationsVO;
  7  
  8   import org .apache.co mmons.coll ections.Co llectionUt ils;
  9   import org .apache.co mmons.lang 3.StringUt ils;
  10   import org .eclipse.e mf.common. util.EList ;
  11   import org .openhealt htools.mdh t.uml.cda. Act;
  12   import org .openhealt htools.mdh t.uml.cda. AssignedEn tity;
  13   import org .openhealt htools.mdh t.uml.cda. Author;
  14   import org .openhealt htools.mdh t.uml.cda. Consumable ;
  15   import org .openhealt htools.mdh t.uml.cda. Criterion;
  16   import org .openhealt htools.mdh t.uml.cda. Entry;
  17   import org .openhealt htools.mdh t.uml.cda. EntryRelat ionship;
  18   import org .openhealt htools.mdh t.uml.cda. Manufactur edProduct;
  19   import org .openhealt htools.mdh t.uml.cda. Material;
  20   import org .openhealt htools.mdh t.uml.cda. Observatio n;
  21   import org .openhealt htools.mdh t.uml.cda. Organizati on;
  22   import org .openhealt htools.mdh t.uml.cda. Participan t2;
  23   import org .openhealt htools.mdh t.uml.cda. Participan tRole;
  24   import org .openhealt htools.mdh t.uml.cda. Performer2 ;
  25   import org .openhealt htools.mdh t.uml.cda. Person;
  26   import org .openhealt htools.mdh t.uml.cda. PlayingEnt ity;
  27   import org .openhealt htools.mdh t.uml.cda. Preconditi on;
  28   import org .openhealt htools.mdh t.uml.cda. StrucDocTe xt;
  29   import org .openhealt htools.mdh t.uml.cda. SubstanceA dministrat ion;
  30   import org .openhealt htools.mdh t.uml.cda. Supply;
  31   import org .openhealt htools.mdh t.uml.cda. ccd.Contin uityOfCare Document;
  32   import org .openhealt htools.mdh t.uml.cda. ccd.Medica tionsSecti on;
  33   import org .openhealt htools.mdh t.uml.hl7. datatypes. AD;
  34   import org .openhealt htools.mdh t.uml.hl7. datatypes. ADXP;
  35   import org .openhealt htools.mdh t.uml.hl7. datatypes. ANY;
  36   import org .openhealt htools.mdh t.uml.hl7. datatypes. CD;
  37   import org .openhealt htools.mdh t.uml.hl7. datatypes. CE;
  38   import org .openhealt htools.mdh t.uml.hl7. datatypes. ED;
  39   import org .openhealt htools.mdh t.uml.hl7. datatypes. EIVL_TS;
  40   import org .openhealt htools.mdh t.uml.hl7. datatypes. ENXP;
  41   import org .openhealt htools.mdh t.uml.hl7. datatypes. II;
  42   import org .openhealt htools.mdh t.uml.hl7. datatypes. INT;
  43   import org .openhealt htools.mdh t.uml.hl7. datatypes. IVL_PQ;
  44   import org .openhealt htools.mdh t.uml.hl7. datatypes. IVL_TS;
  45   import org .openhealt htools.mdh t.uml.hl7. datatypes. ON;
  46   import org .openhealt htools.mdh t.uml.hl7. datatypes. PIVL_TS;
  47   import org .openhealt htools.mdh t.uml.hl7. datatypes. PN;
  48   import org .openhealt htools.mdh t.uml.hl7. datatypes. PQ;
  49   import org .openhealt htools.mdh t.uml.hl7. datatypes. RTO_PQ_PQ;
  50   import org .openhealt htools.mdh t.uml.hl7. datatypes. SXCM_TS;
  51   import org .openhealt htools.mdh t.uml.hl7. datatypes. TS;
  52   import org .openhealt htools.mdh t.uml.hl7. vocab.SetO perator;
  53   import org .openhealt htools.mdh t.uml.hl7. vocab.x_Ac tRelations hipEntryRe lationship ;
  54   import org .openhealt htools.mdh t.uml.hl7. vocab.x_Do cumentSubs tanceMood;
  55   import org .slf4j.Log ger;
  56   import org .slf4j.Log gerFactory ;
  57  
  58   /**
  59    * Mediati ons Compon ent Sectio n
  60    * 
  61    * 
  62    * FullFil lment Hist ory is an  entire sec tion. Curr ently only  the last  one will
  63    * be popu lated.
  64    * 
  65    * @author  Brad Mess erle
  66    * @since  1.0
  67    * 
  68    * @param  <S> Medica tionsCompo nent
  69    */
  70   public cla ss Medicat ionsCompon ent extend s Abstract Component< Medication sSection>
  71   {
  72           pr ivate stat ic final L ogger logg er = Logge rFactory.g etLogger(M edications Component. class);
  73           
  74           /* *
  75            *  Construct or
  76            *  
  77            *  @param me dicationSe ction
  78            *  @param cc dDocument
  79            * /
  80           pu blic Medic ationsComp onent(fina l Continui tyOfCareDo cument ccd Document)
  81           {
  82                    supe r(ccdDocum ent.getMed icationsSe ction(), c cdDocument );
  83           }
  84  
  85           @O verride
  86           pu blic void  execute()
  87           {
  88  
  89                    // S et the nar rative tex t for the  section.
  90                    if(s ection !=  null)
  91                    {
  92                             // Cre ate Sectio n Data
  93                             this.c reateMedic ationHelpe rObjects() ;
  94                             super. execute();
  95                    }
  96  
  97           }
  98  
  99           @O verride
  100           pr otected St ring gener ateXml()
  101           {
  102                    Stri ngBuffer s b = new St ringBuffer ();
  103                    if(C ollectionU tils.isNot Empty(getS ectionData ()))
  104                    {
  105                             if(Col lectionUti ls.isNotEm pty(getCom ments()))
  106                             {
  107                                      sb.appen d("<table  ID='_nbMed icationsCo mments' bo rder='1' w idth='100% '>");
  108                                      sb.appen d("<thead> ");
  109                                      sb.appen d("<tr><th >Comments< /th></tr>" );
  110                                      sb.appen d("</thead >");
  111                                      sb.appen d("<tbody> ");
  112  
  113                                      for(Stri ng comment  : this.ge tComments( ))
  114                                      {
  115                                               sb.append( "<tr width ='100%'>") ;
  116                                               sb.append( "<td width ='100%'>") ;
  117                                               sb.append( "<p>");
  118                                               sb.append( comment);
  119                                               sb.append( "</p>");
  120                                               sb.append( "</td></tr >");
  121                                      }
  122  
  123                                      sb.appen d("</tbody >");
  124                                      sb.appen d("</table >");
  125                             }
  126                             sb.app end("<tabl e ID='_nbM edications ' border=' 1' width=' 100%'>\n") ;
  127  
  128                             sb.app end("\t<th ead>\n");
  129                             sb.app end("<tr>" );
  130                             sb.app end("<th>M edications </th>");
  131                             sb.app end("<th>M edication  Brand Name </th>");
  132                             sb.app end("<th>M edication  Status</th >");
  133                             sb.app end("<th>O rder Date< /th>");
  134                             sb.app end("<th>O rder Expir ation</th> ");
  135                             sb.app end("<th>P rovider (O rdering)</ th>");
  136                             sb.app end("<th>P rescriptio n #</th>") ;
  137                             sb.app end("<th>F ill Status </th>");
  138                             sb.app end("<th>Q uantity Di spensed</t h>");
  139                             sb.app end("<th>D ispense Da te</th>");
  140                             sb.app end("<th>S ig</th>");
  141                             sb.app end("<th>S ource</th> ");
  142                             sb.app end("<th>R eaction</t h>");
  143  
  144                             // Add itional fi elds
  145                             sb.app end("<th>I ndicate Me dication S topped</th >");
  146                             sb.app end("<th>A dministrat ive Timing </th>");
  147                             sb.app end("<th>R oute Code< /th>");
  148                             sb.app end("<th>B ody Site</ th>");
  149                             sb.app end("<th>D ose Quanit y</th>");
  150                             sb.app end("<th>D ose Restri ction</th> ");
  151                             sb.app end("<th>P roduct For m</th>");
  152                             sb.app end("<th>D elivery Me thod</th>" );
  153                             sb.app end("<th>D rug Manufa cture</th> ");
  154                             sb.app end("<th>T ype of Med ication</t h>");
  155                             sb.app end("<th>I ndication< /th>");
  156                             sb.app end("<th>V ehicle</th >");
  157                             sb.app end("<th>D ose Indica tor</th>") ;
  158                             sb.app end("<th>O rder Numbe r</th>");
  159                             sb.app end("<th>T otal Fills </th>");
  160                             sb.app end("<th>F ulFillment  Instructi ons</th>") ;
  161                             sb.app end("<th>D ispensing  Provider</ th>");
  162                             sb.app end("<th>P harmacy Lo cation</th >");
  163                             sb.app end("<th>F ill Number </th>");
  164                             sb.app end("</tr> \n");
  165                             sb.app end("</the ad>\n");
  166                             sb.app end("<tbod y>\n");
  167  
  168                             for(Se ctionValue Object val ueObejct :  this.getS ectionData ())
  169                             {
  170  
  171                                      final Me dicationsV O medicati onValueObj ect = (Med icationsVO ) valueObe jct;
  172                                      sb.appen d("<tr>");
  173                                      sb.appen d("<td>");
  174                                      sb.appen d(medicati onValueObj ect.getPro ductName() .getValueW ithRefDefa ult());
  175                                      sb.appen d("</td>") ;
  176                                      sb.appen d("<td>");
  177                                      sb.appen d(medicati onValueObj ect.getBra ndName().g etValueWit hRefDefaul t());
  178                                      sb.appen d("</td>") ;
  179                                      sb.appen d("<td>");
  180                                      sb.appen d(medicati onValueObj ect.getMed icationSta tus().getV alueWithRe fDefault() );
  181                                      sb.appen d("</td>") ;
  182                                      sb.appen d("<td>");
  183                                      sb.appen d(medicati onValueObj ect.getOrd erDate().g etValueWit hRefDefaul t());
  184                                      sb.appen d("</td>") ;
  185                                      sb.appen d("<td>");
  186                                      sb.appen d(medicati onValueObj ect.getOrd erExpirati on().getVa lueWithRef Default()) ;
  187                                      sb.appen d("</td>") ;
  188                                      sb.appen d("<td>");
  189                                      sb.appen d(medicati onValueObj ect.getOrd eringProvi der().getV alueWithRe fDefault() );
  190                                      sb.appen d("</td>") ;
  191                                      sb.appen d("<td>");
  192                                      sb.appen d(medicati onValueObj ect.getPre scriptionN umber().ge tValueWith RefDefault ());
  193                                      sb.appen d("</td>") ;
  194                                      sb.appen d("<td>");
  195                                      sb.appen d(medicati onValueObj ect.getFil lStatus(). getValueWi thRefDefau lt());
  196                                      sb.appen d("</td>") ;
  197                                      sb.appen d("<td>");
  198                                      sb.appen d(medicati onValueObj ect.getQua ntityDispe nsed().get ValueWithR efDefault( ));
  199                                      sb.appen d("</td>") ;
  200                                      sb.appen d("<td>");
  201                                      sb.appen d(medicati onValueObj ect.getDis penseDate( ).getValue WithRefDef ault());
  202                                      sb.appen d("</td>") ;
  203                                      sb.appen d("<td>");
  204                                      if(!medi cationValu eObject.ge tSig().isE mpty())
  205                                      {
  206                                               sb.append( medication ValueObjec t.getSig() .getValueW ithRefDefa ult());
  207                                      }
  208                                      else if( !medicatio nValueObje ct.getPati entInstruc tions().is Empty())
  209                                      {
  210                                               sb.append( medication ValueObjec t.getPatie ntInstruct ions().get ValueWithR efDefault( ));
  211                                      }
  212                                      else
  213                                      {
  214                                               sb.append( "--");
  215                                      }
  216                                      sb.appen d("</td>") ;
  217                                      sb.appen d("<td>"). append(med icationVal ueObject.g etSource() .getValueW ithRefDefa ult()).app end("</td> ");
  218  
  219                                      sb.appen d("<td>");
  220                                      sb.appen d(medicati onValueObj ect.getRea ction().ge tValueWith RefDefault ());
  221                                      sb.appen d("</td>") ;
  222  
  223                                      // Addit ional Colu mns
  224                                      sb.appen d("<td>");
  225                                      sb.appen d(medicati onValueObj ect.getInd icateMedic ationStopp ed().getVa lueWithRef Default()) ;
  226                                      sb.appen d("</td>") ;
  227                                      sb.appen d("<td>");
  228                                      sb.appen d(medicati onValueObj ect.getEff ectiveTime ().getValu eWithRefDe fault());
  229                                      sb.appen d("</td>") ;
  230                                      sb.appen d("<td>");
  231                                      sb.appen d(medicati onValueObj ect.getRou teCode().g etValueWit hRefDefaul t());
  232                                      sb.appen d("</td>") ;
  233                                      sb.appen d("<td>");
  234                                      sb.appen d(medicati onValueObj ect.getSit eCode().ge tValueWith RefDefault ());
  235                                      sb.appen d("</td>") ;
  236                                      sb.appen d("<td>");
  237                                      sb.appen d(medicati onValueObj ect.getDos eQuanity() .getValueW ithRefDefa ult());
  238                                      sb.appen d("</td>") ;
  239                                      sb.appen d("<td>");
  240                                      sb.appen d(medicati onValueObj ect.getDos eRestricti on().getVa lueWithRef Default()) ;
  241                                      sb.appen d("</td>") ;
  242                                      sb.appen d("<td>");
  243                                      sb.appen d(medicati onValueObj ect.getPro ductForm() .getValueW ithRefDefa ult());
  244                                      sb.appen d("</td>") ;
  245                                      sb.appen d("<td>");
  246                                      sb.appen d(medicati onValueObj ect.getDel iveryMetho d().getVal ueWithRefD efault());
  247                                      sb.appen d("</td>") ;
  248                                      sb.appen d("<td>");
  249                                      sb.appen d(medicati onValueObj ect.getDru gManufactu re().getVa lueWithRef Default()) ;
  250                                      sb.appen d("</td>") ;
  251                                      sb.appen d("<td>");
  252                                      sb.appen d(medicati onValueObj ect.getTyp eOfMedicat ion().getV alueWithRe fDefault() );
  253                                      sb.appen d("</td>") ;
  254                                      sb.appen d("<td>");
  255                                      sb.appen d(medicati onValueObj ect.getInd ication(). getValueWi thRefDefau lt());
  256                                      sb.appen d("</td>") ;
  257                                      sb.appen d("<td>");
  258                                      sb.appen d(medicati onValueObj ect.getVeh icle().get ValueWithR efDefault( ));
  259                                      sb.appen d("</td>") ;
  260                                      sb.appen d("<td>");
  261                                      sb.appen d(medicati onValueObj ect.getDos eIndicator ().getValu eWithRefDe fault());
  262                                      sb.appen d("</td>") ;
  263                                      sb.appen d("<td>");
  264                                      sb.appen d(medicati onValueObj ect.getOrd erNumber() .getValueW ithRefDefa ult());
  265                                      sb.appen d("</td>") ;
  266                                      sb.appen d("<td>");
  267                                      sb.appen d(medicati onValueObj ect.getFil ls().getVa lueWithRef Default()) ;
  268                                      sb.appen d("</td>") ;
  269                                      sb.appen d("<td>");
  270                                      sb.appen d(medicati onValueObj ect.getFul fillmentIn structions ().getValu eWithRefDe fault());
  271                                      sb.appen d("</td>") ;
  272  
  273                                      sb.appen d("<td>"). append(med icationVal ueObject.g etProvider ().getValu eWithRefDe fault()).a ppend("</t d>");
  274                                      sb.appen d("<td>");
  275                                      sb.appen d(medicati onValueObj ect.getPha rmacyLocat ion().getV alueWithRe fDefault() );
  276                                      sb.appen d("</td>") ;
  277                                      sb.appen d("<td>");
  278                                      sb.appen d(medicati onValueObj ect.getFil lNumber(). getValueWi thRefDefau lt());
  279                                      sb.appen d("</td>") ;
  280                                      sb.appen d("</tr>\n ");
  281                             }
  282  
  283                             sb.app end("</tbo dy>");
  284                             sb.app end("</tab le>");
  285                    }
  286                    retu rn sb.toSt ring();
  287           }
  288  
  289           pr ivate void  createMed icationHel perObjects ()
  290           {
  291                    // L oop throug h all of t he entries  in the se ction.
  292                    // T his sectio n is only  for parsin g of the v alues. All  BR's need  to be
  293                    // p rocessed e lsewhere.
  294                    for( Entry entr y : this.s ection.get Entries())
  295                    {
  296                             // All  data shou ld be stor ed in subs tance admi n.
  297                             Substa nceAdminis tration su bAdmin = e ntry.getSu bstanceAdm inistratio n();
  298                             // Mak e sure the re is one.
  299                             if(sub Admin != n ull)
  300                             {
  301                                      // Item  to add the  values to .
  302                                      final Me dicationsV O valueObj ect = new  Medication sVO();
  303                                      // Add a ll items t hat are di rect desce ndants of  substance  admin.
  304                                      // Those  are secti ons 8.01-8 .12
  305                                      // 8.01  Free Text  Sig.
  306                                      this.get Sig(subAdm in, valueO bject);
  307  
  308                                      // 8.02  - 8.06
  309                                      // This  is for pro cessing of  medicatio n frequenc y.
  310                                      this.get EffectiveT ime(subAdm in, valueO bject);
  311  
  312                                      // 8.07  Route.
  313                                      this.get Route(subA dmin, valu eObject);
  314  
  315                                      // 8.08  Dose
  316                                      this.get DoseQuanit y(subAdmin , valueObj ect);
  317  
  318                                      // 8.09  Site
  319                                      this.get SiteCode(s ubAdmin, v alueObject );
  320  
  321                                      // 8.10  Dose Restr iction
  322                                      this.get DoseRestri ction(subA dmin, valu eObject);
  323  
  324                                      // 8.11  Product Fo rm.
  325                                      this.get ProductFor m(subAdmin , valueObj ect);
  326  
  327                                      // 8.12  Delivery M ethod
  328                                      this.get DeliveryMe thod(subAd min, value Object);
  329  
  330                                      // Start  Consumabl es 8.13-8. 17
  331                                      this.pro cessConsum ables(subA dmin, valu eObject);
  332  
  333                                      // VA Sp ecific Ite ms. Source  et al.
  334                                      this.get SourceColu mn(subAdmi n, valueOb ject);
  335  
  336                                      // 8.20
  337                                      this.pro cessVehicl e(subAdmin , valueObj ect);
  338                                      for(Prec ondition p re : subAd min.getPre conditions ())
  339                                      {
  340                                               Criterion  crit = pre .getCriter ion();
  341                                               if(crit !=  null)
  342                                               {
  343                                                       if (crit.getT ext() != n ull)
  344                                                                valu eObject.se tDoseIndic ator(crit. getText(). getText()) ;
  345  
  346                                               }
  347                                      }
  348                                      // 8.19  - 8.40 All  the rest  of the dat a is conta ined in
  349                                      // entry Relationsh ips.
  350                                      this.pro cessEntryR els(subAdm in, valueO bject);
  351                                      if(value Object.get Medication Status() = = null ||  StringUtil s.isBlank( valueObjec t.getMedic ationStatu s().getVal ue()))
  352                                      {
  353                                               if(subAdmi n.getStatu sCode() !=  null && S tringUtils .isNotBlan k(subAdmin .getStatus Code().get Code()))
  354                                               {
  355                                                       va lueObject. setMedicat ionStatus( new ItemOb ject(subAd min.getSta tusCode(). getCode()) );
  356                                               }
  357                                      }
  358                                      // Add t he newly c reated obj ect to the  list.
  359                                      this.get SectionDat a().add(va lueObject) ;
  360                             }
  361                             else
  362                             {
  363                                      logger.d ebug("Fail ed to find  substance  administr ation elem ent in Med ication en try.  Need  to determ ine if the re needs t o be extra  processin g here.");
  364                             }
  365                    }
  366           }
  367  
  368           pr ivate void  processVe hicle(fina l Substanc eAdministr ation subA dmin, fina l Medicati onsVO valu eObject)
  369           {
  370                    Stri ngBuilder  sb = new S tringBuild er();
  371                    for( Participan t2 part :  subAdmin.g etParticip ants())
  372                    {
  373                             Partic ipantRole  role = par t.getParti cipantRole ();
  374                             if(rol e != null)
  375                             {
  376                                      PlayingE ntity ent  = role.get PlayingEnt ity();
  377                                      if(ent ! = null)
  378                                      {
  379                                               for(PN nam e : ent.ge tNames())
  380                                               {
  381                                                       if (StringUti ls.isNotBl ank(name.g etText()))
  382                                                       {
  383                                                                sb.a ppend(name .getText() ).append(" ,");
  384                                                       }
  385                                               }
  386                                      }
  387                             }
  388                    }
  389                    if(s b.length()  > 0)
  390                    {
  391                             valueO bject.setV ehicle(sb. substring( 0, sb.leng th() - 1)) ;
  392                    }
  393           }
  394  
  395           pr ivate void  processCo nsumables( final Subs tanceAdmin istration  subAdmin,  final Medi cationsVO  valueObjec t)
  396           {
  397                    Cons umable con sume = sub Admin.getC onsumable( );
  398                    if(c onsume !=  null)
  399                    {
  400                             // Sta rt Manufac tured Prod uct.
  401                             Manufa cturedProd uct prod =  consume.g etManufact uredProduc t();
  402                             if(pro d != null)
  403                             {
  404                                      // Manuf actured Ma terial
  405                                      Material  material  = prod.get Manufactur edMaterial ();
  406                                      if(mater ial != nul l)
  407                                      {
  408                                               this.getMa terialInfo rmation(ma terial, va lueObject) ;
  409                                      }
  410                                      // Manuf acturer na me. 8.17
  411                                      Organiza tion org =  prod.getM anufacture rOrganizat ion();
  412                                      if(org ! = null)
  413                                      {
  414                                               StringBuil der sb = n ew StringB uilder();
  415                                               for(ON nam e : org.ge tNames())
  416                                               {
  417                                                       if (StringUti ls.isNotBl ank(name.g etText()))
  418                                                       {
  419                                                                sb.a ppend(name .getText() ).append(" ,");
  420                                                       }
  421                                               }
  422                                               if(sb.leng th() > 0)
  423                                               {
  424                                                       va lueObject. setDrugMan ufacture(s b.substrin g(0, sb.le ngth() - 1 ));
  425                                               }
  426                                      }
  427                             }
  428                    }
  429           }
  430  
  431           pr ivate void  processEn tryRels(fi nal Substa nceAdminis tration su bAdmin, fi nal Medica tionsVO va lueObject)
  432           {
  433                    for( EntryRelat ionship re l : subAdm in.getEntr yRelations hips())
  434                    {
  435                             proces sObservati ons(rel, v alueObject );
  436                             Act ac t = rel.ge tAct();
  437                             Supply  supply =  rel.getSup ply();
  438                             if(x_A ctRelation shipEntryR elationshi p.RSON.equ als(rel.ge tTypeCode( )))
  439                             {
  440                                      Observat ion obs =  rel.getObs ervation() ;
  441                                      if(obs ! = null)
  442                                      {
  443                                                if(Utils.c ontainsTem plateId(ob s.getTempl ateIds(),  "2.16.840. 1.113883. IP          "))
  444                                               {
  445                                                       //  First loo k to see i f it was p laced in a  code
  446                                                       //  block
  447                                                       //  8.21
  448                                                       CD  code = ob s.getCode( );
  449                                                       It emObject i tem = Util s.getFromC ode(code,  narrativeT ext);
  450                                                       if (item != n ull && ite m.hasValue ())
  451                                                       {
  452                                                                valu eObject.se tIndicatio n(item);
  453                                                       }
  454                                               }
  455                                      }
  456                             }
  457  
  458                             if(sup ply != nul l)
  459                             {
  460                                      // Check  for prope r moodCode  for Order Informatio n
  461                                      if(x_Doc umentSubst anceMood.I NT.equals( supply.get MoodCode() ))
  462                                      {
  463                                               // Start o rder infor mation 8.2 6-8.31
  464                                               // 8.26
  465                                               getOrderNu mber(suppl y, valueOb ject);
  466  
  467                                               // 8.27
  468                                               getFills(s upply, val ueObject);
  469  
  470                                               // 8.28 Th is is curr ently a no op.
  471                                               getQuantit yOrdered(s upply, val ueObject);
  472  
  473                                               // 8.29
  474                                               getOrderEx peration(s upply, val ueObject);
  475  
  476                                               // 8.30
  477                                               getOrderDa te(supply,  valueObje ct);
  478  
  479                                               // 8.31
  480                                               getOrderin gProvider( supply, va lueObject) ;
  481                                      }
  482  
  483                                      if(x_Doc umentSubst anceMood.E VN.equals( supply.get MoodCode() ))
  484                                      {
  485                                               // 8.34 Pr escription  Number
  486                                               getPerscri ptionNumbe r(supply,  valueObjec t);
  487  
  488                                               // 8.35 &  8.36
  489                                               getAssigne dPharmInfo (supply, v alueObject );
  490  
  491                                               // 8.37
  492                                               getDispens eDate(supp ly, valueO bject);
  493  
  494                                               // 8.38
  495                                               getQuantit yDispensed (supply, v alueObject );
  496  
  497                                               // 8.39 -  8.40
  498                                               getFillNum berAndStat us(supply,  valueObje ct);
  499  
  500                                      }
  501                             }
  502                             // Sta rt process ing items  that do no t have an  explicit
  503                             // Ent ryRelation ship/typeC ode.
  504                             if(act  != null)
  505                             {
  506                                      ED text  = act.getT ext();
  507                                      if(text  != null)
  508                                      {
  509                                                // 8.32 2. 16.840.1.1 13883. IP         
  510                                                if(Utils.c ontainsTem plateId(ac t.getTempl ateIds(),  "2.16.840. 1.113883. IP          "))
  511                                               {
  512                                                       if (StringUti ls.isNotBl ank(text.g etText()))
  513                                                       {
  514                                                                valu eObject.se tFulfillme ntInstruct ions(text. getText()) ;
  515                                                       }
  516                                               }
  517                                               else if(te xt.getRefe rence() !=  null && S tringUtils .isNotBlan k(text.get Reference( ).getValue ()))
  518                                               {
  519                                                       //  8.22 Pati ent Instru ctions Spe cifies a t emplateID  that
  520                                                       //  Kaiser do es not use .
  521                                                       //  Skip that  test for  now.
  522  
  523                                                       //  There is  a referenc e value no t actual.
  524                                                       St ring refva l = Utils. getReferen ceValue(na rrativeTex t, text.ge tReference ().getValu e());
  525                                                       if (StringUti ls.isNotBl ank(refval ))
  526                                                       {
  527                                                                // F ound a ref erence and  a value.  Store it.
  528                                                                valu eObject.se tPatientIn structions (new ItemO bject(text .getRefere nce().getV alue(), re fval));
  529                                                       }
  530                                               }
  531                                               else if(St ringUtils. isNotBlank (text.getT ext()))
  532                                               {
  533                                                       //  Check to  see if fre etext is a ctually in  original
  534                                                       //  text.
  535                                                       va lueObject. setPatient Instructio ns(new Ite mObject(te xt.getText ()));
  536                                               }
  537                                      }
  538                             }
  539                    }
  540           }
  541  
  542           pr ivate void  processOb servations (final Ent ryRelation ship rel,  final Medi cationsVO  valueObjec t)
  543           {
  544                    Obse rvation ob s = rel.ge tObservati on();
  545                    if(o bs == null )
  546                             return ;
  547  
  548                    swit ch(rel.get TypeCode() )
  549                    {
  550                    case  SUBJ:
  551                             // 8.1 9 Type of  medication
  552                             if(Uti ls.contain sTemplateI d(obs.getT emplateIds (), "2.16. 840.1.1138 83.3.88.11 .83.8.1"))
  553                             {
  554                                      // First  look to s ee if it w as placed  in a code
  555                                      // block
  556                                      CD code  = obs.getC ode();
  557                                      valueObj ect.setTyp eOfMedicat ion(Utils. getFromCod e(code, na rrativeTex t));
  558                             }
  559                             break;
  560                    case  REFR:
  561                             // 8.2 0 Status o f Medicati on
  562                              if(Utils.c ontainsTem plateId(ob s.getTempl ateIds(),  "2.16.840. 1.113883. IP          "))
  563                             {
  564  
  565                                      if(Colle ctionUtils .isNotEmpt y(obs.getV alues()))
  566                                      {
  567                                               StringBuil der sb = n ew StringB uilder();
  568                                               for(ANY va l : obs.ge tValues())
  569                                               {
  570                                                       if (val insta nceof CD)
  571                                                       {
  572                                                                // C D is one o f the main  types tha t
  573                                                                // c ontains a  display na me.
  574                                                                CD c d = (CD) v al;
  575                                                                Item Object ite m = Utils. getFromCod e(cd, narr ativeText) ;
  576                                                                if(i tem != nul l && item. hasValue() )
  577                                                                {
  578                                                                         sb.app end(item.g etValue()) .append(", ");
  579                                                                }
  580                                                       }
  581                                               }
  582                                               if(sb.leng th() > 0)
  583                                               {
  584                                                       va lueObject. setMedicat ionStatus( sb.substri ng(0, sb.l ength() -  1));
  585                                               }
  586                                      }
  587  
  588                             }
  589                             break;
  590                    case  CAUS:
  591                             // 8.2 3 Reaction
  592                              if(Utils.c ontainsTem plateId(ob s.getTempl ateIds(),  "2.16.840. 1.113883. IP          "))
  593                             {
  594                                      ED text  = obs.getT ext();
  595                                      if(text  != null)
  596                                      {
  597                                               if(text.ge tReference () != null  && String Utils.isNo tBlank(tex t.getRefer ence().get Value()))
  598                                               {
  599                                                       //  There is  a referenc e value no t actual.
  600                                                       St ring refva l = Utils. getReferen ceValue(na rrativeTex t, text.ge tReference ().getValu e());
  601                                                       if (StringUti ls.isNotBl ank(refval ))
  602                                                       {
  603                                                                // F ound a ref erence and  a value.  Store it.
  604                                                                valu eObject.se tReaction( new ItemOb ject(refva l, text.ge tReference ().getValu e()));
  605                                                       }
  606                                               }
  607                                               else if(St ringUtils. isNotBlank (text.getT ext()))
  608                                               {
  609                                                       //  Check to  see if fre etext is a ctually in
  610                                                       //  original
  611                                                       //  text.
  612                                                       va lueObject. setReactio n(text.get Text());
  613                                               }
  614                                      }
  615                             }
  616                             break;
  617                    defa ult:
  618                             logger .debug("Fo und an ent ry with an  observati on that is  not able  to be proc essed.");
  619                             break;
  620                    }
  621           }
  622  
  623           pr ivate void  getOrderD ate(final  Supply sup ply, final  Medicatio nsVO value Object)
  624           {
  625  
  626                    if(C ollectionU tils.isNot Empty(supp ly.getAuth ors()))
  627                    {
  628                             for(Au thor autho r : supply .getAuthor s())
  629                             {
  630                                      final TS  timeValue  = author. getTime();
  631                                      if(timeV alue != nu ll && Stri ngUtils.is NotBlank(t imeValue.g etValue()) )
  632                                      {
  633                                               valueObjec t.setOrder Date(timeV alue.getVa lue());
  634                                      }
  635                             }
  636                    }
  637  
  638                    if(v alueObject .getOrderD ate().isEm pty())
  639                    {
  640                             valueO bject.setO rderDate(E MPTY_FIELD );
  641                    }
  642           }
  643  
  644           pr ivate void  getOrderE xperation( final Supp ly supply,  final Med icationsVO  valueObje ct)
  645           {
  646                    if(C ollectionU tils.isNot Empty(supp ly.getEffe ctiveTimes ()))
  647                    {
  648                             for(SX CM_TS time  : supply. getEffecti veTimes())
  649                             {
  650                                      if(Strin gUtils.isN otBlank(ti me.getValu e()))
  651                                      {
  652                                               valueObjec t.setOrder Expiration (time.getV alue());
  653                                      }
  654                             }
  655                    }
  656  
  657                    if(v alueObject .getOrderE xpiration( ).isEmpty( ))
  658                    {
  659                             valueO bject.setO rderExpira tion(EMPTY _FIELD);
  660                    }
  661           }
  662  
  663           pr ivate void  getPerscr iptionNumb er(final S upply supp ly, final  Medication sVO valueO bject)
  664           {
  665                    if(s upply != n ull && sup ply.getIds () != null )
  666                    {
  667                             for(II  id : supp ly.getIds( ))
  668                             {
  669                                      if(id.ge tExtension () != null  && !id.ge tExtension ().equalsI gnoreCase( "nullflavo r"))
  670                                      {
  671                                               valueObjec t.setPresc riptionNum ber(id.get Extension( ));
  672                                      }
  673                             }
  674                    }
  675  
  676                    // s till not f ound put t he -- stri ng
  677                    if(v alueObject .getPrescr iptionNumb er().isEmp ty())
  678                    {
  679                             valueO bject.setP rescriptio nNumber(EM PTY_FIELD) ;
  680                    }
  681  
  682           }
  683  
  684           pr ivate void  getQuanti tyDispense d(final Su pply suppl y, final M edications VO valueOb ject)
  685           {
  686                    fina l PQ quant ity = supp ly.getQuan tity();
  687                    if(q uantity !=  null)
  688                    {
  689                             valueO bject.setQ uantityDis pensed(qua ntity.getV alue().toS tring());
  690                    }
  691  
  692                    // T ODO: Move  to busines s rules.
  693                    // i f (valueOb ject.getQu antityDisp ensed() ==  null
  694                    // | | (valueOb ject.getQu antityDisp ensed() !=  null &&
  695                    // v alueObject .getQuanti tyDispense d().isEmpt y())) {
  696                    // f inal IVL_P Q doseQnty  =
  697                    // s upply.getS ubstanceAd ministrati on().getDo seQuantity ();
  698                    //
  699                    // i f (doseQnt y != null  && doseQnt y.getValue () != null ) {
  700                    // v alueObject .setQuanti tyDispense d(doseQnty .getValue( ).toString ());
  701                    // }
  702                    // }
  703  
  704                    // s till not f ound put t he -- stri ng
  705                    if(v alueObject .getQuanti tyDispense d().isEmpt y())
  706                    {
  707                             valueO bject.setQ uantityDis pensed(EMP TY_FIELD);
  708                    }
  709  
  710           }
  711  
  712           pr ivate void  getDispen seDate(fin al Supply  supply, fi nal Medica tionsVO va lueObject)
  713           {
  714                    if(C ollectionU tils.isNot Empty(supp ly.getEffe ctiveTimes ()))
  715                    {
  716                             for(SX CM_TS time  : supply. getEffecti veTimes())
  717                             {
  718                                      if(Strin gUtils.isN otBlank(ti me.getValu e()))
  719                                      {
  720                                               valueObjec t.setDispe nseDate(ti me.getValu e());
  721                                      }
  722                             }
  723                    }
  724  
  725                    // s till not f ound put t he -- stri ng
  726                    if(v alueObject .getDispen seDate().i sEmpty())
  727                    {
  728                             valueO bject.setD ispenseDat e(EMPTY_FI ELD);
  729                    }
  730  
  731           }
  732  
  733           pr ivate void  getSig(fi nal Substa nceAdminis tration su bAdmin, fi nal Medica tionsVO va lueObject)
  734           {
  735  
  736                    fina l ED text  = subAdmin .getText() ;
  737  
  738                    if(t ext != nul l && text. getReferen ce() != nu ll)
  739                    {
  740  
  741                             final  String ref Id = text. getReferen ce().getVa lue();
  742  
  743                             if(ref Id != null )
  744                             {
  745  
  746                                      final St ring refVa lue = Util s.getRefer enceValue( narrativeT ext, refId );
  747                                      valueObj ect.setSig (new ItemO bject(refV alue, refI d));
  748                             }
  749                    }
  750                    else  if(text ! = null &&  StringUtil s.isNotBla nk(text.ge tText()))
  751                    {
  752                             valueO bject.setS ig(new Ite mObject(te xt.getText ()));
  753                    }
  754  
  755                    // / / Check 8. 22
  756                    // i f (valueOb ject.getSi g() == nul l || value Object.get Sig().isEm pty()) {
  757                    // i f (subAdmi n.getAct()  != null & &
  758                    // ! subAdmin.g etAct().ge tTemplateI ds().isEmp ty()) {
  759                    // f inal II te mpId = sub Admin.getA ct().getTe mplateIds( ).get(0);
  760                    // v alueObject .setSig(te mpId.getRo ot());
  761                    // }
  762                    // }
  763  
  764           }
  765  
  766           pr ivate void  getSource Column(fin al Substan ceAdminist ration sub Admin, fin al Medicat ionsVO val ueObject)
  767           {
  768                    for( Author aut hor : subA dmin.getAu thors())
  769                    {
  770                             if(aut hor.getAss ignedAutho r().getRep resentedOr ganization () != null  && Collec tionUtils. isNotEmpty (author.ge tAssignedA uthor().ge tRepresent edOrganiza tion().get Names()))
  771                             {
  772                                      // TODO:  Update th is to loop  through o rgs and co ncatenate  names.
  773                                      valueObj ect.setSou rce(author .getAssign edAuthor() .getRepres entedOrgan ization(). getNames() .get(0).ge tText());
  774                             }
  775                    }
  776  
  777                    // s till not f ound put t he -- stri ng
  778                    if(v alueObject .getSource ().isEmpty ())
  779                    {
  780                             valueO bject.setS ource(EMPT Y_FIELD);
  781                    }
  782  
  783           }
  784  
  785           pr ivate void  getEffect iveTime(fi nal Substa nceAdminis tration su bAdmin, fi nal Medica tionsVO va lueObject)
  786           {
  787                    Stri ngBuilder  ret = new  StringBuil der();
  788  
  789                    for( SXCM_TS ti me : subAd min.getEff ectiveTime s())
  790                    {
  791                             if(tim e instance of PIVL_TS )
  792                             {
  793                                      ret.appe nd(process PIVL((PIVL _TS) time) ).append("  ");
  794                             }
  795                             else i f(time ins tanceof EI VL_TS)
  796                             {
  797                                      ret.appe nd(process EIVL((EIVL _TS) time) ).append("  ");
  798                             }
  799                             else i f(time ins tanceof IV L_TS)
  800                             {
  801                                      ret.appe nd(process IVL((IVL_T S) time, v alueObject )).append( " ");
  802                             }
  803                             else i f(StringUt ils.isNotB lank(time. getValue() ))
  804                             {
  805                                      // Fall  through te st
  806                                      ret.appe nd("Once o n " + time .getValue( ));
  807                             }
  808                    }
  809  
  810                    if(r et.length( ) > 0)
  811                    {
  812                             valueO bject.setE ffectiveTi me(ret.toS tring());
  813                    }
  814                    else
  815                    {
  816                             valueO bject.setE ffectiveTi me(EMPTY_F IELD);
  817                    }
  818           }
  819  
  820           /* *
  821            *  Will set  Indicate m ed stopped  only if t ime.getHig h != null  and
  822            *  time.getL ow == null
  823            *  
  824            *  Otherwise  this will  return th e time str ing for in dicating t iming.
  825            *  
  826            *  @param ti me
  827            *  @param vo
  828            *  @return
  829            * /
  830           pr ivate Stri ng process IVL(final  IVL_TS tim e, final M edications VO vo)
  831           {
  832                    if(t ime == nul l)
  833                    {
  834                             return  StringUti ls.EMPTY;
  835                    }
  836                    Stri ng timeLow ;
  837                    Stri ng timeHig h;
  838  
  839                    if(t ime.getLow () != null )
  840                    {
  841                             timeLo w = time.g etLow().ge tValue();
  842                    }
  843                    else
  844                    {
  845                             timeLo w = String Utils.EMPT Y;
  846                    }
  847  
  848                    if(t ime.getHig h() != nul l)
  849                    {
  850                             timeHi gh = time. getHigh(). getValue() ;
  851                    }
  852                    else
  853                    {
  854                             timeHi gh = Strin gUtils.EMP TY;
  855                    }
  856  
  857                    if(S tringUtils .isNotBlan k(timeHigh ) && Strin gUtils.isB lank(timeL ow))
  858                    {
  859                             // Ind icate MedS topped
  860                             vo.set IndicateMe dicationSt opped(time High);
  861                             return  StringUti ls.EMPTY;
  862                    }
  863  
  864                    if(S tringUtils .isNotBlan k(timeLow)  && String Utils.isNo tBlank(tim eHigh))
  865                    {
  866                             return  "From: "  + timeLow  + " To: "  + timeHigh ;
  867                    }
  868  
  869                    if(S tringUtils .isNotBlan k(time.get Value()))
  870                    {
  871                             return  "Once on  " + time.g etValue();
  872                    }
  873  
  874                    if(S tringUtils .isNotBlan k(timeLow) )
  875                    {
  876                             return  "From: "  + timeLow;
  877                    }
  878  
  879                    retu rn StringU tils.EMPTY ;
  880           }
  881  
  882           pr ivate Stri ng process PIVL(final  PIVL_TS t ime)
  883           {
  884                    if(t ime == nul l)
  885                    {
  886                             return  null;
  887                    }
  888  
  889                    Stri ngBuilder  effectiveT ime = new  StringBuil der();
  890  
  891                    if(t ime.getOpe rator() !=  null && t ime.getOpe rator().eq uals(SetOp erator.A)  && time.ge tPeriod()  != null &&  time.getP eriod().ge tValue() ! = null)
  892                    {
  893                             if(tim e.getInsti tutionSpec ified() &&  "h".equal sIgnoreCas e(time.get Period().g etUnit()))
  894                             {
  895                                      Double v alue = tim e.getPerio d().getVal ue().doubl eValue();
  896                                      Double p eriod = 0. 0;
  897                                      if(value  != null)
  898                                      {
  899                                               if(value <  1.0)
  900                                               {
  901                                                       pe riod = 24. 0 * value;
  902                                               }
  903                                               else
  904                                               {
  905                                                       pe riod = 24. 0 / value;
  906                                               }
  907                                      }
  908  
  909                                      effectiv eTime.appe nd(period) ;
  910                                      effectiv eTime.appe nd(" ");
  911                                      effectiv eTime.appe nd("time(s ) a day");
  912                             }
  913                             else
  914                             {
  915                                      effectiv eTime.appe nd("every  ");
  916                                      effectiv eTime.appe nd(time.ge tPeriod(). getValue() );
  917                                      effectiv eTime.appe nd(" ");
  918                                      effectiv eTime.appe nd(time.ge tPeriod(). getUnit()) .append("  ");
  919                                      String p hase = pro cessPhase( time.getPh ase());
  920                                      if(Strin gUtils.isN otBlank(ph ase))
  921                                      {
  922                                               effectiveT ime.append ("for ").a ppend(phas e).append( " ");
  923                                      }
  924  
  925                             }
  926                    }
  927                    else  if(time.g etPhase()  != null)
  928                    {
  929                             effect iveTime.ap pend(" ");
  930                             effect iveTime.ap pend("for  ");
  931                             effect iveTime.ap pend(proce ssPhase(ti me.getPhas e()));
  932                    }
  933                    retu rn effecti veTime.toS tring().tr im();
  934           }
  935  
  936           pr ivate Stri ng process Phase(fina l IVL_TS p hase)
  937           {
  938                    Stri ngBuilder  sb = new S tringBuild er();
  939  
  940                    if(p hase != nu ll)
  941                    {
  942                             sb.app end(phase. getWidth() .getValue( ));
  943                             sb.app end(" ");
  944                             sb.app end(phase. getWidth() .getUnit() );
  945  
  946                             if(pha se.getLow( ) != null)
  947                             {
  948                                      String t ime = phas e.getLow() .getValue( );
  949                                      if(Strin gUtils.isN otBlank(ti me))
  950                                      {
  951                                               sb.append( " at ");
  952                                               sb.append( time.subst ring(time. length() -  4));
  953                                      }
  954                             }
  955                    }
  956                    retu rn sb.toSt ring().tri m();
  957           }
  958  
  959           pr ivate Stri ng process EIVL(final  EIVL_TS t ime)
  960           {
  961                    if(t ime == nul l)
  962                    {
  963                             return  null;
  964                    }
  965  
  966                    Stri ngBuilder  ret = new  StringBuil der();
  967  
  968                    if(S etOperator .A.equals( time.getOp erator()))
  969                    {
  970                             if(tim e.getEvent () != null  && String Utils.isNo tBlank(tim e.getEvent ().getCode ()))
  971                             {
  972                                      // Cycle  through a ll of the  possible c ode values  to get th e
  973                                      // prope r return.
  974                                      if("AC". equalsIgno reCase(tim e.getEvent ().getCode ()))
  975                                      {
  976                                               ret.append ("before m eal");
  977                                      }
  978                                      else if( "ACD".equa lsIgnoreCa se(time.ge tEvent().g etCode()))
  979                                      {
  980                                               ret.append ("before l unch");
  981                                      }
  982                                      else if( "ACM".equa lsIgnoreCa se(time.ge tEvent().g etCode()))
  983                                      {
  984                                               ret.append ("before b reakfast") ;
  985                                      }
  986                                      else if( "ACV".equa lsIgnoreCa se(time.ge tEvent().g etCode()))
  987                                      {
  988                                               ret.append ("before d inner");
  989                                      }
  990                                      else if( "HS".equal sIgnoreCas e(time.get Event().ge tCode()))
  991                                      {
  992                                               ret.append ("hour of  sleep");
  993                                      }
  994                                      else if( "IC".equal sIgnoreCas e(time.get Event().ge tCode()))
  995                                      {
  996                                               ret.append ("between  meals");
  997                                      }
  998                                      else if( "ICD".equa lsIgnoreCa se(time.ge tEvent().g etCode()))
  999                                      {
  1000                                               ret.append ("between  lunch and  dinner");
  1001                                      }
  1002                                      else if( "ICM".equa lsIgnoreCa se(time.ge tEvent().g etCode()))
  1003                                      {
  1004                                               ret.append ("between  breakfast  and lunch" );
  1005                                      }
  1006                                      else if( "ICV".equa lsIgnoreCa se(time.ge tEvent().g etCode()))
  1007                                      {
  1008                                               ret.append ("between  dinner and  hour of s leep");
  1009                                      }
  1010                                      else if( "PC".equal sIgnoreCas e(time.get Event().ge tCode()))
  1011                                      {
  1012                                               ret.append ("after me al");
  1013                                      }
  1014                                      else if( "PCD".equa lsIgnoreCa se(time.ge tEvent().g etCode()))
  1015                                      {
  1016                                               ret.append ("after lu nch");
  1017                                      }
  1018                                      else if( "PCM".equa lsIgnoreCa se(time.ge tEvent().g etCode()))
  1019                                      {
  1020                                               ret.append ("after br eakfast");
  1021                                      }
  1022                                      else if( "PCV".equa lsIgnoreCa se(time.ge tEvent().g etCode()))
  1023                                      {
  1024                                               ret.append ("after di nner");
  1025                                      }
  1026                             }
  1027                             if(ret .length()  > 1)
  1028                             {
  1029                                      return r et.toStrin g();
  1030                             }
  1031                    }
  1032                    retu rn null;
  1033           }
  1034  
  1035           pr ivate void  getRoute( final Subs tanceAdmin istration  subAdmin,  final Medi cationsVO  valueObjec t)
  1036           {
  1037                    fina l CE route Code = sub Admin.getR outeCode() ;
  1038                    if(r outeCode ! = null)
  1039                    {
  1040                             valueO bject.setR outeCode(U tils.getFr omCode(rou teCode, na rrativeTex t));
  1041                    }
  1042  
  1043                    // s till not f ound put t he -- stri ng
  1044                    if(v alueObject .getRouteC ode().isEm pty())
  1045                    {
  1046                             valueO bject.setR outeCode(E MPTY_FIELD );
  1047                    }
  1048  
  1049           }
  1050  
  1051           //  TODO: Upd ate to dea l with tra nslations.
  1052           pr ivate void  getDoseQu anity(fina l Substanc eAdministr ation subA dmin, fina l Medicati onsVO valu eObject)
  1053           {
  1054                    fina l IVL_PQ d oseQuantit y = subAdm in.getDose Quantity() ;
  1055                    fina l StringBu ilder sb =  new Strin gBuilder() ;
  1056                    if(d oseQuantit y != null)
  1057                    {
  1058                             if(dos eQuantity. getValue()  != null)
  1059                             {
  1060                                      sb.appen d(doseQuan tity.getVa lue().toSt ring());
  1061                             }
  1062  
  1063                             if(Str ingUtils.i sNotBlank( doseQuanti ty.getUnit ()) && !"1 ".equals(d oseQuantit y.getUnit( )))
  1064                             {
  1065                                      sb.appen d(" ").app end(doseQu antity.get Unit());
  1066                             }
  1067                    }
  1068                    valu eObject.se tDoseQuani ty(sb.toSt ring());
  1069                    // s till not f ound put t he -- stri ng
  1070                    if(v alueObject .getDoseQu anity().is Empty())
  1071                    {
  1072                             valueO bject.setD oseQuanity (EMPTY_FIE LD);
  1073                    }
  1074           }
  1075  
  1076           pr ivate void  getSiteCo de(final S ubstanceAd ministrati on subAdmi n, final M edications VO valueOb ject)
  1077           {
  1078                    if(C ollectionU tils.isNot Empty(subA dmin.getAp proachSite Codes()))
  1079                    {
  1080                             String Builder sb  = new Str ingBuilder ();
  1081                             for(CD  siteCode  : subAdmin .getApproa chSiteCode s())
  1082                             {
  1083                                      ItemObje ct item =  Utils.getF romCode(si teCode, na rrativeTex t);
  1084                                      if(item  != null)
  1085                                      {
  1086                                               if(subAdmi n.getAppro achSiteCod es().size( ) < 2)
  1087                                               {
  1088                                                       va lueObject. setSiteCod e(item);
  1089                                                       br eak;
  1090                                               }
  1091                                               sb.append( item.getVa lue()).app end(",");
  1092                                               if(item.ha sReference ())
  1093                                               {
  1094                                                       lo gger.error ("Going to  lose a re ference fo r " + item );
  1095                                               }
  1096                                      }
  1097                             }
  1098                             if(sb. length() >  0)
  1099                             {
  1100                                      valueObj ect.setSit eCode(sb.s ubstring(0 , sb.lengt h() - 1));
  1101                             }
  1102                    }
  1103  
  1104                    // s till not f ound put t he -- stri ng
  1105                    if(v alueObject .getSiteCo de().isEmp ty())
  1106                    {
  1107                             valueO bject.setS iteCode(EM PTY_FIELD) ;
  1108                    }
  1109  
  1110           }
  1111  
  1112           //  TODO: Upd ate with c heck for t ranslation s.
  1113           pr ivate void  getDoseRe striction( final Subs tanceAdmin istration  subAdmin,  final Medi cationsVO  valueObjec t)
  1114           {
  1115                    fina l RTO_PQ_P Q maxDoseQ nty = subA dmin.getMa xDoseQuant ity();
  1116  
  1117                    fina l StringBu ilder maxD oseString  = new Stri ngBuilder( );
  1118  
  1119                    if(m axDoseQnty  != null)
  1120                    {
  1121  
  1122                             if(max DoseQnty.g etNumerato r() != nul l)
  1123                             {
  1124                                      PQ num =  maxDoseQn ty.getNume rator();
  1125                                      if(num.g etValue()  != null)
  1126                                      {
  1127                                               maxDoseStr ing.append (num.getVa lue().toSt ring());
  1128                                      }
  1129                                      if(Strin gUtils.isN otBlank(nu m.getUnit( )))
  1130                                      {
  1131                                               maxDoseStr ing.append (num.getUn it());
  1132                                      }
  1133                             }
  1134  
  1135                             if(max DoseQnty.g etDenomina tor() != n ull)
  1136                             {
  1137                                      maxDoseS tring.appe nd(" / ");
  1138                                      if(maxDo seQnty.get Denominato r().getVal ue() != nu ll)
  1139                                      {
  1140                                               maxDoseStr ing.append (maxDoseQn ty.getDeno minator(). getValue() .toString( ));
  1141                                      }
  1142                                      if(Strin gUtils.isN otBlank(ma xDoseQnty. getDenomin ator().get Unit()))
  1143                                      {
  1144                                               maxDoseStr ing.append (maxDoseQn ty.getDeno minator(). getUnit()) ;
  1145                                      }
  1146                             }
  1147                    }
  1148  
  1149                    valu eObject.se tDoseRestr iction(max DoseString .toString( ));
  1150                    // s till not f ound put t he -- stri ng
  1151                    if(v alueObject .getDoseRe striction( ).isEmpty( ))
  1152                    {
  1153                             valueO bject.setD oseRestric tion(EMPTY _FIELD);
  1154                    }
  1155  
  1156           }
  1157  
  1158           pr ivate void  getProduc tForm(fina l Substanc eAdministr ation subA dmin, fina l Medicati onsVO valu eObject)
  1159           {
  1160                    fina l CE produ ctForm = s ubAdmin.ge tAdministr ationUnitC ode();
  1161                    if(p roductForm  != null)
  1162                    {
  1163                             valueO bject.setP roductForm (Utils.get FromCode(p roductForm , narrativ eText));
  1164                    }
  1165  
  1166                    // s till not f ound put t he -- stri ng
  1167                    if(v alueObject .getProduc tForm().is Empty())
  1168                    {
  1169                             valueO bject.setP roductForm (EMPTY_FIE LD);
  1170                    }
  1171  
  1172           }
  1173  
  1174           pr ivate void  getDelive ryMethod(f inal Subst anceAdmini stration s ubAdmin, f inal Medic ationsVO v alueObject )
  1175           {
  1176                    fina l CD deliv eryMethod  = subAdmin .getCode() ;
  1177  
  1178                    if(d eliveryMet hod != nul l)
  1179                    {
  1180                             valueO bject.setD eliveryMet hod(Utils. getFromCod e(delivery Method, na rrativeTex t));
  1181                    }
  1182  
  1183                    // s till not f ound put t he -- stri ng
  1184                    if(v alueObject .getDelive ryMethod() .isEmpty() )
  1185                    {
  1186                             valueO bject.setD eliveryMet hod(EMPTY_ FIELD);
  1187                    }
  1188  
  1189           }
  1190  
  1191           /* *
  1192            *  Will set  the coded  product na me, produc t Name, co ded brand  name, and
  1193            *  brand nam e
  1194            *  
  1195            *  @param ma terial
  1196            *  @param va lueObject
  1197            * /
  1198           pr ivate void  getMateri alInformat ion(final  Material m aterial, f inal Medic ationsVO v alueObject )
  1199           {
  1200                    CE c ode = mate rial.getCo de();
  1201                    if(c ode != nul l)
  1202                    {
  1203                             // Loo k for free  text prod uct Name 8 .15
  1204                             ED oTe xt = code. getOrigina lText();
  1205                             if(oTe xt != null )
  1206                             {
  1207                                      if(oText .getRefere nce() != n ull && Str ingUtils.i sNotBlank( oText.getR eference() .getValue( )))
  1208                                      {
  1209                                               // There i s a refere nce value  not actual .
  1210                                               String ref val = Util s.getRefer enceValue( narrativeT ext, oText .getRefere nce().getV alue());
  1211                                               if(StringU tils.isNot Blank(refv al))
  1212                                               {
  1213                                                       //  Found a r eference a nd a value . Store it .
  1214                                                       va lueObject. setProduct Name(new I temObject( refval, oT ext.getRef erence().g etValue()) );
  1215                                               }
  1216                                      }
  1217                                      else if( StringUtil s.isNotBla nk(oText.g etText()))
  1218                                      {
  1219                                               // Check t o see if f reetext is  actually  in origina l text.
  1220                                               valueObjec t.setProdu ctName(oTe xt.getText ());
  1221                                      }
  1222                             }
  1223  
  1224                             // Loo k for free text brand  name 8.16
  1225                             if(mat erial.getN ame() != n ull)
  1226                             {
  1227                                      if(Strin gUtils.isN otBlank(ma terial.get Name().get Text()))
  1228                                      {
  1229                                               valueObjec t.setBrand Name(mater ial.getNam e().getTex t());
  1230                                      }
  1231                             }
  1232                    }
  1233           }
  1234  
  1235           pr ivate void  getOrderN umber(fina l Supply s upply, fin al Medicat ionsVO val ueObject)
  1236           {
  1237                    for( II id : su pply.getId s())
  1238                    {
  1239                             if(Str ingUtils.i sNotBlank( id.getExte nsion()))
  1240                             {
  1241                                      valueObj ect.setOrd erNumber(i d.getExten sion());
  1242                             }
  1243                    }
  1244  
  1245                    // s till not f ound put t he -- stri ng
  1246                    if(v alueObject .getOrderN umber().is Empty())
  1247                    {
  1248                             valueO bject.setO rderNumber (EMPTY_FIE LD);
  1249                    }
  1250  
  1251           }
  1252  
  1253           pr ivate void  getFills( final Supp ly supply,  final Med icationsVO  valueObje ct)
  1254           {
  1255  
  1256                    if(s upply.getR epeatNumbe r() != nul l && suppl y.getRepea tNumber(). getValue()  != null)
  1257                    {
  1258                             valueO bject.setF ills(suppl y.getRepea tNumber(). getValue() .toString( ));
  1259                    }
  1260  
  1261                    // s till not f ound put t he -- stri ng
  1262                    if(v alueObject .getFills( ).isEmpty( ))
  1263                    {
  1264                             valueO bject.setF ills(EMPTY _FIELD);
  1265                    }
  1266  
  1267           }
  1268  
  1269           /* *
  1270            *  Currently  a noop. T he custome r has requ ested this  not be di splayed.
  1271            *  
  1272            *  @param su pply
  1273            *  @param va lueObject
  1274            * /
  1275           pr ivate void  getQuanti tyOrdered( final Supp ly supply,  final Med icationsVO  valueObje ct)
  1276           {
  1277           }
  1278  
  1279           pr ivate void  getOrderi ngProvider (final Sup ply supply , final Me dicationsV O valueObj ect)
  1280           {
  1281  
  1282                    fina l StringBu ilder name String = n ew StringB uilder();
  1283  
  1284                    for( Author aut hor : supp ly.getAuth ors())
  1285                    {
  1286  
  1287                             if(aut hor.getAss ignedAutho r() != nul l && autho r.getAssig nedAuthor( ).getAssig nedPerson( ) != null)
  1288                             {
  1289  
  1290                                      for(PN n ame : auth or.getAssi gnedAuthor ().getAssi gnedPerson ().getName s())
  1291                                      {
  1292                                               nameString .append(th is.createN ame(name)) ;
  1293                                      }
  1294                             }
  1295                    }
  1296  
  1297                    valu eObject.se tOrderingP rovider(na meString.t oString()) ;
  1298  
  1299                    // s till not f ound put t he -- stri ng
  1300                    if(v alueObject .getOrderi ngProvider ().isEmpty ())
  1301                    {
  1302                             valueO bject.setO rderingPro vider(EMPT Y_FIELD);
  1303                    }
  1304  
  1305           }
  1306  
  1307           //  private v oid getFul fillmentIn structions (final Ent ry entry,  final
  1308           //  Medicatio nsVO value Object) {
  1309           //
  1310           //  for (Entr yRelations hip er :
  1311           //  entry.get SubstanceA dministrat ion().getE ntryRelati onships())  {
  1312           //  if (er.ge tAct() !=  null && er .getAct(). getText()  != null) {
  1313           //  valueObje ct.setFulf illmentIns tructions( er.getAct( ).getText( ).getText( ));
  1314           //  }
  1315           //  }
  1316           //
  1317           //  // still  not found  put the --  string
  1318           //  if (Strin gUtils.isB lank(value Object.get Fulfillmen tInstructi ons())) {
  1319           //  valueObje ct.setFulf illmentIns tructions( EMPTY_FIEL D);
  1320           //  }
  1321           //
  1322           //  }
  1323           //
  1324           //  private v oid getFul fillmentHi story(fina l Entry en try, final  Medicatio nsVO
  1325           //  valueObje ct) {
  1326           //
  1327           //  for (Supp ly supply  : entry.ge tSubstance Administra tion().get Supplies() ) {
  1328           //  if (suppl y.getMoodC ode().equa ls(x_Docum entSubstan ceMood.EVN )) {
  1329           //  if (suppl y.getText( ) != null)  {
  1330           //  valueObje ct.setFulf illmentHis tory(suppl y.getText( ).getText( ));
  1331           //  }
  1332           //  }
  1333           //  }
  1334           //
  1335           //  // still  not found  put the --  string
  1336           //  if (Strin gUtils.isB lank(value Object.get Fulfillmen tHistory() )) {
  1337           //  valueObje ct.setFulf illmentHis tory(EMPTY _FIELD);
  1338           //  }
  1339           //
  1340           //  }
  1341           //
  1342  
  1343           /* *
  1344            *  Will proc ess the su pply to fi nd 8.35 &  8.36 Pharm acy Locati on and
  1345            *  dispensin g provider .
  1346            *  
  1347            *  @param su pply
  1348            *  @param va lueObject
  1349            * /
  1350           pr ivate void  getAssign edPharmInf o(final Su pply suppl y, final M edications VO valueOb ject)
  1351           {
  1352  
  1353                    fina l StringBu ilder phar macyLocati on = new S tringBuild er();
  1354  
  1355                    for( Performer2  performer  : supply. getPerform ers())
  1356                    {
  1357                             Assign edEntity a ssigned =  performer. getAssigne dEntity();
  1358                             if(ass igned != n ull)
  1359                             {
  1360                                      Person p erson = as signed.get AssignedPe rson();
  1361                                      // 8.35  Get the na me of the  person dis pensing.
  1362                                      if(perso n != null)
  1363                                      {
  1364                                               StringBuil der sb = n ew StringB uilder();
  1365                                               for(PN nam e : person .getNames( ))
  1366                                               {
  1367                                                       St ring val =  createNam e(name);
  1368                                                       if (StringUti ls.isNotBl ank(val))
  1369                                                       {
  1370                                                                sb.a ppend(val) .append(", ");
  1371                                                       }
  1372                                               }
  1373                                               if(sb.leng th() > 0)
  1374                                               {
  1375                                                       va lueObject. setProvide r(new Item Object(sb. substring( 0, sb.leng th() - 1)) );
  1376                                               }
  1377                                      }
  1378  
  1379                                      // 8.36  Get the pa rmacy loca tion.
  1380                                      for(AD a ddress : a ssigned.ge tAddrs())
  1381                                      {
  1382                                               pharmacyLo cation.app end(this.c reateAddre ss(address ));
  1383                                      }
  1384                             }
  1385                    }
  1386  
  1387                    valu eObject.se tPharmacyL ocation(ph armacyLoca tion.toStr ing());
  1388  
  1389                    // s till not f ound put t he -- stri ng
  1390                    if(! valueObjec t.getPharm acyLocatio n().hasVal ue())
  1391                    {
  1392                             valueO bject.setP harmacyLoc ation(EMPT Y_FIELD);
  1393                    }
  1394  
  1395           }
  1396  
  1397           pr ivate void  getFillNu mberAndSta tus(final  Supply sup ply, final  Medicatio nsVO value Object)
  1398           {
  1399                    for( EntryRelat ionship re l : supply .getEntryR elationshi ps())
  1400                    {
  1401                             if(x_A ctRelation shipEntryR elationshi p.COMP.equ als(rel.ge tTypeCode( )))
  1402                             {
  1403                                      INT seq  = rel.getS equenceNum ber();
  1404                                      if(seq ! = null &&  seq.getVal ue() != nu ll)
  1405                                      {
  1406                                               valueObjec t.setFillN umber(rel. getSequenc eNumber(). getValue() .toString( ));
  1407                                      }
  1408                                      CD code  = supply.g etStatusCo de();
  1409                                      valueObj ect.setFil lStatus(Ut ils.getFro mCode(code , narrativ eText));
  1410                             }
  1411                    }
  1412  
  1413                    // s till not f ound put t he -- stri ng
  1414                    if(! valueObjec t.getFillN umber().ha sValue())
  1415                    {
  1416                             valueO bject.setF illNumber( EMPTY_FIEL D);
  1417                    }
  1418  
  1419                    // s till not f ound put t he -- stri ng
  1420                    if(! valueObjec t.getFillS tatus().ha sValue())
  1421                    {
  1422                             valueO bject.setF illStatus( EMPTY_FIEL D);
  1423                    }
  1424  
  1425           }
  1426  
  1427           /* *
  1428            *  @return t he narrati veText
  1429            * /
  1430           pu blic final  StrucDocT ext getNar rativeText ()
  1431           {
  1432                    retu rn narrati veText;
  1433           }
  1434  
  1435           /* *
  1436            *  @param na rrativeTex t the narr ativeText  to set
  1437            * /
  1438           pu blic final  void setN arrativeTe xt(StrucDo cText narr ativeText)
  1439           {
  1440                    this .narrative Text = nar rativeText ;
  1441           }
  1442  
  1443           @O verride
  1444           pr otected vo id createO bjects()
  1445           {
  1446  
  1447           }
  1448  
  1449           pr ivate Stri ng createN ame(final  PN name)
  1450           {
  1451                    fina l StringBu ilder sb =  new Strin gBuilder() ;
  1452  
  1453                    if(S tringUtils .isNotBlan k(name.get Text()))
  1454                    {
  1455                             return  name.getT ext();
  1456                    }
  1457  
  1458                    if(S tringUtils .isNotBlan k(loopForN ame(name.g etPrefixes ())))
  1459                    {
  1460                             sb.app end(loopFo rName(name .getPrefix es())).app end(" ");
  1461                    }
  1462  
  1463                    if(S tringUtils .isNotBlan k(loopForN ame(name.g etGivens() )))
  1464                    {
  1465                             sb.app end(loopFo rName(name .getGivens ())).appen d(" ");
  1466                    }
  1467  
  1468                    if(S tringUtils .isNotBlan k(loopForN ame(name.g etFamilies ())))
  1469                    {
  1470                             sb.app end(loopFo rName(name .getFamili es())).app end(" ");
  1471                    }
  1472  
  1473                    if(S tringUtils .isNotBlan k(loopForN ame(name.g etSuffixes ())))
  1474                    {
  1475                             sb.app end(loopFo rName(name .getSuffix es())).app end(" ");
  1476                    }
  1477                    retu rn sb.toSt ring();
  1478           }
  1479  
  1480           pr ivate Stri ng loopFor Name(final  EList<ENX P> names)
  1481           {
  1482                    for( ENXP name  : names)
  1483                    {
  1484                             if(Str ingUtils.i sNotBlank( name.getTe xt()))
  1485                             {
  1486                                      return n ame.getTex t();
  1487                             }
  1488                    }
  1489  
  1490                    retu rn null;
  1491           }
  1492  
  1493           pr ivate Stri ng createA ddress(fin al AD addr ess)
  1494           {
  1495                    Stri ngBuilder  sb = new S tringBuild er();
  1496                    for( ADXP stree t : addres s.getStree tAddressLi nes())
  1497                    {
  1498                             if(Str ingUtils.i sNotBlank( street.get Text()))
  1499                             {
  1500                                      sb.appen d(street.g etText()). append(" " );
  1501                             }
  1502                    }
  1503  
  1504                    for( ADXP city  : address. getCities( ))
  1505                    {
  1506                             if(Str ingUtils.i sNotBlank( city.getTe xt()))
  1507                             {
  1508                                      sb.appen d(city.get Text()).ap pend(", ") ;
  1509                             }
  1510                    }
  1511  
  1512                    for( ADXP state  : address .getStates ())
  1513                    {
  1514                             if(Str ingUtils.i sNotBlank( state.getT ext()))
  1515                             {
  1516                                      sb.appen d(state.ge tText()).a ppend(" ") ;
  1517                             }
  1518                    }
  1519  
  1520                    for( ADXP zip :  address.g etPostalCo des())
  1521                    {
  1522                             if(Str ingUtils.i sNotBlank( zip.getTex t()))
  1523                             {
  1524                                      sb.appen d(zip.getT ext());
  1525                             }
  1526                    }
  1527  
  1528                    retu rn sb.toSt ring();
  1529           }
  1530   }