示例#1
0
     $form_injury_type = $_POST['form_injury_type'];
 } else {
     $form_injury_part = $_POST['form_medical_system'];
     $form_injury_type = $_POST['form_medical_type'];
 }
 if ($issue) {
     $query = "UPDATE lists SET " . "type = '" . $text_type . "', " . "title = '" . $_POST['form_title'] . "', " . "comments = '" . $_POST['form_comments'] . "', " . "begdate = " . QuotedOrNull($form_begin) . ", " . "enddate = " . QuotedOrNull($form_end) . ", " . "returndate = " . QuotedOrNull($form_return) . ", " . "diagnosis = '" . $_POST['form_diagnosis'] . "', " . "occurrence = '" . $_POST['form_occur'] . "', " . "classification = '" . $_POST['form_classification'] . "', " . "reinjury_id = '" . $_POST['form_reinjury_id'] . "', " . "referredby = '" . $_POST['form_referredby'] . "', " . "injury_grade = '" . $_POST['form_injury_grade'] . "', " . "injury_part = '" . $form_injury_part . "', " . "injury_type = '" . $form_injury_type . "', " . "outcome = '" . $_POST['form_outcome'] . "', " . "destination = '" . $_POST['form_destination'] . "', " . "reaction ='" . $_POST['form_reaction'] . "' " . "WHERE id = '{$issue}'";
     sqlStatement($query);
     if ($text_type == "medication" && enddate != '') {
         sqlStatement('UPDATE prescriptions SET ' . 'medication = 0 where patient_id = ' . $thispid . " and upper(trim(drug)) = '" . strtoupper($_POST['form_title']) . "' " . ' and medication = 1');
     }
 } else {
     $issue = sqlInsert("INSERT INTO lists ( " . "date, pid, type, title, activity, comments, begdate, enddate, returndate, " . "diagnosis, occurrence, classification, referredby, user, groupname, " . "outcome, destination, reinjury_id, injury_grade, injury_part, injury_type, " . "reaction " . ") VALUES ( " . "NOW(), " . "'{$thispid}', " . "'" . $text_type . "', " . "'" . $_POST['form_title'] . "', " . "1, " . "'" . $_POST['form_comments'] . "', " . QuotedOrNull($form_begin) . ", " . QuotedOrNull($form_end) . ", " . QuotedOrNull($form_return) . ", " . "'" . $_POST['form_diagnosis'] . "', " . "'" . $_POST['form_occur'] . "', " . "'" . $_POST['form_classification'] . "', " . "'" . $_POST['form_referredby'] . "', " . "'" . ${$_SESSION}['authUser'] . "', " . "'" . ${$_SESSION}['authProvider'] . "', " . "'" . $_POST['form_outcome'] . "', " . "'" . $_POST['form_destination'] . "', " . "'" . $_POST['form_reinjury_id'] . "', " . "'" . $_POST['form_injury_grade'] . "', " . "'" . $form_injury_part . "', " . "'" . $form_injury_type . "', " . "'" . $_POST['form_reaction'] . "' " . ")");
 }
 // For record/reporting purposes, place entry in lists_touch table.
 setListTouch($thispid, $text_type);
 if ($text_type == 'football_injury') {
     issue_football_injury_save($issue);
 }
 if ($text_type == 'ippf_gcac') {
     issue_ippf_gcac_save($issue);
 }
 if ($text_type == 'contraceptive') {
     issue_ippf_con_save($issue);
 }
 // If requested, link the issue to a specified encounter.
 if ($thisenc) {
     $query = "INSERT INTO issue_encounter ( " . "pid, list_id, encounter " . ") VALUES ( " . "'{$thispid}', '{$issue}', '{$thisenc}'" . ")";
     sqlStatement($query);
 }
 $tmp_title = addslashes($ISSUE_TYPES[$text_type][2] . ": {$form_begin} " . substr($_POST['form_title'], 0, 40));
