Solved: Save and Dispense To Auto Calculate Price

When we decide how many tablets to prescribe to a patient, the no of tablets are reflected automatically in top right of the pop up window. But the price we have to calculate maually calculate and enter otherwise the price of tablets is not automatically added to the bill.

It would be nice if the amount field next to the no of tablets top right is set to auto calculate the price and auto fill…

Steps to have the price of medication prescribed to a patient auto calculated and that amount auto added to the bill.

1 Calculate the price of one tablet manually and enter that value in ndc_number when entering a new drug.
for already saved drugs , the ndc_number values can be entered by clicking on the drug name.
2 open dispense_drug.php ( file location interface/drugs/dispense_drug.php)
find on or around line 68

	if (!$fee) {
    	$fee = 0.00;
	}
and replace with the below code. Ad the below code 
/auto calculate the fee for no of tablets prescribed and add that amount to the bill.
	ry {
   	$db = new PDO('mysql:host=localhost;dbname=YourDatabaseName 'DatabaseUsername', 'DatabasePassword');

    	/ Prepare the SQL statement
    	stmt = $db->prepare("SELECT ndc_number FROM drugs WHERE drug_id = :drug_id");

    	/ Bind the parameters
    	stmt->bindParam(':drug_id', $drug_id);

    	/ Execute the statement
    	stmt->execute();

    	/ Fetch the row
    	row = $stmt->fetch(PDO::FETCH_ASSOC);

    	/ Get the ndc_number
    	ndc_number = $row['ndc_number'];
	 catch (PDOException $e) {
   	echo "Error: " . $e->getMessage();
	

	f (!$fee) {
   	if (isset($ndc_number) && is_numeric($ndc_number)) {
        $fee = ($quantity * $ndc_number);
    	 else {
        echo "The variable \$ndc_number is not set or not a number.";
    }
}

second edit(better if this is also done), it makes the fee field visibe readonly.

find file

on line 137

                        <input class="input-sm" type="text" name="disp_fee" size="5" maxlength="10" value="<?php echo attr($_smarty_tpl->tpl_vars['DISP_FEE']->value);?>
" />

replace with the below code

<input class="input-sm" type="text" name="disp_fee" size="5" maxlength="10" readonly
                        value="<?php echo ""?>"

save the changes and try addign a new drug to the prescription. the price will be automatically calculated and the same amount will be billed to the patient.

maybe the above code can be added to the openemr software as a patch. The admins can check the code pl. :slight_smile: