1. EPMO Open Source Coordination Office Redaction File Detail Report

Produced by Araxis Merge on 6/7/2019 12:47:31 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.

1.1 Files compared

# Location File Last Modified
1 TMP_Integration_v4.6.zip\TMP Integration.zip\CRM\MCSShared CvtHelperEmail.cs Tue May 21 19:06:30 2019 UTC
2 TMP_Integration_v4.6.zip\TMP Integration.zip\CRM\MCSShared CvtHelperEmail.cs Fri Jun 7 12:02:23 2019 UTC

1.2 Comparison summary

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

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

1.4 Active regular expressions

No regular expressions were active.

1.5 Comparison detail

  1   using MCSU tilities20 11;
  2   using Micr osoft.Crm. Sdk.Messag es;
  3   using Micr osoft.Xrm. Sdk;
  4   using Syst em;
  5   using Syst em.Collect ions.Gener ic;
  6   using Syst em.Globali zation;
  7   using Syst em.Linq;
  8   using Syst em.Text;
  9   using VA.T MP.DataMod el;
  10   using VA.T MP.OptionS ets;
  11  
  12   namespace  MCSShared
  13   {
  14       public  static pa rtial clas s CvtHelpe r
  15       {
  16  
  17           #r egion Emai l Related  Functions
  18           // Overloaded  method: c reates a l ist from a n Activty  Party to p opulate a  From, To,  or CC fiel d
  19           pu blic stati c List<Act ivityParty > SetParty List(Activ ityParty u ser)
  20           {
  21                List<Act ivityParty > userList  = new Lis t<Activity Party>();
  22                //user i f exists
  23                if (user  != null)
  24                    user List.Add(u ser);
  25                return u serList;
  26           }
  27  
  28           // Overloaded  method: r eturn empt y list if  userRef is  null, oth erwise get  Activity  party and  call first  SetEmailP roperties  method
  29           pu blic stati c List<Act ivityParty > SetParty List(Entit yReference  userRef)
  30           {
  31                return u serRef ==  null ? new  List<Acti vityParty> () :
  32                    CvtH elper.SetP artyList(n ew Activit yParty() {  PartyId =  new Entit yReference (userRef.L ogicalName , userRef. Id) });
  33           }
  34  
  35           // Overloaded  method: c reates a l ist from a n EntityCo llection t o populate  a From, T o, or CC f ield
  36           pu blic stati c List<Act ivityParty > SetParty List(Entit yCollectio n userColl ection)
  37           {
  38                List<Act ivityParty > userList  = new Lis t<Activity Party>();
  39  
  40                foreach  (var recor d in userC ollection. Entities.S elect(e =>  e).Distin ct())
  41                {
  42                    var  activityPa rty = new  ActivityPa rty() { Pa rtyId = ne w EntityRe ference(re cord.Logic alName, re cord.Id) } ;
  43                    user List.Add(a ctivityPar ty);
  44                }
  45                return u serList;
  46           }
  47  
  48           pu blic stati c List<Act ivityParty > SetParty List(List< SystemUser > userList )
  49           {
  50                List<Act ivityParty > users =  new List<A ctivityPar ty>();
  51  
  52                foreach  (SystemUse r u in use rList.Sele ct(e => e) .Distinct( ))
  53                {
  54                    var  activityPa rty = new  ActivityPa rty() { Pa rtyId = ne w EntityRe ference(u. LogicalNam e, u.Id) } ;
  55                    user s.Add(acti vityParty) ;
  56                }
  57                return u sers;
  58           }
  59  
  60           // This metho d takes th e email pa ssed in an d sends it
  61           pu blic stati c void Sen dEmail(Ema il email,  IOrganizat ionService  Organizat ionService , MCSLogge r logger)
  62           {
  63                //check  for pssc i n the serv er url, if  it is tru e, then do  nothing
  64                var serv erURL = Cv tHelper.ge tServerURL (Organizat ionService );
  65                if (!ser verURL.Con tains("pss c"))
  66                {
  67                    try
  68                    {
  69                         SendEmailR equest req uestObj =  new SendEm ailRequest ()
  70                         {
  71                             EmailI d = (Guid) email.Acti vityId,
  72                             IssueS end = true ,
  73                             Tracki ngToken =  ""
  74                         };
  75                         SendEmailR esponse re sponse = ( SendEmailR esponse)Or ganization Service.Ex ecute(requ estObj);
  76                    }
  77                    catc h (Excepti on ex)
  78                    {
  79                         logger.Wri teToFile($ "Error occ ured while  sending t he email w ith id: {e mail.Activ ityId.Valu e}\nDetail s:{ex.Mess age} {ex}" );
  80                    }
  81                }
  82           }
  83  
  84           // Saves and  Sends the  email
  85           pu blic stati c void Upd ateSendEma il(Email e mail, IOrg anizationS ervice Org anizationS ervice, MC SLogger lo gger)
  86           {
  87                try
  88                {
  89                    if ( email.To.C ount() > 0 )
  90                    {
  91                         Organizati onService. Update(ema il);
  92                         SendEmail( email, Org anizationS ervice, lo gger);
  93                    }
  94                    else
  95                    {
  96                         email.Desc ription =  "No recipi ents found , could no t send.  "  + email.D escription ;
  97                         Organizati onService. Update(ema il);
  98                    }
  99                }
  100                catch (E xception e x)
  101                {
  102                    logg er.WriteTo File($"Err or occured  while upd ating the  email with  id: {emai l.Activity Id.Value}\ nDetails:{ ex.Message } {ex}");
  103                }
  104           }
  105  
  106           pu blic stati c string G enerateNee dHelpSecti on(bool is Cancelled,  out strin g plainTex tHelpSecti on)
  107           {
  108                  var testur l = "https :// DNS . URL  /vvc-app?n ame=TestPa tient&conf erence=Tes tWaitingRo om@ DNS . URL  &pin=5678" ;
  109                var need HelpSectio n = (isCan celled) ?  string.Emp ty : $"<b> Need Help? </b><br/>< ul><li>If  you would  like to te st your co nnection t o VA Video  Connect p rior to yo ur appoint ment, {Cvt Helper.bui ldHTMLUrlA lt(testurl , "Click H ere to Tes t")}"
  110                      + $"<li>If  you would  like more  informati on about V A Video Co nnect, ple ase review  VA Video  Connect in formation  at the fol lowing lin k: {CvtHel per.buildH TMLUrlAlt( "https:// DNS . URL  /app/va-vi deo-connec t", "Addit ional VA V ideo Conne ct Informa tion")}</  li > "
  111                    + "< li>If you  need techn ical assis tance or w ant to do  a test cal l with a V A help des k technici an, please  call the  National T elehealth  Technology  Help Desk  at (866)  651-3180 o r (703) 23 4-4483 Mon day throug h Saturday , 7 a.m. t hrough 11  p.m. EST</ li></ul><b r/><br/>";
  112                needHelp Section +=  "<b>Need  to Resched ule?</b><b r/>Do not  reply to t his messag e. This me ssage is s ent from a n unmonito red mailbo x.  For an y question s or conce rns please  contact y our VA Fac ility or V A Clinical  Team.<br/ >"
  113                    + "- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ------<br/ >"
  114                    + "P lease do n ot reply t o this mes sage.It co mes from a n unmonito red mailbo x.";
  115  
  116                plainTex tHelpSecti on = (isCa ncelled) ?  string.Em pty : $"Ne ed Help?\\ n           o     If  you would  like to te st your co nnection t o VA Video  Connect p rior to yo ur appoint ment, Clic k Here to  Test: {tes turl}"
  117                      + $"\\n                 If you wou ld like mo re informa tion about  VA Video  Connect, p lease revi ew VA Vide o Connect  informatio n at the f ollowing l ink: https :// DNS . URL  /app/va-vi deo-connec t"
  118                    + "\ \n           o     If  you need  technical  assistance  or want t o do a tes t call wit h a VA hel p desk tec hnician, p lease call  the Natio nal Telehe alth Techn ology Help  Desk at ( 866) 651-3 180 or (70 3) 234-448 3 Monday t hrough Sat urday, 7 a .m. throug h 11 p.m.  EST\\n\\n" ;
  119                plainTex tHelpSecti on += "Nee d to Resch edule?\\nD o not repl y to this  message. T his messag e is sent  from an un monitored  mailbox.   For any qu estions or  concerns  please con tact your  VA Facilit y or VA Cl inical Tea m.\\n"
  120                    + "- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ------\\n"
  121                    + "P lease do n ot reply t o this mes sage.It co mes from a n unmonito red mailbo x.";
  122  
  123                return n eedHelpSec tion;
  124           }
  125  
  126           pu blic stati c string E mailFooter ()
  127           {
  128                return " <br/><br/> Please Do  Not Reply  to this me ssage.  It  comes fro m an unmon itored mai lbox.  For  any quest ions or co ncerns, pl ease conta ct your VA  Facility  or VA Clin ical Team. ";
  129           }
  130  
  131           pu blic stati c string T echnicalAs sistanceEm ailFooter( out string  plainText Footer)
  132           {
  133                plainTex tFooter =  "\\nTechni cal Assist ance\\n";
  134                var foot er = "<br/ ><b>Techni cal Assist ance</b><b r/>";
  135                var comm onText = " For techni cal assist ance, clin icians sho uld contac t the Nati onal Teleh ealth Tech nology Hel p Desk (NT THD) (866)  651 - 318 0 or (703)  234 - 448 3, Monday  through Sa turday, 7  a.m. throu gh 11 p.m.  EST.{0}"  +
  136                                 "- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ------" +
  137                                 "P lease do n ot reply t o this mes sage.It co mes from a n unmonito red mailbo x.";
  138                plainTex tFooter +=  commonTex t.Replace( "{0}", "\\ n");
  139                return f ooter + co mmonText.R eplace("{0 }", "<br/> ");
  140           }
  141  
  142           pu blic stati c bool Sho uldGenerat eVeteranEm ail(Guid p atientId,  IOrganizat ionService  Organizat ionService , MCSLogge r Logger)
  143           {
  144                bool sho uldGenerat eVeteranEm ail = fals e;
  145                using (v ar srv = n ew Xrm(Org anizationS ervice))
  146                {
  147                    var  patient =  srv.Contac tSet.First OrDefault( p => p.Id  == patient Id);
  148                    if ( patient !=  null && p atient.cvt _TabletTyp e != null)
  149                    {
  150                         switch (pa tient.cvt_ TabletType .Value)
  151                         {
  152                             case ( int)Contac tcvt_Table tType.Pers onalVAVide oConnectDe vice:
  153                                 sh ouldGenera teVeteranE mail = tru e;
  154                                 br eak;
  155                             case ( int)Contac tcvt_Table tType.VAIs suediOSDev ice:
  156                                 if  (patient. DoNotEMail  != null & & !patient .DoNotEMai l.Value)
  157                                 {
  158                                      shouldGe nerateVete ranEmail =  true;
  159                                 }
  160                                 br eak;
  161                         }
  162                    }
  163                    Logg er.WriteDe bugMessage ($"ShouldG enerateVet eranEmail  for patien t with nam e: {patien t.FullName } and ID:  {patientId } returned  {shouldGe nerateVete ranEmail}" );
  164                }
  165                return s houldGener ateVeteran Email;
  166           }
  167  
  168  
  169           // /// <summa ry>
  170           // /// Overlo ad for bas ic generat eEmailBody  - display s the url  as the mes sage for " Click Here "
  171           // /// </summ ary>
  172           // /// <param  name="rec ord">ID of  the email </param>
  173           // /// <param  name="ent ityStringN ame">strin g name of  the entity  - to retr ieve objec t type cod e</param>
  174           // /// <param  name="cus tomMessage ">The mess age</param >
  175           // /// <retur ns></retur ns>
  176           // internal s tatic stri ng Generat eEmailBody (Guid reco rd, string  entityStr ingName, s tring cust omMessage,  IOrganiza tionServic e Organiza tionServic e)
  177           // {
  178           //     return  GenerateE mailBody(r ecord, ent ityStringN ame, custo mMessage,  Organizati onService) ;
  179           // }
  180  
  181           // / <summary >
  182           // / Standard  "boilerpl ate" E-Mai l body
  183           // / </summar y>
  184           // / <param n ame="recor d">ID of t he email r ecord</par am>
  185           // / <param n ame="entit yStringNam e">The str ing name o f the obje ct type co de</param>
  186           // / <param n ame="custo mMessage"> The custom  string th at goes in to the ema il body</p aram>
  187           // / <param n ame="click HereMessag e">The mes sage that  is used as  the displ ay for the  hyperlink </param>
  188           // / <returns >the body  of the ema il</return s>
  189           in ternal sta tic string  GenerateE mailBody(G uid record , string e ntityStrin gName, str ing custom Message, I Organizati onService  Organizati onService,  string cl ickHereMes sage = "")
  190           {
  191                string b ody;
  192                body = G etRecordLi nk(new Ent ityReferen ce(entityS tringName,  record),  Organizati onService,  clickHere Message);
  193                body +=  "<br/><br/ >" + custo mMessage;
  194                body +=  EmailFoote r();
  195  
  196                return b ody;
  197           }
  198  
  199           in ternal sta tic string  GetRecord Link(Entit y record,  IOrganizat ionService  orgServic e, string  clickHereT ext = "")
  200           {
  201                return G etRecordLi nk(new Ent ityReferen ce(record. LogicalNam e, record. Id), orgSe rvice, cli ckHereText );
  202           }
  203  
  204           in ternal sta tic string  GetRecord Link(Entit yReference  record, I Organizati onService  Organizati onService,  string cl ickHereTex t = "")
  205           {
  206                var etc  = CvtHelpe r.GetEntit yTypeCode( Organizati onService,  record.Lo gicalName) ;
  207                string s ervernameA ndOrgname  = CvtHelpe r.getServe rURL(Organ izationSer vice);
  208                string u rl = serve rnameAndOr gname + "/ userDefine d/edit.asp x?etc=" +  etc + "&id =" + recor d.Id;
  209                return S tring.Form at("<a hre f=\"{0}\"> {1}</a>",  url, !stri ng.IsNullO rEmpty(cli ckHereText ) ? clickH ereText :  url);
  210           }
  211  
  212           in ternal sta tic string  ProviderS afetyCheck s()
  213           {
  214                var safe tyChecks =  "During y our initia l assessme nt be sure  to verify  the follo wing: ";
  215                safetyCh ecks += "< ul><li>Do  you have a ny concern s about su icide?</li >";
  216                safetyCh ecks += "< li>The Pat ient verba lly consen ts to the  telehealth  visit?</l i>";
  217                safetyCh ecks += "< li>If the  line drops , what num ber can I  call you a t?</li>";
  218                safetyCh ecks += "< li>What is  the name,  phone num ber, and r elationshi p of the p erson we s hould cont act in the  case of a n emergenc y?</li>";
  219                safetyCh ecks += "< li>What is  your loca l 10 digit  phone num ber for la w enforcem ent in you r communit y?</li>";
  220                safetyCh ecks += "< li>What is  the addre ss of your  location  during thi s visit?</ li></ul>";
  221                safetyCh ecks += "< li>Are you  in a safe  and priva te place?< /li></ul>" ;
  222                return s afetyCheck s;
  223           }
  224  
  225           in ternal sta tic string  VvcAppoin tmentInstr uctions(bo ol isCvtTa blet, out  string pla inTextInst ructions)
  226           {
  227                plainTex tInstructi ons = $"\\ n\\n{(isCv tTablet ?  "VVC Table t SIP Addr ess dialin g" : "VA V ideo Conne ct (VVC)") } Appointm ent Instru ctions:\\n "
  228                                        + $"           o      {(isCv tTablet ?  "To dial a  patient's  VVC SIP T ablet, you  must add  SIP and co lon as a p refix to a ny SIP Add ress, plus  tablet nu mber, as w ell as .bl tablet to  the end of  each SIP  VVC Tablet  Address."  : "Ensure  you are i n a privat e and safe  space wit h good int ernet conn ectivity,  and have t he followi ng informa tion avail able:")}\\ n"
  229                                         + $"{ (isCvtTabl et ? "           o      To more  easily fin d the VVC  tablet SIP  address a t the time  of the vi sit, we re commend yo u do one o f the foll owing:\\n"  : "           o      Phone numb er: How we  can reach  you by te lephone, i f the vide o call dro ps.")} \\n ";
  230                plainTex tInstructi ons += $"{ (isCvtTabl et ? "           o      Save the  attached  invitation  to your O utlook Cal endar\\n"  : "           o     A ddress: Yo ur locatio n during t he visit.  \\n")}";
  231                plainTex tInstructi ons += $"{ (isCvtTabl et ? "           o       Copy th is invitat ion into y our Outloo k calendar  and creat e a calend ar entry a t the time  of the vi sit, and/  or\\n" : "            o     Emer gency cont act: Name,  relations hip, and p hone numbe r of a per son who we  can conta ct in an e mergency.  \\n\\n")}" ;
  232                plainTex tInstructi ons += $"{ (isCvtTabl et ? "           o      Search y our Outloo k e-mail f or the dat e or Last  Initial /  Last 4, on  the day o f the visi t.\\n\\n"  : " ")}";
  233                plainTex tInstructi ons += $"{ (isCvtTabl et ? "           o      At the s tart of yo ur VVC App ointment ,  remember  (CAPS-Lock ):\\n*Some  informati on can be  obtained p rior to th e VVC appo intment by  another m ember of t he care te am.\\n" :  "")}";
  234                plainTex tInstructi ons += $"{ (isCvtTabl et ? "           o      Consent* : Obtain o r confirm  that verba l consent  for telehe alth has b een docume nted (Note : This is  a one-time  requireme nt for you r service) \\n" : "") }";
  235                plainTex tInstructi ons += $"{ (isCvtTabl et ? "           o      Address:  Obtain or  confirm t he locatio n and addr ess of the  patient t o ensure t hey are in  a safe pl ace and fo r use in c ase of an  emergency. \\n" : "") }";
  236                plainTex tInstructi ons += $"{ (isCvtTabl et ? "           o      Phone Nu mbers:*\\n Patient's  current ph one number  - for use  if discon nected.\\n Emergency  contact's  phone numb er - for u se in an e mergency.\ \n" : "")} ";
  237                plainTex tInstructi ons += $"{ (isCvtTabl et ? "           o      Survey t he environ ment and i dentify al l particip ants.\\n"  : "\\n\\n" )}";
  238  
  239                var appt Instructio ns = $"<br /><b>{(isC vtTablet ?  "VVC Tabl et SIP Add ress diali ng" : "VA  Video Conn ect (VVC)" )} Appoint ment Instr uctions:</ b>"
  240                                    //+ $"<ol> <li>{(isCv tTablet ?  "To dial a  patient’s  VVC SIP T ablet, you  must add  SIP and co lon as a p refix to a ny SIP Add ress, plus  tablet nu mber, as w ell as .bl tablet to  the end of  each SIP  VVC Tablet  Address."  : "The \" Click Here \" link ab ove is uni que to thi s visit.   You will n eed to cli ck it to e nter the V irtual Med ical Room  at the tim e of the a ppointment .")}</li>"
  241                                    + $"<li>{( isCvtTable t ? "To di al a patie nt’s VVC S IP Tablet,  you must  add SIP an d colon as  a prefix  to any SIP  Address,  plus table t number,  as well as  .bltablet  to the en d of each  SIP VVC Ta blet Addre ss." : "Th e \"Click  Here\" lin k above is  unique to  <b>this v isit</b>.   You will  need to cl ick it to  enter the  Virtual Me dical Room  at the ti me of the  appointmen t.")}</li> "
  242                                    + $"{(isCv tTablet ?  "<li>To mo re easily  find the V VC tablet  SIP addres s at the t ime of the  visit, we  recommend  you do on e of the f ollowing:< /li>" : "< li>To more  easily fi nd this un ique link  at the tim e of the v isit, we r ecommend y ou do one  of the fol lowing:</l i>")} ";
  243                apptInst ructions + = $"{(isCv tTablet ?  "<ul><li>S ave the at tached inv itation to  your Outl ook Calend ar</li>" :  "<ul><li> Save the a ttached in vitation t o your Out look Calen dar</li>") }";
  244                apptInst ructions + = $"{(isCv tTablet ?  "<li> Copy  this invi tation int o your Out look calen dar and cr eate a cal endar entr y at the t ime of the  visit, an d/ or</li> " : "<li>  Copy this  invitation  into your  Outlook c alendar an d create a  calendar  entry at t he time of  the visit , and/ or< /li>")}";
  245                apptInst ructions + = $"{(isCv tTablet ?  "< li>Sear ch your Ou tlook e-ma il for the  date or L ast Initia l / Last 4 , on the d ay of the  visit.</li ></ul>" :  "<li>Searc h your Out look e-mai l for the  date or La st Initial  / Last 4,  on the da y of the v isit.</li> </ul>")}";
  246                apptInst ructions + = $"{(isCv tTablet ?  "<li>At th e start of  your VVC  Appointmen t , rememb er (CAPS): <br/><i>*S ome inform ation can  be obtaine d prior to  the VVC a ppointment  by anothe r member o f the care  team.</i> </li>" : " <li>At the  start of  your VVC A ppointment  , remembe r (CAPS-Lo ck):<br/>< i>*Some in formation  can be obt ained prio r to the V VC appoint ment by an other memb er of the  care team. </i></li>" )}";
  247                apptInst ructions + = $"{(isCv tTablet ?  "<ul><li>< b><u>C</u> </b>onsent *: Obtain  or confirm  that verb al consent  for teleh ealth has  been docum ented (Not e: This is  a one-tim e requirem ent for yo ur service )</li>" :  "<ul><li>< b><u>C</u> </b>onsent *: Obtain  or confirm  that verb al consent  for teleh ealth has  been docum ented (Not e: This is  a one-tim e requirem ent for yo ur service )</li>")}" ;
  248                apptInst ructions + = $"{(isCv tTablet ?  "<li><b><u >A</u></b> ddress: Ob tain or co nfirm the  location a nd address  of the pa tient to e nsure they  are in a  safe place  and for u se in case  of an eme rgency.</l i>" : "<li ><b><u>A</ u></b>ddre ss: Obtain  or confir m the loca tion and a ddress of  the patien t to ensur e they are  in a safe  place and  for use i n case of  an emergen cy.</li>") }";
  249                apptInst ructions + = $"{(isCv tTablet ?  "<li><b><u >P</u></b> hone Numbe rs:*<br/>P atient’s c urrent pho ne number  – for use  if disconn ected.<br/ >Emergency  contact’s  phone num ber – for  use in an  emergency. </li>" : " <li><b><u> P</u></b>h one Number s:*<br/>Pa tient’s cu rrent phon e number –  for use i f disconne cted.<br/> Emergency  contact’s  phone numb er – for u se in an e mergency.< /li>")}";
  250                apptInst ructions + = $"{(isCv tTablet ?  "<li><b><u >S</u></b> urvey the  environmen t and iden tify all p articipant s.</li>" :  "<li><b>< u>S</u></b >urvey the  environme nt and ide ntify all  participan ts.</li><b r/><br/>") }";
  251                apptInst ructions + = $"{(isCv tTablet ?  string.Emp ty : "<li> <b><u>L</u ></b>ock t he virtual  conferenc e room onc e all part icipants h ave joined .</li>")}" ;
  252                apptInst ructions + = $"</ul>< /ol>";
  253  
  254                return a pptInstruc tions;
  255           }
  256  
  257           // / <summary >
  258           // / This met hod create s the .ics  attachmen t and appe nds it to  the email
  259           // / </summar y>
  260           // / <param n ame="email ">This is  the email  that the a ttachment  is attachi ng to</par am>
  261           // / <param n ame="sa">T he service  appointme nt which < /param>
  262           // / <param n ame="statu sCode">The  status of  the email  - which s ets the st atus of th e attachme nt as well  as the su bject of t he email</ param>
  263           in ternal sta tic void C reateCalen darAppoint mentAttach ment(Email  email, Se rviceAppoi ntment sa,  int statu sCode, str ing stethI P, IOrgani zationServ ice Organi zationServ ice, MCSLo gger Logge r, string  plainDescr iption)
  264           {
  265                bool gro up = false ;
  266                if (sa.m cs_groupap pointment  != null)
  267                {
  268                    grou p = sa.mcs _groupappo intment.Va lue;
  269                }
  270                Logger.W riteDebugM essage("Be gin Creati ng Calenda r Appointm ent");
  271                string s chLocation  = "See De scription" ;
  272                string s ubjectPref ix = "Tele health Vis it";
  273                if (emai l.Subject. Contains(" VA Video C onnect"))
  274                {
  275                    subj ectPrefix  = "VA Vide o Connect" ;
  276                    schL ocation =  "VA Video  Connect";
  277                }
  278                else if  (email.Sub ject.Conta ins("VVC S IP Tablet" ))
  279                {
  280                    subj ectPrefix  = "VVC SIP  Tablet";
  281                    schL ocation =  "VVC SIP T ablet";
  282                }
  283                string s chSubject  = group ==  true ? $" {subjectPr efix}- Gro up Appoint ment" :
  284                    $"{s ubjectPref ix}-Single  Appointme nt";
  285                string s chDescript ion = emai l.Descript ion;
  286                if (stri ng.IsNullO rWhiteSpac e(plainDes cription))
  287                    plai nDescripti on = schDe scription;
  288                System.D ateTime sc hBeginDate  = (System .DateTime) sa.Schedul edStart;
  289                System.D ateTime sc hEndDate =  (System.D ateTime)sa .Scheduled End;
  290                string s equence =  "";
  291                string s tatus = "C ONFIRMED";
  292                string m ethod = "" ;
  293                //if the  appointme nt is canc eled, send  a cancell ation noti ce based o n the UID  of the pre vious entr y sent
  294                if (stat usCode ==  (int)servi ceappointm ent_status code.Patie ntCanceled  || status Code == (i nt)service appointmen t_statusco de.ClinicC anceled)
  295                {
  296                    meth od = "METH OD:CANCEL\ n";
  297                    sequ ence = "SE QUENCE:1\n ";
  298                    stat us = "CANC ELLED";
  299                    schS ubject = $ "Canceled:  {subjectP refix} : D o Not Repl y";
  300                }
  301  
  302                //attach  a ClearSt eth CVL fi le if a st eth is in  the compon ents
  303                Logger.W riteDebugM essage("Be gin cvlAtt achment: s tethIP val ue = " + s tethIP);
  304                string c vlAtttachm ent = stri ng.IsNullO rEmpty(ste thIP) ? ""  :
  305                    "ATT ACH;ENCODI NG=BASE64; VALUE=BINA RY;X-FILEN AME=invita tion.cvl:"  + Convert .ToBase64S tring(new  ASCIIEncod ing().GetB ytes("<?xm l version= \"1.0\" en coding=\"U TF-8\"?><C VL><IP>" +  stethIP +  "</IP ><P ort>9005</ Port><Conf erenceId>1 2345</Conf erenceId>< /CVL>")) +  "\n";
  306                Logger.W riteDebugM essage("CV L attachme nt convers ion finish ed.");
  307                try
  308                {
  309                    stri ng att = " BEGIN:VCAL ENDAR\n" +
  310                                        "PRODI D:-//VA//V eterans Af fairs//EN\ n" +
  311                                        method  +
  312                                        "BEGIN :VEVENT\n"  +
  313                                        cvlAtt tachment +
  314                                        "UID:"  + sa.Id +  "\n" + se quence +
  315                                        "DTSTA RT:" + sch BeginDate. ToUniversa lTime().To String("yy yyMMdd\\TH Hmmss\\Z")  + "\n" +
  316                                        "DTEND :" + schEn dDate.ToUn iversalTim e().ToStri ng("yyyyMM dd\\THHmms s\\Z") + " \n" +
  317                                        "LOCAT ION:" + sc hLocation  +
  318                                        //Use  Descriptio n tag for  email clie nts that c ant handle  x-alt-des c tag with  HTML
  319                                        "\nDES CRIPTION:"  + plainDe scription. Replace("< br/>", "\\ n").Replac e("<b>", " ").Replace ("</b>", " ").Replace ("<u>", "" ).Replace( "</u>", "" ).Replace( "<i>", "") .Replace(" </i>", "") .Replace(" <li>", "           o      ").Rep lace("</li >", "\\n") .Replace(" <ul>", "") .Replace(" </ul>", "\ \n") +
  320                                        "\nSUM MARY:" + s chSubject  + "\nPRIOR ITY:3\n" +
  321                                        "STATU S:" + stat us + "\n"  +
  322                                        //Incl ude altern ate descri ption if t he calenda r client c an handle  html x-alt -desc tag
  323                                        "X-ALT -DESC;FMTT YPE=text/h tml:<html> " + schDes cription.R eplace("\n ", "<br/>" ) + "</htm l>" + "\n"  +
  324                                    "END:VEVEN T\n" + "EN D:VCALENDA R\n";
  325  
  326                    Acti vityMimeAt tachment c alendarAtt achment =  new Activi tyMimeAtta chment()
  327                    {
  328                         ObjectId =  new Entit yReference (Email.Ent ityLogical Name, emai l.Id),
  329                         ObjectType Code = Ema il.EntityL ogicalName ,
  330                         Subject =  $"{subject Prefix} Ap pointment" ,
  331                         Body = Con vert.ToBas e64String(
  332                                 ne w ASCIIEnc oding().Ge tBytes(att )),
  333                         FileName =  string.Fo rmat(Cultu reInfo.Cur rentCultur e, $"{subj ectPrefix} -Appointme nt.ics")
  334                    };
  335                    Logg er.WriteDe bugMessage ("About to  Create Ca lendar App ointment") ;
  336                    Orga nizationSe rvice.Crea te(calenda rAttachmen t);
  337                    Logg er.WriteDe bugMessage ("Finished  Creating  Calendar A ppointment ");
  338                }
  339                catch (E xception e x)
  340                {
  341                    Logg er.WriteTo File($"Fai led to Cre ate CVL At tachment.  Error: {ex .InnerExce ption.Mess age}");
  342                }
  343                return;
  344           }
  345  
  346           #e ndregion
  347  
  348  
  349           #r egion Comm only Used  Functions
  350           // TODO TO-DO : Consolid ate with E mail Autom ation func tion, shou ld we add  check for  User's Ema il existin g before a dding to t he AP List ?
  351           // / <summary >
  352           // / Gets the  list of t eam member s and retu rns them a s an activ ity party  list to be  added to  whatever e mail we ar e using
  353           // / </summar y>
  354           // / <param n ame="email "></param>
  355           // / <param n ame="TeamI d"></param >
  356           // / <param n ame="origi nalParty"> </param>
  357           // / <returns ></returns >
  358           in ternal sta tic List<A ctivityPar ty> Retrie veFacility TeamMember s(Email em ail, Guid  TeamId, IE numerable< ActivityPa rty> origi nalParty,  IOrganizat ionService  Organizat ionService , MCSLogge r Logger)
  359           {
  360                Logger.W riteDebugM essage("st arting Ret rieveFacil ityTeamMem bers");
  361                using (v ar srv = n ew Xrm(Org anizationS ervice))
  362                {
  363                    var  teamMember s = (List< TeamMember ship>)(srv .TeamMembe rshipSet.W here(t =>  t.TeamId = = TeamId). ToList());
  364                    var  recipientL ist = new  List<Activ ityParty>( );
  365  
  366                    if ( originalPa rty != nul l)
  367                         recipientL ist.AddRan ge(origina lParty);
  368  
  369                    Logg er.WriteDe bugMessage ("About to  add membe rs of team .");
  370                    fore ach (var m ember in t eamMembers )
  371                    {
  372                         var party  = new Acti vityParty( )
  373                         {
  374                             Activi tyId = new  EntityRef erence(ema il.Logical Name, emai l.Id),
  375                             PartyI d = new En tityRefere nce(System User.Entit yLogicalNa me, member .SystemUse rId.Value)
  376                         };
  377                         recipientL ist.Add(pa rty);
  378                    }
  379                    Logg er.WriteDe bugMessage ("Finished  adding me mbers of t eam.");
  380                    retu rn recipie ntList;
  381                }
  382           }
  383           #e ndregion
  384       }
  385   }