Produced by Araxis Merge on 6/9/2017 3:51:26 PM Eastern 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.
| # | Location | File | Last Modified |
|---|---|---|---|
| 1 | Fri Jun 9 19:51:26 2017 UTC | ||
| 2 | eHealth_Exch (eHealth Exchange Enhancements) Build 3 docs & code_May_2017.zip\VAP_CIF_CODE0502.zip\VAP_CIF_CODE0502\VAP_CIF_CODE0502\nvap-web\src\main\java\gov\va\nvap\web\helper\privacy | ConsentManagementHelper.java | Fri Apr 21 20:03:30 2017 UTC |
| Description | Between Files 1 and 2 |
|
|---|---|---|
| Text Blocks | Lines | |
| Unchanged | 0 | 0 |
| Changed | 0 | 0 |
| Inserted | 1 | 976 |
| Removed | 0 | 0 |
| 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 |
No regular expressions were active.
| 1 | package go v.va.nvap. web.helper .privacy; | |||||
| 2 | ||||||
| 3 | import gov .va.nvap.c ommon.date .hl7.HL7Da teUtil; | |||||
| 4 | import gov .va.nvap.c ommon.jaxb .JaxbUtil; | |||||
| 5 | import gov .va.nvap.c ommon.tran sformer.Tr ansformer; | |||||
| 6 | import gov .va.nvap.c ommon.tran sformer.Tr ansformerE xception; | |||||
| 7 | import gov .va.nvap.c ommon.tran sformer.xm l.StringTo XML; | |||||
| 8 | import gov .va.nvap.c ommon.tran sformer.xm l.XMLToStr ing; | |||||
| 9 | import gov .va.nvap.c ommon.tran sformer.xs l.XSLTrans former; | |||||
| 10 | import gov .va.nvap.c ommon.uuid .UUIDUtil; | |||||
| 11 | import gov .va.nvap.c ommon.vali dation.Ass ert; | |||||
| 12 | import gov .va.nvap.c ommon.vali dation.Nul lChecker; | |||||
| 13 | import gov .va.nvap.p rivacy.Con sentDirect iveAuthori zationRequ est; | |||||
| 14 | import gov .va.nvap.p rivacy.Con sentDirect iveAuthori zationResp onse; | |||||
| 15 | import gov .va.nvap.p rivacy.Con sentDirect iveDetaile dExpiratio nRequest; | |||||
| 16 | import gov .va.nvap.p rivacy.Con sentDirect iveDetaile dExpiratio nResponse; | |||||
| 17 | import gov .va.nvap.p rivacy.Con sentDirect iveDocumen tRetrieveR equest; | |||||
| 18 | import gov .va.nvap.p rivacy.Con sentDirect iveDocumen tRetrieveR esponse; | |||||
| 19 | import gov .va.nvap.p rivacy.Con sentDirect iveDocumen tType; | |||||
| 20 | import gov .va.nvap.p rivacy.Con sentDirect iveOptOutR easonType; | |||||
| 21 | import gov .va.nvap.p rivacy.Con sentDirect iveQueryPa ramType; | |||||
| 22 | import gov .va.nvap.p rivacy.Con sentDirect iveQueryRe quest; | |||||
| 23 | import gov .va.nvap.p rivacy.Con sentDirect iveQueryRe sponse; | |||||
| 24 | import gov .va.nvap.p rivacy.Con sentDirect iveReferen ceType; | |||||
| 25 | import gov .va.nvap.p rivacy.Con sentDirect iveRevocat ionRequest ; | |||||
| 26 | import gov .va.nvap.p rivacy.Con sentDirect iveUpdateR equest; | |||||
| 27 | import gov .va.nvap.p rivacy.Con sentDirect iveUpdateR esponse; | |||||
| 28 | import gov .va.nvap.p rivacy.Con sentType; | |||||
| 29 | import gov .va.nvap.p rivacy.Exp iringConse ntConfigur ationReque st; | |||||
| 30 | import gov .va.nvap.p rivacy.Exp iringConse ntConfigur ationRespo nse; | |||||
| 31 | import gov .va.nvap.p rivacy.Exp iringConse ntLetterRe sponse; | |||||
| 32 | import gov .va.nvap.p rivacy.Org anizationT ype; | |||||
| 33 | import gov .va.nvap.p rivacy.Org anizations QueryReque st; | |||||
| 34 | import gov .va.nvap.p rivacy.Org anizations QueryRespo nse; | |||||
| 35 | import gov .va.nvap.p rivacy.Pur poseOfUseT ype; | |||||
| 36 | import gov .va.nvap.p rivacy.Ser viceConsum er; | |||||
| 37 | import gov .va.nvap.p rivacy.Ser viceConsum erContextT ype; | |||||
| 38 | import gov .va.nvap.p rivacy.dat a.ConsentD irectiveDa ta; | |||||
| 39 | import gov .va.nvap.p rivacy.dat a.Particip ant; | |||||
| 40 | import gov .va.nvap.p rivacy.dat a.ScannedC onsentDire ctiveDocum entBase64T ext; | |||||
| 41 | import gov .va.nvap.s ervice.pdq .PatientDe mographics ; | |||||
| 42 | import gov .va.nvap.s ervice.pri vacy.Conse ntManageme ntService; | |||||
| 43 | import gov .va.nvap.s ervice.pri vacy.Conse ntManageme ntServiceE xception; | |||||
| 44 | import gov .va.nvap.s ervice.pri vacy.Expir ingConsent Service; | |||||
| 45 | import jav a.io.ByteA rrayInputS tream; | |||||
| 46 | import jav a.io.IOExc eption; | |||||
| 47 | import jav a.text.Par seExceptio n; | |||||
| 48 | import jav a.util.Arr ayList; | |||||
| 49 | import jav a.util.Cal endar; | |||||
| 50 | import jav a.util.Col lection; | |||||
| 51 | import jav a.util.Dat e; | |||||
| 52 | import jav a.util.Has hMap; | |||||
| 53 | import jav a.util.Lis t; | |||||
| 54 | import jav a.util.Map ; | |||||
| 55 | import jav ax.xml.bin d.JAXBExce ption; | |||||
| 56 | import jav ax.xml.tra nsform.dom .DOMResult ; | |||||
| 57 | import jav ax.xml.tra nsform.dom .DOMSource ; | |||||
| 58 | import org .apache.co mmons.file upload.Fil eItem; | |||||
| 59 | import org .apache.xe rces.impl. dv.util.Ba se64; | |||||
| 60 | import org .springfra mework.bea ns.factory .Initializ ingBean; | |||||
| 61 | import org .springfra mework.bea ns.factory .annotatio n.Required ; | |||||
| 62 | import org .w3c.dom.D ocument; | |||||
| 63 | ||||||
| 64 | /** | |||||
| 65 | * Helper class to d eal with c onsent man agement. | |||||
| 66 | * | |||||
| 67 | * @author Asha Amri traj | |||||
| 68 | * @author Zack Pete rson | |||||
| 69 | */ | |||||
| 70 | public cla ss Consent Management Helper imp lements In itializing Bean { | |||||
| 71 | ||||||
| 72 | /** | |||||
| 73 | * Def ault expir ing consen t configur ation valu es | |||||
| 74 | */ | |||||
| 75 | privat e static f inal Strin g DEFAULT_ FREQUENCY = "MONTHLY "; | |||||
| 76 | privat e static f inal Long DEFAULT_WI NDOW = 30L ; | |||||
| 77 | privat e static f inal Strin g DEFAULT_ EMAILS = " "; | |||||
| 78 | ||||||
| 79 | /** | |||||
| 80 | * Con sent Manag ement Serv ice. | |||||
| 81 | */ | |||||
| 82 | privat e ConsentM anagementS ervice cms ; | |||||
| 83 | /** | |||||
| 84 | * Exp iring Cons ent Servic e. | |||||
| 85 | */ | |||||
| 86 | privat e Expiring ConsentSer vice ecs; | |||||
| 87 | /** | |||||
| 88 | * To convert fr om Consent DirectiveD ata to XML for trans formation into the C DA XML. | |||||
| 89 | */ | |||||
| 90 | privat e JaxbUtil dataJaxbH elper; | |||||
| 91 | /** | |||||
| 92 | * Tra nsformer t o transfor m from the value obj ect to CDA R2 XML do cument. | |||||
| 93 | */ | |||||
| 94 | privat e Transfor mer<Docume nt, Docume nt> dataTo ConsentDir ectiveDocu ment; | |||||
| 95 | /** | |||||
| 96 | * VA Organizati on. | |||||
| 97 | */ | |||||
| 98 | privat e Organiza tionType h omeCommuni ty; | |||||
| 99 | /** | |||||
| 100 | * For m Upload A llowed. | |||||
| 101 | */ | |||||
| 102 | privat e boolean isFormUplo adEnabled; | |||||
| 103 | /** | |||||
| 104 | * Org anizationa l Exclusio ns - Enabl ed. | |||||
| 105 | */ | |||||
| 106 | privat e boolean isOrganiza tionExclus ionsAllowe d; | |||||
| 107 | privat e final Li st<String> optOutRea sons = new ArrayList <String>() ; | |||||
| 108 | ||||||
| 109 | /** | |||||
| 110 | * Str ing to XML Transform er. | |||||
| 111 | */ | |||||
| 112 | privat e StringTo XML string ToXml; | |||||
| 113 | ||||||
| 114 | /** | |||||
| 115 | * Sty lesheet to update th e consent directive document. | |||||
| 116 | */ | |||||
| 117 | privat e XSLTrans former upd ateConsent DirectiveD ocumentSty lesheet; | |||||
| 118 | ||||||
| 119 | /** | |||||
| 120 | * XML to String Transform er. | |||||
| 121 | */ | |||||
| 122 | privat e XMLToStr ing xmlToS tring; | |||||
| 123 | ||||||
| 124 | /* | |||||
| 125 | * ConsumerO nlyOID | |||||
| 126 | */ | |||||
| 127 | privat e String c onsumerOnl yOrgOID; | |||||
| 128 | ||||||
| 129 | @Overr ide | |||||
| 130 | public void afte rPropertie sSet() thr ows Except ion { | |||||
| 131 | // Keep the optout rea sons in th e cache, s o you dont have to h it the | |||||
| 132 | // server ev erytime | |||||
| 133 | fo r (final C onsentDire ctiveOptOu tReasonTyp e types : ConsentDir ectiveOptO utReasonTy pe | |||||
| 134 | .values( )) { | |||||
| 135 | this.opt OutReasons .add(types .value()); | |||||
| 136 | } | |||||
| 137 | } | |||||
| 138 | ||||||
| 139 | /** | |||||
| 140 | * Con struct the patient d emographic s data for the CDA R 2 XML. | |||||
| 141 | */ | |||||
| 142 | privat e ConsentD irectiveDa ta constru ctConsentD irectiveDo cumentDemo graphics( | |||||
| 143 | fi nal Consen tDirective Data data, final Str ing icn, | |||||
| 144 | fi nal Patien tDemograph ics demogr aphics, | |||||
| 145 | fi nal List<F ileItem> f ileItems) { | |||||
| 146 | As sert.asser tNotEmpty( data, "Con sentDirect iveData ca nnot be NU LL!"); | |||||
| 147 | ||||||
| 148 | // Set the d emographic s informat ion | |||||
| 149 | da ta.setIcn( icn); | |||||
| 150 | if (NullChec ker.isNotE mpty(demog raphics)) { | |||||
| 151 | data.set PatientRol eCity(demo graphics.g etResidenc eCity()); | |||||
| 152 | data.set PatientRol eState(dem ographics. getResiden ceState()) ; | |||||
| 153 | data.set PatientRol eGivenName (demograph ics.getFir stName()); | |||||
| 154 | data.set PatientRol eFamilyNam e(demograp hics.getLa stName()); | |||||
| 155 | data.set PatientRol eFamilyNam eAlias(dem ographics. getAlias1( )); | |||||
| 156 | data.set PatientRol eMiddleNam e(demograp hics.getMi ddleName() ); | |||||
| 157 | data.set PatientRol eEthnicGro upCodeDisp layText(de mographics | |||||
| 158 | .get EthnicityD escription ()); | |||||
| 159 | data.set PatientRol eSsn(demog raphics.ge tSsn()); | |||||
| 160 | data.set PatientRol eGenderCod e(demograp hics.getGe nder()); | |||||
| 161 | data.set PatientRol eGenderDis playText(d emographic s | |||||
| 162 | .get GenderDesc ription()) ; | |||||
| 163 | data.set PatientRol eMaritalSt atusCode(d emographic s | |||||
| 164 | .get MaritalSta tus()); | |||||
| 165 | data.set PatientRol eMaritalSt atusDispla yText(demo graphics | |||||
| 166 | .get MaritalSta tusDescrip tion()); | |||||
| 167 | data.set PatientRol ePostalCod e(demograp hics.getRe sidenceZip 4()); | |||||
| 168 | data.set PatientRol ePrefix(de mographics .getPrefix ()); | |||||
| 169 | data.set PatientRol eStreetAdd ressLine(d emographic s | |||||
| 170 | .get StreetAddr essLine1() ); | |||||
| 171 | data.set PatientRol eSuffix(de mographics .getSuffix ()); | |||||
| 172 | data.set PatientRol eTelecom(d emographic s.getResid encePhoneN umber()); | |||||
| 173 | data.set PatientRol eProviderO rganizatio nName(demo graphics | |||||
| 174 | .get FacilityNa me()); | |||||
| 175 | data.set PatientRol eProviderO rganizatio nNumber(de mographics | |||||
| 176 | .get FacilityNu mber()); | |||||
| 177 | data.set PatientRol eProviderO rganizatio nOid(this. getHomeCom munity() | |||||
| 178 | .get OrgOid()); | |||||
| 179 | if (Null Checker.is NotEmpty(d emographic s.getDob() )) { | |||||
| 180 | try { | |||||
| 181 | // Need to use the H L7 date, b ecause the CDA R2 ne eds it | |||||
| 182 | data.setPa tientRoleD ob(HL7Date Util | |||||
| 183 | .yyyyM MddhhmmssZ (demograph ics.getDob ())); | |||||
| 184 | } ca tch (final ParseExce ption ex) { | |||||
| 185 | throw new RuntimeExc eption(ex) ; | |||||
| 186 | } | |||||
| 187 | } | |||||
| 188 | } | |||||
| 189 | // For each file item, create th e media ty pe | |||||
| 190 | if (NullChec ker.isNotE mpty(fileI tems)) { | |||||
| 191 | for (fin al FileIte m fileItem : fileIte ms) { | |||||
| 192 | if ( fileItem.g etSize() > 0) { | |||||
| 193 | final Scan nedConsent DirectiveD ocumentBas e64Text sc annedConse ntDirectiv eDocumentB ase64Text = new Scan nedConsent DirectiveD ocumentBas e64Text(); | |||||
| 194 | ||||||
| 195 | final byte [] bytes = fileItem. get(); | |||||
| 196 | // JAXB au tomaticall y decodes the docume nt when ma king it | |||||
| 197 | // into XM L | |||||
| 198 | // String encodedStr ing = new sun.misc.B ASE64Encod er() | |||||
| 199 | // .encode (bytes); | |||||
| 200 | // byte[] encodedByt es = encod edString.g etBytes(); | |||||
| 201 | final Stri ng content Type = fil eItem.getC ontentType (); | |||||
| 202 | // Set the type and representa tion | |||||
| 203 | scannedCon sentDirect iveDocumen tBase64Tex t | |||||
| 204 | .setMe diaType(co ntentType) ; | |||||
| 205 | scannedCon sentDirect iveDocumen tBase64Tex t | |||||
| 206 | .setRe presentati on("B64"); | |||||
| 207 | scannedCon sentDirect iveDocumen tBase64Tex t | |||||
| 208 | .setDo cument(byt es); | |||||
| 209 | // add the document to Consent DirectiveD ata | |||||
| 210 | data.getSc annedConse ntDirectiv eDocumentB ase64Text( ).add( | |||||
| 211 | scanne dConsentDi rectiveDoc umentBase6 4Text); | |||||
| 212 | } | |||||
| 213 | } | |||||
| 214 | } | |||||
| 215 | // Set a uni que id per document | |||||
| 216 | da ta.setDocI d(UUIDUtil .generateU UID()); | |||||
| 217 | // return re sponse | |||||
| 218 | re turn data; | |||||
| 219 | ||||||
| 220 | } | |||||
| 221 | ||||||
| 222 | privat e ServiceC onsumerCon textType c reateServi ceConsumer Context( | |||||
| 223 | fi nal String userId, f inal Strin g userFaci lityStatio nId) { | |||||
| 224 | fi nal Servic eConsumerC ontextType consumerC ontext = n ew Service ConsumerCo ntextType( ); | |||||
| 225 | co nsumerCont ext.setUse r(userId); | |||||
| 226 | co nsumerCont ext.setFac ility(user FacilitySt ationId); | |||||
| 227 | co nsumerCont ext | |||||
| 228 | .setServ iceConsume rType(Serv iceConsume r.ADMINIST RATOR_PORT AL); | |||||
| 229 | re turn consu merContext ; | |||||
| 230 | } | |||||
| 231 | ||||||
| 232 | /** | |||||
| 233 | * Ana nd - 06/06 /2012 - Da y before 2 .0.0.7 cod e cutoff g etActiveCo nsentDirec tiveForAnn ouncements is a dupl icate of | |||||
| 234 | * get ActiveCons entDirecti ve with mi nor change s 1) The c onsent typ e is set o n the requ est, prior to dispat ching it. | |||||
| 235 | * | |||||
| 236 | * BEf ore creati ng this me thod getAc tiveConsen tDirective was chang ed to inco rporate th e afore-me ntioned ch ange This method is invoked | |||||
| 237 | * bot h during A nnounce an d OptOut S cenarios. The afore- mentioned change cau sed issues during op t-outs | |||||
| 238 | * | |||||
| 239 | * The framework for conse nt managem ent is bug gy and has to be ree valuated i n Incremen t 3. At th at point t his method will be | |||||
| 240 | * rec onsolidate d with get ActiveCons entDirecti ve, in add ition to o ther refac toring | |||||
| 241 | */ | |||||
| 242 | public ConsentDi rectiveRef erenceType getActive ConsentDir ectiveForA nnouncemen ts( | |||||
| 243 | fi nal String patientIc n, final C onsentType consentTy pe) { | |||||
| 244 | As sert.asser tNotEmpty( patientIcn , "ICN can not be emp ty!"); | |||||
| 245 | tr y { | |||||
| 246 | // Const ruct reque st | |||||
| 247 | final Co nsentDirec tiveQueryR equest con sentDirect iveQueryRe quest = ne w ConsentD irectiveQu eryRequest (); | |||||
| 248 | // Set t he patient id | |||||
| 249 | consentD irectiveQu eryRequest .setPatien tId(patien tIcn); | |||||
| 250 | ||||||
| 251 | ServiceC onsumerCon textType t ype = new ServiceCon sumerConte xtType(); | |||||
| 252 | type.set ConsentTyp e(consentT ype); | |||||
| 253 | consentD irectiveQu eryRequest .setServic eConsumerC ontext(typ e); | |||||
| 254 | // Get t he respons e | |||||
| 255 | ||||||
| 256 | // Query only for active | |||||
| 257 | consentD irectiveQu eryRequest | |||||
| 258 | .set QueryParam (ConsentDi rectiveQue ryParamTyp e.ACTIVE); | |||||
| 259 | final Co nsentDirec tiveQueryR esponse re sponse = t his.cms | |||||
| 260 | .get ConsentDir ectives(co nsentDirec tiveQueryR equest); | |||||
| 261 | if (Null Checker.is Empty(resp onse.getCo nsentDirec tiveRefere nce())) { | |||||
| 262 | retu rn null; | |||||
| 263 | } | |||||
| 264 | // Retur n response | |||||
| 265 | return r esponse.ge tConsentDi rectiveRef erence().g et(0); | |||||
| 266 | } catch (fin al Consent Management ServiceExc eption ex) { | |||||
| 267 | throw ne w RuntimeE xception(e x); | |||||
| 268 | } | |||||
| 269 | } | |||||
| 270 | ||||||
| 271 | /** | |||||
| 272 | * Get the activ e consent directive from the C onsent man agement se rvice. | |||||
| 273 | */ | |||||
| 274 | public ConsentDi rectiveRef erenceType getActive ConsentDir ective( | |||||
| 275 | fi nal String patientIc n, final C onsentType consentTy pe) { | |||||
| 276 | As sert.asser tNotEmpty( patientIcn , "ICN can not be emp ty!"); | |||||
| 277 | tr y { | |||||
| 278 | // Const ruct reque st | |||||
| 279 | final Co nsentDirec tiveQueryR equest con sentDirect iveQueryRe quest = ne w ConsentD irectiveQu eryRequest (); | |||||
| 280 | // Set t he patient id | |||||
| 281 | consentD irectiveQu eryRequest .setPatien tId(patien tIcn); | |||||
| 282 | // Query only for active | |||||
| 283 | consentD irectiveQu eryRequest | |||||
| 284 | .set QueryParam (ConsentDi rectiveQue ryParamTyp e.ACTIVE); | |||||
| 285 | final Co nsentDirec tiveQueryR esponse re sponse = t his.cms | |||||
| 286 | .get ConsentDir ectives(co nsentDirec tiveQueryR equest); | |||||
| 287 | ServiceC onsumerCon textType t ype = new ServiceCon sumerConte xtType(); | |||||
| 288 | type.set ConsentTyp e(consentT ype); | |||||
| 289 | consentD irectiveQu eryRequest .setServic eConsumerC ontext(typ e); | |||||
| 290 | // Get t he respons e | |||||
| 291 | if (Null Checker.is Empty(resp onse.getCo nsentDirec tiveRefere nce())) { | |||||
| 292 | retu rn null; | |||||
| 293 | } | |||||
| 294 | // Retur n response | |||||
| 295 | //Need t o differen tiate betw een active consent t ypes and r eturn the correct ac tive conse nt. | |||||
| 296 | for (Con sentDirect iveReferen ceType cdr : respons e.getConse ntDirectiv eReference ()) { | |||||
| 297 | if ( consentTyp e.equals(C onsentType .NW_HIN_RE VOCATION) && (cdr.ge tOptinCons entType() == Consent Type.NW_HI N_AUTHORIZ ATION)) { | |||||
| 298 | return cdr ; | |||||
| 299 | } | |||||
| 300 | if ( consentTyp e.equals(C onsentType .SSA_REVOC ATION) && (cdr.getOp tinConsent Type() == ConsentTyp e.SSA_AUTH ORIZATION) ) { | |||||
| 301 | return cdr ; | |||||
| 302 | } | |||||
| 303 | if ( consentTyp e.equals(C onsentType .NW_HIN_OR GANIZATION _RESTRICTI ON_REVOCAT ION) && (c dr.getOpti nConsentTy pe() == Co nsentType. NW_HIN_ORG ANIZATION_ RESTRICTIO N_AUTHORIZ ATION)) { | |||||
| 304 | return cdr ; | |||||
| 305 | } | |||||
| 306 | } | |||||
| 307 | return response. getConsent DirectiveR eference() .get(0); | |||||
| 308 | } ca tch (final ConsentMa nagementSe rviceExcep tion ex) { | |||||
| 309 | throw new Runtim eException (ex); | |||||
| 310 | } | |||||
| 311 | } | |||||
| 312 | ||||||
| 313 | /* * | |||||
| 314 | * Get all t he allowed organizat ions from the consen t manageme nt service . | |||||
| 315 | * This basi cally retu rns the li st of orga nizations that are s upported b y | |||||
| 316 | * the NHIN including the VA. | |||||
| 317 | * / | |||||
| 318 | pu blic Colle ction<Orga nizationTy pe> getAll Organizati ons() { | |||||
| 319 | try { | |||||
| 320 | // Cal l CMS | |||||
| 321 | final Organizati onsQueryRe sponse res ponse = th is.cms | |||||
| 322 | .getOrgani zations(ne w Organiza tionsQuery Request()) ; | |||||
| 323 | // Add VA to the list | |||||
| 324 | respon se.getOrga nization() .add(this. homeCommun ity); | |||||
| 325 | return response. getOrganiz ation(); | |||||
| 326 | } ca tch (final ConsentMa nagementSe rviceExcep tion ex) { | |||||
| 327 | throw new Runtim eException (ex); | |||||
| 328 | } | |||||
| 329 | } | |||||
| 330 | ||||||
| 331 | /* * | |||||
| 332 | * Get all t he allowed organizat ions from the consen t manageme nt service . | |||||
| 333 | * This basi cally retu rns the li st of orga nizations that are s upported b y | |||||
| 334 | * the NHIN excluding the VA. | |||||
| 335 | * / | |||||
| 336 | pu blic Colle ction<Orga nizationTy pe> getAll owedOrgani zations() { | |||||
| 337 | try { | |||||
| 338 | final Organizati onsQueryRe sponse res ponse = th is.cms | |||||
| 339 | .getOrgani zations(ne w Organiza tionsQuery Request()) ; | |||||
| 340 | return response. getOrganiz ation(); | |||||
| 341 | } ca tch (final ConsentMa nagementSe rviceExcep tion ex) { | |||||
| 342 | throw new Runtim eException (ex); | |||||
| 343 | } | |||||
| 344 | } | |||||
| 345 | ||||||
| 346 | /* * | |||||
| 347 | * Get all t he Non Con sumer only allowed o rganizatio ns from th e consent management service. | |||||
| 348 | * This basi cally retu rns the li st of orga nizations that are s upported b y | |||||
| 349 | * the NHIN excluding the VA, ex cluding SS A | |||||
| 350 | * / | |||||
| 351 | pu blic Colle ction<Orga nizationTy pe> getAll owedNonCon sumerOnlyO rganizatio ns() { | |||||
| 352 | // G et the all owed organ izations f rom the co nsent mana gement ser vice | |||||
| 353 | fina l Collecti on<Organiz ationType> allowedOr ganization s = this | |||||
| 354 | .getAllo wedOrganiz ations(); | |||||
| 355 | fina l List<Org anizationT ype> nonCo nsumerOnly Orgs = new ArrayList <Organizat ionType>() ; | |||||
| 356 | for (final Org anizationT ype allowe dOrganizat ion : allo wedOrganiz ations) { | |||||
| 357 | if (!t his.consum erOnlyOrgO ID.endsWit h(allowedO rganizatio n.getOrgOi d())) { | |||||
| 358 | nonConsu merOnlyOrg s.add(allo wedOrganiz ation); | |||||
| 359 | } | |||||
| 360 | } | |||||
| 361 | retu rn nonCons umerOnlyOr gs; | |||||
| 362 | } | |||||
| 363 | ||||||
| 364 | /* * | |||||
| 365 | * Get the o rganizatio ns that th e patient is current ly sharing informati on | |||||
| 366 | * with. NOT E: SHOULD BE USED ON LY FOR ANN OUNCEMENTS | |||||
| 367 | * @deprecat ed as of V AP 2.1 - P lease do n ot use - A MS | |||||
| 368 | * / | |||||
| 369 | ||||||
| 370 | pr ivate Coll ection<Org anizationT ype> getAu thorizedOr ganization s( | |||||
| 371 | final String pat ientId) { | |||||
| 372 | // G et the act ive consen t directiv e for that patient | |||||
| 373 | fina l ConsentD irectiveRe ferenceTyp e consentD irective = this | |||||
| 374 | .getActi veConsentD irectiveFo rAnnouncem ents(patie ntId, | |||||
| 375 | Co nsentType. NW_HIN_AUT HORIZATION ); | |||||
| 376 | // G et the all owed organ izations f rom the co nsent mana gement ser vice | |||||
| 377 | fina l Collecti on<Organiz ationType> allowedOr ganization s = this | |||||
| 378 | .getAllo wedNonCons umerOnlyOr ganization s(); | |||||
| 379 | fina l List<Org anizationT ype> opted InOrganiza tions = ne w ArrayLis t<Organiza tionType>( ); | |||||
| 380 | // I f no conse nt directi ve - selec t only to DoD. | |||||
| 381 | if ( NullChecke r.isEmpty( consentDir ective)) { | |||||
| 382 | //opte dInOrganiz ations.add (this.getO rganizatio nByNumber( "200DOD")) ; | |||||
| 383 | optedI nOrganizat ions.addAl l(allowedO rganizatio ns); | |||||
| 384 | } el se { | |||||
| 385 | final ConsentDir ectiveRefe renceType restrictio n = this | |||||
| 386 | .getActive ConsentDir ectiveForA nnouncemen ts( | |||||
| 387 | pati entId, | |||||
| 388 | Cons entType.NW _HIN_ORGAN IZATION_RE STRICTION_ AUTHORIZAT ION); | |||||
| 389 | ||||||
| 390 | // sel ect only t o authoriz ed organiz ations | |||||
| 391 | for (f inal Organ izationTyp e allowedO rganizatio n : allowe dOrganizat ions) { | |||||
| 392 | boolean toExclude = false; | |||||
| 393 | if (Null Checker.is NotEmpty(r estriction ) | |||||
| 394 | && NullCheck er.isNotEm pty(restri ction | |||||
| 395 | .getEx cludedOrga nizations( ))) { | |||||
| 396 | for (final Organizat ionType ex cludedOrga nization : restricti on | |||||
| 397 | .get ExcludedOr ganization s()) { | |||||
| 398 | if (allowedO rganizatio n.getOrgNu mber().equ als( | |||||
| 399 | exclud edOrganiza tion.getOr gNumber()) ) { | |||||
| 400 | toEx clude = tr ue; | |||||
| 401 | brea k; | |||||
| 402 | } | |||||
| 403 | } | |||||
| 404 | if (!toExc lude) { | |||||
| 405 | op tedInOrgan izations.a dd(allowed Organizati on); | |||||
| 406 | } | |||||
| 407 | } else { | |||||
| 408 | optedInOrg anizations .add(allow edOrganiza tion); | |||||
| 409 | } | |||||
| 410 | } | |||||
| 411 | } | |||||
| 412 | // R eturn the opted in o rganizatio ns | |||||
| 413 | retu rn optedIn Organizati ons; | |||||
| 414 | } | |||||
| 415 | ||||||
| 416 | /* * | |||||
| 417 | * The compl ete home c ommunity i d with the prefix fo r VA. | |||||
| 418 | * / | |||||
| 419 | pu blic Strin g getCompl eteHomeCom munityId() { | |||||
| 420 | retu rn this.ho meCommunit y.getOrgCo mmunityIdP refix() + ":" | |||||
| 421 | + this.h omeCommuni ty.getOrgO id(); | |||||
| 422 | } | |||||
| 423 | ||||||
| 424 | /* * | |||||
| 425 | * Get all t he consent directive s for a pa tient from the conse nt managem ent | |||||
| 426 | * service. | |||||
| 427 | * / | |||||
| 428 | pu blic List< ConsentDir ectiveRefe renceType> getConsen tDirective History( | |||||
| 429 | final String pat ientIcn) { | |||||
| 430 | Asse rt.assertN otEmpty(pa tientIcn, "ICN canno t be empty !"); | |||||
| 431 | try { | |||||
| 432 | final ConsentDir ectiveQuer yRequest c onsentDire ctiveQuery Request = new Consen tDirective QueryReque st(); | |||||
| 433 | consen tDirective QueryReque st.setPati entId(pati entIcn); | |||||
| 434 | // Set to ALL | |||||
| 435 | consen tDirective QueryReque st | |||||
| 436 | .setQueryP aram(Conse ntDirectiv eQueryPara mType.ALL) ; | |||||
| 437 | final ConsentDir ectiveQuer yResponse response = this.cms | |||||
| 438 | .getConsen tDirective s(consentD irectiveQu eryRequest ); | |||||
| 439 | // Ret urn list | |||||
| 440 | return response. getConsent DirectiveR eference() ; | |||||
| 441 | } ca tch (final ConsentMa nagementSe rviceExcep tion ex) { | |||||
| 442 | throw new Runtim eException (ex); | |||||
| 443 | } | |||||
| 444 | } | |||||
| 445 | ||||||
| 446 | /* * | |||||
| 447 | * Get all e xpiring co nsent dire ctives. | |||||
| 448 | * / | |||||
| 449 | pu blic Conse ntDirectiv eDetailedE xpirationR esponse ge tAllExpiri ngConsentD irectives( | |||||
| 450 | final ConsentDir ectiveDeta iledExpira tionReques t request) { | |||||
| 451 | try { | |||||
| 452 | ||||||
| 453 | final ConsentDir ectiveDeta iledExpira tionRespon se respons e = this.c ms | |||||
| 454 | .getAllExp iringConse ntDirectiv es(request ); | |||||
| 455 | // If empty, ret urn null | |||||
| 456 | if (Nu llChecker. isEmpty(re sponse.get ConsentDir ectiveRefe rence())) { | |||||
| 457 | return n ull; | |||||
| 458 | } | |||||
| 459 | // Ret urn list | |||||
| 460 | return response; | |||||
| 461 | } ca tch (final ConsentMa nagementSe rviceExcep tion ex) { | |||||
| 462 | throw new Runtim eException (ex); | |||||
| 463 | } | |||||
| 464 | } | |||||
| 465 | ||||||
| 466 | /** | |||||
| 467 | * Get all e xpiring co nsent dire ctives wit h some dem ographics. | |||||
| 468 | * / | |||||
| 469 | pu blic Conse ntDirectiv eDetailedE xpirationR esponse ge tAllExpiri ngDetailed ConsentDir ectives( | |||||
| 470 | final ConsentDir ectiveDeta iledExpira tionReques t request) { | |||||
| 471 | try { | |||||
| 472 | final ConsentDir ectiveDeta iledExpira tionRespon se respons e = this.c ms | |||||
| 473 | .getAllExp iringDetai ledConsent Directives (request); | |||||
| 474 | // If empty, ret urn null | |||||
| 475 | if (Nu llChecker. isEmpty(re sponse.get DetailedCo nsentDirec tiveRefere nce())) { | |||||
| 476 | return n ull; | |||||
| 477 | } | |||||
| 478 | // Ret urn list | |||||
| 479 | return response; | |||||
| 480 | } ca tch (final ConsentMa nagementSe rviceExcep tion ex) { | |||||
| 481 | throw new Runtim eException (ex); | |||||
| 482 | } | |||||
| 483 | } | |||||
| 484 | ||||||
| 485 | /** | |||||
| 486 | * Get all e xpiring co nsents by facility f or summary . | |||||
| 487 | * / | |||||
| 488 | pu blic Conse ntDirectiv eDetailedE xpirationR esponse ge tAuthorize dConsentFo rSummary( | |||||
| 489 | final ConsentDir ectiveDeta iledExpira tionReques t request) { | |||||
| 490 | try { | |||||
| 491 | final ConsentDir ectiveDeta iledExpira tionRespon se respons e = this.c ms | |||||
| 492 | .getAuthor izedConsen tForSummar y(request) ; | |||||
| 493 | // If empty, ret urn null | |||||
| 494 | if (Nu llChecker. isEmpty(re sponse.get FacilityOp tInConsent Reference( ))) { | |||||
| 495 | return n ull; | |||||
| 496 | } | |||||
| 497 | // Ret urn list | |||||
| 498 | return response; | |||||
| 499 | } ca tch (final ConsentMa nagementSe rviceExcep tion ex) { | |||||
| 500 | throw new Runtim eException (ex); | |||||
| 501 | } | |||||
| 502 | } | |||||
| 503 | ||||||
| 504 | /* * | |||||
| 505 | * Get the V A organiza tion. | |||||
| 506 | * / | |||||
| 507 | pu blic Organ izationTyp e getHomeC ommunity() { | |||||
| 508 | retu rn this.ho meCommunit y; | |||||
| 509 | } | |||||
| 510 | ||||||
| 511 | /* * | |||||
| 512 | * Get the l ist of opt -out reaso ns to popu late the G UI. | |||||
| 513 | * / | |||||
| 514 | pu blic List< String> ge tOptoutRea sons() { | |||||
| 515 | retu rn this.op tOutReason s; | |||||
| 516 | } | |||||
| 517 | ||||||
| 518 | /* * | |||||
| 519 | * Helper me thod to ge t the orga nization b y domain. | |||||
| 520 | * / | |||||
| 521 | pu blic Organ izationTyp e getOrgan izationByD omain(fina l String f acilityDom ain) { | |||||
| 522 | fina l Collecti on<Organiz ationType> allOrgani zationType s = this | |||||
| 523 | .getAllO rganizatio ns(); | |||||
| 524 | for (final Org anizationT ype Organi zationType : allOrga nizationTy pes) { | |||||
| 525 | if (Or ganization Type.getOr gDomain(). equals(fac ilityDomai n)) { | |||||
| 526 | return O rganizatio nType; | |||||
| 527 | } | |||||
| 528 | } | |||||
| 529 | retu rn null; | |||||
| 530 | } | |||||
| 531 | ||||||
| 532 | /* * | |||||
| 533 | * Helper me thod to ge t the orga nization b y Oid. | |||||
| 534 | * / | |||||
| 535 | pu blic Organ izationTyp e getOrgan izationByH omeCommuni tyId( | |||||
| 536 | final String hom eCommunity Id) { | |||||
| 537 | fina l Collecti on<Organiz ationType> allOrgani zationType s = this | |||||
| 538 | .getAllO rganizatio ns(); | |||||
| 539 | for (final Org anizationT ype Organi zationType : allOrga nizationTy pes) { | |||||
| 540 | if (Or ganization Type.getOr gOid().equ als(homeCo mmunityId) ) { | |||||
| 541 | return O rganizatio nType; | |||||
| 542 | } | |||||
| 543 | } | |||||
| 544 | retu rn null; | |||||
| 545 | } | |||||
| 546 | ||||||
| 547 | /* * | |||||
| 548 | * Helper me thod to ge t the orga nization b y number. | |||||
| 549 | * / | |||||
| 550 | pu blic Organ izationTyp e getOrgan izationByN umber( | |||||
| 551 | final String Org anizationT ypeNumber) { | |||||
| 552 | fina l Collecti on<Organiz ationType> allOrgani zationType s = this | |||||
| 553 | .getAllO rganizatio ns(); | |||||
| 554 | ||||||
| 555 | for (final Org anizationT ype Organi zationType : allOrga nizationTy pes) { | |||||
| 556 | if (Or ganization Type.getOr gNumber(). equals(Org anizationT ypeNumber) ) { | |||||
| 557 | return O rganizatio nType; | |||||
| 558 | } | |||||
| 559 | } | |||||
| 560 | retu rn null; | |||||
| 561 | } | |||||
| 562 | ||||||
| 563 | pu blic boole an isFormU ploadEnabl ed() { | |||||
| 564 | retu rn this.is FormUpload Enabled; | |||||
| 565 | } | |||||
| 566 | ||||||
| 567 | pu blic boole an isOrgan izationExc lusionsAll owed() { | |||||
| 568 | retu rn this.is Organizati onExclusio nsAllowed; | |||||
| 569 | } | |||||
| 570 | ||||||
| 571 | /* * | |||||
| 572 | * Convert f rom the Co nsentDirec tiveData t o the CDA R2 XML Pri vacy conse nt | |||||
| 573 | * directive document and then c onvert tha t to strin g. | |||||
| 574 | * / | |||||
| 575 | pr ivate byte [] makeCon sentDirect iveDocumen tString( | |||||
| 576 | final ConsentDir ectiveData data) { | |||||
| 577 | try { | |||||
| 578 | // Con vert the C onsentDire ctiveData to XML doc ument | |||||
| 579 | final Document c onsentDire ctiveDataD oc = this. dataJaxbHe lper | |||||
| 580 | .marshal(d ata); | |||||
| 581 | // Con vert Conse ntDirectiv eData XML to CDA R2 XML | |||||
| 582 | final Document c onsentDire ctiveDocum ent = this .dataToCon sentDirect iveDocumen t | |||||
| 583 | .transform (consentDi rectiveDat aDoc); | |||||
| 584 | // Con vert CDA R 2 XML to s tring | |||||
| 585 | final String con sentDirect iveDocumen tString = this.xmlTo String | |||||
| 586 | .transform (consentDi rectiveDoc ument); | |||||
| 587 | return consentDi rectiveDoc umentStrin g.getBytes (); | |||||
| 588 | ||||||
| 589 | } ca tch (final Transform erExceptio n ex) { | |||||
| 590 | throw new Runtim eException (ex); | |||||
| 591 | } ca tch (final JAXBExcep tion ex) { | |||||
| 592 | throw new Runtim eException (ex); | |||||
| 593 | } | |||||
| 594 | } | |||||
| 595 | ||||||
| 596 | /* * | |||||
| 597 | * Opt-in Pa tients! | |||||
| 598 | * / | |||||
| 599 | pu blic Strin g optIn(fi nal String icn, fina l String[] organizat ionNumbers , | |||||
| 600 | final PatientDem ographics demographi cs, | |||||
| 601 | final List<FileI tem> fileI tems, fina l String u serId, | |||||
| 602 | final String use rFacilityS tationId, final Date signature Date, | |||||
| 603 | final String con sentType, final Stri ng purpose OfUse, | |||||
| 604 | final String exp irationYea rs) { | |||||
| 605 | Asse rt.assertN otEmpty(ic n, "ICN ca nnot be em pty!"); | |||||
| 606 | Asse rt.assertN otEmpty(si gnatureDat e, "Signat ure Date c annot be e mpty!"); | |||||
| 607 | // G et the exc luded orga nizations | |||||
| 608 | fina l List<Org anizationT ype> exclu dedOrganiz ations = n ew ArrayLi st<Organiz ationType> (); | |||||
| 609 | if ( NullChecke r.isNotEmp ty(organiz ationNumbe rs)) { | |||||
| 610 | final Collection <Organizat ionType> f oreignOrga nizations = this | |||||
| 611 | .getAllowe dOrganizat ions(); | |||||
| 612 | ||||||
| 613 | for (f inal Organ izationTyp e organiza tion : for eignOrgani zations) { | |||||
| 614 | for (fin al String selection : organiza tionNumber s) { | |||||
| 615 | if (organi zation.get OrgNumber( ).equals(s election)) { | |||||
| 616 | ex cludedOrga nizations. add(organi zation); | |||||
| 617 | } | |||||
| 618 | } | |||||
| 619 | } | |||||
| 620 | } | |||||
| 621 | // C reate a Co nsentDirec tiveData o bject | |||||
| 622 | Cons entDirecti veData dat a = new Co nsentDirec tiveData() ; | |||||
| 623 | data = this.co nstructCon sentDirect iveDocumen tDemograph ics(data, icn, | |||||
| 624 | demograp hics, file Items); | |||||
| 625 | // S et author | |||||
| 626 | data .setAuthor PersonOid( userId); | |||||
| 627 | // d ata.setAut horPersonO rgOid(this .homeCommu nity.getOr gOid()); | |||||
| 628 | data .setAuthor PersonOrgO id(userFac ilityStati onId); | |||||
| 629 | // F ill up the excluded organizati ons | |||||
| 630 | if ( NullChecke r.isNotEmp ty(exclude dOrganizat ions)) { | |||||
| 631 | for (f inal Organ izationTyp e organiza tionType : excludedO rganizatio ns) { | |||||
| 632 | final Pa rticipant participan t = new Pa rticipant( ); | |||||
| 633 | particip ant.setCom ponentPart icipantOid (organizat ionType | |||||
| 634 | .g etOrgOid() ); | |||||
| 635 | particip ant | |||||
| 636 | .s etComponen tParticipa ntPlayingE ntityName( organizati onType | |||||
| 637 | .getOr gName()); | |||||
| 638 | data.get Participan t().add(pa rticipant) ; | |||||
| 639 | } | |||||
| 640 | } | |||||
| 641 | // S et the sta tus to act ive | |||||
| 642 | data .setCompon entStatusC ode("activ e"); | |||||
| 643 | data .setCompon entPurpose OfUseDispl ayName(Pur poseOfUseT ype.fromVa lue( | |||||
| 644 | purposeO fUse).valu e()); | |||||
| 645 | ||||||
| 646 | try { | |||||
| 647 | final String sig natureDate String = H L7DateUtil | |||||
| 648 | .yyyyMMddh hmmssZ(sig natureDate ); | |||||
| 649 | // Set the effec tive date | |||||
| 650 | data.s etEffectiv eDateTime( HL7DateUti l.yyyyMMdd hhmmssZ(ne w Date())) ; | |||||
| 651 | // Cre ate the be gin and en d date | |||||
| 652 | data.s etDocument ationBegin Time(signa tureDateSt ring); | |||||
| 653 | if (Nu llChecker. isNotEmpty (expiratio nYears)) { | |||||
| 654 | Calendar dateCal = Calendar. getInstanc e(); | |||||
| 655 | dateCal. setTime(si gnatureDat e); | |||||
| 656 | int expi ryYears = Integer.pa rseInt(exp irationYea rs); | |||||
| 657 | dateCal. add(Calend ar.YEAR, e xpiryYears ); | |||||
| 658 | data.set Documentat ionEndTime (HL7DateUt il | |||||
| 659 | .y yyyMMddhhm mssZ(dateC al.getTime ())); | |||||
| 660 | } | |||||
| 661 | } ca tch (final ParseExce ption ex) { | |||||
| 662 | throw new Runtim eException (ex); | |||||
| 663 | } | |||||
| 664 | // M ake the at tachment i nto bytes | |||||
| 665 | fina l byte[] c onsentDire ctiveDocum entBytes = this | |||||
| 666 | .makeCon sentDirect iveDocumen tString(da ta); | |||||
| 667 | try { | |||||
| 668 | // Cre ate the re quest and send to th e consent management service | |||||
| 669 | final ConsentDir ectiveAuth orizationR equest req uest = new ConsentDi rectiveAut horization Request(); | |||||
| 670 | reques t.setDocum ent(consen tDirective DocumentBy tes); | |||||
| 671 | final ServiceCon sumerConte xtType sc = this | |||||
| 672 | .createSer viceConsum erContext( userId, us erFacility StationId) ; | |||||
| 673 | sc.set ConsentTyp e(ConsentT ype.fromVa lue(consen tType)); | |||||
| 674 | reques t.setServi ceConsumer Context(sc ); | |||||
| 675 | // Pro cess | |||||
| 676 | Consen tDirective Authorizat ionRespons e response = this.cm s.processC onsentDire ctiveAutho rization(r equest); | |||||
| 677 | ||||||
| 678 | return response. getConsent DirectiveR eference() .getConsen tDirId(); | |||||
| 679 | } ca tch (final ConsentMa nagementSe rviceExcep tion ex) { | |||||
| 680 | throw new Runtim eException (ex); | |||||
| 681 | } | |||||
| 682 | } | |||||
| 683 | ||||||
| 684 | /* * | |||||
| 685 | * Opt out t he patient . | |||||
| 686 | * / | |||||
| 687 | pu blic Strin g optOut(f inal Strin g icn, | |||||
| 688 | final PatientDem ographics demographi cs, | |||||
| 689 | final List<FileI tem> fileI tems, fina l String o ptoutReaso n, | |||||
| 690 | final String use rId, final String us erFacility StationId, | |||||
| 691 | final Date signa tureDate, String con sentType, | |||||
| 692 | final String pur poseOfUse) { | |||||
| 693 | Asse rt.assertN otEmpty(ic n, "ICN ca nnot be em pty!"); | |||||
| 694 | Asse rt.assertN otEmpty(op toutReason , "Opt-out reason ca nnot be em pty!"); | |||||
| 695 | Asse rt.assertN otEmpty(us erId, "Use r id canno t be empty !"); | |||||
| 696 | Asse rt.assertN otEmpty(si gnatureDat e, "Signat ure Date c annot be e mpty!"); | |||||
| 697 | // l ook up the record th at needs t o be opted out. | |||||
| 698 | fina l ConsentD irectiveRe ferenceTyp e consentD irective = this | |||||
| 699 | .getActi veConsentD irective(i cn, | |||||
| 700 | Co nsentType. fromValue( consentTyp e)); | |||||
| 701 | if ( NullChecke r.isEmpty( consentDir ective)) { | |||||
| 702 | throw new Runtim eException ( | |||||
| 703 | "There has to be one active co nsent dire ctive to p rocess rev ocation!") ; | |||||
| 704 | } | |||||
| 705 | // C reate a co nsent dire ctive data object | |||||
| 706 | Cons entDirecti veData dat a = new Co nsentDirec tiveData() ; | |||||
| 707 | // C reate Demo graphics | |||||
| 708 | data = this.co nstructCon sentDirect iveDocumen tDemograph ics(data, icn, | |||||
| 709 | demograp hics, file Items); | |||||
| 710 | // S et the sta tus code t o aborted | |||||
| 711 | data .setCompon entStatusC ode("abort ed"); | |||||
| 712 | try { | |||||
| 713 | final String sig natureDate String = H L7DateUtil | |||||
| 714 | .yyyyMMddh hmmssZ(sig natureDate ); | |||||
| 715 | // Set the effec tive date | |||||
| 716 | data.s etEffectiv eDateTime( HL7DateUti l.yyyyMMdd hhmmssZ(ne w Date())) ; | |||||
| 717 | // Cre ate the be gin and en d date | |||||
| 718 | data.s etDocument ationBegin Time(signa tureDateSt ring); | |||||
| 719 | // Sta rt and end time are required | |||||
| 720 | data.s etDocument ationEndTi me(signatu reDateStri ng); | |||||
| 721 | } ca tch (final ParseExce ption ex) { | |||||
| 722 | throw new Runtim eException (ex); | |||||
| 723 | } | |||||
| 724 | // S et the con sent direc tive | |||||
| 725 | data .setPrevio usConsentD irectiveId (consentDi rective.ge tConsentDi rId()); | |||||
| 726 | data .setOptout Reason(opt outReason) ; | |||||
| 727 | data .setAuthor PersonOid( userId); | |||||
| 728 | data .setAuthor PersonOrgO id(userFac ilityStati onId); | |||||
| 729 | // M ake the re quest to r evoke | |||||
| 730 | fina l ServiceC onsumerCon textType s c = this | |||||
| 731 | .createS erviceCons umerContex t(userId, userFacili tyStationI d); | |||||
| 732 | data .setCompon entPurpose OfUseDispl ayName(Pur poseOfUseT ype.fromVa lue( | |||||
| 733 | purposeO fUse).valu e()); | |||||
| 734 | sc.s etConsentT ype(Consen tType.from Value(cons entType)); | |||||
| 735 | // C onvert the PDF into byte strin g | |||||
| 736 | fina l byte[] c onsentDire ctiveDocum entBytes = this | |||||
| 737 | .makeCon sentDirect iveDocumen tString(da ta); | |||||
| 738 | fina l ConsentD irectiveRe vocationRe quest requ est = new ConsentDir ectiveRevo cationRequ est(); | |||||
| 739 | requ est.setSer viceConsum erContext( sc); | |||||
| 740 | requ est.setOpt outReason( ConsentDir ectiveOptO utReasonTy pe | |||||
| 741 | .fromVal ue(optoutR eason)); | |||||
| 742 | requ est.setDoc ument(cons entDirecti veDocument Bytes); | |||||
| 743 | ||||||
| 744 | try { | |||||
| 745 | // Pro cess revok e | |||||
| 746 | this.c ms.process ConsentDir ectiveRevo cation(req uest); | |||||
| 747 | } ca tch (final ConsentMa nagementSe rviceExcep tion ex) { | |||||
| 748 | throw new Runtim eException (ex); | |||||
| 749 | } | |||||
| 750 | return c onsentDire ctive.getC onsentDirI d(); | |||||
| 751 | } | |||||
| 752 | ||||||
| 753 | /* * | |||||
| 754 | * Retrieve a CDA R2 X ML documen t based on the conse nt directi ve Id and | |||||
| 755 | * document type (OPT- IN/OPT-OUT ). | |||||
| 756 | * @pa ram consen tDirId | |||||
| 757 | * @pa ram docume ntType | |||||
| 758 | * @re turn | |||||
| 759 | */ | |||||
| 760 | public String re trieveDocu ment(final String co nsentDirId , | |||||
| 761 | fi nal String documentT ype) { | |||||
| 762 | ||||||
| 763 | As sert.asser tNotEmpty( consentDir Id, | |||||
| 764 | "Consent directive cannot be empty!"); | |||||
| 765 | As sert.asser tNotEmpty( documentTy pe, "Docum ent type c annot be e mpty!"); | |||||
| 766 | ||||||
| 767 | fi nal Consen tDirective DocumentRe trieveRequ est reques t = new Co nsentDirec tiveDocume ntRetrieve Request(); | |||||
| 768 | fi nal Consen tDirective ReferenceT ype refere nce = new ConsentDir ectiveRefe renceType( ); | |||||
| 769 | re ference.se tConsentDi rId(consen tDirId); | |||||
| 770 | // Set the r eference a nd the doc ument type and retri eve the CD A R2 XML | |||||
| 771 | // document | |||||
| 772 | re quest.setD ocumentTyp e(ConsentD irectiveDo cumentType | |||||
| 773 | .fromVal ue(documen tType)); | |||||
| 774 | re quest.setC onsentDire ctiveRefer ence(refer ence); | |||||
| 775 | tr y { | |||||
| 776 | final Co nsentDirec tiveDocume ntRetrieve Response r esponse = this.cms | |||||
| 777 | .get ConsentDir ectiveDocu ments(requ est); | |||||
| 778 | // There would be only one d ocument ba sed on the document type | |||||
| 779 | if (Null Checker.is NotEmpty(r esponse)) { | |||||
| 780 | if ( NullChecke r.isNotEmp ty(respons e.getDocum ents())) { | |||||
| 781 | final byte [] documen t = respon se.getDocu ments().ge t(0); | |||||
| 782 | if (NullCh ecker.isNo tEmpty(doc ument)) { | |||||
| 783 | return new Strin g(document ); | |||||
| 784 | } | |||||
| 785 | } | |||||
| 786 | } | |||||
| 787 | // Empty if no doc ument is f ound | |||||
| 788 | return n ull; | |||||
| 789 | } catch (fin al Consent Management ServiceExc eption ex) { | |||||
| 790 | throw ne w RuntimeE xception(e x); | |||||
| 791 | } | |||||
| 792 | } | |||||
| 793 | ||||||
| 794 | @Requi red | |||||
| 795 | public void setC ms(final C onsentMana gementServ ice cms) { | |||||
| 796 | th is.cms = c ms; | |||||
| 797 | } | |||||
| 798 | ||||||
| 799 | @Requi red | |||||
| 800 | public void setE cs(final E xpiringCon sentServic e ecs) { | |||||
| 801 | th is.ecs = e cs; | |||||
| 802 | } | |||||
| 803 | ||||||
| 804 | @Requi red | |||||
| 805 | public void setD ataJaxbHel per(final JaxbUtil d ataJaxbHel per) { | |||||
| 806 | th is.dataJax bHelper = dataJaxbHe lper; | |||||
| 807 | } | |||||
| 808 | ||||||
| 809 | @Requi red | |||||
| 810 | public void setD ataToConse ntDirectiv eDocument( | |||||
| 811 | fi nal Transf ormer<Docu ment, Docu ment> data ToConsentD irectiveDo cument) { | |||||
| 812 | th is.dataToC onsentDire ctiveDocum ent = data ToConsentD irectiveDo cument; | |||||
| 813 | } | |||||
| 814 | ||||||
| 815 | @Requi red | |||||
| 816 | public void setF ormUploadE nabled(fin al boolean isFormUpl oadEnabled ) { | |||||
| 817 | th is.isFormU ploadEnabl ed = isFor mUploadEna bled; | |||||
| 818 | } | |||||
| 819 | ||||||
| 820 | @Requi red | |||||
| 821 | public void setH omeCommuni ty(final O rganizatio nType home Community) { | |||||
| 822 | th is.homeCom munity = h omeCommuni ty; | |||||
| 823 | } | |||||
| 824 | ||||||
| 825 | @Requi red | |||||
| 826 | public void setO rganizatio nExclusion sAllowed( | |||||
| 827 | fi nal boolea n isOrgani zationExcl usionsAllo wed) { | |||||
| 828 | th is.isOrgan izationExc lusionsAll owed = isO rganizatio nExclusion sAllowed; | |||||
| 829 | } | |||||
| 830 | ||||||
| 831 | @Requi red | |||||
| 832 | public void setS tringToXml (final Str ingToXML s tringToXml ) { | |||||
| 833 | th is.stringT oXml = str ingToXml; | |||||
| 834 | } | |||||
| 835 | ||||||
| 836 | @Requi red | |||||
| 837 | public void setU pdateConse ntDirectiv eDocumentS tylesheet( | |||||
| 838 | fi nal XSLTra nsformer u pdateConse ntDirectiv eDocumentS tylesheet) { | |||||
| 839 | th is.updateC onsentDire ctiveDocum entStylesh eet = upda teConsentD irectiveDo cumentStyl esheet; | |||||
| 840 | } | |||||
| 841 | ||||||
| 842 | @Requi red | |||||
| 843 | public void setX mlToString (final XML ToString x mlToString ) { | |||||
| 844 | th is.xmlToSt ring = xml ToString; | |||||
| 845 | } | |||||
| 846 | ||||||
| 847 | @Requi red | |||||
| 848 | public void setC onsumerOnl yOrgOID(fi nal String consumerO nlyOrgOID) { | |||||
| 849 | th is.consume rOnlyOrgOI D = consum erOnlyOrgO ID; | |||||
| 850 | } | |||||
| 851 | ||||||
| 852 | public void upda teDocument (final Str ing consen tDirId, | |||||
| 853 | fi nal String documentT ype, final List<File Item> file Items, | |||||
| 854 | fi nal String userId, f inal Strin g userFaci lityStatio nId) { | |||||
| 855 | if (NullChec ker.isNotE mpty(fileI tems)) { | |||||
| 856 | final St ring docum ent = this .retrieveD ocument(co nsentDirId , | |||||
| 857 | docu mentType); | |||||
| 858 | Assert.a ssertNotEm pty(docume nt, "Docum ent cannot be empty! "); | |||||
| 859 | // For e ach file i tem, creat e the medi a type | |||||
| 860 | try { | |||||
| 861 | Docu ment resul t = null; | |||||
| 862 | fina l Document doc = thi s.stringTo Xml.transf orm(docume nt); | |||||
| 863 | DOMS ource sour ce = new D OMSource(d oc); | |||||
| 864 | for (final Fil eItem file Item : fil eItems) { | |||||
| 865 | if (fileIt em.getSize () > 0) { | |||||
| 866 | final byte[] byt es = fileI tem.get(); | |||||
| 867 | // JAX B automati cally deco des the do cument whe n making | |||||
| 868 | // it | |||||
| 869 | // int o XML | |||||
| 870 | final String enc odedString = Base64. encode(byt es); | |||||
| 871 | final String con tentType = fileItem. getContent Type(); | |||||
| 872 | final Map<String , Object> dynamicPar ameters = new HashMa p<String, Object>(); | |||||
| 873 | dynami cParameter s.put("med iaType", c ontentType ); | |||||
| 874 | dynami cParameter s.put("doc ument", en codedStrin g); | |||||
| 875 | dynami cParameter s.put("rep resentatio n", "B64") ; | |||||
| 876 | dynami cParameter s.put("use rId", user Id); | |||||
| 877 | dynami cParameter s.put("use rFacilityN umber", | |||||
| 878 | us erFacility StationId) ; | |||||
| 879 | DOMRes ult target = new DOM Result(); | |||||
| 880 | target = (DOMRes ult) this. updateCons entDirecti veDocument Stylesheet | |||||
| 881 | .t ransform(s ource, tar get, dynam icParamete rs); | |||||
| 882 | result = (Docume nt) target .getNode() ; | |||||
| 883 | source = new DOM Source(res ult); | |||||
| 884 | } | |||||
| 885 | } | |||||
| 886 | ||||||
| 887 | if ( NullChecke r.isNotEmp ty(result) ) { | |||||
| 888 | final Stri ng updated Doc = this .xmlToStri ng | |||||
| 889 | .trans form(resul t); | |||||
| 890 | final Cons entDirecti veUpdateRe quest cons entDirecti veUpdateRe quest = ne w ConsentD irectiveUp dateReques t(); | |||||
| 891 | final Serv iceConsume rContextTy pe sc = th is | |||||
| 892 | .creat eServiceCo nsumerCont ext(userId , | |||||
| 893 | us erFacility StationId) ; | |||||
| 894 | consentDir ectiveUpda teRequest. setService ConsumerCo ntext(sc); | |||||
| 895 | consentDir ectiveUpda teRequest. setDocumen t(updatedD oc | |||||
| 896 | .getBy tes()); | |||||
| 897 | final Cons entDirecti veUpdateRe sponse res ponse = th is.cms | |||||
| 898 | .proce ssConsentD irectiveUp date(conse ntDirectiv eUpdateReq uest); | |||||
| 899 | response.g etConsentD irectiveRe ference(); | |||||
| 900 | } | |||||
| 901 | } catch (final jav ax.xml.tra nsform.Tra nsformerEx ception ex ) { | |||||
| 902 | thro w new Runt imeExcepti on(ex); | |||||
| 903 | } catch (final Con sentManage mentServic eException ex) { | |||||
| 904 | thro w new Runt imeExcepti on(ex); | |||||
| 905 | } catch (final Tra nsformerEx ception ex ) { | |||||
| 906 | thro w new Runt imeExcepti on(ex); | |||||
| 907 | } | |||||
| 908 | } | |||||
| 909 | } | |||||
| 910 | ||||||
| 911 | public void upda teExpiring ConsentCon figuration (String fr equency, L ong window , String e mailAddres ses) { | |||||
| 912 | Ex piringCons entConfigu rationRequ est config Request | |||||
| 913 | = new Ex piringCons entConfigu rationRequ est(freque ncy, windo w, emailAd dresses); | |||||
| 914 | th is.ecs.upd ateConfigu ration(con figRequest ); | |||||
| 915 | } | |||||
| 916 | ||||||
| 917 | /** | |||||
| 918 | * Get s the curr ent expiri ng consent report co nfiguratio n from the database. If the co nfiguratio n is not s et, defaul t values a re | |||||
| 919 | * ret urned and these defa ults are t hen saved to the dat abase for the config uration. | |||||
| 920 | * | |||||
| 921 | * @re turn A map of string s that spe cify the e xpiring co nsent conf iguration | |||||
| 922 | */ | |||||
| 923 | public Map<Strin g, String> getExpiri ngConsentC onfigurati on() { | |||||
| 924 | Ex piringCons entConfigu rationResp onse confi gResponse | |||||
| 925 | = this.e cs.getConf iguration( new Expiri ngConsentC onfigurati onRequest( )); | |||||
| 926 | ||||||
| 927 | fi nal Map<St ring, Stri ng> result Map = new HashMap<St ring, Stri ng>(); | |||||
| 928 | if (configRe sponse != null) { | |||||
| 929 | resultMa p.put("fre quency", c onfigRespo nse.getCon figuration Reference( ).getFrequ ency()); | |||||
| 930 | resultMa p.put("win dow", conf igResponse .getConfig urationRef erence().g etWindow() .toString( )); | |||||
| 931 | resultMa p.put("ema ilAddresse s", config Response.g etConfigur ationRefer ence().get EmailAddre sses()); | |||||
| 932 | } else { | |||||
| 933 | // Use d efault con figuration values | |||||
| 934 | resultMa p.put("fre quency", D EFAULT_FRE QUENCY); | |||||
| 935 | resultMa p.put("win dow", DEFA ULT_WINDOW .toString( )); | |||||
| 936 | resultMa p.put("ema ilAddresse s", DEFAUL T_EMAILS); | |||||
| 937 | ||||||
| 938 | // Set c onfigurati on to defa ult values | |||||
| 939 | this.upd ateExpirin gConsentCo nfiguratio n(DEFAULT_ FREQUENCY, | |||||
| 940 | DEFA ULT_WINDOW , DEFAULT_ EMAILS); | |||||
| 941 | } | |||||
| 942 | ||||||
| 943 | re turn resul tMap; | |||||
| 944 | } | |||||
| 945 | ||||||
| 946 | public ByteArray InputStrea m getExpir ingConsent ReportLett ers(Date s tartDate, Date endDa te) throws IOExcepti on { | |||||
| 947 | Co nsentDirec tiveDetail edExpirati onRequest expiration Request | |||||
| 948 | = new Co nsentDirec tiveDetail edExpirati onRequest( ); | |||||
| 949 | ex pirationRe quest.setS tartDate(s tartDate); | |||||
| 950 | ex pirationRe quest.setE ndDate(end Date); | |||||
| 951 | Ex piringCons entLetterR esponse re sponse = t his.ecs.ge tReportLet ters(expir ationReque st); | |||||
| 952 | ||||||
| 953 | by te[] inByt es; | |||||
| 954 | if (response != null) { | |||||
| 955 | inBytes = response .getDownlo adByteArra y(); | |||||
| 956 | } else { | |||||
| 957 | inBytes = new byte [0]; | |||||
| 958 | } | |||||
| 959 | ||||||
| 960 | re turn new B yteArrayIn putStream( inBytes); | |||||
| 961 | } | |||||
| 962 | ||||||
| 963 | public ByteArray InputStrea m getExpir ingConsent ReportLett ers(Consen tDirective DetailedEx pirationRe quest expi rationRequ est) throw s IOExcept ion { | |||||
| 964 | Ex piringCons entLetterR esponse re sponse = t his.ecs.ge tReportLet ters(expir ationReque st); | |||||
| 965 | ||||||
| 966 | by te[] inByt es; | |||||
| 967 | if (response != null) { | |||||
| 968 | inBytes = response .getDownlo adByteArra y(); | |||||
| 969 | } else { | |||||
| 970 | inBytes = new byte [0]; | |||||
| 971 | } | |||||
| 972 | ||||||
| 973 | re turn new B yteArrayIn putStream( inBytes); | |||||
| 974 | } | |||||
| 975 | ||||||
| 976 | } |
Araxis Merge (but not the data content of this report) is Copyright © 1993-2016 Araxis Ltd (www.araxis.com). All rights reserved.