示例#2
0
    /**
     * Insert new allergy as external sourced
     * @param  string  $name       Allergy name to insert
     * @param  integer $allergyId  External allergy Id
     * @param  integer $patientId  Patient Id
     * @param  integer $authUserId User Id
     * @param  integer $outcome    Allergy option Id
     */
    public function insertAllergy($name, $allergyId, $patientId, $authUserId, $outcome)
    {
        sqlQuery('INSERT INTO lists
				(
					date, type, erx_source, begdate,
					title, external_allergyid, pid, user, outcome
				)
			VALUES
				(
					NOW(), \'allergy\', \'1\', NOW(),
					?, ?, ?, ?, ?
				);', array($name, $allergyId, $patientId, $authUserId, $outcome));
        setListTouch($patientId, 'allergy');
    }
示例#3
0
}
$allergyArray = $array['NewDataSet']['Table'];
$j = 0;
for ($i = 0; $i < sizeof($allergyArray); $i++) {
    $qoutcome = sqlStatement("SELECT option_id FROM list_options WHERE list_id='outcome' AND title = ?", array($allergyArray[$i]['AllergySeverityName']));
    $routcome = sqlFetchArray($qoutcome);
    if (!$routcome['option_id']) {
        $routcome = sqlQuery("SELECT option_id AS option_id FROM list_options WHERE list_id='outcome' ORDER BY ABS(option_id) DESC LIMIT 1");
        sqlQuery("INSERT INTO list_options (list_id,option_id,title,seq) VALUES ('outcome',?,?,?)", array($routcome['option_id'] + 1, $allergyArray[$i]['AllergySeverityName'], $routcome['option_id'] + 1));
        $routcome['option_id'] = $routcome['option_id'] + 1;
    }
    $res = sqlStatement("select * from lists where pid=? and type='allergy' and title=? and (enddate is null or enddate = '' or enddate = '0000-00-00')", array($patientid, $allergyArray[$i]['AllergyName']));
    $row = sqlFetchArray($res);
    if (sqlNumRows($res) == 0) {
        sqlQuery("insert into lists (date,type,title,pid,user,outcome,external_allergyid,erx_source,begdate) values (NOW(),'allergy',?,?,?,?,?,'1',now())", array($allergyArray[$i]['AllergyName'], $patientid, $_SESSION['authUserID'], $routcome['option_id'], $allergyArray[$i]['AllergyId']));
        setListTouch($patientid, 'allergy');
        $j++;
    } elseif ($row['erx_source'] == 0) {
        sqlQuery("update lists set outcome=?, erx_source='1', external_allergyid=? where pid=? and title=?", array($routcome['option_id'], $allergyArray[$i]['AllergyId'], $patientid, $allergyArray[$i]['AllergyName']));
    } else {
        sqlQuery("update lists set outcome=? where pid=? and erx_source='1' and external_allergyid=? and title=?", array($routcome['option_id'], $patientid, $allergyArray[$i]['AllergyId'], $allergyArray[$i]['AllergyName']));
    }
    //sqlQuery("update lists set enddate = null where type='allergy' and pid=? and title=?",array($patientid,$allergyArray[$i]['AllergyName']));
}
$res = sqlStatement("select id,title from lists where pid=? and type='allergy' and erx_source='1' and (enddate is null or enddate = '' or enddate = '0000-00-00')", array($patientid));
while ($row = sqlFetchArray($res)) {
    $flag = 0;
    for ($i = 0; $i < sizeof($allergyArray); $i++) {
        if ($allergyArray[$i]['AllergyName'] == $row['title']) {
            $flag = 1;
            break;
示例#4
0
文件: save.php 项目: epsdky/openemr
         }
         if ($_REQUEST['form_outcome'] == '') {
             $_REQUEST['form_outcome'] = '0';
         }
         if ($issue != '0') {
             //if this issue already exists we are updating it...
             $query = "UPDATE lists SET " . "type = '" . add_escape_custom($form_type) . "', " . "title = '" . add_escape_custom($_REQUEST['form_title']) . "', " . "comments = '" . add_escape_custom($_REQUEST['form_comments']) . "', " . "begdate = " . QuotedOrNull($form_begin) . ", " . "enddate = " . QuotedOrNull($form_end) . ", " . "returndate = " . QuotedOrNull($form_return) . ", " . "diagnosis = '" . add_escape_custom($_REQUEST['form_diagnosis']) . "', " . "occurrence = '" . add_escape_custom($_REQUEST['form_occur']) . "', " . "classification = '" . add_escape_custom($_REQUEST['form_classification']) . "', " . "reinjury_id = '" . add_escape_custom($_REQUEST['form_reinjury_id']) . "', " . "referredby = '" . add_escape_custom($_REQUEST['form_referredby']) . "', " . "injury_grade = '" . add_escape_custom($_REQUEST['form_injury_grade']) . "', " . "injury_part = '" . add_escape_custom($form_injury_part) . "', " . "injury_type = '" . add_escape_custom($form_injury_type) . "', " . "outcome = '" . add_escape_custom($_REQUEST['form_outcome']) . "', " . "destination = '" . add_escape_custom($_REQUEST['form_destination']) . "', " . "reaction ='" . add_escape_custom($_REQUEST['form_reaction']) . "', " . "erx_uploaded = '0', " . "modifydate = NOW(), " . "subtype = '" . $subtype . "' " . "WHERE id = '" . add_escape_custom($issue) . "'";
             sqlStatement($query);
             if ($text_type == "medication" && enddate != '') {
                 sqlStatement('UPDATE prescriptions SET ' . 'medication = 0 where patient_id = ? ' . " and upper(trim(drug)) = ? " . ' and medication = 1', array($pid, strtoupper($_REQUEST['form_title'])));
             }
         } else {
             $query = "INSERT INTO lists ( " . "date, pid, type, title, activity, comments, " . "begdate, enddate, returndate, " . "diagnosis, occurrence, classification, referredby, user, " . "groupname, outcome, destination,reaction,subtype " . ") VALUES ( " . "NOW(), ?,?,?,1,?," . QuotedOrNull($form_begin) . ", " . QuotedOrNull($form_end) . ", " . QuotedOrNull($form_return) . ", " . "?,?,?,?,?," . "?,?,?,?,?)";
             $issue = sqlInsert($query, array($pid, $form_type, $_REQUEST['form_title'], $_REQUEST['form_comments'], $_REQUEST['form_diagnosis'], $_REQUEST['form_occur'], $_REQUEST['form_clasification'], $_REQUEST['form_referredby'], $_SESSION['authUser'], $_SESSION['authProvider'], QuotedOrNull($_REQUEST['form_outcome']), $_REQUEST['form_destination'], $_REQUEST['form_reaction'], $subtype));
             // For record/reporting purposes, place entry in lists_touch table.
             setListTouch($pid, $form_type);
             // If requested, link the issue to a specified encounter.
             // we always link them, automatically.
             if ($encounter) {
                 $query = "INSERT INTO issue_encounter ( " . "pid, list_id, encounter " . ") VALUES ( ?,?,? )";
                 sqlStatement($query, array($pid, $issue, $encounter));
             }
         }
         $irow = '';
         //if it is a medication do we need to do something with dosage fields?
         //leave all in title field form now.
     }
     $PMSFH = build_PMSFH($pid);
     send_json_values($PMSFH);
     exit;
 }
