Difference between revisions of "Medikredit Load"

From Book A Flight
Jump to navigation Jump to search
(Created page with "==/app/medikredit.php== If no filename is passed into the landing page, a form is presented asking for a filename to use. From the MediKredit site (https://www.medikredit.co.za/…")
 
Line 32: Line 32:
}
}
...
...

The next step is to look for new formulations, and add these to the "Formulation" table

$sql = "select distinct Form from TradeNamesLoad TNL left outer join Formulation F on Form = FormAbb where FormAbb is null";
$dp = new DataProvider();
$dp->setSQL($sql);
$dp->query();
if ($dp->numRows > 1) {
echo "<b><font color=\"red\">New formulations added</font></b><br>";
foreach($dp->data as $row) {
execSQL("INSERT INTO Formulation(FormAbb) VALUES('".$row[0]."');");
echo $row[0] . "<br>";
}
}

Revision as of 09:23, 15 May 2018

/app/medikredit.php

If no filename is passed into the landing page, a form is presented asking for a filename to use.

From the MediKredit site (https://www.medikredit.co.za/index.php?option=com_content&view=article&id=93&Itemid=121) you use the "Current NAPPI Codes" link and find the filename for the current / latest zip file. As of 2018-05 this is an 8.8mb file containing a single text file. The zip file unzips to a file of the same name but with .txt extension comprising 90mb of data.

Download and unzip

The first step is to download and unzip the file. This is done with WGET and UNZIP in a shell_exec to /tmp

$get = "https://www.medikredit.co.za/attachments/article/93/" . $_REQUEST['filename'];
$output = shell_exec('cd /tmp; rm ' . $_REQUEST['filename'] . '; rm PUBDOM*.TXT;');
$output = shell_exec('cd /tmp; /usr/bin/wget ' . $get);
$output .= shell_exec('cd /tmp; /usr/bin/unzip ' . $_REQUEST['filename']);

The next step is to open the text file for reading and iterate through it, lifting fields from specific locations using substr(). Each matching row is then inserted into the table TradeNamesLoad

$filename = "/tmp/".substr($_REQUEST['filename'],0,14).".TXT";

$handle = @fopen($filename, "r");
if (!$handle) {
   die("No file found for " . $filename);
}
    execSQL('truncate table TradeNamesLoad;');

    while (!feof($handle)) {
      $nappi = substr($buffer,10,6);
 ...
	if ($type != 'S') {		//exclude "surgical" products
           execSQL("INSERT INTO TradeNamesLoad(recType,Nappi,Suffix,Name,Str,Form,PackSize,Man,validDate,EANCode) 
             VALUES('{$type}', '{$nappi}', '{$nappiSuf}','{$Name}','{$Str}','{$form}','{$packsize}', '{$man}','${validDate}', '{$EANCode}');");
            $records ++;
	}
...

The next step is to look for new formulations, and add these to the "Formulation" table

    $sql = "select distinct Form from TradeNamesLoad TNL left outer join Formulation F on Form = FormAbb where FormAbb is null";
    $dp  = new DataProvider();
    $dp->setSQL($sql);
    $dp->query();
    if ($dp->numRows > 1) {
                echo "New formulations added
"; foreach($dp->data as $row) { execSQL("INSERT INTO Formulation(FormAbb) VALUES('".$row[0]."');"); echo $row[0] . "
"; } }