![]() |
| Perl to CF conversion |
|
jleone
|
I have an open source perl script that automates access to the Medi-CAL website to check insurance eligibility (for the health care industry.) I am a CF shop and don't know perl at all.
I need some help converting it to CF (if it is possible.) Would anyone be willing to give it a shot? Below is the perl code if anyone is interested in giving it a whirl. Thanks Josh #!/usr/bin/perl ############################################################################## # COPYRIGHT NOTICE # # Copyright (c) June 18, 2005, Mark Street, All Rights Reserved. # # mark AT oswizards.com # # This script may be used and modified free of charge by anyone so long as # # this copyright notice and the comments remain intact. By using this code # # you agree to indemnify Mark Street from any liability that might arise # # from it's use. # # # # In all cases this copyright and header must remain intact. # ############################################################################## # This program is free software; you can redistribute it and/or modify it # # under the terms of the GNU General Public License as published by the # # Free Software Foundation; either version 2 of the License, or (at your # # option) any later version. # # # # This program is distributed in the hope that it will be useful, but # # WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY # # or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License # # for more details. http://www.gnu.org/licenses/gpl.txt # # # # You should have received a copy of the GNU General Public License # # along with this program; if not, write to the Free Software # # Foundation, Inc., 59 Temple Place, Suite 330, Boston, # # MA 02111-1307 USA # ############################################################################## # # # This script automates the business process of running Medi-Cal eligibility # # transactions over the Internet through the Medi-Cal web site. # # # ############################################################################## use warnings; use strict; use LWP::UserAgent; use HTTP::Cookies; use HTTP::Response; use HTTP::Request::Common; ## The clinic ID and Password to access Medi-Cal Eligibility Transactions ## must be entered here. my $id = ''; my $pw = ''; ################## DO NOT EDIT ANYTHING BELOW THIS LINE ##################### ################## UNLESS YOU READ THROUGH THIS SCRIPT FIRST ################ ## Create some concatenated variables for use later. my $medpact = 'Medi-Cal=' . "$id" . 'xxxxxxxN00000000000'; my $fpact = 'Fpact=' . "$id" . 'xxxxxxxN00000000000'; my $userpw = 'UserPW=' . "$pw"; my $userid = 'UserID=' . "$id"; my $ua = LWP::UserAgent->new( ); my $cookie_jar = HTTP::Cookies->new( ); my $ss; my $res; my $res2; my $res3; my $res4; my $response; my $asp_session; my $siteserv; my $lastime; ##################### ## Listed below are the required 4 fields coming in from the PMS database ## Recipient ID, Recipient Date of Birth, Issue Date and Date of Service. ##################### my $recipid; my $recipdob; my $issuedate; my $servicedate; ###################### ## Subroutine to obtain the LastTime variable ## from request #2 to place in all subsequent ## requests. sub get_lastime ( $$ ) { return (($_[1] =~ m/\Q$_[0]\E(\w.*?M)/msx)[0]); } ###################### ## Subroutine to obtain SITESERVER and ASPSESSION ## variables for insertion into request cookies. ## Should probably either be split a word boundary ## like get_lastime or split into two routines. sub get_ss ( $$ ) { return (($_[1] =~ m/\Q$_[0]\E(.{35})/msx)[0]); } ######################## ### request number 1 ### ######################## my $req1 = HTTP::Request->new(GET => 'https://www.medi-cal.ca.gov/Eligibility/Login.asp '); $req1->header('Connection' => 'Keep-Alive'); $req1->header('User-Agent' => 'Mozilla/5.0 (compatible; Konqueror/3.4; Linux) KHTML/3.4.0 (like Gecko)'); $req1->header('Accept' => 'text/html, image/jpeg, image/png, text/*, image/*, */*'); $req1->header('Accept-Encoding' => 'x-gzip, x-deflate, gzip, deflate'); $req1->header('Accept-Charset' => 'iso-8859-1, utf-8;q=0.5, *;q=0.5'); $req1->header('Accept-Language' => 'en'); $req1->header('Host' => 'www.medi-cal.ca.gov'); $res = $ua->request($req1)->as_string; #print $res; $siteserv = get_ss( "SITESERVER=", $res ); $siteserv = "SITESERVER=" . "$siteserv"; #print "$siteserv \n"; $asp_session = get_ss( "ASPSESSION", $res ); $asp_session = "ASPSESSION" . "$asp_session"; #print "$asp_session \n"; ######################## ### request number 2 ### ######################## my $req2 = HTTP::Request->new(POST => 'https://www.medi-cal.ca.gov/Eligibility/Menu.asp?GoBack= '); $req2->header('Connection' => 'Keep-Alive'); $req2->header('User-Agent' => 'Mozilla/5.0 (compatible; Konqueror/3.4; Linux) KHTML/3.4.0 (like Gecko)'); $req2->header('Referer' => 'https://www.medi-cal.ca.gov/Eligibility/login.asp'); $req2->header('Pragma' => 'no-cache'); $req2->header('Cache-control' => 'no-cache'); $req2->header('Accept' => 'text/html, image/jpeg, image/png, text/*, image/*, */*'); $req2->header('Accept-Encoding' => 'x-gzip, x-deflate, gzip, deflate'); $req2->header('Accept-Charset' => 'iso-8859-1, utf-8;q=0.5, *;q=0.5'); $req2->header('Accept-Language' => 'en'); $req2->header('Host' => 'www.medi-cal.ca.gov'); $req2->header('Cookie' => "$userpw ; $userid"); $req2->header('Content-Type' => 'application/x-www-form-urlencoded'); $req2->header('Content-Length' => '89'); my $req2content = 'JScriptTest=ENABLED&CookieTest=ENABLED&HelpField=5&Flag=1&' . "$userid" . '&' . "$userpw"; $req2->content("$req2content"); $cookie_jar->add_cookie_header($req2); $res2 = $ua->request($req2)->as_string; $lastime = get_lastime( "LastTime=", $res2 ); $lastime = 'LastTime=' . "$lastime"; print "$lastime\n"; ######################## ### request number 3 ### ######################## my $req3 = HTTP::Request->new(GET => 'https://www.medi-cal.ca.gov/Eligibility/Eligibility.asp '); $req3->header('Connection' => 'Keep-Alive'); $req3->header('User-Agent' => 'Mozilla/5.0 (compatible; Konqueror/3.4; Linux) KHTML/3.4.0 (like Gecko)'); $req3->header('Referer' => 'https://www.medi-cal.ca.gov/Eligibility/Menu.asp?GoBack='); $req3->header('Accept' => 'text/html, image/jpeg, image/png, text/*, image/*, */*'); $req3->header('Accept-Encoding' => 'x-gzip, x-deflate, gzip, deflate'); $req3->header('Accept-Charset' => 'iso-8859-1, utf-8;q=0.5, *;q=0.5'); $req3->header('Accept-Language' => 'en'); $req3->header('Host' => 'www.medi-cal.ca.gov'); $req3->header('Cookie' => "$userpw; $userid"); $req3->header('Cookie' => "$medpact; ProvCounty=49; Platform=unknown; $lastime; ProvBCEDP=N; Browser=Default+0%2E0; ProvType=035; ProvBCCCP=N; Menu=DATAONE=N&BCCCP=N&DRUGR=N&TARmds=N&MPCT=N&CCSGHPP=N&COHS=N&MRB=N&FABS=N&TARncpdp=N&DSH=N&BCEDP=N&TARansi=N&TARform=N&MSSP=N&FPACT=N&EAPCGMS=N&STAT=N&PCE=N&MEDI=P&MMCDID=N&CHDPGTWY=P&EAPC=N&BCCTP=N&SVC=N&CMH=N&SOC=P&IPCS=N&CHDP=N&MESH=N&NCPDPresp=N&INB=N&FPACTR=N&RPTS=N&ARDS=N&ELIG=P&LABSERVICES=N&RTIP=N&835=N&CMC=N&RC=0; $fpact; $userpw; $userid; CookieTest=COOKIE; $asp_session; $siteserv"); $cookie_jar->add_cookie_header($req3); $ua->request($req3)->as_string; ### Now the looping routine to submit queries ### to our Eligibility Form. ### You will definitely want to create your own using a database or a file. ############ ############ OK, let's rock and roll through the database file. ############ #open ('batch', "testfile.txt") || die ("Could not open file. $!"); #while (<batch>){ # # my @fields = split /,/, $_; # # $recipid = $fields[0]; # $recipdob = $fields[1]; # $issuedate = $fields[2]; # $servicedate = $fields[3]; # ## Split up Date of Birth # my @bday = split /\//, $recipdob; # my $bday_mo = $bday[0]; # my $bday_day = $bday[1]; # my $bday_year = $bday[2]; ### probably want issue and service date's to be separate when using a web form ### So the user can change these as necessary. If they come encoded from the ### Web form all the better as we can keep the encoding and not worry about this ### splitting stuff. # ## Split up Issue Date # my @idate = split /\//, $issuedate; # my $idate_mo = $idate[0]; # my $idate_day = $idate[1]; # my $idate_year = $idate[2]; # # ## Split up Service Date # my @sdate = split /\//, $servicedate; # my $sdate_mo = $sdate[0]; # my $sdate_day = $sdate[1]; # my $sdate_year = $sdate[2]; ## You have to split the important dates above for the forth request ## cookie string and content string. ######################## ### request number 4 ### ######################## my $req4 = HTTP::Request->new(POST => 'https://www.medi-cal.ca.gov/Eligibility/EligResp.asp '); $req4->header('Connection' => 'Keep-Alive'); $req4->header('User-Agent' => 'Mozilla/5.0 (compatible; Konqueror/3.4; Linux) KHTML/3.4.0 (like Gecko)'); $req4->header('Referer' => 'https://www.medi-cal.ca.gov/Eligibility/Eligibility.asp'); $req4->header('Pragma' => 'no-cache'); $req4->header('Cache-control' => 'no-cache'); $req4->header('Accept' => 'text/html, image/jpeg, image/png, text/*, image/*, */*'); $req4->header('Accept-Encoding' => 'x-gzip, x-deflate, gzip, deflate'); $req4->header('Accept-Charset' => 'iso-8859-1, utf-8;q=0.5, *;q=0.5'); $req4->header('Accept-Language' => 'en'); $req4->header('Host' => 'www.medi-cal.ca.gov'); my $cookie_string = "RecipName=ID%3A+" . "$recipid" . "; PlugData=" . "$recipid" . "%7C" . "$bday_mo" . "%2F" . "$bday_day" . "%2F" . "$bday_year" . "%7C" . "$idate_mo" . "%2F" . "$idate_day" . "%2F" . "$idate_year" . "%7C" . "$sdate_mo" . "%2F" . "$sdate_day" . "%2F" . "$sdate_year" . "%7C%7C%7C%7C%7C%7C%7C%7C%7C; Medi-Cal=; " . "$lastime; ProvCounty=49; Platform=unknown; ProvBCEDP=N; Browser=Default+0%2E0; ProvType=035; ProvBCCCP=N; Menu=DATAONE=N&BCCCP=N&DRUGR=N&TARmds=N&MPCT=N&CCSGHPP=N&COHS=N&MRB=N&FABS=N&TARncpdp=N&DSH=N&BCEDP=N&TARansi=N&TARform=N&MSSP=N&FPACT=N&EAPCGMS=N&STAT=N&PCE=N&MEDI=P&MMCDID=N&CHDPGTWY=P&EAPC=N&BCCTP=N&SVC=N&CMH=N&SOC=P&IPCS=N&CHDP=N&MESH=N&NCPDPresp=N&INB=N&FPACTR=N&RPTS=N&ARDS=N&ELIG=P&LABSERVICES=N&RTIP=N&835=N&CMC=N&RC=0; $fpact; $userpw; $userid; CookieTest=COOKIE; $asp_session; $siteserv"; $req4->header('Cookie' => "$cookie_string"); $req4->header('Content-Type' => 'application/x-www-form-urlencoded'); my $content_string = "HelpField=9&SwipeCard=&UserID=&UserPW=&RecipID=" . "$recipid" . "&RecipDOB=" . "$bday_mo" . "%2F" . "$bday_day" . "%2F" . "$bday_year" . "&RecipDOI=" . "$idate_mo" . "%2F" . "$idate_day" . "%2F" . "$idate_year" . "&RecipDOS=" . "$sdate_mo" . "%2F" . "$sdate_day" . "%2F" . "$sdate_year"; my $content_length = length ($content_string); $req4->header('Content-Length' => "$content_length"); $req4->content("$content_string"); print $ua->request($req4)->as_string; } ## OK, that's great, but we need to slurp out the returned junk and store ## the good stuff found within. ## It just so happens that within each reply screen there is a nice list of ## Returned Values. ## ## What we have to do is slurp these values out for each patient and store ## them in a database or flatfile for display or printing later on. ## Have Fun!! #RecipID = [XXXXXXXXXXXX] #LastName = [XXXXXX] #FirstName = [XXXXXX] #AidCode = [XX] #CountyCode = [XX] #RecipDOB = [XX/XX/XX] #RecipDOI = [XX/XX/XXXX] #RecipDOS = [XX/XX/XXXX] #EligCode = [X] - 0=NO ELIG, 1=ELIG MEDI-CAL, 2=ELIG CMSP, etc... #EVCNo = [XXXXXXXXXX] #FoundElig = [X] #HICNo = [] #LimAidCd = [] #MediSvcsLeft = [] #Messages = [XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX] #OHCInd = [X] #PerOblig = [X] #Phone = [] #UserID = [XXXXXXXXX] #UserPW = [XXXXXXXXX] #ScopeOfCovg = [] #SOCOblig = [X] #SOCCase(1) = [] #SOCBalance(1) = [X] #SOCCase(2) = [] #SOCBalance(2) = [X] #SOCCase(3) = [] #SOCBalance(3) = [X] #SOCCase(4) = [] #SOCBalance(4) = [X] #SOCRem = [X] #SpecAid1 = [] #SpecAid2 = [] #SpecAid3 = [] |
||||||||||||
|
|
|||||||||||||
|
bobclingan
Forum Regular
|
You may want to check with the site and see if they provide any more modern ways of doing this check. It looks like something that could also easily be accomplished with a web service. As far as reproducing that code, I would look and see if you can send Custom HTTP Headers like that script is doing, I'm not sure there are functions for doing that. I would say, check out the cfhttp tag in the ColdFusion docs.
I'd also bet you could do it with java code since there is a more granular level of control. |
||||||||||||
|
|
|||||||||||||
|
Kristi-59162
|
Oh, My God!
|
||||||||||||
|
|
|||||||||||||
| Perl to CF conversion |
|
||
|