示例#5
0
<?php

// Copyright (C) 2011 Brady Miller <*****@*****.**>
//
// 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 file contains a function to keep track of which issues
// types get modified.
//
//SANITIZE ALL ESCAPES
$sanitize_all_escapes = true;
//
//STOP FAKE REGISTER GLOBALS
$fake_register_globals = false;
//
require_once dirname(__FILE__) . "/../../interface/globals.php";
require_once dirname(__FILE__) . "/../lists.inc";
//  IF there is a pid and type then will set the entry in lists_touch table
if (!empty($_POST['patient_id']) && !empty($_POST['type'])) {
    setListTouch($_POST['patient_id'], $_POST['type']);
}
示例#6
0
 /**
  * Insert or update medications for current patient
  * @return integer Count of newly cached records
  */
 public function insertUpdateMedications()
 {
     $store = $this->getStore();
     $insertedRows = 0;
     $medArray = self::htmlFixXmlToArray($this->getPatientFullMedicationHistory6()->GetPatientFullMedicationHistory6Result->XmlResponse);
     $store->updatePrescriptionsActiveByPatientId($this->getPatientId());
     if (is_array($medArray)) {
         foreach ($medArray as $med) {
             if ($med['DosageForm']) {
                 $optionIdDosageForm = $this->insertMissingListOptions('drug_form', $med['DosageForm']);
             } else {
                 $optionIdDosageForm = null;
             }
             if ($med['Route']) {
                 $optionIdRoute = $this->insertMissingListOptions('drug_route', $med['Route']);
             } else {
                 $optionIdRoute = null;
             }
             if ($med['StrengthUOM']) {
                 $optionIdStrengthUOM = $this->insertMissingListOptions('drug_units', $med['StrengthUOM']);
             } else {
                 $optionIdStrengthUOM = null;
             }
             if ($med['DosageFrequencyDescription']) {
                 $optionIdFrequencyDescription = $this->insertMissingListOptions('drug_interval', $med['DosageFrequencyDescription']);
             } else {
                 $optionIdFrequencyDescription = null;
             }
             $providerId = $store->selectUserIdByUserName($med['ExternalPhysicianID']);
             $check = $store->selectPrescriptionIdByGuidPatientId($med['PrescriptionGuid'], $med['ExternalPatientID']);
             $prescriptionId = '';
             if (0 == sqlNumRows($check)) {
                 $prescriptionId = $store->insertPrescriptions($med, $encounter, $providerId, $this->getAuthUserId(), $optionIdDosageForm, $optionIdRoute, $optionIdStrengthUOM, $optionIdFrequencyDescription);
                 ++$insertedRows;
                 setListTouch($this->getPatientId(), 'prescription_erx');
             } else {
                 $store->updatePrescriptions($med, $providerId, $this->getAuthUserId(), $optionIdDosageForm, $optionIdRoute, $optionIdStrengthUOM, $optionIdFrequencyDescription);
             }
             $result = sqlFetchArray($check);
             if ($result['id']) {
                 $prescriptionId = $result['id'];
             }
             // Making sure only transmitted prescriptions entry added into amc_misc_data for eRx Numerator
             if (!empty($med['PharmacyNCPDP'])) {
                 processAmcCall('e_prescribe_amc', true, 'add', $med['ExternalPatientID'], 'prescriptions', $prescriptionId);
             }
             if ($med['FormularyChecked'] === 'true') {
                 processAmcCall('e_prescribe_chk_formulary_amc', true, 'add', $med['ExternalPatientID'], 'prescriptions', $prescriptionId);
             }
         }
     }
     return $insertedRows;
 }
