Weno Validate Fix (#2657)
[openemr.git] / interface / weno / validate.php
blob5fdd09cc8831e7f51f2b81b056c9dc89e650a9cb
1 <?php
2 /**
3 * weno rx validation.
5 * @package OpenEMR
6 * @link http://www.open-emr.org
7 * @author Sherwin Gaddis <sherwingaddis@gmail.com>
8 * @author Brady Miller <brady.g.miller@gmail.com>
9 * @copyright Copyright (c) 2016-2017 Sherwin Gaddis <sherwingaddis@gmail.com>
10 * @copyright Copyright (c) 2017-2018 Brady Miller <brady.g.miller@gmail.com>
11 * @license https://github.com/openemr/openemr/blob/master/LICENSE GNU General Public License 3
15 require_once("../globals.php");
16 require_once("$srcdir/patient.inc");
18 use OpenEMR\Common\Csrf\CsrfUtils;
19 use OpenEMR\Rx\Weno\TransmitData;
20 use OpenEMR\Services\FacilityService;
22 if (!CsrfUtils::verifyCsrfToken($_GET["csrf_token_form"])) {
23 CsrfUtils::csrfNotVerified();
26 $facilityService = new FacilityService();
27 $facility = $facilityService->getPrimaryBillingLocation();
29 $pid = $GLOBALS['pid'];
30 $uid = $_SESSION['authUserID'];
32 $validation = new TransmitData();
34 $patient = $validation->validatePatient($pid);
35 $pharmacy = $validation->patientPharmacyInfo($pid);
37 if (empty($facility['name']) || $facility['name'] == "Your clinic name here") {
38 print xlt("Please fill out facility name properly");
39 exit;
42 if (empty($facility['phone'])) {
43 print xlt("Please fill out facility phone properly");
44 exit;
47 if (empty($facility['fax'])) {
48 print xlt("Please fill out facility fax properly");
49 exit;
52 if (empty($facility['street'])) {
53 print xlt("Please fill out facility street properly");
54 exit;
57 if (empty($facility['city'])) {
58 print xlt("Please fill out facility city properly");
59 exit;
62 if (empty($facility['state'])) {
63 print xlt("Please fill out facility state properly");
64 exit;
67 if (empty($facility['postal_code'])) {
68 print xlt("Please fill out facility postal code properly");
69 exit;
72 if (empty($GLOBALS['weno_account_id'])) {
73 print xlt("Weno Account ID information missing")."<br>";
74 exit;
76 if (empty($GLOBALS['weno_provider_id'])) {
77 print xlt("Weno Account Clinic ID information missing")."<br>";
78 exit;
80 if (empty($patient['DOB'])) {
81 print xlt("Patient DOB missing"). "<br>";
82 exit;
84 if (empty($patient['street'])) {
85 print xlt("Patient street missing"). "<br>";
86 exit;
88 if (empty($patient['postal_code'])) {
89 print xlt("Patient Zip Code missing"). "<br>";
90 exit;
92 if (empty($patient['city'])) {
93 print xlt("Patient city missing"). "<br>";
94 exit;
96 if (empty($patient['state'])) {
97 print xlt("Patient state missing"). "<br>";
98 exit;
100 if (empty($patient['sex'])) {
101 print xlt("Patient sex missing"). "<br>";
102 exit;
104 if (empty($pharmacy['name'])) {
105 print xlt("Pharmacy not assigned to the patient"). "<br>";
106 exit;
108 $ncpdpLength = strlen($pharmacy['ncpdp']);
109 if (empty($pharmacy['ncpdp']) || $ncpdpLength < 7) {
110 print xlt("Pharmacy missing NCPDP ID or less than 7 digits"). "<br>";
111 exit;
113 $npiLength = strlen($pharmacy['npi']);
114 if (empty($pharmacy['npi'] || $npiLength < 10)) {
115 print xlt("Pharmacy missing NPI or less than 10 digits"). "<br>";
116 exit;
118 //validate NPI exist
119 //Test if the NPI is a valid number on file
120 $seekvalidation = $validation->validateNPI($pharmacy['npi']);
121 if ($seekvalidation == 0) {
122 print xlt("Please use valid NPI");
123 exit;
125 header('Location: confirm.php');