762. EPMO Open Source Coordination Office Redaction File Detail Report

Produced by Araxis Merge on 10/18/2018 2:02:17 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.

762.1 Files compared

# Location File Last Modified
1 VIX_SIV_v3_0_patch_201_build_8.zip\v3.0_patch_201_build_8\VISA\Java\FederationCommon\main\src\java\gov\va\med\imaging\federation\rest\translator FederationRestTranslator.java Thu Oct 11 13:30:14 2018 UTC
2 VIX_SIV_v3_0_patch_201_build_8.zip\v3.0_patch_201_build_8\VISA\Java\FederationCommon\main\src\java\gov\va\med\imaging\federation\rest\translator FederationRestTranslator.java Wed Oct 17 18:48:50 2018 UTC

762.2 Comparison summary

Description Between
Files 1 and 2
Text Blocks Lines
Unchanged 3 5388
Changed 2 4
Inserted 0 0
Removed 0 0

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

762.4 Active regular expressions

No regular expressions were active.

762.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: May  15, 2010
  6     Site Nam e:  Washin gton OI Fi eld Office , Silver S pring, MD
  7       Developer:     PII
  8     Descript ion: 
  9  
  10           ;;  +-------- ---------- ---------- ---------- ---------- ---------- ---------- +
  11           ;;  Property  of the US  Government .
  12           ;;  No permis sion to co py or redi stribute t his softwa re is give n.
  13           ;;  Use of un released v ersions of  this soft ware requi res the us er
  14           ;;   to execu te a writt en test ag reement wi th the Vis tA Imaging
  15           ;;   Developm ent Office  of the De partment o f Veterans  Affairs,
  16           ;;   telephon e (301) 73 4-0100.
  17           ;;
  18           ;;  The Food  and Drug A dministrat ion classi fies this  software a s
  19           ;;  a Class I I medical  device.  A s such, it  may not b e changed
  20           ;;  in any wa y.  Modifi cations to  this soft ware may r esult in a n
  21           ;;  adulterat ed medical  device un der 21CFR8 20, the us e of which
  22           ;;  is consid ered to be  a violati on of US F ederal Sta tutes.
  23           ;;  +-------- ---------- ---------- ---------- ---------- ---------- ---------- +
  24  
  25    */
  26   package go v.va.med.i maging.fed eration.re st.transla tor;
  27  
  28   import gov .va.med.Gl obalArtifa ctIdentifi er;
  29   import gov .va.med.Gl obalArtifa ctIdentifi erFactory;
  30   import gov .va.med.He althSummar yURN;
  31   import gov .va.med.Me diaType;
  32   import gov .va.med.OI D;
  33   import gov .va.med.Pa tientArtif actIdentif ierImpl;
  34   import gov .va.med.Pa tientIdent ifier;
  35   import gov .va.med.Ro utingToken ;
  36   import gov .va.med.Ro utingToken Impl;
  37   import gov .va.med.SE RIALIZATIO N_FORMAT;
  38   import gov .va.med.UR N;
  39   import gov .va.med.UR NFactory;
  40   import gov .va.med.ex ceptions.G lobalArtif actIdentif ierFormatE xception;
  41   import gov .va.med.ex ceptions.R outingToke nFormatExc eption;
  42   import gov .va.med.im aging.Abst ractImagin gURN;
  43   import gov .va.med.im aging.Cprs Identifier ;
  44   import gov .va.med.im aging.Imag eAnnotatio nURN;
  45   import gov .va.med.im aging.Imag eURN;
  46   import gov .va.med.im aging.Stri ngUtil;
  47   import gov .va.med.im aging.Stud yURN;
  48   import gov .va.med.im aging.arti factsource .ResolvedA rtifactSou rce;
  49   import gov .va.med.im aging.chan nels.Check sumValue;
  50   import gov .va.med.im aging.core .interface s.exceptio ns.MethodE xception;
  51   import gov .va.med.im aging.exce ptions.OID FormatExce ption;
  52   import gov .va.med.im aging.exce ptions.URN FormatExce ption;
  53   import gov .va.med.im aging.exch ange.Image AccessLogE vent;
  54   import gov .va.med.im aging.exch ange.Image AccessLogE vent.Image AccessLogE ventType;
  55   import gov .va.med.im aging.exch ange.Imagi ngLogEvent ;
  56   import gov .va.med.im aging.exch ange.Proce dureFilter ;
  57   import gov .va.med.im aging.exch ange.busin ess.Artifa ctResultEr ror;
  58   import gov .va.med.im aging.exch ange.busin ess.Artifa ctResults;
  59   import gov .va.med.im aging.exch ange.busin ess.Divisi on;
  60   import gov .va.med.im aging.exch ange.busin ess.Docume ntFilter;
  61   import gov .va.med.im aging.exch ange.busin ess.Electr onicSignat ureResult;
  62   import gov .va.med.im aging.exch ange.busin ess.Health SummaryTyp e;
  63   import gov .va.med.im aging.exch ange.busin ess.Image;
  64   import gov .va.med.im aging.exch ange.busin ess.ImageA ccessReaso n;
  65   import gov .va.med.im aging.exch ange.busin ess.ImageF ormatQuali ty;
  66   import gov .va.med.im aging.exch ange.busin ess.ImageF ormatQuali tyList;
  67   import gov .va.med.im aging.exch ange.busin ess.Passth roughInput Method;
  68   import gov .va.med.im aging.exch ange.busin ess.Passth roughParam eter;
  69   import gov .va.med.im aging.exch ange.busin ess.Passth roughParam eterType;
  70   import gov .va.med.im aging.exch ange.busin ess.Patien t;
  71   import gov .va.med.im aging.exch ange.busin ess.Patien t.PatientS ex;
  72   import gov .va.med.im aging.exch ange.busin ess.Patien tMeansTest Result;
  73   import gov .va.med.im aging.exch ange.busin ess.Patien tSensitive Value;
  74   import gov .va.med.im aging.exch ange.busin ess.Series ;
  75   import gov .va.med.im aging.exch ange.busin ess.Study;
  76   import gov .va.med.im aging.exch ange.busin ess.StudyF ilter;
  77   import gov .va.med.im aging.exch ange.busin ess.StudyS etResult;
  78   import gov .va.med.im aging.exch ange.busin ess.User;
  79   import gov .va.med.im aging.exch ange.busin ess.UserIn formation;
  80   import gov .va.med.im aging.exch ange.busin ess.annota tions.Imag eAnnotatio n;
  81   import gov .va.med.im aging.exch ange.busin ess.annota tions.Imag eAnnotatio nDetails;
  82   import gov .va.med.im aging.exch ange.busin ess.annota tions.Imag eAnnotatio nSource;
  83   import gov .va.med.im aging.exch ange.busin ess.annota tions.Imag eAnnotatio nUser;
  84   import gov .va.med.im aging.exch ange.busin ess.docume nts.Docume nt;
  85   import gov .va.med.im aging.exch ange.busin ess.docume nts.Docume ntSet;
  86   import gov .va.med.im aging.exch ange.busin ess.docume nts.Docume ntSetResul t;
  87   import gov .va.med.im aging.exch ange.busin ess.vistar ad.ActiveE xam;
  88   import gov .va.med.im aging.exch ange.busin ess.vistar ad.ActiveE xams;
  89   import gov .va.med.im aging.exch ange.busin ess.vistar ad.Exam;
  90   import gov .va.med.im aging.exch ange.busin ess.vistar ad.ExamIma ge;
  91   import gov .va.med.im aging.exch ange.busin ess.vistar ad.ExamIma ges;
  92   import gov .va.med.im aging.exch ange.busin ess.vistar ad.ExamLis tResult;
  93   import gov .va.med.im aging.exch ange.busin ess.vistar ad.ExamSit e;
  94   import gov .va.med.im aging.exch ange.busin ess.vistar ad.Patient Registrati on;
  95   import gov .va.med.im aging.exch ange.enums .ArtifactR esultError Code;
  96   import gov .va.med.im aging.exch ange.enums .ArtifactR esultError Severity;
  97   import gov .va.med.im aging.exch ange.enums .ArtifactR esultStatu s;
  98   import gov .va.med.im aging.exch ange.enums .ImageAcce ssReasonTy pe;
  99   import gov .va.med.im aging.exch ange.enums .ImageForm at;
  100   import gov .va.med.im aging.exch ange.enums .ImageQual ity;
  101   import gov .va.med.im aging.exch ange.enums .ObjectOri gin;
  102   import gov .va.med.im aging.exch ange.enums .ObjectSta tus;
  103   import gov .va.med.im aging.exch ange.enums .PatientSe nsitivityL evel;
  104   import gov .va.med.im aging.exch ange.enums .Procedure FilterMatc hMode;
  105   import gov .va.med.im aging.exch ange.enums .StudyDele tedImageSt ate;
  106   import gov .va.med.im aging.exch ange.enums .StudyLoad Level;
  107   import gov .va.med.im aging.exch ange.enums .vistarad. ExamStatus ;
  108   import gov .va.med.im aging.exch ange.trans lation.Abs tractTrans lator;
  109   import gov .va.med.im aging.exch ange.trans lation.exc eptions.Tr anslationE xception;
  110   import gov .va.med.im aging.fede ration.Fed erationArt ifactResul tError;
  111   import gov .va.med.im aging.fede ration.Fed erationUse r;
  112   import gov .va.med.im aging.fede ration.res t.types.Fe derationAc tiveExamTy pe;
  113   import gov .va.med.im aging.fede ration.res t.types.Fe derationAc tiveExamsT ype;
  114   import gov .va.med.im aging.fede ration.res t.types.Fe derationAr tifactResu ltErrorCod eType;
  115   import gov .va.med.im aging.fede ration.res t.types.Fe derationAr tifactResu ltErrorSev erityType;
  116   import gov .va.med.im aging.fede ration.res t.types.Fe derationAr tifactResu ltErrorTyp e;
  117   import gov .va.med.im aging.fede ration.res t.types.Fe derationAr tifactResu ltStatusTy pe;
  118   import gov .va.med.im aging.fede ration.res t.types.Fe derationAr tifactResu ltsType;
  119   import gov .va.med.im aging.fede ration.res t.types.Fe derationCh ecksumType ;
  120   import gov .va.med.im aging.fede ration.res t.types.Fe derationCp rsIdentifi erType;
  121   import gov .va.med.im aging.fede ration.res t.types.Fe derationCp rsIdentifi ersType;
  122   import gov .va.med.im aging.fede ration.res t.types.Fe derationDi visionType ;
  123   import gov .va.med.im aging.fede ration.res t.types.Fe derationDo cumentFilt erType;
  124   import gov .va.med.im aging.fede ration.res t.types.Fe derationDo cumentSetR esultType;
  125   import gov .va.med.im aging.fede ration.res t.types.Fe derationDo cumentSetT ype;
  126   import gov .va.med.im aging.fede ration.res t.types.Fe derationDo cumentType ;
  127   import gov .va.med.im aging.fede ration.res t.types.Fe derationEl ectronicSi gnatureRes ultType;
  128   import gov .va.med.im aging.fede ration.res t.types.Fe derationEx amImageTyp e;
  129   import gov .va.med.im aging.fede ration.res t.types.Fe derationEx amImagesTy pe;
  130   import gov .va.med.im aging.fede ration.res t.types.Fe derationEx amResultTy pe;
  131   import gov .va.med.im aging.fede ration.res t.types.Fe derationEx amStatusTy pe;
  132   import gov .va.med.im aging.fede ration.res t.types.Fe derationEx amType;
  133   import gov .va.med.im aging.fede ration.res t.types.Fe derationFi lterType;
  134   import gov .va.med.im aging.fede ration.res t.types.Fe derationHe althSummar yType;
  135   import gov .va.med.im aging.fede ration.res t.types.Fe derationIm ageAccessL ogEventTyp e;
  136   import gov .va.med.im aging.fede ration.res t.types.Fe derationIm ageAccessL ogEventTyp eType;
  137   import gov .va.med.im aging.fede ration.res t.types.Fe derationIm ageAccessR easonType;
  138   import gov .va.med.im aging.fede ration.res t.types.Fe derationIm ageAccessR easonTypeH olderType;
  139   import gov .va.med.im aging.fede ration.res t.types.Fe derationIm ageAccessR easonTypeT ype;
  140   import gov .va.med.im aging.fede ration.res t.types.Fe derationIm ageAnnotat ionDetails Type;
  141   import gov .va.med.im aging.fede ration.res t.types.Fe derationIm ageAnnotat ionSourceT ype;
  142   import gov .va.med.im aging.fede ration.res t.types.Fe derationIm ageAnnotat ionType;
  143   import gov .va.med.im aging.fede ration.res t.types.Fe derationIm ageAnnotat ionUserTyp e;
  144   import gov .va.med.im aging.fede ration.res t.types.Fe derationIm ageFormatQ ualitiesTy pe;
  145   import gov .va.med.im aging.fede ration.res t.types.Fe derationIm ageFormatQ ualityType ;
  146   import gov .va.med.im aging.fede ration.res t.types.Fe derationIm ageType;
  147   import gov .va.med.im aging.fede ration.res t.types.Fe derationIm agingLogEv entType;
  148   import gov .va.med.im aging.fede ration.res t.types.Fe derationMe diaType;
  149   import gov .va.med.im aging.fede ration.res t.types.Fe derationOb jectStatus Type;
  150   import gov .va.med.im aging.fede ration.res t.types.Fe derationPa tientMeans TestResult Type;
  151   import gov .va.med.im aging.fede ration.res t.types.Fe derationPa tientRegis trationTyp e;
  152   import gov .va.med.im aging.fede ration.res t.types.Fe derationPa tientSensi tiveType;
  153   import gov .va.med.im aging.fede ration.res t.types.Fe derationPa tientSensi tivityLeve lType;
  154   import gov .va.med.im aging.fede ration.res t.types.Fe derationPa tientSexTy pe;
  155   import gov .va.med.im aging.fede ration.res t.types.Fe derationPa tientType;
  156   import gov .va.med.im aging.fede ration.res t.types.Fe derationRe moteMethod ParameterT ype;
  157   import gov .va.med.im aging.fede ration.res t.types.Fe derationRe moteMethod ParameterT ypeType;
  158   import gov .va.med.im aging.fede ration.res t.types.Fe derationRe moteMethod ParameterV alueType;
  159   import gov .va.med.im aging.fede ration.res t.types.Fe derationRe moteMethod Type;
  160   import gov .va.med.im aging.fede ration.res t.types.Fe derationSe riesType;
  161   import gov .va.med.im aging.fede ration.res t.types.Fe derationSt ringArrayT ype;
  162   import gov .va.med.im aging.fede ration.res t.types.Fe derationSt udyDeleted ImageState Type;
  163   import gov .va.med.im aging.fede ration.res t.types.Fe derationSt udyLoadLev elType;
  164   import gov .va.med.im aging.fede ration.res t.types.Fe derationSt udyResultT ype;
  165   import gov .va.med.im aging.fede ration.res t.types.Fe derationSt udyType;
  166   import gov .va.med.im aging.fede ration.res t.types.Fe derationUs erInformat ionType;
  167   import gov .va.med.im aging.fede ration.res t.types.Fe derationUs erType;
  168  
  169   import jav a.text.Par seExceptio n;
  170   import jav a.util.Arr ayList;
  171   import jav a.util.Col lection;
  172   import jav a.util.Has hMap;
  173   import jav a.util.Ite rator;
  174   import jav a.util.Lis t;
  175   import jav a.util.Map ;
  176   import jav a.util.Map .Entry;
  177   import jav a.util.Set ;
  178   import jav a.util.Sor tedSet;
  179   import jav a.util.Tre eSet;
  180  
  181   import org .apache.lo gging.log4 j.LogManag er;
  182   import org .apache.lo gging.log4 j.Logger;
  183  
  184   /**
  185    * @author   DPII
  186    *
  187    */
  188   public cla ss Federat ionRestTra nslator
  189   extends Ab stractTran slator
  190   {
  191           pr ivate stat ic Map<Stu dyLoadLeve l, Federat ionStudyLo adLevelTyp e> loadLev elMap;
  192           pr ivate stat ic Map<Pas sthroughPa rameterTyp e, Federat ionRemoteM ethodParam eterTypeTy pe> parame terTypeMap ;
  193           pr ivate stat ic Map<Exa mStatus, F ederationE xamStatusT ype> examS tatusMap;
  194           pr ivate stat ic Map<Ima geAccessLo gEventType , Federati onImageAcc essLogEven tTypeType>  imageAcce ssMap;
  195           pr ivate stat ic Map<Pat ientSensit ivityLevel , Federati onPatientS ensitivity LevelType>  patientSe nsitiveLev elMap;
  196           pr ivate stat ic Map<Pat ientSex, F ederationP atientSexT ype> patie ntSexMap;
  197           pr ivate stat ic Map<Obj ectStatus,  Federatio nObjectSta tusType> o bjectStatu sMap;
  198           pr ivate stat ic Map<Stu dyDeletedI mageState,  Federatio nStudyDele tedImageSt ateType> s tudyDelete dImageStat eMap;
  199           pr ivate stat ic Map<Art ifactResul tStatus, F ederationA rtifactRes ultStatusT ype> artif actResultS tatusMap;
  200           pr ivate stat ic Map<Med iaType, Fe derationMe diaType> m ediaTypeMa p;
  201           pr ivate stat ic Map<Art ifactResul tErrorCode , Federati onArtifact ResultErro rCodeType>  artifactR esultError CodeMap;
  202           pr ivate stat ic Map<Art ifactResul tErrorSeve rity, Fede rationArti factResult ErrorSever ityType> a rtifactRes ultErrorSe verityMap;
  203           pr ivate stat ic Map<Ima geAnnotati onSource,  Federation ImageAnnot ationSourc eType> ima geAnnotati onSourceMa p;
  204           pr ivate stat ic Map<Ima geAccessRe asonType,  Federation ImageAcces sReasonTyp eType> ima geAccessRe asonTypesM ap;
  205           
  206           st atic
  207           {
  208                    load LevelMap =  new HashM ap<StudyLo adLevel, F ederationS tudyLoadLe velType>() ;
  209                    load LevelMap.p ut(StudyLo adLevel.FU LL, Federa tionStudyL oadLevelTy pe.FULL);
  210                    load LevelMap.p ut(StudyLo adLevel.ST UDY_AND_RE PORT, Fede rationStud yLoadLevel Type.STUDY _AND_REPOR T);
  211                    load LevelMap.p ut(StudyLo adLevel.ST UDY_AND_IM AGES, Fede rationStud yLoadLevel Type.STUDY _AND_IMAGE S);
  212                    load LevelMap.p ut(StudyLo adLevel.ST UDY_ONLY,  Federation StudyLoadL evelType.S TUDY_ONLY) ;
  213                    load LevelMap.p ut(StudyLo adLevel.ST UDY_ONLY_N OSERIES, F ederationS tudyLoadLe velType.ST UDY_ONLY_N OSERIES);
  214                    
  215                    para meterTypeM ap = new H ashMap<Pas sthroughPa rameterTyp e, Federat ionRemoteM ethodParam eterTypeTy pe>();
  216                    para meterTypeM ap.put(Pas sthroughPa rameterTyp e.literal,  Federatio nRemoteMet hodParamet erTypeType .LITERAL);
  217                    para meterTypeM ap.put(Pas sthroughPa rameterTyp e.list, Fe derationRe moteMethod ParameterT ypeType.LI ST);
  218                    para meterTypeM ap.put(Pas sthroughPa rameterTyp e.referenc e, Federat ionRemoteM ethodParam eterTypeTy pe.REFEREN CE);
  219                    
  220                    exam StatusMap  = new Hash Map<ExamSt atus, Fede rationExam StatusType >();
  221                    exam StatusMap. put(ExamSt atus.INTER PRETED, Fe derationEx amStatusTy pe.INTERPR ETED);
  222                    exam StatusMap. put(ExamSt atus.NOT_I NTERPRETED , Federati onExamStat usType.NOT _INTERPRET ED);
  223                    
  224                    imag eAccessMap  = new Has hMap<Image AccessLogE ventType,  Federation ImageAcces sLogEventT ypeType>() ;
  225                    imag eAccessMap .put(Image AccessLogE ventType.I MAGE_COPY,  Federatio nImageAcce ssLogEvent TypeType.I MAGE_COPY) ;
  226                    imag eAccessMap .put(Image AccessLogE ventType.I MAGE_PRINT , Federati onImageAcc essLogEven tTypeType. IMAGE_PRIN T); 
  227                    imag eAccessMap .put(Image AccessLogE ventType.P ATIENT_ID_ MISMATCH,  Federation ImageAcces sLogEventT ypeType.PA TIENT_ID_M ISMATCH); 
  228                    imag eAccessMap .put(Image AccessLogE ventType.R ESTRICTED_ ACCESS, Fe derationIm ageAccessL ogEventTyp eType.REST RICTED_ACC ESS); 
  229                    imag eAccessMap .put(Image AccessLogE ventType.I MAGE_ACCES S,  Federa tionImageA ccessLogEv entTypeTyp e.IMAGE_AC CESS);
  230                    
  231                    pati entSensiti veLevelMap  = new Has hMap<Patie ntSensitiv ityLevel,  Federation PatientSen sitivityLe velType>() ;
  232                    pati entSensiti veLevelMap .put(Patie ntSensitiv ityLevel.A CCESS_DENI ED, Federa tionPatien tSensitivi tyLevelTyp e.ACCESS_D ENIED);
  233                    pati entSensiti veLevelMap .put(Patie ntSensitiv ityLevel.D ATASOURCE_ FAILURE, F ederationP atientSens itivityLev elType.DAT ASOURCE_FA ILURE);
  234                    pati entSensiti veLevelMap .put(Patie ntSensitiv ityLevel.D ISPLAY_WAR NING, Fede rationPati entSensiti vityLevelT ype.DISPLA Y_WARNING) ;
  235                    pati entSensiti veLevelMap .put(Patie ntSensitiv ityLevel.D ISPLAY_WAR NING_CANNO T_CONTINUE
  236                                      Federati onPatientS ensitivity LevelType. DISPLAY_WA RNING_CANN OT_CONTINU E);
  237                    pati entSensiti veLevelMap .put(Patie ntSensitiv ityLevel.D ISPLAY_WAR NING_REQUI RE_OK, Fed erationPat ientSensit ivityLevel Type.DISPL AY_WARNING _REQUIRE_O K);
  238                    pati entSensiti veLevelMap .put(Patie ntSensitiv ityLevel.N O_ACTION_R EQUIRED, F ederationP atientSens itivityLev elType.NO_ ACTION_REQ UIRED);
  239                    
  240                    pati entSexMap  = new Hash Map<Patien tSex, Fede rationPati entSexType >();
  241                    pati entSexMap. put(Patien tSex.Male,  Federatio nPatientSe xType.Male );
  242                    pati entSexMap. put(Patien tSex.Femal e, Federat ionPatient SexType.Fe male);
  243                    pati entSexMap. put(Patien tSex.Unkno wn, Federa tionPatien tSexType.U nknown);
  244                    
  245                    obje ctStatusMa p = new Ha shMap<Obje ctStatus,  Federation ObjectStat usType>();
  246                    obje ctStatusMa p.put(Obje ctStatus.C ONTROLLED,  Federatio nObjectSta tusType.CO NTROLLED);
  247                    obje ctStatusMa p.put(Obje ctStatus.D ELETED, Fe derationOb jectStatus Type.DELET ED);
  248                    obje ctStatusMa p.put(Obje ctStatus.I MAGE_GROUP , Federati onObjectSt atusType.I MAGE_GROUP );
  249                    obje ctStatusMa p.put(Obje ctStatus.I N_PROGRESS , Federati onObjectSt atusType.I N_PROGRESS );
  250                    obje ctStatusMa p.put(Obje ctStatus.N EEDS_REFRE SH, Federa tionObject StatusType .NEEDS_REF RESH);
  251                    obje ctStatusMa p.put(Obje ctStatus.N EEDS_REVIE W, Federat ionObjectS tatusType. NEEDS_REVI EW);
  252                    obje ctStatusMa p.put(Obje ctStatus.N O_STATUS,  Federation ObjectStat usType.NO_ STATUS);
  253                    obje ctStatusMa p.put(Obje ctStatus.Q A_REVIEWED , Federati onObjectSt atusType.Q A_REVIEWED );
  254                    obje ctStatusMa p.put(Obje ctStatus.Q UESTIONABL E_INTEGRIT Y, Federat ionObjectS tatusType. QUESTIONAB LE_INTEGRI TY);
  255                    obje ctStatusMa p.put(Obje ctStatus.R AD_EXAM_ST ATUS_BLOCK , Federati onObjectSt atusType.R AD_EXAM_ST ATUS_BLOCK );
  256                    obje ctStatusMa p.put(Obje ctStatus.T IU_AUTHORI ZATION_BLO CK, Federa tionObject StatusType .TIU_AUTHO RIZATION_B LOCK);
  257                    obje ctStatusMa p.put(Obje ctStatus.U NKNOWN, Fe derationOb jectStatus Type.UNKNO WN);
  258                    obje ctStatusMa p.put(Obje ctStatus.V IEWABLE, F ederationO bjectStatu sType.VIEW ABLE);
  259                    
  260                    stud yDeletedIm ageStateMa p = new Ha shMap<Stud yDeletedIm ageState,  Federation StudyDelet edImageSta teType>();
  261                    stud yDeletedIm ageStateMa p.put(Stud yDeletedIm ageState.c annotInclu deDeletedI mages, Fed erationStu dyDeletedI mageStateT ype.cannot IncludeDel etedImages );
  262                    stud yDeletedIm ageStateMa p.put(Stud yDeletedIm ageState.d oesNotIncl udeDeleted Images, Fe derationSt udyDeleted ImageState Type.doesN otIncludeD eletedImag es);
  263                    stud yDeletedIm ageStateMa p.put(Stud yDeletedIm ageState.i ncludesDel etedImages , Federati onStudyDel etedImageS tateType.i ncludesDel etedImages );
  264                    
  265                    arti factResult StatusMap  = new Hash Map<Artifa ctResultSt atus, Fede rationArti factResult StatusType >();
  266                    arti factResult StatusMap. put(Artifa ctResultSt atus.fullR esult, Fed erationArt ifactResul tStatusTyp e.fullResu lt);
  267                    arti factResult StatusMap. put(Artifa ctResultSt atus.parti alResult,  Federation ArtifactRe sultStatus Type.parti alResult);
  268                    arti factResult StatusMap. put(Artifa ctResultSt atus.error Result, Fe derationAr tifactResu ltStatusTy pe.errorRe sult);
  269                    
  270                    medi aTypeMap =  new HashM ap<MediaTy pe, Federa tionMediaT ype>();
  271                    medi aTypeMap.p ut(MediaTy pe.APPLICA TION_DICOM , Federati onMediaTyp e.APPLICAT ION_DICOM) ;
  272                    medi aTypeMap.p ut(MediaTy pe.APPLICA TION_DOC,  Federation MediaType. APPLICATIO N_DOC);
  273                    medi aTypeMap.p ut(MediaTy pe.APPLICA TION_OCTET STREAM, Fe derationMe diaType.AP PLICATION_ OCTETSTREA M);
  274                    medi aTypeMap.p ut(MediaTy pe.APPLICA TION_PDF,  Federation MediaType. APPLICATIO N_PDF);
  275                    medi aTypeMap.p ut(MediaTy pe.APPLICA TION_EXCEL , Federati onMediaTyp e.APPLICAT ION_EXCEL) ;
  276                    medi aTypeMap.p ut(MediaTy pe.APPLICA TION_PPT,  Federation MediaType. APPLICATIO N_PPT);
  277                    medi aTypeMap.p ut(MediaTy pe.APPLICA TION_RTF,  Federation MediaType. APPLICATIO N_RTF);
  278                    medi aTypeMap.p ut(MediaTy pe.APPLICA TION_DOCX,  Federatio nMediaType .APPLICATI ON_DOCX);
  279                    medi aTypeMap.p ut(MediaTy pe.AUDIO_M P4, Federa tionMediaT ype.AUDIO_ MP4);
  280                    medi aTypeMap.p ut(MediaTy pe.AUDIO_M PEG, Feder ationMedia Type.AUDIO _MPEG);
  281                    medi aTypeMap.p ut(MediaTy pe.AUDIO_W AV, Federa tionMediaT ype.AUDIO_ WAV);
  282                    medi aTypeMap.p ut(MediaTy pe.IMAGE_B MP, Federa tionMediaT ype.IMAGE_ BMP);
  283                    medi aTypeMap.p ut(MediaTy pe.IMAGE_X BMP, Feder ationMedia Type.IMAGE _XBMP);
  284                    medi aTypeMap.p ut(MediaTy pe.IMAGE_J 2K, Federa tionMediaT ype.IMAGE_ J2K);
  285                    medi aTypeMap.p ut(MediaTy pe.IMAGE_J P2, Federa tionMediaT ype.IMAGE_ JP2);
  286                    medi aTypeMap.p ut(MediaTy pe.IMAGE_J PEG, Feder ationMedia Type.IMAGE _JPEG);
  287                    medi aTypeMap.p ut(MediaTy pe.IMAGE_P NG, Federa tionMediaT ype.IMAGE_ PNG);
  288                    medi aTypeMap.p ut(MediaTy pe.IMAGE_T GA, Federa tionMediaT ype.IMAGE_ TGA);
  289                    medi aTypeMap.p ut(MediaTy pe.IMAGE_T IFF, Feder ationMedia Type.IMAGE _TIFF);
  290                    medi aTypeMap.p ut(MediaTy pe.MULTIPA RT_FORM_DA TA, Federa tionMediaT ype.MULTIP ART_FORM_D ATA);
  291                    medi aTypeMap.p ut(MediaTy pe.MULTIPA RT_MIXED,  Federation MediaType. MULTIPART_ MIXED);
  292                    medi aTypeMap.p ut(MediaTy pe.TEXT_CS S, Federat ionMediaTy pe.TEXT_CS S);
  293                    medi aTypeMap.p ut(MediaTy pe.TEXT_CS V, Federat ionMediaTy pe.TEXT_CS V);
  294                    medi aTypeMap.p ut(MediaTy pe.TEXT_EN RICHED, Fe derationMe diaType.TE XT_ENRICHE D);
  295                    medi aTypeMap.p ut(MediaTy pe.TEXT_HT ML, Federa tionMediaT ype.TEXT_H TML);
  296                    medi aTypeMap.p ut(MediaTy pe.TEXT_PL AIN, Feder ationMedia Type.TEXT_ PLAIN);
  297                    medi aTypeMap.p ut(MediaTy pe.TEXT_RT F, Federat ionMediaTy pe.TEXT_RT F);
  298                    medi aTypeMap.p ut(MediaTy pe.TEXT_TS V, Federat ionMediaTy pe.TEXT_TS V);
  299                    medi aTypeMap.p ut(MediaTy pe.TEXT_UR I_LIST, Fe derationMe diaType.TE XT_URI_LIS T);
  300                    medi aTypeMap.p ut(MediaTy pe.TEXT_XM L, Federat ionMediaTy pe.TEXT_XM L);
  301                    medi aTypeMap.p ut(MediaTy pe.TEXT_XM L_EXTERNAL _PARSED_EN TITY, Fede rationMedi aType.TEXT _XML_EXTER NAL_PARSED _ENTITY);                 
  302                    medi aTypeMap.p ut(MediaTy pe.VIDEO_A VI, Federa tionMediaT ype.VIDEO_ AVI);
  303                    medi aTypeMap.p ut(MediaTy pe.VIDEO_B MPEG, Fede rationMedi aType.VIDE O_BMPEG);
  304                    medi aTypeMap.p ut(MediaTy pe.VIDEO_J PEG, Feder ationMedia Type.VIDEO _JPEG);
  305                    medi aTypeMap.p ut(MediaTy pe.VIDEO_J PEG2000, F ederationM ediaType.V IDEO_JPEG2 000);
  306                    medi aTypeMap.p ut(MediaTy pe.VIDEO_M P4, Federa tionMediaT ype.VIDEO_ MP4);
  307                    medi aTypeMap.p ut(MediaTy pe.VIDEO_M PEG, Feder ationMedia Type.VIDEO _MPEG);
  308                    medi aTypeMap.p ut(MediaTy pe.VIDEO_M PEG4_GENER IC, Federa tionMediaT ype.VIDEO_ MPEG4_GENE RIC);
  309                    medi aTypeMap.p ut(MediaTy pe.VIDEO_O GG, Federa tionMediaT ype.VIDEO_ OGG);
  310                    medi aTypeMap.p ut(MediaTy pe.VIDEO_Q UICKTIME,  Federation MediaType. VIDEO_QUIC KTIME);
  311                    
  312                    arti factResult ErrorCodeM ap = new H ashMap<Art ifactResul tErrorCode , Federati onArtifact ResultErro rCodeType> ();
  313                    arti factResult ErrorCodeM ap.put(Art ifactResul tErrorCode .authoriza tionExcept ion, Feder ationArtif actResultE rrorCodeTy pe.authori zationExce ption);
  314                    arti factResult ErrorCodeM ap.put(Art ifactResul tErrorCode .internalE xception,  Federation ArtifactRe sultErrorC odeType.in ternalExce ption);
  315                    arti factResult ErrorCodeM ap.put(Art ifactResul tErrorCode .invalidRe questExcep tion, Fede rationArti factResult ErrorCodeT ype.invali dRequestEx ception);
  316                    arti factResult ErrorCodeM ap.put(Art ifactResul tErrorCode .timeoutEx ception, F ederationA rtifactRes ultErrorCo deType.tim eoutExcept ion);
  317                    arti factResult ErrorCodeM ap.put(Art ifactResul tErrorCode .unknownPa tientId, F ederationA rtifactRes ultErrorCo deType.unk nownPatien tId);
  318                    
  319                    arti factResult ErrorSever ityMap = n ew HashMap <ArtifactR esultError Severity,  Federation ArtifactRe sultErrorS everityTyp e>();
  320                    arti factResult ErrorSever ityMap.put (ArtifactR esultError Severity.e rror, Fede rationArti factResult ErrorSever ityType.er ror);
  321                    arti factResult ErrorSever ityMap.put (ArtifactR esultError Severity.w arning, Fe derationAr tifactResu ltErrorSev erityType. warning);
  322                    
  323                    imag eAnnotatio nSourceMap  = new Has hMap<Image Annotation Source, Fe derationIm ageAnnotat ionSourceT ype>();
  324                    imag eAnnotatio nSourceMap .put(Image Annotation Source.cli nicalDispl ay, Federa tionImageA nnotationS ourceType. clinicalDi splay);
  325                    imag eAnnotatio nSourceMap .put(Image Annotation Source.vis taRad, Fed erationIma geAnnotati onSourceTy pe.vistaRa d);
  326                    imag eAnnotatio nSourceMap .put(Image Annotation Source.cli nicalCaptu re, Federa tionImageA nnotationS ourceType. clinicalCa pture);
  327  
  328                    imag eAccessRea sonTypesMa p = new Ha shMap<Imag eAccessRea sonType, F ederationI mageAccess ReasonType Type>();
  329                    imag eAccessRea sonTypesMa p.put(Imag eAccessRea sonType.ch angingImag eStatus, F ederationI mageAccess ReasonType Type.chang ingImageSt atus);
  330                    imag eAccessRea sonTypesMa p.put(Imag eAccessRea sonType.co pyImage, F ederationI mageAccess ReasonType Type.copyI mage);
  331                    imag eAccessRea sonTypesMa p.put(Imag eAccessRea sonType.de leteImage,  Federatio nImageAcce ssReasonTy peType.del eteImage);
  332                    imag eAccessRea sonTypesMa p.put(Imag eAccessRea sonType.pr intImage,  Federation ImageAcces sReasonTyp eType.prin tImage);
  333  
  334           }
  335           
  336           pu blic stati c Federati onCprsIden tifierType  translate (CprsIdent ifier cprs Identifier )
  337           {
  338                    Fede rationCprs Identifier Type resul t =
  339                             new Fe derationCp rsIdentifi erType();
  340                    
  341                    resu lt.setCprs Identifier (cprsIdent ifier.getC prsIdentif ier());
  342                    
  343                    retu rn result;
  344           }
  345  
  346           
  347           pu blic stati c Federati onCprsIden tifiersTyp e translat eCprsIdent ifierList( List<CprsI dentifier>  cprsIdent ifiers)
  348           {
  349                    if(c prsIdentif iers == nu ll)
  350                             return  null;
  351  
  352                    Stri ng[] list  = new Stri ng[cprsIde ntifiers.s ize()];
  353                    for( int i=0; i <cprsIdent ifiers.siz e(); i++){
  354                             list[i ] = cprsId entifiers. get(i).get CprsIdenti fier();
  355                    }                 
  356                    Fede rationCprs Identifier sType resu lt = 
  357                             new Fe derationCp rsIdentifi ersType();
  358                    
  359                    resu lt.setCprs Identifier s(list);
  360                    
  361                    retu rn result;
  362           }
  363           
  364           pu blic stati c List<Cpr sIdentifie r> transla te(Federat ionCprsIde ntifiersTy pe cprsIde ntifiers){
  365                    if(c prsIdentif iers == nu ll){
  366                             return  null;
  367                    }
  368                    
  369                    Stri ng[] list  = cprsIden tifiers.ge tCprsIdent ifiers();
  370                    List <CprsIdent ifier> res ult = new  ArrayList< CprsIdenti fier>(list .length);
  371                    for( int i=0; i <list.leng th; i++){
  372                             result .add(new C prsIdentif ier(list[i ]));
  373                    }
  374                    retu rn result;
  375           }
  376  
  377           pu blic stati c ImageAcc essLogEven t translat e(Federati onImageAcc essLogEven tType logE ventType) 
  378           {
  379                    if(l ogEventTyp e == null)
  380                             return  null;
  381  
  382                    Imag eAccessLog EventType  imageAcces sLogEventT ype = 
  383                             transl ate(logEve ntType.get EventType( ));
  384  
  385                    Imag eAccessLog Event resu lt = 
  386                             new Im ageAccessL ogEvent(lo gEventType .getImageI d(), "", l ogEventTyp e.getPatie ntIcn(), 
  387                                               logEventTy pe.getSite Number(),  System.cur rentTimeMi llis(), 
  388                                               logEventTy pe.getReas onCode(),  logEventTy pe.getReas onDescript ion(),
  389                                               imageAcces sLogEventT ype, logEv entType.ge tUserSiteN umber());
  390                    
  391                    retu rn result;
  392           }
  393           
  394           pu blic stati c Federati onImageAcc essLogEven tType tran slate(
  395                             ImageA ccessLogEv ent logEve nt)
  396           {
  397                    Fede rationImag eAccessLog EventType  result = n ew Federat ionImageAc cessLogEve ntType();
  398                    resu lt.setImag eId(logEve nt.getImag eIen());
  399                    resu lt.setPati entIcn(log Event.getP atientIcn( ));
  400                    resu lt.setReas onCode(log Event.getR easonCode( ));
  401                    resu lt.setReas onDescript ion(logEve nt.getReas onDescript ion());
  402                    resu lt.setSite Number(log Event.getS iteNumber( ));
  403                    resu lt.setEven tType(tran slate(logE vent.getEv entType()) );
  404                    resu lt.setUser SiteNumber (logEvent. getUserSit eNumber()) ;
  405                    retu rn result;
  406           }
  407           
  408           pu blic stati c ImageAcc essLogEven tType tran slate(Fede rationImag eAccessLog EventTypeT ype eventT ype) 
  409           {
  410                    for(  Entry<Ima geAccessLo gEventType , Federati onImageAcc essLogEven tTypeType>  entry : F ederationR estTransla tor.imageA ccessMap.e ntrySet()  )
  411                             if( en try.getVal ue() == ev entType )
  412                                      return e ntry.getKe y();
  413                    
  414                    retu rn ImageAc cessLogEve ntType.IMA GE_ACCESS;
  415           }
  416           
  417           pu blic stati c Federati onImageAcc essLogEven tTypeType  translate( ImageAcces sLogEventT ype eventT ype) 
  418           {
  419                    for(  Entry<Ima geAccessLo gEventType , Federati onImageAcc essLogEven tTypeType>  entry : F ederationR estTransla tor.imageA ccessMap.e ntrySet()  )
  420                             if( en try.getKey () == even tType )
  421                                      return e ntry.getVa lue();
  422                    
  423                    retu rn Federat ionImageAc cessLogEve ntTypeType .IMAGE_ACC ESS;
  424           }
  425           
  426           pu blic stati c String [ ] translat eStringArr ay(Federat ionStringA rrayType v alues)
  427           {
  428                    if(v alues == n ull)
  429                             return  null;
  430                    // J ersey seem s to conve rt empty s tring arra ys into nu ll respons es
  431                    // w hen reques ting treat ing sites  for a pati ent, the r esult is e xpected to  be an emp ty array i f no sites  for the p atient
  432                    if(v alues.getV alues() ==  null)
  433                             return  new Strin g[0];
  434                    retu rn values. getValues( );
  435           }
  436           
  437           pu blic stati c Federati onStringAr rayType tr anslateStr ingList(Li st<String>  values)
  438           {
  439                    if(v alues == n ull)
  440                             return  null;
  441                    Fede rationStri ngArrayTyp e result =  new Feder ationStrin gArrayType ();
  442                    Stri ng [] arra y = new St ring[value s.size()];
  443                    for( int i = 0;  i < value s.size();  i++)
  444                    {
  445                             array[ i] = value s.get(i);
  446                    }
  447                    resu lt.setValu es(array);
  448                    
  449                    retu rn result;
  450           }
  451           
  452           pu blic stati c Federati onStringAr rayType tr anslateStr ingArray(S tring [] v alues)
  453           {
  454                    Fede rationStri ngArrayTyp e result =  new Feder ationStrin gArrayType ();
  455                    resu lt.setValu es(values) ;
  456                    
  457                    retu rn result;
  458           }
  459           
  460           pu blic stati c PatientR egistratio n translat e(
  461                    Fede rationPati entRegistr ationType  patientReg istration)
  462           {
  463                    Pati entRegistr ation resu lt = new P atientRegi stration() ;
  464                    resu lt.setCptC ode(patien tRegistrat ion.getCpt Code());
  465                    resu lt.setPati entIcn(pat ientRegist ration.get PatientIcn ());
  466                    retu rn result;
  467           }
  468           
  469           pu blic stati c Federati onPatientR egistratio nType tran slate(
  470                    Pati entRegistr ation pati entRegistr ation)
  471           {
  472                    Fede rationPati entRegistr ationType  result = n ew Federat ionPatient Registrati onType();
  473                    resu lt.setCptC ode(patien tRegistrat ion.getCpt Code());
  474                    resu lt.setPati entIcn(pat ientRegist ration.get PatientIcn ());
  475                    retu rn result;
  476           }        
  477           
  478           pu blic stati c ExamList Result tra nslate(Fed erationExa mResultTyp e examResu lt)
  479           th rows URNFo rmatExcept ion
  480           {
  481                    if(e xamResult  == null)
  482                    {
  483                             getLog ger().erro r("Null Fe derationEx amResultTy pe, return ing empty  ExamListRe sult");
  484                             return  ExamListR esult.crea teFullResu lt(null);
  485                    }
  486                    List <Exam> exa ms = trans late(examR esult.getE xams());
  487                    Arti factResult Status art ifactResul tStatus =  translate( examResult .getArtifa ctResultSt atus());
  488                    List <ArtifactR esultError > artifact ResultErro rs = trans late(examR esult.getE rrors());               
  489                    retu rn ExamLis tResult.cr eate(exams , artifact ResultStat us, artifa ctResultEr rors);
  490           }
  491           
  492           pr ivate stat ic List<Ex am> transl ate(Federa tionExamTy pe [] exam s)
  493           th rows URNFo rmatExcept ion
  494           {
  495                    if(e xams == nu ll)
  496                    {
  497                             getLog ger().warn ("Received  null exam s, returni ng empty a rray of ex ams.");
  498                             return  new Array List<Exam> (0);
  499                    }
  500                    List <Exam> res ult = new  ArrayList< Exam>(exam s.length);
  501                    
  502                    for( Federation ExamType e xam : exam s)
  503                    {
  504                             result .add(trans late(exam) );
  505                    }                 
  506                    retu rn result;
  507           }
  508           
  509           pu blic stati c Federati onExamResu ltType tra nslate(
  510                    Exam Site examS ite) 
  511           th rows Trans lationExce ption
  512           {
  513                    Fede rationExam ResultType  result =  new Federa tionExamRe sultType() ;
  514                    if(e xamSite ==  null)
  515                             return  result;
  516                    Fede rationExam Type [] ex ams = new  Federation ExamType[e xamSite.si ze()];
  517                    
  518                    int  i = 0;
  519                    for( Exam exam  : examSite )
  520                             exams[ i++] = tra nslate(exa m);
  521                    
  522                    resu lt.setExam s(exams);
  523                    resu lt.setArti factResult Status(tra nslate(exa mSite.getA rtifactRes ultStatus( )));
  524                    resu lt.setErro rs(transla teArtifact ResultErro rList(exam Site.getAr tifactResu ltErrors() ));
  525                    retu rn result;
  526           }
  527           
  528           pu blic stati c ActiveEx am transla te(Federat ionActiveE xamType ac tiveExam)
  529           {
  530                    Acti veExam res ult = new  ActiveExam (
  531                             active Exam.getSi teNumber()
  532                             active Exam.getEx amId(), 
  533                             active Exam.getPa tientIcn() );
  534                    resu lt.setRawV alue(activ eExam.getR awValue()) ;            
  535                    retu rn result;
  536           }
  537           
  538           pu blic stati c ActiveEx ams transl ate(Federa tionActive ExamsType  activeExam s)
  539           {
  540                    Stri ng rawHead er1 = (act iveExams.g etRawHeade r1() == nu ll ? "" :  activeExam s.getRawHe ader1());
  541                    Stri ng rawHead er2 = (act iveExams.g etRawHeade r2() == nu ll ? "" :  activeExam s.getRawHe ader2());
  542                    
  543                    Acti veExams re sult = new  ActiveExa ms(
  544                             active Exams.getS iteNumber( ), 
  545                             rawHea der1, 
  546                             rawHea der2);
  547                    // i f there ar e no activ e exams re turned fro m the web  service ca ll, the ge tActiveExa ms appears  to 
  548                    // t urn into n ull, so ne ed to chec k for null
  549                    if(a ctiveExams .getActive Exams() !=  null)
  550                    {
  551                             for(Fe derationAc tiveExamTy pe activeE xam : acti veExams.ge tActiveExa ms())
  552                                      result.a dd(transla te(activeE xam));
  553                    }
  554                    
  555                    retu rn result;
  556           }
  557           
  558           pu blic stati c Federati onActiveEx amType tra nslate(
  559                             Active Exam activ eExam)
  560           {
  561                    Fede rationActi veExamType  result =  new Federa tionActive ExamType() ;
  562                    
  563                    resu lt.setExam Id(activeE xam.getExa mId());
  564                    resu lt.setPati entIcn(act iveExam.ge tPatientIc n());
  565                    resu lt.setRawV alue(activ eExam.getR awValue()) ;
  566                    resu lt.setSite Number(act iveExam.ge tSiteNumbe r());
  567                    
  568                    retu rn result;
  569           }
  570           
  571           pu blic stati c Federati onActiveEx amsType tr anslate(
  572                             Active Exams acti veExams) 
  573           {
  574                    Fede rationActi veExamsTyp e result =  new Feder ationActiv eExamsType ();
  575                    resu lt.setRawH eader1(act iveExams.g etRawHeade r1());
  576                    resu lt.setRawH eader2(act iveExams.g etRawHeade r2());
  577                    resu lt.setSite Number(act iveExams.g etSiteNumb er());
  578                    
  579                    Fede rationActi veExamType  [] active ExamArray  = new Fede rationActi veExamType [activeExa ms.size()] ;
  580                    int  i = 0;
  581                    for( ActiveExam  activeExa m : active Exams)
  582                    {
  583                             active ExamArray[ i] = trans late(activ eExam);
  584                             i++;
  585                    }
  586                    resu lt.setActi veExams(ac tiveExamAr ray);
  587                    
  588                    retu rn result;
  589           }
  590           
  591           pu blic stati c ExamImag e translat e(Federati onExamImag eType exam Image)
  592           th rows URNFo rmatExcept ion
  593           {
  594                    if(e xamImage = = null)
  595                             return  null;
  596                    Exam Image resu lt = ExamI mage.creat e(
  597                             examIm age.getSit eNumber(),  
  598                             examIm age.getIma geId(), 
  599                             examIm age.getExa mId(),
  600                             examIm age.getPat ientIcn()) ;
  601                    resu lt.setDiag nosticFile Path(examI mage.getBi gImageFile name());
  602                    resu lt.setPati entName("" );
  603                    resu lt.setAlie nSiteNumbe r(examImag e.getAlien SiteNumber ());
  604                    retu rn result;
  605           }
  606           
  607           pu blic stati c ExamImag es transla te(Federat ionExamIma gesType ex amImages)
  608           th rows URNFo rmatExcept ion
  609           {
  610                    Exam Images res ult = new  ExamImages (examImage s.getRawHe ader(), fa lse);            
  611                    
  612                    if(e xamImages. getImages( ) != null)
  613                    {                 
  614                             for(Fe derationEx amImageTyp e examImag e : examIm ages.getIm ages())
  615                             {
  616                                      ExamImag e img = tr anslate(ex amImage);
  617                                      if(img ! = null)
  618                                               result.add (img);
  619                             }
  620                    }
  621                    retu rn result;   
  622           }
  623           
  624           pu blic stati c Exam tra nslate(Fed erationExa mType exam )
  625           th rows URNFo rmatExcept ion
  626           {
  627                    Exam  result =  Exam.creat e(
  628                             exam.g etSiteNumb er(), 
  629                             exam.g etExamId()
  630                             exam.g etPatientI cn());
  631                    resu lt.setCptC ode(exam.g etCptCode( ));                              // CTB 29M ar2010, nu ll was tra nsformed t o blank
  632                    resu lt.setExam Report(exa m.getRadio logyReport ()); // wa nt it null  if it is  null
  633                    resu lt.setExam Requisitio nReport(ex am.getRequ isitionRep ort());//  want it nu ll if it i s null
  634                    resu lt.setExam Status(tra nslate(exa m.getExamS tatus()));           
  635                    
  636                    // t his indica tes the im ages were  not includ ed (shallo w exam)
  637                    if(e xam.getExa mImages()  == null)
  638                             result .setImages (null);
  639                    else
  640                             result .setImages (translate (exam.getE xamImages( )));
  641                    resu lt.setPres entationSt ateData(ex am.getPres entationSt ate()); //  don't che ck for nul l, want nu ll if null  value
  642                    resu lt.setModa lity(exam. getModalit y());
  643                    resu lt.setPati entName(ex am.getPati entName()) ;
  644                    resu lt.setRawH eaderLine1 (exam.getR awHeader1( ));
  645                    resu lt.setRawH eaderLine2 (exam.getR awHeader2( ));
  646                    resu lt.setRawO utput(exam .getRawVal ue());
  647                    resu lt.setSite Abbr(exam. getSiteAbb r());
  648                    resu lt.setSite Name(exam. getSiteNam e());
  649                    retu rn result;
  650           }
  651           
  652           pu blic stati c Federati onExamType  translate (Exam exam
  653           {
  654                    Fede rationExam Type resul t = new Fe derationEx amType();
  655                    
  656                    resu lt.setCptC ode(exam.g etCptCode( ));
  657                    resu lt.setExam Id(exam.ge tExamId()) ;
  658                    resu lt.setExam Status( tr anslate(ex am.getExam Status())  );
  659                    resu lt.setModa lity(exam. getModalit y());
  660                    resu lt.setPati entIcn(exa m.getPatie ntIcn());
  661                    resu lt.setPati entName(ex am.getPati entName()) ;
  662                    resu lt.setRadi ologyRepor t(exam.get ExamReport ());
  663                    resu lt.setRawH eader1(exa m.getRawHe aderLine1( ));
  664                    resu lt.setRawH eader2(exa m.getRawHe aderLine2( ));
  665                    resu lt.setRawV alue(exam. getRawOutp ut());
  666                    resu lt.setRequ isitionRep ort(exam.g etExamRequ isitionRep ort());
  667                    resu lt.setSite Abbr(exam. getSiteAbb r());
  668                    resu lt.setSite Name(exam. getSiteNam e());
  669                    resu lt.setSite Number(exa m.getSiteN umber());
  670                    resu lt.setPres entationSt ate(exam.g etPresenta tionStateD ata());
  671                    
  672                    if(e xam.getIma ges() == n ull)
  673                    {
  674                             // thi s will hap pen if the  examSite  does not h ave images  at all
  675                             result .setExamIm ages(null) ;
  676                    }
  677                    else
  678                    {
  679                             // if  the images  were atte mpted to l oad, they  might be o n jukebox  so not con sidered fu lly loaded , but stll  need to c all transl ate so the  header is  set
  680                             Federa tionExamIm agesType e xamImages  = translat e(exam.get Images());
  681                             result .setExamIm ages(examI mages);
  682                    }                 
  683                    retu rn result;
  684           }
  685           
  686           pu blic stati c Federati onExamImag eType tran slate(Exam Image exam Image)
  687           {
  688                    Fede rationExam ImageType  result = n ew Federat ionExamIma geType();
  689                    
  690                    resu lt.setBigI mageFilena me(examIma ge.getDiag nosticFile Path());
  691                    resu lt.setExam Id(examIma ge.getExam Id());
  692                    resu lt.setImag eId(examIm age.getIma geId()) ;
  693                    resu lt.setPati entIcn(exa mImage.get PatientIcn ());
  694                    resu lt.setSite Number(exa mImage.get SiteNumber ());
  695                    resu lt.setAlie nSiteNumbe r(examImag e.getAlien SiteNumber ());
  696                    
  697                    retu rn result;
  698           }
  699           
  700           pu blic stati c Federati onExamImag esType tra nslate(Exa mImages ex amImages)
  701           {
  702                    Fede rationExam ImagesType  result =  new Federa tionExamIm agesType() ;
  703                    resu lt.setRawH eader(exam Images.get RawHeader( ));
  704                    Fede rationExam ImageType  [] images  = new Fede rationExam ImageType[ examImages .size()];
  705                    int  i = 0;
  706                    for( ExamImage  image : ex amImages)
  707                    {
  708                             images [i] = tran slate(imag e);
  709                             i++;
  710                    }
  711                    resu lt.setImag es(images) ;
  712                    
  713                    retu rn result;
  714           }
  715           
  716           pu blic stati c Federati onExamStat usType tra nslate(
  717                             ExamSt atus examS tatus)
  718                    {
  719                             for( E ntry<ExamS tatus, Fed erationExa mStatusTyp e> entry :  Federatio nRestTrans lator.exam StatusMap. entrySet()  )
  720                                      if( entr y.getKey()  == examSt atus )
  721                                               return ent ry.getValu e();
  722                             
  723                             return  Federatio nExamStatu sType.INTE RPRETED;
  724                    }
  725                    
  726                    
  727                    publ ic static  ExamStatus  translate (
  728                                      Federati onExamStat usType sta tusType)
  729                    {
  730                             for( E ntry<ExamS tatus, Fed erationExa mStatusTyp e> entry :  Federatio nRestTrans lator.exam StatusMap. entrySet()  )
  731                                      if( entr y.getValue () == stat usType )
  732                                               return ent ry.getKey( );
  733                             
  734                             return  ExamStatu s.INTERPRE TED;
  735                    }
  736           
  737           pu blic stati c Federati onRemoteMe thodType t ranslate(P assthrough InputMetho d inputMet hod, Strin g imagingS ecurityCon text)
  738           {
  739                    Sort edSet<Pass throughPar ameter> pa rameters =  inputMeth od.getPara meters();
  740                    Fede rationRemo teMethodTy pe result  = new Fede rationRemo teMethodTy pe();
  741                    resu lt.setImag ingSecurit yContext(i magingSecu rityContex t);
  742                    resu lt.setMeth odName(inp utMethod.g etMethodNa me());
  743                    Fede rationRemo teMethodPa rameterTyp e [] param eterTypes  = new Fede rationRemo teMethodPa rameterTyp e[paramete rs.size()] ;
  744                    int  i = 0;
  745                    for( Passthroug hParameter  parameter  : paramet ers)
  746                    {
  747                             parame terTypes[i ] = transl ate(parame ter);
  748                             i++;
  749                    }
  750                    resu lt.setPara meters(par ameterType s);
  751                    retu rn result;
  752           }
  753           
  754           pu blic stati c Passthro ughInputMe thod trans late(Feder ationRemot eMethodTyp e remoteMe thodType)
  755           {
  756                    Pass throughInp utMethod r esult = ne w Passthro ughInputMe thod(remot eMethodTyp e.getMetho dName());
  757                    
  758                    if(r emoteMetho dType.getP arameters( ) != null)
  759                             for(Fe derationRe moteMethod ParameterT ype parame ter : remo teMethodTy pe.getPara meters())
  760                                      result.g etParamete rs().add(t ranslate(p arameter)) ;
  761                                      
  762                    retu rn result;
  763           }
  764           
  765           pu blic stati c Federati onRemoteMe thodParame terType tr anslate(Pa ssthroughP arameter p arameter)
  766           {
  767                    Fede rationRemo teMethodPa rameterTyp e result =  
  768                             new Fe derationRe moteMethod ParameterT ype();
  769                    resu lt.setPara meterIndex (parameter .getIndex( ));
  770                    
  771                    resu lt.setPara meterType( translate( parameter. getParamet erType())) ;
  772                    
  773                    Fede rationRemo teMethodPa rameterVal ueType val ue = 
  774                             new Fe derationRe moteMethod ParameterV alueType() ;
  775                    
  776                    // o k if null
  777                    valu e.setValue (parameter .getValue( ));
  778                    valu e.setMulti pleValues( parameter. getMultipl eValues()) ;
  779                    resu lt.setPara meterValue (value);                  
  780                    
  781                    retu rn result;
  782           }
  783           
  784           pu blic stati c Federati onRemoteMe thodParame terTypeTyp e translat e(
  785                             Passth roughParam eterType p arameterTy pe)
  786           {                 
  787                    for(  Entry<Pas sthroughPa rameterTyp e, Federat ionRemoteM ethodParam eterTypeTy pe> entry  : Federati onRestTran slator.par ameterType Map.entryS et() )
  788                             if( en try.getKey () == para meterType  )
  789                                      return e ntry.getVa lue();
  790                    
  791                    retu rn Federat ionRemoteM ethodParam eterTypeTy pe.LITERAL ;
  792           }        
  793           
  794           /*
  795           pu blic stati c Passthro ughInputMe thod trans late(Strin g methodNa me, Federa tionRemote MethodPara meterType  [] paramet ers)
  796           {
  797                    if(m ethodName  == null)
  798                             return  null;
  799                    Pass throughInp utMethod r esult = ne w Passthro ughInputMe thod(metho dName);
  800                    if(p arameters  != null)
  801                             for(Fe derationRe moteMethod ParameterT ype parame ter : para meters)
  802                                      result.g etParamete rs().add(t ranslate(p arameter)) ;
  803                    
  804                    retu rn result;
  805           }* /     
  806           
  807           pu blic stati c Passthro ughParamet er transla te(Federat ionRemoteM ethodParam eterType p arameter)
  808           {
  809                    Pass throughPar ameter res ult = new  Passthroug hParameter ();
  810                    resu lt.setInde x(paramete r.getParam eterIndex( ));
  811                    
  812                    resu lt.setPara meterType( translate( parameter. getParamet erType())) ;
  813                    Fede rationRemo teMethodPa rameterVal ueType par ameterValu e = parame ter.getPar ameterValu e();
  814                    if(p arameterVa lue == nul l)
  815                    {
  816                             result .setValue( null);
  817                             result .setMultip leValues(n ull);
  818                    }
  819                    else
  820                    {
  821                             String  value = p arameterVa lue.getVal ue();
  822                             result .setValue( value);
  823                             String  [] multip leValues =  parameter Value.getM ultipleVal ues();
  824                             result .setMultip leValues(m ultipleVal ues);
  825                    }
  826                    
  827                    retu rn result;
  828           }
  829           
  830           pu blic stati c Passthro ughParamet erType tra nslate(Fed erationRem oteMethodP arameterTy peType par ameterType )
  831           {
  832                    Pass throughPar ameterType  result =  Passthroug hParameter Type.liter al;
  833                    if(p arameterTy pe == Fede rationRemo teMethodPa rameterTyp eType.LIST )
  834                             result  = Passthr oughParame terType.li st;
  835                    else  if(parame terType ==  Federatio nRemoteMet hodParamet erTypeType .REFERENCE )
  836                             result  = Passthr oughParame terType.re ference;
  837                    retu rn result;
  838           }
  839           
  840           pu blic stati c Document Filter tra nslate(Fed erationDoc umentFilte rType filt erType)
  841           th rows Trans lationExce ption
  842           {
  843                    Docu mentFilter  result =  new Docume ntFilter(f ilterType. getPatient Id(), filt erType.get ClassCode( ), 
  844                                      filterTy pe.getPrac ticeSettin gCode(), f ilterType. getCreatio nTimeFrom( ), filterT ype.getCre ationTimeT o(),
  845                                      filterTy pe.getServ iceStartTi meFrom(),  filterType .getServic eStartTime To(), 
  846                                      filterTy pe.getServ iceStopTim eFrom(), f ilterType. getService StopTimeTo (), filter Type.getHe althcareFa cilityType Code(),
  847                                      filterTy pe.getEven tCodes(),  filterType .getConfid entialityC odes(), fi lterType.g etAuthor() , filterTy pe.getForm atCode(),
  848                                      filterTy pe.getEntr yStatus(),  filterTyp e.getMaxRe sultsCount (), filter Type.getSi teNumber() ,
  849                                      filterTy pe.isUseAl ternatePat ientId()
  850                    );
  851                    
  852                    resu lt.setStud y_class(fi lterType.g et_class() );
  853                    resu lt.setStud y_package( filterType .get_packa ge());
  854                    resu lt.setStud y_event(fi lterType.g etEvent()) ;
  855                    resu lt.setFrom Date(filte rType.getF romDate()) ;
  856                    resu lt.setIncl udeDeleted (filterTyp e.isInclud eDeletedIm ages());
  857                    resu lt.setOrig in(filterT ype.getOri gin());
  858                    resu lt.setStud y_specialt y(filterTy pe.getSpec ialty());
  859                    if(( filterType .getStudyI d() != nul l) && (fil terType.ge tStudyId() .length()  > 0))
  860                    {
  861                             try
  862                             {
  863                                      URN gai  = URNFacto ry.create( filterType .getStudyI d());
  864                                      if(gai i nstanceof  GlobalArti factIdenti fier)
  865                                               result.set StudyId((G lobalArtif actIdentif ier)gai);
  866                             }
  867                             catch  (URNFormat Exception  x)
  868                             {
  869                                      throw ne w Translat ionExcepti on(filterT ype.getStu dyId() + 
  870                                               " cannot b e transfor med into a  GlobalArt ifactIdent ifier real ization."
  871                                      );
  872                             }
  873                    }
  874                    resu lt.setToDa te(filterT ype.getToD ate());
  875                    resu lt.setStud y_type(fil terType.ge tTypes());
  876                    
  877                    retu rn result;
  878           }
  879           
  880           pu blic stati c Federati onDocument FilterType  translate (DocumentF ilter filt er)
  881           {
  882                    Fede rationDocu mentFilter Type docum entFilterT ype = new  Federation DocumentFi lterType() ;
  883                    docu mentFilter Type.set_c lass(filte r.getStudy _class());
  884                    docu mentFilter Type.set_p ackage(fil ter.getStu dy_package ());
  885                    docu mentFilter Type.setEv ent(filter .getStudy_ event());
  886                    docu mentFilter Type.setFr omDate(fil ter.getFro mDate());
  887                    docu mentFilter Type.setIn cludeDelet edImages(f ilter.isIn cludeDelet ed());
  888                    docu mentFilter Type.setOr igin(filte r.getOrigi n());
  889                    docu mentFilter Type.setSp ecialty(fi lter.getSt udy_specia lty());
  890                    docu mentFilter Type.setSt udyId(filt er.getStud yId() == n ull ? "" :  filter.ge tStudyId() .toString( ));
  891                    docu mentFilter Type.setTo Date(filte r.getToDat e());
  892                    docu mentFilter Type.setTy pes(filter .getStudy_ type());
  893                    
  894                    docu mentFilter Type.setPa tientId(fi lter.getPa tientId()) ;
  895                    docu mentFilter Type.setCl assCode(fi lter.getCl assCode()) ;
  896                    docu mentFilter Type.setPr acticeSett ingCode(fi lter.getPr acticeSett ingCode()) ;
  897                    docu mentFilter Type.setCr eationTime From(filte r.getCreat ionTimeFro m());
  898                    docu mentFilter Type.setCr eationTime To(filter. getCreatio nTimeTo()) ;
  899                    docu mentFilter Type.setSe rviceStart TimeFrom(f ilter.getS erviceStar tTimeFrom( ));
  900                    docu mentFilter Type.setSe rviceStart TimeTo(fil ter.getSer viceStartT imeTo());
  901                    docu mentFilter Type.setSe rviceStopT imeFrom(fi lter.getSe rviceStopT imeFrom()) ;
  902                    docu mentFilter Type.setSe rviceStopT imeTo(filt er.getServ iceStopTim eTo());
  903                    docu mentFilter Type.setHe althcareFa cilityType Code(filte r.getHealt hcareFacil ityTypeCod e());
  904                    docu mentFilter Type.setEv entCodes(f ilter.getE ventCodes( ));
  905                    docu mentFilter Type.setCo nfidential ityCodes(f ilter.getC onfidentia lityCodes( ));
  906                    docu mentFilter Type.setAu thor(filte r.getAutho r());
  907                    docu mentFilter Type.setFo rmatCode(f ilter.getF ormatCode( ));
  908                    docu mentFilter Type.setEn tryStatus( filter.get EntryStatu s());
  909                    docu mentFilter Type.setMa xResultsCo unt(filter .getMaximu mResults() );
  910                    docu mentFilter Type.setSi teNumber(f ilter.getS iteNumber( ));
  911                    docu mentFilter Type.setUs eAlternate PatientId( filter.isU seAlternat ePatientId ());
  912                    
  913                    retu rn documen tFilterTyp e;
  914           }
  915           
  916           pu blic stati c Federati onFilterTy pe transla te(StudyFi lter filte rType)
  917           {
  918                    Fede rationFilt erType fil ter = new  Federation FilterType ();
  919                    if(f ilterType  != null)
  920                    {
  921                             filter .setFromDa te(filterT ype.getFro mDate());
  922                             filter .setToDate (filterTyp e.getToDat e());
  923                             filter .set_class (filterTyp e.getStudy _class()==  null ? ""  : filterT ype.getStu dy_class() );
  924                             filter .setEvent( filterType .getStudy_ event() ==  null ? ""  : filterT ype.getStu dy_event() );
  925                             filter .set_packa ge(filterT ype.getStu dy_package () == null  ? "" : fi lterType.g etStudy_pa ckage());
  926                             filter .setSpecia lty(filter Type.getSt udy_specia lty() == n ull ? "" :  filterTyp e.getStudy _specialty ());
  927                             filter .setTypes( filterType .getStudy_ type() ==  null ? ""  : filterTy pe.getStud y_type());
  928                             Global ArtifactId entifier s tudyIdenti fier = fil terType.ge tStudyId() ;
  929                             if(stu dyIdentifi er != null )
  930                             {
  931                                      filter.s etStudyId( studyIdent ifier.toSt ring());
  932                             }
  933                             else
  934                                      filter.s etStudyId( null);
  935                             filter .setOrigin (filterTyp e.getOrigi n() == nul l ? "" : f ilterType. getOrigin( ));
  936                             filter .setInclud eDeletedIm ages(filte rType.isIn cludeDelet ed());
  937                             filter .setInclud eAllObject s(filterTy pe.isInclu deAllObjec ts());
  938                             filter .setInclud ePatientOr ders(filte rType.isIn cludePatie ntOrders() );
  939                             filter .setInclud eEncounter Orders(fil terType.is IncludeEnc ounterOrde rs());
  940                             filter .setInclud eMuseOrder s(filterTy pe.isInclu deMuseOrde rs());
  941                    }
  942                    retu rn filter;
  943           }
  944           
  945           pu blic stati c StudyFil ter transl ate(Federa tionFilter Type filte rType,
  946                             int au thorizedSe nsitiveLev el, boolea n filterPr ocedures)
  947           th rows Globa lArtifactI dentifierF ormatExcep tion
  948           {
  949                    Stud yFilter fi lter = nul l;
  950                    if(f ilterProce dures)
  951                             filter  = new Pro cedureFilt er(Procedu reFilterMa tchMode.ex istInProce dureList);
  952                    else
  953                             filter  = new Stu dyFilter() ;              
  954                    filt er.setMaxi mumAllowed Level(Pati entSensiti vityLevel. getPatient Sensitivit yLevel(aut horizedSen sitiveLeve l));
  955                    if(f ilterType  != null)
  956                    {
  957                             filter .setFromDa te(filterT ype.getFro mDate());
  958                             filter .setToDate (filterTyp e.getToDat e());
  959                             filter .setStudy_ class(filt erType.get _class() = = null ? " " : filter Type.get_c lass());
  960                             filter .setStudy_ event(filt erType.get Event() ==  null ? ""  : filterT ype.getEve nt());
  961                             filter .setStudy_ package(fi lterType.g et_package () == null  ? "" : fi lterType.g et_package ());
  962                             filter .setStudy_ specialty( filterType .getSpecia lty() == n ull ? "" :  filterTyp e.getSpeci alty());
  963                             filter .setStudy_ type(filte rType.getT ypes() ==  null ? ""  : filterTy pe.getType s());
  964                             String  requested StudyIdAsS tring = fi lterType.g etStudyId( );
  965                             if(req uestedStud yIdAsStrin g != null)
  966                             {
  967                                      try
  968                                      {
  969                                               URN studyU rn = URNFa ctory.crea te(request edStudyIdA sString);
  970                                               if(studyUr n instance of GlobalA rtifactIde ntifier)
  971                                                       fi lter.setSt udyId( (Gl obalArtifa ctIdentifi er)studyUr n );
  972                                      }
  973                                      catch (U RNFormatEx ception x)
  974                                      {
  975                                               throw new  GlobalArti factIdenti fierFormat Exception( requestedS tudyIdAsSt ring + 
  976                                                       "  cannot be  transforme d into a G lobalArtif actIdentif ier realiz ation."
  977                                               );
  978                                      }
  979                             }
  980                             else
  981                                      filter.s etStudyId( null);
  982                             filter .setOrigin (filterTyp e.getOrigi n() == nul l ? "" : f ilterType. getOrigin( ));
  983                             filter .setInclud eDeleted(f ilterType. isIncludeD eletedImag es());
  984                             filter .setInclud eAllObject s(filterTy pe.isInclu deAllObjec ts());
  985                             filter .setInclud ePatientOr ders(filte rType.isIn cludePatie ntOrders() );
  986                             filter .setInclud eEncounter Orders(fil terType.is IncludeEnc ounterOrde rs());
  987                             filter .setInclud eMuseOrder s(filterTy pe.isInclu deMuseOrde rs());
  988                    }
  989                    retu rn filter;
  990           }
  991  
  992  
  993           
  994           // WFP-Need t o fix this  with resp ect to Fed erationFil terType an d MaximumA llowedLeve l. The cur rent
  995           //       solu tion will  not go thr u the Fede ration bec ause it's  not a prim itive.
  996           pu blic stati c StudyFil ter transl ate(Federa tionFilter Type filte rType)
  997           th rows Globa lArtifactI dentifierF ormatExcep tion
  998           {
  999                    Stud yFilter fi lter = new  StudyFilt er();
  1000                    filt er.setMaxi mumAllowed Level(filt erType.get MaximumAll owedLevel( ));
  1001                    filt er.setFrom Date(filte rType.getF romDate()) ;
  1002                    filt er.setToDa te(filterT ype.getToD ate());
  1003                    filt er.setStud y_class(fi lterType.g et_class()  == null ?  "" : filt erType.get _class());
  1004                    filt er.setStud y_event(fi lterType.g etEvent()  == null ?  "" : filte rType.getE vent());
  1005                    filt er.setStud y_package( filterType .get_packa ge() == nu ll ? "" :  filterType .get_packa ge());
  1006                    filt er.setStud y_specialt y(filterTy pe.getSpec ialty() ==  null ? ""  : filterT ype.getSpe cialty());
  1007                    filt er.setStud y_type(fil terType.ge tTypes() = = null ? " " : filter Type.getTy pes());
  1008                    Stri ng request edStudyIdA sString =  filterType .getStudyI d();
  1009                    if(r equestedSt udyIdAsStr ing != nul l)
  1010                    {
  1011                             try
  1012                             {
  1013                                      URN stud yUrn = URN Factory.cr eate(reque stedStudyI dAsString) ;
  1014                                      if(study Urn instan ceof Globa lArtifactI dentifier)
  1015                                               filter.set StudyId( ( GlobalArti factIdenti fier)study Urn );
  1016                             }
  1017                             catch  (URNFormat Exception  x)
  1018                             {
  1019                                      throw ne w GlobalAr tifactIden tifierForm atExceptio n(requeste dStudyIdAs String + 
  1020                                               " cannot b e transfor med into a  GlobalArt ifactIdent ifier real ization."
  1021                                      );
  1022                             }
  1023                    }
  1024                    else
  1025                             filter .setStudyI d(null);
  1026                    filt er.setOrig in(filterT ype.getOri gin() == n ull ? "" :  filterTyp e.getOrigi n());
  1027                    filt er.setIncl udeDeleted (filterTyp e.isInclud eDeletedIm ages());
  1028                    filt er.setIncl udeAllObje cts(filter Type.isInc ludeAllObj ects());
  1029                    filt er.setIncl udePatient Orders(fil terType.is IncludePat ientOrders ());
  1030                    filt er.setIncl udeEncount erOrders(f ilterType. isIncludeE ncounterOr ders());
  1031                    filt er.setIncl udeMuseOrd ers(filter Type.isInc ludeMuseOr ders());
  1032                    retu rn filter;
  1033           }
  1034           
  1035  
  1036           pu blic stati c SortedSe t<Study> t ranslate(F ederationS tudyType [ ] studies)
  1037           th rows Trans lationExce ption
  1038           {
  1039                    retu rn transla te(studies , null);
  1040           }
  1041           
  1042           pu blic stati c Federati onDocument SetResultT ype transl ate(Docume ntSetResul t document SetResult)
  1043           {
  1044                    if(d ocumentSet Result ==  null)
  1045                             return  null;
  1046                    Fede rationDocu mentSetRes ultType re sult = new  Federatio nDocumentS etResultTy pe();
  1047                    
  1048                    Fede rationDocu mentSetTyp e[] docume ntSets = t ranslate(d ocumentSet Result.get Artifacts( ));
  1049                    
  1050                    Fede rationArti factResult StatusType  artifactR esultStatu s = 
  1051                             transl ate(docume ntSetResul t.getArtif actResultS tatus());
  1052                    
  1053                    resu lt.setDocu mentSets(d ocumentSet s);
  1054                    resu lt.setArti factResult Status(art ifactResul tStatus);
  1055                    resu lt.setErro rs(transla teArtifact ResultErro rList(docu mentSetRes ult.getArt ifactResul tErrors()) );
  1056                    
  1057                    retu rn result;
  1058           }
  1059           
  1060           pr ivate stat ic Federat ionDocumen tSetType[]  translate (SortedSet <DocumentS et> docume ntSets)
  1061           {
  1062                    if(d ocumentSet s == null)
  1063                             return  null;
  1064                    Fede rationDocu mentSetTyp e[] result  = new Fed erationDoc umentSetTy pe[documen tSets.size ()];
  1065                    int  i = 0;
  1066                    for( DocumentSe t document Set : docu mentSets)
  1067                    {
  1068                             result [i] = tran slate(docu mentSet);
  1069                             i++;
  1070                    }
  1071                    
  1072                    retu rn result;
  1073           }
  1074           
  1075           pr ivate stat ic Federat ionDocumen tSetType t ranslate(D ocumentSet  documentS et)
  1076           {
  1077                    if(d ocumentSet  == null)
  1078                             return  null;
  1079                    Fede rationDocu mentSetTyp e result =  new Feder ationDocum entSetType ();
  1080                    resu lt.setAcqu isitionDat e(document Set.getAcq uisitionDa te());
  1081                    resu lt.setAlie nSiteNumbe r(document Set.getAli enSiteNumb er());
  1082                    resu lt.setClin icalType(d ocumentSet .getClinic alType());           
  1083                    resu lt.setErro rMessage(d ocumentSet .getErrorM essage());
  1084                    resu lt.setFirs tImageIen( documentSe t.getFirst ImageIen() );
  1085                    resu lt.setHome CommunityI d(document Set.getHom eCommunity Id().toStr ing());
  1086                    resu lt.setIden tifier(doc umentSet.g etIdentifi er());
  1087                    resu lt.setPati entIcn(doc umentSet.g etPatientI cn());
  1088                    resu lt.setPati entName(do cumentSet. getPatient Name());
  1089                    resu lt.setProc edureDate( documentSe t.getProce dureDate() );
  1090                    resu lt.setRepo sitoryId(d ocumentSet .getReposi toryId());
  1091                    resu lt.setRpcR esponseMsg (documentS et.getRpcR esponseMsg ());
  1092                    resu lt.setSite Abbr(docum entSet.get SiteAbbr() );
  1093                    resu lt.setSite Name(docum entSet.get SiteName() );
  1094                    resu lt.setCons olidatedSi teNumber(d ocumentSet .getConsol idatedSite Number());
  1095                    
  1096                    Fede rationDocu mentType [ ] document s = new Fe derationDo cumentType [documentS et.size()] ;
  1097                    int  i = 0; 
  1098                    for( Document d ocument :  documentSe t)
  1099                    {
  1100                             docume nts[i] = t ranslate(d ocument);
  1101                             i++;
  1102                    }
  1103                    resu lt.setDocu ments(docu ments);
  1104                    
  1105                    retu rn result;
  1106           }
  1107           
  1108           pr ivate stat ic Federat ionDocumen tType tran slate(Docu ment docum ent)
  1109           {
  1110                    if(d ocument ==  null)
  1111                             return  null;
  1112                    
  1113                    Fede rationDocu mentType r esult = ne w Federati onDocument Type();
  1114                    resu lt.setChec ksum(trans late(docum ent.getChe cksumValue ()));
  1115                    resu lt.setClin icalType(d ocument.ge tClinicalT ype());
  1116                    resu lt.setConf identialit yCode(docu ment.getCo nfidential ityCode()) ;
  1117                    resu lt.setCont entLenth(d ocument.ge tContentLe ngth());
  1118                    resu lt.setCrea tionDate(d ocument.ge tCreationD ate());
  1119                    resu lt.setDesc ription(do cument.get Descriptio n());
  1120                    resu lt.setDocu mentSetIen (document. getDocumen tSetIen()) ;
  1121                    resu lt.setIden tifier(doc ument.getG lobalArtif actIdentif ier().toSt ring());
  1122                    resu lt.setLang uageCode(d ocument.ge tLanguageC ode());
  1123                    resu lt.setMedi aType(tran slate(docu ment.getMe diaType()) );
  1124                    resu lt.setName (document. getName()) ;
  1125                    resu lt.setVist aImageType (document. getVistaIm ageType()) ;
  1126                    resu lt.setCons olidatedSi teNumber(d ocument.ge tConsolida tedSiteNum ber());
  1127                    retu rn result;
  1128           }
  1129           
  1130           pu blic stati c Document SetResult  translate( Federation DocumentSe tResultTyp e document SetResultT ype)
  1131           th rows Trans lationExce ption
  1132           {
  1133                    if(d ocumentSet ResultType  == null)
  1134                    {
  1135                             getLog ger().erro r("Cannot  translate  null Feder ationDocum entSetResu ltType");
  1136                             return  DocumentS etResult.c reateFullR esult(null );
  1137                    }
  1138                    Sort edSet<Docu mentSet> d ocumentSet s = transl ate(docume ntSetResul tType.getD ocumentSet s());
  1139                    Arti factResult Status art ifactResul tStatus =  translate( documentSe tResultTyp e.getArtif actResultS tatus());
  1140                    List <ArtifactR esultError > artifact ResultErro rs = trans late(docum entSetResu ltType.get Errors());           
  1141                    retu rn Documen tSetResult .create(do cumentSets , artifact ResultStat us, artifa ctResultEr rors);
  1142           }
  1143           
  1144           pr ivate stat ic SortedS et<Documen tSet> tran slate(Fede rationDocu mentSetTyp e [] docum entSets)
  1145           th rows Trans lationExce ption
  1146           {
  1147                    Sort edSet<Docu mentSet> r esult = ne w TreeSet< DocumentSe t>();
  1148                    if(d ocumentSet s == null)
  1149                             return  result;
  1150                    for( Federation DocumentSe tType docu mentSet :  documentSe ts)
  1151                    {
  1152                             result .add(trans late(docum entSet));
  1153                    }
  1154                    retu rn result;
  1155           }
  1156           
  1157           pr ivate stat ic Documen tSet trans late(Feder ationDocum entSetType  documentS et)
  1158           th rows Trans lationExce ption
  1159           {
  1160                    try
  1161                    {
  1162                             Docume ntSet resu lt = new D ocumentSet (OID.creat e(document Set.getHom eCommunity Id()), 
  1163                                               documentSe t.getRepos itoryId(),  documentS et.getIden tifier());
  1164                             
  1165                             result .setAcquis itionDate( documentSe t.getAcqui sitionDate ());
  1166                             result .setAlienS iteNumber( documentSe t.getAlien SiteNumber ());
  1167                             result .setClinic alType(doc umentSet.g etClinical Type());
  1168                             result .setErrorM essage(doc umentSet.g etErrorMes sage());
  1169                             result .setFirstI mageIen(do cumentSet. getFirstIm ageIen());
  1170                             result .setPatien tIcn(docum entSet.get PatientIcn ());
  1171                             result .setPatien tName(docu mentSet.ge tPatientNa me());
  1172                             result .setProced ureDate(do cumentSet. getProcedu reDate());
  1173                             result .setRpcRes ponseMsg(d ocumentSet .getRpcRes ponseMsg() );
  1174                             result .setSiteAb br(documen tSet.getSi teAbbr());
  1175                             result .setSiteNa me(documen tSet.getSi teName());
  1176                             result .setConsol idatedSite Number(doc umentSet.g etConsolid atedSiteNu mber());
  1177                             for(Fe derationDo cumentType  document  : document Set.getDoc uments())
  1178                             {
  1179                                      result.a dd(transla te(documen t, result) );
  1180                             }
  1181                             return  result;
  1182                    }
  1183                    catc h(OIDForma tException  oidfX)
  1184                    {
  1185                             throw  new Transl ationExcep tion("Unab le to crea te OID fro m Id '" +  documentSe t.getHomeC ommunityId () + "', "  + oidfX.g etMessage( ), oidfX);
  1186                    }
  1187           }
  1188           
  1189           pr ivate stat ic Documen t translat e(Federati onDocument Type docum ent, Docum entSet doc umentSet)
  1190           th rows Trans lationExce ption
  1191           {
  1192                    try
  1193                    {
  1194                             @Suppr essWarning s("uncheck ed")
  1195                             Global ArtifactId entifier g ai = 
  1196                                      GlobalAr tifactIden tifierFact ory.create (document. getIdentif ier(), Glo balArtifac tIdentifie r.class);
  1197                             if(gai  instanceo f ImageURN )
  1198                             {
  1199                                      // the i dentifier  is a URN c ontaining  the patien t ICN alre ady in it  so don't d o anything
  1200                                      // to it
  1201                             }
  1202                             else
  1203                             {
  1204                                      // JMW 1 2/10/2010  P104
  1205                                      // The p atient ICN  must come  from the  documentSe t, not the  document  since it i s not
  1206                                      // consi stently se t - the pa tientICN c omes from  the URN of  the docum ent, if it s not a UR N
  1207                                      // then  the ICN wi ll be null  from the  Document o bject. 
  1208                                      gai = Pa tientArtif actIdentif ierImpl.cr eate(gai,  documentSe t.getPatie ntIcn());
  1209                             }
  1210  
  1211                             
  1212                             Checks umValue ch ecksum = t ranslate(d ocument.ge tChecksum( ));
  1213                             Docume nt result  = new Docu ment(docum entSet, ga i, documen t.getCreat ionDate(),  
  1214                                               document.g etVistaIma geType(),  document.g etClinical Type(), do cument.get ContentLen th(), chec ksum);
  1215                             result .setConfid entialityC ode(docume nt.getConf identialit yCode());
  1216                             result .setDescri ption(docu ment.getDe scription( ));
  1217                             result .setLangua geCode(doc ument.getL anguageCod e());
  1218                             result .setMediaT ype(transl ate(docume nt.getMedi aType()));
  1219                             result .setName(d ocument.ge tName());
  1220                             result .setConsol idatedSite Number(doc ument.getC onsolidate dSiteNumbe r());
  1221                             
  1222                             return  result;
  1223                    }
  1224                    catc h(GlobalAr tifactIden tifierForm atExceptio n urnfX)
  1225                    {
  1226                             throw  new Transl ationExcep tion("Unab le to crea te GlobalA rtifactIde ntifier fr om identif ier '" + d ocument.ge tIdentifie r() + "',  " + urnfX. getMessage (), urnfX) ;
  1227                    }
  1228                    catc h(URNForma tException  urnfX)
  1229                    {
  1230                             throw  new Transl ationExcep tion("URNF ormatExcep tion, unab le to crea te Patient ArtifactId entifier f rom identi fier '" +  document.g etIdentifi er() + "'  and ICN '"  + documen tSet.getPa tientIcn()  + "', " +  urnfX.get Message(),  urnfX);
  1231                    }
  1232           }
  1233           
  1234           pu blic stati c MediaTyp e translat e(Federati onMediaTyp e mediaTyp e)
  1235           {
  1236                    for(  Entry<Med iaType, Fe derationMe diaType> e ntry : Fed erationRes tTranslato r.mediaTyp eMap.entry Set() )
  1237                             if( en try.getVal ue() == me diaType )
  1238                                      return e ntry.getKe y();
  1239                    
  1240                    retu rn MediaTy pe.APPLICA TION_OCTET STREAM;
  1241           }
  1242           
  1243           pu blic stati c Federati onMediaTyp e translat e(MediaTyp e mediaTyp e)
  1244           {
  1245                    for(  Entry<Med iaType, Fe derationMe diaType> e ntry : Fed erationRes tTranslato r.mediaTyp eMap.entry Set() )
  1246                             if( en try.getKey () == medi aType )
  1247                                      return e ntry.getVa lue();
  1248                    
  1249                    retu rn Federat ionMediaTy pe.APPLICA TION_OCTET STREAM;
  1250           }
  1251           
  1252           pr ivate stat ic Checksu mValue tra nslate(Fed erationChe cksumType  checksum)
  1253           {
  1254                    if(c hecksum ==  null)
  1255                             return  null;
  1256                    retu rn new Che cksumValue (checksum. getAlgorit hm(), chec ksum.getVa lue());
  1257           }
  1258           
  1259           pr ivate stat ic Federat ionChecksu mType tran slate(Chec ksumValue  checksum)
  1260           {
  1261                    if(c hecksum ==  null)
  1262                             return  null;
  1263                    Fede rationChec ksumType r esult = ne w Federati onChecksum Type();
  1264                    resu lt.setAlgo rithm(chec ksum.getAl gorithm()) ;
  1265                    resu lt.setValu e(checksum .getValue( ));
  1266                    retu rn result;
  1267           }
  1268           
  1269           pu blic stati c Federati onArtifact ResultsTyp e translat e(Artifact Results ar tifactResu lts)
  1270           th rows Trans lationExce ption
  1271           {
  1272                    if(a rtifactRes ults == nu ll)
  1273                             return  null;
  1274                    Fede rationArti factResult sType resu lt = new F ederationA rtifactRes ultsType() ;
  1275                    
  1276                    resu lt.setDocu mentSetRes ult(transl ate(artifa ctResults. getDocumen tSetResult ()));
  1277                    resu lt.setStud ySetResult (translate (artifactR esults.get StudySetRe sult()));
  1278                    
  1279                    retu rn result;           
  1280           }
  1281           
  1282           pu blic stati c Artifact Results tr anslate(Fe derationAr tifactResu ltsType ar tifactResu ltsType, S tudyFilter  studyFilt er)
  1283           th rows Trans lationExce ption
  1284           {
  1285                    if(a rtifactRes ultsType = = null)
  1286                             return  null;
  1287                    Stud ySetResult  studySetR esult = nu ll;
  1288                    if(a rtifactRes ultsType.g etStudySet Result() ! = null)
  1289                    {
  1290                             studyS etResult =  translate (artifactR esultsType .getStudyS etResult() , studyFil ter);
  1291                    }
  1292                    Docu mentSetRes ult docume ntSetResul t = null;
  1293                    if(a rtifactRes ultsType.g etDocument SetResult( ) != null)
  1294                    {
  1295                             docume ntSetResul t = transl ate(artifa ctResultsT ype.getDoc umentSetRe sult());
  1296                    }
  1297                    retu rn Artifac tResults.c reate(stud ySetResult , document SetResult) ;
  1298           }
  1299           
  1300           pu blic stati c StudySet Result tra nslate(Fed erationStu dyResultTy pe studyRe sultType,  StudyFilte r studyFil ter)
  1301           th rows Trans lationExce ption
  1302           {
  1303                    if(s tudyResult Type == nu ll)
  1304                    {
  1305                             getLog ger().erro r("Cannot  translate  null Feder ationStudy ResultType ");
  1306                             return  StudySetR esult.crea teFullResu lt(null);
  1307                    }
  1308                    Sort edSet<Stud y> studies  = transla te(studyRe sultType.g etStudies( ), studyFi lter);
  1309                    Arti factResult Status art ifactResul tStatus =  translate( studyResul tType.getA rtifactRes ultStatus( ));
  1310                    List <ArtifactR esultError > artifact ResultErro rs = trans late(study ResultType .getErrors ());                 
  1311                    
  1312                    retu rn StudySe tResult.cr eate(studi es, artifa ctResultSt atus, arti factResult Errors);                
  1313           }        
  1314           
  1315           pr ivate stat ic SortedS et<Study>  translate( Federation StudyType  [] studies , StudyFil ter studyF ilter)
  1316           th rows Trans lationExce ption
  1317           {
  1318                    Sort edSet<Stud y> result  = new Tree Set<Study> (); 
  1319                    if(s tudies ==  null)
  1320                             return  result;
  1321                    for( int i = 0;  i < studi es.length;  i++)
  1322                    {
  1323                             Federa tionStudyT ype studyT ype = stud ies[i];
  1324                             // CTB  29March20 10
  1325                             // eit her the st udy filter  has no st udy ID spe cified or  the study  IDs match
  1326                             // the  study ID  from the f ederation  call will  be base 32  encoded
  1327                             
  1328                             // JMW  6/1/2010  - need to  translate  first to g et the pro per URN to  determine  if allowe d to inclu de in resu lt
  1329                             Study  study = tr anslate(st udyType);
  1330                             boolea n useStudy  = true;
  1331                             if(stu dyFilter ! = null)
  1332                             {
  1333                                      useStudy  = !studyF ilter.isSt udyIenSpec ified() ||
  1334                                               studyFilte r.isAllowa bleStudyId ( study.ge tGlobalArt ifactIdent ifier()) | |
  1335                                                       st udyFilter. isAllowabl eStudyId(s tudy.getAl ternateArt ifactIdent ifier());                                             
  1336                             }
  1337                             if(use Study)
  1338                                      result.a dd(study);
  1339                    }                 
  1340                    // J MW 1/5/200 9 - if the  study IEN  is not sp ecified th en the res ults need  to be filt ered.
  1341                    // c all the pr e and post  filter si nce the pr e filter c annot run  on the Fed eration Da tasource b efore call ing the DS
  1342                    // b oth need t o be run d epending o n the crea tor - migh t have dif ferent fun ctionality  on the fi lter funct ions
  1343                    if(( studyFilte r != null)  && (!stud yFilter.is StudyIenSp ecified()) )
  1344                    {
  1345                             studyF ilter.preF ilter(resu lt);
  1346                             studyF ilter.post Filter(res ult);
  1347                    }
  1348                    retu rn result;
  1349           }
  1350           
  1351           @S uppressWar nings({ "d eprecation ", "unchec ked" })
  1352           pu blic stati c Study tr anslate(Fe derationSt udyType st udyType) 
  1353           th rows Trans lationExce ption
  1354           {
  1355                    Stud y study =  null;
  1356                    Stri ng studyId  = studyTy pe.getStud yId();
  1357                    Stud yLoadLevel  studyLoad Level = tr anslate(st udyType.ge tStudyLoad Level());
  1358                    try
  1359                    {
  1360                             study  = Study.cr eate(Objec tOrigin.UN KNOWN, stu dyType.get SiteNumber (), 
  1361                                               studyId, P atientIden tifier.icn PatientIde ntifier(st udyType.ge tPatientIc n()), 
  1362                                               studyLoadL evel, 
  1363                                               translate( studyType. getStudyDe letedImage State()),  studyType. isStudyInN ewDataStru cture());
  1364                    }
  1365                    catc h (URNForm atExceptio n x)
  1366                    {
  1367                             getLog ger().erro r("Unable  to create  a Study fr om the giv en key ele ments");
  1368                             throw  new Transl ationExcep tion("Unab le to crea te a Study  from the  given key  elements") ;
  1369                    }
  1370                    if(( studyType. getAlterna teArtifact Id() != nu ll) && (st udyType.ge tAlternate ArtifactId ().length( ) > 0))
  1371                    {
  1372                             try
  1373                             {
  1374                                      study.se tAlternate ArtifactId entifier(G lobalArtif actIdentif ierFactory .create(st udyType.ge tAlternate ArtifactId (), StudyU RN.class)) ;
  1375                             }
  1376                             catch( GlobalArti factIdenti fierFormat Exception  gaifX)
  1377                             {
  1378                                      getLogge r().error( "GlobalArt ifactIdent ifierForma tException  creating  alternate  artifact I D for stud y from val ue '" + st udyType.ge tAlternate ArtifactId () + "', "  + gaifX.g etMessage( ), gaifX);
  1379                             }
  1380                    }
  1381                    
  1382                    if ( studyType. getDescrip tion() !=  null)
  1383                    {
  1384                             study. setDescrip tion(study Type.getDe scription( ));
  1385                    }
  1386                    else
  1387                    {
  1388                             study. setDescrip tion("");
  1389                    }
  1390                    
  1391                    if(s tudyType.g etAlternat eExamNumbe r() != nul l)
  1392                    {
  1393                             study. setAlterna teExamNumb er(studyTy pe.getAlte rnateExamN umber());
  1394                    }
  1395                    else
  1396                    {
  1397                             study. setAlterna teExamNumb er("");
  1398                    }
  1399  
  1400                    stud y.setStudy Uid(studyT ype.getDic omUid());
  1401                    stud y.setImage Count(stud yType.getI mageCount( ));
  1402                    //st udy.setPat ientIcn(st udyType.ge tPatientIc n());
  1403                    if ( studyType. getPatient Name() ==  null)
  1404                    {
  1405                             studyT ype.setPat ientName(" ");
  1406                    }
  1407                    stud y.setPatie ntName(stu dyType.get PatientNam e().replac eAll("\\^" , " "));
  1408                    
  1409                    stud y.setProce dureDate(  studyType. getProcedu reDate() ) ;
  1410                    stud y.setProce dure(study Type.getPr ocedureDes cription()  == null ?  "" : stud yType.getP rocedureDe scription( ));
  1411                    //st udy.setRad iologyRepo rt((studyT ype.getRad iologyRepo rt() == nu ll ? "" :  studyType. getRadiolo gyReport() ));
  1412                    // J MW 10/12/2 010 - chec k the stud y load lev el to see  if the rep ort should  have been  included.  If not th en
  1413                    // d on't use t he report  value beca use it mig ht be an e mpty strin g which do esn't alwa ys mean th e report i s there
  1414                    // t his is a b it sad but  necessary  for some  reason
  1415                    if(s tudyLoadLe vel.isIncl udeReport( ))
  1416                             study. setRadiolo gyReport(s tudyType.g etRadiolog yReport()) ; // even  if its nul l, thats o k, means s tudy not l oaded
  1417                    
  1418                    stud y.setSiteN ame(studyT ype.getSit eName() ==  null ? ""  : studyTy pe.getSite Name());
  1419                    stud y.setSpeci alty(study Type.getSp ecialtyDes cription()  == null ?  "" : stud yType.getS pecialtyDe scription( ));
  1420  
  1421                    stud y.setOrigi n(studyTyp e.getOrigi n());
  1422                    stud y.setSiteA bbr(studyT ype.getSit eAbbreviat ion());
  1423                    if(s tudyType.g etStudyMod alities()  != null)
  1424                    {                         
  1425                             String [] modalit ies = stud yType.getS tudyModali ties();
  1426                             if(mod alities !=  null)
  1427                             {
  1428                                      for(int  i = 0; i <  modalitie s.length;  i++)
  1429                                      {
  1430                                               study.addM odality(mo dalities[i ]);
  1431                                      }
  1432                             }
  1433                    }
  1434                    
  1435                    // D isplay spe cific fiel ds
  1436                    stud y.setNoteT itle(study Type.getNo teTitle()) ;
  1437                    stud y.setImage Package(st udyType.ge tImagePack age());
  1438                    stud y.setImage Type(study Type.getIm ageType()) ;
  1439                    stud y.setEvent (studyType .getEvent( ));
  1440                    stud y.setOrigi n(studyTyp e.getOrigi n());
  1441                    stud y.setImage Package(st udyType.ge tImagePack age());
  1442                    stud y.setStudy Class(stud yType.getS tudyClass( ));
  1443                    stud y.setCaptu reDate(stu dyType.get CaptureDat e());
  1444                    stud y.setCaptu reBy(study Type.getCa pturedBy() );
  1445                    stud y.setRpcRe sponseMsg( studyType. getRpcResp onseMsg()) ;
  1446                    stud y.setError Message(st udyType.ge tErrorMess age() == n ull ? "" :  studyType .getErrorM essage());
  1447                    stud y.setDocum entDate(st udyType.ge tDocumentD ate());
  1448                    stud y.setSensi tive(study Type.isSen sitive());
  1449                    stud y.setStudy Status(tra nslate(stu dyType.get StudyStatu s()));
  1450                    stud y.setStudy ViewStatus (translate (studyType .getStudyV iewStatus( )));
  1451                    stud y.setCptCo de(studyTy pe.getCptC ode());
  1452                    stud y.setConso lidatedSit eNumber(st udyType.ge tConsolida tedSiteNum ber());
  1453                    stud y.setAlien SiteNumber (studyType .getAlienS iteNumber( ));
  1454                    stud y.setStudy ImagesHave Annotation s(studyTyp e.isStudyI magesHaveA nnotations ());
  1455                    stud y.setGroup Ien(studyT ype.getGro upIen());
  1456                    //st udy.setAlt ernateExam Number(stu dyType.get AlternateE xamNumber( ));
  1457                    stud y.setConte xtId(study Type.getCo ntextId()) ;
  1458                    stud y.setStudy InNewDataS tructure(s tudyType.i sStudyInNe wDataStruc ture());
  1459                    Imag e firstIma ge = null;
  1460                    
  1461                    firs tImage = t ranslate(s tudyType.g etFirstIma ge());
  1462                    if(s tudyType.g etSeries()  != null)
  1463                    {
  1464                             for(Fe derationSe riesType s eries : st udyType.ge tSeries())
  1465                             {
  1466                                      Series s er = trans late(serie s);
  1467                                      study.ad dSeries(se r);
  1468                                      if(first Image == n ull)
  1469                                      {
  1470                                               Iterator<I mage> iter  = ser.ite rator();
  1471                                               if(iter.ha sNext())
  1472                                                       fi rstImage =  iter.next ();
  1473                                      }
  1474                             }
  1475                    }
  1476                    
  1477                    if(f irstImage  != null)
  1478                    {
  1479                             study. setFirstIm age(firstI mage);
  1480                             study. setFirstIm ageIen(fir stImage.ge tIen());
  1481                    }
  1482                    
  1483                    retu rn study;
  1484           }
  1485           
  1486           pu blic stati c ObjectSt atus trans late(Feder ationObjec tStatusTyp e objectSt atus)
  1487           {
  1488                    for( Entry<Obje ctStatus,  Federation ObjectStat usType> en try : obje ctStatusMa p.entrySet ())
  1489                    {
  1490                             if(ent ry.getValu e() == obj ectStatus)
  1491                                      return e ntry.getKe y();
  1492                    }
  1493                    retu rn ObjectS tatus.UNKN OWN;
  1494           }
  1495           
  1496           pu blic stati c Federati onObjectSt atusType t ranslate(O bjectStatu s objectSt atus)
  1497           {
  1498                    for( Entry<Obje ctStatus,  Federation ObjectStat usType> en try : obje ctStatusMa p.entrySet ())
  1499                    {
  1500                             if(ent ry.getKey( ) == objec tStatus)
  1501                                      return e ntry.getVa lue();
  1502                    }
  1503                    retu rn Federat ionObjectS tatusType. UNKNOWN;
  1504           }
  1505           
  1506           pu blic stati c Federati onStudyRes ultType tr anslate(St udySetResu lt studySe t)
  1507           th rows Trans lationExce ption
  1508           {
  1509                    if(s tudySet ==  null)
  1510                             return  null;
  1511                    
  1512                    Fede rationStud yResultTyp e result =  new Feder ationStudy ResultType ();
  1513                    resu lt.setStud ies(transl ate(studyS et.getArti facts()));
  1514                    resu lt.setArti factResult Status(tra nslate(stu dySet.getA rtifactRes ultStatus( )));
  1515                    resu lt.setErro rs(transla teArtifact ResultErro rList(stud ySet.getAr tifactResu ltErrors() ));
  1516                    retu rn result;           
  1517           }
  1518           
  1519           pr ivate stat ic List<Ar tifactResu ltError> t ranslate(F ederationA rtifactRes ultErrorTy pe [] erro rs)
  1520           {
  1521                    if(e rrors == n ull)
  1522                             return  null;
  1523                    
  1524                    List <ArtifactR esultError > result =  new Array List<Artif actResultE rror>(erro rs.length) ;
  1525                    for( Federation ArtifactRe sultErrorT ype error  : errors)
  1526                    {
  1527                             result .add(trans late(error ));
  1528                    }
  1529                    
  1530                    retu rn result;
  1531           }
  1532           
  1533           pr ivate stat ic Artifac tResultErr or transla te(Federat ionArtifac tResultErr orType err or)
  1534           {
  1535                    Stri ng context  = error.g etCodeCont ext();
  1536                    Stri ng locatio n = error. getLocatio n();
  1537                    Arti factResult ErrorCode  errorCode  = translat e(error.ge tErrorCode ());
  1538                    Arti factResult ErrorSever ity severi ty = trans late(error .getSeveri ty());
  1539                    retu rn new Fed erationArt ifactResul tError(con text, loca tion, erro rCode, sev erity);
  1540           }
  1541           
  1542           pr ivate stat ic Federat ionArtifac tResultErr orType []  translateA rtifactRes ultErrorLi st(List<Ar tifactResu ltError> e rrors)
  1543           {
  1544                    if(e rrors == n ull)
  1545                             return  null;
  1546                    
  1547                    Fede rationArti factResult ErrorType  [] result  = new Fede rationArti factResult ErrorType  [errors.si ze()];
  1548                    int  i = 0;
  1549                    for( ArtifactRe sultError  error : er rors)
  1550                    {
  1551                             result [i] = tran slate(erro r);
  1552                             i++;
  1553                    }
  1554                    
  1555                    retu rn result;
  1556           }
  1557           
  1558           pr ivate stat ic Federat ionArtifac tResultErr orType tra nslate(Art ifactResul tError err or)
  1559           {
  1560                    Fede rationArti factResult ErrorType  result = n ew Federat ionArtifac tResultErr orType();
  1561                    
  1562                    resu lt.setCode Context(er ror.getCod eContext() );
  1563                    resu lt.setLoca tion(error .getLocati on());
  1564                    resu lt.setErro rCode(tran slate(erro r.getError Code()));
  1565                    resu lt.setSeve rity(trans late(error .getSeveri ty()));
  1566                    retu rn result;
  1567           }
  1568           
  1569           pu blic stati c Federati onArtifact ResultErro rSeverityT ype transl ate(Artifa ctResultEr rorSeverit y artifact ResultErro rSeverity)
  1570           {
  1571                    for( Entry<Arti factResult ErrorSever ity, Feder ationArtif actResultE rrorSeveri tyType> en try : Fede rationRest Translator .artifactR esultError SeverityMa p.entrySet ())
  1572                    {
  1573                             if(ent ry.getKey( ) == artif actResultE rrorSeveri ty)
  1574                             {
  1575                                      return e ntry.getVa lue();
  1576                             }
  1577                    }
  1578                    retu rn Federat ionArtifac tResultErr orSeverity Type.error ;
  1579           }
  1580           
  1581           pu blic stati c Artifact ResultErro rSeverity  translate( Federation ArtifactRe sultErrorS everityTyp e artifact ResultErro rSeverityT ype)
  1582           {
  1583                    for( Entry<Arti factResult ErrorSever ity, Feder ationArtif actResultE rrorSeveri tyType> en try : Fede rationRest Translator .artifactR esultError SeverityMa p.entrySet ())
  1584                    {
  1585                             if(ent ry.getValu e() == art ifactResul tErrorSeve rityType)
  1586                             {
  1587                                      return e ntry.getKe y();
  1588                             }
  1589                    }
  1590                    retu rn Artifac tResultErr orSeverity .error;
  1591           }
  1592           
  1593           pu blic stati c Federati onArtifact ResultErro rCodeType  translate( ArtifactRe sultErrorC ode artifa ctResultEr rorCode)
  1594           {
  1595                    for( Entry<Arti factResult ErrorCode,  Federatio nArtifactR esultError CodeType>  entry : Fe derationRe stTranslat or.artifac tResultErr orCodeMap. entrySet() )
  1596                    {
  1597                             if(ent ry.getKey( ) == artif actResultE rrorCode)
  1598                             {
  1599                                      return e ntry.getVa lue();
  1600                             }
  1601                    }
  1602                    retu rn Federat ionArtifac tResultErr orCodeType .internalE xception;
  1603           }
  1604           
  1605           pu blic stati c Artifact ResultErro rCode tran slate(Fede rationArti factResult ErrorCodeT ype artifa ctResultEr rorCodeTyp e)
  1606           {
  1607                    for( Entry<Arti factResult ErrorCode,  Federatio nArtifactR esultError CodeType>  entry : Fe derationRe stTranslat or.artifac tResultErr orCodeMap. entrySet() )
  1608                    {
  1609                             if(ent ry.getValu e() == art ifactResul tErrorCode Type)
  1610                             {
  1611                                      return e ntry.getKe y();
  1612                             }
  1613                    }
  1614                    retu rn Artifac tResultErr orCode.int ernalExcep tion;
  1615           }        
  1616           
  1617           pu blic stati c Federati onStudyTyp e [] trans late(Colle ction<Stud y> studies )
  1618           th rows Trans lationExce ption
  1619           {
  1620                    if(s tudies ==  null)
  1621                             return  null;
  1622                    
  1623                    Fede rationStud yType [] r esult = ne w Federati onStudyTyp e [studies .size()];
  1624                    int  i = 0;
  1625                    for( Study stud y : studie s)
  1626                    {
  1627                             result [i] = tran slate(stud y);
  1628                             i++;
  1629                    }
  1630                    
  1631                    retu rn result;
  1632           }
  1633           
  1634           pu blic stati c Federati onStudyTyp e translat e(Study st udy)
  1635           th rows Trans lationExce ption
  1636           {
  1637                    if(s tudy == nu ll)
  1638                             return  null;
  1639                    Fede rationStud yType resu lt = 
  1640                             new Fe derationSt udyType();
  1641                    Fede rationStud yLoadLevel Type loadL evel = tra nslate(stu dy.getStud yLoadLevel ());
  1642                    resu lt.setStud yLoadLevel ( loadLeve l );
  1643                    resu lt.setStud yDeletedIm ageState(t ranslate(s tudy.getSt udyDeleted ImageState ()));
  1644                    //re sult.setDe scription( study.getD escription ());
  1645                    
  1646                    resu lt.setEven t(study.ge tEvent());
  1647                    resu lt.setImag eCount(stu dy.getImag eCount());
  1648                    resu lt.setImag ePackage(s tudy.getIm agePackage ());
  1649                    resu lt.setImag eType(stud y.getImage Type());
  1650                    resu lt.setNote Title(stud y.getNoteT itle());
  1651                    resu lt.setOrig in(study.g etOrigin() );
  1652                    resu lt.setPati entIcn(stu dy.getPati entId());
  1653                    resu lt.setPati entName(st udy.getPat ientName() );
  1654                    resu lt.setProc edureDescr iption(stu dy.getProc edure());
  1655                    resu lt.setRadi ologyRepor t(study.ge tRadiology Report());
  1656                    resu lt.setSite Number(stu dy.getSite Number());
  1657                    resu lt.setSite Name(study .getSiteNa me());
  1658                    resu lt.setSite Abbreviati on(study.g etSiteAbbr ());
  1659                    resu lt.setSpec ialtyDescr iption(stu dy.getSpec ialty());
  1660                    resu lt.setProc edureDate( study.getP rocedureDa te());
  1661                    
  1662                    resu lt.setStud yPackage(s tudy.getIm agePackage ());
  1663                    resu lt.setStud yClass(stu dy.getStud yClass() = = null ? " " : study. getStudyCl ass());
  1664                    resu lt.setStud yType(stud y.getImage Type());
  1665                    resu lt.setCapt ureDate(st udy.getCap tureDate() );
  1666                    resu lt.setCapt uredBy(stu dy.getCapt ureBy());      
  1667                    resu lt.setRpcR esponseMsg (study.get RpcRespons eMsg());
  1668                    
  1669                    resu lt.setDocu mentDate(s tudy.getDo cumentDate ());
  1670                    resu lt.setSens itive(stud y.isSensit ive());
  1671                    resu lt.setStud yStatus(tr anslate(st udy.getStu dyStatus() ));
  1672                    resu lt.setStud yViewStatu s(translat e(study.ge tStudyView Status())) ;
  1673                    resu lt.setCptC ode(study. getCptCode ());
  1674                    resu lt.setCons olidatedSi teNumber(s tudy.getCo nsolidated SiteNumber ());
  1675                    resu lt.setAlie nSiteNumbe r(study.ge tAlienSite Number());
  1676                    resu lt.setAlte rnateExamN umber(stud y.getAlter nateExamNu mber());
  1677                    resu lt.setGrou pIen(study .getGroupI en());
  1678                    resu lt.setCont extId(stud y.getConte xtId());
  1679                    resu lt.setStud yInNewData Structure( study.isSt udyInNewDa taStructur e());
  1680                    if(s tudy.getAl ternateArt ifactIdent ifier() !=  null)
  1681                    {
  1682                             result .setAltern ateArtifac tId(study. getAlterna teArtifact Identifier ().toStrin g());
  1683                    }
  1684                    
  1685                    resu lt.setDesc ription(st udy.getDes cription()  == null ?  "" : stud y.getDescr iption());
  1686  
  1687                    resu lt.setErro rMessage(s tudy.getEr rorMessage () == null  ? "" : st udy.getErr orMessage( ));
  1688                    // r eturn null  for the U ID instead  of the em pty string  to be con sistent wi th the WSD L - DKB
  1689                    if ( study.getS tudyUid()  != null &&  study.get StudyUid() .trim().le ngth() > 0 )
  1690                             result .setDicomU id(study.g etStudyUid ());
  1691                    else
  1692                             result .setDicomU id(null);
  1693                    
  1694                    resu lt.setStud yId(study. getStudyIe n());
  1695                    
  1696                    if(s tudy.getSe ries() !=  null)
  1697                    {
  1698                             Federa tionSeries Type [] se riesSet =  new Federa tionSeries Type[study .getSeries Count()]; 
  1699                             int i  = 0;
  1700                             for(Se ries serie s : study)
  1701                             {
  1702                                      seriesSe t[i] = tra nslate(ser ies);
  1703                                      i++;
  1704                             }
  1705                             result .setSeries (seriesSet );
  1706                    }
  1707                    
  1708                    //WF P-I want t o know why  this now  works corr ectly when  I removed  the excep tion.
  1709                    //       The st udy still  contains t he firstIm age Image  object.
  1710                    //       Yet at  this poin t it is nu ll.
  1711                    if(s tudy.getFi rstImage()  == null)
  1712                    //       throw  new Transl ationExcep tion("Stud y.firstIma ge is null , translat ion of stu dy '" + st udy.getStu dyUrn() +  "' cannot  continue." );
  1713                             getLog ger().warn ("First Im age is nul l.");
  1714                             
  1715                    Fede rationImag eType firs tImage = t ranslate(s tudy.getFi rstImage() );
  1716                    resu lt.setFirs tImage(fir stImage);
  1717                    if(f irstImage  != null)
  1718                             result .setFirstI mageIen(fi rstImage.g etImageId( ));
  1719                    
  1720                    if(s tudy.getMo dalities()  != null)
  1721                             result .setStudyM odalities( study.getM odalities( ).toArray( new String  [study.ge tModalitie s().size() ]));
  1722                    resu lt.setStud yImagesHav eAnnotatio ns(study.i sStudyImag esHaveAnno tations()) ;
  1723                    retu rn result;
  1724           }
  1725           
  1726           pu blic stati c Federati onSeriesTy pe [] tran slate(
  1727                             Set<Se ries> seri esSet) 
  1728                    thro ws ParseEx ception
  1729                    {
  1730                             if(ser iesSet ==  null)// ||  seriesSet .size() ==  0)
  1731                                      return n ull;
  1732                             
  1733                             Federa tionSeries Type [] re sult = new  Federatio nSeriesTyp e[seriesSe t.size()];
  1734                             int i  = 0;
  1735                             for(Se ries serie s : series Set)
  1736                             {
  1737                                      result[i ] = transl ate(series );
  1738                                      i++;
  1739                             }
  1740                             
  1741                             return  result;
  1742                    }
  1743           
  1744           pu blic stati c Series t ranslate(F ederationS eriesType  series)
  1745           {
  1746                    if(s eries == n ull)
  1747                             return  null;
  1748                    
  1749                    Seri es result 
  1750                             new Se ries();
  1751  
  1752                    // J MW 2/12/20 13 - if th e images a re empty t hen they m ight come  across as  a null arr ay
  1753                    // c heck for n ull to avo id a NPE
  1754                    Fede rationImag eType [] i mages = se ries.getIm ages();
  1755                    if(i mages != n ull)
  1756                    {
  1757                             for(Fe derationIm ageType im age : imag es)
  1758                                      result.a ddImage(tr anslate(im age));
  1759                    }
  1760  
  1761                    resu lt.setSeri esUid(seri es.getSeri esUid());
  1762                    resu lt.setSeri esNumber(s eries.getS eriesNumbe r());        
  1763                    resu lt.setSeri esIen(seri es.getSeri esIen());
  1764                    resu lt.setModa lity(serie s.getModal ity());
  1765                    
  1766                    retu rn result;
  1767           }
  1768           
  1769           pu blic stati c Federati onSeriesTy pe transla te(Series  series)
  1770           {
  1771                    if(s eries == n ull)
  1772                             return  null;
  1773                    
  1774                    Fede rationSeri esType res ult = 
  1775                             new Fe derationSe riesType() ;
  1776                    Fede rationImag eType [] i nstances =  
  1777                             new Fe derationIm ageType[se ries.getIm ageCount() ];
  1778  
  1779                    int  index=0;
  1780                    for( Image imag e : series )
  1781                             instan ces[index+ +] = trans late(image );
  1782                    resu lt.setImag es(instanc es);
  1783  
  1784                    resu lt.setSeri esUid(seri es.getSeri esUid());
  1785                    resu lt.setSeri esNumber(s eries.getS eriesNumbe r());        
  1786                    resu lt.setSeri esIen(seri es.getSeri esIen());
  1787                    resu lt.setModa lity(serie s.getModal ity());
  1788                    
  1789                    retu rn result;
  1790           }
  1791           
  1792           pu blic stati c RoutingT oken trans lateRoutin gToken(Str ing serial izedRoutin gToken)
  1793           th rows Routi ngTokenFor matExcepti on
  1794           {
  1795                    retu rn Routing TokenImpl. parse(seri alizedRout ingToken);
  1796           }
  1797           
  1798           pu blic stati c StudyLoa dLevel tra nslate(
  1799                             Federa tionStudyL oadLevelTy pe loadLev elType)
  1800                    {                 
  1801                             for( E ntry<Study LoadLevel,  Federatio nStudyLoad LevelType>  entry : F ederationR estTransla tor.loadLe velMap.ent rySet() )
  1802                                      if( entr y.getValue () == load LevelType  )
  1803                                               return ent ry.getKey( );
  1804                             
  1805                             return  StudyLoad Level.FULL ;
  1806                    }        
  1807           
  1808           pu blic stati c Federati onStudyLoa dLevelType  translate (
  1809                             StudyL oadLevel l oadLevel)
  1810                    {                 
  1811                             for( E ntry<Study LoadLevel,  Federatio nStudyLoad LevelType>  entry : F ederationR estTransla tor.loadLe velMap.ent rySet() )
  1812                                      if( entr y.getKey()  == loadLe vel )
  1813                                               return ent ry.getValu e();
  1814                             
  1815                             return  Federatio nStudyLoad LevelType. FULL;
  1816                    }        
  1817           
  1818           pu blic stati c Image tr anslate(Fe derationIm ageType in stanceType
  1819           // throws Tra nslationEx ception
  1820           {
  1821                    if(i nstanceTyp e == null)
  1822                             return  null;             
  1823                    Imag e image =  null;
  1824                    try
  1825                    {
  1826                             if(ins tanceType. isImageInN ewDataStru cture()){
  1827                                      image =  Image.crea te(
  1828                                                       in stanceType .getSiteNu mber(), 
  1829                                                       in stanceType .getImageI d(),               
  1830                                                       in stanceType .getStudyI d(),
  1831                                                       Pa tientIdent ifier.icnP atientIden tifier(ins tanceType. getPatient Icn()),
  1832                                                       in stanceType .getFullAr tifactIen( ),
  1833                                                       in stanceType .getAbsArt ifactIen() ,
  1834                                                       in stanceType .getImageM odality(),
  1835                                                       in stanceType .isImageIn NewDataStr ucture()
  1836                                               );                                 
  1837                             }
  1838                             else{
  1839                                      image =  Image.crea te(
  1840                                               instanceTy pe.getSite Number(), 
  1841                                               instanceTy pe.getImag eId(),               
  1842                                               instanceTy pe.getStud yId(),
  1843                                               PatientIde ntifier.ic nPatientId entifier(i nstanceTyp e.getPatie ntIcn()), 
  1844                                               instanceTy pe.getImag eModality(
  1845                                      );
  1846                             }
  1847                    }
  1848                    catc h (URNForm atExceptio n x)
  1849                    {
  1850                             getLog ger().erro r("Unable  to create  an Image i nstance fr om the giv en key ele ments.", x );
  1851                             return  null;
  1852                    }
  1853                    
  1854                    imag e.setImage Number(ins tanceType. getImageNu mber() ==  null ? ""  : instance Type.getIm ageNumber( ) + "");
  1855                    imag e.setImage Uid(instan ceType.get DicomUid()  == null ?  "" : inst anceType.g etDicomUid ());
  1856  
  1857                    imag e.setDescr iption("") ;
  1858                    imag e.setAlter nateExamNu mber("");
  1859  
  1860                    if(i nstanceTyp e.getDescr iption() ! = null)
  1861                    {
  1862                             String  descripti onElement  = instance Type.getDe scription( );
  1863                             image. setDescrip tion(descr iptionElem ent);
  1864  
  1865                             String [] parts =  StringUti l.split(de scriptionE lement, St ringUtil.R IGHT_BRACK ET);
  1866                             if (pa rts.length  > 0)
  1867                             {
  1868                                      String a ltExamNumb er = parts [0];
  1869                                      altExamN umber = al tExamNumbe r.substrin g(1).trim( );
  1870                                      image.se tAlternate ExamNumber (altExamNu mber);
  1871                                      getLogge r().debug( "Exam#: "+ altExamNum ber);
  1872                             }
  1873                    }
  1874  
  1875                    //im age.setPat ientICN(in stanceType .getPatien tIcn());
  1876                    imag e.setPatie ntName(ins tanceType. getPatient Name() ==  null ? ""  : instance Type.getPa tientName( ).replaceA ll("\\^",  " "));
  1877                    imag e.setProce dureDate(i nstanceTyp e.getProce dureDate()  );
  1878                    imag e.setProce dure(insta nceType.ge tProcedure () == null  ? "" : in stanceType .getProced ure());
  1879                    imag e.setSiteA bbr(instan ceType.get SiteAbbr() );
  1880                    imag e.setFullL ocation(in stanceType .getFullLo cation());
  1881                    imag e.setFullF ilename(in stanceType .getFullIm ageFilenam e());
  1882                    imag e.setAbsLo cation(ins tanceType. getAbsLoca tion());
  1883                    imag e.setAbsFi lename(ins tanceType. getAbsImag eFilename( ));
  1884                    imag e.setDicom ImageNumbe rForDispla y(instance Type.getDi comImageNu mberForDis play() ==  null ? ""  : instance Type.getDi comImageNu mberForDis play() + " ");
  1885                    imag e.setDicom SequenceNu mberForDis play(insta nceType.ge tDicomSequ enceNumber ForDisplay () == null  ? "" : in stanceType .getDicomS equenceNum berForDisp lay() + "" );
  1886                    imag e.setImgTy pe(instanc eType.getI mageType() );
  1887                    imag e.setImage Class(inst anceType.g etImageCla ss());
  1888                    imag e.setBigFi lename(ins tanceType. getBigImag eFilename( ));
  1889                    imag e.setQaMes sage(insta nceType.ge tQaMessage ());
  1890                    //im age.setIma geModality (instanceT ype.getIma geModality () == null  ? "" : in stanceType .getImageM odality()) ;
  1891                    imag e.setError Message(in stanceType .getErrorM essage() = = null ? " " : instan ceType.get ErrorMessa ge());
  1892                    imag e.setAlien SiteNumber (instanceT ype.getAli enSiteNumb er());
  1893                    imag e.setConso lidatedSit eNumber(in stanceType .getConsol idatedSite Number());
  1894                    imag e.setImage Annotation Status(ins tanceType. getImageAn notationSt atus());
  1895                    imag e.setImage Annotation StatusDesc ription(in stanceType .getImageA nnotationS tatusDescr iption());
  1896                    imag e.setAssoc iatedNoteR esulted(in stanceType .getAssoci atedNoteRe sulted());
  1897                    imag e.setImage Package(in stanceType .getImageP ackage());
  1898                    imag e.setImage HasAnnotat ions(insta nceType.is ImageHasAn notations( ));
  1899                    
  1900                    imag e.setCaptu reDate(ins tanceType. getCapture Date());
  1901                    imag e.setDocum entDate(in stanceType .getDocume ntDate());
  1902                    imag e.setSensi tive(insta nceType.is Sensitive( ));
  1903                    imag e.setImage ViewStatus (translate (instanceT ype.getIma geViewStat us()));
  1904                    imag e.setImage Status(tra nslate(ins tanceType. getImageSt atus()));
  1905                    imag e.setImage InNewDataS tructure(i nstanceTyp e.isImageI nNewDataSt ructure()) ;
  1906                    imag e.setAbsAr tifactIen( instanceTy pe.getAbsA rtifactIen ());
  1907                    imag e.setFullA rtifactIen (instanceT ype.getFul lArtifactI en());
  1908                    imag e.setAbsDi skVolumeIe n(instance Type.getAb sDiskVolum eIen());
  1909                    imag e.setFullD iskVolumeI en(instanc eType.getF ullDiskVol umeIen());
  1910                    imag e.setFullF ilespec(in stanceType .getFullFi lespec());
  1911                    imag e.setAbsFi lespec(ins tanceType. getAbsFile spec());
  1912                    imag e.setFullF ilepath(in stanceType .getFullFi lepath());
  1913                    imag e.setAbsFi lepath(ins tanceType. getAbsFile path());
  1914                    
  1915                    retu rn image;
  1916           }
  1917           
  1918           pu blic stati c Federati onImageTyp e translat e(Image im age)
  1919           {
  1920                    if(i mage == nu ll)
  1921                             return  null;
  1922                    Fede rationImag eType resu lt = new F ederationI mageType() ;
  1923                    resu lt.setImag eId( image .getIen()  );             
  1924                    
  1925                    // E xchange fi elds
  1926                    // r eturn null  for the U ID instead  of the em pty string  to be con sistent wi th the WSD L - DKB
  1927                    if ( image.getI mageUid()! = null &&  image.getI mageUid(). trim().len gth() > 0)
  1928                    {
  1929                             result .setDicomU id(image.g etImageUid ().trim()) ;
  1930                    }
  1931                    
  1932                    
  1933                    if ( image.getI mageNumber () != null  && image. getImageNu mber().tri m().length () > 0)
  1934                    {
  1935                             try
  1936                             {
  1937                                      Integer  imageNumbe r = new In teger(imag e.getImage Number());
  1938                                      result.s etImageNum ber(imageN umber);
  1939                             }
  1940                             catch  (NumberFor matExcepti on ex)
  1941                             {
  1942                                      // not a  number -  return nul l
  1943                                      result.s etImageNum ber(null);
  1944                             }
  1945                    }
  1946                    else
  1947                    {
  1948                             result .setImageN umber(null );
  1949                    }
  1950                    
  1951                    // C linical Di splay fiel ds
  1952                    resu lt.setDesc ription(im age.getDes cription() );
  1953                    resu lt.setDico mImageNumb erForDispl ay(image.g etDicomIma geNumberFo rDisplay() );
  1954                    resu lt.setDico mSequenceN umberForDi splay(imag e.getDicom SequenceNu mberForDis play());
  1955                    resu lt.setPati entIcn(ima ge.getPati entId());
  1956                    resu lt.setPati entName(im age.getPat ientName() );
  1957                    resu lt.setProc edure(imag e.getProce dure());
  1958                    if(i mage.getPr ocedureDat e() == nul l)
  1959                    {
  1960                             getLog ger().warn ("Setting  null proce dure date  for image" );
  1961                             result .setProced ureDate(nu ll);
  1962                    }
  1963                    else  
  1964                    {
  1965                             /*
  1966                             // if  the hour a nd minute  are not 0,  then like ly they co ntain real  values fo r hour and  minute (n ot 00:00)
  1967                             // thi s leaves o pen the po ssibility  of invalid  data, if  the real d ate was at  00:00 the n this wou ld not sho w that tim e.
  1968                             // we  would then  omit data , not show  invalid d ata
  1969                             if((im age.getPro cedureDate ().getHour s() > 0) & & (image.g etProcedur eDate().ge tMinutes()  > 0))
  1970                             {
  1971                                      instance Type.setPr ocedureDat e(getFeder ationWebse rviceLongD ateFormat( ).format(i mage.getPr ocedureDat e()));
  1972                             }
  1973                             else
  1974                             {
  1975                                      instance Type.setPr ocedureDat e(getFeder ationWebse rviceShort DateFormat ().format( image.getP rocedureDa te()));
  1976                             }
  1977                             */
  1978                             result .setProced ureDate(im age.getPro cedureDate ());
  1979                    }
  1980                    resu lt.setSite Number(ima ge.getSite Number());
  1981                    resu lt.setSite Abbr(image .getSiteAb br());
  1982                    resu lt.setImag eClass(ima ge.getImag eClass());
  1983                    resu lt.setAbsL ocation(im age.getAbs Location() );
  1984                    resu lt.setFull Location(i mage.getFu llLocation ());
  1985                    resu lt.setAbsA rtifactIen (image.get AbsArtifac tIen());
  1986                    resu lt.setFull ArtifactIe n(image.ge tFullArtif actIen());
  1987                    
  1988                    resu lt.setQaMe ssage(imag e.getQaMes sage());
  1989                    resu lt.setImag eType(imag e.getImgTy pe());
  1990                    resu lt.setFull ImageFilen ame(image. getFullFil ename());
  1991                    resu lt.setAbsI mageFilena me(image.g etAbsFilen ame());
  1992                    resu lt.setBigI mageFilena me(image.g etBigFilen ame());
  1993  
  1994                    resu lt.setStud yId( image .getStudyI en() );
  1995                    resu lt.setImag eModality( image.getI mageModali ty());
  1996                    resu lt.setErro rMessage(i mage.getEr rorMessage () == null  ? "" : im age.getErr orMessage( ));
  1997                    resu lt.setCons olidatedSi teNumber(i mage.getCo nsolidated SiteNumber ());
  1998                    resu lt.setAlie nSiteNumbe r(image.ge tAlienSite Number());
  1999                    resu lt.setAsso ciatedNote Resulted(i mage.getAs sociatedNo teResulted ());
  2000                    resu lt.setImag eAnnotatio nStatus(im age.getIma geAnnotati onStatus() );
  2001                    resu lt.setImag eAnnotatio nStatusDes cription(i mage.getIm ageAnnotat ionStatusD escription ());
  2002                    resu lt.setImag eHasAnnota tions(imag e.isImageH asAnnotati ons());
  2003                    resu lt.setImag ePackage(i mage.getIm agePackage ());
  2004                    
  2005                    resu lt.setCapt ureDate(im age.getCap tureDate() );
  2006                    resu lt.setDocu mentDate(i mage.getDo cumentDate ());
  2007                    resu lt.setSens itive(imag e.isSensit ive());
  2008                    resu lt.setImag eViewStatu s(translat e(image.ge tImageView Status())) ;
  2009                    resu lt.setImag eStatus(tr anslate(im age.getIma geStatus() ));
  2010                    resu lt.setImag eInNewData Structure( image.isIm ageInNewDa taStructur e());
  2011                    
  2012                    
  2013                    resu lt.setAbsD iskVolumeI en(image.g etAbsDiskV olumeIen() );
  2014                    resu lt.setFull DiskVolume Ien(image. getFullDis kVolumeIen ());
  2015                    resu lt.setFull Filespec(i mage.getFu llFilespec ());
  2016                    resu lt.setAbsF ilespec(im age.getAbs Filespec() );
  2017                    resu lt.setFull Filepath(i mage.getFu llFilepath ());
  2018                    resu lt.setAbsF ilepath(im age.getAbs Filepath() );
  2019                    
  2020                    retu rn result;
  2021                    
  2022           }
  2023           
  2024           pu blic stati c Federati onPatientS ensitiveTy pe transla te(
  2025                             Patien tSensitive Value pati entSensiti veValue)
  2026           {
  2027                    Fede rationPati entSensiti veType res ult = new  Federation PatientSen sitiveType ();
  2028                    resu lt.setWarn ingMessage (patientSe nsitiveVal ue.getWarn ingMessage ());
  2029                    resu lt.setSens itiveLevel (translate (patientSe nsitiveVal ue.getSens itiveLevel ()));
  2030                    retu rn result;
  2031           }
  2032           
  2033           pu blic stati c List<Str ing> trans late(Strin g [] sites )
  2034           {
  2035                    List <String> r esult = ne w ArrayLis t<String>( sites.leng th);
  2036                    for( String sit e : sites)
  2037                    {
  2038                             result .add(site) ;
  2039                    }
  2040                    retu rn result;
  2041           }
  2042           
  2043           pu blic stati c String [ ] translat eResolvedA rtifactSou rceList(Li st<Resolve dArtifactS ource> sit es)
  2044           {
  2045                    Stri ng [] resu lt = new S tring[site s.size()];
  2046                    for( int i = 0;  i < sites .size(); i ++)
  2047                    {
  2048                             result [i] = site s.get(i).g etArtifact Source().g etReposito ryId();
  2049                    }
  2050                    retu rn result;
  2051           }
  2052           
  2053           pu blic stati c PatientS ensitiveVa lue transl ate(
  2054                             Federa tionPatien tSensitive Type patie ntSensitiv eValue)
  2055           {
  2056                    retu rn new Pat ientSensit iveValue(t ranslate(p atientSens itiveValue .getSensit iveLevel() ), 
  2057                                      patientS ensitiveVa lue.getWar ningMessag e());
  2058           }
  2059           
  2060           pr ivate stat ic Federat ionPatient Sensitivit yLevelType  translate (
  2061                             Patien tSensitivi tyLevel pa tientSensi tivityLeve l)
  2062           {
  2063                    for(  Entry<Pat ientSensit ivityLevel , Federati onPatientS ensitivity LevelType>  entry : F ederationR estTransla tor.patien tSensitive LevelMap.e ntrySet()  )
  2064                             if( en try.getKey () == pati entSensiti vityLevel  )
  2065                                      return e ntry.getVa lue();
  2066                    
  2067                    retu rn Federat ionPatient Sensitivit yLevelType .NO_ACTION _REQUIRED;
  2068           }
  2069           
  2070           pr ivate stat ic Patient Sensitivit yLevel tra nslate(
  2071                             Federa tionPatien tSensitivi tyLevelTyp e patientS ensitivity Level)
  2072           {
  2073                    for(  Entry<Pat ientSensit ivityLevel , Federati onPatientS ensitivity LevelType>  entry : F ederationR estTransla tor.patien tSensitive LevelMap.e ntrySet()  )
  2074                             if( en try.getVal ue() == pa tientSensi tivityLeve l )
  2075                                      return e ntry.getKe y();
  2076                    
  2077                    retu rn Patient Sensitivit yLevel.NO_ ACTION_REQ UIRED;
  2078           }
  2079  
  2080           pu blic stati c Federati onPatientT ype[] tran slatePatie ntList(Lis t<Patient>  patients)
  2081           {
  2082                    Fede rationPati entType[]  result = n ew Federat ionPatient Type[patie nts.size() ];
  2083                    for( int i = 0;  i < patie nts.size() ; i++)
  2084                    {
  2085                             result [i] = tran slate(pati ents.get(i ));
  2086                    }
  2087                    retu rn result;
  2088           }
  2089           
  2090           pu blic stati c List<Pat ient> tran slate(Fede rationPati entType []  patients)
  2091           {
  2092                    List <Patient>  result = n ew ArrayLi st<Patient >(patients .length);
  2093                    for( Federation PatientTyp e patient  : patients )
  2094                    {
  2095                             result .add(trans late(patie nt));
  2096                    }
  2097                    retu rn result;
  2098           }
  2099           
  2100           pu blic stati c SortedSe t<Patient>  translate ToSet(Fede rationPati entType []  patients)
  2101           {
  2102                    Sort edSet<Pati ent> resul t = new Tr eeSet<Pati ent>();
  2103                    for( Federation PatientTyp e patient  : patients )
  2104                    {
  2105                             result .add(trans late(patie nt));
  2106                    }
  2107                    retu rn result;
  2108           }
  2109           
  2110           pu blic stati c Federati onPatientT ype transl ate(Patien t patient)
  2111           {
  2112                    retu rn new Fed erationPat ientType(
  2113                                      patient. getPatient Name(),
  2114                                      patient. getPatient Icn(),
  2115                                      patient. getVeteran Status(),
  2116                                      translat e(patient. getPatient Sex()),
  2117                                      patient. getDob(),
  2118                                      patient. getSsn(),
  2119                                      patient. getSensiti ve()
  2120                             );
  2121           }
  2122           
  2123           pu blic stati c Patient  translate( Federation PatientTyp e patient)
  2124           {
  2125                    retu rn new Pat ient(
  2126                                      patient. getPatient Name(),
  2127                                      patient. getPatient Icn(),
  2128                                      patient. getVeteran Status(),
  2129                                      translat e(patient. getPatient Sex()),
  2130                                      patient. getDob(), 
  2131                                      patient. getSsn(),
  2132                                      null,
  2133                                      patient. getSensiti ve()
  2134                             );
  2135           }
  2136           
  2137           pu blic stati c Federati onPatientS exType tra nslate(Pat ientSex pa tientSex)
  2138           {
  2139                    for( Entry<Pati entSex, Fe derationPa tientSexTy pe> entry  : Federati onRestTran slator.pat ientSexMap .entrySet( ))
  2140                    {
  2141                             if(ent ry.getKey( ) == patie ntSex)
  2142                                      return e ntry.getVa lue();
  2143                    }
  2144  
  2145                    retu rn Federat ionPatient SexType.Un known;
  2146           }
  2147           
  2148           pu blic stati c PatientS ex transla te(Federat ionPatient SexType pa tientSex)
  2149           {
  2150                    for( Entry<Pati entSex, Fe derationPa tientSexTy pe> entry  : Federati onRestTran slator.pat ientSexMap .entrySet( ))
  2151                    {
  2152                             if(ent ry.getValu e() == pat ientSex)
  2153                                      return e ntry.getKe y();
  2154                    }
  2155                    retu rn Patient Sex.Unknow n;
  2156           }
  2157           
  2158           pu blic stati c StudyDel etedImageS tate trans late(Feder ationStudy DeletedIma geStateTyp e studyDel etedImageS tate)
  2159           {
  2160                    for( Entry<Stud yDeletedIm ageState,  Federation StudyDelet edImageSta teType> en try : Fede rationRest Translator .studyDele tedImageSt ateMap.ent rySet())
  2161                    {
  2162                             if(ent ry.getValu e() == stu dyDeletedI mageState)
  2163                                      return e ntry.getKe y();                            
  2164                    }
  2165                    retu rn StudyDe letedImage State.cann otIncludeD eletedImag es;
  2166           }
  2167           
  2168           pu blic stati c Federati onStudyDel etedImageS tateType t ranslate(S tudyDelete dImageStat e studyDel etedImageS tate)
  2169           {
  2170                    for( Entry<Stud yDeletedIm ageState,  Federation StudyDelet edImageSta teType> en try : Fede rationRest Translator .studyDele tedImageSt ateMap.ent rySet())
  2171                    {
  2172                             if(ent ry.getKey( ) == study DeletedIma geState)
  2173                                      return e ntry.getVa lue();                                   
  2174                    }
  2175                    retu rn Federat ionStudyDe letedImage StateType. cannotIncl udeDeleted Images;
  2176           }
  2177           
  2178           pu blic stati c Artifact ResultStat us transla te(Federat ionArtifac tResultSta tusType ar tifactResu ltStatus)
  2179           {
  2180                    for( Entry<Arti factResult Status, Fe derationAr tifactResu ltStatusTy pe> entry  : Federati onRestTran slator.art ifactResul tStatusMap .entrySet( ))
  2181                    {
  2182                             if(ent ry.getValu e() == art ifactResul tStatus)
  2183                                      return e ntry.getKe y();
  2184                    }
  2185                    retu rn Artifac tResultSta tus.fullRe sult;
  2186           }
  2187           
  2188           pu blic stati c Federati onArtifact ResultStat usType tra nslate(Art ifactResul tStatus ar tifactResu ltStatus)
  2189           {
  2190                    for( Entry<Arti factResult Status, Fe derationAr tifactResu ltStatusTy pe> entry  : Federati onRestTran slator.art ifactResul tStatusMap .entrySet( ))
  2191                    {
  2192                             if(ent ry.getKey( ) == artif actResultS tatus)
  2193                                      return e ntry.getVa lue();
  2194                    }
  2195                    retu rn Federat ionArtifac tResultSta tusType.fu llResult;
  2196           }
  2197           
  2198           pu blic stati c Federati onImageFor matQualiti esType tra nslate(Ima geFormatQu alityList  imageForma tQualityLi st)
  2199           {
  2200                    if(i mageFormat QualityLis t == null)
  2201                             return  null;
  2202                    Fede rationImag eFormatQua litiesType  result =  new Federa tionImageF ormatQuali tiesType() ;
  2203                    List <Federatio nImageForm atQualityT ype> quali ties = new  ArrayList <Federatio nImageForm atQualityT ype>();
  2204                    for( ImageForma tQuality i mageFormat Quality :  imageForma tQualityLi st)
  2205                    {
  2206                             Federa tionImageF ormatQuali tyType qua lityType =  translate (imageForm atQuality) ;
  2207                             if(qua lityType ! = null)
  2208                                      qualitie s.add(qual ityType);
  2209                    }
  2210                    resu lt.setImag eFormatQua lities(qua lities.toA rray(new F ederationI mageFormat QualityTyp e[qualitie s.size()]) );
  2211                    retu rn result;
  2212           }
  2213           
  2214           pr ivate stat ic Federat ionImageFo rmatQualit yType tran slate(Imag eFormatQua lity image FormatQual ity)
  2215           {
  2216                    if(i mageFormat Quality ==  null)
  2217                             return  null;
  2218                    Fede rationImag eFormatQua lityType r esult = ne w Federati onImageFor matQuality Type();
  2219                    resu lt.setImag eFormat(im ageFormatQ uality.get ImageForma t().name() );
  2220                    resu lt.setImag eQuality(i mageFormat Quality.ge tImageQual ity().getC anonical() );
  2221                    retu rn result;
  2222           }
  2223           
  2224           pu blic stati c ImageFor matQuality List trans late(Feder ationImage FormatQual itiesType  imageForma tQualities Type)
  2225           {
  2226                    if(i mageFormat QualitiesT ype == nul l)
  2227                             return  null;
  2228                    Imag eFormatQua lityList r esult = ne w ImageFor matQuality List();
  2229                    if(i mageFormat QualitiesT ype.getIma geFormatQu alities()  != null)
  2230                    {
  2231                             for(Fe derationIm ageFormatQ ualityType  imageForm atQualityT ype : imag eFormatQua litiesType .getImageF ormatQuali ties())
  2232                             {
  2233                                      ImageFor matQuality  imageForm atQuality  = translat e(imageFor matQuality Type);
  2234                                      if(image FormatQual ity != nul l)
  2235                                               result.add (imageForm atQuality) ;
  2236                             }
  2237                    }
  2238                    
  2239                    retu rn result;
  2240           }
  2241           
  2242           pr ivate stat ic ImageFo rmatQualit y translat e(Federati onImageFor matQuality Type image FormatQual ityType)
  2243           {
  2244                    if(i mageFormat QualityTyp e == null)
  2245                             return  null;
  2246                    Imag eFormat im ageFormat  = ImageFor mat.valueO f(imageFor matQuality Type.getIm ageFormat( ));
  2247                    
  2248                    Imag eQuality i mageQualit y = ImageQ uality.get ImageQuali ty(imageFo rmatQualit yType.getI mageQualit y());
  2249                    if(( imageForma t == null)  || (image Quality ==  null))
  2250                             return  null;
  2251                    
  2252                    retu rn new Ima geFormatQu ality(imag eFormat, i mageQualit y);
  2253           }
  2254           
  2255           pu blic stati c List<Ima geAnnotati on> transl ate(Federa tionImageA nnotationT ype [] ima geAnnotati ons)
  2256           th rows URNFo rmatExcept ion
  2257           {
  2258                    if(i mageAnnota tions == n ull)
  2259                             return  null;
  2260                    List <ImageAnno tation> re sult = new  ArrayList <ImageAnno tation>();
  2261                    
  2262                    for( Federation ImageAnnot ationType  imageAnnot ation : im ageAnnotat ions)
  2263                    {
  2264                             result .add(trans late(image Annotation ));
  2265                    }
  2266                    
  2267                    retu rn result;
  2268           }
  2269           
  2270           pu blic stati c ImageAnn otation tr anslate(Fe derationIm ageAnnotat ionType im ageAnnotat ion)
  2271           th rows URNFo rmatExcept ion
  2272           {
  2273                    Abst ractImagin gURN imagi ngUrn = 
  2274                             URNFac tory.creat e(imageAnn otation.ge tImagingUr n(), Abstr actImaging URN.class) ;
  2275                    Imag eAnnotatio nURN image Annotation Urn = URNF actory.cre ate(imageA nnotation. getImageAn notationUr n(), Image Annotation URN.class) ;
  2276                    Imag eAnnotatio nSource im ageAnnotat ionSource  = translat e(imageAnn otation.ge tAnnotatio nSource()) ;
  2277                    Imag eAnnotatio nUser imag eAnnotatio nUser = tr anslate(im ageAnnotat ion.getAnn otationSav edByUser() );
  2278                    Imag eAnnotatio n result =  new Image Annotation (imagingUr n, imageAn notationUr n, 
  2279                                      imageAnn otationUse r, imageAn notation.g etAnnotati onSavedDat e(),
  2280                                      imageAnn otationSou rce, image Annotation .isSavedAf terResult( ), 
  2281                                      imageAnn otation.ge tAnnotatio nVersion()
  2282                                      imageAnn otation.is Annotation Deleted()) ;
  2283                    retu rn result;
  2284           }
  2285           
  2286           pr ivate stat ic ImageAn notationUs er transla te(Federat ionImageAn notationUs erType ima geAnnotati onUser)
  2287           {
  2288                    retu rn new Ima geAnnotati onUser(ima geAnnotati onUser.get UserId(),  imageAnnot ationUser. getName(),  imageAnno tationUser .getServic e());
  2289           }
  2290           
  2291           pu blic stati c ImageAnn otationSou rce transl ate(Federa tionImageA nnotationS ourceType  imageAnnot ationSourc e)
  2292           {
  2293                    for( Entry<Imag eAnnotatio nSource, F ederationI mageAnnota tionSource Type> entr y : Federa tionRestTr anslator.i mageAnnota tionSource Map.entryS et())
  2294                    {
  2295                             if(ent ry.getValu e() == ima geAnnotati onSource)
  2296                             {
  2297                                      return e ntry.getKe y();
  2298                             }
  2299                    }
  2300                    retu rn ImageAn notationSo urce.clini calDisplay ;
  2301           }
  2302           
  2303           pu blic stati c Federati onImageAnn otationSou rceType tr anslate(Im ageAnnotat ionSource  imageAnnot ationSourc e)
  2304           {
  2305                    for( Entry<Imag eAnnotatio nSource, F ederationI mageAnnota tionSource Type> entr y : Federa tionRestTr anslator.i mageAnnota tionSource Map.entryS et())
  2306                    {
  2307                             if(ent ry.getKey( ) == image Annotation Source)
  2308                             {
  2309                                      return e ntry.getVa lue();
  2310                             }
  2311                    }
  2312                    retu rn Federat ionImageAn notationSo urceType.c linicalDis play;
  2313           }
  2314           
  2315           pu blic stati c ImageAnn otationDet ails trans late(Feder ationImage Annotation DetailsTyp e imageAnn otationDet ails)
  2316           th rows URNFo rmatExcept ion
  2317           {
  2318                    if(i mageAnnota tionDetail s == null)
  2319                             return  null;
  2320                    Imag eAnnotatio n imageAnn otation =  translate( imageAnnot ationDetai ls.getImag eAnnotatio n());
  2321                    retu rn new Ima geAnnotati onDetails( imageAnnot ation, ima geAnnotati onDetails. getAnnotat ionXml());
  2322           }
  2323           
  2324           pu blic stati c Federati onImageAnn otationTyp e[] transl ate(List<I mageAnnota tion> imag eAnnotatio ns)
  2325           {
  2326                    if(i mageAnnota tions == n ull)
  2327                             return  null;
  2328                    Fede rationImag eAnnotatio nType [] r esult = 
  2329                             new Fe derationIm ageAnnotat ionType[im ageAnnotat ions.size( )];
  2330                    
  2331                    for( int i = 0;  i < image Annotation s.size();  i++)
  2332                    {
  2333                             result [i] = tran slate(imag eAnnotatio ns.get(i)) ;
  2334                    }
  2335                    
  2336                    retu rn result;
  2337           }
  2338           
  2339           pu blic stati c Federati onImageAnn otationTyp e translat e(ImageAnn otation im ageAnnotat ion)
  2340           {
  2341                    Fede rationImag eAnnotatio nType resu lt = 
  2342                             new Fe derationIm ageAnnotat ionType();
  2343                    
  2344                    resu lt.setAnno tationSave dByUser(tr anslate(im ageAnnotat ion.getAnn otationSav edByUser() ));
  2345                    resu lt.setAnno tationSave dDate(imag eAnnotatio n.getAnnot ationSaved Date());
  2346                    resu lt.setAnno tationSour ce(transla te(imageAn notation.g etAnnotati onSource() ));
  2347                    resu lt.setAnno tationVers ion(imageA nnotation. getAnnotat ionVersion ());
  2348                    resu lt.setImag eAnnotatio nUrn(image Annotation .getAnnota tionUrn(). toString() );
  2349                    resu lt.setImag ingUrn(ima geAnnotati on.getImag ingUrn().t oString()) ;
  2350                    resu lt.setSave dAfterResu lt(imageAn notation.i sSavedAfte rResult()) ;
  2351                    resu lt.setAnno tationDele ted(imageA nnotation. isAnnotati onDeleted( ));
  2352                    
  2353                    retu rn result;
  2354           }
  2355           
  2356           pr ivate stat ic Federat ionImageAn notationUs erType tra nslate(Ima geAnnotati onUser ima geAnnotati onUser)
  2357           {
  2358                    Fede rationImag eAnnotatio nUserType  result = 
  2359                             new Fe derationIm ageAnnotat ionUserTyp e();
  2360                    
  2361                    resu lt.setName (imageAnno tationUser .getName() );
  2362                    resu lt.setServ ice(imageA nnotationU ser.getSer vice());
  2363                    resu lt.setUser Id(imageAn notationUs er.getUser Id());
  2364                    
  2365                    retu rn result;
  2366           }
  2367           
  2368           pu blic stati c Federati onImageAnn otationDet ailsType t ranslate(I mageAnnota tionDetail s imageAnn otationDet ails)
  2369           {
  2370                    if(i mageAnnota tionDetail s == null)
  2371                             return  null;
  2372                    Fede rationImag eAnnotatio nDetailsTy pe result 
  2373                             new Fe derationIm ageAnnotat ionDetails Type();
  2374                    
  2375                    resu lt.setAnno tationXml( imageAnnot ationDetai ls.getAnno tationXml( ));
  2376                    resu lt.setImag eAnnotatio n(translat e(imageAnn otationDet ails.getIm ageAnnotat ion()));
  2377                    
  2378                    retu rn result;
  2379           }
  2380           
  2381           pu blic stati c List<Str ing> trans late(Feder ationStrin gArrayType  values)
  2382           {
  2383                    if(v alues == n ull)
  2384                             return  null;
  2385                    // J ersey seem s to conve rt empty s tring arra ys into nu ll respons es
  2386                    // w hen reques ting treat ing sites  for a pati ent, the r esult is e xpected to  be an emp ty array i f no sites  for the p atient
  2387                    if(v alues.getV alues() ==  null)
  2388                             return  new Array List<Strin g>(0);
  2389                    List <String> r esult = ne w ArrayLis t<String>( values.get Values().l ength);
  2390                    for( String val ue : value s.getValue s())
  2391                    {
  2392                             result .add(value );
  2393                    }
  2394                    retu rn result;           
  2395           }        
  2396           
  2397           pu blic stati c List<Div ision> tra nslate(Fed erationDiv isionType  [] divisio ns)
  2398           {
  2399                    if(d ivisions = = null)
  2400                             return  null;
  2401                    List <Division>  result =  new ArrayL ist<Divisi on>();
  2402                    
  2403                    for( Federation DivisionTy pe divisio n : divisi ons)
  2404                    {
  2405                             result .add(new D ivision(di vision.get DivisionIe n(), divis ion.getDiv isionName( ), divisio n.getDivis ionCode()) );
  2406                    }
  2407                    
  2408                    retu rn result;
  2409           }
  2410           
  2411           pu blic stati c Federati onDivision Type [] tr anslateDiv isionList( List<Divis ion> divis ions)
  2412           {
  2413                    if(d ivisions = = null)
  2414                             return  null;
  2415                    Fede rationDivi sionType [ ] result =  new Feder ationDivis ionType[di visions.si ze()];
  2416                    for( int i = 0;  i < divis ions.size( ); i++)
  2417                    {
  2418                             result [i] = tran slate(divi sions.get( i));
  2419                    }
  2420                    
  2421                    retu rn result;
  2422           }
  2423           
  2424           pr ivate stat ic Federat ionDivisio nType tran slate(Divi sion divis ion)
  2425           {
  2426                    Fede rationDivi sionType r esult = ne w Federati onDivision Type();
  2427                    
  2428                    resu lt.setDivi sionCode(d ivision.ge tDivisionC ode());
  2429                    resu lt.setDivi sionIen(di vision.get DivisionIe n());
  2430                    resu lt.setDivi sionName(d ivision.ge tDivisionN ame());
  2431                    
  2432                    retu rn result;
  2433           }
  2434           
  2435           pu blic stati c UserInfo rmation tr anslate(Fe derationUs erInformat ionType us erInformat ion)
  2436           {
  2437                    if(u serInforma tion == nu ll)
  2438                             return  null;
  2439                    
  2440                    List <String> k eys = tran slate(user Informatio n.getKeys( ));
  2441                    User  user = tr anslate(us erInformat ion.getUse r());
  2442                    retu rn new Use rInformati on(user, k eys, userI nformation .isCanUser Annotate() );
  2443           }
  2444           
  2445           pr ivate stat ic User tr anslate(Fe derationUs erType use r)
  2446           {
  2447                    if(u ser == nul l)
  2448                             return  null;
  2449                    retu rn new Fed erationUse r(user.get UserId(),  user.getNa me(), user .getTitle( ), user.ge tService() );
  2450           }
  2451           
  2452           pu blic stati c Federati onUserInfo rmationTyp e translat e(UserInfo rmation us erInformat ion)
  2453           {
  2454                    if(u serInforma tion == nu ll)
  2455                             return  null;
  2456                    
  2457                    Fede rationUser Informatio nType resu lt = new F ederationU serInforma tionType() ;
  2458                    resu lt.setKeys (translate StringList (userInfor mation.get Keys()));
  2459                    resu lt.setUser (translate (userInfor mation.get User()));
  2460                    resu lt.setCanU serAnnotat e(userInfo rmation.is UserCanAnn otate());
  2461                    
  2462                    retu rn result;
  2463           }
  2464           
  2465           pr ivate stat ic Federat ionUserTyp e translat e(User use r)
  2466           {
  2467                    if(u ser == nul l)
  2468                             return  null;
  2469                    Fede rationUser Type resul t = new Fe derationUs erType();
  2470                    resu lt.setName (user.getN ame());
  2471                    resu lt.setServ ice(user.g etService( ));
  2472                    resu lt.setTitl e(user.get Title());
  2473                    resu lt.setUser Id(user.ge tUserId()) ;
  2474                    retu rn result;
  2475           }
  2476           
  2477           pu blic stati c Federati onPatientM eansTestRe sultType t ranslate(P atientMean sTestResul t patientM eansTestRe sult)
  2478           {
  2479                    if(p atientMean sTestResul t == null)
  2480                             return  null;
  2481                    retu rn new Fed erationPat ientMeansT estResultT ype(patien tMeansTest Result.get Code(), 
  2482                                      patientM eansTestRe sult.getMe ssage());
  2483           }
  2484           
  2485           pu blic stati c PatientM eansTestRe sult trans late(Feder ationPatie ntMeansTes tResultTyp e patientM eansTestRe sult)
  2486           {
  2487                    if(p atientMean sTestResul t == null)
  2488                             return  null;
  2489                    retu rn new Pat ientMeansT estResult( patientMea nsTestResu lt.getCode (), 
  2490                                      patientM eansTestRe sult.getMe ssage());
  2491           }
  2492           
  2493           pu blic stati c Electron icSignatur eResult tr anslate(Fe derationEl ectronicSi gnatureRes ultType el ectronicSi gnature)
  2494           {
  2495                    if(e lectronicS ignature = = null)
  2496                             return  null;
  2497                    retu rn new Ele ctronicSig natureResu lt(electro nicSignatu re.isSucce ss(), 
  2498                                      electron icSignatur e.getMessa ge());
  2499           }
  2500           
  2501           pu blic stati c Federati onElectron icSignatur eResultTyp e translat e(Electron icSignatur eResult el ectronicSi gnature)
  2502           {
  2503                    if(e lectronicS ignature = = null)
  2504                             return  null;
  2505                    retu rn new Fed erationEle ctronicSig natureResu ltType(ele ctronicSig nature.isS uccess(), 
  2506                                      electron icSignatur e.getMessa ge());
  2507           }
  2508           
  2509           pu blic stati c Federati onImageAcc essReasonT ypeHolderT ype transl ateReasonT ypesToHold er(List<Im ageAccessR easonType>  reasonTyp es)
  2510           {
  2511                    if(r easonTypes  == null)
  2512                             return  new Feder ationImage AccessReas onTypeHold erType();
  2513                    retu rn new Fed erationIma geAccessRe asonTypeHo lderType(t ranslateRe asonTypes( reasonType s));
  2514           }
  2515           
  2516           pr ivate stat ic Federat ionImageAc cessReason TypeType[]  translate ReasonType s(List<Ima geAccessRe asonType>  reasonType s)
  2517           {
  2518                    if(r easonTypes  == null)
  2519                             return  null;
  2520                    
  2521                    Fede rationImag eAccessRea sonTypeTyp e [] resul t = new Fe derationIm ageAccessR easonTypeT ype [reaso nTypes.siz e()];
  2522                    for( int i = 0;  i < reaso nTypes.siz e(); i++)
  2523                    {
  2524                             result [i] = tran slate(reas onTypes.ge t(i));
  2525                    }                 
  2526                    retu rn result;
  2527           }
  2528           
  2529           pu blic stati c List<Ima geAccessRe asonType>  translate( Federation ImageAcces sReasonTyp eHolderTyp e reasonTy pesHolder)
  2530           {
  2531                    List <ImageAcce ssReasonTy pe> result  = new Arr ayList<Ima geAccessRe asonType>( );
  2532                    if(r easonTypes Holder !=  null)
  2533                    {                         
  2534                             result .addAll(tr anslate(re asonTypesH older.getR easons())) ;
  2535                    }
  2536                    
  2537                    retu rn result;
  2538           }
  2539           
  2540           pr ivate stat ic List<Im ageAccessR easonType>  translate (Federatio nImageAcce ssReasonTy peType []  reasonType s)
  2541           {
  2542                    if(r easonTypes  == null)
  2543                             return  null;
  2544                    List <ImageAcce ssReasonTy pe> result  = new Arr ayList<Ima geAccessRe asonType>( );
  2545                    for( Federation ImageAcces sReasonTyp eType reas onType : r easonTypes )
  2546                    {
  2547                             result .add(trans late(reaso nType));
  2548                    }
  2549                    
  2550                    retu rn result;
  2551           }
  2552           
  2553           pr ivate stat ic Federat ionImageAc cessReason TypeType t ranslate(I mageAccess ReasonType  reasonTyp e)
  2554           {
  2555                    for( Entry<Imag eAccessRea sonType, F ederationI mageAccess ReasonType Type> entr y : imageA ccessReaso nTypesMap. entrySet() )
  2556                    {
  2557                             if(ent ry.getKey( ) == reaso nType)
  2558                                      return e ntry.getVa lue();                          
  2559                    }
  2560                    retu rn null;
  2561           }
  2562           
  2563           pr ivate stat ic ImageAc cessReason Type trans late(Feder ationImage AccessReas onTypeType  reasonTyp e)
  2564           {
  2565                    for( Entry<Imag eAccessRea sonType, F ederationI mageAccess ReasonType Type> entr y : imageA ccessReaso nTypesMap. entrySet() )
  2566                    {
  2567                             if(ent ry.getValu e() == rea sonType)
  2568                                      return e ntry.getKe y();                    
  2569                    }
  2570                    retu rn null;
  2571           }
  2572           
  2573           pu blic stati c List<Ima geAccessRe ason> tran slate( Fed erationIma geAccessRe asonType [ ] reasons)
  2574           th rows Routi ngTokenFor matExcepti on
  2575           {
  2576                    if(r easons ==  null)
  2577                             return  null;
  2578                    List <ImageAcce ssReason>  result = n ew ArrayLi st<ImageAc cessReason >();
  2579                    for( Federation ImageAcces sReasonTyp e reason :  reasons)
  2580                    {
  2581                             result .add(trans late(reaso n));
  2582                    }
  2583                    
  2584                    retu rn result;
  2585           }
  2586           
  2587           pu blic stati c Federati onImageAcc essReasonT ype [] tra nslateImag eAccessRea sons(List< ImageAcces sReason> r easons)
  2588           {
  2589                    if(r easons ==  null)
  2590                             return  null;
  2591                    Fede rationImag eAccessRea sonType []  result =  new Federa tionImageA ccessReaso nType [rea sons.size( )];
  2592                    for( int i = 0;  i < reaso ns.size();  i++)
  2593                    {
  2594                             result [i] = tran slate(reas ons.get(i) );
  2595                    }
  2596                    retu rn result;
  2597           }
  2598           
  2599           pr ivate stat ic Federat ionImageAc cessReason Type trans late(Image AccessReas on reason)
  2600           {
  2601                    retu rn new Fed erationIma geAccessRe asonType(r eason.getR outingToke n().toRout ingTokenSt ring(), 
  2602                                      reason.g etReasonCo de(), reas on.getDesc ription(),  translate ReasonType s(reason.g etReasonTy pes()), 
  2603                                      reason.g etGlobalRe asonCode() );
  2604           }
  2605           
  2606           pr ivate stat ic ImageAc cessReason  translate (Federatio nImageAcce ssReasonTy pe reason)  
  2607           th rows Routi ngTokenFor matExcepti on
  2608           {
  2609                    retu rn new Ima geAccessRe ason(trans lateRoutin gToken(rea son.getRou tingTokenS tring()),
  2610                                      reason.g etReasonCo de(), reas on.getDesc ription(),  translate (reason.ge tReasonTyp es()), 
  2611                                      reason.g etGlobalRe asonCode() );
  2612           }
  2613           
  2614           pu blic stati c Federati onImagingL ogEventTyp e translat e(ImagingL ogEvent im agingLogEv ent)
  2615           {
  2616                    retu rn new Fed erationIma gingLogEve ntType(ima gingLogEve nt.getRout ingTokenTo LogTo().to RoutingTok enString() ,
  2617                                      imagingL ogEvent.ge tImagingUr n() == nul l ? null :  imagingLo gEvent.get ImagingUrn ().toStrin gCDTP(),
  2618                                      imagingL ogEvent.ge tPatientIc n(), imagi ngLogEvent .getAccess Type(), im agingLogEv ent.getUse rInterface (), 
  2619                                      imagingL ogEvent.ge tImageCoun t(), imagi ngLogEvent .getAdditi onalData() );
  2620           }
  2621           
  2622           pu blic stati c ImagingL ogEvent tr anslate(Fe derationIm agingLogEv entType im agingLogEv ent)
  2623           th rows Trans lationExce ption
  2624           {
  2625                    try
  2626                    {
  2627                             Routin gToken rou tingToken 
  2628                                      translat eRoutingTo ken(imagin gLogEvent. getRouting TokenToLog ToString() );
  2629                             Abstra ctImagingU RN imaging Urn = null ;
  2630                             String  imagingUr nString =  imagingLog Event.getI magingUrnS tring();
  2631                             if(ima gingUrnStr ing != nul l && imagi ngUrnStrin g.length()  > 0)
  2632                             {
  2633                                      imagingU rn = 
  2634                                               URNFactory .create(im agingUrnSt ring, SERI ALIZATION_ FORMAT.CDT P, Abstrac tImagingUR N.class);
  2635                                      
  2636                             }
  2637                             return  new Imagi ngLogEvent (routingTo ken, imagi ngUrn, ima gingLogEve nt.getPati entIcn(), 
  2638                                               imagingLog Event.getA ccessType( ), imaging LogEvent.g etUserInte rface(), 
  2639                                               imagingLog Event.getI mageCount( ), imaging LogEvent.g etAddition alData());
  2640                             
  2641                    } 
  2642                    catc h (Routing TokenForma tException  rtfX)
  2643                    {
  2644                             throw  new Transl ationExcep tion(rtfX) ;
  2645                    }
  2646                    catc h(URNForma tException  urnfX)
  2647                    {
  2648                             throw  new Transl ationExcep tion(urnfX );
  2649                    }
  2650           }
  2651           
  2652           pu blic stati c Federati onHealthSu mmaryType  [] transla teHealthSu mmaries(Li st<HealthS ummaryType > healthSu mmaries)
  2653           {
  2654                    if(h ealthSumma ries == nu ll)
  2655                             return  null;
  2656                    Fede rationHeal thSummaryT ype [] res ult = new  Federation HealthSumm aryType[he althSummar ies.size() ];
  2657                    for( int i = 0;  i < healt hSummaries .size(); i ++)
  2658                    {
  2659                             result [i] = tran slate(heal thSummarie s.get(i));
  2660                    }
  2661                    retu rn result;
  2662           }
  2663           
  2664           pr ivate stat ic Federat ionHealthS ummaryType  translate (HealthSum maryType h ealthSumma ry)
  2665           {
  2666                    retu rn new Fed erationHea lthSummary Type(healt hSummary.g etHealthSu mmaryUrn() .toString( ), healthS ummary.get Name());
  2667           }
  2668           
  2669           pu blic stati c List<Hea lthSummary Type> tran slate(Fede rationHeal thSummaryT ype [] hea lthSummari es)
  2670           th rows Metho dException
  2671           {
  2672                    if(h ealthSumma ries == nu ll)
  2673                             return  null;
  2674                    
  2675                    List <HealthSum maryType>  result = n ew ArrayLi st<HealthS ummaryType >();
  2676                    for( Federation HealthSumm aryType he althSummar y : health Summaries)
  2677                    {
  2678                             result .add(trans late(healt hSummary)) ;
  2679                    }
  2680                    retu rn result;
  2681           }
  2682           
  2683           pr ivate stat ic HealthS ummaryType  translate (Federatio nHealthSum maryType h ealthSumma ry)
  2684           th rows Metho dException
  2685           {
  2686                    try
  2687                    {
  2688                             Health SummaryURN  healthSum maryUrn =  URNFactory .create(he althSummar y.getHealt hSummaryId (), Health SummaryURN .class);
  2689                             return  new Healt hSummaryTy pe(healthS ummaryUrn,  healthSum mary.getNa me());
  2690                    }
  2691                    catc h(URNForma tException  urnfX)
  2692                    {
  2693                             throw  new Method Exception( urnfX);
  2694                    }
  2695           }
  2696   }