/**
 * update issues from list of diagnosis
 *
 * This function checks to see if a given list of diagnoses is already
 * associated with the given encounter.  Each diagnoses which has a
 * corresponding entry in the problem list, but isn't already associated gets
 * flagged. (update to issue_encounter table)
 * 
 * If the $create parameter is true, any diagnosis which doesn't have a
 * corresponding problem list entry has one created.
 * 
 * @param int   $pid        the ID of the patient
 * @param int   $encounter  the encounter ID
 * @param array $diags      a list of diagnoses
 * @param bool  $create     if set issue not already in the patient problem list will be created
 */
function update_issues($pid, $encounter, $diags)
{
    $list_touched = false;
    // flag to determine if we have actually affected the medical_problem list.
    $sqlEncounterDate = 'select date FROM form_encounter where encounter=?';
    $res = sqlQuery($sqlEncounterDate, array($encounter));
    $target_date = $res['date'];
    $lists_params = array();
    $encounter_params = array();
    $sqlUpdateIssueDescription = "UPDATE lists SET title=?, modifydate=NOW() WHERE id=? AND TITLE!=?";
    $sqlFindProblem = "SELECT id, title FROM lists WHERE ";
    $sqlFindProblem .= " ( (`begdate` IS NULL) OR (`begdate` IS NOT NULL AND `begdate`<=?) ) AND ";
    array_push($lists_params, $target_date);
    $sqlFindProblem .= " ( (`enddate` IS NULL) OR (`enddate` IS NOT NULL AND `enddate`>=?) ) ";
    array_push($lists_params, $target_date);
    $sqlFindProblem .= "  AND pid=? AND diagnosis like ? ";
    array_push($lists_params, $pid);
    array_push($lists_params, "");
    $idx_diagnosis = count($lists_params) - 1;
    $sqlFindIssueEncounter = "SELECT encounter FROM issue_encounter WHERE pid=? AND encounter=? AND list_id=?";
    array_push($encounter_params, $pid, $encounter);
    array_push($encounter_params, "");
    $sqlCreateIssueEncounter = " INSERT into issue_encounter(pid,list_id,encounter)values (?,?,?) ";
    $sqlCreateProblem = " INSERT into lists(date,begdate,type,occurrence,classification,pid,diagnosis,title,modifydate) values(?,?,'medical_problem',0,0,?,?,?,NOW())";
    $idx_list_id = count($encounter_params) - 1;
    foreach ($diags as $diags) {
        // ensure that a problem is allowed to be created from the diagnostic element
        if ($diags->allowed_to_create_problem_from_diagnosis != "TRUE") {
            continue;
        }
        $diagnosis_key = $diags->code_type . ":" . $diags->code;
        $list_id = null;
        if ($diags->db_id != null) {
            // If we got a the id for the problem passed in, then use it.
            $list_id = $diags->db_id;
        } else {
            // If not, then search the database for it.
            $lists_params[$idx_diagnosis] = '%' . $diagnosis_key . '%';
            $res = sqlStatement($sqlFindProblem, $lists_params);
            if (sqlNumRows($res) > 0) {
                $list_id = $res->fields['id'];
            }
        }
        if (!($list_id == null)) {
            // We found a problem corresponding to this diagnosis
            $encounter_params[$idx_list_id] = $list_id;
            $issue_encounter = sqlStatement($sqlFindIssueEncounter, $encounter_params);
            if (sqlNumRows($issue_encounter) == 0) {
                // An issue encounter entry didn't exist, so create it
                sqlInsert($sqlCreateIssueEncounter, array($pid, $list_id, $encounter));
            }
            // Check the description in the problem
            sqlStatement($sqlUpdateIssueDescription, array($diags->description, $list_id, $diags->description));
            $list_touched = true;
            // Since there is already medical_problem listed, then the list has been touched in the past, so make sure it's flagged correctly
        } else {
            // No Problem found for this diagnosis
            if ($diags->create_problem) {
                // If the create flag is set, then create an entry for this diagnosis.
                sqlInsert($sqlCreateProblem, array($target_date, $target_date, $pid, $diagnosis_key, $diags->description));
                $newProblem = sqlStatement($sqlFindProblem, $lists_params);
                // requerying the database for the newly created ID, instead of using the sqlInsert return value for backwards compatbility with 4.1.0 and earlier insert ID bug.
                if (sqlNumRows($newProblem) > 0) {
                    $list_id = $newProblem->fields['id'];
                    if ($list_id > 0) {
                        sqlInsert($sqlCreateIssueEncounter, array($pid, $list_id, $encounter));
                    }
                }
                $list_touched = true;
                // Since we are creating a new problem, the list has been touched
            }
        }
    }
    if ($list_touched) {
        // If the list was touched at any point by this code, then flag it in the DB.
        setListTouch($pid, 'medical_problem');
    }
}
    }
    if ($medArray[$i]['DosageFrequencyDescription']) {
        $qint = sqlStatement("SELECT option_id FROM list_options WHERE list_id='drug_interval' AND title = ?", array($medArray[$i]['DosageFrequencyDescription']));
        $rint = sqlFetchArray($qint);
        if (sqlNumRows($qint) <= 0) {
            $rint = sqlQuery("SELECT option_id AS option_id FROM list_options WHERE list_id='drug_interval' ORDER BY ABS(option_id) DESC LIMIT 1");
            sqlQuery("INSERT INTO list_options (list_id,option_id,title,seq) VALUES ('drug_interval',?,?,?)", array($rint['option_id'] + 1, $medArray[$i]['DosageFrequencyDescription'], $rint['option_id'] + 1));
            $rint['option_id'] = $rint['option_id'] + 1;
        }
    }
    $check = sqlStatement("select * from prescriptions where prescriptionguid=? and patient_id=? and prescriptionguid is not null", array($medArray[$i]['PrescriptionGuid'], $medArray[$i]['ExternalPatientID']));
    $prescription_id = '';
    if (sqlNumRows($check) == 0) {
        $prescription_id = sqlInsert("insert into prescriptions \n        (\n            patient_id,provider_id,encounter,date_added,drug,drug_id,drug_info_erx,form,dosage,size,unit,route,`INTERVAL`,refills,note,`DATETIME`,\n            `USER`,site,prescriptionguid,erx_source,rxnorm_drugcode\n        )\n        values\n        (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,NOW(),?,?,?,'1',?)", array($medArray[$i]['ExternalPatientID'], $provider['id'], $encounter, substr($medArray[$i]['PrescriptionDate'], 0, 10), $medArray[$i]['DrugName'], $medArray[$i]['DrugID'], $medArray[$i]['DrugInfo'], $rin['option_id'], $medArray[$i]['DosageNumberDescription'], number($medArray[$i]['Strength']), $runit['option_id'], $rroute['option_id'], $rint['option_id'], $medArray[$i]['Refills'], $medArray[$i]['PrescriptionNotes'], $_SESSION['authUserID'], $medArray[$i]['SiteID'], $medArray[$i]['PrescriptionGuid'], $medArray[$i]['rxcui']));
        $j++;
        setListTouch($patientid, 'prescription_erx');
    } else {
        sqlQuery("update prescriptions set \n        provider_id=?, drug=?, drug_id=?, drug_info_erx=?, form=?, dosage=?, size=? ,unit=?, route=?, `INTERVAL`=?, refills=?, note=?, \n        `DATETIME`=NOW(),`USER`=?, site=? ,erx_source='1', rxnorm_drugcode=?, active='1'\n        WHERE prescriptionguid=? AND patient_id=?\n        ", array($provider['id'], $medArray[$i]['DrugName'], $medArray[$i]['DrugID'], $medArray[$i]['DrugInfo'], $rin['option_id'], $medArray[$i]['DosageNumberDescription'], number($medArray[$i]['Strength']), $runit['option_id'], $rroute['option_id'], $rint['option_id'], $medArray[$i]['Refills'], $medArray[$i]['PrescriptionNotes'], $_SESSION['authUserID'], $medArray[$i]['SiteID'], $medArray[$i]['rxcui'], $medArray[$i]['PrescriptionGuid'], $medArray[$i]['ExternalPatientID']));
    }
    $result = sqlFetchArray($check);
    if ($result['id']) {
        $prescription_id = $result['id'];
    }
    processAmcCall('e_prescribe_amc', true, 'add', $medArray[$i]['ExternalPatientID'], 'prescriptions', $prescription_id);
}
if ($j != 0) {
    sqlQuery("update patient_data set soap_import_status=? where pid=?", array('2', $pid));
}
if ($xml_response_count == 0) {
    echo htmlspecialchars(xl("Nothing to import for Prescription"), ENT_NOQUOTES);
} elseif ($xml_response_count > 0) {
示例#9
0
$injury_type = isset($_POST['injury_type']) ? $_POST['injury_type'] : '';
$injury_grade = isset($_POST['injury_grade']) ? $_POST['injury_grade'] : '';
$reaction = isset($_POST['reaction']) ? $_POST['reaction'] : '';
$external_allergyid = isset($_POST['external_allergyid']) ? $_POST['external_allergyid'] : '';
$erx_source = isset($_POST['erx_source']) ? $_POST['erx_source'] : 0;
$erx_uploaded = isset($_POST['erx_uploaded']) ? $_POST['erx_uploaded'] : 0;
$xml_string = "";
$xml_string = "<list>";
if ($userId = validateToken($token)) {
    $user = getUsername($userId);
    $acl_allow = acl_check('patients', 'med', $user);
    $_SESSION['authUser'] = $user;
    $_SESSION['authGroup'] = $site;
    $_SESSION['pid'] = $pid;
    if ($acl_allow) {
        setListTouch($pid, $type);
        $strQuery = "INSERT INTO `lists`(`date`, `type`, `title`, `begdate`, `enddate`, `returndate`, `occurrence`, `classification`, `referredby`, `extrainfo`, `diagnosis`, `activity`, `comments`, `pid`, `user`, `groupname`, `outcome`, `destination`, `reinjury_id`, `injury_part`, `injury_type`, `injury_grade`, `reaction`, `external_allergyid`, `erx_source`, `erx_uploaded`) \n                                        VALUES (\n                                                '" . add_escape_custom($date) . "',\n                                                '" . add_escape_custom($type) . "',\n                                                '" . add_escape_custom($title) . "',\n                                                '" . add_escape_custom($begdate) . "',\n                                                '" . add_escape_custom($enddate) . "',\n                                                '" . add_escape_custom($returndate) . "',\n                                                '" . add_escape_custom($occurrence) . "',\n                                                '" . add_escape_custom($classification) . "',\n                                                '" . add_escape_custom($referredby) . "',\n                                                '" . add_escape_custom($extrainfo) . "',\n                                                '" . add_escape_custom($diagnosis) . "',\n                                                '" . add_escape_custom($activity) . "',\n                                                '" . add_escape_custom($comments) . "',\n                                                '" . add_escape_custom($pid) . "',\n                                                '" . add_escape_custom($user) . "',\n                                                '" . add_escape_custom($groupname) . "',\n                                                '" . add_escape_custom($outcome) . "',\n                                                '" . add_escape_custom($destination) . "',\n                                                '" . add_escape_custom($reinjury_id) . "',\n                                                '" . add_escape_custom($injury_part) . "',\n                                                '" . add_escape_custom($injury_type) . "',\n                                                '" . add_escape_custom($injury_grade) . "',\n                                                '" . add_escape_custom($reaction) . "',\n                                                '" . add_escape_custom($external_allergyid) . "',\n                                                '" . add_escape_custom($erx_source) . "',\n                                                '" . add_escape_custom($erx_uploaded) . "')";
        $result = sqlInsert($strQuery);
        $last_inseted_id = $result;
        $result1 = 1;
        if ($visit_id) {
            $sql_list_query = "INSERT INTO `issue_encounter`(`pid`, `list_id`, `encounter`, `resolved`) \n                            VALUES (\n                                '" . add_escape_custom($pid) . "',\n                                '" . add_escape_custom($last_inseted_id) . "',\n                                '" . add_escape_custom($visit_id) . "',\n                                0)";
            $result1 = sqlInsert($sql_list_query);
        }
        if ($result && $result1) {
            $xml_string .= "<status>0</status>";
            $xml_string .= "<reason>The {$type} has been added</reason>";
            $xml_string .= "<id>{$last_inseted_id}</id>";
        } else {
            $xml_string .= "<status>-1</status>";
            $xml_string .= "<reason>ERROR: Sorry, there was an error processing your data. Please re-submit the information again.</reason>";