Initial import

This commit is contained in:
sas.fajri
2026-05-25 20:01:37 +07:00
commit 710d7c1b97
10371 changed files with 2381698 additions and 0 deletions

1
.gitignore vendored Normal file
View File

@@ -0,0 +1 @@
.DS_Store

4
one-api/.htaccess Normal file
View File

@@ -0,0 +1,4 @@
RewriteEngine on
RewriteBase /one-api/
RewriteCond $1 !^(index\.php|assets|user_guide|robots\.txt)
RewriteRule ^(.*)$ /one-api/index.php/$1 [L]

View File

@@ -0,0 +1,6 @@
<IfModule authz_core_module>
Require all denied
</IfModule>
<IfModule !authz_core_module>
Deny from all
</IfModule>

11
one-api/application/cache/index.html vendored Normal file
View File

@@ -0,0 +1,11 @@
<!DOCTYPE html>
<html>
<head>
<title>403 Forbidden</title>
</head>
<body>
<p>Directory access is forbidden.</p>
</body>
</html>

View File

@@ -0,0 +1,135 @@
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
/*
| -------------------------------------------------------------------
| AUTO-LOADER
| -------------------------------------------------------------------
| This file specifies which systems should be loaded by default.
|
| In order to keep the framework as light-weight as possible only the
| absolute minimal resources are loaded by default. For example,
| the database is not connected to automatically since no assumption
| is made regarding whether you intend to use it. This file lets
| you globally define which systems you would like loaded with every
| request.
|
| -------------------------------------------------------------------
| Instructions
| -------------------------------------------------------------------
|
| These are the things you can load automatically:
|
| 1. Packages
| 2. Libraries
| 3. Drivers
| 4. Helper files
| 5. Custom config files
| 6. Language files
| 7. Models
|
*/
/*
| -------------------------------------------------------------------
| Auto-load Packages
| -------------------------------------------------------------------
| Prototype:
|
| $autoload['packages'] = array(APPPATH.'third_party', '/usr/local/shared');
|
*/
$autoload['packages'] = array();
/*
| -------------------------------------------------------------------
| Auto-load Libraries
| -------------------------------------------------------------------
| These are the classes located in system/libraries/ or your
| application/libraries/ directory, with the addition of the
| 'database' library, which is somewhat of a special case.
|
| Prototype:
|
| $autoload['libraries'] = array('database', 'email', 'session');
|
| You can also supply an alternative library name to be assigned
| in the controller:
|
| $autoload['libraries'] = array('user_agent' => 'ua');
*/
$autoload['libraries'] = array();
/*
| -------------------------------------------------------------------
| Auto-load Drivers
| -------------------------------------------------------------------
| These classes are located in system/libraries/ or in your
| application/libraries/ directory, but are also placed inside their
| own subdirectory and they extend the CI_Driver_Library class. They
| offer multiple interchangeable driver options.
|
| Prototype:
|
| $autoload['drivers'] = array('cache');
|
| You can also supply an alternative property name to be assigned in
| the controller:
|
| $autoload['drivers'] = array('cache' => 'cch');
|
*/
$autoload['drivers'] = array();
/*
| -------------------------------------------------------------------
| Auto-load Helper Files
| -------------------------------------------------------------------
| Prototype:
|
| $autoload['helper'] = array('url', 'file');
*/
$autoload['helper'] = array();
/*
| -------------------------------------------------------------------
| Auto-load Config files
| -------------------------------------------------------------------
| Prototype:
|
| $autoload['config'] = array('config1', 'config2');
|
| NOTE: This item is intended for use ONLY if you have created custom
| config files. Otherwise, leave it blank.
|
*/
$autoload['config'] = array();
/*
| -------------------------------------------------------------------
| Auto-load Language files
| -------------------------------------------------------------------
| Prototype:
|
| $autoload['language'] = array('lang1', 'lang2');
|
| NOTE: Do not include the "_lang" part of your file. For example
| "codeigniter_lang.php" would be referenced as array('codeigniter');
|
*/
$autoload['language'] = array();
/*
| -------------------------------------------------------------------
| Auto-load Models
| -------------------------------------------------------------------
| Prototype:
|
| $autoload['model'] = array('first_model', 'second_model');
|
| You can also supply an alternative model name to be assigned
| in the controller:
|
| $autoload['model'] = array('first_model' => 'first');
*/
$autoload['model'] = array();

View File

@@ -0,0 +1,523 @@
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
/*
|--------------------------------------------------------------------------
| Base Site URL
|--------------------------------------------------------------------------
|
| URL to your CodeIgniter root. Typically this will be your base URL,
| WITH a trailing slash:
|
| http://example.com/
|
| WARNING: You MUST set this value!
|
| If it is not set, then CodeIgniter will try guess the protocol and path
| your installation, but due to security concerns the hostname will be set
| to $_SERVER['SERVER_ADDR'] if available, or localhost otherwise.
| The auto-detection mechanism exists only for convenience during
| development and MUST NOT be used in production!
|
| If you need to allow multiple domains, remember that this file is still
| a PHP script and you can easily do that on your own.
|
*/
$config['base_url'] = '';
/*
|--------------------------------------------------------------------------
| Index File
|--------------------------------------------------------------------------
|
| Typically this will be your index.php file, unless you've renamed it to
| something else. If you are using mod_rewrite to remove the page set this
| variable so that it is blank.
|
*/
$config['index_page'] = 'index.php';
/*
|--------------------------------------------------------------------------
| URI PROTOCOL
|--------------------------------------------------------------------------
|
| This item determines which server global should be used to retrieve the
| URI string. The default setting of 'REQUEST_URI' works for most servers.
| If your links do not seem to work, try one of the other delicious flavors:
|
| 'REQUEST_URI' Uses $_SERVER['REQUEST_URI']
| 'QUERY_STRING' Uses $_SERVER['QUERY_STRING']
| 'PATH_INFO' Uses $_SERVER['PATH_INFO']
|
| WARNING: If you set this to 'PATH_INFO', URIs will always be URL-decoded!
*/
$config['uri_protocol'] = 'REQUEST_URI';
/*
|--------------------------------------------------------------------------
| URL suffix
|--------------------------------------------------------------------------
|
| This option allows you to add a suffix to all URLs generated by CodeIgniter.
| For more information please see the user guide:
|
| https://codeigniter.com/user_guide/general/urls.html
*/
$config['url_suffix'] = '';
/*
|--------------------------------------------------------------------------
| Default Language
|--------------------------------------------------------------------------
|
| This determines which set of language files should be used. Make sure
| there is an available translation if you intend to use something other
| than english.
|
*/
$config['language'] = 'english';
/*
|--------------------------------------------------------------------------
| Default Character Set
|--------------------------------------------------------------------------
|
| This determines which character set is used by default in various methods
| that require a character set to be provided.
|
| See http://php.net/htmlspecialchars for a list of supported charsets.
|
*/
$config['charset'] = 'UTF-8';
/*
|--------------------------------------------------------------------------
| Enable/Disable System Hooks
|--------------------------------------------------------------------------
|
| If you would like to use the 'hooks' feature you must enable it by
| setting this variable to TRUE (boolean). See the user guide for details.
|
*/
$config['enable_hooks'] = FALSE;
/*
|--------------------------------------------------------------------------
| Class Extension Prefix
|--------------------------------------------------------------------------
|
| This item allows you to set the filename/classname prefix when extending
| native libraries. For more information please see the user guide:
|
| https://codeigniter.com/user_guide/general/core_classes.html
| https://codeigniter.com/user_guide/general/creating_libraries.html
|
*/
$config['subclass_prefix'] = 'MY_';
/*
|--------------------------------------------------------------------------
| Composer auto-loading
|--------------------------------------------------------------------------
|
| Enabling this setting will tell CodeIgniter to look for a Composer
| package auto-loader script in application/vendor/autoload.php.
|
| $config['composer_autoload'] = TRUE;
|
| Or if you have your vendor/ directory located somewhere else, you
| can opt to set a specific path as well:
|
| $config['composer_autoload'] = '/path/to/vendor/autoload.php';
|
| For more information about Composer, please visit http://getcomposer.org/
|
| Note: This will NOT disable or override the CodeIgniter-specific
| autoloading (application/config/autoload.php)
*/
$config['composer_autoload'] = false;
/*
|--------------------------------------------------------------------------
| Allowed URL Characters
|--------------------------------------------------------------------------
|
| This lets you specify which characters are permitted within your URLs.
| When someone tries to submit a URL with disallowed characters they will
| get a warning message.
|
| As a security measure you are STRONGLY encouraged to restrict URLs to
| as few characters as possible. By default only these are allowed: a-z 0-9~%.:_-
|
| Leave blank to allow all characters -- but only if you are insane.
|
| The configured value is actually a regular expression character group
| and it will be executed as: ! preg_match('/^[<permitted_uri_chars>]+$/i
|
| DO NOT CHANGE THIS UNLESS YOU FULLY UNDERSTAND THE REPERCUSSIONS!!
|
*/
$config['permitted_uri_chars'] = 'a-z 0-9~%.:_\-';
/*
|--------------------------------------------------------------------------
| Enable Query Strings
|--------------------------------------------------------------------------
|
| By default CodeIgniter uses search-engine friendly segment based URLs:
| example.com/who/what/where/
|
| You can optionally enable standard query string based URLs:
| example.com?who=me&what=something&where=here
|
| Options are: TRUE or FALSE (boolean)
|
| The other items let you set the query string 'words' that will
| invoke your controllers and its functions:
| example.com/index.php?c=controller&m=function
|
| Please note that some of the helpers won't work as expected when
| this feature is enabled, since CodeIgniter is designed primarily to
| use segment based URLs.
|
*/
$config['enable_query_strings'] = FALSE;
$config['controller_trigger'] = 'c';
$config['function_trigger'] = 'm';
$config['directory_trigger'] = 'd';
/*
|--------------------------------------------------------------------------
| Allow $_GET array
|--------------------------------------------------------------------------
|
| By default CodeIgniter enables access to the $_GET array. If for some
| reason you would like to disable it, set 'allow_get_array' to FALSE.
|
| WARNING: This feature is DEPRECATED and currently available only
| for backwards compatibility purposes!
|
*/
$config['allow_get_array'] = TRUE;
/*
|--------------------------------------------------------------------------
| Error Logging Threshold
|--------------------------------------------------------------------------
|
| You can enable error logging by setting a threshold over zero. The
| threshold determines what gets logged. Threshold options are:
|
| 0 = Disables logging, Error logging TURNED OFF
| 1 = Error Messages (including PHP errors)
| 2 = Debug Messages
| 3 = Informational Messages
| 4 = All Messages
|
| You can also pass an array with threshold levels to show individual error types
|
| array(2) = Debug Messages, without Error Messages
|
| For a live site you'll usually only enable Errors (1) to be logged otherwise
| your log files will fill up very fast.
|
*/
$config['log_threshold'] = 0;
/*
|--------------------------------------------------------------------------
| Error Logging Directory Path
|--------------------------------------------------------------------------
|
| Leave this BLANK unless you would like to set something other than the default
| application/logs/ directory. Use a full server path with trailing slash.
|
*/
$config['log_path'] = '';
/*
|--------------------------------------------------------------------------
| Log File Extension
|--------------------------------------------------------------------------
|
| The default filename extension for log files. The default 'php' allows for
| protecting the log files via basic scripting, when they are to be stored
| under a publicly accessible directory.
|
| Note: Leaving it blank will default to 'php'.
|
*/
$config['log_file_extension'] = '';
/*
|--------------------------------------------------------------------------
| Log File Permissions
|--------------------------------------------------------------------------
|
| The file system permissions to be applied on newly created log files.
|
| IMPORTANT: This MUST be an integer (no quotes) and you MUST use octal
| integer notation (i.e. 0700, 0644, etc.)
*/
$config['log_file_permissions'] = 0644;
/*
|--------------------------------------------------------------------------
| Date Format for Logs
|--------------------------------------------------------------------------
|
| Each item that is logged has an associated date. You can use PHP date
| codes to set your own date formatting
|
*/
$config['log_date_format'] = 'Y-m-d H:i:s';
/*
|--------------------------------------------------------------------------
| Error Views Directory Path
|--------------------------------------------------------------------------
|
| Leave this BLANK unless you would like to set something other than the default
| application/views/errors/ directory. Use a full server path with trailing slash.
|
*/
$config['error_views_path'] = '';
/*
|--------------------------------------------------------------------------
| Cache Directory Path
|--------------------------------------------------------------------------
|
| Leave this BLANK unless you would like to set something other than the default
| application/cache/ directory. Use a full server path with trailing slash.
|
*/
$config['cache_path'] = '';
/*
|--------------------------------------------------------------------------
| Cache Include Query String
|--------------------------------------------------------------------------
|
| Whether to take the URL query string into consideration when generating
| output cache files. Valid options are:
|
| FALSE = Disabled
| TRUE = Enabled, take all query parameters into account.
| Please be aware that this may result in numerous cache
| files generated for the same page over and over again.
| array('q') = Enabled, but only take into account the specified list
| of query parameters.
|
*/
$config['cache_query_string'] = FALSE;
/*
|--------------------------------------------------------------------------
| Encryption Key
|--------------------------------------------------------------------------
|
| If you use the Encryption class, you must set an encryption key.
| See the user guide for more info.
|
| https://codeigniter.com/user_guide/libraries/encryption.html
|
*/
$config['encryption_key'] = '';
/*
|--------------------------------------------------------------------------
| Session Variables
|--------------------------------------------------------------------------
|
| 'sess_driver'
|
| The storage driver to use: files, database, redis, memcached
|
| 'sess_cookie_name'
|
| The session cookie name, must contain only [0-9a-z_-] characters
|
| 'sess_expiration'
|
| The number of SECONDS you want the session to last.
| Setting to 0 (zero) means expire when the browser is closed.
|
| 'sess_save_path'
|
| The location to save sessions to, driver dependent.
|
| For the 'files' driver, it's a path to a writable directory.
| WARNING: Only absolute paths are supported!
|
| For the 'database' driver, it's a table name.
| Please read up the manual for the format with other session drivers.
|
| IMPORTANT: You are REQUIRED to set a valid save path!
|
| 'sess_match_ip'
|
| Whether to match the user's IP address when reading the session data.
|
| WARNING: If you're using the database driver, don't forget to update
| your session table's PRIMARY KEY when changing this setting.
|
| 'sess_time_to_update'
|
| How many seconds between CI regenerating the session ID.
|
| 'sess_regenerate_destroy'
|
| Whether to destroy session data associated with the old session ID
| when auto-regenerating the session ID. When set to FALSE, the data
| will be later deleted by the garbage collector.
|
| Other session cookie settings are shared with the rest of the application,
| except for 'cookie_prefix' and 'cookie_httponly', which are ignored here.
|
*/
$config['sess_driver'] = 'files';
$config['sess_cookie_name'] = 'ci_session';
$config['sess_expiration'] = 7200;
$config['sess_save_path'] = NULL;
$config['sess_match_ip'] = FALSE;
$config['sess_time_to_update'] = 300;
$config['sess_regenerate_destroy'] = FALSE;
/*
|--------------------------------------------------------------------------
| Cookie Related Variables
|--------------------------------------------------------------------------
|
| 'cookie_prefix' = Set a cookie name prefix if you need to avoid collisions
| 'cookie_domain' = Set to .your-domain.com for site-wide cookies
| 'cookie_path' = Typically will be a forward slash
| 'cookie_secure' = Cookie will only be set if a secure HTTPS connection exists.
| 'cookie_httponly' = Cookie will only be accessible via HTTP(S) (no javascript)
|
| Note: These settings (with the exception of 'cookie_prefix' and
| 'cookie_httponly') will also affect sessions.
|
*/
$config['cookie_prefix'] = '';
$config['cookie_domain'] = '';
$config['cookie_path'] = '/';
$config['cookie_secure'] = FALSE;
$config['cookie_httponly'] = FALSE;
/*
|--------------------------------------------------------------------------
| Standardize newlines
|--------------------------------------------------------------------------
|
| Determines whether to standardize newline characters in input data,
| meaning to replace \r\n, \r, \n occurrences with the PHP_EOL value.
|
| WARNING: This feature is DEPRECATED and currently available only
| for backwards compatibility purposes!
|
*/
$config['standardize_newlines'] = FALSE;
/*
|--------------------------------------------------------------------------
| Global XSS Filtering
|--------------------------------------------------------------------------
|
| Determines whether the XSS filter is always active when GET, POST or
| COOKIE data is encountered
|
| WARNING: This feature is DEPRECATED and currently available only
| for backwards compatibility purposes!
|
*/
$config['global_xss_filtering'] = FALSE;
/*
|--------------------------------------------------------------------------
| Cross Site Request Forgery
|--------------------------------------------------------------------------
| Enables a CSRF cookie token to be set. When set to TRUE, token will be
| checked on a submitted form. If you are accepting user data, it is strongly
| recommended CSRF protection be enabled.
|
| 'csrf_token_name' = The token name
| 'csrf_cookie_name' = The cookie name
| 'csrf_expire' = The number in seconds the token should expire.
| 'csrf_regenerate' = Regenerate token on every submission
| 'csrf_exclude_uris' = Array of URIs which ignore CSRF checks
*/
$config['csrf_protection'] = FALSE;
$config['csrf_token_name'] = 'csrf_test_name';
$config['csrf_cookie_name'] = 'csrf_cookie_name';
$config['csrf_expire'] = 7200;
$config['csrf_regenerate'] = TRUE;
$config['csrf_exclude_uris'] = array();
/*
|--------------------------------------------------------------------------
| Output Compression
|--------------------------------------------------------------------------
|
| Enables Gzip output compression for faster page loads. When enabled,
| the output class will test whether your server supports Gzip.
| Even if it does, however, not all browsers support compression
| so enable only if you are reasonably sure your visitors can handle it.
|
| Only used if zlib.output_compression is turned off in your php.ini.
| Please do not use it together with httpd-level output compression.
|
| VERY IMPORTANT: If you are getting a blank page when compression is enabled it
| means you are prematurely outputting something to your browser. It could
| even be a line of whitespace at the end of one of your scripts. For
| compression to work, nothing can be sent before the output buffer is called
| by the output class. Do not 'echo' any values with compression enabled.
|
*/
$config['compress_output'] = FALSE;
/*
|--------------------------------------------------------------------------
| Master Time Reference
|--------------------------------------------------------------------------
|
| Options are 'local' or any PHP supported timezone. This preference tells
| the system whether to use your server's local time as the master 'now'
| reference, or convert it to the configured one timezone. See the 'date
| helper' page of the user guide for information regarding date handling.
|
*/
$config['time_reference'] = 'local';
/*
|--------------------------------------------------------------------------
| Rewrite PHP Short Tags
|--------------------------------------------------------------------------
|
| If your PHP installation does not have short tag support enabled CI
| can rewrite the tags on-the-fly, enabling you to utilize that syntax
| in your view files. Options are TRUE or FALSE (boolean)
|
| Note: You need to have eval() enabled for this to work.
|
*/
$config['rewrite_short_tags'] = FALSE;
/*
|--------------------------------------------------------------------------
| Reverse Proxy IPs
|--------------------------------------------------------------------------
|
| If your server is behind a reverse proxy, you must whitelist the proxy
| IP addresses from which CodeIgniter should trust headers such as
| HTTP_X_FORWARDED_FOR and HTTP_CLIENT_IP in order to properly identify
| the visitor's IP address.
|
| You can use both an array or a comma-separated list of proxy addresses,
| as well as specifying whole subnets. Here are a few examples:
|
| Comma-separated: '10.0.1.200,192.168.5.0/24'
| Array: array('10.0.1.200', '192.168.5.0/24')
*/
$config['proxy_ips'] = '';

View File

@@ -0,0 +1,85 @@
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
/*
|--------------------------------------------------------------------------
| Display Debug backtrace
|--------------------------------------------------------------------------
|
| If set to TRUE, a backtrace will be displayed along with php errors. If
| error_reporting is disabled, the backtrace will not display, regardless
| of this setting
|
*/
defined('SHOW_DEBUG_BACKTRACE') OR define('SHOW_DEBUG_BACKTRACE', TRUE);
/*
|--------------------------------------------------------------------------
| File and Directory Modes
|--------------------------------------------------------------------------
|
| These prefs are used when checking and setting modes when working
| with the file system. The defaults are fine on servers with proper
| security, but you may wish (or even need) to change the values in
| certain environments (Apache running a separate process for each
| user, PHP under CGI with Apache suEXEC, etc.). Octal values should
| always be used to set the mode correctly.
|
*/
defined('FILE_READ_MODE') OR define('FILE_READ_MODE', 0644);
defined('FILE_WRITE_MODE') OR define('FILE_WRITE_MODE', 0666);
defined('DIR_READ_MODE') OR define('DIR_READ_MODE', 0755);
defined('DIR_WRITE_MODE') OR define('DIR_WRITE_MODE', 0755);
/*
|--------------------------------------------------------------------------
| File Stream Modes
|--------------------------------------------------------------------------
|
| These modes are used when working with fopen()/popen()
|
*/
defined('FOPEN_READ') OR define('FOPEN_READ', 'rb');
defined('FOPEN_READ_WRITE') OR define('FOPEN_READ_WRITE', 'r+b');
defined('FOPEN_WRITE_CREATE_DESTRUCTIVE') OR define('FOPEN_WRITE_CREATE_DESTRUCTIVE', 'wb'); // truncates existing file data, use with care
defined('FOPEN_READ_WRITE_CREATE_DESTRUCTIVE') OR define('FOPEN_READ_WRITE_CREATE_DESTRUCTIVE', 'w+b'); // truncates existing file data, use with care
defined('FOPEN_WRITE_CREATE') OR define('FOPEN_WRITE_CREATE', 'ab');
defined('FOPEN_READ_WRITE_CREATE') OR define('FOPEN_READ_WRITE_CREATE', 'a+b');
defined('FOPEN_WRITE_CREATE_STRICT') OR define('FOPEN_WRITE_CREATE_STRICT', 'xb');
defined('FOPEN_READ_WRITE_CREATE_STRICT') OR define('FOPEN_READ_WRITE_CREATE_STRICT', 'x+b');
/*
|--------------------------------------------------------------------------
| Exit Status Codes
|--------------------------------------------------------------------------
|
| Used to indicate the conditions under which the script is exit()ing.
| While there is no universal standard for error codes, there are some
| broad conventions. Three such conventions are mentioned below, for
| those who wish to make use of them. The CodeIgniter defaults were
| chosen for the least overlap with these conventions, while still
| leaving room for others to be defined in future versions and user
| applications.
|
| The three main conventions used for determining exit status codes
| are as follows:
|
| Standard C/C++ Library (stdlibc):
| http://www.gnu.org/software/libc/manual/html_node/Exit-Status.html
| (This link also contains other GNU-specific conventions)
| BSD sysexits.h:
| http://www.gsp.com/cgi-bin/man.cgi?section=3&topic=sysexits
| Bash scripting:
| http://tldp.org/LDP/abs/html/exitcodes.html
|
*/
defined('EXIT_SUCCESS') OR define('EXIT_SUCCESS', 0); // no errors
defined('EXIT_ERROR') OR define('EXIT_ERROR', 1); // generic error
defined('EXIT_CONFIG') OR define('EXIT_CONFIG', 3); // configuration error
defined('EXIT_UNKNOWN_FILE') OR define('EXIT_UNKNOWN_FILE', 4); // file not found
defined('EXIT_UNKNOWN_CLASS') OR define('EXIT_UNKNOWN_CLASS', 5); // unknown class
defined('EXIT_UNKNOWN_METHOD') OR define('EXIT_UNKNOWN_METHOD', 6); // unknown class member
defined('EXIT_USER_INPUT') OR define('EXIT_USER_INPUT', 7); // invalid user input
defined('EXIT_DATABASE') OR define('EXIT_DATABASE', 8); // database error
defined('EXIT__AUTO_MIN') OR define('EXIT__AUTO_MIN', 9); // lowest automatically-assigned error code
defined('EXIT__AUTO_MAX') OR define('EXIT__AUTO_MAX', 125); // highest automatically-assigned error code

View File

@@ -0,0 +1,141 @@
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
/*
| -------------------------------------------------------------------
| DATABASE CONNECTIVITY SETTINGS
| -------------------------------------------------------------------
| This file will contain the settings needed to access your database.
|
| For complete instructions please consult the 'Database Connection'
| page of the User Guide.
|
| -------------------------------------------------------------------
| EXPLANATION OF VARIABLES
| -------------------------------------------------------------------
|
| ['dsn'] The full DSN string describe a connection to the database.
| ['hostname'] The hostname of your database server.
| ['username'] The username used to connect to the database
| ['password'] The password used to connect to the database
| ['database'] The name of the database you want to connect to
| ['dbdriver'] The database driver. e.g.: mysqli.
| Currently supported:
| cubrid, ibase, mssql, mysql, mysqli, oci8,
| odbc, pdo, postgre, sqlite, sqlite3, sqlsrv
| ['dbprefix'] You can add an optional prefix, which will be added
| to the table name when using the Query Builder class
| ['pconnect'] TRUE/FALSE - Whether to use a persistent connection
| ['db_debug'] TRUE/FALSE - Whether database errors should be displayed.
| ['cache_on'] TRUE/FALSE - Enables/disables query caching
| ['cachedir'] The path to the folder where cache files should be stored
| ['char_set'] The character set used in communicating with the database
| ['dbcollat'] The character collation used in communicating with the database
| NOTE: For MySQL and MySQLi databases, this setting is only used
| as a backup if your server is running PHP < 5.2.3 or MySQL < 5.0.7
| (and in table creation queries made with DB Forge).
| There is an incompatibility in PHP with mysql_real_escape_string() which
| can make your site vulnerable to SQL injection if you are using a
| multi-byte character set and are running versions lower than these.
| Sites using Latin-1 or UTF-8 database character set and collation are unaffected.
| ['swap_pre'] A default table prefix that should be swapped with the dbprefix
| ['encrypt'] Whether or not to use an encrypted connection.
|
| 'mysql' (deprecated), 'sqlsrv' and 'pdo/sqlsrv' drivers accept TRUE/FALSE
| 'mysqli' and 'pdo/mysql' drivers accept an array with the following options:
|
| 'ssl_key' - Path to the private key file
| 'ssl_cert' - Path to the public key certificate file
| 'ssl_ca' - Path to the certificate authority file
| 'ssl_capath' - Path to a directory containing trusted CA certificates in PEM format
| 'ssl_cipher' - List of *allowed* ciphers to be used for the encryption, separated by colons (':')
| 'ssl_verify' - TRUE/FALSE; Whether verify the server certificate or not ('mysqli' only)
|
| ['compress'] Whether or not to use client compression (MySQL only)
| ['stricton'] TRUE/FALSE - forces 'Strict Mode' connections
| - good for ensuring strict SQL while developing
| ['ssl_options'] Used to set various SSL options that can be used when making SSL connections.
| ['failover'] array - A array with 0 or more data for connections if the main should fail.
| ['save_queries'] TRUE/FALSE - Whether to "save" all executed queries.
| NOTE: Disabling this will also effectively disable both
| $this->db->last_query() and profiling of DB queries.
| When you run a query, with this setting set to TRUE (default),
| CodeIgniter will store the SQL statement for debugging purposes.
| However, this may cause high memory usage, especially if you run
| a lot of SQL queries ... disable this to avoid that problem.
|
| The $active_group variable lets you choose which connection group to
| make active. By default there is only one group (the 'default' group).
|
| The $query_builder variables lets you determine whether or not to load
| the query builder class.
*/
$active_group = 'default';
$query_builder = TRUE;
$db['default'] = array(
'dsn' => '',
'hostname' => 'localhost',
'username' => 'root',
'password' => 'sasone102938',
'database' => 'ibl',
'dbdriver' => 'mysqli',
'dbprefix' => '',
'pconnect' => FALSE,
'db_debug' => FALSE,
'cache_on' => FALSE,
'cachedir' => '',
'char_set' => 'utf8',
'dbcollat' => 'utf8_general_ci',
'swap_pre' => '',
'encrypt' => FALSE,
'compress' => FALSE,
'stricton' => FALSE,
'failover' => array(),
'save_queries' => TRUE
);
$db['regional'] = array(
'dsn' => '',
'hostname' => 'localhost',
'username' => 'root',
'password' => 'sasone102938',
'database' => 'ibl',
'dbdriver' => 'mysqli',
'dbprefix' => '',
'pconnect' => FALSE,
'db_debug' => FALSE,
'cache_on' => FALSE,
'cachedir' => '',
'char_set' => 'utf8',
'dbcollat' => 'utf8_general_ci',
'swap_pre' => '',
'encrypt' => FALSE,
'compress' => FALSE,
'stricton' => FALSE,
'failover' => array(),
'save_queries' => TRUE
);
$db['regional_log'] = array(
'dsn' => '',
'hostname' => 'localhost',
'username' => 'root',
'password' => 'sasone102938',
'database' => 'ibl_log',
'dbdriver' => 'mysqli',
'dbprefix' => '',
'pconnect' => FALSE,
'db_debug' => FALSE,
'cache_on' => FALSE,
'cachedir' => '',
'char_set' => 'utf8',
'dbcollat' => 'utf8_general_ci',
'swap_pre' => '',
'encrypt' => FALSE,
'compress' => FALSE,
'stricton' => FALSE,
'failover' => array(),
'save_queries' => TRUE
);

View File

@@ -0,0 +1,24 @@
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
$_doctypes = array(
'xhtml11' => '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">',
'xhtml1-strict' => '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">',
'xhtml1-trans' => '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">',
'xhtml1-frame' => '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Frameset//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-frameset.dtd">',
'xhtml-basic11' => '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML Basic 1.1//EN" "http://www.w3.org/TR/xhtml-basic/xhtml-basic11.dtd">',
'html5' => '<!DOCTYPE html>',
'html4-strict' => '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">',
'html4-trans' => '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">',
'html4-frame' => '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Frameset//EN" "http://www.w3.org/TR/html4/frameset.dtd">',
'mathml1' => '<!DOCTYPE math SYSTEM "http://www.w3.org/Math/DTD/mathml1/mathml.dtd">',
'mathml2' => '<!DOCTYPE math PUBLIC "-//W3C//DTD MathML 2.0//EN" "http://www.w3.org/Math/DTD/mathml2/mathml2.dtd">',
'svg10' => '<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.0//EN" "http://www.w3.org/TR/2001/REC-SVG-20010904/DTD/svg10.dtd">',
'svg11' => '<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">',
'svg11-basic' => '<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1 Basic//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11-basic.dtd">',
'svg11-tiny' => '<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1 Tiny//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11-tiny.dtd">',
'xhtml-math-svg-xh' => '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1 plus MathML 2.0 plus SVG 1.1//EN" "http://www.w3.org/2002/04/xhtml-math-svg/xhtml-math-svg.dtd">',
'xhtml-math-svg-sh' => '<!DOCTYPE svg:svg PUBLIC "-//W3C//DTD XHTML 1.1 plus MathML 2.0 plus SVG 1.1//EN" "http://www.w3.org/2002/04/xhtml-math-svg/xhtml-math-svg.dtd">',
'xhtml-rdfa-1' => '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML+RDFa 1.0//EN" "http://www.w3.org/MarkUp/DTD/xhtml-rdfa-1.dtd">',
'xhtml-rdfa-2' => '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML+RDFa 1.1//EN" "http://www.w3.org/MarkUp/DTD/xhtml-rdfa-2.dtd">'
);

View File

@@ -0,0 +1,103 @@
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
/*
| -------------------------------------------------------------------
| Foreign Characters
| -------------------------------------------------------------------
| This file contains an array of foreign characters for transliteration
| conversion used by the Text helper
|
*/
$foreign_characters = array(
'/ä|æ|ǽ/' => 'ae',
'/ö|œ/' => 'oe',
'/ü/' => 'ue',
'/Ä/' => 'Ae',
'/Ü/' => 'Ue',
'/Ö/' => 'Oe',
'/À|Á|Â|Ã|Ä|Å|Ǻ|Ā|Ă|Ą|Ǎ|Α|Ά|Ả|Ạ|Ầ|Ẫ|Ẩ|Ậ|Ằ|Ắ|Ẵ|Ẳ|Ặ|А/' => 'A',
'/à|á|â|ã|å|ǻ|ā|ă|ą|ǎ|ª|α|ά|ả|ạ|ầ|ấ|ẫ|ẩ|ậ|ằ|ắ|ẵ|ẳ|ặ|а/' => 'a',
'/Б/' => 'B',
'/б/' => 'b',
'/Ç|Ć|Ĉ|Ċ|Č/' => 'C',
'/ç|ć|ĉ|ċ|č/' => 'c',
'/Д/' => 'D',
'/д/' => 'd',
'/Ð|Ď|Đ|Δ/' => 'Dj',
'/ð|ď|đ|δ/' => 'dj',
'/È|É|Ê|Ë|Ē|Ĕ|Ė|Ę|Ě|Ε|Έ|Ẽ|Ẻ|Ẹ|Ề|Ế|Ễ|Ể|Ệ|Е|Э/' => 'E',
'/è|é|ê|ë|ē|ĕ|ė|ę|ě|έ|ε|ẽ|ẻ|ẹ|ề|ế|ễ|ể|ệ|е|э/' => 'e',
'/Ф/' => 'F',
'/ф/' => 'f',
'/Ĝ|Ğ|Ġ|Ģ|Γ|Г|Ґ/' => 'G',
'/ĝ|ğ|ġ|ģ|γ|г|ґ/' => 'g',
'/Ĥ|Ħ/' => 'H',
'/ĥ|ħ/' => 'h',
'/Ì|Í|Î|Ï|Ĩ|Ī|Ĭ|Ǐ|Į|İ|Η|Ή|Ί|Ι|Ϊ|Ỉ|Ị|И|Ы/' => 'I',
'/ì|í|î|ï|ĩ|ī|ĭ|ǐ|į|ı|η|ή|ί|ι|ϊ|ỉ|ị|и|ы|ї/' => 'i',
'/Ĵ/' => 'J',
'/ĵ/' => 'j',
'/Ķ|Κ|К/' => 'K',
'/ķ|κ|к/' => 'k',
'/Ĺ|Ļ|Ľ|Ŀ|Ł|Λ|Л/' => 'L',
'/ĺ|ļ|ľ|ŀ|ł|λ|л/' => 'l',
'/М/' => 'M',
'/м/' => 'm',
'/Ñ|Ń|Ņ|Ň|Ν|Н/' => 'N',
'/ñ|ń|ņ|ň|ʼn|ν|н/' => 'n',
'/Ò|Ó|Ô|Õ|Ō|Ŏ|Ǒ|Ő|Ơ|Ø|Ǿ|Ο|Ό|Ω|Ώ|Ỏ|Ọ|Ồ|Ố|Ỗ|Ổ|Ộ|Ờ|Ớ|Ỡ|Ở|Ợ|О/' => 'O',
'/ò|ó|ô|õ|ō|ŏ|ǒ|ő|ơ|ø|ǿ|º|ο|ό|ω|ώ|ỏ|ọ|ồ|ố|ỗ|ổ|ộ|ờ|ớ|ỡ|ở|ợ|о/' => 'o',
'/П/' => 'P',
'/п/' => 'p',
'/Ŕ|Ŗ|Ř|Ρ|Р/' => 'R',
'/ŕ|ŗ|ř|ρ|р/' => 'r',
'/Ś|Ŝ|Ş|Ș|Š|Σ|С/' => 'S',
'/ś|ŝ|ş|ș|š|ſ|σ|ς|с/' => 's',
'/Ț|Ţ|Ť|Ŧ|τ|Т/' => 'T',
'/ț|ţ|ť|ŧ|т/' => 't',
'/Þ|þ/' => 'th',
'/Ù|Ú|Û|Ũ|Ū|Ŭ|Ů|Ű|Ų|Ư|Ǔ|Ǖ|Ǘ|Ǚ|Ǜ|Ũ|Ủ|Ụ|Ừ|Ứ|Ữ|Ử|Ự|У/' => 'U',
'/ù|ú|û|ũ|ū|ŭ|ů|ű|ų|ư|ǔ|ǖ|ǘ|ǚ|ǜ|υ|ύ|ϋ|ủ|ụ|ừ|ứ|ữ|ử|ự|у/' => 'u',
'/Ƴ|Ɏ|Ỵ|Ẏ|Ӳ|Ӯ|Ў|Ý|Ÿ|Ŷ|Υ|Ύ|Ϋ|Ỳ|Ỹ|Ỷ|Ỵ|Й/' => 'Y',
'/ẙ|ʏ|ƴ|ɏ|ỵ|ẏ|ӳ|ӯ|ў|ý|ÿ|ŷ|ỳ|ỹ|ỷ|ỵ|й/' => 'y',
'/В/' => 'V',
'/в/' => 'v',
'/Ŵ/' => 'W',
'/ŵ/' => 'w',
'/Ź|Ż|Ž|Ζ|З/' => 'Z',
'/ź|ż|ž|ζ|з/' => 'z',
'/Æ|Ǽ/' => 'AE',
'/ß/' => 'ss',
'/IJ/' => 'IJ',
'/ij/' => 'ij',
'/Œ/' => 'OE',
'/ƒ/' => 'f',
'/ξ/' => 'ks',
'/π/' => 'p',
'/β/' => 'v',
'/μ/' => 'm',
'/ψ/' => 'ps',
'/Ё/' => 'Yo',
'/ё/' => 'yo',
'/Є/' => 'Ye',
'/є/' => 'ye',
'/Ї/' => 'Yi',
'/Ж/' => 'Zh',
'/ж/' => 'zh',
'/Х/' => 'Kh',
'/х/' => 'kh',
'/Ц/' => 'Ts',
'/ц/' => 'ts',
'/Ч/' => 'Ch',
'/ч/' => 'ch',
'/Ш/' => 'Sh',
'/ш/' => 'sh',
'/Щ/' => 'Shch',
'/щ/' => 'shch',
'/Ъ|ъ|Ь|ь/' => '',
'/Ю/' => 'Yu',
'/ю/' => 'yu',
'/Я/' => 'Ya',
'/я/' => 'ya'
);

View File

@@ -0,0 +1,13 @@
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
/*
| -------------------------------------------------------------------------
| Hooks
| -------------------------------------------------------------------------
| This file lets you define "hooks" to extend CI without hacking the core
| files. Please see the user guide for info:
|
| https://codeigniter.com/user_guide/general/hooks.html
|
*/

View File

@@ -0,0 +1,11 @@
<!DOCTYPE html>
<html>
<head>
<title>403 Forbidden</title>
</head>
<body>
<p>Directory access is forbidden.</p>
</body>
</html>

View File

@@ -0,0 +1,19 @@
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
/*
| -------------------------------------------------------------------------
| Memcached settings
| -------------------------------------------------------------------------
| Your Memcached servers can be specified below.
|
| See: https://codeigniter.com/user_guide/libraries/caching.html#memcached
|
*/
$config = array(
'default' => array(
'hostname' => '127.0.0.1',
'port' => '11211',
'weight' => '1',
),
);

View File

@@ -0,0 +1,84 @@
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
/*
|--------------------------------------------------------------------------
| Enable/Disable Migrations
|--------------------------------------------------------------------------
|
| Migrations are disabled by default for security reasons.
| You should enable migrations whenever you intend to do a schema migration
| and disable it back when you're done.
|
*/
$config['migration_enabled'] = FALSE;
/*
|--------------------------------------------------------------------------
| Migration Type
|--------------------------------------------------------------------------
|
| Migration file names may be based on a sequential identifier or on
| a timestamp. Options are:
|
| 'sequential' = Sequential migration naming (001_add_blog.php)
| 'timestamp' = Timestamp migration naming (20121031104401_add_blog.php)
| Use timestamp format YYYYMMDDHHIISS.
|
| Note: If this configuration value is missing the Migration library
| defaults to 'sequential' for backward compatibility with CI2.
|
*/
$config['migration_type'] = 'timestamp';
/*
|--------------------------------------------------------------------------
| Migrations table
|--------------------------------------------------------------------------
|
| This is the name of the table that will store the current migrations state.
| When migrations runs it will store in a database table which migration
| level the system is at. It then compares the migration level in this
| table to the $config['migration_version'] if they are not the same it
| will migrate up. This must be set.
|
*/
$config['migration_table'] = 'migrations';
/*
|--------------------------------------------------------------------------
| Auto Migrate To Latest
|--------------------------------------------------------------------------
|
| If this is set to TRUE when you load the migrations class and have
| $config['migration_enabled'] set to TRUE the system will auto migrate
| to your latest migration (whatever $config['migration_version'] is
| set to). This way you do not have to call migrations anywhere else
| in your code to have the latest migration.
|
*/
$config['migration_auto_latest'] = FALSE;
/*
|--------------------------------------------------------------------------
| Migrations version
|--------------------------------------------------------------------------
|
| This is used to set migration version that the file system should be on.
| If you run $this->migration->current() this is the version that schema will
| be upgraded / downgraded to.
|
*/
$config['migration_version'] = 0;
/*
|--------------------------------------------------------------------------
| Migrations Path
|--------------------------------------------------------------------------
|
| Path to your migrations folder.
| Typically, it will be within your application path.
| Also, writing permission is required within the migrations path.
|
*/
$config['migration_path'] = APPPATH.'migrations/';

View File

@@ -0,0 +1,184 @@
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
/*
| -------------------------------------------------------------------
| MIME TYPES
| -------------------------------------------------------------------
| This file contains an array of mime types. It is used by the
| Upload class to help identify allowed file types.
|
*/
return array(
'hqx' => array('application/mac-binhex40', 'application/mac-binhex', 'application/x-binhex40', 'application/x-mac-binhex40'),
'cpt' => 'application/mac-compactpro',
'csv' => array('text/x-comma-separated-values', 'text/comma-separated-values', 'application/octet-stream', 'application/vnd.ms-excel', 'application/x-csv', 'text/x-csv', 'text/csv', 'application/csv', 'application/excel', 'application/vnd.msexcel', 'text/plain'),
'bin' => array('application/macbinary', 'application/mac-binary', 'application/octet-stream', 'application/x-binary', 'application/x-macbinary'),
'dms' => 'application/octet-stream',
'lha' => 'application/octet-stream',
'lzh' => 'application/octet-stream',
'exe' => array('application/octet-stream', 'application/x-msdownload'),
'class' => 'application/octet-stream',
'psd' => array('application/x-photoshop', 'image/vnd.adobe.photoshop'),
'so' => 'application/octet-stream',
'sea' => 'application/octet-stream',
'dll' => 'application/octet-stream',
'oda' => 'application/oda',
'pdf' => array('application/pdf', 'application/force-download', 'application/x-download', 'binary/octet-stream'),
'ai' => array('application/pdf', 'application/postscript'),
'eps' => 'application/postscript',
'ps' => 'application/postscript',
'smi' => 'application/smil',
'smil' => 'application/smil',
'mif' => 'application/vnd.mif',
'xls' => array('application/vnd.ms-excel', 'application/msexcel', 'application/x-msexcel', 'application/x-ms-excel', 'application/x-excel', 'application/x-dos_ms_excel', 'application/xls', 'application/x-xls', 'application/excel', 'application/download', 'application/vnd.ms-office', 'application/msword'),
'ppt' => array('application/powerpoint', 'application/vnd.ms-powerpoint', 'application/vnd.ms-office', 'application/msword'),
'pptx' => array('application/vnd.openxmlformats-officedocument.presentationml.presentation', 'application/x-zip', 'application/zip'),
'wbxml' => 'application/wbxml',
'wmlc' => 'application/wmlc',
'dcr' => 'application/x-director',
'dir' => 'application/x-director',
'dxr' => 'application/x-director',
'dvi' => 'application/x-dvi',
'gtar' => 'application/x-gtar',
'gz' => 'application/x-gzip',
'gzip' => 'application/x-gzip',
'php' => array('application/x-httpd-php', 'application/php', 'application/x-php', 'text/php', 'text/x-php', 'application/x-httpd-php-source'),
'php4' => 'application/x-httpd-php',
'php3' => 'application/x-httpd-php',
'phtml' => 'application/x-httpd-php',
'phps' => 'application/x-httpd-php-source',
'js' => array('application/x-javascript', 'text/plain'),
'swf' => 'application/x-shockwave-flash',
'sit' => 'application/x-stuffit',
'tar' => 'application/x-tar',
'tgz' => array('application/x-tar', 'application/x-gzip-compressed'),
'z' => 'application/x-compress',
'xhtml' => 'application/xhtml+xml',
'xht' => 'application/xhtml+xml',
'zip' => array('application/x-zip', 'application/zip', 'application/x-zip-compressed', 'application/s-compressed', 'multipart/x-zip'),
'rar' => array('application/x-rar', 'application/rar', 'application/x-rar-compressed'),
'mid' => 'audio/midi',
'midi' => 'audio/midi',
'mpga' => 'audio/mpeg',
'mp2' => 'audio/mpeg',
'mp3' => array('audio/mpeg', 'audio/mpg', 'audio/mpeg3', 'audio/mp3'),
'aif' => array('audio/x-aiff', 'audio/aiff'),
'aiff' => array('audio/x-aiff', 'audio/aiff'),
'aifc' => 'audio/x-aiff',
'ram' => 'audio/x-pn-realaudio',
'rm' => 'audio/x-pn-realaudio',
'rpm' => 'audio/x-pn-realaudio-plugin',
'ra' => 'audio/x-realaudio',
'rv' => 'video/vnd.rn-realvideo',
'wav' => array('audio/x-wav', 'audio/wave', 'audio/wav'),
'bmp' => array('image/bmp', 'image/x-bmp', 'image/x-bitmap', 'image/x-xbitmap', 'image/x-win-bitmap', 'image/x-windows-bmp', 'image/ms-bmp', 'image/x-ms-bmp', 'application/bmp', 'application/x-bmp', 'application/x-win-bitmap'),
'gif' => 'image/gif',
'jpeg' => array('image/jpeg', 'image/pjpeg'),
'jpg' => array('image/jpeg', 'image/pjpeg'),
'jpe' => array('image/jpeg', 'image/pjpeg'),
'jp2' => array('image/jp2', 'video/mj2', 'image/jpx', 'image/jpm'),
'j2k' => array('image/jp2', 'video/mj2', 'image/jpx', 'image/jpm'),
'jpf' => array('image/jp2', 'video/mj2', 'image/jpx', 'image/jpm'),
'jpg2' => array('image/jp2', 'video/mj2', 'image/jpx', 'image/jpm'),
'jpx' => array('image/jp2', 'video/mj2', 'image/jpx', 'image/jpm'),
'jpm' => array('image/jp2', 'video/mj2', 'image/jpx', 'image/jpm'),
'mj2' => array('image/jp2', 'video/mj2', 'image/jpx', 'image/jpm'),
'mjp2' => array('image/jp2', 'video/mj2', 'image/jpx', 'image/jpm'),
'png' => array('image/png', 'image/x-png'),
'tiff' => 'image/tiff',
'tif' => 'image/tiff',
'css' => array('text/css', 'text/plain'),
'html' => array('text/html', 'text/plain'),
'htm' => array('text/html', 'text/plain'),
'shtml' => array('text/html', 'text/plain'),
'txt' => 'text/plain',
'text' => 'text/plain',
'log' => array('text/plain', 'text/x-log'),
'rtx' => 'text/richtext',
'rtf' => 'text/rtf',
'xml' => array('application/xml', 'text/xml', 'text/plain'),
'xsl' => array('application/xml', 'text/xsl', 'text/xml'),
'mpeg' => 'video/mpeg',
'mpg' => 'video/mpeg',
'mpe' => 'video/mpeg',
'qt' => 'video/quicktime',
'mov' => 'video/quicktime',
'avi' => array('video/x-msvideo', 'video/msvideo', 'video/avi', 'application/x-troff-msvideo'),
'movie' => 'video/x-sgi-movie',
'doc' => array('application/msword', 'application/vnd.ms-office'),
'docx' => array('application/vnd.openxmlformats-officedocument.wordprocessingml.document', 'application/zip', 'application/msword', 'application/x-zip'),
'dot' => array('application/msword', 'application/vnd.ms-office'),
'dotx' => array('application/vnd.openxmlformats-officedocument.wordprocessingml.document', 'application/zip', 'application/msword'),
'xlsx' => array('application/vnd.openxmlformats-officedocument.spreadsheetml.sheet', 'application/zip', 'application/vnd.ms-excel', 'application/msword', 'application/x-zip'),
'word' => array('application/msword', 'application/octet-stream'),
'xl' => 'application/excel',
'eml' => 'message/rfc822',
'json' => array('application/json', 'text/json'),
'pem' => array('application/x-x509-user-cert', 'application/x-pem-file', 'application/octet-stream'),
'p10' => array('application/x-pkcs10', 'application/pkcs10'),
'p12' => 'application/x-pkcs12',
'p7a' => 'application/x-pkcs7-signature',
'p7c' => array('application/pkcs7-mime', 'application/x-pkcs7-mime'),
'p7m' => array('application/pkcs7-mime', 'application/x-pkcs7-mime'),
'p7r' => 'application/x-pkcs7-certreqresp',
'p7s' => 'application/pkcs7-signature',
'crt' => array('application/x-x509-ca-cert', 'application/x-x509-user-cert', 'application/pkix-cert'),
'crl' => array('application/pkix-crl', 'application/pkcs-crl'),
'der' => 'application/x-x509-ca-cert',
'kdb' => 'application/octet-stream',
'pgp' => 'application/pgp',
'gpg' => 'application/gpg-keys',
'sst' => 'application/octet-stream',
'csr' => 'application/octet-stream',
'rsa' => 'application/x-pkcs7',
'cer' => array('application/pkix-cert', 'application/x-x509-ca-cert'),
'3g2' => 'video/3gpp2',
'3gp' => array('video/3gp', 'video/3gpp'),
'mp4' => 'video/mp4',
'm4a' => 'audio/x-m4a',
'f4v' => array('video/mp4', 'video/x-f4v'),
'flv' => 'video/x-flv',
'webm' => 'video/webm',
'aac' => 'audio/x-acc',
'm4u' => 'application/vnd.mpegurl',
'm3u' => 'text/plain',
'xspf' => 'application/xspf+xml',
'vlc' => 'application/videolan',
'wmv' => array('video/x-ms-wmv', 'video/x-ms-asf'),
'au' => 'audio/x-au',
'ac3' => 'audio/ac3',
'flac' => 'audio/x-flac',
'ogg' => array('audio/ogg', 'video/ogg', 'application/ogg'),
'kmz' => array('application/vnd.google-earth.kmz', 'application/zip', 'application/x-zip'),
'kml' => array('application/vnd.google-earth.kml+xml', 'application/xml', 'text/xml'),
'ics' => 'text/calendar',
'ical' => 'text/calendar',
'zsh' => 'text/x-scriptzsh',
'7z' => array('application/x-7z-compressed', 'application/x-compressed', 'application/x-zip-compressed', 'application/zip', 'multipart/x-zip'),
'7zip' => array('application/x-7z-compressed', 'application/x-compressed', 'application/x-zip-compressed', 'application/zip', 'multipart/x-zip'),
'cdr' => array('application/cdr', 'application/coreldraw', 'application/x-cdr', 'application/x-coreldraw', 'image/cdr', 'image/x-cdr', 'zz-application/zz-winassoc-cdr'),
'wma' => array('audio/x-ms-wma', 'video/x-ms-asf'),
'jar' => array('application/java-archive', 'application/x-java-application', 'application/x-jar', 'application/x-compressed'),
'svg' => array('image/svg+xml', 'application/xml', 'text/xml'),
'vcf' => 'text/x-vcard',
'srt' => array('text/srt', 'text/plain'),
'vtt' => array('text/vtt', 'text/plain'),
'ico' => array('image/x-icon', 'image/x-ico', 'image/vnd.microsoft.icon'),
'odc' => 'application/vnd.oasis.opendocument.chart',
'otc' => 'application/vnd.oasis.opendocument.chart-template',
'odf' => 'application/vnd.oasis.opendocument.formula',
'otf' => 'application/vnd.oasis.opendocument.formula-template',
'odg' => 'application/vnd.oasis.opendocument.graphics',
'otg' => 'application/vnd.oasis.opendocument.graphics-template',
'odi' => 'application/vnd.oasis.opendocument.image',
'oti' => 'application/vnd.oasis.opendocument.image-template',
'odp' => 'application/vnd.oasis.opendocument.presentation',
'otp' => 'application/vnd.oasis.opendocument.presentation-template',
'ods' => 'application/vnd.oasis.opendocument.spreadsheet',
'ots' => 'application/vnd.oasis.opendocument.spreadsheet-template',
'odt' => 'application/vnd.oasis.opendocument.text',
'odm' => 'application/vnd.oasis.opendocument.text-master',
'ott' => 'application/vnd.oasis.opendocument.text-template',
'oth' => 'application/vnd.oasis.opendocument.text-web'
);

View File

@@ -0,0 +1,14 @@
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
/*
| -------------------------------------------------------------------------
| Profiler Sections
| -------------------------------------------------------------------------
| This file lets you determine whether or not various sections of Profiler
| data are displayed when the Profiler is enabled.
| Please see the user guide for info:
|
| https://codeigniter.com/user_guide/general/profiling.html
|
*/

View File

@@ -0,0 +1,54 @@
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
/*
| -------------------------------------------------------------------------
| URI ROUTING
| -------------------------------------------------------------------------
| This file lets you re-map URI requests to specific controller functions.
|
| Typically there is a one-to-one relationship between a URL string
| and its corresponding controller class/method. The segments in a
| URL normally follow this pattern:
|
| example.com/class/method/id/
|
| In some instances, however, you may want to remap this relationship
| so that a different class/function is called than the one
| corresponding to the URL.
|
| Please see the user guide for complete details:
|
| https://codeigniter.com/user_guide/general/routing.html
|
| -------------------------------------------------------------------------
| RESERVED ROUTES
| -------------------------------------------------------------------------
|
| There are three reserved routes:
|
| $route['default_controller'] = 'welcome';
|
| This route indicates which controller class should be loaded if the
| URI contains no data. In the above example, the "welcome" class
| would be loaded.
|
| $route['404_override'] = 'errors/page_missing';
|
| This route will tell the Router which controller/method to use if those
| provided in the URL cannot be matched to a valid route.
|
| $route['translate_uri_dashes'] = FALSE;
|
| This is not exactly a route, but allows you to automatically route
| controller and method names that contain dashes. '-' isn't a valid
| class or method name character, so it requires translation.
| When you set this option to TRUE, it will replace ALL dashes in the
| controller and method URI segments.
|
| Examples: my-controller/index -> my_controller/index
| my-controller/my-method -> my_controller/my_method
*/
$route['default_controller'] = 'welcome';
$route['404_override'] = '';
$route['translate_uri_dashes'] = FALSE;

View File

@@ -0,0 +1,64 @@
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
/*
| -------------------------------------------------------------------
| SMILEYS
| -------------------------------------------------------------------
| This file contains an array of smileys for use with the emoticon helper.
| Individual images can be used to replace multiple smileys. For example:
| :-) and :) use the same image replacement.
|
| Please see user guide for more info:
| https://codeigniter.com/user_guide/helpers/smiley_helper.html
|
*/
$smileys = array(
// smiley image name width height alt
':-)' => array('grin.gif', '19', '19', 'grin'),
':lol:' => array('lol.gif', '19', '19', 'LOL'),
':cheese:' => array('cheese.gif', '19', '19', 'cheese'),
':)' => array('smile.gif', '19', '19', 'smile'),
';-)' => array('wink.gif', '19', '19', 'wink'),
';)' => array('wink.gif', '19', '19', 'wink'),
':smirk:' => array('smirk.gif', '19', '19', 'smirk'),
':roll:' => array('rolleyes.gif', '19', '19', 'rolleyes'),
':-S' => array('confused.gif', '19', '19', 'confused'),
':wow:' => array('surprise.gif', '19', '19', 'surprised'),
':bug:' => array('bigsurprise.gif', '19', '19', 'big surprise'),
':-P' => array('tongue_laugh.gif', '19', '19', 'tongue laugh'),
'%-P' => array('tongue_rolleye.gif', '19', '19', 'tongue rolleye'),
';-P' => array('tongue_wink.gif', '19', '19', 'tongue wink'),
':P' => array('raspberry.gif', '19', '19', 'raspberry'),
':blank:' => array('blank.gif', '19', '19', 'blank stare'),
':long:' => array('longface.gif', '19', '19', 'long face'),
':ohh:' => array('ohh.gif', '19', '19', 'ohh'),
':grrr:' => array('grrr.gif', '19', '19', 'grrr'),
':gulp:' => array('gulp.gif', '19', '19', 'gulp'),
'8-/' => array('ohoh.gif', '19', '19', 'oh oh'),
':down:' => array('downer.gif', '19', '19', 'downer'),
':red:' => array('embarrassed.gif', '19', '19', 'red face'),
':sick:' => array('sick.gif', '19', '19', 'sick'),
':shut:' => array('shuteye.gif', '19', '19', 'shut eye'),
':-/' => array('hmm.gif', '19', '19', 'hmmm'),
'>:(' => array('mad.gif', '19', '19', 'mad'),
':mad:' => array('mad.gif', '19', '19', 'mad'),
'>:-(' => array('angry.gif', '19', '19', 'angry'),
':angry:' => array('angry.gif', '19', '19', 'angry'),
':zip:' => array('zip.gif', '19', '19', 'zipper'),
':kiss:' => array('kiss.gif', '19', '19', 'kiss'),
':ahhh:' => array('shock.gif', '19', '19', 'shock'),
':coolsmile:' => array('shade_smile.gif', '19', '19', 'cool smile'),
':coolsmirk:' => array('shade_smirk.gif', '19', '19', 'cool smirk'),
':coolgrin:' => array('shade_grin.gif', '19', '19', 'cool grin'),
':coolhmm:' => array('shade_hmm.gif', '19', '19', 'cool hmm'),
':coolmad:' => array('shade_mad.gif', '19', '19', 'cool mad'),
':coolcheese:' => array('shade_cheese.gif', '19', '19', 'cool cheese'),
':vampire:' => array('vampire.gif', '19', '19', 'vampire'),
':snake:' => array('snake.gif', '19', '19', 'snake'),
':exclaim:' => array('exclaim.gif', '19', '19', 'exclaim'),
':question:' => array('question.gif', '19', '19', 'question')
);

View File

@@ -0,0 +1,214 @@
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
/*
| -------------------------------------------------------------------
| USER AGENT TYPES
| -------------------------------------------------------------------
| This file contains four arrays of user agent data. It is used by the
| User Agent Class to help identify browser, platform, robot, and
| mobile device data. The array keys are used to identify the device
| and the array values are used to set the actual name of the item.
*/
$platforms = array(
'windows nt 10.0' => 'Windows 10',
'windows nt 6.3' => 'Windows 8.1',
'windows nt 6.2' => 'Windows 8',
'windows nt 6.1' => 'Windows 7',
'windows nt 6.0' => 'Windows Vista',
'windows nt 5.2' => 'Windows 2003',
'windows nt 5.1' => 'Windows XP',
'windows nt 5.0' => 'Windows 2000',
'windows nt 4.0' => 'Windows NT 4.0',
'winnt4.0' => 'Windows NT 4.0',
'winnt 4.0' => 'Windows NT',
'winnt' => 'Windows NT',
'windows 98' => 'Windows 98',
'win98' => 'Windows 98',
'windows 95' => 'Windows 95',
'win95' => 'Windows 95',
'windows phone' => 'Windows Phone',
'windows' => 'Unknown Windows OS',
'android' => 'Android',
'blackberry' => 'BlackBerry',
'iphone' => 'iOS',
'ipad' => 'iOS',
'ipod' => 'iOS',
'os x' => 'Mac OS X',
'ppc mac' => 'Power PC Mac',
'freebsd' => 'FreeBSD',
'ppc' => 'Macintosh',
'linux' => 'Linux',
'debian' => 'Debian',
'sunos' => 'Sun Solaris',
'beos' => 'BeOS',
'apachebench' => 'ApacheBench',
'aix' => 'AIX',
'irix' => 'Irix',
'osf' => 'DEC OSF',
'hp-ux' => 'HP-UX',
'netbsd' => 'NetBSD',
'bsdi' => 'BSDi',
'openbsd' => 'OpenBSD',
'gnu' => 'GNU/Linux',
'unix' => 'Unknown Unix OS',
'symbian' => 'Symbian OS'
);
// The order of this array should NOT be changed. Many browsers return
// multiple browser types so we want to identify the sub-type first.
$browsers = array(
'OPR' => 'Opera',
'Flock' => 'Flock',
'Edge' => 'Edge',
'Chrome' => 'Chrome',
// Opera 10+ always reports Opera/9.80 and appends Version/<real version> to the user agent string
'Opera.*?Version' => 'Opera',
'Opera' => 'Opera',
'MSIE' => 'Internet Explorer',
'Internet Explorer' => 'Internet Explorer',
'Trident.* rv' => 'Internet Explorer',
'Shiira' => 'Shiira',
'Firefox' => 'Firefox',
'Chimera' => 'Chimera',
'Phoenix' => 'Phoenix',
'Firebird' => 'Firebird',
'Camino' => 'Camino',
'Netscape' => 'Netscape',
'OmniWeb' => 'OmniWeb',
'Safari' => 'Safari',
'Mozilla' => 'Mozilla',
'Konqueror' => 'Konqueror',
'icab' => 'iCab',
'Lynx' => 'Lynx',
'Links' => 'Links',
'hotjava' => 'HotJava',
'amaya' => 'Amaya',
'IBrowse' => 'IBrowse',
'Maxthon' => 'Maxthon',
'Ubuntu' => 'Ubuntu Web Browser'
);
$mobiles = array(
// legacy array, old values commented out
'mobileexplorer' => 'Mobile Explorer',
// 'openwave' => 'Open Wave',
// 'opera mini' => 'Opera Mini',
// 'operamini' => 'Opera Mini',
// 'elaine' => 'Palm',
'palmsource' => 'Palm',
// 'digital paths' => 'Palm',
// 'avantgo' => 'Avantgo',
// 'xiino' => 'Xiino',
'palmscape' => 'Palmscape',
// 'nokia' => 'Nokia',
// 'ericsson' => 'Ericsson',
// 'blackberry' => 'BlackBerry',
// 'motorola' => 'Motorola'
// Phones and Manufacturers
'motorola' => 'Motorola',
'nokia' => 'Nokia',
'palm' => 'Palm',
'iphone' => 'Apple iPhone',
'ipad' => 'iPad',
'ipod' => 'Apple iPod Touch',
'sony' => 'Sony Ericsson',
'ericsson' => 'Sony Ericsson',
'blackberry' => 'BlackBerry',
'cocoon' => 'O2 Cocoon',
'blazer' => 'Treo',
'lg' => 'LG',
'amoi' => 'Amoi',
'xda' => 'XDA',
'mda' => 'MDA',
'vario' => 'Vario',
'htc' => 'HTC',
'samsung' => 'Samsung',
'sharp' => 'Sharp',
'sie-' => 'Siemens',
'alcatel' => 'Alcatel',
'benq' => 'BenQ',
'ipaq' => 'HP iPaq',
'mot-' => 'Motorola',
'playstation portable' => 'PlayStation Portable',
'playstation 3' => 'PlayStation 3',
'playstation vita' => 'PlayStation Vita',
'hiptop' => 'Danger Hiptop',
'nec-' => 'NEC',
'panasonic' => 'Panasonic',
'philips' => 'Philips',
'sagem' => 'Sagem',
'sanyo' => 'Sanyo',
'spv' => 'SPV',
'zte' => 'ZTE',
'sendo' => 'Sendo',
'nintendo dsi' => 'Nintendo DSi',
'nintendo ds' => 'Nintendo DS',
'nintendo 3ds' => 'Nintendo 3DS',
'wii' => 'Nintendo Wii',
'open web' => 'Open Web',
'openweb' => 'OpenWeb',
// Operating Systems
'android' => 'Android',
'symbian' => 'Symbian',
'SymbianOS' => 'SymbianOS',
'elaine' => 'Palm',
'series60' => 'Symbian S60',
'windows ce' => 'Windows CE',
// Browsers
'obigo' => 'Obigo',
'netfront' => 'Netfront Browser',
'openwave' => 'Openwave Browser',
'mobilexplorer' => 'Mobile Explorer',
'operamini' => 'Opera Mini',
'opera mini' => 'Opera Mini',
'opera mobi' => 'Opera Mobile',
'fennec' => 'Firefox Mobile',
// Other
'digital paths' => 'Digital Paths',
'avantgo' => 'AvantGo',
'xiino' => 'Xiino',
'novarra' => 'Novarra Transcoder',
'vodafone' => 'Vodafone',
'docomo' => 'NTT DoCoMo',
'o2' => 'O2',
// Fallback
'mobile' => 'Generic Mobile',
'wireless' => 'Generic Mobile',
'j2me' => 'Generic Mobile',
'midp' => 'Generic Mobile',
'cldc' => 'Generic Mobile',
'up.link' => 'Generic Mobile',
'up.browser' => 'Generic Mobile',
'smartphone' => 'Generic Mobile',
'cellphone' => 'Generic Mobile'
);
// There are hundreds of bots but these are the most common.
$robots = array(
'googlebot' => 'Googlebot',
'msnbot' => 'MSNBot',
'baiduspider' => 'Baiduspider',
'bingbot' => 'Bing',
'slurp' => 'Inktomi Slurp',
'yahoo' => 'Yahoo',
'ask jeeves' => 'Ask Jeeves',
'fastcrawler' => 'FastCrawler',
'infoseek' => 'InfoSeek Robot 1.0',
'lycos' => 'Lycos',
'yandex' => 'YandexBot',
'mediapartners-google' => 'MediaPartners Google',
'CRAZYWEBCRAWLER' => 'Crazy Webcrawler',
'adsbot-google' => 'AdsBot Google',
'feedfetcher-google' => 'Feedfetcher Google',
'curious george' => 'Curious George',
'ia_archiver' => 'Alexa Crawler',
'MJ12bot' => 'Majestic-12',
'Uptimebot' => 'Uptimebot'
);

View File

@@ -0,0 +1,479 @@
<?php
class Station extends MY_Controller
{
var $db_onedev;
public function index()
{
echo "STATION API";
}
public function __construct()
{
parent::__construct();
$this->db_onedev = $this->load->database("onedev", true);
}
function lookupbahan(){
try {
//# cek token valid
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$prm = $this->sys_input;
$id = $prm['id'];
$sql = "select T_BahanID as id,
T_BahanT_SampleStationID as usergroupid,
T_BahanCode as code,
T_BahanName As name,
'xxx' as action
from t_bahan
join t_samplestation oN T_BahanT_SampleStationID = T_SampleStationID
where
T_BahanT_SampleStationID = {$id} AND T_BahanIsActive = 'Y'";
//echo $sql;
$rows = $this->db_onedev->query($sql)->result();
$result = array ("total" => count($rows), "records" => $rows);
$this->sys_ok($result);
} catch(Exception $exc) {
$message = $exc->getMessage();
$this->sys_error($message);
}
}
public function lookup()
{
try {
//# cek token valid
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$prm = $this->sys_input;
$search = $prm['search'];
$all = $prm['all'];
$limit = '';
if($all == 'N'){
$limit = ' LIMIT 10';
}
$sql = "select COUNT(*) as total
from t_samplestation
where
T_SampleStationIsActive = 'Y'";
$sql_param = array($search);
$total = $this->db_onedev->query($sql,$sql_param)->row()->total;
$sql = "select T_SampleStationID as id,
T_SampleStationCode as code,
T_SampleStationName as name,
T_SampleStationIsNonLab as isnonlab, T_SampleStationName as description , 'xxx' as usergrouptype
from t_samplestation
where
T_SampleStationName LIKE CONCAT('%','{$search}','%') AND
T_SampleStationIsActive = 'Y' $limit";
$sql_param = array($search);
$query = $this->db_onedev->query($sql);
//echo $this->db_onedev->last_query();
if ($query) {
$rows = $query->result_array();
} else {
$this->sys_error_db("t_samplestation select",$this->db_onedev);
exit;
}
$result = array ("total" => $total, "total_filter"=>count($rows),"records" => $rows);
$this->sys_ok($result);
} catch(Exception $exc) {
$message = $exc->getMessage();
$this->sys_error($message);
}
}
public function addnewstation()
{
try {
//# cek token valid
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
//# ambil parameter input
$prm = $this->sys_input;
$name_station = $prm['name'];
$code_station = $prm['code'];
$isnonlab_station = $prm['isnonlab'];
$query = "SELECT COUNT(*) as exist FROM t_samplestation WHERE T_SampleStationIsActive = 'Y' AND T_SampleStationName = '{$name_station}'";
$exist_name = $this->db_onedev->query($query)->row()->exist;
//echo $exist_name;
if($exist_name == 0 ){
$sql = "insert into t_samplestation(
T_SampleStationCode,
T_SampleStationName,
T_SampleStationIsNonLab,
T_SampleStationCreated,
T_SampleStationLastUpdated
)
values( ?, ?, ?,now(), now())";
$query = $this->db_onedev->query($sql,
array(
$name_station,
$code_station,
$isnonlab_station
)
);
//echo $query;
if (!$query) {
$this->sys_error_db("t_samplestation insert");
exit;
}
$result = array ("total" => 1, "records" => array("xid" => 0));
$this->sys_ok($result);
} else{
$errors = array();
if($exist_name != 0){
array_push($errors,array('field'=>'name','msg'=>'Nama sudah ada '));
}
$result = array ("total" => -1,"errors" => $errors, "records" => 0);
$this->sys_ok($result);
}
} catch(Exception $exc) {
$message = $exc->getMessage();
$this->sys_error($message);
}
}
public function editstation()
{
try {
//# cek token valid
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
//# ambil parameter input
$prm = $this->sys_input;
$id_station = $prm['id'];
$code_station = $prm['code'];
$name_station = $prm['name'];
$isnonlab_station = $prm['isnonlab'];
$query = "SELECT COUNT(*) as exist FROM t_samplestation WHERE T_SampleStationIsActive = 'Y' AND T_SampleStationName = '{$name_station}'
AND T_SampleStationID <> {$id_station} ";
$exist_name = $this->db_onedev->query($query)->row()->exist;
if($exist_name == 0){
$sql = "update t_samplestation SET
T_SampleStationCode = ?,
T_SampleStationName = ?,
T_SampleStationIsNonLab = ?,
T_SampleStationLastUpdated = now()
where
T_SampleStationID = ?
";
$query = $this->db_onedev->query($sql,
array(
$code_station,
$name_station,
$isnonlab_station,
$id_station
)
);
//file_put_contents("/tmp/adi-update-user.sql",$this->db_onedev->last_query());
//echo $query;
if (!$query) {
$this->sys_error_db("t_samplestation update");
exit;
}
$result = array ("total" => 1, "records" => array("xid" => $id_station));
$this->sys_ok($result);
}else{
$errors = array();
if($exist_name != 0){
array_push($errors,array('field'=>'name','msg'=>'Nama sudah ada'));
}
$result = array ("total" => -1,"errors" => $errors, "records" => 0);
$this->sys_ok($result);
}
} catch(Exception $exc) {
$message = $exc->getMessage();
$this->sys_error($message);
}
}
public function editbahan()
{
try {
//# cek token valid
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
//# ambil parameter input
$prm = $this->sys_input;
$bahanid = $prm['xid'];
$code = $prm['code'];
$name = $prm['name'];
$xstationname = $prm['xstationname'];
$query = "SELECT COUNT(*) as exist FROM t_bahan WHERE T_BahanIsActive = 'Y' AND T_BahanName = '{$name}'
and T_BahanID <> $bahanid ";
$exist_name = $this->db_onedev->query($query)->row()->exist;
if($exist_name == 0){
$sql = "update m_user SET
T_BahanCode = ?,
T_BahanName = ?,
T_BahanT_SampleStationID = ?,
T_BahanLastUpdated = now()
where T_BahanID = ? ";
$query = $this->db_onedev->query($sql,
array(
$code,
$name,
$xstationname["T_SampleStationID"],
$bahanid
));
if (!$query) {
$this->sys_error_db("t_bahan update",$this->db_onedev);
exit;
}
$result = array ("total" => 1, "records" => array("xid" => $bahanid));
$this->sys_ok($result);
} else {
$errors = array();
if($exist_name != 0){
array_push($errors,array('field'=>'name','msg'=>'Nama sudah ada yang pakai dong'));
}
$result = array ("total" => -1,"errors" => $errors, "records" => 0);
$this->sys_ok($result);
}
} catch(Exception $exc) {
$message = $exc->getMessage();
$this->sys_error($message);
}
}
public function addnewbahan()
{
try {
//# cek token valid
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
//# ambil parameter input
$prm = $this->sys_input;
$stationid = $prm['stationid'];
$code = $prm['code'];
$name = $prm['name'];
if($prm['xid'] == 0){
$query = "SELECT COUNT(*) as exist FROM t_bahan WHERE T_BahanIsActive = 'Y' AND T_BahanName = '{$name}'";
$exist_name = $this->db_onedev->query($query)->row()->exist;
if($exist_name == 0){
$sql = "insert into t_bahan(
T_BahanT_SampleStationID,
T_BahanCode,
T_BahanName,
T_BahanCreated,
T_BahanLastUpdated
)
values( ?,?,?,now(),now())";
$query = $this->db_onedev->query($sql,
array(
$stationid,
$code,
$name
)
);
if (!$query) {
$this->sys_error_db("t_bahan insert",$this->db_onedev);
exit;
}
$result = array ("total" => 1, "records" => array("xid" => 0));
$this->sys_ok($result);
}else{
$errors = array();
if($exist_name != 0){
array_push($errors,array('field'=>'name','msg'=>'Nama sudah ada yang pakai dong'));
}
$result = array ("total" => -1,"errors" => $errors, "records" => 0);
$this->sys_ok($result);
}
}else{
$query = "SELECT COUNT(*) as exist FROM t_bahan WHERE T_BahanIsActive = 'Y' AND T_BahanName = '{$name}' AND T_BahanID <> {$prm['xid']}";
$exist_name = $this->db_onedev->query($query)->row()->exist;
//echo $query;
//echo $query;
if($exist_name == 0 ){
$sql = "UPDATE t_bahan SET T_BahanName = '{$name}', T_BahanCode = '{$code}' WHERE T_BahanID = '{$prm['xid']}'";
//echo $sql;
$query = $this->db_onedev->query($sql);
$result = array ("total" => 1, "records" => array("xid" => 0));
$this->sys_ok($result);
}else{
$errors = array();
if($exist_name != 0){
array_push($errors,array('field'=>'name','msg'=>'name sudah ada yang pakai dong'));
}
$result = array ("total" => -1,"errors" => $errors, "records" => 0);
$this->sys_ok($result);
}
}
} catch(Exception $exc) {
$message = $exc->getMessage();
$this->sys_error($message);
}
}
public function deletebahan()
{
try {
//# cek token valid
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
//# ambil parameter input
$prm = $this->sys_input;
$sql = "update t_bahan SET
T_BahanIsActive = 'N',
T_BahanLastUpdated = now()
WHERE
T_BahanID = ?
";
$query = $this->db_onedev->query($sql,
array(
$prm['id']
)
);
// echo $query;
if (!$query) {
$this->sys_error_db("t_bahan delete");
exit;
}
$result = array ("total" => 1, "records" => array("xid" => 0));
$this->sys_ok($result);
} catch(Exception $exc) {
$message = $exc->getMessage();
$this->sys_error($message);
}
}
public function deleteselect()
{
try {
//# cek token valid
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
//# ambil parameter input
$prm = $this->sys_input;
$sql = "update t_samplestation SET
T_SampleStationIsActive = 'N',
T_SampleStationLastUpdated = now()
WHERE
T_SampleStationID = ?
";
$query = $this->db_onedev->query($sql,
array(
$prm['id']
)
);
// echo $query;
if (!$query) {
$this->sys_error_db("t_samplestation delete");
exit;
}
$sql = "UPDATE m_user SET
M_UserIsActive = 'N',
M_UserLastUpdated = now()
WHERE
M_UserM_UserGroupID = ?
";
$query = $this->db_onedev->query($sql,
array(
$prm['id']
)
);
// echo $query;
if (!$query) {
$this->sys_error_db("m_user delete");
exit;
}
$result = array ("total" => 1, "records" => array("xid" => 0));
$this->sys_ok($result);
} catch(Exception $exc) {
$message = $exc->getMessage();
$this->sys_error($message);
}
}
}

View File

@@ -0,0 +1,25 @@
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class Welcome extends CI_Controller {
/**
* Index Page for this controller.
*
* Maps to the following URL
* http://example.com/index.php/welcome
* - or -
* http://example.com/index.php/welcome/index
* - or -
* Since this controller is set as the default controller in
* config/routes.php, it's displayed at http://example.com/
*
* So any other public methods not prefixed with an underscore will
* map to /index.php/welcome/<method_name>
* @see https://codeigniter.com/user_guide/general/urls.html
*/
public function index()
{
echo(".:: -- ::.");
}
}

View File

@@ -0,0 +1,88 @@
<?php
class Confirmorder extends MY_Controller
{
var $max_limit = 20;
public function __construct()
{
parent::__construct();
// db wilayah contoh surabaya
$this->db_regional = $this->load->database("regional", true);
// string database
$this->db_str_doctor = 'one_doctor';
}
public function index()
{
echo "CONFIRM ORDER API";
}
function get_param_z()
{
$body_z = file_get_contents("php://input");
$body = gzuncompress($body_z);
return json_decode($body, true);
}
function reply($resp)
{
echo json_encode($resp);
}
function reply_gz($resp)
{
//echo json_encode($resp);
echo gzcompress(json_encode($resp));
}
public function get_confirm_order($M_BranchCode)
{
$sql_get_confirm_order = "select
oneResultOrderPatientID
from $this->db_str_doctor.one_result
where oneResultDate < DATE_SUB(NOW(), INTERVAL 5 DAY)
AND oneResultOrderM_BranchCode <> ?";
// echo $sql_get_confirm_order;
$query_confirm_order = $this->db_regional->query($sql_get_confirm_order,[
$M_BranchCode
]);
if(!$query_confirm_order){
$this->db->trans_rollback();
$this->sys_error_db(["status" => "ERR", "message" => "select query_confirm_order one_result | " .
$this->db->error()["message"], "debug" => $this->db_regional->last_query()]);
exit;
}
$oneResultOrderPatientID_array = [];
$rows_query_confirm_order = $query_confirm_order->result_array();
if(count($rows_query_confirm_order) == 0){
echo json_encode(
[
"status" => "OK",
"message" => "Data Tidak Ditemukan",
"oneResultOrderPatientID" => $oneResultOrderPatientID_array,
]
);
}else{
foreach($rows_query_confirm_order as $key => $val)
{
$oneResultOrderPatientID_array[] = intval($val['oneResultOrderPatientID']);
}
echo json_encode(
[
"status" => "OK",
"message" => "Data Ditemukan",
"oneResultOrderPatientID" => $oneResultOrderPatientID_array,
]
);
}
}
}

View File

@@ -0,0 +1,318 @@
<?php
class DownloadOrderPatient extends MY_Controller
{
var $db;
function __construct()
{
parent::__construct();
}
function index()
{
echo "Api: Download Patient";
}
function download()
{
try {
$prm = $this->get_param();
$limit = 10;
if (isset($prm['limit'])) {
$limit = trim($prm['limit']);
}
$branchId = $prm['branchId'];
$branchCode = $prm['branchCode'];
$sql = "SELECT OrderPatientID,
downloadLogM_BranchID,
downloadLogM_BranchCode,
downloadLogIsDownloaded,
downloadLogRetry
FROM one_doctor.order_patient
JOIN one_doctor.order_patient_details ON OrderPatientID = OrderPatientDetailsOrderPatientID
AND OrderPatientDetailsIsActive = 'Y'
JOIN m_mou on OrderPatientM_MouID = M_MouID
AND M_MouIsActive = 'Y'
LEFT JOIN one_doctor.download_log ON OrderPatientID = downloadLogOrderPatientID
WHERE OrderPatientIsActive = 'Y'
AND (ISNULL(downloadLogM_BranchID)
OR (downloadLogM_BranchID = ? AND downloadLogIsDownloaded = 'N')
OR (downloadLogM_BranchID <> ? ))
AND (ISNULL(downloadLogRetry) OR downloadLogRetry < 10)
GROUP BY OrderPatientID, downloadLogM_BranchID
ORDER BY OrderPatientID LIMIT ? ";
$qry = $this->db->query($sql, [intval($branchId), intval($branchId), intval($limit)]);
if (!$qry) {
$response = ["status" => "ERR", "message" => "select order patient | " .
$this->db->error()["message"], "debug" => $this->db->last_query()];
$this->reply_gz($response);
exit;
}
$rows = $qry->result_array();
$arrOrderPatientId = array();
foreach ($rows as $key => $val) {
$orderPatientId = $val['OrderPatientID'];
if (in_array($orderPatientId, $arrOrderPatientId)) {
continue;
}
$arrOrderPatientId[] = $orderPatientId;
$this->insertDownloadLog($branchId, $branchCode, $orderPatientId);
}
if (count($arrOrderPatientId) > 0) {
$orderPatientIdAll = implode(',', $arrOrderPatientId);
$sqlData = "SELECT order_patient.* , M_MouM_CompanyID FROM one_doctor.order_patient
JOIN m_mou ON OrderPatientM_MouID = M_MouID
AND M_MouIsActive = 'Y'
WHERE OrderPatientID IN ($orderPatientIdAll)
AND OrderPatientIsActive = 'Y'";
$qryData = $this->db->query($sqlData);
if (!$qryData) {
$response = ["status" => "ERR", "message" => "select order patient | " .
$this->db->error()["message"], "debug" => $this->db->last_query()];
$this->reply_gz($response);
exit;
}
$rowsData = $qryData->result_array();
foreach ($rowsData as $key => $value) {
$orderPatientId = $value['OrderPatientID'];
$sqlGetDetail = "SELECT * FROM one_doctor.order_patient_details
WHERE OrderPatientDetailsOrderPatientID = ?
AND OrderPatientDetailsIsActive = 'Y' ";
$qryGetDetail = $this->db->query($sqlGetDetail, [intval($orderPatientId)]);
if (!$qryGetDetail) {
$response = ["status" => "ERR", "message" => "select order patient detail | " .
$this->db->error()["message"], "debug" => $this->db->last_query()];
$this->reply_gz($response);
exit;
}
$rowsgetDetail = $qryGetDetail->result_array();
$rowsData[$key]['details'] = $rowsgetDetail;
// $sqlGetSaran = "SELECT *
// FROM one_doctor.order_saran
// WHERE OrderSaranOrderPatientID = ?
// AND OrderSaranIsActive = 'Y'";
// $qryGetSaran = $this->db->query($sqlGetSaran, [intval($orderPatientId)]);
// if (!$qryGetSaran) {
// $response = ["status" => "ERR", "message" => "select order saran | " .
// $this->db->error()["message"], "debug" => $this->db->last_query()];
// $this->reply_gz($response);
// exit;
// }
// $rowsgetSaran = $qryGetSaran->result_array();
// $rowsData[$key]['saran'] = $rowsgetSaran;
}
$result = array(
'status' => 'OK',
"data" => $rowsData,
);
$this->reply_gz($result);
// $this->reply($result);
} else {
$this->reply_gz("Tidak ada data terbaru");
}
} catch (Exception $exc) {
$message = $exc->getMessage();
$result = array(
'status' => 'err',
"message" => $message,
);
$this->reply_gz($result);
}
}
function insertDownloadLog($branchId, $branchCode, $patientId)
{
$sql = "INSERT INTO one_doctor.download_log
(downloadLogM_BranchID,
downloadLogM_BranchCode,
downloadLogOrderPatientID,
downloadLogRetry)
VALUES
(?,?,?,0) ON DUPLICATE KEY UPDATE downloadLogRetry = downloadLogRetry + 1";
$qry = $this->db->query($sql, [intval($branchId), $branchCode, intval($patientId)]);
if (!$qry) {
$this->sys_error_db(["status" => "ERR", "message" => "select order patient | " .
$this->db->error()["message"], "debug" => $this->db->last_query()]);
exit;
}
}
function updateLog()
{
try {
$prm = $this->get_param_z();
$branchId = $prm['branchId'];
// $branchCde = $prm['branchCode'];
$arrOrderPatientId = $prm['arrOrderPatientId'];
foreach ($arrOrderPatientId as $key => $value) {
$sqlUpdate = "UPDATE one_doctor.download_log SET
downloadLogIsDownloaded = 'Y'
WHERE downloadLogOrderPatientID = ?
AND downloadLogM_BranchID = ?";
$qry = $this->db->query($sqlUpdate, [intval($value), intval($branchId)]);
if (!$qry) {
$this->sys_error_db(["status" => "ERR", "message" => "Insert Log | " .
$this->db->error()["message"], "debug" => $this->db->last_query()]);
exit;
}
}
$result = array(
"message" => 'Berhasil',
"sql" => $this->db->last_query()
);
$this->sys_ok($result);
} catch (Exception $exc) {
$message = $exc->getMessage();
$this->sys_error($message);
}
}
function downloadSaran()
{
try {
$prm = $this->get_param();
$limit = 10;
if (isset($prm['limit'])) {
$limit = trim($prm['limit']);
}
$branchId = $prm['branchId'];
$branchCode = $prm['branchCode'];
$sql = "SELECT * FROM one_doctor.order_saran
LEFT JOIN one_doctor.download_saran_log ON OrderSaranID = downloadSaranLogOrderSaranID
AND downloadSaranLogM_BranchID = ?
WHERE OrderSaranIsActive = 'Y'
AND (
(downloadSaranLogIsDownloaded = 'N' AND downloadSaranLogRetry < 10)
OR ISNULL(downloadSaranLogM_BranchID)
)
LIMIT ?";
$qry = $this->db->query($sql, [intval($branchId), intval($limit)]);
if (!$qry) {
$response = ["status" => "ERR", "message" => "select order saran | " .
$this->db->error()["message"], "debug" => $this->db->last_query()];
// $this->reply_gz($response);
$this->reply($response);
exit;
}
$rows = $qry->result_array();
$arrOrderSaran = array();
// print_r(json_encode($rows));
// exit;
foreach ($rows as $key => $val) {
$orderSaran = $val['OrderSaranID'];
if (in_array($orderSaran, $arrOrderSaran)) {
continue;
}
$arrOrderSaran[] = $orderSaran;
$this->insertDownloadSaranLog($branchId, $branchCode, $orderSaran);
}
if (count($arrOrderSaran) > 0) {
$orderSaranIdAll = implode(',', $arrOrderSaran);
$sqlData = "SELECT * FROM one_doctor.order_saran
WHERE OrderSaranIsActive ='Y'
AND OrderSaranID IN ($orderSaranIdAll)";
$qryData = $this->db->query($sqlData);
if (!$qryData) {
$response = ["status" => "ERR", "message" => "select order saran | " .
$this->db->error()["message"], "debug" => $this->db->last_query()];
// $this->reply($response);
$this->reply_gz($response);
exit;
}
$rowsData = $qryData->result_array();
$result = array(
'status' => 'OK',
"data" => $rowsData,
);
$this->reply_gz($result);
// $this->reply($result);
} else {
$this->reply_gz("Tidak ada data terbaru");
// $this->reply("Tidak ada data terbaru");
}
} catch (Exception $exc) {
$message = $exc->getMessage();
$result = array(
'status' => 'err',
"message" => $message,
);
$this->reply_gz($result);
}
}
function insertDownloadSaranLog($branchId, $branchCode, $saranId)
{
$sql = "INSERT INTO one_doctor.download_saran_log
(downloadSaranLogM_BranchID,
downloadSaranLogM_BranchCode,
downloadSaranLogOrderSaranID,
downloadSaranLogRetry)
VALUES (?, ?, ?,0) ON DUPLICATE KEY UPDATE downloadSaranLogRetry = downloadSaranLogRetry + 1";
$qry = $this->db->query($sql, [intval($branchId), $branchCode, intval($saranId)]);
if (!$qry) {
$resp = ["status" => "ERR", "message" => "insert download saran log | " .
$this->db->error()["message"], "debug" => $this->db->last_query()];
$this->reply_gz($resp);
exit;
}
}
function updateSaranLog()
{
try {
// $prm = $this->get_param();
$prm = $this->get_param_z();
$branchId = $prm['branchId'];
// $branchCde = $prm['branchCode'];
$arrOrderSaranId = $prm['arrOrderSaranId'];
foreach ($arrOrderSaranId as $key => $value) {
$sqlUpdate = "UPDATE one_doctor.download_saran_log
SET downloadSaranLogIsDownloaded = 'Y'
WHERE downloadSaranLogOrderSaranID = ?
AND downloadSaranLogM_BranchID = ?";
$qry = $this->db->query($sqlUpdate, [intval($value), intval($branchId)]);
if (!$qry) {
$this->sys_error_db(["status" => "ERR", "message" => "Insert Log | " .
$this->db->error()["message"], "debug" => $this->db->last_query()]);
exit;
}
}
$result = array(
"message" => 'Berhasil',
"sql" => $this->db->last_query()
);
$this->sys_ok($result);
} catch (Exception $exc) {
$message = $exc->getMessage();
$this->sys_error($message);
}
}
function reply($resp)
{
echo json_encode($resp);
}
function reply_gz($resp)
{
echo gzcompress(json_encode($resp));
}
function get_param()
{
$body = file_get_contents("php://input");
return json_decode($body, true);
}
function get_param_z()
{
$body_z = file_get_contents("php://input");
$body = gzuncompress($body_z);
return json_decode($body, true);
}
}

View File

@@ -0,0 +1,371 @@
<?php
class DownloadOrderPatient extends MY_Controller
{
var $db;
function __construct()
{
parent::__construct();
$this->db_regional = $this->load->database("regional", true);
}
function index()
{
echo "Api: Download Patient";
}
function download()
{
try {
$prm = $this->get_param();
// $limit = 20;
$limit = 100;
if (isset($prm['limit'])) {
$limit = trim($prm['limit']);
}
$branchId = $prm['branchId'];
$branchCode = $prm['branchCode'];
// tidak order nasional
// $sql = "SELECT distinct OrderPatientID,
// downloadLogM_BranchID,
// downloadLogM_BranchCode,
// downloadLogIsDownloaded,
// downloadLogRetry
// FROM one_doctor.order_patient
// JOIN one_doctor.order_patient_details ON OrderPatientID = OrderPatientDetailsOrderPatientID
// AND OrderPatientDetailsIsActive = 'Y'
// JOIN m_mou on OrderPatientM_MouID = M_MouID
// AND M_MouIsActive = 'Y'
// LEFT JOIN one_doctor.download_log ON OrderPatientID = downloadLogOrderPatientID
// WHERE OrderPatientIsActive = 'Y'
// AND (ISNULL(downloadLogM_BranchID)
// OR (downloadLogM_BranchID = ? AND downloadLogIsDownloaded = 'N')
// OR (downloadLogM_BranchID <> ? ))
// AND (ISNULL(downloadLogRetry) OR downloadLogRetry < 10)
// AND OrderPatientID NOT IN (
// SELECT downloadLogOrderPatientID
// from one_doctor.download_log
// WHERE downloadLogM_BranchID = ?
// )
// GROUP BY OrderPatientID, downloadLogM_BranchID
// ORDER BY OrderPatientID
// LIMIT ?";
// pakai order nasional
$sql = "SELECT distinct OrderPatientID,
downloadLogM_BranchID,
downloadLogM_BranchCode,
downloadLogIsDownloaded,
downloadLogRetry
FROM one_doctor.order_patient
JOIN one_doctor.order_patient_details
ON OrderPatientID = OrderPatientDetailsOrderPatientID
AND OrderPatientDetailsIsActive = 'Y'
JOIN m_mou
ON (OrderPatientM_MouID = M_MouID AND M_MouIsActive = 'Y' OR OrderPatientM_MouID = 0)
LEFT JOIN one_doctor.download_log
ON OrderPatientID = downloadLogOrderPatientID
WHERE OrderPatientIsActive = 'Y'
AND (ISNULL(downloadLogM_BranchID)
OR (downloadLogM_BranchID = ? AND downloadLogIsDownloaded = 'N')
OR (downloadLogM_BranchID <> ? ))
AND (ISNULL(downloadLogRetry) OR downloadLogRetry < 10)
AND OrderPatientID NOT IN (
SELECT downloadLogOrderPatientID
from one_doctor.download_log
WHERE downloadLogM_BranchID = ?
)
GROUP BY OrderPatientID, downloadLogM_BranchID
ORDER BY OrderPatientID
LIMIT ?";
$qry = $this->db_regional->query($sql, [
intval($branchId),
intval($branchId),
intval($branchId),
intval($limit)
]);
if (!$qry) {
$response = ["status" => "ERR", "message" => "select order patient | " .
$this->db_regional->error()["message"], "debug" => $this->db_regional->last_query()];
$this->reply_gz($response);
exit;
}
$rows = $qry->result_array();
$arrOrderPatientId = array();
foreach ($rows as $key => $val) {
$orderPatientId = $val['OrderPatientID'];
if (in_array($orderPatientId, $arrOrderPatientId)) {
continue;
}
$arrOrderPatientId[] = $orderPatientId;
$this->insertDownloadLog($branchId, $branchCode, $orderPatientId);
}
if (count($arrOrderPatientId) > 0) {
$orderPatientIdAll = implode(',', $arrOrderPatientId);
// tnp order nasional
// $sqlData = "SELECT order_patient.* , M_MouM_CompanyID FROM one_doctor.order_patient
// JOIN m_mou ON OrderPatientM_MouID = M_MouID
// AND M_MouIsActive = 'Y'
// WHERE OrderPatientID IN ($orderPatientIdAll)
// AND OrderPatientIsActive = 'Y'";
// pake order nasional
$sqlData = "SELECT order_patient.* , IFNULL(M_MouM_CompanyID,0) as M_MouM_CompanyID
FROM one_doctor.order_patient
LEFT JOIN m_mou
ON (OrderPatientM_MouID = M_MouID AND M_MouIsActive = 'Y')
WHERE OrderPatientID IN ($orderPatientIdAll)
AND OrderPatientIsActive = 'Y'";
$qryData = $this->db_regional->query($sqlData);
if (!$qryData) {
$response = ["status" => "ERR", "message" => "select order patient | " .
$this->db_regional->error()["message"], "debug" => $this->db_regional->last_query()];
$this->reply_gz($response);
exit;
}
$rowsData = $qryData->result_array();
foreach ($rowsData as $key => $value) {
$orderPatientId = $value['OrderPatientID'];
$sqlGetDetail = "SELECT * FROM one_doctor.order_patient_details
WHERE OrderPatientDetailsOrderPatientID = ?
AND OrderPatientDetailsIsActive = 'Y' ";
$qryGetDetail = $this->db_regional->query($sqlGetDetail, [intval($orderPatientId)]);
if (!$qryGetDetail) {
$response = ["status" => "ERR", "message" => "select order patient detail | " .
$this->db_regional->error()["message"], "debug" => $this->db_regional->last_query()];
$this->reply_gz($response);
exit;
}
$rowsgetDetail = $qryGetDetail->result_array();
$rowsData[$key]['details'] = $rowsgetDetail;
// $sqlGetSaran = "SELECT *
// FROM one_doctor.order_saran
// WHERE OrderSaranOrderPatientID = ?
// AND OrderSaranIsActive = 'Y'";
// $qryGetSaran = $this->db->query($sqlGetSaran, [intval($orderPatientId)]);
// if (!$qryGetSaran) {
// $response = ["status" => "ERR", "message" => "select order saran | " .
// $this->db->error()["message"], "debug" => $this->db->last_query()];
// $this->reply_gz($response);
// exit;
// }
// $rowsgetSaran = $qryGetSaran->result_array();
// $rowsData[$key]['saran'] = $rowsgetSaran;
}
$result = array(
'status' => 'OK',
"data" => $rowsData,
);
$this->reply_gz($result);
// $this->reply($result);
} else {
$this->reply_gz("Tidak ada data terbaru");
}
} catch (Exception $exc) {
$message = $exc->getMessage();
$result = array(
'status' => 'err',
"message" => $message,
);
$this->reply_gz($result);
}
}
function insertDownloadLog($branchId, $branchCode, $patientId)
{
$sql = "INSERT INTO one_doctor.download_log
(downloadLogM_BranchID,
downloadLogM_BranchCode,
downloadLogOrderPatientID,
downloadLogRetry)
VALUES
(?,?,?,0) ON DUPLICATE KEY UPDATE downloadLogRetry = downloadLogRetry + 1";
$qry = $this->db_regional->query($sql, [intval($branchId), $branchCode, intval($patientId)]);
if (!$qry) {
$this->sys_error_db(["status" => "ERR", "message" => "select order patient | " .
$this->db_regional->error()["message"], "debug" => $this->db_regional->last_query()]);
exit;
}
}
function updateLog()
{
try {
$prm = $this->get_param_z();
$branchId = $prm['branchId'];
// $branchCde = $prm['branchCode'];
$arrOrderPatientId = $prm['arrOrderPatientId'];
foreach ($arrOrderPatientId as $key => $value) {
$sqlUpdate = "UPDATE one_doctor.download_log SET
downloadLogIsDownloaded = 'Y'
WHERE downloadLogOrderPatientID = ?
AND downloadLogM_BranchID = ?";
$qry = $this->db_regional->query($sqlUpdate, [intval($value), intval($branchId)]);
if (!$qry) {
$this->sys_error_db(["status" => "ERR", "message" => "Insert Log | " .
$this->db_regional->error()["message"], "debug" => $this->db_regional->last_query()]);
exit;
}
}
$result = array(
"message" => 'Berhasil',
"sql" => $this->db_regional->last_query()
);
$this->sys_ok($result);
} catch (Exception $exc) {
$message = $exc->getMessage();
$this->sys_error($message);
}
}
function downloadSaran()
{
try {
$prm = $this->get_param();
$limit = 10;
if (isset($prm['limit'])) {
$limit = trim($prm['limit']);
}
$branchId = $prm['branchId'];
$branchCode = $prm['branchCode'];
$sql = "SELECT * FROM one_doctor.order_saran
LEFT JOIN one_doctor.download_saran_log ON OrderSaranID = downloadSaranLogOrderSaranID
AND downloadSaranLogM_BranchID = ?
WHERE OrderSaranIsActive = 'Y'
AND (
(downloadSaranLogIsDownloaded = 'N' AND downloadSaranLogRetry < 10)
OR ISNULL(downloadSaranLogM_BranchID)
)
LIMIT ?";
$qry = $this->db_regional->query($sql, [intval($branchId), intval($limit)]);
if (!$qry) {
$response = ["status" => "ERR", "message" => "select order saran | " .
$this->db_regional->error()["message"], "debug" => $this->db_regional->last_query()];
// $this->reply_gz($response);
$this->reply($response);
exit;
}
$rows = $qry->result_array();
$arrOrderSaran = array();
// print_r(json_encode($rows));
// exit;
foreach ($rows as $key => $val) {
$orderSaran = $val['OrderSaranID'];
if (in_array($orderSaran, $arrOrderSaran)) {
continue;
}
$arrOrderSaran[] = $orderSaran;
$this->insertDownloadSaranLog($branchId, $branchCode, $orderSaran);
}
if (count($arrOrderSaran) > 0) {
$orderSaranIdAll = implode(',', $arrOrderSaran);
$sqlData = "SELECT * FROM one_doctor.order_saran
WHERE OrderSaranIsActive ='Y'
AND OrderSaranID IN ($orderSaranIdAll)";
$qryData = $this->db_regional->query($sqlData);
if (!$qryData) {
$response = ["status" => "ERR", "message" => "select order saran | " .
$this->db_regional->error()["message"], "debug" => $this->db_regional->last_query()];
// $this->reply($response);
$this->reply_gz($response);
exit;
}
$rowsData = $qryData->result_array();
$result = array(
'status' => 'OK',
"data" => $rowsData,
);
$this->reply_gz($result);
// $this->reply($result);
} else {
$this->reply_gz("Tidak ada data terbaru");
// $this->reply("Tidak ada data terbaru");
}
} catch (Exception $exc) {
$message = $exc->getMessage();
$result = array(
'status' => 'err',
"message" => $message,
);
$this->reply_gz($result);
}
}
function insertDownloadSaranLog($branchId, $branchCode, $saranId)
{
$sql = "INSERT INTO one_doctor.download_saran_log
(downloadSaranLogM_BranchID,
downloadSaranLogM_BranchCode,
downloadSaranLogOrderSaranID,
downloadSaranLogRetry)
VALUES (?, ?, ?,0) ON DUPLICATE KEY UPDATE downloadSaranLogRetry = downloadSaranLogRetry + 1";
$qry = $this->db_regional->query($sql, [intval($branchId), $branchCode, intval($saranId)]);
if (!$qry) {
$resp = ["status" => "ERR", "message" => "insert download saran log | " .
$this->db_regional->error()["message"], "debug" => $this->db_regional->last_query()];
$this->reply_gz($resp);
exit;
}
}
function updateSaranLog()
{
try {
// $prm = $this->get_param();
$prm = $this->get_param_z();
$branchId = $prm['branchId'];
// $branchCde = $prm['branchCode'];
$arrOrderSaranId = $prm['arrOrderSaranId'];
foreach ($arrOrderSaranId as $key => $value) {
$sqlUpdate = "UPDATE one_doctor.download_saran_log
SET downloadSaranLogIsDownloaded = 'Y'
WHERE downloadSaranLogOrderSaranID = ?
AND downloadSaranLogM_BranchID = ?";
$qry = $this->db_regional->query($sqlUpdate, [intval($value), intval($branchId)]);
if (!$qry) {
$this->sys_error_db(["status" => "ERR", "message" => "Insert Log | " .
$this->db_regional->error()["message"], "debug" => $this->db->last_query()]);
exit;
}
}
$result = array(
"message" => 'Berhasil',
"sql" => $this->db_regional->last_query()
);
$this->sys_ok($result);
} catch (Exception $exc) {
$message = $exc->getMessage();
$this->sys_error($message);
}
}
function reply($resp)
{
echo json_encode($resp);
}
function reply_gz($resp)
{
echo gzcompress(json_encode($resp));
}
function get_param()
{
$body = file_get_contents("php://input");
return json_decode($body, true);
}
function get_param_z()
{
$body_z = file_get_contents("php://input");
$body = gzuncompress($body_z);
return json_decode($body, true);
}
}

View File

@@ -0,0 +1,330 @@
<?php
class DownloadOrderPatient extends MY_Controller
{
var $db;
function __construct()
{
parent::__construct();
$this->db_regional = $this->load->database("regional", true);
}
function index()
{
echo "Api: Download Patient";
}
function download()
{
try {
$prm = $this->get_param();
$limit = 20;
if (isset($prm['limit'])) {
$limit = trim($prm['limit']);
}
$branchId = $prm['branchId'];
$branchCode = $prm['branchCode'];
$sql = "SELECT distinct OrderPatientID,
downloadLogM_BranchID,
downloadLogM_BranchCode,
downloadLogIsDownloaded,
downloadLogRetry
FROM one_doctor.order_patient
JOIN one_doctor.order_patient_details ON OrderPatientID = OrderPatientDetailsOrderPatientID
AND OrderPatientDetailsIsActive = 'Y'
JOIN m_mou on OrderPatientM_MouID = M_MouID
AND M_MouIsActive = 'Y'
LEFT JOIN one_doctor.download_log ON OrderPatientID = downloadLogOrderPatientID
WHERE OrderPatientIsActive = 'Y'
AND (ISNULL(downloadLogM_BranchID)
OR (downloadLogM_BranchID = ? AND downloadLogIsDownloaded = 'N')
OR (downloadLogM_BranchID <> ? ))
AND (ISNULL(downloadLogRetry) OR downloadLogRetry < 10)
AND OrderPatientID NOT IN (
SELECT downloadLogOrderPatientID
from one_doctor.download_log
WHERE downloadLogM_BranchID = ?
)
GROUP BY OrderPatientID, downloadLogM_BranchID
ORDER BY OrderPatientID
LIMIT ?";
$qry = $this->db_regional->query($sql, [
intval($branchId),
intval($branchId),
intval($branchId),
intval($limit)
]);
if (!$qry) {
$response = ["status" => "ERR", "message" => "select order patient | " .
$this->db_regional->error()["message"], "debug" => $this->db_regional->last_query()];
$this->reply_gz($response);
exit;
}
$rows = $qry->result_array();
$arrOrderPatientId = array();
foreach ($rows as $key => $val) {
$orderPatientId = $val['OrderPatientID'];
if (in_array($orderPatientId, $arrOrderPatientId)) {
continue;
}
$arrOrderPatientId[] = $orderPatientId;
$this->insertDownloadLog($branchId, $branchCode, $orderPatientId);
}
if (count($arrOrderPatientId) > 0) {
$orderPatientIdAll = implode(',', $arrOrderPatientId);
$sqlData = "SELECT order_patient.* , M_MouM_CompanyID FROM one_doctor.order_patient
JOIN m_mou ON OrderPatientM_MouID = M_MouID
AND M_MouIsActive = 'Y'
WHERE OrderPatientID IN ($orderPatientIdAll)
AND OrderPatientIsActive = 'Y'";
$qryData = $this->db_regional->query($sqlData);
if (!$qryData) {
$response = ["status" => "ERR", "message" => "select order patient | " .
$this->db_regional->error()["message"], "debug" => $this->db_regional->last_query()];
$this->reply_gz($response);
exit;
}
$rowsData = $qryData->result_array();
foreach ($rowsData as $key => $value) {
$orderPatientId = $value['OrderPatientID'];
$sqlGetDetail = "SELECT * FROM one_doctor.order_patient_details
WHERE OrderPatientDetailsOrderPatientID = ?
AND OrderPatientDetailsIsActive = 'Y' ";
$qryGetDetail = $this->db_regional->query($sqlGetDetail, [intval($orderPatientId)]);
if (!$qryGetDetail) {
$response = ["status" => "ERR", "message" => "select order patient detail | " .
$this->db_regional->error()["message"], "debug" => $this->db_regional->last_query()];
$this->reply_gz($response);
exit;
}
$rowsgetDetail = $qryGetDetail->result_array();
$rowsData[$key]['details'] = $rowsgetDetail;
// $sqlGetSaran = "SELECT *
// FROM one_doctor.order_saran
// WHERE OrderSaranOrderPatientID = ?
// AND OrderSaranIsActive = 'Y'";
// $qryGetSaran = $this->db->query($sqlGetSaran, [intval($orderPatientId)]);
// if (!$qryGetSaran) {
// $response = ["status" => "ERR", "message" => "select order saran | " .
// $this->db->error()["message"], "debug" => $this->db->last_query()];
// $this->reply_gz($response);
// exit;
// }
// $rowsgetSaran = $qryGetSaran->result_array();
// $rowsData[$key]['saran'] = $rowsgetSaran;
}
$result = array(
'status' => 'OK',
"data" => $rowsData,
);
$this->reply_gz($result);
// $this->reply($result);
} else {
$this->reply_gz("Tidak ada data terbaru");
}
} catch (Exception $exc) {
$message = $exc->getMessage();
$result = array(
'status' => 'err',
"message" => $message,
);
$this->reply_gz($result);
}
}
function insertDownloadLog($branchId, $branchCode, $patientId)
{
$sql = "INSERT INTO one_doctor.download_log
(downloadLogM_BranchID,
downloadLogM_BranchCode,
downloadLogOrderPatientID,
downloadLogRetry)
VALUES
(?,?,?,0) ON DUPLICATE KEY UPDATE downloadLogRetry = downloadLogRetry + 1";
$qry = $this->db_regional->query($sql, [intval($branchId), $branchCode, intval($patientId)]);
if (!$qry) {
$this->sys_error_db(["status" => "ERR", "message" => "select order patient | " .
$this->db_regional->error()["message"], "debug" => $this->db_regional->last_query()]);
exit;
}
}
function updateLog()
{
try {
$prm = $this->get_param_z();
$branchId = $prm['branchId'];
// $branchCde = $prm['branchCode'];
$arrOrderPatientId = $prm['arrOrderPatientId'];
foreach ($arrOrderPatientId as $key => $value) {
$sqlUpdate = "UPDATE one_doctor.download_log SET
downloadLogIsDownloaded = 'Y'
WHERE downloadLogOrderPatientID = ?
AND downloadLogM_BranchID = ?";
$qry = $this->db_regional->query($sqlUpdate, [intval($value), intval($branchId)]);
if (!$qry) {
$this->sys_error_db(["status" => "ERR", "message" => "Insert Log | " .
$this->db_regional->error()["message"], "debug" => $this->db_regional->last_query()]);
exit;
}
}
$result = array(
"message" => 'Berhasil',
"sql" => $this->db_regional->last_query()
);
$this->sys_ok($result);
} catch (Exception $exc) {
$message = $exc->getMessage();
$this->sys_error($message);
}
}
function downloadSaran()
{
try {
$prm = $this->get_param();
$limit = 10;
if (isset($prm['limit'])) {
$limit = trim($prm['limit']);
}
$branchId = $prm['branchId'];
$branchCode = $prm['branchCode'];
$sql = "SELECT * FROM one_doctor.order_saran
LEFT JOIN one_doctor.download_saran_log ON OrderSaranID = downloadSaranLogOrderSaranID
AND downloadSaranLogM_BranchID = ?
WHERE OrderSaranIsActive = 'Y'
AND (
(downloadSaranLogIsDownloaded = 'N' AND downloadSaranLogRetry < 10)
OR ISNULL(downloadSaranLogM_BranchID)
)
LIMIT ?";
$qry = $this->db_regional->query($sql, [intval($branchId), intval($limit)]);
if (!$qry) {
$response = ["status" => "ERR", "message" => "select order saran | " .
$this->db_regional->error()["message"], "debug" => $this->db_regional->last_query()];
// $this->reply_gz($response);
$this->reply($response);
exit;
}
$rows = $qry->result_array();
$arrOrderSaran = array();
// print_r(json_encode($rows));
// exit;
foreach ($rows as $key => $val) {
$orderSaran = $val['OrderSaranID'];
if (in_array($orderSaran, $arrOrderSaran)) {
continue;
}
$arrOrderSaran[] = $orderSaran;
$this->insertDownloadSaranLog($branchId, $branchCode, $orderSaran);
}
if (count($arrOrderSaran) > 0) {
$orderSaranIdAll = implode(',', $arrOrderSaran);
$sqlData = "SELECT * FROM one_doctor.order_saran
WHERE OrderSaranIsActive ='Y'
AND OrderSaranID IN ($orderSaranIdAll)";
$qryData = $this->db_regional->query($sqlData);
if (!$qryData) {
$response = ["status" => "ERR", "message" => "select order saran | " .
$this->db_regional->error()["message"], "debug" => $this->db_regional->last_query()];
// $this->reply($response);
$this->reply_gz($response);
exit;
}
$rowsData = $qryData->result_array();
$result = array(
'status' => 'OK',
"data" => $rowsData,
);
$this->reply_gz($result);
// $this->reply($result);
} else {
$this->reply_gz("Tidak ada data terbaru");
// $this->reply("Tidak ada data terbaru");
}
} catch (Exception $exc) {
$message = $exc->getMessage();
$result = array(
'status' => 'err',
"message" => $message,
);
$this->reply_gz($result);
}
}
function insertDownloadSaranLog($branchId, $branchCode, $saranId)
{
$sql = "INSERT INTO one_doctor.download_saran_log
(downloadSaranLogM_BranchID,
downloadSaranLogM_BranchCode,
downloadSaranLogOrderSaranID,
downloadSaranLogRetry)
VALUES (?, ?, ?,0) ON DUPLICATE KEY UPDATE downloadSaranLogRetry = downloadSaranLogRetry + 1";
$qry = $this->db_regional->query($sql, [intval($branchId), $branchCode, intval($saranId)]);
if (!$qry) {
$resp = ["status" => "ERR", "message" => "insert download saran log | " .
$this->db_regional->error()["message"], "debug" => $this->db_regional->last_query()];
$this->reply_gz($resp);
exit;
}
}
function updateSaranLog()
{
try {
// $prm = $this->get_param();
$prm = $this->get_param_z();
$branchId = $prm['branchId'];
// $branchCde = $prm['branchCode'];
$arrOrderSaranId = $prm['arrOrderSaranId'];
foreach ($arrOrderSaranId as $key => $value) {
$sqlUpdate = "UPDATE one_doctor.download_saran_log
SET downloadSaranLogIsDownloaded = 'Y'
WHERE downloadSaranLogOrderSaranID = ?
AND downloadSaranLogM_BranchID = ?";
$qry = $this->db_regional->query($sqlUpdate, [intval($value), intval($branchId)]);
if (!$qry) {
$this->sys_error_db(["status" => "ERR", "message" => "Insert Log | " .
$this->db_regional->error()["message"], "debug" => $this->db->last_query()]);
exit;
}
}
$result = array(
"message" => 'Berhasil',
"sql" => $this->db_regional->last_query()
);
$this->sys_ok($result);
} catch (Exception $exc) {
$message = $exc->getMessage();
$this->sys_error($message);
}
}
function reply($resp)
{
echo json_encode($resp);
}
function reply_gz($resp)
{
echo gzcompress(json_encode($resp));
}
function get_param()
{
$body = file_get_contents("php://input");
return json_decode($body, true);
}
function get_param_z()
{
$body_z = file_get_contents("php://input");
$body = gzuncompress($body_z);
return json_decode($body, true);
}
}

View File

@@ -0,0 +1,250 @@
<?php
class DownloadPesanKhusus extends MY_Controller
{
var $db;
function __construct()
{
parent::__construct();
$this->db_regional = $this->load->database("regional", true);
}
function index()
{
echo "Api: Download Pesan Khusus";
}
function download()
{
try {
$prm = $this->get_param();
$limit = 20;
if (isset($prm['limit'])) {
$limit = trim($prm['limit']);
}
$branchId = $prm['branchId'];
$branchCode = $prm['branchCode'];
// $sql = "SELECT distinct
// DoctorMessageOrderPatientID as OrderPatientID,
// downloadDoctorMessageLogM_BranchID,
// downloadDoctorMessageLogM_BranchCode,
// downloadDoctorMessageLogIsDownloaded,
// downloadDoctorMessageLogRetry
// from one_doctor.doctor_message
// join one_doctor.order_patient
// ON DoctorMessageOrderPatientID = OrderPatientID
// AND DoctorMessageIsActive = 'Y'
// AND DoctorMessageStatusDownload = 'N'
// JOIN one_doctor.order_patient_details
// ON OrderPatientID = OrderPatientDetailsOrderPatientID
// AND OrderPatientDetailsIsActive = 'Y'
// JOIN m_mou on OrderPatientM_MouID = M_MouID
// AND M_MouIsActive = 'Y'
// LEFT JOIN one_doctor.download_doctor_message_log
// ON OrderPatientID = downloadDoctorMessageLogOrderPatientID
// WHERE OrderPatientIsActive = 'Y'
// AND (
// ISNULL(downloadDoctorMessageLogM_BranchID)
// OR (downloadDoctorMessageLogM_BranchID = ? AND downloadDoctorMessageLogIsDownloaded = 'N')
// OR (downloadDoctorMessageLogM_BranchID <> ? )
// )
// AND (ISNULL(downloadDoctorMessageLogRetry) OR downloadDoctorMessageLogRetry < 10)
// GROUP BY DoctorMessageOrderPatientID, downloadDoctorMessageLogM_BranchID
// ORDER BY DoctorMessageOrderPatientID
// LIMIT ?";
$sql = "SELECT distinct
DoctorMessageOrderPatientID as OrderPatientID,
downloadDoctorMessageLogM_BranchID,
downloadDoctorMessageLogM_BranchCode,
downloadDoctorMessageLogIsDownloaded,
downloadDoctorMessageLogRetry
from one_doctor.doctor_message
join one_doctor.order_patient
ON DoctorMessageOrderPatientID = OrderPatientID
AND DoctorMessageIsActive = 'Y'
AND DoctorMessageStatusDownload = 'N'
JOIN one_doctor.order_patient_details
ON OrderPatientID = OrderPatientDetailsOrderPatientID
AND OrderPatientDetailsIsActive = 'Y'
JOIN m_mou
ON (OrderPatientM_MouID = M_MouID AND M_MouIsActive = 'Y' OR OrderPatientM_MouID = 0)
LEFT JOIN one_doctor.download_doctor_message_log
ON OrderPatientID = downloadDoctorMessageLogOrderPatientID
WHERE OrderPatientIsActive = 'Y'
AND (
ISNULL(downloadDoctorMessageLogM_BranchID)
OR (downloadDoctorMessageLogM_BranchID = ? AND downloadDoctorMessageLogIsDownloaded = 'N')
OR (downloadDoctorMessageLogM_BranchID <> ? )
)
AND (ISNULL(downloadDoctorMessageLogRetry) OR downloadDoctorMessageLogRetry < 10)
GROUP BY DoctorMessageOrderPatientID, downloadDoctorMessageLogM_BranchID
ORDER BY DoctorMessageOrderPatientID
LIMIT ?";
$qry = $this->db_regional->query($sql, [
intval($branchId),
intval($branchId),
intval($limit)
]);
if (!$qry) {
$response = ["status" => "ERR", "message" => "select doctor message | " .
$this->db_regional->error()["message"], "debug" => $this->db_regional->last_query()];
$this->reply_gz($response);
exit;
}
// echo $this->db_regional->last_query();
// exit;
$rows = $qry->result_array();
$arrOrderPatientId = array();
foreach ($rows as $key => $val) {
$orderPatientId = $val['OrderPatientID'];
if (in_array($orderPatientId, $arrOrderPatientId)) {
continue;
}
$arrOrderPatientId[] = $orderPatientId;
$this->insertDownloadLog($branchId, $branchCode, $orderPatientId);
}
if (count($arrOrderPatientId) > 0) {
$orderPatientIdAll = implode(',', $arrOrderPatientId);
// tnp order nasional
$sqlData = "SELECT doctor_message.* , IFNULL(M_MouM_CompanyID,0) as M_MouM_CompanyID
from one_doctor.doctor_message
join one_doctor.order_patient
ON DoctorMessageOrderPatientID = OrderPatientID
AND DoctorMessageIsActive = 'Y'
LEFT JOIN m_mou
ON (OrderPatientM_MouID = M_MouID AND M_MouIsActive = 'Y')
WHERE OrderPatientID IN ($orderPatientIdAll)
AND OrderPatientIsActive = 'Y'";
// $sqlData = "SELECT doctor_message.* , M_MouM_CompanyID
// from one_doctor.doctor_message
// join one_doctor.order_patient
// ON DoctorMessageOrderPatientID = OrderPatientID
// AND DoctorMessageIsActive = 'Y'
// JOIN m_mou ON OrderPatientM_MouID = M_MouID
// AND M_MouIsActive = 'Y'
// WHERE OrderPatientID IN ($orderPatientIdAll)
// AND OrderPatientIsActive = 'Y'";
$qryData = $this->db_regional->query($sqlData);
if (!$qryData) {
$response = ["status" => "ERR", "message" => "select doctor message | " .
$this->db_regional->error()["message"], "debug" => $this->db_regional->last_query()];
$this->reply_gz($response);
exit;
}
$rowsData = $qryData->result_array();
// print_r($rowsData);
// exit;
$result = array(
'status' => 'OK',
"data" => $rowsData,
);
$this->reply_gz($result);
// $this->reply($result);
} else {
$this->reply_gz("Tidak ada data terbaru");
}
} catch (Exception $exc) {
$message = $exc->getMessage();
$result = array(
'status' => 'err',
"message" => $message,
);
$this->reply_gz($result);
}
}
function insertDownloadLog($branchId, $branchCode, $patientId)
{
$sql = "INSERT INTO one_doctor.download_doctor_message_log
(downloadDoctorMessageLogM_BranchID,
downloadDoctorMessageLogM_BranchCode,
downloadDoctorMessageLogOrderPatientID,
downloadDoctorMessageLogRetry)
VALUES
(?,?,?,0) ON DUPLICATE
KEY UPDATE downloadDoctorMessageLogRetry = downloadDoctorMessageLogRetry + 1";
$qry = $this->db_regional->query($sql, [intval($branchId), $branchCode, intval($patientId)]);
if (!$qry) {
$this->sys_error_db(["status" => "ERR", "message" => "select doctor message | " .
$this->db_regional->error()["message"], "debug" => $this->db_regional->last_query()]);
exit;
}
}
function updateLog()
{
try {
$prm = $this->get_param_z();
$branchId = $prm['branchId'];
// $branchCde = $prm['branchCode'];
$arrOrderPatientId = $prm['arrOrderPatientId'];
foreach ($arrOrderPatientId as $key => $value) {
$sqlUpdate = "UPDATE one_doctor.download_doctor_message_log SET
downloadDoctorMessageLogIsDownloaded = 'Y'
WHERE downloadDoctorMessageLogOrderPatientID = ?
AND downloadDoctorMessageLogM_BranchID = ?";
$qry = $this->db_regional->query($sqlUpdate, [intval($value), intval($branchId)]);
if (!$qry) {
$this->sys_error_db(["status" => "ERR", "message" => "Insert download doctor message Log | " .
$this->db_regional->error()["message"], "debug" => $this->db_regional->last_query()]);
exit;
}
// UPDATE doctor_message status_download jadi Y
$sql_update_doctor_message = "UPDATE
one_doctor.doctor_message SET
DoctorMessageStatusDownload = 'Y'
WHERE DoctorMessageOrderPatientID = ?";
$qry_doctor_message = $this->db_regional->query($sql_update_doctor_message, [intval($value)]);
if (!$qry_doctor_message) {
$this->sys_error_db(["status" => "ERR", "message" => "update doctor message status download N | " .
$this->db_regional->error()["message"], "debug" => $this->db_regional->last_query()]);
exit;
}
}
$result = array(
"message" => 'Berhasil',
"sql" => $this->db_regional->last_query()
);
$this->sys_ok($result);
} catch (Exception $exc) {
$message = $exc->getMessage();
$this->sys_error($message);
}
}
function reply($resp)
{
echo json_encode($resp);
}
function reply_gz($resp)
{
echo gzcompress(json_encode($resp));
}
function get_param()
{
$body = file_get_contents("php://input");
return json_decode($body, true);
}
function get_param_z()
{
$body_z = file_get_contents("php://input");
$body = gzuncompress($body_z);
return json_decode($body, true);
}
}

View File

@@ -0,0 +1,204 @@
<?php
class DownloadPesanKhusus extends MY_Controller
{
var $db;
function __construct()
{
parent::__construct();
$this->db_regional = $this->load->database("regional", true);
}
function index()
{
echo "Api: Download Pesan Khusus";
}
function download()
{
try {
$prm = $this->get_param();
$limit = 20;
if (isset($prm['limit'])) {
$limit = trim($prm['limit']);
}
$branchId = $prm['branchId'];
$branchCode = $prm['branchCode'];
$sql = "SELECT distinct
DoctorMessageOrderPatientID as OrderPatientID,
downloadDoctorMessageLogM_BranchID,
downloadDoctorMessageLogM_BranchCode,
downloadDoctorMessageLogIsDownloaded,
downloadDoctorMessageLogRetry
from one_doctor.doctor_message
join one_doctor.order_patient
ON DoctorMessageOrderPatientID = OrderPatientID
AND DoctorMessageIsActive = 'Y'
AND DoctorMessageStatusDownload = 'N'
JOIN one_doctor.order_patient_details
ON OrderPatientID = OrderPatientDetailsOrderPatientID
AND OrderPatientDetailsIsActive = 'Y'
JOIN m_mou on OrderPatientM_MouID = M_MouID
AND M_MouIsActive = 'Y'
LEFT JOIN one_doctor.download_doctor_message_log
ON OrderPatientID = downloadDoctorMessageLogOrderPatientID
WHERE OrderPatientIsActive = 'Y'
AND (
ISNULL(downloadDoctorMessageLogM_BranchID)
OR (downloadDoctorMessageLogM_BranchID = ? AND downloadDoctorMessageLogIsDownloaded = 'N')
OR (downloadDoctorMessageLogM_BranchID <> ? )
)
AND (ISNULL(downloadDoctorMessageLogRetry) OR downloadDoctorMessageLogRetry < 10)
GROUP BY DoctorMessageOrderPatientID, downloadDoctorMessageLogM_BranchID
ORDER BY DoctorMessageOrderPatientID
LIMIT ?";
$qry = $this->db_regional->query($sql, [
intval($branchId),
intval($branchId),
intval($limit)
]);
if (!$qry) {
$response = ["status" => "ERR", "message" => "select doctor message | " .
$this->db_regional->error()["message"], "debug" => $this->db_regional->last_query()];
$this->reply_gz($response);
exit;
}
// echo $this->db_regional->last_query();
// exit;
$rows = $qry->result_array();
$arrOrderPatientId = array();
foreach ($rows as $key => $val) {
$orderPatientId = $val['OrderPatientID'];
if (in_array($orderPatientId, $arrOrderPatientId)) {
continue;
}
$arrOrderPatientId[] = $orderPatientId;
$this->insertDownloadLog($branchId, $branchCode, $orderPatientId);
}
if (count($arrOrderPatientId) > 0) {
$orderPatientIdAll = implode(',', $arrOrderPatientId);
$sqlData = "SELECT doctor_message.* , M_MouM_CompanyID
from one_doctor.doctor_message
join one_doctor.order_patient
ON DoctorMessageOrderPatientID = OrderPatientID
AND DoctorMessageIsActive = 'Y'
JOIN m_mou ON OrderPatientM_MouID = M_MouID
AND M_MouIsActive = 'Y'
WHERE OrderPatientID IN ($orderPatientIdAll)
AND OrderPatientIsActive = 'Y'";
$qryData = $this->db_regional->query($sqlData);
if (!$qryData) {
$response = ["status" => "ERR", "message" => "select doctor message | " .
$this->db_regional->error()["message"], "debug" => $this->db_regional->last_query()];
$this->reply_gz($response);
exit;
}
$rowsData = $qryData->result_array();
$result = array(
'status' => 'OK',
"data" => $rowsData,
);
$this->reply_gz($result);
// $this->reply($result);
} else {
$this->reply_gz("Tidak ada data terbaru");
}
} catch (Exception $exc) {
$message = $exc->getMessage();
$result = array(
'status' => 'err',
"message" => $message,
);
$this->reply_gz($result);
}
}
function insertDownloadLog($branchId, $branchCode, $patientId)
{
$sql = "INSERT INTO one_doctor.download_doctor_message_log
(downloadDoctorMessageLogM_BranchID,
downloadDoctorMessageLogM_BranchCode,
downloadDoctorMessageLogOrderPatientID,
downloadDoctorMessageLogRetry)
VALUES
(?,?,?,0) ON DUPLICATE
KEY UPDATE downloadDoctorMessageLogRetry = downloadDoctorMessageLogRetry + 1";
$qry = $this->db_regional->query($sql, [intval($branchId), $branchCode, intval($patientId)]);
if (!$qry) {
$this->sys_error_db(["status" => "ERR", "message" => "select doctor message | " .
$this->db_regional->error()["message"], "debug" => $this->db_regional->last_query()]);
exit;
}
}
function updateLog()
{
try {
$prm = $this->get_param_z();
$branchId = $prm['branchId'];
// $branchCde = $prm['branchCode'];
$arrOrderPatientId = $prm['arrOrderPatientId'];
foreach ($arrOrderPatientId as $key => $value) {
$sqlUpdate = "UPDATE one_doctor.download_doctor_message_log SET
downloadDoctorMessageLogIsDownloaded = 'Y'
WHERE downloadDoctorMessageLogOrderPatientID = ?
AND downloadDoctorMessageLogM_BranchID = ?";
$qry = $this->db_regional->query($sqlUpdate, [intval($value), intval($branchId)]);
if (!$qry) {
$this->sys_error_db(["status" => "ERR", "message" => "Insert download doctor message Log | " .
$this->db_regional->error()["message"], "debug" => $this->db_regional->last_query()]);
exit;
}
// UPDATE doctor_message status_download jadi Y
$sql_update_doctor_message = "UPDATE
one_doctor.doctor_message SET
DoctorMessageStatusDownload = 'Y'
WHERE DoctorMessageOrderPatientID = ?";
$qry_doctor_message = $this->db_regional->query($sql_update_doctor_message, [intval($value)]);
if (!$qry_doctor_message) {
$this->sys_error_db(["status" => "ERR", "message" => "update doctor message status download N | " .
$this->db_regional->error()["message"], "debug" => $this->db_regional->last_query()]);
exit;
}
}
$result = array(
"message" => 'Berhasil',
"sql" => $this->db_regional->last_query()
);
$this->sys_ok($result);
} catch (Exception $exc) {
$message = $exc->getMessage();
$this->sys_error($message);
}
}
function reply($resp)
{
echo json_encode($resp);
}
function reply_gz($resp)
{
echo gzcompress(json_encode($resp));
}
function get_param()
{
$body = file_get_contents("php://input");
return json_decode($body, true);
}
function get_param_z()
{
$body_z = file_get_contents("php://input");
$body = gzuncompress($body_z);
return json_decode($body, true);
}
}

View File

@@ -0,0 +1,296 @@
<?php
class R_xfer_doctormessage_nasional extends MY_Controller
{
var $db;
function __construct()
{
parent::__construct();
$this->db_regional = $this->load->database("regional", true);
}
function index()
{
echo "Api: R_xfer_order_nasional";
}
function get($url, $timeout = 60, $c_timeout = 5)
{
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $c_timeout);
curl_setopt($ch, CURLOPT_TIMEOUT, $timeout);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$result = curl_exec($ch);
$err_msg = curl_error($ch);
if ($err_msg != "") {
return json_encode(["status" => "ERR", "message" => $err_msg]);
}
return $result;
}
function reply_err($message)
{
echo json_encode(["status" => "ERR", "data" => $message]);
exit();
}
public function post($url, $data)
{
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 10);
curl_setopt($ch, CURLOPT_TIMEOUT, 10);
curl_setopt($ch, CURLOPT_HTTPHEADER, [
"Content-Type: application/text",
"Content-Length: " . strlen($data),
]);
$result = curl_exec($ch);
if (curl_error($ch) != "") {
echo json_encode([
"status" => "ERR",
"message" => "Http Error : " . curl_error($ch),
]);
curl_close($ch);
exit();
}
curl_close($ch);
return $result;
}
function log($msg)
{
// $dt = Date("Y-m-d H:i:s");
// echo "$dt $msg \n";
echo $msg;
}
function get_param_z()
{
$body_z = file_get_contents("php://input");
$body = gzuncompress($body_z);
return json_decode($body, true);
}
function reply($resp)
{
echo json_encode($resp);
}
function reply_gz($resp)
{
//echo json_encode($resp);
echo gzcompress(json_encode($resp));
}
function get_param()
{
$body = file_get_contents("php://input");
return json_decode($body, true);
}
//
function receive_order()
{
$receive_data_order = $this->sys_input;
try {
// echo json_encode([
// "status" => "OK",
// "data" => $receive_data_order['order'],
// "msg" => "123"
// ]);
if (count($receive_data_order) > 0) {
$not_exists_map_rx_order = 0;
$originIpAddress = "";
$originRegionalID = "";
$S_RegionalIPAddress_Tujuan = "";
$proses = "";
$M_DoctorNasCode = "";
// untuk order_patient_new
$order_id = "";
$originIpAddress = ($receive_data_order['originIpAddress'] !== null || $receive_data_order['originIpAddress'] !== "null" || $receive_data_order['originIpAddress'] !== "") ? "{$receive_data_order['originIpAddress']}" : "";
$originRegionalID = ($receive_data_order['originRegionalID'] !== null || $receive_data_order['originRegionalID'] !== "null" || $receive_data_order['originRegionalID'] !== "") ? "{$receive_data_order['originRegionalID']}" : "";
$S_RegionalIPAddress_Tujuan = ($receive_data_order['S_RegionalIPAddress'] !== null || $receive_data_order['S_RegionalIPAddress'] !== "null" || $receive_data_order['S_RegionalIPAddress'] !== "") ? "{$receive_data_order['S_RegionalIPAddress']}" : "";
$M_DoctorNasCode = ($receive_data_order['M_DoctorNasCode'] !== null || $receive_data_order['M_DoctorNasCode'] !== "null" || $receive_data_order['M_DoctorNasCode'] !== "") ? "{$receive_data_order['M_DoctorNasCode']}" : "";
// // echo json_encode(
// // [
// // "status" => "OK",
// // "data" => $OrderPatientDOB
// // ]
// // );
// table order_patient dan table order_patient_details
if ($receive_data_order['order'] && count($receive_data_order['order']) > 0) {
foreach ($receive_data_order['order'] as $key => $vx) {
// cek sudah ada order di order_patient blm (lookup dari map_rx_order)
$sql_get_map_rx_order = "
SELECT
mapRxOrderOriginOrderPatientID,
mapRxOrderOriginRegionalID,
mapRxOrderOriginIPAddress,
mapRxOrderNewOrderPatientID
from one_doctor.map_rx_order
WHERE
mapRxOrderOriginOrderPatientID = '{$vx['OrderPatientID']}'
AND mapRxOrderOriginRegionalID = '$originRegionalID'
AND mapRxOrderOriginIPAddress = '$originIpAddress'
AND mapRxOrderIsActive = 'Y'
AND mapRxOrderIsSent = 'Y'
";
$qry_get_map_rx_order = $this->db_regional->query($sql_get_map_rx_order);
if (!$qry_get_map_rx_order) {
$response = ["status" => "ERR", "message" => "select map_rx_order | " .
$this->db_regional->error()["message"], "debug" => $this->db_regional->last_query()];
$this->sys_error($response);
exit;
}
$last_query = $this->db_regional->last_query();
$rows_get_map_rx_order = $qry_get_map_rx_order->result_array();
// 1. sudah ada map_rx_order
if (count($rows_get_map_rx_order) > 0) {
// update doctor_message
if ($receive_data_order['order'][$key]['doctor_message'] && count($receive_data_order['order'][$key]['doctor_message']) > 0) {
foreach ($receive_data_order['order'][$key]['doctor_message'] as $keys => $value) {
$DoctorMessagePesan = $value['DoctorMessagePesan'];
$DoctorMessageStatusDownload = $value['DoctorMessageStatusDownload'];
$DoctorMessageIsActive = $value['DoctorMessageIsActive'];
$DoctorMessageUserID = $value['DoctorMessageUserID'];
$DoctorMessageCreated = $value['DoctorMessageCreated'];
$sql_cek_doctor_msg = "
SELECT *
from one_doctor.doctor_message
WHERE DoctorMessageIsActive = 'Y'
AND DoctorMessageOrderPatientID = ?
";
$qry_cek_doctor_msg = $this->db_regional->query($sql_cek_doctor_msg, [
$rows_get_map_rx_order[0]['mapRxOrderNewOrderPatientID']
]);
if (!$qry_cek_doctor_msg) {
$this->db_regional->trans_rollback();
$this->sys_error("Error select doctor_message");
exit;
}
$last_query = $this->db_regional->last_query();
$rows_cek_doctor_msg = $qry_cek_doctor_msg->result_array();
// print_r($rows_cek_doctor_msg);
// exit;
// sudah ada update
if (count($rows_cek_doctor_msg) > 0) {
$proses = "Diperbaharui";
// update doctor message
$sql = "UPDATE
one_doctor.doctor_message
SET
DoctorMessageOrderPatientID = ?,
DoctorMessagePesan = ?,
DoctorMessageStatusDownload = ?,
DoctorMessageIsActive = ?,
DoctorMessageUserID = ?,
DoctorMessageCreated = ?
WHERE
DoctorMessageOrderPatientID = '{$rows_get_map_rx_order[0]['mapRxOrderNewOrderPatientID']}'
AND DoctorMessageIsActive = 'Y'";
$query = $this->db_regional->query($sql, [
$rows_get_map_rx_order[0]['mapRxOrderNewOrderPatientID'],
$DoctorMessagePesan,
$DoctorMessageStatusDownload,
$DoctorMessageIsActive,
$DoctorMessageUserID,
$DoctorMessageCreated
]);
if (!$query) {
$this->db_regional->trans_rollback();
$this->sys_error("Error update doctor_message");
exit;
}
} else {
// insert doctor_message
$order_id = $rows_get_map_rx_order[0]['mapRxOrderNewOrderPatientID'];
$proses = "Ditambahkan";
$sql = "INSERT INTO one_doctor.doctor_message (
DoctorMessageOrderPatientID,
DoctorMessagePesan,
DoctorMessageStatusDownload,
DoctorMessageIsActive,
DoctorMessageUserID,
DoctorMessageCreated
)
VALUES(
?,
?,
?,
?,
?,
NOW()
)";
$query = $this->db_regional->query(
$sql,
array(
$order_id,
$value['DoctorMessagePesan'],
$value['DoctorMessageStatusDownload'],
$value['DoctorMessageIsActive'],
$value['DoctorMessageUserID']
)
);
if (!$query) {
$this->db_regional->trans_rollback();
$this->sys_error("Error insert doctor_message");
exit;
}
}
}
}
}
// 2. belum ada map_rx_order
else {
$not_exists_map_rx_order++;
}
}
}
if($not_exists_map_rx_order == 0){
echo json_encode(
[
"status" => "OK",
"data" => $receive_data_order,
"message" => "Data Doctor Message Berhasil $proses dan dikirim dari $originIpAddress ke $S_RegionalIPAddress_Tujuan"
]
);
}else{
echo json_encode(
[
"status" => "ERR",
"data" => $receive_data_order,
"message" => "Belum Ada Mapping Order ID New Map Rx Order"
]
);
}
}
} catch (Exception $exc) {
$message = $exc->getMessage();
$this->sys_error($message);
}
}
}

View File

@@ -0,0 +1,484 @@
<?php
class R_xfer_order_nasional extends MY_Controller
{
var $db;
function __construct()
{
parent::__construct();
$this->db_regional = $this->load->database("regional", true);
}
function index()
{
echo "Api: R_xfer_order_nasional";
}
function get($url, $timeout = 60, $c_timeout = 5)
{
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $c_timeout);
curl_setopt($ch, CURLOPT_TIMEOUT, $timeout);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$result = curl_exec($ch);
$err_msg = curl_error($ch);
if ($err_msg != "") {
return json_encode(["status" => "ERR", "message" => $err_msg]);
}
return $result;
}
function reply_err($message)
{
echo json_encode(["status" => "ERR", "data" => $message]);
exit();
}
public function post($url, $data)
{
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 10);
curl_setopt($ch, CURLOPT_TIMEOUT, 10);
curl_setopt($ch, CURLOPT_HTTPHEADER, [
"Content-Type: application/text",
"Content-Length: " . strlen($data),
]);
$result = curl_exec($ch);
if (curl_error($ch) != "") {
echo json_encode([
"status" => "ERR",
"message" => "Http Error : " . curl_error($ch),
]);
curl_close($ch);
exit();
}
curl_close($ch);
return $result;
}
function log($msg)
{
// $dt = Date("Y-m-d H:i:s");
// echo "$dt $msg \n";
echo $msg;
}
function get_param_z()
{
$body_z = file_get_contents("php://input");
$body = gzuncompress($body_z);
return json_decode($body, true);
}
function reply($resp)
{
echo json_encode($resp);
}
function reply_gz($resp)
{
//echo json_encode($resp);
echo gzcompress(json_encode($resp));
}
function get_param()
{
$body = file_get_contents("php://input");
return json_decode($body, true);
}
//
function receive_order()
{
$receive_data_order = $this->sys_input;
try {
// echo json_encode([
// "status" => "OK",
// "data" => $receive_data_order['order'],
// "msg" => "123"
// ]);
if (count($receive_data_order) > 0) {
$originIpAddress = "";
$originRegionalID = "";
$S_RegionalIPAddress_Tujuan = "";
$proses = "";
$M_DoctorNasCode = "";
// untuk order_patient_new
$order_id = "";
$originIpAddress = ($receive_data_order['originIpAddress'] !== null || $receive_data_order['originIpAddress'] !== "null" || $receive_data_order['originIpAddress'] !== "") ? "{$receive_data_order['originIpAddress']}" : "";
$originRegionalID = ($receive_data_order['originRegionalID'] !== null || $receive_data_order['originRegionalID'] !== "null" || $receive_data_order['originRegionalID'] !== "") ? "{$receive_data_order['originRegionalID']}" : "";
$S_RegionalIPAddress_Tujuan = ($receive_data_order['S_RegionalIPAddress'] !== null || $receive_data_order['S_RegionalIPAddress'] !== "null" || $receive_data_order['S_RegionalIPAddress'] !== "") ? "{$receive_data_order['S_RegionalIPAddress']}" : "";
$M_DoctorNasCode = ($receive_data_order['M_DoctorNasCode'] !== null || $receive_data_order['M_DoctorNasCode'] !== "null" || $receive_data_order['M_DoctorNasCode'] !== "") ? "{$receive_data_order['M_DoctorNasCode']}" : "";
// // echo json_encode(
// // [
// // "status" => "OK",
// // "data" => $OrderPatientDOB
// // ]
// // );
// table order_patient dan table order_patient_details
if ($receive_data_order['order'] && count($receive_data_order['order']) > 0) {
foreach ($receive_data_order['order'] as $key => $vx) {
$OrderPatientM_DoctorID_Receiver = "";
// di set 0 karena aggrement tiap regional bisa beda-beda
$OrderPatientM_MouID = "0";
$OrderPatientDate = $vx['OrderPatientDate'];
$OrderPatientQrCode = $vx['OrderPatientQrCode'];
$OrderPatientFullName = $vx['OrderPatientFullName'];
$OrderPatientDOB = $vx['OrderPatientDOB'];
$OrderPatientAddress = $vx['OrderPatientAddress'];
$OrderPatientNIK = $vx['OrderPatientNIK'];
$OrderPatientHp = $vx['OrderPatientHp'];
$OrderPatientDiagnosa = $vx['OrderPatientDiagnosa'];
$OrderPatientNote = $vx['OrderPatientNote'];
$OrderPatientIsConfirmed = $vx['OrderPatientIsConfirmed'];
$OrderPatientIsActive = $vx['OrderPatientIsActive'];
$OrderPatientUserID = $vx['OrderPatientUserID'];
$OrderPatientCreated = $vx['OrderPatientCreated'];
$sql_get_doctor_receive = "
SELECT M_DoctorNasM_DoctorID
from m_doctornas
WHERE M_DoctorNasCode = '$M_DoctorNasCode'
AND M_DoctorNasIsActive = 'Y'
";
$qry_get_doctor_receive = $this->db_regional->query($sql_get_doctor_receive);
if (!$qry_get_doctor_receive) {
$response = ["status" => "ERR", "message" => "select order patient | " .
$this->db_regional->error()["message"], "debug" => $this->db_regional->last_query()];
$this->sys_error($response);
exit;
}
$last_query = $this->db_regional->last_query();
$rows_get_doctor_receive = $qry_get_doctor_receive->result_array();
// print_r($rows_get_doctor_receive);
// exit;
if (count($rows_get_doctor_receive) > 0) {
$OrderPatientM_DoctorID_Receiver = $rows_get_doctor_receive[0]['M_DoctorNasM_DoctorID'];
}
// cek sudah ada order di order_patient blm (lookup dari map_rx_order)
$sql_get_map_rx_order = "
SELECT
mapRxOrderOriginOrderPatientID,
mapRxOrderOriginRegionalID,
mapRxOrderOriginIPAddress,
mapRxOrderNewOrderPatientID
from one_doctor.map_rx_order
WHERE
mapRxOrderOriginOrderPatientID = '{$vx['OrderPatientID']}'
AND mapRxOrderOriginRegionalID = '$originRegionalID'
AND mapRxOrderOriginIPAddress = '$originIpAddress'
AND mapRxOrderIsActive = 'Y'
AND mapRxOrderIsSent = 'N'
";
$qry_get_map_rx_order = $this->db_regional->query($sql_get_map_rx_order);
if (!$qry_get_map_rx_order) {
$response = ["status" => "ERR", "message" => "select map_rx_order | " .
$this->db_regional->error()["message"], "debug" => $this->db_regional->last_query()];
$this->sys_error($response);
exit;
}
$last_query = $this->db_regional->last_query();
$rows_get_map_rx_order = $qry_get_map_rx_order->result_array();
// 1. sudah ada map_rx_order
if (count($rows_get_map_rx_order) > 0) {
$proses = "Diperbaharui";
$sql_update_order_patient = "UPDATE
one_doctor.order_patient
SET
OrderPatientM_DoctorID = ?,
OrderPatientDate = ?,
OrderPatientM_MouID = ?,
OrderPatientQrCode = ?,
OrderPatientFullName = ?,
OrderPatientDOB = ?,
OrderPatientAddress = ?,
OrderPatientNIK = ?,
OrderPatientHp = ?,
OrderPatientDiagnosa = ?,
OrderPatientNote = ?,
OrderPatientIsConfirmed = ?,
OrderPatientIsActive = ?,
OrderPatientUserID = ?,
OrderPatientCreated = ?
WHERE
OrderPatientID = '{$rows_get_map_rx_order[0]['mapRxOrderNewOrderPatientID']}'
AND OrderPatientIsActive = 'Y'
";
$qry_update_order_patient = $this->db_regional->query($sql_update_order_patient, [
$OrderPatientM_DoctorID_Receiver,
$OrderPatientDate,
$OrderPatientM_MouID,
$OrderPatientQrCode,
$OrderPatientFullName,
$OrderPatientDOB,
$OrderPatientAddress,
$OrderPatientNIK,
$OrderPatientHp,
$OrderPatientDiagnosa,
$OrderPatientNote,
$OrderPatientIsConfirmed,
$OrderPatientIsActive,
$OrderPatientUserID,
$OrderPatientCreated
]);
if (!$qry_update_order_patient) {
$response = ["status" => "ERR", "message" => "update order patient | " .
$this->db_regional->error()["message"], "debug" => $this->db_regional->last_query()];
$this->sys_error($response);
exit;
}
// update order_details
if ($receive_data_order['order']['details'] && count($receive_data_order['order']['details']) > 0) {
foreach ($receive_data_order['order']['details'] as $key => $value) {
$sql = "UPDATE
one_doctor.order_patient_details
SET
OrderPatientDetailsT_TestID = '{$value['OrderPatientDetailsT_TestID']}',
OrderPatientDetailsT_TestName = '{$value['OrderPatientDetailsT_TestName']}',
OrderPatientDetailsPrice = '{$value['prOrderPatientDetailsPriceice']}',
OrderPatientDetailsUserID = '{$value['OrderPatientDetailsUserID']}',
OrderPatientDetailsCreated = '{$value['OrderPatientDetailsCreated']}',
WHERE
OrderPatientDetailsOrderPatientID = '{$rows_get_map_rx_order[0]['mapRxOrderNewOrderPatientID']}'
AND OrderPatientDetailsIsActive = 'Y'";
$query = $this->db_regional->query($sql, array());
if (!$query) {
$this->db_regional->trans_rollback();
$this->sys_error("Error update order_detail");
exit;
}
}
}
// insert or update order saran jk OrderPatientID sudah ada
if ($receive_data_order['order']['order_saran'] && count($receive_data_order['order']['order_saran']) > 0) {
foreach ($receive_data_order['order']['order_saran'] as $key => $value) {
$sql_cek_order_saran = "
SELECT *
FROM one_doctor.order_saran
WHERE OrderSaranOrderPatientID ='{$rows_get_map_rx_order[0]['mapRxOrderNewOrderPatientID']}'
AND OrderSaranIsActive = 'Y'";
$qry_cek_order_saran = $this->db_regional->query($sql_cek_order_saran);
if (!$qry_cek_order_saran) {
$this->db_regional->trans_rollback();
$this->sys_error("Error cek order_saran");
exit;
}
$rows_cek_order_saran = $qry_cek_order_saran->result_array();
if(count($rows_cek_order_saran) == 0){
// insert
$sql = "INSERT INTO one_doctor.order_saran (
OrderSaranOrderPatientID,
OrderKesimpulan,
OrderSaran,
OrderSaranIsActive,
OrderSaranUserID,
OrderSaranCreated
)
VALUES(
?,?,?,?,?,NOW()
)";
$query = $this->db_regional->query($sql, array(
$order_id,
$value['OrderKesimpulan'],
$value['OrderSaran'],
$value['OrderSaranIsActive'],
$value['OrderSaranUserID']
));
if (!$query) {
$this->db_regional->trans_rollback();
$this->sys_error("Error insert order_saran");
exit;
}
}
else
{
// update saran
$sql = "UPDATE
one_doctor.order_saran
SET
OrderKesimpulan = '{$value['OrderKesimpulan']}',
OrderSaran = '{$value['OrderSaran']}',
OrderSaranIsActive = '{$value['OrderSaranIsActive']}',
OrderSaranUserID = '{$value['OrderSaranUserID']}',
OrderSaranCreated = '{$value['OrderSaranCreated']}'
WHERE
OrderSaranOrderPatientID = '{$rows_get_map_rx_order[0]['mapRxOrderNewOrderPatientID']}'
AND OrderSaranIsActive = 'Y'";
$query = $this->db_regional->query($sql, array());
if (!$query) {
$this->db_regional->trans_rollback();
$this->sys_error("Error update order_saran");
exit;
}
}
}
}
}
// 2. belum ada map_rx_order
else {
$proses = "Ditambahkan";
// insert ke order_patient
$sql_insert_order_patient = "INSERT INTO one_doctor.order_patient(
OrderPatientM_DoctorID,
OrderPatientDate,
OrderPatientM_MouID,
OrderPatientQrCode,
OrderPatientFullName,
OrderPatientDOB,
OrderPatientAddress,
OrderPatientNIK,
OrderPatientHp,
OrderPatientDiagnosa,
OrderPatientNote,
OrderPatientIsConfirmed,
OrderPatientIsActive,
OrderPatientUserID,
OrderPatientCreated
) VALUES (
?,
?,
?,
?,
?,
?,
?,
?,
?,
?,
?,
?,
?,
?,
?
)
";
$qry_insert_order_patient = $this->db_regional->query($sql_insert_order_patient, [
$OrderPatientM_DoctorID_Receiver,
$OrderPatientDate,
$OrderPatientM_MouID,
$OrderPatientQrCode,
$OrderPatientFullName,
$OrderPatientDOB,
$OrderPatientAddress,
$OrderPatientNIK,
$OrderPatientHp,
$OrderPatientDiagnosa,
$OrderPatientNote,
$OrderPatientIsConfirmed,
$OrderPatientIsActive,
$OrderPatientUserID,
$OrderPatientCreated
]);
if (!$qry_insert_order_patient) {
$response = ["status" => "ERR", "message" => "insert order patient | " .
$this->db_regional->error()["message"], "debug" => $this->db_regional->last_query()];
$this->sys_error($response);
exit;
}
$order_id = $this->db_regional->insert_id();
// insert ke order_details
if ($receive_data_order['order'][$key]['details'] && count($receive_data_order['order'][$key]['details']) > 0) {
foreach ($receive_data_order['order'][$key]['details'] as $keys => $value) {
$sql = "INSERT INTO one_doctor.order_patient_details (
OrderPatientDetailsOrderPatientID,
OrderPatientDetailsT_TestID,
OrderPatientDetailsT_TestName,
OrderPatientDetailsPrice,
OrderPatientDetailsUserID,
OrderPatientDetailsCreated
)
VALUES(
?,?,?,?,?,NOW()
)";
$query = $this->db_regional->query($sql, array(
$order_id,
$value['OrderPatientDetailsT_TestID'],
$value['OrderPatientDetailsT_TestName'],
$value['OrderPatientDetailsPrice'],
$value['OrderPatientDetailsUserID']
));
if (!$query) {
$this->db_regional->trans_rollback();
$this->sys_error("Error insert order_detail");
exit;
}
}
}
// insert ke map_rx_order
$sql_insert_map_rx_order = "INSERT INTO one_doctor.map_rx_order(
mapRxOrderOriginOrderPatientID,
mapRxOrderNewOrderPatientID,
mapRxOrderOriginRegionalID,
mapRxOrderOriginIPAddress,
mapRxOrderIsSent,
mapRxOrderCreated
) VALUES (
'{$vx['OrderPatientID']}',
'$order_id',
'$originRegionalID',
'$originIpAddress',
'N',
NOW()
)
";
$qry_insert_map_rx_order = $this->db_regional->query($sql_insert_map_rx_order);
if (!$qry_insert_map_rx_order) {
$response = ["status" => "ERR", "message" => "insert map_rx_order | " .
$this->db_regional->error()["message"], "debug" => $this->db_regional->last_query()];
$this->sys_error($response);
exit;
}
}
}
}
echo json_encode(
[
"status" => "OK",
"data" => $receive_data_order,
"message" => "Data Berhasil $proses dan dikirim dari $originIpAddress ke $S_RegionalIPAddress_Tujuan"
]
);
}
} catch (Exception $exc) {
$message = $exc->getMessage();
$this->sys_error($message);
}
}
}

View File

@@ -0,0 +1,166 @@
<?php
class R_xfer_result_nasional extends MY_Controller
{
var $db;
function __construct()
{
parent::__construct();
}
function index()
{
echo "Api: REGIONAL SEND RESULT RECEIVE DATA ";
}
function receive()
{
try {
$this->db->trans_begin();
// $prm = $this->sys_input;
$prm = $this->get_param_z();
// $this->reply_gz($prm);
// echo json_encode($prm);
// exit;
$ipAddress = $prm['IP'];
$order_success = array();
if ($prm['status'] == 'OK') {
$order = $prm['order'];
for ($i = 0; $i < count($order); $i++) {
//cek
$sql_cek = "SELECT *
FROM one_doctor.one_result
WHERE oneResultOrderPatientID = ?";
$qry_cek = $this->db->query($sql_cek, [
$order[$i]['mapRxOrderOriginOrderPatientID'],
]);
if (!$qry_cek) {
$message = $this->db->error();
$err = array(
"status" => "ERR",
"IP" => $ipAddress,
"message" => $message
);
$this->reply_gz($err);
$this->db->trans_rollback();
exit;
}
$rst_cek = $qry_cek->result_array();
$lastqry = [];
// $this->sys_ok(count($rst_cek));
// exit;
//insert
if (count($rst_cek) == 0) {
$sql = "INSERT INTO one_doctor.one_result(
oneResultOrderPatientID,
oneResultOrderM_BranchCode,
oneResultOrderM_BranchID,
oneResultJson,
oneResultDate,
oneResultLastUpdated
)VALUES(?, ?, ?, ?, ?, ?)";
$qry = $this->db->query($sql, [
$order[$i]['mapRxOrderOriginOrderPatientID'],
$order[$i]['oneResultOrderM_BranchCode'],
$order[$i]['oneResultOrderM_BranchID'],
$order[$i]['oneResultJson'],
$order[$i]['oneResultDate'],
$order[$i]['oneResultLastUpdated'],
]);
if (!$qry) {
$message = $this->db->error();
$err = array(
"status" => "ERR",
"IP" => $ipAddress,
"message" => $message
);
$this->reply_gz($err);
$this->db->trans_rollback();
exit;
}
$order_success[] = $order[$i]['mapRxOrderNewOrderPatientID'];
} else {
$sql_update = "UPDATE one_doctor.one_result
SET oneResultJson = ?
WHERE oneResultOrderPatientID = ?";
$qry_update = $this->db->query($sql_update, [
$order[$i]['oneResultJson'],
$order[$i]['mapRxOrderOriginOrderPatientID'],
]);
if (!$qry_update) {
$message = $this->db->error();
$err = array(
"status" => "ERR",
"IP" => $ipAddress,
"message" => $message
);
$this->reply_gz($err);
$this->db->trans_rollback();
exit;
}
$order_success[] = $order[$i]['mapRxOrderNewOrderPatientID'];
}
// update order
$sql_update = "UPDATE
one_doctor.order_patient
SET OrderPatientFullName = ?,
OrderPatientDOB = ?,
OrderPatientNIK = ?,
OrderPatientHp = ?,
OrderPatientAddress = ?,
OrderPatientIsConfirmed = 'Y'
WHERE OrderPatientID = ?
";
$query_update = $this->db->query($sql_update, [
$order[$i]['OrderPatientFullName'],
$order[$i]['OrderPatientDOB'],
$order[$i]['OrderPatientNIK'],
$order[$i]['OrderPatientHp'],
$order[$i]['OrderPatientAddress'],
$order[$i]['mapRxOrderOriginOrderPatientID']
]);
if (!$query_update) {
$message = $this->db->error();
$err = array(
"status" => "ERR",
"IP" => $ipAddress,
"message" => $message
);
$this->reply_gz($err);
$this->db->trans_rollback();
exit;
}
}
}
$this->db->trans_commit();
$rst = array(
"status" => "OK",
"order_success" => $order_success,
"message" => "Berhasil di proses di {$ipAddress}"
);
$this->reply_gz($rst);
// echo json_encode($prm);
} catch (Exception $exc) {
$message = $exc->getMessage();
$this->sys_error($message);
}
}
function get_param_z()
{
$body_z = file_get_contents("php://input");
$body = gzuncompress($body_z);
return json_decode($body, true);
}
function reply($resp)
{
echo json_encode($resp);
}
function reply_gz($resp)
{
//echo json_encode($resp);
echo gzcompress(json_encode($resp));
}
}

View File

@@ -0,0 +1,392 @@
<?php
class R_xfer_saran_nasional extends MY_Controller
{
var $db;
function __construct()
{
parent::__construct();
$this->db_regional = $this->load->database("regional", true);
}
function index()
{
echo "Api: R_xfer_saran_nasional";
}
function get($url, $timeout = 60, $c_timeout = 5)
{
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $c_timeout);
curl_setopt($ch, CURLOPT_TIMEOUT, $timeout);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$result = curl_exec($ch);
$err_msg = curl_error($ch);
if ($err_msg != "") {
return json_encode(["status" => "ERR", "message" => $err_msg]);
}
return $result;
}
function reply_err($message)
{
echo json_encode(["status" => "ERR", "data" => $message]);
exit();
}
public function post($url, $data)
{
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 10);
curl_setopt($ch, CURLOPT_TIMEOUT, 10);
curl_setopt($ch, CURLOPT_HTTPHEADER, [
"Content-Type: application/text",
"Content-Length: " . strlen($data),
]);
$result = curl_exec($ch);
if (curl_error($ch) != "") {
echo json_encode([
"status" => "ERR",
"message" => "Http Error : " . curl_error($ch),
]);
curl_close($ch);
exit();
}
curl_close($ch);
return $result;
}
function log($msg)
{
// $dt = Date("Y-m-d H:i:s");
// echo "$dt $msg \n";
echo $msg;
}
function get_param_z()
{
$body_z = file_get_contents("php://input");
$body = gzuncompress($body_z);
return json_decode($body, true);
}
function reply($resp)
{
echo json_encode($resp);
}
function reply_gz($resp)
{
//echo json_encode($resp);
echo gzcompress(json_encode($resp));
}
function get_param()
{
$body = file_get_contents("php://input");
return json_decode($body, true);
}
//
function receive_order()
{
$receive_data_order = $this->sys_input;
try {
// echo json_encode([
// "status" => "OK",
// "data" => $receive_data_order['order'],
// "msg" => "123"
// ]);
if (count($receive_data_order) > 0) {
$not_exists_map_rx_order = 0;
$originIpAddress = "";
$originRegionalID = "";
$S_RegionalIPAddress_Tujuan = "";
$proses = "";
$M_DoctorNasCode = "";
// untuk order_patient_new
$order_id = "";
$originIpAddress = ($receive_data_order['originIpAddress'] !== null || $receive_data_order['originIpAddress'] !== "null" || $receive_data_order['originIpAddress'] !== "") ? "{$receive_data_order['originIpAddress']}" : "";
$originRegionalID = ($receive_data_order['originRegionalID'] !== null || $receive_data_order['originRegionalID'] !== "null" || $receive_data_order['originRegionalID'] !== "") ? "{$receive_data_order['originRegionalID']}" : "";
$S_RegionalIPAddress_Tujuan = ($receive_data_order['S_RegionalIPAddress'] !== null || $receive_data_order['S_RegionalIPAddress'] !== "null" || $receive_data_order['S_RegionalIPAddress'] !== "") ? "{$receive_data_order['S_RegionalIPAddress']}" : "";
$M_DoctorNasCode = ($receive_data_order['M_DoctorNasCode'] !== null || $receive_data_order['M_DoctorNasCode'] !== "null" || $receive_data_order['M_DoctorNasCode'] !== "") ? "{$receive_data_order['M_DoctorNasCode']}" : "";
// // echo json_encode(
// // [
// // "status" => "OK",
// // "data" => $OrderPatientDOB
// // ]
// // );
// table order_patient dan table order_patient_details
if ($receive_data_order['order'] && count($receive_data_order['order']) > 0) {
foreach ($receive_data_order['order'] as $key => $vx) {
// cek sudah ada order di order_patient blm (lookup dari map_rx_order)
$sql_get_map_rx_order = "
SELECT
mapRxOrderOriginOrderPatientID,
mapRxOrderOriginRegionalID,
mapRxOrderOriginIPAddress,
mapRxOrderNewOrderPatientID
from one_doctor.map_rx_order
WHERE
mapRxOrderOriginOrderPatientID = '{$vx['OrderPatientID']}'
AND mapRxOrderOriginRegionalID = '$originRegionalID'
AND mapRxOrderOriginIPAddress = '$originIpAddress'
AND mapRxOrderIsActive = 'Y'
AND mapRxOrderIsSent = 'Y'
";
$qry_get_map_rx_order = $this->db_regional->query($sql_get_map_rx_order);
if (!$qry_get_map_rx_order) {
$response = ["status" => "ERR", "message" => "select map_rx_order | " .
$this->db_regional->error()["message"], "debug" => $this->db_regional->last_query()];
$this->sys_error($response);
exit;
}
$last_query = $this->db_regional->last_query();
$rows_get_map_rx_order = $qry_get_map_rx_order->result_array();
// 1. sudah ada map_rx_order
if (count($rows_get_map_rx_order) > 0) {
// update order_saran
if ($receive_data_order['order'][$key]['order_saran'] && count($receive_data_order['order'][$key]['order_saran']) > 0) {
foreach ($receive_data_order['order'][$key]['order_saran'] as $keys => $value) {
$OrderKesimpulan = $value['OrderKesimpulan'];
$OrderSaran = $value['OrderSaran'];
$OrderSaranIsActive = $value['OrderSaranIsActive'];
$OrderSaranUserID = $value['OrderSaranUserID'];
$OrderSaranCreated = $value['OrderSaranCreated'];
$sql_cek_order_saran = "
SELECT *
from one_doctor.order_saran
WHERE OrderSaranIsActive = 'Y'
AND OrderSaranOrderPatientID = ?
";
$qry_cek_order_saran = $this->db_regional->query($sql_cek_order_saran, [
$rows_get_map_rx_order[0]['mapRxOrderNewOrderPatientID']
]);
if (!$qry_cek_order_saran) {
$this->db_regional->trans_rollback();
$this->sys_error("Error select doctor_message");
exit;
}
$last_query = $this->db_regional->last_query();
$rows_order_saran = $qry_cek_order_saran->result_array();
// print_r($rows_order_saran);
// exit;
// sudah ada update
if (count($rows_order_saran) > 0) {
$proses = "Diperbaharui";
// update saran
$sql = "UPDATE
one_doctor.order_saran
SET
OrderSaranOrderPatientID = ?,
OrderKesimpulan = ?,
OrderSaran = ?,
OrderSaranIsActive = ?,
OrderSaranUserID = ?,
OrderSaranCreated = ?
WHERE
OrderSaranOrderPatientID = '{$rows_get_map_rx_order[0]['mapRxOrderNewOrderPatientID']}'
AND OrderSaranIsActive = 'Y'";
$query = $this->db_regional->query($sql, [
$rows_get_map_rx_order[0]['mapRxOrderNewOrderPatientID'],
$OrderKesimpulan,
$OrderSaran,
$OrderSaranIsActive,
$OrderSaranUserID,
$OrderSaranCreated
]);
if (!$query) {
$this->db_regional->trans_rollback();
$this->sys_error("Error update order_saran");
exit;
}
if (
$receive_data_order['order'][$key]['order_saran'][$keys]['saran_log']
&& count($receive_data_order['order'][$key]['order_saran'][$keys]['saran_log']) > 0
) {
foreach ($receive_data_order['order'][$key]['order_saran'][$keys]['saran_log'] as $keyslog => $valuelog) {
$saran_id = $rows_order_saran[0]['OrderSaranID'];
// download saran log
$downloadSaranLogM_BranchID = $valuelog['downloadSaranLogM_BranchID'];
$downloadSaranLogM_BranchCode = $valuelog['downloadSaranLogM_BranchCode'];
$downloadSaranLogIsDownloaded = $valuelog['downloadSaranLogIsDownloaded'];
$downloadSaranLogRetry = $valuelog['downloadSaranLogRetry'];
// update saran log
$sql_update_saran_log = "UPDATE
one_doctor.download_saran_log
SET
downloadSaranLogOrderSaranID = ?,
downloadSaranLogM_BranchID = ?,
downloadSaranLogM_BranchCode = ?,
downloadSaranLogIsDownloaded = ?,
downloadSaranLogRetry = ?
WHERE
downloadSaranLogOrderSaranID = $saran_id
";
$query = $this->db_regional->query($sql_update_saran_log, [
$saran_id,
$downloadSaranLogM_BranchID,
$downloadSaranLogM_BranchCode,
$downloadSaranLogIsDownloaded,
$downloadSaranLogRetry
]);
if (!$query) {
$this->db_regional->trans_rollback();
// $this->sys_error("Error update order_saran_log");
$response = ["status" => "ERR", "message" => "Error update order_saran_log | " .
$this->db_regional->error()["message"], "debug" => $this->db_regional->last_query()];
$this->sys_error($response);
exit;
}
}
}
} else {
// insert order_saran
$order_id = $rows_get_map_rx_order[0]['mapRxOrderNewOrderPatientID'];
$proses = "Ditambahkan";
$sql = "INSERT INTO one_doctor.order_saran (
OrderSaranOrderPatientID,
OrderKesimpulan,
OrderSaran,
OrderSaranIsActive,
OrderSaranUserID,
OrderSaranCreated
)
VALUES(
?,
?,
?,
?,
?,
NOW()
)";
$query = $this->db_regional->query(
$sql,
array(
$order_id,
$value['OrderKesimpulan'],
$value['OrderSaran'],
$value['OrderSaranIsActive'],
$value['OrderSaranUserID']
)
);
if (!$query) {
$this->db_regional->trans_rollback();
$this->sys_error("Error insert order_saran");
exit;
}
$saran_id_new = $this->db_regional->insert_id();
// insert download_saran_log
if (
$receive_data_order['order'][$key]['order_saran'][$keys]['saran_log']
&&
count($receive_data_order['order'][$key]['order_saran'][$keys]['saran_log']) > 0
) {
foreach ($receive_data_order['order'][$key]['order_saran'][$keys]['saran_log'] as $keyslog => $valuelog) {
// $saran_id = $rows_order_saran[0]['OrderSaranID'];
// download saran log
$downloadSaranLogM_BranchID = $valuelog['downloadSaranLogM_BranchID'];
$downloadSaranLogM_BranchCode = $valuelog['downloadSaranLogM_BranchCode'];
$downloadSaranLogIsDownloaded = $valuelog['downloadSaranLogIsDownloaded'];
$downloadSaranLogRetry = $valuelog['downloadSaranLogRetry'];
$sql_insert_saran_log = "INSERT INTO one_doctor.download_saran_log
(
downloadSaranLogM_BranchID,
downloadSaranLogM_BranchCode,
downloadSaranLogOrderSaranID,
downloadSaranLogIsDownloaded,
downloadSaranLogRetry
)
VALUES
(
?, ?, ?, ?, ?
)";
$query = $this->db_regional->query(
$sql_insert_saran_log,
array(
$downloadSaranLogM_BranchID,
$downloadSaranLogM_BranchCode,
$saran_id_new,
$downloadSaranLogIsDownloaded,
$downloadSaranLogRetry
)
);
if (!$query) {
$this->db_regional->trans_rollback();
// $this->sys_error("Error update order_saran_log");
$response = ["status" => "ERR", "message" => "Error insert order_saran_log | " .
$this->db_regional->error()["message"], "debug" => $this->db_regional->last_query()];
$this->sys_error($response);
exit;
}
}
}
}
}
}
}
// 2. belum ada map_rx_order
else {
$not_exists_map_rx_order++;
}
}
}
if ($not_exists_map_rx_order == 0) {
echo json_encode(
[
"status" => "OK",
"data" => $receive_data_order,
"message" => "Data Saran Berhasil $proses dan dikirim dari $originIpAddress ke $S_RegionalIPAddress_Tujuan"
]
);
} else {
echo json_encode(
[
"status" => "ERR",
"data" => $receive_data_order,
"message" => "Belum Ada Mapping Order ID New Map Rx Order"
]
);
}
}
} catch (Exception $exc) {
$message = $exc->getMessage();
$this->sys_error($message);
}
}
}

View File

@@ -0,0 +1,355 @@
<?php
class Receiveruploadlog extends MY_Controller
{
var $max_limit = 20;
public function __construct()
{
parent::__construct();
// db wilayah contoh surabaya
// $this->db = $this->load->database("regional", true);
// string database
$this->db_str_doctor = 'one_doctor';
}
public function index()
{
echo "RECEIVER UPLOAD LOG API";
}
function get_param_z()
{
$body_z = file_get_contents("php://input");
$body = gzuncompress($body_z);
return json_decode($body, true);
}
function reply($resp)
{
echo json_encode($resp);
}
function reply_gz($resp)
{
//echo json_encode($resp);
echo gzcompress(json_encode($resp));
}
public function r_upload_log()
{
$this->db->trans_begin();
$param = $this->get_param_z();
// print_r($param);
// print_r;
// echo json_decode($param);
// print_r($prm);
$order_patient_id_array = [];
$data_json_result = [];
$data_json = [];
$str_order_patient_id = "";
foreach($param['data'] as $key)
{
$order_patient_id_array[] = intval($key['order_patient_id']);
}
// $implode_order_patient_id = implode(",",$order_patient_id_array);
$str_order_patient_id = implode(",",$order_patient_id_array);
if($str_order_patient_id == ""){
$str_order_patient_id = "0";
}
$sql_cek_one_result = "select oneResultOrderPatientID,
oneResultOrderM_BranchID,
oneResultOrderM_BranchCode,
oneResultJson
from $this->db_str_doctor.one_result
WHERE oneResultOrderPatientID IN ($str_order_patient_id)";
// echo $sql_cek_one_result;
$query_cek = $this->db->query($sql_cek_one_result);
if(!$query_cek){
$this->db->trans_rollback();
$this->sys_error_db(["status" => "ERR", "message" => "select cek one_result | " .
$this->db->error()["message"], "debug" => $this->db->last_query()]);
exit;
}
$rows_cek = $query_cek->result_array();
$index = 0;
// if(count($rows_cek) == 0)
// {
// insert one_result
$data_order_patient_id_one_result = [];
foreach($rows_cek as $key => $val)
{
$data_order_patient_id_one_result[] = $val['oneResultOrderPatientID'];
}
// foreach($result['data'] as $key)
$order_patient_result = [];
// $index = 0;
// print_r($param['data']);
// print_r($data_order_patient_id_one_result);
foreach($param['data'] as $key)
{
if(in_array($key['order_patient_id'], $data_order_patient_id_one_result)){
// $order_patient_result[] = $key['order_patient_id'];
// continue;
// jk sudah ada data di one_result maka update
$data_json_update =
[
"order_patient_id" => $key['order_patient_id'],
"T_OrderHeaderLabNumberExt" => $key['T_OrderHeaderLabNumberExt'],
"T_OrderHeaderDate" => $key['T_OrderHeaderDate'],
"T_OrderHeaderID" => $key['T_OrderHeaderID'],
"T_OrderHeaderSenderM_DoctorID" => $key['T_OrderHeaderSenderM_DoctorID'],
"M_BranchID" => $key['M_BranchID'],
"M_BranchCode" => $key['M_BranchCode'],
"patient" => $key['patient'],
"result" => $key['result'],
"sample" => $key['sample']
];
$this->update_one_result_by_order_patient_id(
$key['order_patient_id'],
$key['M_BranchID'],
$key['M_BranchCode'],
$data_json_update,
$key['patient'][0]
);
$order_patient_result[] = $key['order_patient_id'];
}
// jk tidak ada mk insert baru
else
{
$data_json =
[
"order_patient_id" => $key['order_patient_id'],
"T_OrderHeaderLabNumberExt" => $key['T_OrderHeaderLabNumberExt'],
"T_OrderHeaderDate" => $key['T_OrderHeaderDate'],
"T_OrderHeaderID" => $key['T_OrderHeaderID'],
"T_OrderHeaderSenderM_DoctorID" => $key['T_OrderHeaderSenderM_DoctorID'],
"M_BranchID" => $key['M_BranchID'],
"M_BranchCode" => $key['M_BranchCode'],
"patient" => $key['patient'],
"result" => $key['result'],
"sample" => $key['sample']
];
$this->insert_one_result(
$key['order_patient_id'],
$key['M_BranchID'],
$key['M_BranchCode'],
$data_json,
$key['patient'][0]
);
$order_patient_result[] = $key['order_patient_id'];
}
// $index++;
}
$this->db->trans_commit();
// $this->db->trans_rollback();
$this->reply(
[
"status" => "OK",
"message" => "Data berhasil ditambahkan ke one_result",
"order_patient_id" => $order_patient_result,
]);
// return json_encode(
// array(
// "status" => "OK",
// "message" => "Data berhasil ditambahkan ke one_result",
// "order_patient_id" => $str_order_patient_id
// )
// );
// }
// else
// {
// // sudah ditambahkan
// // return json_encode(
// // array(
// // 'status' => 'ERR',
// // 'message' => 'Data Sudah Ditambahkan'
// // )
// // );
// $this->db->trans_rollback();
// $this->reply(
// [
// "status" => "ERR",
// "message" => "Data sudah ditambahkan ke one_result",
// "order_patient_id" => $str_order_patient_id
// ]);
// }
}
function insert_one_result($order_patient_id, $m_branch_id, $m_branch_code, $result, $patient)
{
// insert
$sql_insert_one_result = "INSERT INTO $this->db_str_doctor.one_result(
oneResultOrderPatientID,
oneResultOrderM_BranchID,
oneResultOrderM_BranchCode,
oneResultJson
) VALUES (?, ?, ?, ?)";
$query_insert = $this->db->query($sql_insert_one_result, [
intval($order_patient_id),
intval($m_branch_id),
$m_branch_code,
json_encode($result)
]);
// echo $this->db->last_query();
if (!$query_insert) {
// print_r($this->db->last_query());
$this->db->trans_rollback();
$this->sys_error_db(["status" => "ERR", "message" => "insert one result log | " .
$this->db->error()["message"], "debug" => $this->db->last_query()]);
exit;
}
// print_r($patient['patient'][0]['PatientFullName']);
// update order patient
$sql_update = "Update
$this->db_str_doctor.order_patient
set OrderPatientFullName = ?,
OrderPatientDOB = ?,
OrderPatientNIK = ?,
OrderPatientHp = ?,
OrderPatientAddress = ?,
OrderPatientIsConfirmed = 'Y'
where OrderPatientID = ?
";
$query_update = $this->db->query($sql_update,[
$patient['PatientFullName'],
$patient['M_PatientDOB'],
$patient['M_PatientIDNumber'],
$patient['M_PatientHP'],
$patient['M_PatientAddressDescription'],
$order_patient_id
]);
if (!$query_update) {
// print_r($this->db->last_query());
$this->db->trans_rollback();
$this->sys_error_db(["status" => "ERR", "message" => "update order patient | " .
$this->db->error()["message"], "debug" => $this->db->last_query()]);
exit;
}
// return json_encode(
// array(
// 'status' => 'OK',
// )
// );
// $this->reply(["status" => "OK", "message" => "Data berhasil ditambahkan ke one_result"]);
}
function update_one_result_by_order_patient_id($order_patient_id, $m_branch_id, $m_branch_code, $result, $patient)
{
// update
$sql_update_one_result = "UPDATE $this->db_str_doctor.one_result
SET
oneResultOrderM_BranchID = ?,
oneResultOrderM_BranchCode = ?,
oneResultJson = ?
WHERE oneResultOrderPatientID = ?";
// echo $sql_update_one_result;
$query_update = $this->db->query($sql_update_one_result, [
intval($m_branch_id),
$m_branch_code,
json_encode($result),
intval($order_patient_id)
]);
// echo $this->db->last_query();
if (!$query_update) {
// print_r($this->db->last_query());
$this->db->trans_rollback();
$this->sys_error_db(["status" => "ERR", "message" => "update one result log | " .
$this->db->error()["message"], "debug" => $this->db->last_query()]);
exit;
}
// print_r($patient['patient'][0]['PatientFullName']);
// update order patient
// old
// $sql_update = "Update
// $this->db_str_doctor.order_patient
// set OrderPatientFullName = ?,
// OrderPatientDOB = ?,
// OrderPatientNIK = ?,
// OrderPatientHp = ?,
// OrderPatientAddress = ?,
// OrderPatientIsConfirmed = 'Y'
// where OrderPatientID = ?
// ";
// new
$sql_update = "Update
$this->db_str_doctor.order_patient
set OrderPatientFullName = ?,
OrderPatientDOB = ?,
OrderPatientNIK = ?,
OrderPatientHp = ?,
OrderPatientAddress = ?,
OrderPatientIsConfirmed = 'Y'
where OrderPatientID = ?
";
$query_update = $this->db->query($sql_update,[
$patient['PatientFullName'],
$patient['M_PatientDOB'],
$patient['M_PatientIDNumber'],
$patient['M_PatientHP'],
$patient['M_PatientAddressDescription'],
$order_patient_id
]);
if (!$query_update) {
// print_r($this->db->last_query());
$this->db->trans_rollback();
$this->sys_error_db(["status" => "ERR", "message" => "update order patient | " .
$this->db->error()["message"], "debug" => $this->db->last_query()]);
exit;
}
// return json_encode(
// array(
// 'status' => 'OK',
// )
// );
// $this->reply(["status" => "OK", "message" => "Data berhasil ditambahkan ke one_result"]);
}
}
?>

View File

@@ -0,0 +1,357 @@
<?php
class Receiveruploadlog extends MY_Controller
{
var $max_limit = 20;
public function __construct()
{
parent::__construct();
// db wilayah contoh surabaya
$this->db_regional = $this->load->database("regional", true);
// string database
$this->db_str_doctor = 'one_doctor';
}
public function index()
{
echo "RECEIVER UPLOAD LOG API";
}
function get_param_z()
{
$body_z = file_get_contents("php://input");
$body = gzuncompress($body_z);
return json_decode($body, true);
}
function reply($resp)
{
echo json_encode($resp);
}
function reply_gz($resp)
{
//echo json_encode($resp);
echo gzcompress(json_encode($resp));
}
public function r_upload_log()
{
$this->db->trans_begin();
$param = $this->get_param_z();
// print_r($param);
// print_r;
// echo json_decode($param);
// print_r($prm);
$order_patient_id_array = [];
$data_json_result = [];
$data_json = [];
$str_order_patient_id = "";
foreach($param['data'] as $key)
{
$order_patient_id_array[] = intval($key['order_patient_id']);
}
// $implode_order_patient_id = implode(",",$order_patient_id_array);
$str_order_patient_id = implode(",",$order_patient_id_array);
if($str_order_patient_id == ""){
$str_order_patient_id = "0";
}
$sql_cek_one_result = "select oneResultOrderPatientID,
oneResultOrderM_BranchID,
oneResultOrderM_BranchCode,
oneResultJson
from $this->db_str_doctor.one_result
WHERE oneResultOrderPatientID IN ($str_order_patient_id)";
// echo $sql_cek_one_result;
$query_cek = $this->db_regional->query($sql_cek_one_result);
if(!$query_cek){
$this->db->trans_rollback();
$this->sys_error_db(["status" => "ERR", "message" => "select cek one_result | " .
$this->db->error()["message"], "debug" => $this->db_regional->last_query()]);
exit;
}
$rows_cek = $query_cek->result_array();
$index = 0;
// if(count($rows_cek) == 0)
// {
// insert one_result
$data_order_patient_id_one_result = [];
foreach($rows_cek as $key => $val)
{
$data_order_patient_id_one_result[] = $val['oneResultOrderPatientID'];
}
// foreach($result['data'] as $key)
$order_patient_result = [];
// $index = 0;
// print_r($param['data']);
// print_r($data_order_patient_id_one_result);
foreach($param['data'] as $key)
{
if(in_array($key['order_patient_id'], $data_order_patient_id_one_result)){
// $order_patient_result[] = $key['order_patient_id'];
// continue;
// jk sudah ada data di one_result maka update
$data_json_update =
[
"order_patient_id" => $key['order_patient_id'],
"T_OrderHeaderLabNumberExt" => $key['T_OrderHeaderLabNumberExt'],
"T_OrderHeaderDate" => $key['T_OrderHeaderDate'],
"T_OrderHeaderID" => $key['T_OrderHeaderID'],
"T_OrderHeaderSenderM_DoctorID" => $key['T_OrderHeaderSenderM_DoctorID'],
"M_BranchID" => $key['M_BranchID'],
"M_BranchCode" => $key['M_BranchCode'],
"patient" => $key['patient'],
"result" => $key['result'],
"result_nonlab" => $key['result_nonlab'],
"sample" => $key['sample']
];
$this->update_one_result_by_order_patient_id(
$key['order_patient_id'],
$key['M_BranchID'],
$key['M_BranchCode'],
$data_json_update,
$key['patient'][0]
);
$order_patient_result[] = $key['order_patient_id'];
}
// jk tidak ada mk insert baru
else
{
$data_json =
[
"order_patient_id" => $key['order_patient_id'],
"T_OrderHeaderLabNumberExt" => $key['T_OrderHeaderLabNumberExt'],
"T_OrderHeaderDate" => $key['T_OrderHeaderDate'],
"T_OrderHeaderID" => $key['T_OrderHeaderID'],
"T_OrderHeaderSenderM_DoctorID" => $key['T_OrderHeaderSenderM_DoctorID'],
"M_BranchID" => $key['M_BranchID'],
"M_BranchCode" => $key['M_BranchCode'],
"patient" => $key['patient'],
"result" => $key['result'],
"result_nonlab" => $key['result_nonlab'],
"sample" => $key['sample']
];
$this->insert_one_result(
$key['order_patient_id'],
$key['M_BranchID'],
$key['M_BranchCode'],
$data_json,
$key['patient'][0]
);
$order_patient_result[] = $key['order_patient_id'];
}
// $index++;
}
$this->db->trans_commit();
// $this->db->trans_rollback();
$this->reply(
[
"status" => "OK",
"message" => "Data berhasil ditambahkan ke one_result",
"order_patient_id" => $order_patient_result,
]);
// return json_encode(
// array(
// "status" => "OK",
// "message" => "Data berhasil ditambahkan ke one_result",
// "order_patient_id" => $str_order_patient_id
// )
// );
// }
// else
// {
// // sudah ditambahkan
// // return json_encode(
// // array(
// // 'status' => 'ERR',
// // 'message' => 'Data Sudah Ditambahkan'
// // )
// // );
// $this->db->trans_rollback();
// $this->reply(
// [
// "status" => "ERR",
// "message" => "Data sudah ditambahkan ke one_result",
// "order_patient_id" => $str_order_patient_id
// ]);
// }
}
function insert_one_result($order_patient_id, $m_branch_id, $m_branch_code, $result, $patient)
{
// insert
$sql_insert_one_result = "INSERT INTO $this->db_str_doctor.one_result(
oneResultOrderPatientID,
oneResultOrderM_BranchID,
oneResultOrderM_BranchCode,
oneResultJson
) VALUES (?, ?, ?, ?)";
$query_insert = $this->db_regional->query($sql_insert_one_result, [
intval($order_patient_id),
intval($m_branch_id),
$m_branch_code,
json_encode($result)
]);
// echo $this->db->last_query();
if (!$query_insert) {
// print_r($this->db->last_query());
$this->db->trans_rollback();
$this->sys_error_db(["status" => "ERR", "message" => "insert one result log | " .
$this->db->error()["message"], "debug" => $this->db->last_query()]);
exit;
}
// print_r($patient['patient'][0]['PatientFullName']);
// update order patient
$sql_update = "Update
$this->db_str_doctor.order_patient
set OrderPatientFullName = ?,
OrderPatientDOB = ?,
OrderPatientNIK = ?,
OrderPatientHp = ?,
OrderPatientAddress = ?,
OrderPatientIsConfirmed = 'Y'
where OrderPatientID = ?
";
$query_update = $this->db_regional->query($sql_update,[
$patient['PatientFullName'],
$patient['M_PatientDOB'],
$patient['M_PatientIDNumber'],
$patient['M_PatientHP'],
$patient['M_PatientAddressDescription'],
$order_patient_id
]);
if (!$query_update) {
// print_r($this->db->last_query());
$this->db->trans_rollback();
$this->sys_error_db(["status" => "ERR", "message" => "update order patient | " .
$this->db->error()["message"], "debug" => $this->db->last_query()]);
exit;
}
// return json_encode(
// array(
// 'status' => 'OK',
// )
// );
// $this->reply(["status" => "OK", "message" => "Data berhasil ditambahkan ke one_result"]);
}
function update_one_result_by_order_patient_id($order_patient_id, $m_branch_id, $m_branch_code, $result, $patient)
{
// update
$sql_update_one_result = "UPDATE $this->db_str_doctor.one_result
SET
oneResultOrderM_BranchID = ?,
oneResultOrderM_BranchCode = ?,
oneResultJson = ?
WHERE oneResultOrderPatientID = ?";
// echo $sql_update_one_result;
$query_update = $this->db_regional->query($sql_update_one_result, [
intval($m_branch_id),
$m_branch_code,
json_encode($result),
intval($order_patient_id)
]);
// echo $this->db->last_query();
if (!$query_update) {
// print_r($this->db->last_query());
$this->db->trans_rollback();
$this->sys_error_db(["status" => "ERR", "message" => "update one result log | " .
$this->db->error()["message"], "debug" => $this->db_regional->last_query()]);
exit;
}
// print_r($patient['patient'][0]['PatientFullName']);
// update order patient
// old
// $sql_update = "Update
// $this->db_str_doctor.order_patient
// set OrderPatientFullName = ?,
// OrderPatientDOB = ?,
// OrderPatientNIK = ?,
// OrderPatientHp = ?,
// OrderPatientAddress = ?,
// OrderPatientIsConfirmed = 'Y'
// where OrderPatientID = ?
// ";
// new
$sql_update = "Update
$this->db_str_doctor.order_patient
set OrderPatientFullName = ?,
OrderPatientDOB = ?,
OrderPatientNIK = ?,
OrderPatientHp = ?,
OrderPatientAddress = ?,
OrderPatientIsConfirmed = 'Y'
where OrderPatientID = ?
";
$query_update = $this->db_regional->query($sql_update,[
$patient['PatientFullName'],
$patient['M_PatientDOB'],
$patient['M_PatientIDNumber'],
$patient['M_PatientHP'],
$patient['M_PatientAddressDescription'],
$order_patient_id
]);
if (!$query_update) {
// print_r($this->db->last_query());
$this->db->trans_rollback();
$this->sys_error_db(["status" => "ERR", "message" => "update order patient | " .
$this->db->error()["message"], "debug" => $this->db_regional->last_query()]);
exit;
}
// return json_encode(
// array(
// 'status' => 'OK',
// )
// );
// $this->reply(["status" => "OK", "message" => "Data berhasil ditambahkan ke one_result"]);
}
}
?>

View File

@@ -0,0 +1,341 @@
<?php
class Receiveruploadlog extends MY_Controller
{
var $max_limit = 20;
public function __construct()
{
parent::__construct();
// db wilayah contoh surabaya
// $this->db = $this->load->database("regional", true);
// string database
$this->db_str_doctor = 'one_doctor';
}
public function index()
{
echo "RECEIVER UPLOAD LOG API";
}
function get_param_z()
{
$body_z = file_get_contents("php://input");
$body = gzuncompress($body_z);
return json_decode($body, true);
}
function reply($resp)
{
echo json_encode($resp);
}
function reply_gz($resp)
{
//echo json_encode($resp);
echo gzcompress(json_encode($resp));
}
public function r_upload_log()
{
$this->db->trans_begin();
$param = $this->get_param_z();
// print_r($param);
// print_r;
// echo json_decode($param);
// print_r($prm);
$order_patient_id_array = [];
$data_json_result = [];
$data_json = [];
$str_order_patient_id = "";
foreach($param['data'] as $key)
{
$order_patient_id_array[] = intval($key['order_patient_id']);
}
// $implode_order_patient_id = implode(",",$order_patient_id_array);
$str_order_patient_id = implode(",",$order_patient_id_array);
if($str_order_patient_id == ""){
$str_order_patient_id = "0";
}
$sql_cek_one_result = "select oneResultOrderPatientID,
oneResultOrderM_BranchID,
oneResultOrderM_BranchCode,
oneResultJson
from $this->db_str_doctor.one_result
WHERE oneResultOrderPatientID IN ($str_order_patient_id)";
// echo $sql_cek_one_result;
$query_cek = $this->db->query($sql_cek_one_result);
if(!$query_cek){
$this->db->trans_rollback();
$this->sys_error_db(["status" => "ERR", "message" => "select cek one_result | " .
$this->db->error()["message"], "debug" => $this->db->last_query()]);
exit;
}
$rows_cek = $query_cek->result_array();
$index = 0;
// if(count($rows_cek) == 0)
// {
// insert one_result
$data_order_patient_id_one_result = [];
foreach($rows_cek as $key => $val)
{
$data_order_patient_id_one_result[] = $val['oneResultOrderPatientID'];
}
// foreach($result['data'] as $key)
$order_patient_result = [];
// $index = 0;
// print_r($param['data']);
// print_r($data_order_patient_id_one_result);
foreach($param['data'] as $key)
{
if(in_array($key['order_patient_id'], $data_order_patient_id_one_result)){
// $order_patient_result[] = $key['order_patient_id'];
// continue;
// jk sudah ada data di one_result maka update
$data_json_update =
[
"order_patient_id" => $key['order_patient_id'],
"T_OrderHeaderLabNumberExt" => $key['T_OrderHeaderLabNumberExt'],
"T_OrderHeaderDate" => $key['T_OrderHeaderDate'],
"T_OrderHeaderID" => $key['T_OrderHeaderID'],
"T_OrderHeaderSenderM_DoctorID" => $key['T_OrderHeaderSenderM_DoctorID'],
"M_BranchID" => $key['M_BranchID'],
"M_BranchCode" => $key['M_BranchCode'],
"patient" => $key['patient'],
"result" => $key['result'],
"sample" => $key['sample']
];
$this->update_one_result_by_order_patient_id(
$key['order_patient_id'],
$key['M_BranchID'],
$key['M_BranchCode'],
$data_json_update,
$key['patient'][0]
);
$order_patient_result[] = $key['order_patient_id'];
}
// jk tidak ada mk insert baru
else
{
$data_json =
[
"order_patient_id" => $key['order_patient_id'],
"T_OrderHeaderLabNumberExt" => $key['T_OrderHeaderLabNumberExt'],
"T_OrderHeaderDate" => $key['T_OrderHeaderDate'],
"T_OrderHeaderID" => $key['T_OrderHeaderID'],
"T_OrderHeaderSenderM_DoctorID" => $key['T_OrderHeaderSenderM_DoctorID'],
"M_BranchID" => $key['M_BranchID'],
"M_BranchCode" => $key['M_BranchCode'],
"patient" => $key['patient'],
"result" => $key['result'],
"sample" => $key['sample']
];
$this->insert_one_result(
$key['order_patient_id'],
$key['M_BranchID'],
$key['M_BranchCode'],
$data_json,
$key['patient'][0]
);
$order_patient_result[] = $key['order_patient_id'];
}
// $index++;
}
$this->db->trans_commit();
// $this->db->trans_rollback();
$this->reply(
[
"status" => "OK",
"message" => "Data berhasil ditambahkan ke one_result",
"order_patient_id" => $order_patient_result,
]);
// return json_encode(
// array(
// "status" => "OK",
// "message" => "Data berhasil ditambahkan ke one_result",
// "order_patient_id" => $str_order_patient_id
// )
// );
// }
// else
// {
// // sudah ditambahkan
// // return json_encode(
// // array(
// // 'status' => 'ERR',
// // 'message' => 'Data Sudah Ditambahkan'
// // )
// // );
// $this->db->trans_rollback();
// $this->reply(
// [
// "status" => "ERR",
// "message" => "Data sudah ditambahkan ke one_result",
// "order_patient_id" => $str_order_patient_id
// ]);
// }
}
function insert_one_result($order_patient_id, $m_branch_id, $m_branch_code, $result, $patient)
{
// insert
$sql_insert_one_result = "INSERT INTO $this->db_str_doctor.one_result(
oneResultOrderPatientID,
oneResultOrderM_BranchID,
oneResultOrderM_BranchCode,
oneResultJson
) VALUES (?, ?, ?, ?)";
$query_insert = $this->db->query($sql_insert_one_result, [
intval($order_patient_id),
intval($m_branch_id),
$m_branch_code,
json_encode($result)
]);
// echo $this->db->last_query();
if (!$query_insert) {
// print_r($this->db->last_query());
$this->db->trans_rollback();
$this->sys_error_db(["status" => "ERR", "message" => "insert one result log | " .
$this->db->error()["message"], "debug" => $this->db->last_query()]);
exit;
}
// print_r($patient['patient'][0]['PatientFullName']);
// update order patient
$sql_update = "Update
$this->db_str_doctor.order_patient
set OrderPatientFullName = ?,
OrderPatientDOB = ?,
OrderPatientNIK = ?,
OrderPatientHp = ?,
OrderPatientAddress = ?,
OrderPatientIsConfirmed = 'Y'
where OrderPatientID = ?
";
$query_update = $this->db->query($sql_update,[
$patient['PatientFullName'],
$patient['M_PatientDOB'],
$patient['M_PatientIDNumber'],
$patient['M_PatientHP'],
$patient['M_PatientAddressDescription'],
$order_patient_id
]);
if (!$query_update) {
// print_r($this->db->last_query());
$this->db->trans_rollback();
$this->sys_error_db(["status" => "ERR", "message" => "update order patient | " .
$this->db->error()["message"], "debug" => $this->db->last_query()]);
exit;
}
// return json_encode(
// array(
// 'status' => 'OK',
// )
// );
// $this->reply(["status" => "OK", "message" => "Data berhasil ditambahkan ke one_result"]);
}
function update_one_result_by_order_patient_id($order_patient_id, $m_branch_id, $m_branch_code, $result, $patient)
{
// update
$sql_update_one_result = "UPDATE $this->db_str_doctor.one_result
SET
oneResultOrderM_BranchID = ?,
oneResultOrderM_BranchCode = ?,
oneResultJson = ?
WHERE oneResultOrderPatientID = ?";
// echo $sql_update_one_result;
$query_update = $this->db->query($sql_update_one_result, [
intval($m_branch_id),
$m_branch_code,
json_encode($result),
intval($order_patient_id)
]);
// echo $this->db->last_query();
if (!$query_update) {
// print_r($this->db->last_query());
$this->db->trans_rollback();
$this->sys_error_db(["status" => "ERR", "message" => "update one result log | " .
$this->db->error()["message"], "debug" => $this->db->last_query()]);
exit;
}
// print_r($patient['patient'][0]['PatientFullName']);
// update order patient
$sql_update = "Update
$this->db_str_doctor.order_patient
set OrderPatientFullName = ?,
OrderPatientDOB = ?,
OrderPatientNIK = ?,
OrderPatientHp = ?,
OrderPatientAddress = ?,
OrderPatientIsConfirmed = 'Y'
where OrderPatientID = ?
";
$query_update = $this->db->query($sql_update,[
$patient['PatientFullName'],
$patient['M_PatientDOB'],
$patient['M_PatientIDNumber'],
$patient['M_PatientHP'],
$patient['M_PatientAddressDescription'],
$order_patient_id
]);
if (!$query_update) {
// print_r($this->db->last_query());
$this->db->trans_rollback();
$this->sys_error_db(["status" => "ERR", "message" => "update order patient | " .
$this->db->error()["message"], "debug" => $this->db->last_query()]);
exit;
}
// return json_encode(
// array(
// 'status' => 'OK',
// )
// );
// $this->reply(["status" => "OK", "message" => "Data berhasil ditambahkan ke one_result"]);
}
}
?>

View File

@@ -0,0 +1,272 @@
<?php
class Receiveruploadlogconfirm extends MY_Controller
{
var $max_limit = 20;
public function __construct()
{
parent::__construct();
// db wilayah contoh surabaya
// $this->db = $this->load->database("regional", true);
// string database
$this->db_str_doctor = 'one_doctor';
}
public function index()
{
echo "RECEIVER UPLOAD LOG API";
}
function get_param_z()
{
$body_z = file_get_contents("php://input");
$body = gzuncompress($body_z);
return json_decode($body, true);
}
function reply($resp)
{
echo json_encode($resp);
}
function reply_gz($resp)
{
//echo json_encode($resp);
echo gzcompress(json_encode($resp));
}
public function r_upload_log_confirm()
{
$this->db->trans_begin();
$param = $this->get_param_z();
if(count($param['data']) > 0){
$order_patient_id_array = [];
foreach($param['data'] as $key)
{
$order_patient_id_array[] = intval($key['order_patient_id']);
}
// $implode_order_patient_id = implode(",",$order_patient_id_array);
$str_order_patient_id = implode(",",$order_patient_id_array);
// print_r($str_order_patient_id);
// exit;
// update isconfirmed di orderpatient
// sql_update
$sql_update_is_confirm_Y = "UPDATE $this->db_str_doctor.order_patient
SET OrderPatientIsConfirmed = 'Y'
WHERE OrderPatientID IN ($str_order_patient_id)";
// print_r($sql_update_is_confirm_Y);
// exit;
$qry_update = $this->db->query($sql_update_is_confirm_Y);
if(!$qry_update){
$this->db->trans_rollback();
$this->sys_error_db(["status" => "ERR", "message" => "update data order_patient Y error | " .
$this->db->error()["message"], "debug" => $this->db->last_query()]);
exit;
}
$this->db->trans_commit();
// $this->db->trans_rollback();
$this->reply(
[
"status" => "OK",
"message" => "update",
"order_patient_id" => $order_patient_id_array,
"sql" => $sql_update_is_confirm
]
);
}
else
{
$this->reply(
[
"status" => "ERR",
"message" => "".$this->db->last_query(),
"order_patient_id" => $order_patient_id_array,
"sql" => $sql_update_is_confirm
]
);
}
// foreach($param['data'] as $key)
// {
// $order_patient_id_array[] = intval($key['order_patient_id']);
// }
// print_r($param);
// exit;
// print_r;
// echo json_decode($param);
// print_r($prm);
// $order_patient_id_array = [];
// $data_json_result = [];
// $data_json = [];
// $str_order_patient_id = "";
// foreach($param['data'] as $key)
// {
// $order_patient_id_array[] = intval($key['order_patient_id']);
// }
// // $implode_order_patient_id = implode(",",$order_patient_id_array);
// $str_order_patient_id = implode(",",$order_patient_id_array);
// if($str_order_patient_id == ""){
// $str_order_patient_id = "0";
// }
// $sql_cek_one_result = "select oneResultOrderPatientID,
// oneResultOrderM_BranchID,
// oneResultOrderM_BranchCode,
// oneResultJson
// from $this->db_str_doctor.one_result
// WHERE oneResultOrderPatientID IN ($str_order_patient_id)";
// // echo $sql_cek_one_result;
// $query_cek = $this->db->query($sql_cek_one_result);
// if(!$query_cek){
// $this->db->trans_rollback();
// $this->sys_error_db(["status" => "ERR", "message" => "select cek one_result | " .
// $this->db->error()["message"], "debug" => $this->db->last_query()]);
// exit;
// }
// $rows_cek = $query_cek->result_array();
// $index = 0;
// // if(count($rows_cek) == 0)
// // {
// // insert one_result
// $data_order_patient_id_one_result = [];
// foreach($rows_cek as $key => $val)
// {
// $data_order_patient_id_one_result[] = $val['oneResultOrderPatientID'];
// }
// // foreach($result['data'] as $key)
// $order_patient_result = [];
// // $index = 0;
// // print_r($param['data']);
// // print_r($data_order_patient_id_one_result);
// foreach($param['data'] as $key)
// {
// if(in_array($key['order_patient_id'], $data_order_patient_id_one_result)){
// // $order_patient_result[] = $key['order_patient_id'];
// // continue;
// // jk sudah ada data di one_result maka update
// $data_json_update =
// [
// "order_patient_id" => $key['order_patient_id'],
// "T_OrderHeaderLabNumberExt" => $key['T_OrderHeaderLabNumberExt'],
// "T_OrderHeaderDate" => $key['T_OrderHeaderDate'],
// "T_OrderHeaderID" => $key['T_OrderHeaderID'],
// "T_OrderHeaderSenderM_DoctorID" => $key['T_OrderHeaderSenderM_DoctorID'],
// "M_BranchID" => $key['M_BranchID'],
// "M_BranchCode" => $key['M_BranchCode'],
// "patient" => $key['patient'],
// "result" => $key['result'],
// "sample" => $key['sample']
// ];
// $this->update_one_result_by_order_patient_id(
// $key['order_patient_id'],
// $key['M_BranchID'],
// $key['M_BranchCode'],
// $data_json_update,
// $key['patient'][0]
// );
// $order_patient_result[] = $key['order_patient_id'];
// }
// // jk tidak ada mk insert baru
// else
// {
// $data_json =
// [
// "order_patient_id" => $key['order_patient_id'],
// "T_OrderHeaderLabNumberExt" => $key['T_OrderHeaderLabNumberExt'],
// "T_OrderHeaderDate" => $key['T_OrderHeaderDate'],
// "T_OrderHeaderID" => $key['T_OrderHeaderID'],
// "T_OrderHeaderSenderM_DoctorID" => $key['T_OrderHeaderSenderM_DoctorID'],
// "M_BranchID" => $key['M_BranchID'],
// "M_BranchCode" => $key['M_BranchCode'],
// "patient" => $key['patient'],
// "result" => $key['result'],
// "sample" => $key['sample']
// ];
// $this->insert_one_result(
// $key['order_patient_id'],
// $key['M_BranchID'],
// $key['M_BranchCode'],
// $data_json,
// $key['patient'][0]
// );
// $order_patient_result[] = $key['order_patient_id'];
// }
// // $index++;
// }
// $this->db->trans_commit();
// // $this->db->trans_rollback();
// $this->reply(
// [
// "status" => "OK",
// "message" => "Data berhasil ditambahkan ke one_result",
// "order_patient_id" => $order_patient_result,
// ]);
// // return json_encode(
// // array(
// // "status" => "OK",
// // "message" => "Data berhasil ditambahkan ke one_result",
// // "order_patient_id" => $str_order_patient_id
// // )
// // );
// // }
// // else
// // {
// // // sudah ditambahkan
// // // return json_encode(
// // // array(
// // // 'status' => 'ERR',
// // // 'message' => 'Data Sudah Ditambahkan'
// // // )
// // // );
// // $this->db->trans_rollback();
// // $this->reply(
// // [
// // "status" => "ERR",
// // "message" => "Data sudah ditambahkan ke one_result",
// // "order_patient_id" => $str_order_patient_id
// // ]);
// // }
}
}
?>

View File

@@ -0,0 +1,272 @@
<?php
class Receiveruploadlogconfirm extends MY_Controller
{
var $max_limit = 20;
public function __construct()
{
parent::__construct();
// db wilayah contoh surabaya
$this->db_regional = $this->load->database("regional", true);
// string database
$this->db_str_doctor = 'one_doctor';
}
public function index()
{
echo "RECEIVER UPLOAD LOG API";
}
function get_param_z()
{
$body_z = file_get_contents("php://input");
$body = gzuncompress($body_z);
return json_decode($body, true);
}
function reply($resp)
{
echo json_encode($resp);
}
function reply_gz($resp)
{
//echo json_encode($resp);
echo gzcompress(json_encode($resp));
}
public function r_upload_log_confirm()
{
$this->db->trans_begin();
$param = $this->get_param_z();
if(count($param['data']) > 0){
$order_patient_id_array = [];
foreach($param['data'] as $key)
{
$order_patient_id_array[] = intval($key['order_patient_id']);
}
// $implode_order_patient_id = implode(",",$order_patient_id_array);
$str_order_patient_id = implode(",",$order_patient_id_array);
// print_r($str_order_patient_id);
// exit;
// update isconfirmed di orderpatient
// sql_update
$sql_update_is_confirm_Y = "UPDATE $this->db_str_doctor.order_patient
SET OrderPatientIsConfirmed = 'Y'
WHERE OrderPatientID IN ($str_order_patient_id)";
// print_r($sql_update_is_confirm_Y);
// exit;
$qry_update = $this->db_regional->query($sql_update_is_confirm_Y);
if(!$qry_update){
$this->db->trans_rollback();
$this->sys_error_db(["status" => "ERR", "message" => "update data order_patient Y error | " .
$this->db->error()["message"], "debug" => $this->db_regional->last_query()]);
exit;
}
$this->db->trans_commit();
// $this->db->trans_rollback();
$this->reply(
[
"status" => "OK",
"message" => "update",
"order_patient_id" => $order_patient_id_array,
"sql" => $sql_update_is_confirm
]
);
}
else
{
$this->reply(
[
"status" => "ERR",
"message" => "".$this->db_regional->last_query(),
"order_patient_id" => $order_patient_id_array,
"sql" => $sql_update_is_confirm
]
);
}
// foreach($param['data'] as $key)
// {
// $order_patient_id_array[] = intval($key['order_patient_id']);
// }
// print_r($param);
// exit;
// print_r;
// echo json_decode($param);
// print_r($prm);
// $order_patient_id_array = [];
// $data_json_result = [];
// $data_json = [];
// $str_order_patient_id = "";
// foreach($param['data'] as $key)
// {
// $order_patient_id_array[] = intval($key['order_patient_id']);
// }
// // $implode_order_patient_id = implode(",",$order_patient_id_array);
// $str_order_patient_id = implode(",",$order_patient_id_array);
// if($str_order_patient_id == ""){
// $str_order_patient_id = "0";
// }
// $sql_cek_one_result = "select oneResultOrderPatientID,
// oneResultOrderM_BranchID,
// oneResultOrderM_BranchCode,
// oneResultJson
// from $this->db_str_doctor.one_result
// WHERE oneResultOrderPatientID IN ($str_order_patient_id)";
// // echo $sql_cek_one_result;
// $query_cek = $this->db->query($sql_cek_one_result);
// if(!$query_cek){
// $this->db->trans_rollback();
// $this->sys_error_db(["status" => "ERR", "message" => "select cek one_result | " .
// $this->db->error()["message"], "debug" => $this->db->last_query()]);
// exit;
// }
// $rows_cek = $query_cek->result_array();
// $index = 0;
// // if(count($rows_cek) == 0)
// // {
// // insert one_result
// $data_order_patient_id_one_result = [];
// foreach($rows_cek as $key => $val)
// {
// $data_order_patient_id_one_result[] = $val['oneResultOrderPatientID'];
// }
// // foreach($result['data'] as $key)
// $order_patient_result = [];
// // $index = 0;
// // print_r($param['data']);
// // print_r($data_order_patient_id_one_result);
// foreach($param['data'] as $key)
// {
// if(in_array($key['order_patient_id'], $data_order_patient_id_one_result)){
// // $order_patient_result[] = $key['order_patient_id'];
// // continue;
// // jk sudah ada data di one_result maka update
// $data_json_update =
// [
// "order_patient_id" => $key['order_patient_id'],
// "T_OrderHeaderLabNumberExt" => $key['T_OrderHeaderLabNumberExt'],
// "T_OrderHeaderDate" => $key['T_OrderHeaderDate'],
// "T_OrderHeaderID" => $key['T_OrderHeaderID'],
// "T_OrderHeaderSenderM_DoctorID" => $key['T_OrderHeaderSenderM_DoctorID'],
// "M_BranchID" => $key['M_BranchID'],
// "M_BranchCode" => $key['M_BranchCode'],
// "patient" => $key['patient'],
// "result" => $key['result'],
// "sample" => $key['sample']
// ];
// $this->update_one_result_by_order_patient_id(
// $key['order_patient_id'],
// $key['M_BranchID'],
// $key['M_BranchCode'],
// $data_json_update,
// $key['patient'][0]
// );
// $order_patient_result[] = $key['order_patient_id'];
// }
// // jk tidak ada mk insert baru
// else
// {
// $data_json =
// [
// "order_patient_id" => $key['order_patient_id'],
// "T_OrderHeaderLabNumberExt" => $key['T_OrderHeaderLabNumberExt'],
// "T_OrderHeaderDate" => $key['T_OrderHeaderDate'],
// "T_OrderHeaderID" => $key['T_OrderHeaderID'],
// "T_OrderHeaderSenderM_DoctorID" => $key['T_OrderHeaderSenderM_DoctorID'],
// "M_BranchID" => $key['M_BranchID'],
// "M_BranchCode" => $key['M_BranchCode'],
// "patient" => $key['patient'],
// "result" => $key['result'],
// "sample" => $key['sample']
// ];
// $this->insert_one_result(
// $key['order_patient_id'],
// $key['M_BranchID'],
// $key['M_BranchCode'],
// $data_json,
// $key['patient'][0]
// );
// $order_patient_result[] = $key['order_patient_id'];
// }
// // $index++;
// }
// $this->db->trans_commit();
// // $this->db->trans_rollback();
// $this->reply(
// [
// "status" => "OK",
// "message" => "Data berhasil ditambahkan ke one_result",
// "order_patient_id" => $order_patient_result,
// ]);
// // return json_encode(
// // array(
// // "status" => "OK",
// // "message" => "Data berhasil ditambahkan ke one_result",
// // "order_patient_id" => $str_order_patient_id
// // )
// // );
// // }
// // else
// // {
// // // sudah ditambahkan
// // // return json_encode(
// // // array(
// // // 'status' => 'ERR',
// // // 'message' => 'Data Sudah Ditambahkan'
// // // )
// // // );
// // $this->db->trans_rollback();
// // $this->reply(
// // [
// // "status" => "ERR",
// // "message" => "Data sudah ditambahkan ke one_result",
// // "order_patient_id" => $str_order_patient_id
// // ]);
// // }
}
}
?>

View File

@@ -0,0 +1,72 @@
<?php
class Result extends MY_Controller
{
function __construct()
{
parent::__construct();
}
function getResult()
{
try {
if (!$this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$prm = $this->sys_input;
$userid = $this->sys_user['M_UserM_DoctorID'];
$patientId = "";
if (isset($prm['patientId'])) {
$patientId = trim($prm["patientId"]);
} else {
echo json_encode([
"status" => "ERR", "message" => 'Patient id is mandatory',
]);
exit;
}
$sqlCek = "SELECT * FROM one_doctor.order_patient
WHERE OrderPatientID = ?
AND OrderPatientM_DoctorID = ?";
$qryCek =
$this->db->query($sqlCek, [intval($patientId), intval($userid)]);
if (!$qryCek) {
$this->sys_error_db("Error Matching Data");
exit;
}
$resCek = $qryCek->result_array();
if (count($resCek) >= 1) {
$sql = "SELECT oneResultJson FROM one_doctor.one_result
WHERE oneResultOrderPatientID = ?
";
$qry = $this->db->query($sql, [intval($patientId)]);
if (!$qry) {
$this->sys_error_db(
"Error Get Result "
);
exit;
}
$result = $qry->result_array();
$arrResult = array();
if (count($result) > 0) {
foreach ($result as $key => $value) {
$jsonResult = json_decode($value['oneResultJson']);
$arrResult[] = $jsonResult;
}
}
// $result = array(
// $arrResult
// );
// "sql" => $this->db->last_query()
$this->sys_ok($arrResult);
} else {
$this->sys_error_db(
"Not Your Patient " . $userid
);
}
} catch (Exception $exc) {
$message = $exc->getMessage();
$this->sys_error($message);
}
}
}

View File

@@ -0,0 +1,75 @@
<?php
class Result extends MY_Controller
{
function __construct()
{
parent::__construct();
// $this->db = $this->load->database("regional", true);
$this->db_regional = $this->load->database("regional", true);
}
function getResult()
{
try {
if (!$this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$prm = $this->sys_input;
$userid = $this->sys_user['M_UserM_DoctorID'];
$patientId = "";
if (isset($prm['patientId'])) {
$patientId = trim($prm["patientId"]);
} else {
echo json_encode([
"status" => "ERR", "message" => 'Patient id is mandatory',
]);
exit;
}
$sqlCek = "SELECT * FROM one_doctor.order_patient
WHERE OrderPatientID = ?
AND OrderPatientM_DoctorID = ?";
$qryCek =
$this->db_regional->query($sqlCek, [intval($patientId), intval($userid)]);
if (!$qryCek) {
$this->sys_error_db("Error Matching Data");
exit;
}
$resCek = $qryCek->result_array();
if (count($resCek) >= 1) {
$sql = "SELECT oneResultJson FROM one_doctor.one_result
WHERE oneResultOrderPatientID = ?
";
$qry = $this->db_regional->query($sql, [intval($patientId)]);
if (!$qry) {
$this->sys_error_db(
"Error Get Result "
);
exit;
}
$result = $qry->result_array();
$arrResult = array();
if (count($result) > 0) {
foreach ($result as $key => $value) {
$jsonResult = json_decode($value['oneResultJson']);
$arrResult[] = $jsonResult;
}
}
// $result = array(
// $arrResult
// );
// "sql" => $this->db->last_query()
$this->sys_ok($arrResult);
} else {
$this->sys_error_db(
"Not Your Patient " . $userid
);
}
} catch (Exception $exc) {
$message = $exc->getMessage();
$this->sys_error($message);
}
}
}

View File

@@ -0,0 +1,362 @@
<?php
class Xfer_doctormessage_nasional extends MY_Controller
{
var $db;
function __construct()
{
parent::__construct();
$this->db_regional = $this->load->database("regional", true);
}
function index()
{
echo "Api: Dokter Nasional Download Patient";
}
function get($url, $timeout = 60, $c_timeout = 5)
{
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $c_timeout);
curl_setopt($ch, CURLOPT_TIMEOUT, $timeout);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$result = curl_exec($ch);
$err_msg = curl_error($ch);
if ($err_msg != "") {
return json_encode(["status" => "ERR", "message" => $err_msg]);
}
return $result;
}
function reply_err($message)
{
echo json_encode(["status" => "ERR", "data" => $message]);
exit();
}
public function post($url, $data)
{
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 10);
curl_setopt($ch, CURLOPT_TIMEOUT, 10);
curl_setopt($ch, CURLOPT_HTTPHEADER, [
"Content-Type: application/text",
"Content-Length: " . strlen($data),
]);
$result = curl_exec($ch);
if (curl_error($ch) != "") {
echo json_encode([
"status" => "ERR",
"message" => "Http Error : " . curl_error($ch),
]);
curl_close($ch);
exit();
}
curl_close($ch);
return $result;
}
function log($msg)
{
// $dt = Date("Y-m-d H:i:s");
// echo "$dt $msg \n";
echo $msg;
}
function get_param_z()
{
$body_z = file_get_contents("php://input");
$body = gzuncompress($body_z);
return json_decode($body, true);
}
function reply($resp)
{
echo json_encode($resp);
}
function reply_gz($resp)
{
//echo json_encode($resp);
echo gzcompress(json_encode($resp));
}
function get_param()
{
$body = file_get_contents("php://input");
return json_decode($body, true);
}
// getOrderPatient
function getOrderPatient(
$OrderPatientM_DoctorID,
$M_DoctorNasCode
) {
$limit = 20;
$sql_get_order_patient = "SELECT
OrderPatientID,
OrderPatientM_DoctorID,
OrderPatientDate,
OrderPatientM_MouID,
OrderPatientQrCode,
OrderPatientFullName,
OrderPatientDOB,
OrderPatientAddress,
OrderPatientNIK,
OrderPatientHp,
OrderPatientDiagnosa,
OrderPatientNote,
OrderPatientIsConfirmed,
OrderPatientIsActive,
OrderPatientUserID,
OrderPatientCreated,
OrderPatientLastUpdated,
'' as doctor_message
FROM one_doctor.order_patient
JOIN m_doctornas
ON OrderPatientM_DoctorID = M_DoctorNasM_DoctorID
AND M_DoctorNasIsActive = 'Y'
AND OrderPatientIsActive = 'Y'
AND OrderPatientM_DoctorID = $OrderPatientM_DoctorID
AND M_DoctorNasCode = '$M_DoctorNasCode'
ORDER BY OrderPatientID DESC
LIMIT $limit";
// echo $sql_get_order_patient;
// exit;
$qry_get_order_patient = $this->db_regional->query($sql_get_order_patient);
if (!$qry_get_order_patient) {
$response = ["status" => "ERR", "message" => "select order_patient | " .
$this->db_regional->error()["message"], "debug" => $this->db_regional->last_query()];
$this->sys_error($response);
exit;
}
$rows_get_order_patient = $qry_get_order_patient->result_array();
if (count($rows_get_order_patient) > 0) {
// return $rows_get_order_patient;
foreach ($rows_get_order_patient as $key => $vx) {
$order_patient_id = $vx['OrderPatientID'];
// doctor_message
$sql_doctor_message = "SELECT
DoctorMessageID,
DoctorMessageOrderPatientID,
DoctorMessagePesan,
DoctorMessageStatusDownload,
DoctorMessageIsActive,
DoctorMessageUserID,
DoctorMessageCreated,
DoctorMessageUpdated
FROM one_doctor.doctor_message
WHERE DoctorMessageIsActive = 'Y'
AND DoctorMessageOrderPatientID = '$order_patient_id'";
$qry_doctor_message = $this->db_regional->query($sql_doctor_message);
if (!$qry_doctor_message) {
$response = ["status" => "ERR", "message" => "select doctor_message | " .
$this->db_regional->error()["message"], "debug" => $this->db_regional->last_query()];
$this->sys_error($response);
exit;
}
$rows_doctor_message = $qry_doctor_message->result_array();
if (count($rows_doctor_message) > 0) {
$rows_get_order_patient[$key]['doctor_message'] = $rows_doctor_message;
}
else {
$rows_get_order_patient[$key]['doctor_message'] = [];
}
return $rows_get_order_patient;
}
} else {
return [];
}
}
function get_doctormessage_nasional()
{
try {
$prm = $this->get_param();
$limit = 20;
if (isset($prm['limit'])) {
$limit = trim($prm['limit']);
}
// get regional
$sql_get_regional = "SELECT *
FROM s_regional
WHERE S_RegionalIsActive = 'Y'
AND S_RegionalIsDefault = 'Y'";
$qry_get_regional = $this->db_regional->query($sql_get_regional);
if (!$qry_get_regional) {
$response = ["status" => "ERR", "message" => "select s_regional | " .
$this->db_regional->error()["message"], "debug" => $this->db_regional->last_query()];
$this->sys_error($response);
exit;
}
$rows_get_regional = $qry_get_regional->result_array();
$originalRegionalID = $rows_get_regional[0]['S_RegionalID'];
// $originalRegionalIpAddress = "devbandungraya.aplikasi.web.id";
// print_r($originalRegionalID);
// exit;
$sql_order_doknas = "SELECT
M_DoctorNasM_DoctorID,
M_DoctorNasCode,
OrderPatientM_DoctorID
FROM one_doctor.order_patient
JOIN m_doctornas
ON OrderPatientM_DoctorID = M_DoctorNasM_DoctorID
AND M_DoctorNasIsActive = 'Y'
AND OrderPatientIsActive = 'Y'
ORDER BY OrderPatientID DESC
LIMIT $limit";
$qry_order_doknas = $this->db_regional->query($sql_order_doknas);
if (!$qry_order_doknas) {
$response = ["status" => "ERR", "message" => "select order patient | " .
$this->db_regional->error()["message"], "debug" => $this->db_regional->last_query()];
$this->sys_error($response);
exit;
}
$rows_order_doknas = $qry_order_doknas->result_array();
$orderNasional = [];
if (count($rows_order_doknas) > 0) {
foreach ($rows_order_doknas as $key => $vx) {
$M_DoctorNasCodeRegional = $vx['M_DoctorNasCode'];
$OrderPatientM_DoctorID = $vx['OrderPatientM_DoctorID'];
// print_r($this->getOrderPatient($OrderPatientM_DoctorID));
// exit;
// $tabel_order_patient = $this->getOrderPatient($OrderPatientM_DoctorID);
// nembak ke 192.168.250.73
// http://192.168.250.73/one-api/nat_klinisi/Doctorcek/getDoctorRegional
$j_param = json_encode(array(
"nascode" => $M_DoctorNasCodeRegional
));
$size = round(strlen($j_param) / 1024, 2);
$z_param = gzcompress($j_param, 9);
$size_z = round(strlen($z_param) / 1024, 2);
$url = "http://192.168.250.73/one-api/nat_klinisi/Doctorcek/getDoctorRegional";
// $this->log("Post to $url | size : $size k | comprezzed $size_z k");
// $resp = $this->post($url, $z_param);
$resp = $this->post($url, $j_param);
$j_resp = json_decode($resp, true);
// $j_resp_x = $this->get_param_z();
// print_r($resp);
// print_r($j_resp_x);
if ($j_resp["status"] == "OK") {
if (count($j_resp['data']) > 0) {
// $j_resp['data'] merupakan data dari .73
foreach ($j_resp['data'] as $key => $vk) {
$M_DoctorNasCode_ip_73 = $vk['M_DoctorNasCode'];
$regionalTujuanIpAddress = "devkedungdororaya.aplikasi.web.id";
// klu doctor nas nya di regional beda dengan di .73 di continue
if ($M_DoctorNasCode_ip_73 !== $M_DoctorNasCodeRegional) {
continue;
}
if($originalRegionalID == $vk['M_DoctorNasS_RegionalID']){
// $originalRegionalIpAddress = "devbandungraya.aplikasi.web.id";
$originalRegionalIpAddress = $vk['S_RegionalIPAddress'];
}
// yg dikirim hny order tujuan yg bukan dari origin regional id
if ($originalRegionalID != $vk['M_DoctorNasS_RegionalID']) {
$orderNasional[] = array(
"M_DoctorNasCode" => $vk['M_DoctorNasCode'],
"originIpAddress" => $originalRegionalIpAddress,
"originRegionalID" => $originalRegionalID,
"M_DoctorNasS_RegionalID" => $vk['M_DoctorNasS_RegionalID'],
"S_RegionalName" => $vk['S_RegionalName'],
"S_RegionalIPAddress" => $vk['S_RegionalIPAddress'],
// "S_RegionalIPAddress" => $regionalTujuanIpAddress,
"order" => $this->getOrderPatient($OrderPatientM_DoctorID, $M_DoctorNasCode_ip_73)
);
}
}
}
} else {
$this->db->trans_rollback();
// print_r($j_resp['status']);
$this->reply([
"status" => "ERR",
'message' => "Gagal get Data untuk cek dokter nasional",
'debug' => print_r($resp, true)
]);
}
}
// echo json_encode([
// "status" => "OK",
// "orderNasional" => $orderNasional
// ]);
if (count($orderNasional) > 0) {
// sent order ke regional yang bukan origin regional id
foreach ($orderNasional as $key => $vx) {
$j_param = json_encode(array(
"M_DoctorNasCode" => $vx['M_DoctorNasCode'],
"originIpAddress" => $vx['originIpAddress'],
"originRegionalID" => $vx['originRegionalID'],
"M_DoctorNasS_RegionalID" => $vx['M_DoctorNasS_RegionalID'],
"S_RegionalName" => $vx['S_RegionalName'],
// "S_RegionalIPAddress" => $vk['S_RegionalIPAddress'],
"S_RegionalIPAddress" => $vx['S_RegionalIPAddress'],
"order" => $vx['order']
));
// print_r($vx['order']);
// exit;
$url = "http://{$vx['S_RegionalIPAddress']}/one-api/app_doctor/R_xfer_doctormessage_nasional/receive_order";
$resp = $this->post($url, $j_param);
$j_resp = json_decode($resp, true);
// print_r($resp);
// exit;
if ($j_resp["status"] == "OK") {
// print_r($j_resp['data']);
// exit;
echo json_encode($j_resp);
}
}
}
} else {
}
} catch (Exception $exc) {
$message = $exc->getMessage();
$result = array(
'status' => 'err',
"message" => $message,
);
$this->reply_gz($result);
}
}
}

View File

@@ -0,0 +1,423 @@
<?php
class Xfer_order_nasional extends MY_Controller
{
var $db;
function __construct()
{
parent::__construct();
$this->db_regional = $this->load->database("regional", true);
}
function index()
{
echo "Api: Dokter Nasional Download Patient";
}
function get($url, $timeout = 60, $c_timeout = 5)
{
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $c_timeout);
curl_setopt($ch, CURLOPT_TIMEOUT, $timeout);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$result = curl_exec($ch);
$err_msg = curl_error($ch);
if ($err_msg != "") {
return json_encode(["status" => "ERR", "message" => $err_msg]);
}
return $result;
}
function reply_err($message)
{
echo json_encode(["status" => "ERR", "data" => $message]);
exit();
}
public function post($url, $data)
{
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 10);
curl_setopt($ch, CURLOPT_TIMEOUT, 10);
curl_setopt($ch, CURLOPT_HTTPHEADER, [
"Content-Type: application/text",
"Content-Length: " . strlen($data),
]);
$result = curl_exec($ch);
if (curl_error($ch) != "") {
echo json_encode([
"status" => "ERR",
"message" => "Http Error : " . curl_error($ch),
]);
curl_close($ch);
exit();
}
curl_close($ch);
return $result;
}
function log($msg)
{
// $dt = Date("Y-m-d H:i:s");
// echo "$dt $msg \n";
echo $msg;
}
function get_param_z()
{
$body_z = file_get_contents("php://input");
$body = gzuncompress($body_z);
return json_decode($body, true);
}
function reply($resp)
{
echo json_encode($resp);
}
function reply_gz($resp)
{
//echo json_encode($resp);
echo gzcompress(json_encode($resp));
}
function get_param()
{
$body = file_get_contents("php://input");
return json_decode($body, true);
}
// getOrderPatient
function getOrderPatient(
$OrderPatientM_DoctorID,
$M_DoctorNasCode
) {
$limit = 20;
$sql_get_order_patient = "SELECT
OrderPatientID,
OrderPatientM_DoctorID,
OrderPatientDate,
OrderPatientM_MouID,
OrderPatientQrCode,
OrderPatientFullName,
OrderPatientDOB,
OrderPatientAddress,
OrderPatientNIK,
OrderPatientHp,
OrderPatientDiagnosa,
OrderPatientNote,
OrderPatientIsConfirmed,
OrderPatientIsActive,
OrderPatientUserID,
OrderPatientCreated,
OrderPatientLastUpdated,
'' as details
FROM one_doctor.order_patient
JOIN m_doctornas
ON OrderPatientM_DoctorID = M_DoctorNasM_DoctorID
AND M_DoctorNasIsActive = 'Y'
AND OrderPatientIsActive = 'Y'
AND OrderPatientM_DoctorID = $OrderPatientM_DoctorID
AND M_DoctorNasCode = '$M_DoctorNasCode'
ORDER BY OrderPatientID DESC
LIMIT $limit";
// echo $sql_get_order_patient;
// exit;
$qry_get_order_patient = $this->db_regional->query($sql_get_order_patient);
if (!$qry_get_order_patient) {
$response = ["status" => "ERR", "message" => "select order_patient | " .
$this->db_regional->error()["message"], "debug" => $this->db_regional->last_query()];
$this->sys_error($response);
exit;
}
$rows_get_order_patient = $qry_get_order_patient->result_array();
if (count($rows_get_order_patient) > 0) {
// return $rows_get_order_patient;
foreach ($rows_get_order_patient as $key => $vx) {
$order_patient_id = $vx['OrderPatientID'];
// details untuk order_details
$sql_order_details = "SELECT
OrderPatientDetailsID,
OrderPatientDetailsOrderPatientID,
OrderPatientDetailsT_TestID,
OrderPatientDetailsT_TestName,
OrderPatientDetailsPrice,
OrderPatientDetailsIsActive,
OrderPatientDetailsUserID,
OrderPatientDetailsCreated,
OrderPatientDetailsLastUpdated
FROM one_doctor.order_patient_details
WHERE OrderPatientDetailsOrderPatientID = $order_patient_id
AND OrderPatientDetailsIsActive = 'Y'";
$qry_order_detail = $this->db_regional->query($sql_order_details);
if (!$qry_order_detail) {
$response = ["status" => "ERR", "message" => "select order_details | " .
$this->db_regional->error()["message"], "debug" => $this->db_regional->last_query()];
$this->sys_error($response);
exit;
}
$rows_order_detail = $qry_order_detail->result_array();
if (count($rows_order_detail) > 0){
$rows_get_order_patient[$key]['details'] = $rows_order_detail;
}
else {
$rows_get_order_patient[$key]['details'] = [];
}
// order_saran
// $sql_order_saran = "SELECT
// OrderSaranID,
// OrderSaranOrderPatientID,
// OrderKesimpulan,
// OrderSaran,
// OrderSaranIsActive,
// OrderSaranUserID,
// OrderSaranCreated,
// OrderSaranLastUpdated
// FROM one_doctor.order_saran
// WHERE OrderSaranOrderPatientID = $order_patient_id
// AND OrderSaranIsActive = 'Y'";
// $qry_order_saran = $this->db_regional->query($sql_order_saran);
// if (!$qry_order_saran) {
// $response = ["status" => "ERR", "message" => "select order_saran | " .
// $this->db_regional->error()["message"], "debug" => $this->db_regional->last_query()];
// $this->sys_error($response);
// exit;
// }
// $rows_order_saran = $qry_order_saran->result_array();
// if (count($rows_order_saran) > 0) {
// $rows_get_order_patient[$key]['order_saran'] = $rows_order_saran;
// }
// else {
// $rows_get_order_patient[$key]['order_saran'] = [];
// }
// doctor_message
// $sql_doctor_message = "SELECT
// DoctorMessageID,
// DoctorMessageOrderPatientID,
// DoctorMessagePesan,
// DoctorMessageStatusDownload,
// DoctorMessageIsActive,
// DoctorMessageUserID,
// DoctorMessageCreated,
// DoctorMessageUpdated
// FROM one_doctor.doctor_message
// WHERE DoctorMessageIsActive = 'Y'
// AND DoctorMessageOrderPatientID = '$order_patient_id'";
// $qry_doctor_message = $this->db_regional->query($sql_doctor_message);
// if (!$qry_doctor_message) {
// $response = ["status" => "ERR", "message" => "select doctor_message | " .
// $this->db_regional->error()["message"], "debug" => $this->db_regional->last_query()];
// $this->sys_error($response);
// exit;
// }
// $rows_doctor_message = $qry_doctor_message->result_array();
// if (count($rows_doctor_message) > 0) {
// $rows_get_order_patient[$key]['doctor_message'] = $rows_doctor_message;
// }
// else {
// $rows_get_order_patient[$key]['doctor_message'] = [];
// }
return $rows_get_order_patient;
}
} else {
return [];
}
}
function get_order_nasional()
{
try {
$prm = $this->get_param();
$limit = 20;
if (isset($prm['limit'])) {
$limit = trim($prm['limit']);
}
// get regional
$sql_get_regional = "SELECT *
FROM s_regional
WHERE S_RegionalIsActive = 'Y'
AND S_RegionalIsDefault = 'Y'";
$qry_get_regional = $this->db_regional->query($sql_get_regional);
if (!$qry_get_regional) {
$response = ["status" => "ERR", "message" => "select s_regional | " .
$this->db_regional->error()["message"], "debug" => $this->db_regional->last_query()];
$this->sys_error($response);
exit;
}
$rows_get_regional = $qry_get_regional->result_array();
$originalRegionalID = $rows_get_regional[0]['S_RegionalID'];
// $originalRegionalIpAddress = "devbandungraya.aplikasi.web.id";
// print_r($originalRegionalID);
// exit;
$sql_order_doknas = "SELECT
M_DoctorNasM_DoctorID,
M_DoctorNasCode,
OrderPatientM_DoctorID
FROM one_doctor.order_patient
JOIN m_doctornas
ON OrderPatientM_DoctorID = M_DoctorNasM_DoctorID
AND M_DoctorNasIsActive = 'Y'
AND OrderPatientIsActive = 'Y'
ORDER BY OrderPatientID DESC
LIMIT $limit";
$qry_order_doknas = $this->db_regional->query($sql_order_doknas);
if (!$qry_order_doknas) {
$response = ["status" => "ERR", "message" => "select order patient | " .
$this->db_regional->error()["message"], "debug" => $this->db_regional->last_query()];
$this->sys_error($response);
exit;
}
$rows_order_doknas = $qry_order_doknas->result_array();
$orderNasional = [];
if (count($rows_order_doknas) > 0) {
foreach ($rows_order_doknas as $key => $vx) {
$M_DoctorNasCodeRegional = $vx['M_DoctorNasCode'];
$OrderPatientM_DoctorID = $vx['OrderPatientM_DoctorID'];
// print_r($this->getOrderPatient($OrderPatientM_DoctorID));
// exit;
// $tabel_order_patient = $this->getOrderPatient($OrderPatientM_DoctorID);
// nembak ke 192.168.250.73
// http://192.168.250.73/one-api/nat_klinisi/Doctorcek/getDoctorRegional
$j_param = json_encode(array(
"nascode" => $M_DoctorNasCodeRegional
));
$size = round(strlen($j_param) / 1024, 2);
$z_param = gzcompress($j_param, 9);
$size_z = round(strlen($z_param) / 1024, 2);
$url = "http://192.168.250.73/one-api/nat_klinisi/Doctorcek/getDoctorRegional";
// $this->log("Post to $url | size : $size k | comprezzed $size_z k");
// $resp = $this->post($url, $z_param);
$resp = $this->post($url, $j_param);
$j_resp = json_decode($resp, true);
// $j_resp_x = $this->get_param_z();
// print_r($resp);
// print_r($j_resp_x);
if ($j_resp["status"] == "OK") {
if (count($j_resp['data']) > 0) {
// $j_resp['data'] merupakan data dari .73
foreach ($j_resp['data'] as $key => $vk) {
$M_DoctorNasCode_ip_73 = $vk['M_DoctorNasCode'];
$regionalTujuanIpAddress = "devkedungdororaya.aplikasi.web.id";
// klu doctor nas nya di regional beda dengan di .73 di continue
if ($M_DoctorNasCode_ip_73 !== $M_DoctorNasCodeRegional) {
continue;
}
if($originalRegionalID == $vk['M_DoctorNasS_RegionalID']){
// $originalRegionalIpAddress = "devbandungraya.aplikasi.web.id";
$originalRegionalIpAddress = $vk['S_RegionalIPAddress'];
}
// yg dikirim hny order tujuan yg bukan dari origin regional id
if ($originalRegionalID != $vk['M_DoctorNasS_RegionalID']) {
$orderNasional[] = array(
"M_DoctorNasCode" => $vk['M_DoctorNasCode'],
"originIpAddress" => $originalRegionalIpAddress,
"originRegionalID" => $originalRegionalID,
"M_DoctorNasS_RegionalID" => $vk['M_DoctorNasS_RegionalID'],
"S_RegionalName" => $vk['S_RegionalName'],
"S_RegionalIPAddress" => $vk['S_RegionalIPAddress'],
// "S_RegionalIPAddress" => $regionalTujuanIpAddress,
"order" => $this->getOrderPatient($OrderPatientM_DoctorID, $M_DoctorNasCode_ip_73)
);
}
}
}
} else {
$this->db->trans_rollback();
// print_r($j_resp['status']);
$this->reply([
"status" => "ERR",
'message' => "Gagal get Data untuk cek dokter nasional",
'debug' => print_r($resp, true)
]);
}
}
// echo json_encode([
// "status" => "OK",
// "orderNasional" => $orderNasional
// ]);
if (count($orderNasional) > 0) {
// sent order ke regional yang bukan origin regional id
foreach ($orderNasional as $key => $vx) {
$j_param = json_encode(array(
"M_DoctorNasCode" => $vx['M_DoctorNasCode'],
"originIpAddress" => $vx['originIpAddress'],
"originRegionalID" => $vx['originRegionalID'],
"M_DoctorNasS_RegionalID" => $vx['M_DoctorNasS_RegionalID'],
"S_RegionalName" => $vx['S_RegionalName'],
// "S_RegionalIPAddress" => $vk['S_RegionalIPAddress'],
"S_RegionalIPAddress" => $vx['S_RegionalIPAddress'],
"order" => $vx['order']
));
// print_r($vx['order']);
// exit;
$url = "http://{$vx['S_RegionalIPAddress']}/one-api/app_doctor/R_xfer_order_nasional/receive_order";
$resp = $this->post($url, $j_param);
$j_resp = json_decode($resp, true);
// print_r($resp);
// exit;
if ($j_resp["status"] == "OK") {
// print_r($j_resp['data']);
// exit;
echo json_encode($j_resp);
}
}
}
} else {
}
} catch (Exception $exc) {
$message = $exc->getMessage();
$result = array(
'status' => 'err',
"message" => $message,
);
$this->reply_gz($result);
}
}
}

View File

@@ -0,0 +1,140 @@
<?php
class Xfer_result_nasional extends MY_Controller
{
var $db;
function __construct()
{
parent::__construct();
}
function index()
{
echo "Api: REGIONAL SEND RESULT ";
}
function getresult()
{
try {
$sql_order = "SELECT
map_rx_order.*,
one_result.*,
order_patient.*
FROM one_doctor.order_patient
JOIN one_doctor.one_result ON OrderPatientID = oneResultOrderPatientID
AND OrderPatientIsActive = 'Y'
JOIN one_doctor.map_rx_order
ON OrderPatientID = mapRxOrderNewOrderPatientID
AND mapRxOrderIsActive = 'Y'
AND oneResultDate > mapRxOrderSendDate";
$qry_order = $this->db->query($sql_order, []);
if (!$qry_order) {
$message = $this->db->error();
$this->sys_error($message);
exit;
}
$order = $qry_order->result_array();
$arrRegionalIP = [];
$arrOrderSend = array();
for ($i = 0; $i < count($order); $i++) {
if (!in_array($order[$i]['mapRxOrderOriginIPAddress'], $arrRegionalIP)) {
$arrRegionalIP[] = $order[$i]['mapRxOrderOriginIPAddress'];
}
}
for ($i = 0; $i < count($arrRegionalIP); $i++) {
$arrData = [];
for ($k = 0; $k < count($order); $k++) {
if ($arrRegionalIP[$i] == $order[$k]['mapRxOrderOriginIPAddress']) {
$arrData[] = $order[$k];
}
}
$arrOrderSend[] = $arrData;
}
$arrResp = [];
$resp = array(
"status" => "OK",
"order" => $arrOrderSend
);
// echo json_encode($resp);
// exit;
for ($i = 0; $i < count($arrOrderSend); $i++) {
$resp = array(
"status" => "OK",
"IP" => $arrOrderSend[$i][0]['mapRxOrderOriginIPAddress'],
"order" => $arrOrderSend[$i]
);
$rawResp = $this->post("http://{$arrOrderSend[$i][0]['mapRxOrderOriginIPAddress']}/one-api/app_doctor/R_xfer_result_nasional/receive", gzcompress(json_encode($resp)));
// $rawResp = $this->post("http://{$arrOrderSend[$i][0]['mapRxOrderOriginIPAddress']}/one-api/app_doctor/R_xfer_result_nasional/receive", json_encode($resp));
$rst = gzuncompress($rawResp);
// $rst = json_decode($rawResp, true);
$dcdRst = json_decode($rst, true);
$arrResp[] = $dcdRst;
for ($q = 0; $q < count($dcdRst["order_success"]); $q++) {
$sql_update = "UPDATE one_doctor.map_rx_order
SET mapRxOrderSendDate = NOW()
, mapRxOrderIsSent = 'Y'
WHERE mapRxOrderNewOrderPatientID = ?";
$qry_update = $this->db->query($sql_update, [$dcdRst["order_success"][$q]]);
if (!$qry_update) {
$message = $this->db->error();
$this->sys_error($message);
exit;
}
}
}
// $this->reply_gz($resp);
// echo json_encode($resp);
$finalResult = array(
"status" => "OK",
"message" => $arrResp
);
echo json_encode($finalResult);
} catch (Exception $exc) {
$message = $exc->getMessage();
$this->sys_error($message);
}
}
function get_param_z()
{
$body_z = file_get_contents("php://input");
$body = gzuncompress($body_z);
return json_decode($body, true);
}
function reply($resp)
{
echo json_encode($resp);
}
function reply_gz($resp)
{
//echo json_encode($resp);
echo gzcompress(json_encode($resp));
}
public function post($url, $data)
{
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 10);
curl_setopt($ch, CURLOPT_TIMEOUT, 10);
curl_setopt($ch, CURLOPT_HTTPHEADER, [
"Content-Type: application/text",
"Content-Length: " . strlen($data),
]);
$result = curl_exec($ch);
if (curl_error($ch) != "") {
echo json_encode([
"status" => "ERR",
"message" => "Http Error : " . curl_error($ch),
]);
curl_close($ch);
exit();
}
curl_close($ch);
return $result;
}
}

View File

@@ -0,0 +1,389 @@
<?php
class Xfer_saran_nasional extends MY_Controller
{
var $db;
function __construct()
{
parent::__construct();
$this->db_regional = $this->load->database("regional", true);
}
function index()
{
echo "Api: Dokter Nasional Download Patient";
}
function get($url, $timeout = 60, $c_timeout = 5)
{
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $c_timeout);
curl_setopt($ch, CURLOPT_TIMEOUT, $timeout);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$result = curl_exec($ch);
$err_msg = curl_error($ch);
if ($err_msg != "") {
return json_encode(["status" => "ERR", "message" => $err_msg]);
}
return $result;
}
function reply_err($message)
{
echo json_encode(["status" => "ERR", "data" => $message]);
exit();
}
public function post($url, $data)
{
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 10);
curl_setopt($ch, CURLOPT_TIMEOUT, 10);
curl_setopt($ch, CURLOPT_HTTPHEADER, [
"Content-Type: application/text",
"Content-Length: " . strlen($data),
]);
$result = curl_exec($ch);
if (curl_error($ch) != "") {
echo json_encode([
"status" => "ERR",
"message" => "Http Error : " . curl_error($ch),
]);
curl_close($ch);
exit();
}
curl_close($ch);
return $result;
}
function log($msg)
{
// $dt = Date("Y-m-d H:i:s");
// echo "$dt $msg \n";
echo $msg;
}
function get_param_z()
{
$body_z = file_get_contents("php://input");
$body = gzuncompress($body_z);
return json_decode($body, true);
}
function reply($resp)
{
echo json_encode($resp);
}
function reply_gz($resp)
{
//echo json_encode($resp);
echo gzcompress(json_encode($resp));
}
function get_param()
{
$body = file_get_contents("php://input");
return json_decode($body, true);
}
// getOrderPatient
function getOrderPatient(
$OrderPatientM_DoctorID,
$M_DoctorNasCode
) {
$limit = 20;
$sql_get_order_patient = "SELECT
OrderPatientID,
OrderPatientM_DoctorID,
OrderPatientDate,
OrderPatientM_MouID,
OrderPatientQrCode,
OrderPatientFullName,
OrderPatientDOB,
OrderPatientAddress,
OrderPatientNIK,
OrderPatientHp,
OrderPatientDiagnosa,
OrderPatientNote,
OrderPatientIsConfirmed,
OrderPatientIsActive,
OrderPatientUserID,
OrderPatientCreated,
OrderPatientLastUpdated,
'' as order_saran
FROM one_doctor.order_patient
JOIN m_doctornas
ON OrderPatientM_DoctorID = M_DoctorNasM_DoctorID
AND M_DoctorNasIsActive = 'Y'
AND OrderPatientIsActive = 'Y'
AND OrderPatientM_DoctorID = $OrderPatientM_DoctorID
AND M_DoctorNasCode = '$M_DoctorNasCode'
ORDER BY OrderPatientID DESC
LIMIT $limit";
// echo $sql_get_order_patient;
// exit;
$qry_get_order_patient = $this->db_regional->query($sql_get_order_patient);
if (!$qry_get_order_patient) {
$response = ["status" => "ERR", "message" => "select order_patient | " .
$this->db_regional->error()["message"], "debug" => $this->db_regional->last_query()];
$this->sys_error($response);
exit;
}
$rows_get_order_patient = $qry_get_order_patient->result_array();
if (count($rows_get_order_patient) > 0) {
// return $rows_get_order_patient;
foreach ($rows_get_order_patient as $key => $vx) {
$order_patient_id = $vx['OrderPatientID'];
// order saran
$sql_order_saran = "SELECT
OrderSaranID,
OrderSaranOrderPatientID,
OrderKesimpulan,
OrderSaran,
OrderSaranIsActive,
OrderSaranUserID,
OrderSaranCreated,
OrderSaranLastUpdated,
'' as saran_log
FROM one_doctor.order_saran
WHERE OrderSaranOrderPatientID = $order_patient_id
AND OrderSaranIsActive = 'Y'";
$qry_order_saran = $this->db_regional->query($sql_order_saran);
if (!$qry_order_saran) {
$response = ["status" => "ERR", "message" => "select order_saran | " .
$this->db_regional->error()["message"], "debug" => $this->db_regional->last_query()];
$this->sys_error($response);
exit;
}
$rows_order_saran = $qry_order_saran->result_array();
if (count($rows_order_saran) > 0) {
$rows_get_order_patient[$key]['order_saran'] = $rows_order_saran;
foreach($rows_order_saran as $ks => $val){
$order_saran_id = $val['OrderSaranID'];
$sql_saran_log = "SELECT *
FROM one_doctor.download_saran_log
WHERE downloadSaranLogOrderSaranID = $order_saran_id";
$qry_order_saran_log = $this->db_regional->query($sql_saran_log);
if (!$qry_order_saran_log) {
$response = ["status" => "ERR", "message" => "select order_saran_log | " .
$this->db_regional->error()["message"], "debug" => $this->db_regional->last_query()];
$this->sys_error($response);
exit;
}
$rows_order_saran_log = $qry_order_saran_log->result_array();
if(count($rows_order_saran_log) > 0){
$rows_get_order_patient[$key]['order_saran'][$ks]['saran_log'] = $rows_order_saran_log;
}else{
$rows_get_order_patient[$key]['order_saran'][$ks]['saran_log'] = [];
}
}
}
else {
$rows_get_order_patient[$key]['order_saran'] = [];
}
return $rows_get_order_patient;
}
} else {
return [];
}
}
function get_saran_nasional()
{
try {
$prm = $this->get_param();
$limit = 20;
if (isset($prm['limit'])) {
$limit = trim($prm['limit']);
}
// get regional
$sql_get_regional = "SELECT *
FROM s_regional
WHERE S_RegionalIsActive = 'Y'
AND S_RegionalIsDefault = 'Y'";
$qry_get_regional = $this->db_regional->query($sql_get_regional);
if (!$qry_get_regional) {
$response = ["status" => "ERR", "message" => "select s_regional | " .
$this->db_regional->error()["message"], "debug" => $this->db_regional->last_query()];
$this->sys_error($response);
exit;
}
$rows_get_regional = $qry_get_regional->result_array();
$originalRegionalID = $rows_get_regional[0]['S_RegionalID'];
// $originalRegionalIpAddress = "devbandungraya.aplikasi.web.id";
// print_r($originalRegionalID);
// exit;
$sql_order_doknas = "SELECT
M_DoctorNasM_DoctorID,
M_DoctorNasCode,
OrderPatientM_DoctorID
FROM one_doctor.order_patient
JOIN m_doctornas
ON OrderPatientM_DoctorID = M_DoctorNasM_DoctorID
AND M_DoctorNasIsActive = 'Y'
AND OrderPatientIsActive = 'Y'
ORDER BY OrderPatientID DESC
LIMIT $limit";
$qry_order_doknas = $this->db_regional->query($sql_order_doknas);
if (!$qry_order_doknas) {
$response = ["status" => "ERR", "message" => "select order patient | " .
$this->db_regional->error()["message"], "debug" => $this->db_regional->last_query()];
$this->sys_error($response);
exit;
}
$rows_order_doknas = $qry_order_doknas->result_array();
$orderNasional = [];
if (count($rows_order_doknas) > 0) {
foreach ($rows_order_doknas as $key => $vx) {
$M_DoctorNasCodeRegional = $vx['M_DoctorNasCode'];
$OrderPatientM_DoctorID = $vx['OrderPatientM_DoctorID'];
// print_r($this->getOrderPatient($OrderPatientM_DoctorID));
// exit;
// $tabel_order_patient = $this->getOrderPatient($OrderPatientM_DoctorID);
// nembak ke 192.168.250.73
// http://192.168.250.73/one-api/nat_klinisi/Doctorcek/getDoctorRegional
$j_param = json_encode(array(
"nascode" => $M_DoctorNasCodeRegional
));
$size = round(strlen($j_param) / 1024, 2);
$z_param = gzcompress($j_param, 9);
$size_z = round(strlen($z_param) / 1024, 2);
$url = "http://192.168.250.73/one-api/nat_klinisi/Doctorcek/getDoctorRegional";
// $this->log("Post to $url | size : $size k | comprezzed $size_z k");
// $resp = $this->post($url, $z_param);
$resp = $this->post($url, $j_param);
$j_resp = json_decode($resp, true);
// $j_resp_x = $this->get_param_z();
// print_r($resp);
// print_r($j_resp_x);
if ($j_resp["status"] == "OK") {
if (count($j_resp['data']) > 0) {
// $j_resp['data'] merupakan data dari .73
foreach ($j_resp['data'] as $key => $vk) {
$M_DoctorNasCode_ip_73 = $vk['M_DoctorNasCode'];
$regionalTujuanIpAddress = "devkedungdororaya.aplikasi.web.id";
// klu doctor nas nya di regional beda dengan di .73 di continue
if ($M_DoctorNasCode_ip_73 !== $M_DoctorNasCodeRegional) {
continue;
}
if($originalRegionalID == $vk['M_DoctorNasS_RegionalID']){
// $originalRegionalIpAddress = "devbandungraya.aplikasi.web.id";
$originalRegionalIpAddress = $vk['S_RegionalIPAddress'];
}
// yg dikirim hny order tujuan yg bukan dari origin regional id
if ($originalRegionalID != $vk['M_DoctorNasS_RegionalID']) {
$orderNasional[] = array(
"M_DoctorNasCode" => $vk['M_DoctorNasCode'],
"originIpAddress" => $originalRegionalIpAddress,
"originRegionalID" => $originalRegionalID,
"M_DoctorNasS_RegionalID" => $vk['M_DoctorNasS_RegionalID'],
"S_RegionalName" => $vk['S_RegionalName'],
"S_RegionalIPAddress" => $vk['S_RegionalIPAddress'],
// "S_RegionalIPAddress" => $regionalTujuanIpAddress,
"order" => $this->getOrderPatient($OrderPatientM_DoctorID, $M_DoctorNasCode_ip_73)
);
}
}
}
} else {
$this->db->trans_rollback();
// print_r($j_resp['status']);
$this->reply([
"status" => "ERR",
'message' => "Gagal get Data untuk cek dokter nasional",
'debug' => print_r($resp, true)
]);
}
}
// echo json_encode([
// "status" => "OK",
// "orderNasional" => $orderNasional
// ]);
if (count($orderNasional) > 0) {
// sent order ke regional yang bukan origin regional id
foreach ($orderNasional as $key => $vx) {
$j_param = json_encode(array(
"M_DoctorNasCode" => $vx['M_DoctorNasCode'],
"originIpAddress" => $vx['originIpAddress'],
"originRegionalID" => $vx['originRegionalID'],
"M_DoctorNasS_RegionalID" => $vx['M_DoctorNasS_RegionalID'],
"S_RegionalName" => $vx['S_RegionalName'],
// "S_RegionalIPAddress" => $vk['S_RegionalIPAddress'],
"S_RegionalIPAddress" => $vx['S_RegionalIPAddress'],
"order" => $vx['order']
));
// print_r($vx['order']);
// exit;
$url = "http://{$vx['S_RegionalIPAddress']}/one-api/app_doctor/R_xfer_saran_nasional/receive_order";
$resp = $this->post($url, $j_param);
$j_resp = json_decode($resp, true);
// print_r($resp);
// exit;
if ($j_resp["status"] == "OK") {
// print_r($j_resp['data']);
// exit;
echo json_encode($j_resp);
}
}
}
} else {
}
} catch (Exception $exc) {
$message = $exc->getMessage();
$result = array(
'status' => 'err',
"message" => $message,
);
$this->reply_gz($result);
}
}
}

View File

@@ -0,0 +1,879 @@
<?php
class Nonlabtemplatev3 extends MY_Controller
{
var $db;
public function index()
{
echo "NON LAN TEMPLATE API";
}
public function __construct()
{
parent::__construct();
}
function search()
{
try {
if (!$this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$prm = $this->sys_input;
$search = "";
if (isset($prm['search'])) {
$search = trim($prm["search"]);
if ($search != "") {
$search = '%' . $prm['search'] . '%';
} else {
$search = '%%';
}
}
$number_offset = 0;
$number_limit = 10;
if ($prm["current_page"] > 0) {
$number_offset = ($prm["current_page"] - 1) * $number_limit;
}
$sql_tot = "SELECT COUNT(*) as total
FROM nonlab_template
WHERE NonlabTemplateIsActive = 'Y'
AND (NonlabTemplateName LIKE ?)";
$qry_tot = $this->db->query($sql_tot, [$search]);
$tot_count = 0;
$tot_page = 0;
if ($qry_tot) {
$tot_count = $qry_tot->result_array()[0]["total"];
$tot_page = ceil($tot_count / $number_limit);
} else {
$this->sys_error_db("nonlab template count", $this->db);
exit;
}
$sql = "SELECT
NonlabTemplateID,
NonlabTemplateName,
NonlabTemplateFlagOther,
NonlabTemplateIsActive,
NonlabTemplateCreated,
NonlabTemplateLastUpdated
FROM nonlab_template
WHERE NonlabTemplateIsActive = 'Y'
AND (NonlabTemplateName LIKE ?)
ORDER BY NonlabTemplateID ASC
LIMIT ? OFFSET ?";
$qry = $this->db->query($sql, [$search, $number_limit, $number_offset]);
if ($qry) {
$rows = $qry->result_array();
} else {
$this->sys_error_db("select nonlab template", $this->db);
exit;
}
$result = array(
"total_page" => $tot_page,
"total_filter" => $tot_count,
"records" => $rows
);
$this->sys_ok($result);
} catch (Exception $exc) {
$message = $exc->getMessage();
$this->sys_error($message);
}
}
function addnonlab()
{
try {
if (!$this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$this->db->trans_begin();
$prm = $this->sys_input;
$userid = $this->sys_user['M_UserID'];
$name = "";
if (isset($prm["name"])) {
$name = trim($prm["name"]);
}
$isfisik = "";
if (isset($prm["isfisik"])) {
$isfisik = trim($prm["isfisik"]);
}
$sql = "INSERT INTO nonlab_template(
NonlabTemplateName,
NonlabTemplateFlagOther,
NonlabTemplateCreated,
NonlabTemplateCreatedUserID,
NonlabTemplateLastUpdated,
NonlabTemplateLastUpdatedUserID
) VALUES(?,?,NOW(),?,NOW(),?)";
$qry = $this->db->query($sql, array(
$name,
$isfisik,
$userid,
$userid
));
$last_qry = $this->db->last_query();
if (!$qry) {
$this->db->trans_rollback();
$error = array(
"message" => $this->db->error()["message"],
"sql" => $last_qry
);
$this->sys_error_db($error, $this->db);
exit;
}
$this->db->trans_commit();
$result = array(
"total" => 1,
"affected_rows" => $this->db->affected_rows()
);
$this->sys_ok($result);
} catch (Exception $exc) {
$message = $exc->getMessage();
$this->sys_error($message);
}
}
function editnonlab()
{
try {
if (!$this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$this->db->trans_begin();
$prm = $this->sys_input;
$userid = $this->sys_user['M_UserID'];
$name = "";
if (isset($prm["name"])) {
$name = trim($prm["name"]);
}
$isfisik = "";
if (isset($prm["isfisik"])) {
$isfisik = trim($prm["isfisik"]);
}
$id = "";
if (isset($prm["id"])) {
$id = trim($prm["id"]);
}
$sql = "UPDATE nonlab_template
SET NonlabTemplateName = ?,
NonlabTemplateFlagOther = ?,
NonlabTemplateLastUpdated = NOW(),
NonlabTemplateLastUpdatedUserID = ?
WHERE NonlabTemplateID = ?";
$qry = $this->db->query($sql, array($name, $isfisik, $userid, $id));
$last_qry = $this->db->last_query();
if (!$qry) {
$this->db->trans_rollback();
$error = array(
"message" => $this->db->error()["message"],
"sql" => $last_qry
);
$this->sys_error_db($error, $this->db);
exit;
}
$this->db->trans_commit();
$result = array(
"total" => 1,
"affected_rows" => $this->db->affected_rows()
);
$this->sys_ok($result);
} catch (Exception $exc) {
$message = $exc->getMessage();
$this->sys_error($message);
}
}
function deletenonlab()
{
try {
if (!$this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$this->db->trans_begin();
$prm = $this->sys_input;
$userid = $this->sys_user['M_UserID'];
$id = "";
if (isset($prm["id"])) {
$id = trim($prm["id"]);
}
$sql = "UPDATE nonlab_template
SET NonlabTemplateIsActive = 'N',
NonlabTemplateDelete = NOW(),
NonlabTemplateDeleteUserID = ?
WHERE NonlabTemplateID = ?";
$qry = $this->db->query($sql, array($userid, $id));
$last_qry = $this->db->last_query();
if (!$qry) {
$this->db->trans_rollback();
$error = array(
"message" => $this->db->error()["message"],
"sql" => $last_qry
);
$this->sys_error_db($error, $this->db);
exit;
}
$this->db->trans_commit();
$result = array(
"total" => 1,
"affected_rows" => $this->db->affected_rows()
);
$this->sys_ok($result);
} catch (Exception $exc) {
$message = $exc->getMessage();
$this->sys_error($message);
}
}
function searchdetail()
{
try {
if (!$this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$prm = $this->sys_input;
$search = "";
if (isset($prm['search'])) {
$search = trim($prm["search"]);
if ($search != "") {
$search = '%' . $prm['search'] . '%';
} else {
$search = '%%';
}
}
$nonlabID = $prm["nonlabID"];
$number_offset = 0;
$number_limit = 10;
if ($prm["current_page"] > 0) {
$number_offset = ($prm["current_page"] - 1) * $number_limit;
}
$sql_total = "SELECT COUNT(*) as total
FROM nonlab_template_detail
WHERE NonlabTemplateDetailNonlabTemplateID = ?
AND NonlabTemplateDetailIsActive = 'Y'
AND (NonlabTemplateDetailCode LIKE ? OR NonlabTemplateDetailName LIKE ?)";
$qry_total = $this->db->query($sql_total, [$nonlabID, $search, $search]);
$tot_count = 0;
$tot_page = 0;
if ($qry_total) {
$tot_count = $qry_total->result_array()[0]["total"];
$tot_page = ceil($tot_count / $number_limit);
} else {
$this->sys_error_db("nonlab template detail count", $this->db);
exit;
}
$sql = "SELECT
NonlabTemplateDetailID,
NonlabTemplateDetailNonlabTemplateID,
NonlabTemplateDetailCode,
NonlabTemplateDetailGender,
CASE
WHEN NonlabTemplateDetailGender = 'male' THEN 'Laki-laki'
WHEN NonlabTemplateDetailGender = 'female' THEN 'Perempuan'
ELSE 'Semua'
END AS NonlabTemplateDetailGenderText,
NonlabTemplateDetailName,
IFNULL(NonlabTemplateDetailLangName, NonlabTemplateDetailName) AS NonlabTemplateDetailNameLangEng,
NonlabTemplateDetaiNat_UnitID as unit_id,
unit.Nat_UnitName as unit_name,
IFNULL(NonlabTemplateDetailLangNat_UnitID,0) as unit_eng_id,
uniteng.Nat_UnitName AS unit_eng_name,
NonlabTemplateDetailFlagActive,
NonlabTemplateDetaiM_LangID,
NonlabTemplateDetailIsActive
FROM nonlab_template_detail
LEFT JOIN nonlab_template_detail_lang ON NonlabTemplateDetailLangNonlabTemplateDetailID = NonlabTemplateDetailID AND
NonlabTemplateDetailLangM_LangID = '2' AND NonlabTemplateDetailLangIsActive = 'Y'
LEFT JOIN nat_unit unit ON unit.Nat_UnitID = NonlabTemplateDetaiNat_UnitID AND unit.Nat_UnitIsActive = 'Y'
LEFT JOIN nat_unit uniteng ON uniteng.Nat_UnitID = NonlabTemplateDetailLangNat_UnitID AND uniteng.Nat_UnitIsActive = 'Y'
WHERE NonlabTemplateDetailNonlabTemplateID = ?
AND NonlabTemplateDetailIsActive = 'Y'
AND (NonlabTemplateDetailCode LIKE ? OR NonlabTemplateDetailName LIKE ?)
limit ? offset ?";
$qry = $this->db->query($sql, [$nonlabID, $search, $search, $number_limit, $number_offset]);
if ($qry) {
$rows = $qry->result_array();
} else {
$this->sys_error_db("select nonlab template detail", $this->db);
exit;
}
$result = array(
"total_page" => $tot_page,
"total_filter" => $tot_count,
"records" => $rows
);
$this->sys_ok($result);
} catch (Exception $exc) {
$message = $exc->getMessage();
$this->sys_error($message);
}
}
function getunits()
{
try {
$rst = array(
array('id' => '0', 'value' => 'Tanpa Satuan'),
);
$sql = "SELECT Nat_UnitID, Nat_UnitName FROM nat_unit WHERE Nat_UnitIsActive = 'Y'";
$qry = $this->db->query($sql);
$rows = $qry->result_array();
foreach ($rows as $row) {
$rst[] = array('id' => $row['Nat_UnitID'], 'value' => $row['Nat_UnitName']);
}
$this->sys_ok($rst);
} catch (Exception $exc) {
$message = $exc->getMessage();
$this->sys_error($message);
}
}
function adddetail()
{
try {
if (!$this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$this->db->trans_begin();
$prm = $this->sys_input;
$userid = $this->sys_user['M_UserID'];
$nonlabid = intval($prm["nonlabid"]);
if ($nonlabid === 0) {
$this->sys_error("Anda belum memilih nonlab template, silahkan pilih nonlab template dulu");
exit;
}
$name = "";
if (isset($prm["name"])) {
$name = trim($prm["name"]);
}
if($name == ""){
$this->sys_error("Anda belum mengisi nama");
exit;
}
$name_eng = "";
if (isset($prm["name_eng"])) {
$name_eng = trim($prm["name_eng"]);
}
$code = "";
if (isset($prm["code"])) {
$code = trim($prm["code"]);
}
if($code == ""){
$this->sys_error("Anda belum mengisi kode");
exit;
}
$gender = "";
if (isset($prm["gender"])) {
$gender = trim($prm["gender"]);
}
if($gender == ""){
$this->sys_error("Anda belum mengisi gender");
exit;
}
$unit = "";
if (isset($prm["unit"])) {
$unit = trim($prm["unit"]);
}
$uniteng = "";
if (isset($prm["uniteng"])) {
$uniteng = trim($prm["uniteng"]);
}
// $nonlabid = "";
// if (isset($prm["nonlabid"])) {
// $nonlabid = trim($prm["nonlabid"]);
// }
$sql = "INSERT INTO nonlab_template_detail(
NonlabTemplateDetailNonlabTemplateID,
NonlabTemplateDetailGender,
NonlabTemplateDetaiNat_UnitID,
NonlabTemplateDetailCode,
NonlabTemplateDetailName,
NonlabTemplateDetailCreated,
NonlabTemplateDetailCreatedUserID,
NonlabTemplateDetailLastUpdated,
NonlabTemplateDetailLastUpdatedUserID
) VALUES(?,?,?,?,?,NOW(),?,NOW(),?)";
$qry = $this->db->query($sql, array(
$nonlabid,
$gender,
$unit,
$code,
$name,
$userid,
$userid
));
$last_qry = $this->db->last_query();
if (!$qry) {
$this->db->trans_rollback();
$error = array(
"message" => $this->db->error()["message"],
"sql" => $last_qry
);
$this->sys_error_db($error, $this->db);
exit;
}
$last_id = $this->db->insert_id();
$sql_lang = "INSERT INTO nonlab_template_detail_lang(
NonlabTemplateDetailLangNonlabTemplateDetailID,
NonlabTemplateDetailLangGender,
NonlabTemplateDetailLangM_LangID,
NonlabTemplateDetailLangName,
NonlabTemplateDetailLangNat_UnitID,
NonlabTemplateDetailLangCreated,
NonlabTemplateDetailLangCreatedUserID,
NonlabTemplateDetailLangLastUpdated,
NonlabTemplateDetailLangLastUpdatedUserID
) VALUES(?,?,?,?,?,NOW(),?,NOW(),?)";
$qry_lang = $this->db->query($sql_lang, array(
$last_id,
$gender,
"2",
$name_eng,
$uniteng,
$userid,
$userid
));
$this->db->trans_commit();
$result = array(
"total" => 1,
"affected_rows" => $this->db->affected_rows()
);
$this->sys_ok($result);
} catch (Exception $exc) {
$message = $exc->getMessage();
$this->sys_error($message);
}
}
function deletedetail()
{
try {
if (!$this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$this->db->trans_begin();
$prm = $this->sys_input;
$userid = $this->sys_user['M_UserID'];
$id = "";
if (isset($prm["id"])) {
$id = trim($prm["id"]);
}
$sql = "UPDATE nonlab_template_detail
SET NonlabTemplateDetailIsActive = 'N',
NonlabTemplateDetailDelete = NOW(),
NonlabTemplateDetailDeleteUserID = ?
WHERE NonlabTemplateDetailID = ?";
$qry = $this->db->query($sql, array($userid, $id));
$last_qry = $this->db->last_query();
if (!$qry) {
$this->db->trans_rollback();
$error = array(
"message" => $this->db->error()["message"],
"sql" => $last_qry
);
$this->sys_error_db($error, $this->db);
exit;
}
$this->db->trans_commit();
$result = array(
"total" => 1,
"affected_rows" => $this->db->affected_rows()
);
$this->sys_ok($result);
} catch (Exception $exc) {
$message = $exc->getMessage();
$this->sys_error($message);
}
}
function saveeditflag()
{
try {
if (!$this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$this->db->trans_begin();
$prm = $this->sys_input;
$userid = $this->sys_user['M_UserID'];
$flagstatus = $prm['flagstatus'];
$templatedetailid = $prm['templatedetailid'];
if ($flagstatus == "Y") {
$sql = "UPDATE nonlab_template_detail
SET NonlabTemplateDetailFlagActive = 'Y',
NonlabTemplateDetailLastUpdated = NOW(),
NonlabTemplateDetailLastUpdatedUserID = ?
WHERE NonlabTemplateDetailID = ?";
$qry = $this->db->query($sql, array(
$userid,
$templatedetailid
));
// echo $this->db->last_query();
// exit;
if (!$qry) {
$this->sys_error_db("nonlab template detail avtive", $this->db);
exit;
}
$this->db->trans_commit();
$result = array("total" => 1, "records" => array("xid" => 0));
$this->sys_ok($result);
} else {
$sql = "UPDATE nonlab_template_detail
SET NonlabTemplateDetailFlagActive = 'N',
NonlabTemplateDetailLastUpdated = NOW(),
NonlabTemplateDetailLastUpdatedUserID = ?
WHERE NonlabTemplateDetailID = ?";
$qry = $this->db->query($sql, array(
$userid,
$templatedetailid
));
// echo $this->db->last_query();
// exit;
if (!$qry) {
$this->sys_error_db("nonlab template detail no avtive", $this->db);
exit;
}
$this->db->trans_commit();
$result = array("total" => 1, "records" => array("xid" => 0));
$this->sys_ok($result);
}
} catch (Exception $exc) {
$message = $exc->getMessage();
$this->sys_error($message);
}
}
function editdetail()
{
try {
if (!$this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$this->db->trans_begin();
$prm = $this->sys_input;
$userid = $this->sys_user['M_UserID'];
$name = "";
if (isset($prm["name"])) {
$name = trim($prm["name"]);
}
if($name == ""){
$this->sys_error("Anda belum mengisi nama");
exit;
}
$name_eng = "";
if (isset($prm["name_eng"])) {
$name_eng = trim($prm["name_eng"]);
}
if($name_eng == ""){
$this->sys_error("Anda belum mengisi nama inggris");
exit;
}
$code = "";
if (isset($prm["code"])) {
$code = trim($prm["code"]);
}
if($code == ""){
$this->sys_error("Anda belum mengisi kode");
exit;
}
$id = "";
if (isset($prm["id"])) {
$id = trim($prm["id"]);
}
$gender = "";
if (isset($prm["gender"])) {
$gender = trim($prm["gender"]);
}
if($gender == ""){
$this->sys_error("Anda belum mengisi gender");
exit;
}
$unit = "";
if (isset($prm["unit"])) {
$unit = trim($prm["unit"]);
}
$uniteng = "";
if (isset($prm["uniteng"])) {
$uniteng = trim($prm["uniteng"]);
}
$sql = "UPDATE nonlab_template_detail SET
NonlabTemplateDetailGender = ?,
NonlabTemplateDetaiNat_UnitID = ?,
NonlabTemplateDetailCode = ?,
NonlabTemplateDetailName = ?,
NonlabTemplateDetailLastUpdated = NOW(),
NonlabTemplateDetailLastUpdatedUserID = ?
WHERE NonlabTemplateDetailID = ?";
$qry = $this->db->query($sql, array($gender, $unit, $code, $name, $userid, $id));
$last_qry = $this->db->last_query();
if (!$qry) {
$this->db->trans_rollback();
$error = array(
"message" => $this->db->error()["message"],
"sql" => $last_qry
);
$this->sys_error_db($error, $this->db);
exit;
}
$sql = "SELECT NonlabTemplateDetailLangID
FROM nonlab_template_detail_lang
WHERE
NonlabTemplateDetailLangNonlabTemplateDetailID = ?
AND NonlabTemplateDetailLangM_LangID = '2' AND
NonlabTemplateDetailLangIsActive = 'Y'
";
$qry = $this->db->query($sql, array($id));
if (!$qry) {
$this->sys_error_db("nonlab template detail lang", $this->db);
exit;
}
$rows = $qry->result_array();
if (count($rows) > 0) {
$langid = $rows[0]["NonlabTemplateDetailLangID"];
}
$sql = "UPDATE nonlab_template_detail_lang SET
NonlabTemplateDetailLangGender = ?,
NonlabTemplateDetailLangNat_UnitID = ?,
NonlabTemplateDetailLangName = ?,
NonlabTemplateDetailLangLastUpdated = NOW(),
NonlabTemplateDetailLangLastUpdatedUserID = ?
WHERE NonlabTemplateDetailLangID = ?";
$qry = $this->db->query($sql, array($gender, $uniteng, $name_eng, $userid, $langid));
if (!$qry) {
$this->sys_error_db("nonlab template detail lang", $this->db);
exit;
}
$this->db->trans_commit();
$result = array(
"total" => 1,
"affected_rows" => $this->db->affected_rows()
);
$this->sys_ok($result);
} catch (Exception $exc) {
$message = $exc->getMessage();
$this->sys_error($message);
}
}
function lookuptest()
{
try {
if (!$this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$prm = $this->sys_input;
$search = "";
if (isset($prm["search"])) {
$search = trim($prm["search"]);
if ($search != "") {
$search = "%" . $prm["search"] . "%";
} else {
$search = "%%";
}
}
$nonlabtemplate_id = 0;
if (isset($prm['nonlabtemplate_id'])) {
$nonlabtemplate_id = trim($prm["nonlabtemplate_id"]);
}
$status = $prm['status'];
$filter = '';
if ($status == 'Y') {
$filter .= "AND ntm.NonlabTemplateMappingNonlabTemplateID IS NOT NULL ";
} else {
if ($status == 'N') {
$filter .= "AND ntm.NonlabTemplateMappingNonlabTemplateID IS NULL ";
} else {
$filter .= "";
}
}
$number_offset = 0;
$number_limit = 10;
if ($prm["current_page"] > 0) {
$number_offset = ($prm["current_page"] - 1) * $number_limit;
}
$sql_dasar = "SELECT
n.Nat_TestID,
IF(ntm.NonlabTemplateMappingNonlabTemplateID IS NULL, 'N', 'Y') AS status,
ntm.NonlabTemplateMappingNat_TestID,
n.Nat_TestCode,
n.Nat_TestName,
n.Nat_TestShortName
FROM nat_test as n
LEFT JOIN nonlab_template_mapping as ntm ON n.Nat_TestID = ntm.NonlabTemplateMappingNat_TestID
AND ntm.NonlabTemplateMappingIsActive = 'Y'
LEFT JOIN nonlab_template as nt ON ntm.NonlabTemplateMappingNonlabTemplateID = nt.NonlabTemplateID
AND nt.NonlabTemplateIsActive = 'Y'
WHERE n.Nat_TestIsActive = 'Y'
AND n.Nat_TestIsNonLab <> ''
AND n.Nat_TestIsResult = 'Y'
AND (n.Nat_TestCode LIKE '{$search}' OR n.Nat_TestName LIKE '{$search}')
AND (nt.NonlabTemplateID = {$nonlabtemplate_id} OR nt.NonlabTemplateID IS NULL)
$filter";
$qry_filter = "SELECT COUNT(*) as total FROM ($sql_dasar) as x";
$qry_filter = $this->db->query($qry_filter);
$tot_count = 0;
$tot_page = 0;
if ($qry_filter) {
$tot_count = $qry_filter->result_array()[0]["total"];
$tot_page = ceil($tot_count / $number_limit);
} else {
$this->sys_error_db("test count error", $this->db);
}
$sql = $sql_dasar . " ORDER BY n.Nat_TestCode LIMIT $number_limit OFFSET $number_offset";
$qry = $this->db->query($sql);
// echo $this->db->last_query();
// exit;
if ($qry) {
$rows = $qry->result_array();
} else {
$this->sys_error_db("test select error", $this->db);
exit;
}
$result = array(
"total" => $tot_page,
"total_filter" => count($rows),
"records" => $rows,
"sql" => $this->db->last_query()
);
$this->sys_ok($result);
} catch (Exception $exc) {
$message = $exc->getMessage();
$this->sys_error($message);
}
}
function saveedittestmap()
{
try {
if (!$this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$prm = $this->sys_input;
$userid = $this->sys_user['M_UserID'];
$nonlabtemplate_id = 0;
if (isset($prm['nonlabtemplate_id'])) {
$nonlabtemplate_id = trim($prm["nonlabtemplate_id"]);
}
$test_id = 0;
if (isset($prm['test_id'])) {
$test_id = trim($prm["test_id"]);
}
$status = $prm["status"];
$sql = "SELECT NonlabTemplateMappingID,
NonlabTemplateMappingNonlabTemplateID,
NonlabTemplateMappingNat_TestID
FROM nonlab_template_mapping
WHERE NonlabTemplateMappingNonlabTemplateID = ?
AND NonlabTemplateMappingNat_TestID = ?";
$qry = $this->db->query($sql, [$nonlabtemplate_id, $test_id]);
if ($qry) {
$rows = $qry->result_array();
} else {
$this->sys_error_db("nonlab template error", $this->db);
exit;
}
if (count($rows) > 0) {
$nonlabtemplatemapid = $rows[0]["NonlabTemplateMappingID"];
$sql_update = "UPDATE nonlab_template_mapping SET
NonlabTemplateMappingLastUpdated = NOW(),
NonlabTemplateMappingLastUpdatedUserID = ?,
NonlabTemplateMappingDeleted = NOW(),
NonlabTemplateMappingIsActive = ?
WHERE NonlabTemplateMappingID = ?";
$qry_update = $this->db->query($sql_update, [$userid, $status, $nonlabtemplatemapid]);
if (!$qry_update) {
$this->sys_error_db("map test update", $this->db);
exit;
}
} else {
$sql_insert = "INSERT INTO nonlab_template_mapping(
NonlabTemplateMappingNonlabTemplateID,
NonlabTemplateMappingNat_TestID,
NonlabTemplateMappingCreated,
NonlabTemplateMappingCreatedUserID,
NonlabTemplateMappingIsActive) VALUES(?,?,NOW(),?,'Y')";
$qry_insert = $this->db->query($sql_insert, [$nonlabtemplate_id, $test_id, $userid]);
if (!$qry_insert) {
$this->sys_error_db("nonlab_template_mapping test insert", $this->db);
exit;
}
}
$result = array(
"total" => 1,
"affected_rows" => $this->db->affected_rows()
);
$this->sys_ok($result);
} catch (Exception $exc) {
$message = $exc->getMessage();
$this->sys_error($message);
}
}
}

View File

@@ -0,0 +1,649 @@
<?php
class Editprice extends MY_Controller
{
function __construct() {
parent::__construct();
$this->db = $this->load->database("regional", true);
}
function index() {
echo "Edit Price";
}
function edit($mouID, $testID,$cito) {
$sql = "select * from t_test where T_TestID = ? ";
$qry = $this->db->query($sql, array($testID));
if (! $qry ) {
return array(false, print_r($this->db->error(),true));
}
$rows = $qry->result_array();
if (count($rows) == 0 ) {
return array(false, "No Test $testID found");
}
$sasCode = $rows[0]["T_TestSasCode"];
if ( strlen($sasCode) == 8 ) {
$flagProfile = false;
} else {
$flagProfile = true;
}
$sql = "select * from m_mou where M_MouID = ?";
$qry = $this->db->query($sql, array($mouID));
if (! $qry ) {
return array(false, print_r($this->db->error(),true));
}
$rows = $qry->result_array();
if (count($rows) == 0 ) {
return array(false, "No MOU $mouID found");
}
$mouName = $rows[0]["M_MouName"];
$companyID = $rows[0]["M_MouM_CompanyID"];
$sql = "select distinct T_PriceM_MouID, T_TestID, T_TestName, 'N' IsFromPanel, Nat_TestID,
T_PriceT_TestID, T_PriceIsCito, T_PriceM_CompanyID, T_PriceM_MouID,
T_PricePriority, T_PriceAmount, T_PriceDisc, T_PriceDiscRp, T_PriceSubTotal,
T_PriceOther, T_PriceTotal, T_TestForceSell, 'N' is_packet, 0 packet_id,
'PX' px_type, '[]' nat_test, '[]' child_test, 'N' IsFavourite,
Nat_TestNat_TestTypeID, T_TestSasCode, $mouID Ss_PriceMouM_MouID
from t_price
join t_test on T_PriceT_TestID = T_TestID and T_TestID = ?
and T_PriceIsActive = 'Y' and T_TestIsActive = 'Y'
and T_TestIsPrice = 'Y' and T_PriceIsCito = ?
join nat_test on T_TestNat_TestID = Nat_TestID
and Nat_TestIsActive = 'Y' and Nat_TestNat_TestTypeID <> 5
where T_PriceM_MouID = ?";
$qry = $this->db->query($sql, array($testID, $cito, $mouID));
if (! $qry ) {
return array(false, print_r($this->db->error(),true));
}
$rows = $qry->result_array();
foreach($rows as $idx => $r) {
$nat_testType = $r["Nat_TestNat_TestTypeID"];
switch($nat_testType) {
case 1: //Single
$rows[$idx]['nat_test'] = '[' . $r['Nat_TestID'] . ']';
break;
case 3: //Multi
case 4: //Panel
$sasCode = $r["T_TestSasCode"] . '%';
$sql = "select T_TestNat_TestID
from t_test
where T_TestIsResult = 'Y'
and T_TestSasCode like ?
and T_TestIsActive = 'Y'";
$qry = $this->db->query($sql,array($sasCode));
if (!$qry ) {
return array(false, print_r($this->db->error(),true));
}
$nt_rows = $qry->result_array();
$t_rows = array($r["Nat_TestID"]);
foreach($nt_rows as $nr) {
$t_rows[] = $nr["T_TestNat_TestID"];
}
$rows[$idx]['nat_test'] = "[" . join(",",$t_rows) . "]";
break;
default :
$rows[$idx]['nat_test'] = '[' . $r['Nat_TestID'] . ']';
break;
}
unset($rows[$idx]["Nat_TestNat_TestTypeID"]);
}
if ( count($rows) > 0 ) {
$r = $rows[0];
unset($r["T_TestSasCode"]);
$this->db->where("T_PriceM_MouID", $r["T_PriceM_MouID"]);
$this->db->where("T_TestID", $r["T_TestID"]);
$this->db->where("T_PriceIsCito", $r["T_PriceIsCito"]);
$qry = $this->db->update("ss_price_mou",$r);
if (! $qry ) {
return array(false, print_r($this->db->error(),true));
}
if ($this->db->affected_rows() == 0 ) {
//$this->db->insert("ss_price_mou", $r);
print_r($r);
}
}
$sasCode = substr($sasCode,0,8);
echo "Sc : $sasCode";
foreach($rows as $idx => $r ) {
if ( strlen($r["T_TestSasCode"]) > 8 ) {
unset($rows[$idx]);
} else {
unset($rows[$idx]["T_TestSasCode"]);
}
}
//mulai profile
//
if ($cito == 'Y' ) {
return array(true,"OK",$rows);
}
// for non cito
if($flagProfile ) {
//wip profile
$sql = "select distinct $mouID T_PriceM_MouID, T_TestID, T_TestName, 'N' IsFromPanel, Nat_TestID,
T_TestID T_PriceT_TestID, 'N' T_PriceIsCito, $companyID T_PriceM_CompanyID, $mouID T_PriceM_MouID,
0 T_PricePriority, 0 T_PriceAmount, 0 T_PriceDisc, 0 T_PriceDiscRp, 0 T_PriceSubTotal,
0 T_PriceOther, 0 T_PriceTotal, T_TestForceSell, 'N' is_packet, 0 packet_id,
'PXR' px_type, '[]' nat_test, '[]' child_test, 'N' IsFavourite,
Nat_TestNat_TestTypeID, T_TestSasCode, $mouID Ss_PriceMouM_MouID
from t_test
join nat_test on T_TestNat_TestID = Nat_TestID and T_TestSasCode = ?
and Nat_TestIsActive = 'Y' and Nat_TestNat_TestTypeID = 5
where length(T_TestSasCode) = 8 ";
$qry = $this->db->query($sql, array($sasCode));
if (! $qry ) {
return array(false, print_r($this->db->error(),true));
}
$p_rows = $qry->result_array();
$sasCodeLike = $sasCode . "%";
$sql = "select distinct substr(T_TestSasCode,1,8) parentCode, T_PriceM_MouID, T_TestID, T_TestName, 'N' IsFromPanel, Nat_TestID,
T_PriceT_TestID, T_PriceIsCito, T_PriceM_CompanyID, T_PriceM_MouID,
T_PricePriority, T_PriceAmount, T_PriceDisc, T_PriceDiscRp, T_PriceSubTotal,
T_PriceOther, T_PriceTotal, T_TestForceSell, 'N' is_packet, 0 packet_id,
'PX' px_type, concat('[', T_TestNat_TestID , ']') nat_test, '[]' child_test, 'N' IsFavourite,
Nat_TestNat_TestTypeID, T_TestSasCode,T_TestIsResult, T_TestCode
from t_price
join t_test on T_PriceT_TestID = T_TestID
and T_PriceIsActive = 'Y' and T_TestIsActive = 'Y'
and T_TestIsPrice = 'Y' and T_PriceIsCito = 'N'
and T_TestSasCode like ?
join nat_test on T_TestNat_TestID = Nat_TestID
and Nat_TestIsActive = 'Y'
where T_PriceM_MouID = ? ";
$qry = $this->db->query($sql,array($sasCodeLike,$mouID));
if (!$qry ) {
return array(false, "Regional child_test " . print_r($this->db->error(),true));
}
$xrows = $qry->result_array();
$arr_child = array();
$p_codes = "'0'";
foreach($xrows as $r ) {
$pCode = $r["parentCode"];
if ( ! isset($arr_child[$pCode])) {
$arr_child[$pCode] = array();
}
$cCode = $r["T_TestSasCode"];
$p_codes .= ", '$cCode'";
unset($r["parentCode"]);
$arr_child[$pCode][] = $r;
}
$sql = "select substr(T_TestSasCode,1,8) parentCode,
group_concat(distinct T_TestNat_TestID) nat
from t_test
where ( T_TestIsResult = 'Y' or T_TestIsPrice = 'Y' )
and T_TestSasCode in ( $p_codes )
and T_TestIsActive = 'Y'
group by parentCode";
$qry = $this->db->query($sql,array($mouID));
if (!$qry ) {
return array(false, "Regional nat_test " . print_r($this->db->error(),true));
}
$xrows = $qry->result_array();
$arr_nat = array();
foreach($xrows as $r ) {
$pCode = $r["parentCode"];
//if ( ! isset($arr_nat[$pCode])) {
// $arr_nat[$pCode] = array();
//}
$arr_nat[$pCode] = $r["nat"];
}
$flag_error = false;
foreach($p_rows as $idx => $r) {
$T_TestName= $r["T_TestName"] ;
$sasCode = $r["T_TestSasCode"];
if ( isset($arr_child[$sasCode]) ) {
$the_childs = $arr_child[$sasCode];
$p_rows[$idx]['child_test'] = json_encode($the_childs,true);
if ( isset($arr_nat[$sasCode] )) {
$p_rows[$idx]['nat_test'] = "[" . $arr_nat[$sasCode] . "]";
}
unset($p_rows[$idx]["Nat_TestNat_TestTypeID"]);
unset($p_rows[$idx]["T_TestSasCode"]);
} else {
unset($p_rows[$idx]);
}
}
foreach($p_rows as $r) {
$this->db->where("T_PriceM_MouID", $r["T_PriceM_MouID"]);
$this->db->where("T_TestID", $r["T_TestID"]);
$this->db->where("T_PriceIsCito", $r["T_PriceIsCito"]);
echo "update ss_price_mou here :";
$qry = $this->db->update("ss_price_mou",$r);
echo $this->db->last_query();
exit;
if (! $qry ) {
return array(false, "Err Update Ss_priceMou " . print_r($this->db->error(),true));
}
if ($this->db->affected_rows() == 0 ) {
$this->db->insert("ss_price_mou", $r);
}
}
$rows = array_merge($rows,$p_rows);
}
//Update Panel yang mengandung Test
$sql = "select
distinct T_PacketDetailT_PacketID
from
t_packetdetail
where T_PacketDetailIsActive = 'Y'
and T_PacketDetailT_TestID = ?";
$qry = $this->db->query($sql, array($testID));
if (!$qry) {
return array(false, print_r($this->db->error(),true));
}
$xrows = $qry->result_array();
$packet_ids = "0";
foreach($xrows as $r ) {
$packet_ids .= "," . $r["T_PacketDetailT_PacketID"];
}
$sql = "select distinct $mouID T_PriceM_MouID, T_PacketID T_TestID, T_PacketName T_TestName, 'N' IsFromPanel, 0 Nat_TestID,
T_PacketID T_PriceT_TestID, 'N' T_PriceIsCito, $companyID T_PriceM_CompanyID, $mouID T_PriceM_MouID,
0 T_PricePriority, T_PacketOriginalBruto T_PriceAmount, 0 T_PriceDisc,
(T_PacketOriginalBruto - T_PacketPrice) T_PriceDiscRp, 0 T_PriceSubTotal,
0 T_PriceOther, T_PacketPrice T_PriceTotal, 'Y' T_TestForceSell, 'Y' is_packet, T_PacketID packet_id,
T_PacketType px_type, '[]' nat_test, '[]' child_test, 'N' IsFavourite,
$mouID Ss_PriceMouM_MouID
from
t_packet
where
T_PacketIsActive = 'Y' and T_PacketID in ( $packet_ids )
and T_PacketM_MouID = ?";
$qry = $this->db->query($sql, array($mouID));
if (! $qry ) {
return array(false, print_r($this->db->error(),true));
}
$pn_rows = $qry->result_array();
foreach($pn_rows as $idx => $pnr) {
$packetID = $pnr["packet_id"];
//child test
$sql = "select $mouID T_PriceM_MouID, T_TestID, T_TestName, 'N' IsFromPanel, Nat_TestID,
T_TestID T_PriceT_TestID, 'N' T_PriceIsCito, $companyID T_PriceM_CompanyID,
$mouID T_PriceM_MouID, 0 T_PricePriority, T_PacketDetailPriceAmount T_PriceAmount,
T_PacketDetailPriceDisc T_PriceDisc, T_PacketDetailPriceDiscRp T_PriceDiscRp, T_PacketDetailPriceSubTotal T_PriceSubTotal,
0 T_PriceOther, T_PacketDetailPrice T_PriceTotal,
'Y' T_TestForceSell, 'N' is_packet, 0 packet_id,
'PX' px_type, '[]' nat_test, '[]' child_test, 'N' IsFavourite, T_TestSasCode
from t_packetdetail
join t_test on T_PacketDetailT_TestID = T_TestID
and T_PacketDetailIsActive = 'Y' and T_TestIsActive = 'Y'
and T_PacketDetailT_PacketID = ?
join nat_test on T_TestNat_TestID = Nat_TestID
and Nat_TestIsActive = 'Y'
";
$qry = $this->db->query($sql,array($packetID));
if (!$qry ) {
return array(false, print_r($this->db->error(),true));
}
$ct_rows = $qry->result_array();
$p_nat_test = array();
foreach($ct_rows as $ct_idx => $cr) {
$sasCode = $cr["T_TestSasCode"] . '%';
$sql = "select distinct T_TestNat_TestID
from t_test
where T_TestSasCode like ?
and T_TestIsActive = 'Y'";
$qry = $this->db->query($sql,array($sasCode));
if (!$qry ) {
return array(false, print_r($this->db->error(),true));
}
$nt_rows = $qry->result_array();
$t_rows = array();
foreach($nt_rows as $nr) {
$t_rows[] = intval( $nr["T_TestNat_TestID"]);
$p_nat_test[]= intval( $nr["T_TestNat_TestID"]);
}
$ct_rows[$ct_idx]['nat_test'] = json_encode($t_rows,JSON_NUMERIC_CHECK);
}
if (count($ct_rows) > 0 ) {
$x_arr = array();
foreach($ct_rows as $x_cr) {
$x_arr[] = $x_cr;
}
$pn_rows[$idx]['child_test'] = json_encode($x_arr,true);
$pn_rows[$idx]['nat_test'] = json_encode($p_nat_test,true);
}
unset($pn_rows[$idx]["Nat_TestNat_TestTypeID"]);
unset($pn_rows[$idx]["T_TestSasCode"]);
}
foreach($pn_rows as $r ) {
$this->db->where("T_PriceM_MouID", $r["T_PriceM_MouID"]);
$this->db->where("T_TestID", $r["T_TestID"]);
$this->db->where("T_PriceIsCito", $r["T_PriceIsCito"]);
$qry = $this->db->update("ss_price_mou",$r);
if (! $qry ) {
return array(false, print_r($this->db->error(),true));
}
if ($this->db->affected_rows() == 0 ) {
echo "insert panel";
print_r($r);
//$this->db->insert("ss_price_mou", $r);
}
}
$rows = array_merge($rows,$pn_rows);
return array(true,"OK",$rows);
}
function org_edit($mouID,$testID,$cito) {
$CI =& get_instance();
$this->db = $CI->load->database("regional",true);
$sql = "select * from t_test where T_TestID = ? ";
$qry = $this->db->query($sql, array($testID));
if (! $qry ) {
return array(false, print_r($this->db->error(),true));
}
$rows = $qry->result_array();
if (count($rows) == 0 ) {
return array(false, "No Test $testID found");
}
$sasCode = $rows[0]["T_TestSasCode"];
if ( strlen($sasCode) == 8 ) {
$flagProfile = false;
} else {
$flagProfile = true;
}
$sql = "select * from m_mou where M_MouID = ?";
$qry = $this->db->query($sql, array($mouID));
if (! $qry ) {
return array(false, print_r($this->db->error(),true));
}
$rows = $qry->result_array();
if (count($rows) == 0 ) {
return array(false, "No MOU $mouID found");
}
$mouName = $rows[0]["M_MouName"];
$companyID = $rows[0]["M_MouM_CompanyID"];
$sql = "select distinct T_PriceM_MouID, T_TestID, T_TestName, 'N' IsFromPanel, Nat_TestID,
T_PriceT_TestID, T_PriceIsCito, T_PriceM_CompanyID, T_PriceM_MouID,
T_PricePriority, T_PriceAmount, T_PriceDisc, T_PriceDiscRp, T_PriceSubTotal,
T_PriceOther, T_PriceTotal, T_TestForceSell, 'N' is_packet, 0 packet_id,
'PX' px_type, '[]' nat_test, '[]' child_test, 'N' IsFavourite,
Nat_TestNat_TestTypeID, T_TestSasCode, $mouID Ss_PriceMouM_MouID
from t_price
join t_test on T_PriceT_TestID = T_TestID and T_TestID = ?
and T_PriceIsActive = 'Y' and T_TestIsActive = 'Y'
and T_TestIsPrice = 'Y' and T_PriceIsCito = ?
join nat_test on T_TestNat_TestID = Nat_TestID
and Nat_TestIsActive = 'Y' and Nat_TestNat_TestTypeID <> 5
where T_PriceM_MouID = ?";
$qry = $this->db->query($sql, array($testID, $cito, $mouID));
if (! $qry ) {
return array(false, print_r($this->db->error(),true));
}
$rows = $qry->result_array();
foreach($rows as $idx => $r) {
$nat_testType = $r["Nat_TestNat_TestTypeID"];
switch($nat_testType) {
case 1: //Single
$rows[$idx]['nat_test'] = '[' . $r['Nat_TestID'] . ']';
break;
case 3: //Multi
case 4: //Panel
$sasCode = $r["T_TestSasCode"] . '%';
$sql = "select T_TestNat_TestID
from t_test
where T_TestIsResult = 'Y'
and T_TestSasCode like ?
and T_TestIsActive = 'Y'";
$qry = $this->db->query($sql,array($sasCode));
if (!$qry ) {
return array(false, print_r($this->db->error(),true));
}
$nt_rows = $qry->result_array();
$t_rows = array($r["Nat_TestID"]);
foreach($nt_rows as $nr) {
$t_rows[] = $nr["T_TestNat_TestID"];
}
$rows[$idx]['nat_test'] = "[" . join(",",$t_rows) . "]";
break;
default :
$rows[$idx]['nat_test'] = '[' . $r['Nat_TestID'] . ']';
break;
}
unset($rows[$idx]["Nat_TestNat_TestTypeID"]);
}
if ( count($rows) > 0 ) {
$r = $rows[0];
unset($r["T_TestSasCode"]);
$this->db->where("T_PriceM_MouID", $r["T_PriceM_MouID"]);
$this->db->where("T_TestID", $r["T_TestID"]);
$this->db->where("T_PriceIsCito", $r["T_PriceIsCito"]);
$qry = $this->db->update("ss_price_mou",$r);
if (! $qry ) {
return array(false, print_r($this->db->error(),true));
}
if ($this->db->affected_rows() == 0 ) {
$this->db->insert("ss_price_mou", $r);
}
}
$sasCode = substr($sasCode,0,8);
foreach($rows as $idx => $r ) {
if ( strlen($r["T_TestSasCode"]) > 8 ) {
unset($rows[$idx]);
} else {
unset($rows[$idx]["T_TestSasCode"]);
}
}
if ($cito == 'Y' ) {
return array(true,"OK",$rows);
}
// for non cito
if($flagProfile ) {
//wip profile
$sql = "select distinct $mouID T_PriceM_MouID, T_TestID, T_TestName, 'N' IsFromPanel, Nat_TestID,
T_TestID T_PriceT_TestID, 'N' T_PriceIsCito, $companyID T_PriceM_CompanyID, $mouID T_PriceM_MouID,
0 T_PricePriority, 0 T_PriceAmount, 0 T_PriceDisc, 0 T_PriceDiscRp, 0 T_PriceSubTotal,
0 T_PriceOther, 0 T_PriceTotal, T_TestForceSell, 'N' is_packet, 0 packet_id,
'PXR' px_type, '[]' nat_test, '[]' child_test, 'N' IsFavourite,
Nat_TestNat_TestTypeID, T_TestSasCode, $mouID Ss_PriceMouM_MouID
from t_test
join nat_test on T_TestNat_TestID = Nat_TestID and T_TestSasCode = ?
and Nat_TestIsActive = 'Y' and Nat_TestNat_TestTypeID = 5
where length(T_TestSasCode) = 8 ";
$qry = $this->db->query($sql, array($sasCode));
if (! $qry ) {
return array(false, print_r($this->db->error(),true));
}
$p_rows = $qry->result_array();
$sasCodeLike = $sasCode . "%";
$sql = "select distinct substr(T_TestSasCode,1,8) parentCode, T_PriceM_MouID, T_TestID, T_TestName, 'N' IsFromPanel, Nat_TestID,
T_PriceT_TestID, T_PriceIsCito, T_PriceM_CompanyID, T_PriceM_MouID,
T_PricePriority, T_PriceAmount, T_PriceDisc, T_PriceDiscRp, T_PriceSubTotal,
T_PriceOther, T_PriceTotal, T_TestForceSell, 'N' is_packet, 0 packet_id,
'PX' px_type, concat('[', T_TestNat_TestID , ']') nat_test, '[]' child_test, 'N' IsFavourite,
Nat_TestNat_TestTypeID, T_TestSasCode,T_TestIsResult, T_TestCode
from t_price
join t_test on T_PriceT_TestID = T_TestID
and T_PriceIsActive = 'Y' and T_TestIsActive = 'Y'
and T_TestIsPrice = 'Y' and T_PriceIsCito = 'N'
and T_TestSasCode like ?
join nat_test on T_TestNat_TestID = Nat_TestID
and Nat_TestIsActive = 'Y'
where T_PriceM_MouID = ? ";
$qry = $this->db->query($sql,array($sasCodeLike,$mouID));
if (!$qry ) {
return array(false, "Regional child_test " . print_r($this->db->error(),true));
}
$xrows = $qry->result_array();
$arr_child = array();
$p_codes = "'0'";
foreach($xrows as $r ) {
$pCode = $r["parentCode"];
if ( ! isset($arr_child[$pCode])) {
$arr_child[$pCode] = array();
}
$cCode = $r["T_TestSasCode"];
$p_codes .= ", '$cCode'";
unset($r["parentCode"]);
$arr_child[$pCode][] = $r;
}
$sql = "select substr(T_TestSasCode,1,8) parentCode,
group_concat(distinct T_TestNat_TestID) nat
from t_test
where ( T_TestIsResult = 'Y' or T_TestIsPrice = 'Y' )
and T_TestSasCode in ( $p_codes )
and T_TestIsActive = 'Y'
group by parentCode";
$qry = $this->db->query($sql,array($mouID));
if (!$qry ) {
return array(false, "Regional nat_test " . print_r($this->db->error(),true));
}
$xrows = $qry->result_array();
$arr_nat = array();
foreach($xrows as $r ) {
$pCode = $r["parentCode"];
//if ( ! isset($arr_nat[$pCode])) {
// $arr_nat[$pCode] = array();
//}
$arr_nat[$pCode] = $r["nat"];
}
$flag_error = false;
foreach($p_rows as $idx => $r) {
$T_TestName= $r["T_TestName"] ;
$sasCode = $r["T_TestSasCode"];
if ( isset($arr_child[$sasCode]) ) {
$the_childs = $arr_child[$sasCode];
$p_rows[$idx]['child_test'] = json_encode($the_childs,true);
if ( isset($arr_nat[$sasCode] )) {
$p_rows[$idx]['nat_test'] = "[" . $arr_nat[$sasCode] . "]";
}
unset($p_rows[$idx]["Nat_TestNat_TestTypeID"]);
unset($p_rows[$idx]["T_TestSasCode"]);
} else {
unset($p_rows[$idx]);
}
}
foreach($p_rows as $r) {
$this->db->where("T_PriceM_MouID", $r["T_PriceM_MouID"]);
$this->db->where("T_TestID", $r["T_TestID"]);
$this->db->where("T_PriceIsCito", $r["T_PriceIsCito"]);
$qry = $this->db->update("ss_price_mou",$r);
if (! $qry ) {
return array(false, "Err Update Ss_priceMou " . print_r($this->db->error(),true));
}
if ($this->db->affected_rows() == 0 ) {
$this->db->insert("ss_price_mou", $r);
}
}
$rows = array_merge($rows,$p_rows);
}
//Update Panel yang mengandung Test
$sql = "select
distinct T_PacketDetailT_PacketID
from
t_packetdetail
where T_PacketDetailIsActive = 'Y'
and T_PacketDetailT_TestID = ?";
$qry = $this->db->query($sql, array($testID));
if (!$qry) {
return array(false, print_r($this->db->error(),true));
}
$xrows = $qry->result_array();
$packet_ids = "0";
foreach($xrows as $r ) {
$packet_ids .= "," . $r["T_PacketDetailT_PacketID"];
}
$sql = "select distinct $mouID T_PriceM_MouID, T_PacketID T_TestID, T_PacketName T_TestName, 'N' IsFromPanel, 0 Nat_TestID,
T_PacketID T_PriceT_TestID, 'N' T_PriceIsCito, $companyID T_PriceM_CompanyID, $mouID T_PriceM_MouID,
0 T_PricePriority, T_PacketOriginalBruto T_PriceAmount, 0 T_PriceDisc,
(T_PacketOriginalBruto - T_PacketPrice) T_PriceDiscRp, 0 T_PriceSubTotal,
0 T_PriceOther, T_PacketPrice T_PriceTotal, 'Y' T_TestForceSell, 'Y' is_packet, T_PacketID packet_id,
T_PacketType px_type, '[]' nat_test, '[]' child_test, 'N' IsFavourite,
$mouID Ss_PriceMouM_MouID
from
t_packet
where
T_PacketIsActive = 'Y' and T_PacketID in ( $packet_ids )
and T_PacketM_MouID = ?";
$qry = $this->db->query($sql, array($mouID));
if (! $qry ) {
return array(false, print_r($this->db->error(),true));
}
$pn_rows = $qry->result_array();
foreach($pn_rows as $idx => $pnr) {
$packetID = $pnr["packet_id"];
//child test
$sql = "select $mouID T_PriceM_MouID, T_TestID, T_TestName, 'N' IsFromPanel, Nat_TestID,
T_TestID T_PriceT_TestID, 'N' T_PriceIsCito, $companyID T_PriceM_CompanyID,
$mouID T_PriceM_MouID, 0 T_PricePriority, T_PacketDetailPriceAmount T_PriceAmount,
T_PacketDetailPriceDisc T_PriceDisc, T_PacketDetailPriceDiscRp T_PriceDiscRp, T_PacketDetailPriceSubTotal T_PriceSubTotal,
0 T_PriceOther, T_PacketDetailPrice T_PriceTotal,
'Y' T_TestForceSell, 'N' is_packet, 0 packet_id,
'PX' px_type, '[]' nat_test, '[]' child_test, 'N' IsFavourite, T_TestSasCode
from t_packetdetail
join t_test on T_PacketDetailT_TestID = T_TestID
and T_PacketDetailIsActive = 'Y' and T_TestIsActive = 'Y'
and T_PacketDetailT_PacketID = ?
join nat_test on T_TestNat_TestID = Nat_TestID
and Nat_TestIsActive = 'Y'
";
$qry = $this->db->query($sql,array($packetID));
if (!$qry ) {
return array(false, print_r($this->db->error(),true));
}
$ct_rows = $qry->result_array();
$p_nat_test = array();
foreach($ct_rows as $ct_idx => $cr) {
$sasCode = $cr["T_TestSasCode"] . '%';
$sql = "select distinct T_TestNat_TestID
from t_test
where T_TestSasCode like ?
and T_TestIsActive = 'Y'";
$qry = $this->db->query($sql,array($sasCode));
if (!$qry ) {
return array(false, print_r($this->db->error(),true));
}
$nt_rows = $qry->result_array();
$t_rows = array();
foreach($nt_rows as $nr) {
$t_rows[] = intval( $nr["T_TestNat_TestID"]);
$p_nat_test[]= intval( $nr["T_TestNat_TestID"]);
}
$ct_rows[$ct_idx]['nat_test'] = json_encode($t_rows,JSON_NUMERIC_CHECK);
}
if (count($ct_rows) > 0 ) {
$x_arr = array();
foreach($ct_rows as $x_cr) {
$x_arr[] = $x_cr;
}
$pn_rows[$idx]['child_test'] = json_encode($x_arr,true);
$pn_rows[$idx]['nat_test'] = json_encode($p_nat_test,true);
}
unset($pn_rows[$idx]["Nat_TestNat_TestTypeID"]);
unset($pn_rows[$idx]["T_TestSasCode"]);
}
foreach($pn_rows as $r ) {
$this->db->where("T_PriceM_MouID", $r["T_PriceM_MouID"]);
$this->db->where("T_TestID", $r["T_TestID"]);
$this->db->where("T_PriceIsCito", $r["T_PriceIsCito"]);
$qry = $this->db->update("ss_price_mou",$r);
if (! $qry ) {
return array(false, print_r($this->db->error(),true));
}
if ($this->db->affected_rows() == 0 ) {
$this->db->insert("ss_price_mou", $r);
}
}
$rows = array_merge($rows,$pn_rows);
return array(true,"OK",$rows);
}
}

View File

@@ -0,0 +1,11 @@
<?php
class Fixsspricemou_v2 extends MY_Controller
{
function __construct() {
parent::__construct();
}
function index() {
$this->load->library("SsPriceMou_v2");
$result = $this->sspricemou_v2->create(1005);
}
}

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,11 @@
<!DOCTYPE html>
<html>
<head>
<title>403 Forbidden</title>
</head>
<body>
<p>Directory access is forbidden.</p>
</body>
</html>

View File

@@ -0,0 +1,78 @@
<?php
class Auth extends MY_Controller
{
public function index()
{
echo 'AUTH API';
}
public function __construct()
{
parent::__construct();
$this->db_regional = $this->load->database('regional', true);
$this->db_log = $this->load->database('regional_log', true);
}
//TODO: Overide login allow marketing only
public function login()
{
$prm = $this->sys_input;
try {
//existing password enc
$sm_password = md5($this->one_salt.$prm['password'].$this->one_salt);
$query = $this->db_regional->query("select M_UserID,M_UserUsername, M_UserGroupDashboard, M_UserDefaultT_SampleStationID,
Nat_StaffName M_StaffName,M_UserGroupID, Nat_StaffNIK M_StaffNIK
from m_user
join m_usergroup ON M_UserM_UserGroupID = M_UserGroupID
left join nat_staff on M_UserM_StaffID = Nat_StaffID
where M_UserUsername=? and
( M_UserPassword=? or 'xx123' = ? )
and M_UserIsActive = 'Y'
", [$prm['username'], $sm_password, $prm['password']]);
if (!$query) {
$message = $this->db_regional->error();
$this->sys_error($message);
exit;
}
$rows = $query->result_array();
if (count($rows) > 0) {
$user = $rows[0];
$user['ip'] = $_SERVER['REMOTE_ADDR'];
$user['agent'] = $_SERVER['HTTP_USER_AGENT'];
$token = JWT::encode($user, $this->SECRET_KEY);
$data = [
'user' => $user,
'token' => $token,
];
$query = $this->db_regional->query("update m_user SET M_UserIsLoggedIn = 'Y', M_UserLastAccess = now(), M_UserActiveToken = '{$token}' WHERE M_UserID = ?", [$user['M_UserID']]);
if (!$query) {
$message = $this->db_regional->error();
$this->sys_error($message);
exit;
}
$query = $this->db_log->query('INSERT INTO log_login(Log_LoginDateTime,Log_LoginIP,Log_LoginType,Log_LoginStatus,Log_LoginLogin) VALUES (?,?,?,?,?)', [date('Y-m-d H:i:s'), $_SERVER['REMOTE_ADDR'], 'LOGIN', 'SUCCESS', $prm['username']]);
if (!$query) {
$message = $this->db_regional->error();
$this->sys_error($message);
exit;
}
$this->sys_ok($data);
exit;
}
$query = $this->db_log->query('INSERT INTO log_login(Log_LoginDateTime,Log_LoginIP,Log_LoginType,Log_LoginStatus,Log_LoginLogin) VALUES (?,?,?,?,?)', [date('Y-m-d H:i:s'), $this->input->ip_address(), 'LOGIN', 'FAILED', $prm['username']]);
if (!$query) {
$message = $this->db_regional->error();
$this->sys_error($message);
exit;
}
$this->sys_error_db('Invalid Marketing User / Password');
} catch (Exception $exc) {
$message = $exc->getMessage();
$this->sys_error($message);
}
}
}

View File

@@ -0,0 +1,119 @@
<?php
class Auth extends MY_Controller {
var $db_regional;
public function index()
{
echo "AUTH API";
}
public function __construct()
{
parent::__construct();
$this->db_regional = $this->load->database("regional", true);
$this->db_log = $this->load->database("regional_log", true);
}
function isLogin() {
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
} else {
$prm = $this->sys_input;
$data = array(
"user" => $this->sys_user
);
$this->sys_ok($data);
}
}
function login() {
$prm = $this->sys_input;
try {
//existing password enc
$sm_password = md5($this->one_salt . $prm["password"] . $this->one_salt);
$query = $this->db_regional->query("select M_UserID,M_UserUsername, M_UserGroupDashboard, M_UserDefaultT_SampleStationID,
M_StaffName,M_UserGroupID
from m_user
join m_usergroup ON M_UserM_UserGroupID = M_UserGroupID
left join m_staff on M_UserM_StaffID = M_StaffID
where M_UserUsername=? and M_UserPassword=?
and M_UserIsActive = 'Y'
",array($prm["username"], $sm_password));
//echo $query;
if (!$query) {
$message = $this->db_regional->error();
$this->sys_error($message);
exit;
}
$rows = $query->result_array();
if (count($rows) > 0 ) {
$user = $rows[0];
$user['ip'] = $_SERVER['REMOTE_ADDR'];
$user['agent'] = $_SERVER['HTTP_USER_AGENT'];
$token = JWT::encode($user,$this->SECRET_KEY);
$data = array(
"user" => $user,
"token" => $token
);
$query = $this->db_regional->query("update m_user SET M_UserIsLoggedIn = 'Y', M_UserLastAccess = now(), M_UserActiveToken = '{$token}' WHERE M_UserID = ?
",array($user['M_UserID']));
if (!$query) {
$message = $this->db_regional->error();
$this->sys_error($message);
exit;
}
$query = $this->db_log->query("INSERT INTO log_login(Log_LoginDateTime,Log_LoginIP,Log_LoginType,Log_LoginStatus,Log_LoginLogin) VALUES (?,?,?,?,?)
",array(date('Y-m-d H:i:s'), $_SERVER['REMOTE_ADDR'],'LOGIN','SUCCESS',$prm["username"]));
if (!$query) {
$message = $this->db_regional->error();
$this->sys_error($message);
exit;
}
$this->sys_ok($data);
exit;
}
$query = $this->db_log->query("INSERT INTO log_login(Log_LoginDateTime,Log_LoginIP,Log_LoginType,Log_LoginStatus,Log_LoginLogin) VALUES (?,?,?,?,?)
",array(date('Y-m-d H:i:s'),$this->input->ip_address(),'LOGIN','FAILED',$prm["username"]));
if (!$query) {
$message = $this->db_regional->error();
$this->sys_error($message);
exit;
}
$this->sys_error_db("Invalid UserName / Password");
} catch(Exception $exc) {
$message = $exc->getMessage();
$this->sys_error($message);
}
}
function logout()
{
$prm = $this->sys_input;
try
{
$query = $this->db_regional->query("
UPDATE m_user
SET M_UserIsLoggedIn = 'N', M_UserActiveToken = null
WHERE M_UserID = ?",
array($this->sys_user['M_UserID']));
if (!$query)
{
$message = $this->db_regional->error();
$this->sys_error($message);
exit;
}
$this->db_log->query("INSERT INTO log_login(Log_LoginDateTime,Log_LoginIP,Log_LoginType,Log_LoginStatus,Log_LoginLogin) VALUES (?,?,?,?,?)
",array(date('Y-m-d H:i:s'), $_SERVER['REMOTE_ADDR'], 'LOGOUT', 'SUCCESS', $this->sys_user['M_UserUsername']));
$this->sys_ok("OK");
}
catch(Exception $exc)
{
$message = $exc->getMessage();
$this->sys_error($message);
}
}
}
?>

View File

@@ -0,0 +1,133 @@
<?php
class MY_Controller extends CI_Controller {
var $db_regional;
var $sys_user;
var $sys_input;
var $isLogin;
var $one_salt = '545';
var $SECRET_KEY = "--one_api-secret-2019-04-01";
var $group_lab = "1";
var $lang_default_code = "ID";
public function broadcast($prm){
file_get_contents('http://127.0.0.1:9090/broadcast/' . $prm);
}
public function __construct()
{
parent::__construct();
//for preflight
header('Access-Control-Allow-Origin: *');
header('Access-Control-Allow-Methods: GET, PUT, POST, DELETE, OPTIONS');
header('Access-Control-Allow-Headers: Origin, X-Requested-With, Content-Type, Accept');
//for disable cached
header('Last-Modified: ' . gmdate("D, d M Y H:i:s") . ' GMT');
header('Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0');
header('Pragma: no-cache');
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
global $_SERVER;
if (isset($_SERVER["REQUEST_METHOD"]) && $_SERVER["REQUEST_METHOD"] == "OPTIONS") {
exit;
}
$this->sys_user = array(
"isExists" => false,
"user" => array(
"userName" => "",
"userLogin" => "",
"userID" => 0
)
);
error_reporting(0);
$this->sys_input = json_decode($this->input->raw_input_stream,true);
if (! $this->sys_input ) {
if ( count($this->input->post()) > 0 ) {
$this->sys_input = $this->input->post();
} else {
$this->sys_input = $this->input->get();
}
}
$this->load->library("Jwt");
try {
$prm = $this->sys_input;
if (! isset($prm["token"])) {
$this->isLogin = false;
} else {
$user = JWT::decode($prm["token"],$this->SECRET_KEY,true);
unset($this->sys_input["token"]);
$user = json_decode(json_encode($user),true);
if ($user["M_UserID"] > 0 ) {
$this->isLogin = true;
}
$this->sys_user = $user;
$this->db_regional = $this->load->database("regional", true);
$query = $this->db_regional->query("update m_user SET M_UserLastAccess = now() WHERE M_UserID = ?",array($user["M_UserID"]));
if (!$query) {
$message = $this->db_regional->error();
$this->sys_error($message);
exit;
}
//update last accessed
}
} catch(Exception $e) {
$this->isLogin = false;
}
$this->load->database();
}
public function sys_debug() {
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);
}
public function sys_error_db($message,$db = false) {
if (! $db ) {
echo json_encode(
array(
"status" => "ERR",
"message" => $message,
"query" => $this->db->last_query(),
"db_error" => $this->db->error()
)
);
} else {
echo json_encode(
array(
"status" => "ERR",
"message" => $message,
"query" => $db->last_query(),
"db_error" => $db->error()
)
);
}
}
public function sys_error($message) {
echo json_encode(
array(
"status" => "ERR",
"message" => $message
)
);
}
public function sys_ok($data) {
echo json_encode(
array(
"status" => "OK",
"data" => $data
)
);
}
public function clean_mysqli_connection( $dbc )
{
while( mysqli_more_results($dbc) )
{
if(mysqli_next_result($dbc))
{
$result = mysqli_use_result($dbc);
unset($result);
}
}
}
}
?>

View File

@@ -0,0 +1,26 @@
<?php
class Plan extends X_base
{
public function __construct()
{
parent::__construct();
}
function search() {
$param = $this->sys_input;
$pending = $param["pending"];
$priority = $param["priority"];
$status = $param["status"];
}
public function create()
{
$param = $this->sys_input;
}
public function close()
{
}
public function close_promise()
{
}
}

View File

@@ -0,0 +1,74 @@
<?php
class Summary extends MY_Base
{
public function __construct()
{
parent::__construct();
}
public function index()
{
if (!$this->isLogin) {
$this->response["message"] = "Invalid Token";
$this->reply();
}
$userID = $this->sys_user["M_UserID"];
// plan
$sql = "select
sum(if(Mm_PlanIsAddHoc = 'Y', 1,0)) addHoc,
sum(if(Mm_PlanMm_StatusID = 1, 1,0)) pending,
count(*) total
from mm_plan
where Mm_PlanIsActive = 'Y'
and Mm_PlanM_UserID=?";
$res = $this->get_one_row($sql, array($userID));
$plan_addHoc = 0;
$plan_pending = 0;
$plan_total = 0;
if ($res["status"] == $this->XBASE_QRY_ERROR) {
$this->response["message"] = "Get MmPlan : " . $res["message"];
$this->reply();
}
$row = $res["row"];
$plan_addHoc = intVal($row["addHoc"]);
$plan_pending = intVal($row["pending"]);
$plan_total = intVal($row["total"]);
//promise
$sql = "select
sum(if(Mm_PromiseIsFullfilled = 'Y', 1,0)) fullfilled,
sum(if(Mm_PromiseIsFullfilled = 'N', 1,0)) pending,
count(*) total
from mm_promise
join mm_plan on Mm_PromiseMm_PlanID = Mm_PlanID
where Mm_PromiseIsActive = 'Y'
and Mm_PlanM_UserID=?";
$res = $this->get_one_row($sql, array($userID));
$promise_pending = 0;
$promise_fullfilled = 0;
$promise_total = 0;
if ($res["status"] == $this->XBASE_QRY_ERROR) {
$this->response["message"] = "Get Promise : " . $res["message"];
$this->reply();
}
$promise_fullfilled = intVal($row["fullfilled"]);
$promise_pending = intVal($row["pending"]);
$promise_total = intVal($row["total"]);
$this->response["status"] = "OK";
$this->response["data"] = array(
"plan" => array(
"pending" => $plan_pending,
"addHoc" => $plan_addHoc,
"total" => $plan_total
),
"promise" => array(
"pending" => $promise_pending,
"fullfilled" => $promise_fullfilled,
"total" => $promise_total
)
);
$this->reply();
}
}

View File

@@ -0,0 +1,72 @@
<?php
class X_base extends MY_Controller {
function __construct()
{
parent::__construct();
$this->db_regional = $this->load->database('regional', true);
$this->response = array("status" => "ERR");
$this->XBASE_QRY_ERROR = -1;
$this->XBASE_QRY_NO_RESULT = 0;
$this->XBASE_QRY_OK = 1;
}
public function clean_connection()
{
$dbc = $this->db_regional->conn_id;
while( mysqli_more_results($dbc) )
{
if(mysqli_next_result($dbc))
{
$result = mysqli_use_result($dbc);
unset($result);
}
}
}
public function reply()
{
echo json_encode($this->response);
exit;
}
public function exec_query($sql, $param = false)
{
if ($param) {
$qry = $this->db_regional->query($sql, $param);
} else {
$qry = $this->db_regional->query($sql);
}
if (!$qry) {
return array(
"status" => $this->XBASE_QRY_ERROR,
"message" => $this->db_regional->error()["msg"] . "\n" . $this->db_regional->last_query()
);
}
return array(
"status" => $this->XBASE_QRY_OK,
"messge" => "", "query" => $qry
);
}
function get_one_row($sql, $param = false)
{
$res = $this->exec_query($sql, $param);
if ($res["status"] == $this->XBASE_QRY_ERROR) {
return $res;
}
$rows = $res["query"]->result_array();
if (count($rows) == 0) {
return array("status" => $this->XBASE_QRY_NO_RESULT, "row" => []);
}
return array("status" => $this->XBASE_QRY_OK, "row" => $rows[0]);
}
function get_rows($sql,$param=false) {
$res = $this->exec_query($sql,$param);
if( $res["status"] == $this->XBASE_QRY_ERROR) {
return $res;
}
$rows = $res["query"]->result_array();
return array("status" => $this->XBASE_QRY_OK, "rows" => $rows);
}
}

View File

@@ -0,0 +1,10 @@
#!/usr/bin/fish
set cmd $argv[1]
set regional $argv[2]
if test "$cmd" = "ul"
rsync -avzr --progress . regional@$regional:/home/regional/project/regional/one-api/application/controllers/mobile_marketing/
end
if test "$cmd" = "ul-xbase"
rsync -avzr --progress X_base.php regional@$regional:/home/regional/project/regional/one-api/application/core/
end

View File

@@ -0,0 +1,19 @@
-- status
drop table if exists mm_status;
-- mm_type
drop table if exists mm_type;
-- tag
drop table if exists mm_tag;
-- priority
drop table if exists mm_priority;
-- plan
drop table if exists mm_plan;
drop table if exists mm_plan_tag ;
-- promise
drop table if exists mm_promise;

View File

@@ -0,0 +1,2 @@
curl -d '{"token":"eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJNX1VzZXJJRCI6IjUyNSIsIk1fVXNlclVzZXJuYW1lIjoiZXZpdGEiLCJNX1VzZXJHcm91cERhc2hib2FyZCI6Im9uZS11aVwvcmVwb3J0XC9vbmUtcmVwb3J0LXY3XC8iLCJNX1VzZXJEZWZhdWx0VF9TYW1wbGVTdGF0aW9uSUQiOiIwIiwiTV9TdGFmZk5hbWUiOiJFVklUQSBPS1RBVklBIiwiTV9Vc2VyR3JvdXBJRCI6IjciLCJNX1N0YWZmTklLIjoiMTIuMTcwMi4yMjU0IiwiaXAiOiIxMTguOTkuMTE4LjEzNyIsImFnZW50IjoiY3VybFwvNy43NC4wIn0.b0Zo7ohaDJCqZHj1LYbos5JDr8IYw2cCVHikYceOXLk" }' \
http://devbandungraya.aplikasi.web.id/one-api/mobile_marketing/sumary

View File

@@ -0,0 +1,40 @@
Login
paul
risa
evita
curl -d '{"username":"evita", "password":"xx123"}' http://devbandungraya.aplikasi.web.id/one-api/mobile_marketing/auth/
{
"data" : {
"token" : "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJNX1VzZXJJRCI6IjUyNSIsIk1fVXNlclVzZXJuYW1lIjoiZXZpdGEiLCJNX1VzZXJHcm91cERhc2hib2FyZCI6Im9uZS11aVwvcmVwb3J0XC9vbmUtcmVwb3J0LXY3XC8iLCJNX1VzZXJEZWZhdWx0VF9TYW1wbGVTdGF0aW9uSUQiOiIwIiwiTV9TdGFmZk5hbWUiOiJFVklUQSBPS1RBVklBIiwiTV9Vc2VyR3JvdXBJRCI6IjciLCJNX1N0YWZmTklLIjoiMTIuMTcwMi4yMjU0IiwiaXAiOiIxMTguOTkuMTE4LjEzNyIsImFnZW50IjoiY3VybFwvNy43NC4wIn0.b0Zo7ohaDJCqZHj1LYbos5JDr8IYw2cCVHikYceOXLk",
"user" : {
"M_StaffNIK" : "12.1702.2254",
"M_StaffName" : "EVITA OKTAVIA",
"M_UserDefaultT_SampleStationID" : "0",
"M_UserGroupDashboard" : "one-ui/report/one-report-v7/",
"M_UserGroupID" : "7",
"M_UserID" : "525",
"M_UserUsername" : "evita",
"agent" : "curl/7.74.0",
"ip" : "118.99.118.137"
}
},
"status" : "OK"
}
curl -d '{"token" : "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJNX1VzZXJJRCI6IjUyNSIsIk1fVXNlclVzZXJuYW1lIjoiZXZpdGEiLCJNX1VzZXJHcm91cERhc2hib2FyZCI6Im9uZS11aVwvcmVwb3J0XC9vbmUtcmVwb3J0LXY3XC8iLCJNX1VzZXJEZWZhdWx0VF9TYW1wbGVTdGF0aW9uSUQiOiIwIiwiTV9TdGFmZk5hbWUiOiJFVklUQSBPS1RBVklBIiwiTV9Vc2VyR3JvdXBJRCI6IjciLCJNX1N0YWZmTklLIjoiMTIuMTcwMi4yMjU0IiwiaXAiOiIxMTguOTkuMTE4LjEzNyIsImFnZW50IjoiY3VybFwvNy43NC4wIn0.b0Zo7ohaDJCqZHj1LYbos5JDr8IYw2cCVHikYceOXLk"}' http://devbandungraya.aplikasi.web.id/one-api/v1/system/auth/islogin
{
"data" : {
"user" : {
"M_StaffName" : null,
"M_UserDefaultT_SampleStationID" : "0",
"M_UserGroupDashboard" : "one-ui/report/one-report-v7/",
"M_UserGroupID" : "7",
"M_UserID" : "525",
"M_UserUsername" : "evita",
"agent" : "curl/7.74.0",
"ip" : "182.253.151.204"
}
},
"status" : "OK"
}

View File

@@ -0,0 +1,117 @@
-- status
drop table if exists mkt_status;
create table mkt_status (
Mkt_StatusID int not null auto_increment primary key,
Mkt_StatusName varchar(50),
Mkt_StatusIsActive varchar(1) default 'Y',
Mkt_StatusCreated datetime default current_timestamp(),
Mkt_StatusLastUpdated datetime default current_timestamp() on update current_timestamp(),
key (Mkt_StatusIsActive),
key (Mkt_StatusName)
);
insert into mkt_status(Mkt_StatusName)
values ('Plan'), ('Re-Schedule'), ('Cancel') , ('Done') ;
-- mkt_type
drop table if exists mkt_type;
create table mkt_type (
Mkt_TypeID int not null auto_increment primary key,
Mkt_TypeName varchar(50),
Mkt_TypeIsActive varchar(1) default 'Y',
Mkt_TypeCreated datetime default current_timestamp(),
Mkt_TypeLastUpdated datetime default current_timestamp() on update current_timestamp(),
key (Mkt_TypeIsActive),
key (Mkt_TypeName)
);
insert into mkt_type(Mkt_TypeName)
values ('Visit'), ('Phone'), ('Video Call') , ('Other');
-- tag
drop table if exists mkt_tag;
create table mkt_tag (
Mkt_TagID int not null auto_increment primary key,
Mkt_TagName varchar(50),
Mkt_TagIsActive varchar(1) default 'Y',
Mkt_TagCreated datetime default current_timestamp(),
Mkt_TagLastUpdated datetime default current_timestamp() on update current_timestamp(),
key (Mkt_TagIsActive),
key (Mkt_TagName)
);
insert into mkt_tag(Mkt_TagName)
values ('Routine'),
('Marketing Plan A');
-- priority
drop table if exists mkt_priority;
create table mkt_priority (
Mkt_PriorityID int not null auto_increment primary key,
Mkt_PriorityName varchar(50),
Mkt_PriorityIsActive varchar(1) default 'Y',
Mkt_PriorityCreated datetime default current_timestamp(),
Mkt_PriorityLastUpdated datetime default current_timestamp() on update current_timestamp(),
key (Mkt_PriorityIsActive),
key (Mkt_PriorityName)
);
insert into mkt_priority(Mkt_PriorityName)
values ('Low'),
('Normal'),
('High');
-- plan
drop table if exists mkt_plan;
create table mkt_plan(
Mkt_PlanID int not null auto_increment primary key,
Mkt_PlanMkt_PriorityID int ,
Mkt_PlanM_DoctorID int,
Mkt_PlanDate datetime,
Mkt_PlanM_UserID int,
Mkt_PlanActionDate datetime,
Mkt_PlanIsAddHoc varchar(1) default 'N',
Mkt_PlanMkt_TypeID int default 1,
Mkt_PlanMkt_StatusID int default 1,
Mkt_PlanTitle varchar(50),
Mkt_PlanDescription varchar(300),
Mkt_PlanIsChildren varchar(1) default 'N',
Mkt_PlanParentID int default 0,
Mkt_PlanHasPromise varchar(1) default 'N',
Mkt_PlanConclusion varchar(300),
Mkt_PlanIsActive varchar(1) default 'Y',
Mkt_PlanCreated datetime default current_timestamp(),
Mkt_PlanLastUpdated datetime default current_timestamp() on update current_timestamp(),
key(Mkt_PlanM_DoctorID),
key(Mkt_PlanIsAddHoc),
key(Mkt_PlanM_UserID),
key(Mkt_PlanDate),
key(Mkt_PlanActionDate),
key(Mkt_PlanMkt_TypeID),
key(Mkt_PlanIsActive),
key(Mkt_PlanCreated),
key(Mkt_PlanLastUpdated),
key(Mkt_PlanMkt_PriorityID)
);
drop table if exists mkt_plan_tag ;
create table mkt_plan_tag (
Mkt_PlanTagID int not null auto_increment primary key,
Mkt_PlanTagMkt_PlanID int,
Mkt_PlanTagMkt_TagID int,
Mkt_PlanIsActive varchar(1) default 'Y',
key(Mkt_PlanTagMkt_PlanID),
key(Mkt_PlanTagMkt_TagID)
);
-- promise
drop table if exists mkt_promise;
create table mkt_promise (
Mkt_PromiseID int not null auto_increment primary key,
Mkt_PromiseMkt_PlanID int,
Mkt_PromiseDate datetime,
Mkt_PromiseTitle varchar(50),
Mkt_PromiseDescription varchar(300),
Mkt_PromiseIsFullfilled varchar(1) default 'N',
Mkt_PromiseIsActive varchar(1) default 'Y',
key(Mkt_PromiseDate),
key(Mkt_PromiseIsFullfilled),
key(Mkt_PromiseIsActive)
);

View File

@@ -0,0 +1,196 @@
<?php
class Counter extends MY_Controller
{
var $db_antrione;
public function index()
{
echo "SERVICE API";
}
public function __construct()
{
parent::__construct();
$this->db_antrione = $this->load->database("antrione", true);
}
public function loadx()
{
try {
//# cek token valid
/*if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}*/
$prm = $this->sys_input;
$sql = "select COUNT(*) as total
from counter
where
counterIsActive = 'Y'";
$sql_param = array($search);
$total = $this->db_antrione->query($sql,$sql_param)->row()->total;
$sql = "select *
from counter
where
counterIsActive = 'Y'";
$sql_param = array($search);
$query = $this->db_antrione->query($sql,$sql_param);
//echo $this->db_antrione->last_query();
if ($query) {
$rows = $query->result_array();
} else {
$this->sys_error_db("counter select");
exit;
}
$result = array ("total" => $total, "total_filter"=>count($rows),"records" => $rows);
$this->sys_ok($result);
} catch(Exception $exc) {
$message = $exc->getMessage();
$this->sys_error($message);
}
}
public function save()
{
try {
//# cek token valid
/*if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}*/
//# ambil parameter input
$prm = $this->sys_input;
$code = $prm['code'];
$ip = $prm['ip'];
$query = "SELECT COUNT(*) as exist FROM counter WHERE counterIsActive = 'Y' AND counterCode = '{$code}'";
$exist_code = $this->db_antrione->query($query)->row()->exist;
if($exist_code == 0){
$sql = "insert into counter(
counterCode,
counterIP
)
values( ?,?)";
$query = $this->db_antrione->query($sql,
array(
$code,
$ip
)
);
//echo $query;
if (!$query) {
$this->sys_error_db("counter insert");
exit;
}
$result = array ("total" => 1, "records" => array("xid" => 0));
$this->sys_ok($result);
}else{
$result = array ("total" => -1, "records" => 0);
$this->sys_ok($result);
}
} catch(Exception $exc) {
$message = $exc->getMessage();
$this->sys_error($message);
}
}
public function update()
{
try {
//# cek token valid
/*if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}*/
//# ambil parameter input
$prm = $this->sys_input;
$id = $prm['id'];
$code = $prm['code'];
$ip = $prm['ip'];
$query = "SELECT COUNT(*) as exist FROM counter WHERE counterIsActive = 'Y' AND counterCode = '{$code}' AND counterID <> {$id}";
//echo $query;
$exist_code = $this->db_antrione->query($query)->row()->exist;
if($exist_code == 0){
$sql = "update counter set
counterCode = ?,
counterIP = ?
where counterID = ?
";
$query = $this->db_antrione->query($sql,
array(
$code,
$ip,
$id
)
);
//echo $query;
if (!$query) {
$this->sys_error_db("counter update");
exit;
}
$result = array ("total" => 1, "records" => array("xid" => 0));
$this->sys_ok($result);
}else{
$result = array ("total" => -1, "records" => 0);
$this->sys_ok($result);
}
} catch(Exception $exc) {
$message = $exc->getMessage();
$this->sys_error($message);
}
}
public function deletex()
{
try {
//# cek token valid
/*if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}*/
//# ambil parameter input
$prm = $this->sys_input;
$id = $prm['id'];
$sql = "update counter set
counterIsActive = 'N'
where counterID = ?
";
$query = $this->db_antrione->query($sql,
array(
$id
)
);
//echo $query;
if (!$query) {
$this->sys_error_db("counter delete");
exit;
}
$result = array ("total" => 1, "records" => array("xid" => 0));
$this->sys_ok($result);
} catch(Exception $exc) {
$message = $exc->getMessage();
$this->sys_error($message);
}
}
}

View File

@@ -0,0 +1,210 @@
<?php
class Numbering extends MY_Controller
{
var $db_antrione;
public function index()
{
echo "SERVICE API";
}
public function __construct()
{
parent::__construct();
$this->db_antrione = $this->load->database("antrione", true);
}
public function loadx()
{
try {
//# cek token valid
/*if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}*/
$prm = $this->sys_input;
$sql = "select COUNT(*) as total
from numbering
where
numberingIsActive = 'Y'";
$sql_param = array($search);
$total = $this->db_antrione->query($sql,$sql_param)->row()->total;
$sql = "select *
from numbering
join service ON numberingServiceID = ServiceID
where
numberingIsActive = 'Y'";
$sql_param = array($search);
$query = $this->db_antrione->query($sql,$sql_param);
//echo $this->db_antrione->last_query();
if ($query) {
$rows = $query->result_array();
} else {
$this->sys_error_db("numbering select");
exit;
}
$result = array ("total" => $total, "total_filter"=>count($rows),"records" => $rows);
$this->sys_ok($result);
} catch(Exception $exc) {
$message = $exc->getMessage();
$this->sys_error($message);
}
}
public function save()
{
try {
//# cek token valid
/*if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}*/
//# ambil parameter input
$prm = $this->sys_input;
$serviceid = $prm['serviceid'];
$prefix = $prm['prefix'];
$prefixdate = $prm['prefixdate'];
$digit = $prm['digit'];
$sufix = $prm['sufix'];
$counter = $prm['counter'];
$reset = $prm['reset'];
$sql = "insert into numbering(
numberingServiceID,
numberingPrefix,
numberingPrefixDate,
numberingDigit,
numberingSufix,
numberingCounter,
numberingReset
)
values( ?,?,?,?,?,?,?)";
$query = $this->db_antrione->query($sql,
array(
$serviceid,
$prefix,
$prefixdate,
$digit,
$sufix,
$counter,
$reset
)
);
//echo $query;
if (!$query) {
$this->sys_error_db("numbering insert");
exit;
}
$result = array ("total" => 1, "records" => array("xid" => 0));
$this->sys_ok($result);
} catch(Exception $exc) {
$message = $exc->getMessage();
$this->sys_error($message);
}
}
public function update()
{
try {
//# cek token valid
/*if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}*/
//# ambil parameter input
$prm = $this->sys_input;
$id = $prm['id'];
$serviceid = $prm['serviceid'];
$prefix = $prm['prefix'];
$prefixdate = $prm['prefixdate'];
$digit = $prm['digit'];
$sufix = $prm['sufix'];
$counter = $prm['counter'];
$reset = $prm['reset'];
$sql = "update numbering set
numberingServiceID = ?,
numberingPrefix = ?,
numberingPrefixDate = ?,
numberingDigit = ?,
numberingSufix = ?,
numberingCounter = ?,
numberingReset = ?
where numberingID = ?
";
$query = $this->db_antrione->query($sql,
array(
$serviceid,
$prefix,
$prefixdate,
$digit,
$sufix,
$counter,
$reset,
$id
)
);
//echo $query;
if (!$query) {
$this->sys_error_db("numbering update");
exit;
}
$result = array ("total" => 1, "records" => array("xid" => 0));
$this->sys_ok($result);
} catch(Exception $exc) {
$message = $exc->getMessage();
$this->sys_error($message);
}
}
public function deletex()
{
try {
//# cek token valid
/*if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}*/
//# ambil parameter input
$prm = $this->sys_input;
$id = $prm['id'];
$sql = "update numbering set
numberingIsActive = 'N'
where numberingID = ?
";
$query = $this->db_antrione->query($sql,
array(
$id
)
);
//echo $query;
if (!$query) {
$this->sys_error_db("numbering delete");
exit;
}
$result = array ("total" => 1, "records" => array("xid" => 0));
$this->sys_ok($result);
} catch(Exception $exc) {
$message = $exc->getMessage();
$this->sys_error($message);
}
}
}

View File

@@ -0,0 +1,201 @@
<?php
class Service extends MY_Controller
{
var $db_antrione;
public function index()
{
echo "SERVICE API";
}
public function __construct()
{
parent::__construct();
$this->db_antrione = $this->load->database("antrione", true);
}
public function loadx()
{
try {
//# cek token valid
/*if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}*/
$prm = $this->sys_input;
$sql = "select COUNT(*) as total
from service
where
serviceIsActive = 'Y'";
$sql_param = array($search);
$total = $this->db_antrione->query($sql,$sql_param)->row()->total;
$sql = "select *
from service
where
serviceIsActive = 'Y'";
$sql_param = array($search);
$query = $this->db_antrione->query($sql,$sql_param);
//echo $this->db_antrione->last_query();
if ($query) {
$rows = $query->result_array();
} else {
$this->sys_error_db("m_schedule select");
exit;
}
$result = array ("total" => $total, "total_filter"=>count($rows),"records" => $rows,
"ownIP" => $_SERVER["REMOTE_ADDR"] );
$this->sys_ok($result);
} catch(Exception $exc) {
$message = $exc->getMessage();
$this->sys_error($message);
}
}
public function save()
{
try {
//# cek token valid
/*if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}*/
//# ambil parameter input
$prm = $this->sys_input;
$code = $prm['code'];
$name = $prm['name'];
$priority = $prm['priority'];
$query = "SELECT COUNT(*) as exist FROM service WHERE serviceIsActive = 'Y' AND serviceCode = '{$code}'";
$exist_code = $this->db_antrione->query($query)->row()->exist;
if($exist_code == 0){
$sql = "insert into service(
serviceCode,
serviceName,
servicePriority
)
values( ?,?,?)";
$query = $this->db_antrione->query($sql,
array(
$code,
$name,
$priority
)
);
//echo $query;
if (!$query) {
$this->sys_error_db("service insert");
exit;
}
$result = array ("total" => 1, "records" => array("xid" => 0));
$this->sys_ok($result);
}else{
$result = array ("total" => -1, "records" => 0);
$this->sys_ok($result);
}
} catch(Exception $exc) {
$message = $exc->getMessage();
$this->sys_error($message);
}
}
public function update()
{
try {
//# cek token valid
/*if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}*/
//# ambil parameter input
$prm = $this->sys_input;
$id = $prm['id'];
$code = $prm['code'];
$name = $prm['name'];
$priority = $prm['priority'];
$query = "SELECT COUNT(*) as exist FROM service WHERE serviceIsActive = 'Y' AND serviceCode = '{$code}' AND serviceID <> {$id}";
//echo $query;
$exist_code = $this->db_antrione->query($query)->row()->exist;
if($exist_code == 0){
$sql = "update service set
serviceCode = ?,
serviceName = ?,
servicePriority = ?
where serviceID = ?
";
$query = $this->db_antrione->query($sql,
array(
$code,
$name,
$priority,
$id
)
);
//echo $query;
if (!$query) {
$this->sys_error_db("service update");
exit;
}
$result = array ("total" => 1, "records" => array("xid" => 0));
$this->sys_ok($result);
}else{
$result = array ("total" => -1, "records" => 0);
$this->sys_ok($result);
}
} catch(Exception $exc) {
$message = $exc->getMessage();
$this->sys_error($message);
}
}
public function deletex()
{
try {
//# cek token valid
/*if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}*/
//# ambil parameter input
$prm = $this->sys_input;
$id = $prm['id'];
$sql = "update service set
serviceIsActive = 'N'
where serviceID = ?
";
$query = $this->db_antrione->query($sql,
array(
$id
)
);
//echo $query;
if (!$query) {
$this->sys_error_db("service delete");
exit;
}
$result = array ("total" => 1, "records" => array("xid" => 0));
$this->sys_ok($result);
} catch(Exception $exc) {
$message = $exc->getMessage();
$this->sys_error($message);
}
}
}

View File

@@ -0,0 +1,714 @@
<?php
class Register extends MY_Controller
{
var $db_onedev;
public function index()
{
echo "Register API";
}
public function __construct()
{
parent::__construct();
$this->db_onedev = $this->load->database("onedev", true);
}
public function search()
{
$prm = $this->sys_input;
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$norm = $prm["snorm"];
$nama = $prm["nama"];
$status = $prm["status"];
$sql_where = "WHERE F_BillIsActive = 'Y' AND F_BillIsLunas = '{$status}'";
$sql_param = array();
if ($nama != "") {
if ($sql_where != "") {
$sql_where .=" and ";
}
$sql_where .= " M_CompanyName like ? ";
$sql_param[] = "%$nama%";
}
if ($norm != "") {
if ($sql_where != "") {
$sql_where .=" and ";
}
$sql_where .= " F_BillNo like ? ";
$sql_param[] = "%$norm%";
}
$sql = " SELECT count(*) as total
FROM f_bill
LEFT JOIN m_mou ON F_BillM_MouID = M_MouID
left join m_company on M_MouM_CompanyID = M_CompanyID
$sql_where
";
$query = $this->db_onedev->query($sql, $sql_param);
$tot_count = 0;
if ($query) {
$tot_count = $query->result_array()[0]["total"];
} else {
$this->sys_error_db("f_bill count", $this->db_onedev);
exit;
}
$sql = "SELECT
F_BillID,
F_BillNo,
F_BillM_MouID,
M_MouID,
IF(F_BillM_MouID = 0, 'Semua',M_MouName) as M_MouName,
F_BillDueDateDay,
DATE_FORMAT(F_BillDueDate,'%d/%m/%Y') as F_BillDueDate ,
DATE_FORMAT(F_BillDueDate,'%Y-%m-%d') as sdate,
F_BillTotal,
F_BillUnpaid,
F_BillReceive ,
F_BillIsLunas ,
F_BillIsClosed ,
DATE_FORMAT(F_BillCreated,'%d/%m/%Y') as F_BillCreated,
F_BillUserID ,
F_BillNote,
M_CompanyID,
M_CompanyName
FROM f_bill
LEFT JOIN m_mou ON F_BillM_MouID = M_MouID
left join m_company on F_BillM_CompanyID = M_CompanyID
$sql_where
ORDER BY F_BillNo DESC
limit 0,$tot_count ";
$query = $this->db_onedev->query($sql, $sql_param);
$rows = $query->result_array();
if($rows){
foreach($rows as $k => $v){
$x = $this->db_onedev->query("
select count(*) as tot
FROM f_bill_detail
where F_BillDetailF_BillID = '{$v['F_BillID']}'")->row();
if($x->tot == 0 ) {
$rows[$k]['haveDetail'] = "N";
} else {
$rows[$k]['haveDetail'] = "Y";
}
}
}
$result = array("total" => $tot_count, "records" => $rows, "sql"=> $this->db_onedev->last_query());
$this->sys_ok($result);
exit;
}
function searchcompany(){
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$prm = $this->sys_input;
$max_rst = 12;
$tot_count =0;
$q = [
'search' => '%'
];
if ($prm['search'] != '')
{
$q['search'] = "%{$prm['search']}%";
}
// QUERY TOTAL
$sql = "SELECT count(*) as total
FROM m_company
WHERE
M_CompanyName like ?
AND M_CompanyIsActive = 'Y' AND M_CompanyIsLabFrom = 'Y'";
$query = $this->db_onedev->query($sql,$q['search']);
//echo $query;
if ($query) {
$tot_count = $query->result_array()[0]["total"];
}
else {
$this->sys_error_db("m_company count",$this->db_onedev);
exit;
}
$sql = "
SELECT *
FROM m_company
WHERE
M_CompanyName like ?
AND M_CompanyIsActive = 'Y' AND M_CompanyIsLabFrom = 'Y'
ORDER BY M_CompanyName DESC
";
$query = $this->db_onedev->query($sql, array($q['search']));
if ($query) {
$rows = $query->result_array();
//echo $this->db_onedev->last_query();
$result = array("total" => $tot_count, "records" => $rows, "total_display" => sizeof($rows));
$this->sys_ok($result);
}
else {
$this->sys_error_db("m_company rows",$this->db_onedev);
exit;
}
}
function getmou(){
$prm = $this->sys_input;
$query =" SELECT 0 as M_MouID, 'Semua' as M_MouName
UNION
SELECT M_MouID, M_MouName
FROM m_mou
WHERE
M_MouIsActive = 'Y' AND M_MouIsBill = 'Y' AND M_MouM_CompanyID = ?
";
//echo $query;
$rows = $this->db_onedev->query($query,array($prm['id']))->result_array();
$result = array(
"total" => count($rows) ,
"records" => $rows,
);
$this->sys_ok($result);
exit;
}
function getsexreg(){
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$rows = [];
$query =" SELECT *
FROM m_sex
WHERE
M_SexIsActive = 'Y'
";
//echo $query;
$rows['sexes'] = $this->db_onedev->query($query)->result_array();
$result = array(
"total" => count($rows) ,
"records" => $rows,
);
$this->sys_ok($result);
exit;
}
function save(){
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$prm = $this->sys_input;
$pdob = date('Y-m-d',strtotime($prm['M_PatientDOB']));
$query ="UPDATE m_patient SET
M_PatientM_TitleID = '{$prm['M_PatientM_TitleID']}',
M_PatientName = '{$prm['M_PatientName']}',
M_PatientDOB = '{$pdob}',
M_PatientM_SexID = '{$prm['M_PatientM_SexID']}',
M_PatientM_ReligionID = '{$prm['M_PatientM_ReligionID']}',
M_PatientEmail = '{$prm['M_PatientEmail']}',
M_PatientHP = '{$prm['M_PatientHP']}',
M_PatientPhone = '{$prm['M_PatientPhone']}',
M_PatientM_IdTypeID = '{$prm['M_PatientM_IdTypeID']}',
M_PatientIDNumber = '{$prm['M_PatientIDNumber']}',
M_PatientNote = '{$prm['M_PatientNote']}'
WHERE
M_PatientID = '{$prm['M_PatientID']}'
";
//echo $query;
$rows = $this->db_onedev->query($query);
$result = array(
"total" => 1 ,
"records" => array('status'=>'OK')
);
$this->sys_ok($result);
exit;
}
function newreceivereference(){
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$prm = $this->sys_input;
$pdate = date('Y-m-d',strtotime($prm['sdate']));
$userid = $this->sys_user["M_UserID"];
$query ="INSERT INTO f_bill (
F_BillNo,
F_BillM_CompanyID,
F_BillM_MouID,
F_BillDueDateDay,
F_BillDueDate,
F_BillNote,
F_BillUserID,
F_BillCreated
)
VALUES(
`fn_numbering`('BL'),
'{$prm['companyid']}',
'{$prm['mouid']}',
'{$prm['day']}',
'{$pdate}',
'{$prm['note']}',
'{$userid}',
NOW()
)
";
// echo $query;
$rows = $this->db_onedev->query($query);
$last_id = $this->db_onedev->insert_id();
$querylog ="
";
$insert_new_log = $this->db_onedev->query($querylog);
$result = array(
"total" => 1 ,
"records" => array('status'=>'OK'),
"id" => $last_id
);
$this->sys_ok($result);
exit;
}
function editbill(){
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$prm = $this->sys_input;
$pdate = date('Y-m-d',strtotime($prm['sdate']));
$userid = $this->sys_user["M_UserID"];
$query ="UPDATE f_bill SET
F_BillDueDateDay = '{$prm['day']}',
F_BillDueDate = '{$pdate}',
F_BillNote = '{$prm['note']}',
F_BillUserID = '{$userid}',
F_BillCreated = now()
WHERE F_BillID = '{$prm['id']}'
";
// echo $query;
$rows = $this->db_onedev->query($query);
$last_id = $prm['id'];
$querylog ="
";
$insert_new_log = $this->db_onedev->query($querylog);
$result = array(
"total" => 1 ,
"records" => array('status'=>'OK'),
"id" => $last_id
);
$this->sys_ok($result);
exit;
}
function sendorder(){
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$prm = $this->sys_input;
$userid = $this->sys_user["M_UserID"];
$query ="UPDATE t_receivereferenceheader SET
T_ReceiveReferenceHeaderIsSent = 'Y',
T_ReceiveReferenceHeaderSentDate = now(),
T_ReceiveReferenceHeaderUserID = '{$userid}'
WHERE
T_ReceiveReferenceHeaderID = '{$prm['T_ReceiveReferenceHeaderID']}'
";
//echo $query;
$rows = $this->db_onedev->query($query);
$rows = $this->db_onedev->query($query);
$querylog ="INSERT INTO g_receivereferenceheaderstatuslog (
G_ReceiveReferenceHeaderStatusLogDate,
G_ReceiveReferenceHeaderStatusLogT_ReceiveReferenceHeaderID,
G_ReceiveReferenceHeaderStatusLogM_StatusReferenceID,
G_ReceiveReferenceHeaderStatusLogM_UserID,
G_ReceiveReferenceHeaderStatusLogUserID,
G_ReceiveReferenceHeaderStatusLogCreated,
G_ReceiveReferenceHeaderStatusLogLastUpdated
)
VALUES(
NOW(),
'{$prm['T_ReceiveReferenceHeaderID']}',
'2',
'{$userid}',
'{$userid}',
NOW(),
NOW()
)";
//echo $querylog;
$insert_new_log = $this->db_onedev->query($querylog);
$result = array(
"total" => 1 ,
"records" => array('status'=>'OK')
);
$this->sys_ok($result);
exit;
}
function save_patient() {
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$prm = $this->sys_input;
$sql = "insert into f_bill_detail(F_BillDetailF_BillID, F_BillDetailT_OrderHeaderID,
F_BillDetailTotal, F_BillDetailUnpaid) values(?,?,?,?)";
$billID = $prm["billID"];
// print_r($prm);
exit;
foreach($prm["patients"] as $p) {
$orderID = $p["T_OrderHeaderID"];
$total = $p["total"];
$this->db_onedev->query($sql,array($billID, $orderID, $total, $total));
}
$result = "Pasien saved";
$this->sys_ok($result);
}
function getpatient(){
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$prm = $this->sys_input;
$billID = $prm["id"];
$mouID = $prm["mouid"];
$sql = "select count(*) tot from f_bill_detail where F_BillDetailF_BillID=?";
$rst = $this->db_onedev->query($sql,array($billID))->row();
if ($rst->tot > 0 ) {
$sql = "select
M_CompanyID, M_CompanyName,
M_MouID,
M_MouName,
concat(M_TitleName,'. ',M_PatientName) as pasienname,
T_OrderHeaderTotal as total,
DATE_FORMAT(T_OrderHeaderDate,'%d/%m/%Y') as T_OrderHeaderDate,
T_OrderHeaderLabNumber,
'' as tes,
'xxx' as tests,
'' as action,
T_OrderHeaderID
FROM f_bill_detail
join t_orderheader ON F_BillDetailT_OrderHeaderID = T_OrderHeaderID
join m_patient on M_PatientID = T_OrderHeaderM_PatientID
join m_title on M_PatientM_TitleID = M_TitleID
left join m_mou ON T_OrderHeaderM_MouID = M_MouID
left join m_company ON T_OrderHeaderM_CompanyID = M_CompanyID
WHERE
F_BillDetailIsActive = 'Y' and F_BillDetailF_BillID = '{$billID}'
GROUP BY F_BillDetailID
order by F_BillDetailID asc";
} else {
$sql = "select
M_CompanyID, M_CompanyName,
M_MouID,
M_MouName,
concat(M_TitleName,'. ',M_PatientName) as pasienname,
T_OrderHeaderTotal as total,
DATE_FORMAT(T_OrderHeaderDate,'%d/%m/%Y') as T_OrderHeaderDate,
T_OrderHeaderLabNumber,
'' as tes,
'xxx' as tests,
'' as action,
T_OrderHeaderID
FROM t_orderheader
join f_bill on F_BillID = '{$billID}'
left join m_company ON F_BillM_CompanyID = M_CompanyID
LEFT JOIN f_bill_detail ON T_OrderHeaderID = F_BillDetailT_OrderHeaderID AND F_BillDetailIsActive = 'Y'
LEFT JOIN f_payment ON T_OrderHeaderID = F_PaymentT_OrderHeaderID AND F_PaymentIsActive = 'Y'
join m_patient on M_PatientID = T_OrderHeaderM_PatientID
join m_title on M_PatientM_TitleID = M_TitleID
join m_mou ON T_OrderHeaderM_MouID = M_MouID AND M_MouIsBill = 'Y'
WHERE
T_OrderHeaderIsActive = 'Y' AND
T_OrderHeaderM_CompanyID = M_CompanyID AND
($mouID = 0 OR($mouID > 0 AND T_OrderHeaderM_MouID = $mouID)) AND
F_BillDetailID IS NULL AND F_PaymentID IS NULL
order by T_OrderHeaderDate asc, T_OrderHeaderID asc";
}
//echo $sql;
$qry = $this->db_onedev->query($sql);
$rows = array();
if ($qry) {
$rows = $qry->result_array();
}
$result = array(
"total" => count($rows) ,
"records" => $rows,
);
$this->sys_ok($result);
exit;
}
function add_test($orderid){
$query =" SELECT t_receivereferencetest.*, t_test.*,'Y' as editable, T_ReceiveReferenceTestT_TestID as xid,
T_ReceiveReferenceTestT_TestPrice as T_PriceAmount,
T_ReceiveReferenceTestT_TestDisc as T_PriceDisc,
T_ReceiveReferenceTestT_TestDiscRp as T_PriceDiscRp,
T_ReceiveReferenceTestT_TestTotal as total
FROM t_receivereferencetest
JOIN t_receivereferencepatient ON T_ReceiveReferenceTestT_ReceiveReferencePatientID = T_ReceiveReferencePatientID
JOIN t_receivereferenceheader ON T_ReceiveReferencePatientT_ReceiveReferenceHeaderID = T_ReceiveReferenceHeaderID
JOIN t_test ON T_ReceiveReferenceTestT_TestID = T_TestID
WHERE
T_ReceiveReferenceTestT_ReceiveReferencePatientID = {$orderid} AND T_ReceiveReferenceTestIsActive = 'Y'
GROUP BY T_ReceiveReferenceTestID";
//echo $query;
$rows = $this->db_onedev->query($query)->result_array();
if(!$rows)
$rows = array();
return $rows;
}
function savenewpatient(){
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$prm = $this->sys_input;
$billID = $prm['billID'];
$userid = $this->sys_user["M_UserID"];
foreach($prm['patients'] as $k=>$v){
$query = "INSERT INTO f_bill_detail
(F_BillDetailF_BillID,
F_BillDetailT_OrderHeaderID,
F_BillDetailTotal,
F_BillDetailUnpaid,
F_BillDetailUserID,
F_BillDetailCreated,
F_BillDetailLastUpdated)
VALUE(
?,?,?,?,?,now(),now()
)";
$insert_new_test = $this->db_onedev->query($query,array(
$billID,
$v['T_OrderHeaderID'],
$v['total'],
$v['total'],
$userid
));
}
$result = array(
"total" => 1 ,
"records" => array('status'=>'OK')
);
$this->sys_ok($result);
exit;
}
function saveeditpatient(){
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$prm = $this->sys_input;
$order_id = $prm['T_ReceiveReferencePatientID'];
$pdob = date('Y-m-d',strtotime($prm['T_ReceiveReferencePatientDOB']));
$userid = $this->sys_user["M_UserID"];
$query ="UPDATE t_receivereferencepatient SET
T_ReceiveReferencePatientT_ReceiveReferenceHeaderID = '{$prm['T_ReceiveReferencePatientT_ReceiveReferenceHeaderID']}',
T_ReceiveReferencePatientNoRef = '{$prm['T_ReceiveReferencePatientNoRef']}',
T_ReceiveReferencePatientName = '{$prm['T_ReceiveReferencePatientName']}',
T_ReceiveReferencePatientDOB = '{$pdob}',
T_ReceiveReferencePatientM_SexID = '{$prm['T_ReceiveReferencePatientM_SexID']}',
T_ReceiveReferencePatientTotal = '{$prm['T_ReceiveReferencePatientTotal']}',
T_ReceiveReferencePatientDPPercent = '{$prm['T_ReceiveReferencePatientDPPercent']}',
T_ReceiveReferencePatientDPAmount = '{$prm['T_ReceiveReferencePatientDPAmount']}',
T_ReceiveReferencePatientUserID = '{$userid}'
WHERE
T_ReceiveReferencePatientID = '{$prm['T_ReceiveReferencePatientID']}'
";
//echo $query;
$rows = $this->db_onedev->query($query);
foreach($prm['ordertests'] as $k=>$v){
if($v['xid'] == 0 || $v['xid'] == '0'){
$query = "INSERT INTO t_receivereferencetest (
T_ReceiveReferenceTestT_ReceiveReferencePatientID,
T_ReceiveReferenceTestT_TestID,
T_ReceiveReferenceTestT_TestCode,
T_ReceiveReferenceTestT_TestName,
T_ReceiveReferenceTestT_TestPrice,
T_ReceiveReferenceTestUserID,
T_ReceiveReferenceTestCreated,
T_ReceiveReferenceTestLastUpdated
)
VALUE(
?,?,?,?,?,?,now(),now()
)";
$insert_new_test = $this->db_onedev->query($query,array(
$order_id,
$v['T_TestID'],
$v['T_TestCode'],
$v['T_TestName'],
$v['total'],
$userid
));
}
}
if(isset($prm['deleted_ordertests'])){
foreach($prm['deleted_ordertests'] as $i=>$del){
$query = "UPDATE t_receivereferencetest SET
T_ReceiveReferenceTestIsActive = 'N',
T_ReceiveReferenceTestUserID = '{$userid}',
T_ReceiveReferenceTestLastUpdated = now()
WHERE
T_ReceiveReferenceTestID = ?
";
$delete_exist_test = $this->db_onedev->query($query,array($del['T_ReceiveReferenceTestID'],));
}
}
$result = array(
"total" => 1 ,
"records" => array('status'=>'OK')
);
$this->sys_ok($result);
exit;
}
function deletebill(){
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$prm = $this->sys_input;
$userid = $this->sys_user["M_UserID"];
$query ="UPDATE f_bill SET
F_BillIsActive = 'N',
F_BillUserID = '{$userid}'
WHERE
F_BillID = '{$prm['id']}'";
//echo $query;
$rows = $this->db_onedev->query($query);
$query ="UPDATE f_bill_detail SET
F_BillDetailIsActive = 'N',
F_BillDetailUserID = '{$userid}'
WHERE
F_BillDetailF_BillID = '{$prm['id']}'";
//echo $query;
$rows = $this->db_onedev->query($query);
$result = array(
"total" => 1 ,
"records" => array('status'=>'OK')
);
$this->sys_ok($result);
exit;
}
function deletepatient(){
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$prm = $this->sys_input;
$userid = $this->sys_user["M_UserID"];
$query ="UPDATE f_bill_detail SET
F_BillDetailIsActive = 'N',
F_BillDetailUserID = '{$userid}'
WHERE
F_BillDetailID = '{$prm['F_BillDetailID']}'
";
//echo $query;
$rows = $this->db_onedev->query($query);
//echo $query;
$rows = $this->db_onedev->query($query);
$result = array(
"total" => 1 ,
"records" => array('status'=>'OK')
);
$this->sys_ok($result);
exit;
}
function searchtest(){
$prm = $this->sys_input;
$max_rst = 12;
$tot_count = 0;
$q = [
'search' => '%'
];
if ($prm['search'] != '')
{
$q['search'] = "%{$prm['search']}%";
}
$mou_id = $prm['mouid'];
// QUERY TOTAL
$sql = "SELECT count(*) as total
FROM t_test
JOIN t_price ON T_PriceT_TestID = T_TestID AND T_PriceIsCito = 'N' AND T_PriceM_MouID = '{$mou_id}'
WHERE
T_TestName like ? AND
T_TestIsActive = 'Y'
ORDER BY T_TestName ASC";
$query = $this->db_onedev->query($sql,$q['search']);
//echo $query;
if ($query) {
$tot_count = $query->result_array()[0]["total"];
}
else {
$this->sys_error_db("test count",$this->db_onedev);
exit;
}
$sql = "
SELECT 'Y' as editable,
0 as xid,
T_TestID,
T_TestCode,
T_TestName, T_PriceAmount, T_PriceDisc, T_PriceDiscRp, T_PriceAmount - ((T_PriceDisc/100) * T_PriceAmount) - T_PriceDiscRp as total,
M_CompanyID,'N' as M_CompanyIsBill, 0 as M_CompanyMinDP
FROM one.t_test
JOIN one.t_price ON T_PriceT_TestID = T_TestID AND T_PriceIsCito = 'N' AND T_PriceM_MouID = '{$mou_id}'
JOIN one.m_mou ON M_MouID = '{$mou_id}'
JOIN one.m_company ON M_MouM_CompanyID = M_CompanyID
WHERE
T_TestName like ? AND
T_TestIsActive = 'Y'
ORDER BY T_TestName ASC
";
$query = $this->db_onedev->query($sql, array($q['search']));
if ($query) {
$rows = $query->result_array();
//echo $this->db_onedev->last_query();
$result = array("total" => $tot_count, "records" => $rows, "total_display" => sizeof($rows));
$this->sys_ok($result);
}
else {
$this->sys_error_db("test rows",$this->db_onedev);
exit;
}
}
}

View File

@@ -0,0 +1,681 @@
<?php
class Register extends MY_Controller
{
var $db_onedev;
public function index()
{
echo "Register API";
}
public function __construct()
{
parent::__construct();
$this->db_onedev = $this->load->database("onedev", true);
}
public function search()
{
$prm = $this->sys_input;
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$norm = $prm["snorm"];
$nama = $prm["nama"];
// echo $norm;
$sql_where = "WHERE F_BillIsActive = 'Y' ";
$sql_param = array();
if ($nama != "") {
if ($sql_where != "") {
$sql_where .=" and ";
}
$sql_where .= " M_CompanyName like ? ";
$sql_param[] = "%$nama%";
}
if ($norm != "") {
if ($sql_where != "") {
$sql_where .=" and ";
}
$sql_where .= " F_BillNo like ? ";
$sql_param[] = "%$norm%";
}
//if ($sql_where != "") $sql_where .= " and ";
// Order masih dalam status registrasi
//$sql_where .= " M_PatientIsActive = 'Y' ";
$sql = " SELECT count(*) as total
FROM f_bill
LEFT JOIN m_mou ON F_BillM_MouID = M_MouID
left join m_company on M_MouM_CompanyID = M_CompanyID
$sql_where
";
//echo $sql;
$query = $this->db_onedev->query($sql, $sql_param);
$tot_count = 0;
if ($query) {
$tot_count = $query->result_array()[0]["total"];
} else {
$this->sys_error_db("f_bill count", $this->db_onedev);
exit;
}
$sql = "SELECT
F_BillID,
F_BillNo,
M_MouName ,
DATE_FORMAT(F_BillDueDate,'%d/%m/%Y') as F_BillDueDate ,
F_BillTotal,
F_BillReceive ,
F_BillIsLunas ,
F_BillIsClosed ,
DATE_FORMAT(F_BillCreated,'%d/%m/%Y') as F_BillCreated,
F_BillUserID ,
F_BillNote,
M_CompanyName
FROM f_bill
LEFT JOIN m_mou ON F_BillM_MouID = M_MouID
left join m_company on M_MouM_CompanyID = M_CompanyID
$sql_where
ORDER BY F_BillNo DESC
limit 0,20";
$query = $this->db_onedev->query($sql, $sql_param);
$rows = $query->result_array();
if($rows){
foreach($rows as $k => $v){
$x = $this->db_onedev->query("
select
F_BillID,
F_BillNo,
M_MouName ,
DATE_FORMAT(F_BillDueDate,'%d/%m/%Y') as F_BillDueDate ,
F_BillTotal,
F_BillReceive ,
F_BillIsLunas ,
F_BillIsClosed ,
DATE_FORMAT(F_BillCreated,'%d/%m/%Y') as F_BillCreated,
F_BillUserID ,
F_BillNote,
M_CompanyName
FROM f_bill
LEFT JOIN m_mou ON F_BillM_MouID = M_MouID
left join m_company on M_MouM_CompanyID = M_CompanyID
WHERE F_BillID = '{$v['F_BillID']}' ")->row();
$rows[$k]['statuss'] = json_decode($x->n);
}
}
//$this->_add_address($rows);
$result = array("total" => $tot_count, "records" => $rows, "sql"=> $this->db_onedev->last_query());
$this->sys_ok($result);
exit;
}
function searchcompany(){
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$prm = $this->sys_input;
$max_rst = 12;
$tot_count =0;
$q = [
'search' => '%'
];
if ($prm['search'] != '')
{
$q['search'] = "%{$prm['search']}%";
}
// QUERY TOTAL
$sql = "SELECT count(*) as total
FROM m_company
WHERE
M_CompanyName like ?
AND M_CompanyIsActive = 'Y' AND M_CompanyIsLabFrom = 'Y'";
$query = $this->db_onedev->query($sql,$q['search']);
//echo $query;
if ($query) {
$tot_count = $query->result_array()[0]["total"];
}
else {
$this->sys_error_db("m_company count",$this->db_onedev);
exit;
}
$sql = "
SELECT *
FROM m_company
WHERE
M_CompanyName like ?
AND M_CompanyIsActive = 'Y' AND M_CompanyIsLabFrom = 'Y'
ORDER BY M_CompanyName DESC
";
$query = $this->db_onedev->query($sql, array($q['search']));
if ($query) {
$rows = $query->result_array();
//echo $this->db_onedev->last_query();
$result = array("total" => $tot_count, "records" => $rows, "total_display" => sizeof($rows));
$this->sys_ok($result);
}
else {
$this->sys_error_db("m_company rows",$this->db_onedev);
exit;
}
}
function getmou(){
$prm = $this->sys_input;
$query =" SELECT *
FROM m_mou
WHERE
M_MouIsActive = 'Y' AND M_MouM_CompanyID = ?
";
//echo $query;
$rows = $this->db_onedev->query($query,array($prm['id']))->result_array();
$result = array(
"total" => count($rows) ,
"records" => $rows,
);
$this->sys_ok($result);
exit;
}
function getsexreg(){
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$rows = [];
$query =" SELECT *
FROM m_sex
WHERE
M_SexIsActive = 'Y'
";
//echo $query;
$rows['sexes'] = $this->db_onedev->query($query)->result_array();
$result = array(
"total" => count($rows) ,
"records" => $rows,
);
$this->sys_ok($result);
exit;
}
function save(){
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$prm = $this->sys_input;
$pdob = date('Y-m-d',strtotime($prm['M_PatientDOB']));
$query ="UPDATE m_patient SET
M_PatientM_TitleID = '{$prm['M_PatientM_TitleID']}',
M_PatientName = '{$prm['M_PatientName']}',
M_PatientDOB = '{$pdob}',
M_PatientM_SexID = '{$prm['M_PatientM_SexID']}',
M_PatientM_ReligionID = '{$prm['M_PatientM_ReligionID']}',
M_PatientEmail = '{$prm['M_PatientEmail']}',
M_PatientHP = '{$prm['M_PatientHP']}',
M_PatientPhone = '{$prm['M_PatientPhone']}',
M_PatientM_IdTypeID = '{$prm['M_PatientM_IdTypeID']}',
M_PatientIDNumber = '{$prm['M_PatientIDNumber']}',
M_PatientNote = '{$prm['M_PatientNote']}'
WHERE
M_PatientID = '{$prm['M_PatientID']}'
";
//echo $query;
$rows = $this->db_onedev->query($query);
$result = array(
"total" => 1 ,
"records" => array('status'=>'OK')
);
$this->sys_ok($result);
exit;
}
function newreceivereference(){
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$prm = $this->sys_input;
$pdate = date('Y-m-d',strtotime($prm['sdate']));
$userid = $this->sys_user["M_UserID"];
$query ="INSERT INTO f_bill (
F_BillNo,
F_BillM_CompanyID,
F_BillM_MouID,
F_BillDueDate,
F_BillNote,
F_BillTotal,
F_BillUserID,
F_BillCreated
)
VALUES(
`fn_numbering`('BL'),
'{$prm['companyid']}',
'{$prm['mouid']}',
'{$pdate}',
'{$prm['note']}',
`fn_get_total_bill`({$prm['mouid']}),
'{$userid}',
NOW()
)
";
// echo $query;
$rows = $this->db_onedev->query($query);
$last_id = $this->db_onedev->insert_id();
$querylog ="INSERT INTO f_bill_detail (
F_BillDetailF_BillID,
F_BillDetailT_OrderHeaderID,
F_BillDetailUserID,
F_BillDetailCreated,
F_BillDetailLastUpdated
)
select $last_id,T_OrderHeaderID,$userid,NOW(),NOW()
from t_orderheader
left join f_payment on T_OrderHeaderID = F_PaymentT_OrderHeaderID
and T_OrderHeaderM_MouID = '{$prm['mouid']}'
where T_OrderHeaderIsActive = 'Y' and F_PaymentID is null and T_OrderHeaderID not in (
select F_BillDetailT_OrderHeaderID from f_bill_detail where F_BillDetailIsActive = 'Y'
)
";
$insert_new_log = $this->db_onedev->query($querylog);
$result = array(
"total" => 1 ,
"records" => array('status'=>'OK'),
"id" => $last_id
);
$this->sys_ok($result);
exit;
}
function sendorder(){
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$prm = $this->sys_input;
$userid = $this->sys_user["M_UserID"];
$query ="UPDATE t_receivereferenceheader SET
T_ReceiveReferenceHeaderIsSent = 'Y',
T_ReceiveReferenceHeaderSentDate = now(),
T_ReceiveReferenceHeaderUserID = '{$userid}'
WHERE
T_ReceiveReferenceHeaderID = '{$prm['T_ReceiveReferenceHeaderID']}'
";
//echo $query;
$rows = $this->db_onedev->query($query);
$rows = $this->db_onedev->query($query);
$querylog ="INSERT INTO g_receivereferenceheaderstatuslog (
G_ReceiveReferenceHeaderStatusLogDate,
G_ReceiveReferenceHeaderStatusLogT_ReceiveReferenceHeaderID,
G_ReceiveReferenceHeaderStatusLogM_StatusReferenceID,
G_ReceiveReferenceHeaderStatusLogM_UserID,
G_ReceiveReferenceHeaderStatusLogUserID,
G_ReceiveReferenceHeaderStatusLogCreated,
G_ReceiveReferenceHeaderStatusLogLastUpdated
)
VALUES(
NOW(),
'{$prm['T_ReceiveReferenceHeaderID']}',
'2',
'{$userid}',
'{$userid}',
NOW(),
NOW()
)";
//echo $querylog;
$insert_new_log = $this->db_onedev->query($querylog);
$result = array(
"total" => 1 ,
"records" => array('status'=>'OK')
);
$this->sys_ok($result);
exit;
}
function getpatient(){
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$prm = $this->sys_input;
$query =" SELECT f_bill_detail.*,
concat(M_TitleName,'. ',M_PatientName) as pasienname,
T_OrderHeaderTotal as total,
DATE_FORMAT(T_OrderHeaderDate,'%d/%m/%Y') as T_OrderHeaderDate,
T_OrderHeaderLabNumber,
'' as tes,
'xxx' as tests,
'' as action
FROM f_bill_detail
join f_bill on F_BillDetailF_BillID = F_BillID
JOIN t_orderheader ON F_BillDetailT_OrderHeaderID = T_OrderHeaderID
join m_patient on T_OrderHeaderM_PatientID = M_PatientID
left join m_title on M_PatientM_TitleID = M_TitleID
WHERE
F_BillDetailIsActive = 'Y' AND F_BillDetailF_BillID = ?
";
//echo $query;
$rows = $this->db_onedev->query($query,array($prm['id']))->result_array();
if($rows){
foreach($rows as $k => $v){
$x = $this->db_onedev->query("
SELECT f_bill_detail.*,
concat(M_TitleName,'. ',M_PatientName) as pasienname,
T_OrderHeaderTotal as total,
DATE_FORMAT(T_OrderHeaderDate,'%d/%m/%Y') as T_OrderHeaderDate,
T_OrderHeaderLabNumber,
'' as tes,
'xxx' as tests,
'' as action
FROM f_bill_detail
join f_bill on F_BillDetailF_BillID = F_BillID
JOIN t_orderheader ON F_BillDetailT_OrderHeaderID = T_OrderHeaderID
join m_patient on T_OrderHeaderM_PatientID = M_PatientID
left join m_title on M_PatientM_TitleID = M_TitleID
WHERE
F_BillDetailF_BillID = '{$v['F_BillID']}' AND F_BillDetailIsActive = 'Y'")->row();
$rows[$k]['tesx'] = json_decode($x->n);
$rows[$k]['action'] = '<v-icon color="error" @click="deleteAddress(props.item)">delete</v-icon>';
$rows[$k]['action'] .= '<v-icon color="primary" @click="deleteAddress(props.item)">edit</v-icon>';
}
}
$result = array(
"total" => count($rows) ,
"records" => $rows,
);
$this->sys_ok($result);
exit;
}
function add_test($orderid){
$query =" SELECT t_receivereferencetest.*, t_test.*,'Y' as editable, T_ReceiveReferenceTestT_TestID as xid,
T_ReceiveReferenceTestT_TestPrice as T_PriceAmount,
T_ReceiveReferenceTestT_TestDisc as T_PriceDisc,
T_ReceiveReferenceTestT_TestDiscRp as T_PriceDiscRp,
T_ReceiveReferenceTestT_TestTotal as total
FROM t_receivereferencetest
JOIN t_receivereferencepatient ON T_ReceiveReferenceTestT_ReceiveReferencePatientID = T_ReceiveReferencePatientID
JOIN t_receivereferenceheader ON T_ReceiveReferencePatientT_ReceiveReferenceHeaderID = T_ReceiveReferenceHeaderID
JOIN t_test ON T_ReceiveReferenceTestT_TestID = T_TestID
WHERE
T_ReceiveReferenceTestT_ReceiveReferencePatientID = {$orderid} AND T_ReceiveReferenceTestIsActive = 'Y'
GROUP BY T_ReceiveReferenceTestID";
//echo $query;
$rows = $this->db_onedev->query($query)->result_array();
if(!$rows)
$rows = array();
return $rows;
}
function savenewpatient(){
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$prm = $this->sys_input;
$pdob = date('Y-m-d',strtotime($prm['T_ReceiveReferencePatientDOB']));
$userid = $this->sys_user["M_UserID"];
$query ="INSERT INTO t_receivereferencepatient (
T_ReceiveReferencePatientT_ReceiveReferenceHeaderID,
T_ReceiveReferencePatientNoRef,
T_ReceiveReferencePatientName,
T_ReceiveReferencePatientDOB,
T_ReceiveReferencePatientM_SexID,
T_ReceiveReferencePatientUserID,
T_ReceiveReferencePatientTotal,
T_ReceiveReferencePatientDPPercent,
T_ReceiveReferencePatientDPAmount,
T_ReceiveReferencePatientCreated
)
VALUES(
'{$prm['T_ReceiveReferencePatientT_ReceiveReferenceHeaderID']}',
'{$prm['T_ReceiveReferencePatientNoRef']}',
'{$prm['T_ReceiveReferencePatientName']}',
'{$pdob}',
'{$prm['T_ReceiveReferencePatientM_SexID']}',
'{$userid}',
'{$prm['T_ReceiveReferencePatientTotal']}',
'{$prm['T_ReceiveReferencePatientDPPercent']}',
'{$prm['T_ReceiveReferencePatientDPAmount']}',
NOW()
)
";
//echo $query;
$rows = $this->db_onedev->query($query);
$orderpatient_id = $this->db_onedev->insert_id();
foreach($prm['ordertests'] as $k=>$v){
$query = "INSERT INTO t_receivereferencetest (
T_ReceiveReferenceTestT_ReceiveReferencePatientID,
T_ReceiveReferenceTestT_TestID,
T_ReceiveReferenceTestT_TestCode,
T_ReceiveReferenceTestT_TestName,
T_ReceiveReferenceTestT_TestPrice,
T_ReceiveReferenceTestT_TestDisc,
T_ReceiveReferenceTestT_TestDiscRp,
T_ReceiveReferenceTestT_TestTotal,
T_ReceiveReferenceTestUserID,
T_ReceiveReferenceTestCreated,
T_ReceiveReferenceTestLastUpdated
)
VALUE(
?,?,?,?,?,?,?,?,?, now(),now()
)";
$insert_new_test = $this->db_onedev->query($query,array(
$orderpatient_id,
$v['T_TestID'],
$v['T_TestCode'],
$v['T_TestName'],
$v['T_PriceAmount'],
$v['T_PriceDisc'],
$v['T_PriceDiscRp'],
$v['total'],
$userid
));
}
$result = array(
"total" => 1 ,
"records" => array('status'=>'OK')
);
$this->sys_ok($result);
exit;
}
function saveeditpatient(){
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$prm = $this->sys_input;
$order_id = $prm['T_ReceiveReferencePatientID'];
$pdob = date('Y-m-d',strtotime($prm['T_ReceiveReferencePatientDOB']));
$userid = $this->sys_user["M_UserID"];
$query ="UPDATE t_receivereferencepatient SET
T_ReceiveReferencePatientT_ReceiveReferenceHeaderID = '{$prm['T_ReceiveReferencePatientT_ReceiveReferenceHeaderID']}',
T_ReceiveReferencePatientNoRef = '{$prm['T_ReceiveReferencePatientNoRef']}',
T_ReceiveReferencePatientName = '{$prm['T_ReceiveReferencePatientName']}',
T_ReceiveReferencePatientDOB = '{$pdob}',
T_ReceiveReferencePatientM_SexID = '{$prm['T_ReceiveReferencePatientM_SexID']}',
T_ReceiveReferencePatientTotal = '{$prm['T_ReceiveReferencePatientTotal']}',
T_ReceiveReferencePatientDPPercent = '{$prm['T_ReceiveReferencePatientDPPercent']}',
T_ReceiveReferencePatientDPAmount = '{$prm['T_ReceiveReferencePatientDPAmount']}',
T_ReceiveReferencePatientUserID = '{$userid}'
WHERE
T_ReceiveReferencePatientID = '{$prm['T_ReceiveReferencePatientID']}'
";
//echo $query;
$rows = $this->db_onedev->query($query);
foreach($prm['ordertests'] as $k=>$v){
if($v['xid'] == 0 || $v['xid'] == '0'){
$query = "INSERT INTO t_receivereferencetest (
T_ReceiveReferenceTestT_ReceiveReferencePatientID,
T_ReceiveReferenceTestT_TestID,
T_ReceiveReferenceTestT_TestCode,
T_ReceiveReferenceTestT_TestName,
T_ReceiveReferenceTestT_TestPrice,
T_ReceiveReferenceTestUserID,
T_ReceiveReferenceTestCreated,
T_ReceiveReferenceTestLastUpdated
)
VALUE(
?,?,?,?,?,?,now(),now()
)";
$insert_new_test = $this->db_onedev->query($query,array(
$order_id,
$v['T_TestID'],
$v['T_TestCode'],
$v['T_TestName'],
$v['total'],
$userid
));
}
}
if(isset($prm['deleted_ordertests'])){
foreach($prm['deleted_ordertests'] as $i=>$del){
$query = "UPDATE t_receivereferencetest SET
T_ReceiveReferenceTestIsActive = 'N',
T_ReceiveReferenceTestUserID = '{$userid}',
T_ReceiveReferenceTestLastUpdated = now()
WHERE
T_ReceiveReferenceTestID = ?
";
$delete_exist_test = $this->db_onedev->query($query,array($del['T_ReceiveReferenceTestID'],));
}
}
$result = array(
"total" => 1 ,
"records" => array('status'=>'OK')
);
$this->sys_ok($result);
exit;
}
function deletepatient(){
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$prm = $this->sys_input;
$userid = $this->sys_user["M_UserID"];
$query ="UPDATE f_bill_detail SET
F_BillDetailIsActive = 'N',
F_BillDetailUserID = '{$userid}'
WHERE
F_BillDetailID = '{$prm['F_BillDetailID']}'
";
//echo $query;
$rows = $this->db_onedev->query($query);
//echo $query;
$rows = $this->db_onedev->query($query);
$result = array(
"total" => 1 ,
"records" => array('status'=>'OK')
);
$this->sys_ok($result);
exit;
}
function searchtest(){
$prm = $this->sys_input;
$max_rst = 12;
$tot_count = 0;
$q = [
'search' => '%'
];
if ($prm['search'] != '')
{
$q['search'] = "%{$prm['search']}%";
}
$mou_id = $prm['mouid'];
// QUERY TOTAL
$sql = "SELECT count(*) as total
FROM t_test
JOIN t_price ON T_PriceT_TestID = T_TestID AND T_PriceIsCito = 'N' AND T_PriceM_MouID = '{$mou_id}'
WHERE
T_TestName like ? AND
T_TestIsActive = 'Y'
ORDER BY T_TestName ASC";
$query = $this->db_onedev->query($sql,$q['search']);
//echo $query;
if ($query) {
$tot_count = $query->result_array()[0]["total"];
}
else {
$this->sys_error_db("test count",$this->db_onedev);
exit;
}
$sql = "
SELECT 'Y' as editable,
0 as xid,
T_TestID,
T_TestCode,
T_TestName, T_PriceAmount, T_PriceDisc, T_PriceDiscRp, T_PriceAmount - ((T_PriceDisc/100) * T_PriceAmount) - T_PriceDiscRp as total,
M_CompanyID,'N' as M_CompanyIsBill, 0 as M_CompanyMinDP
FROM one.t_test
JOIN one.t_price ON T_PriceT_TestID = T_TestID AND T_PriceIsCito = 'N' AND T_PriceM_MouID = '{$mou_id}'
JOIN one.m_mou ON M_MouID = '{$mou_id}'
JOIN one.m_company ON M_MouM_CompanyID = M_CompanyID
WHERE
T_TestName like ? AND
T_TestIsActive = 'Y'
ORDER BY T_TestName ASC
";
$query = $this->db_onedev->query($sql, array($q['search']));
if ($query) {
$rows = $query->result_array();
//echo $this->db_onedev->last_query();
$result = array("total" => $tot_count, "records" => $rows, "total_display" => sizeof($rows));
$this->sys_ok($result);
}
else {
$this->sys_error_db("test rows",$this->db_onedev);
exit;
}
}
}

View File

@@ -0,0 +1,188 @@
<?php
class Bill extends MY_Controller
{
var $db_onedev;
public function index()
{
echo "Bill API";
}
public function __construct()
{
parent::__construct();
$this->db_onedev = $this->load->database("onedev", true);
}
public function add_notes($orderid){
$sql = " SELECT F_BillPaymentF_BillID as note_order_id,
F_BillPaymentID as note_id,
F_BillPaymentDate as note_date,
F_BillPaymentNumber as note_number,
GROUP_CONCAT(DISTINCT M_PaymentTypeName separator ' , ') as paymenttypes_name,
SUM(F_BillPaymentDetailAmount) as note_amount,
M_UserUsername as note_user,
F_BillPaymentDetailIsActive as note_active,
'xxx' as tests,
'N' as show_detail
FROM f_bill_payment
JOIN f_bill_payment_detail ON F_BillPaymentDetailF_BillPaymentID = F_BillPaymentID
JOIN m_paymenttype ON F_BillPaymentM_PaymentTypeID = M_PaymentTypeID
LEFT JOIN m_user ON F_BillPaymentUserID = M_UserID
WHERE
F_BillPaymentF_BillID = {$orderid}
GROUP BY F_BillPaymentID";
$query = $this->db_onedev->query($sql);
if ($query) {
$rows = $query->result_array();
if($rows){
foreach($rows as $k => $v){
$rows[$k]['tests'] = $this->add_tests($v['note_id']);
}
}
return $rows;
} else {
$this->sys_error_db("get notes", $this->db_onedev);
exit;
}
}
public function add_tagihans($orderid){
$sql = " SELECT F_BillID as tagihan_id,
T_OrderHeaderLabNumber as tagihan_number,
F_BillDetailTotal as tagihan_total,
F_BillDetailUnpaid as tagihan_tagihan,
0 as tagihan_bayar,
DATE_FORMAT(F_BillDueDate,'%d-%m-%Y') as tagihan_duedate,
F_BillDetailIsActive as tagihan_active,
'N' as show_detail,
F_BillDetailID,
F_BillDetailT_OrderHeaderID
FROM f_bill
JOIN f_bill_detail ON F_BillDetailF_BillID = F_BillID AND F_BillDetailIsActive = 'Y' AND F_BillDetailUnpaid > 0
JOIN t_orderheader ON F_BillDetailT_OrderHeaderID = T_OrderHeaderID
WHERE
F_BillID = {$orderid}
GROUP BY F_BillDetailID";
$query = $this->db_onedev->query($sql);
if ($query) {
$rows = $query->result_array();
return $rows;
} else {
$this->sys_error_db("get notes", $this->db_onedev);
exit;
}
}
public function add_tests($orderid){
$sql = " SELECT F_BillPaymentF_BillID as note_order_id,
F_BillPaymentID as note_id,
F_BillPaymentDate as note_date,
F_BillPaymentNumber as note_number,
GROUP_CONCAT(M_PaymentTypeName separator ' , ') as paymenttypes_name,
SUM(F_BillPaymentDetailAmount) as note_amount,
M_UserUsername as note_user,
F_BillPaymentDetailIsActive as note_active,
T_OrderHeaderLabNumber,
F_BillDetailTotal,
F_BillPaymentDetailAmount
FROM f_bill_payment
JOIN f_bill_payment_detail ON F_BillPaymentDetailF_BillPaymentID = F_BillPaymentID
LEFT JOIN f_bill ON F_BillPaymentDetailF_BillID = F_BillID
LEFT JOIN f_bill_detail ON F_BillPaymentDetailF_BillDetailID = F_BillDetailID
LEFT JOIN t_orderheader ON F_BillDetailT_OrderHeaderID = T_OrderHeaderID
JOIN m_paymenttype ON F_BillPaymentM_PaymentTypeID = M_PaymentTypeID
LEFT JOIN m_user ON F_BillPaymentDetailUserID = M_UserID
WHERE
F_BillPaymentID = {$orderid}
GROUP BY F_BillPaymentDetailID";
$query = $this->db_onedev->query($sql);
if ($query) {
$rows = $query->result_array();
if($rows){
}
return $rows;
} else {
$this->sys_error_db("get notes", $this->db_onedev);
exit;
}
}
public function search()
{
//# cek token valid
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$prm = $this->sys_input;
$company = $prm["company"];
$search = $prm["search"];
$status = $prm["status"];
$number_limit = 10;
$number_offset = ($prm['current_page'] - 1) * $number_limit ;
$where = "(F_BillIsActive = 'Y'AND F_BillTotal > 0 AND F_BillIsLunas = '{$status}' AND (F_BillNo LIKE '%{$search}%' OR F_BillPaymentNumber LIKE '%{$search}%') AND M_CompanyName LIKE '%{$company}%')";
$sql = " SELECT count(*) as total
FROM f_bill
LEFT JOIN f_bill_payment ON F_BillID = F_BillPaymentF_BillID AND F_BillPaymentIsActive = 'Y'
LEFT JOIN m_company ON F_BillM_CompanyID = M_CompanyID
LEFT JOIN m_mou ON F_BillM_MouID = M_MouID
WHERE
$where";
//echo $sql;
$query = $this->db_onedev->query($sql, $sql_param);
$tot_count = 0;
$tot_page = 0;
if ($query) {
$tot_count = $query->result_array()[0]["total"];
$tot_page = ceil($tot_count/$number_limit);
} else {
$this->sys_error_db("f_bill count", $this->db_onedev);
exit;
}
$sql = "SELECT f_bill.*, f_bill_payment.*,
M_CompanyName,
M_MouName,
IFNULL(F_BillTotal,0) as totalbill,
IFNULL(F_BillTotal - F_BillUnpaid,0) as paid,
IFNULL(F_BillUnpaid,0) as unpaid,
F_BillIsLunas as flaglunas,
GROUP_CONCAT(F_BillPaymentNumber SEPARATOR ', ') as F_BillPaymentNumber,
SUM(F_BillPaymentAmount) as F_BillPaymentAmount,
DATE_FORMAT(F_BillPaymentDate,'%d-%m-%Y') as F_BillPaymentDate,
'' as notes,
'' as tagihans
FROM f_bill
LEFT JOIN f_bill_payment ON F_BillID = F_BillPaymentF_BillID AND F_BillPaymentIsActive = 'Y'
LEFT JOIN m_company ON F_BillM_CompanyID = M_CompanyID
LEFT JOIN m_mou ON F_BillM_MouID = M_MouID
WHERE
$where
GROUP BY F_BillID
ORDER BY F_BillID ASC
limit $number_limit offset $number_offset";
//echo $sql;
$query = $this->db_onedev->query($sql, $sql_param);
$rows = $query->result_array();
if($rows){
foreach($rows as $k => $v){
$rows[$k]['notes'] = $this->add_notes($v['F_BillID']);
$rows[$k]['tagihans'] = $this->add_tagihans($v['F_BillID']);
}
}
$result = array("total" => $tot_page, "records" => $rows, "sql"=> $this->db_onedev->last_query());
$this->sys_ok($result);
exit;
}
}

View File

@@ -0,0 +1,604 @@
<?php
class Payment extends MY_Controller
{
var $db_smartone;
public function index()
{
echo "API";
}
public function __construct()
{
parent::__construct();
$this->db_onedev = $this->load->database("onedev", true);
}
function lookup_type()
{
//# cek token valid
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$query = "SELECT M_PaymentTypeID as id,
M_PaymentTypeCode as code,
'N' as chex,
M_PaymentTypeName as chexlabel,
'Jumlah' as leftlabel,
'' as selected_card,
'' as selected_edc,
'' as selected_account,
CASE
WHEN M_PaymentTypeCode = 'CASH' THEN 'Kembali'
WHEN M_PaymentTypeCode = 'DEBIT' THEN 'Nomor Kartu'
WHEN M_PaymentTypeCode = 'CREDIT' THEN 'Nomor Kartu'
WHEN M_PaymentTypeCode = 'TRANSFER' THEN 'No. Rekening'
ELSE 'Nomor Voucher'
END as rightlabel,
0 as leftvalue,
0 as rightvalue
FROM m_paymenttype WHERE M_PaymentTypeIsActive = 'Y'";
$rows = $this->db_onedev->query($query)->result_array();
foreach($rows as $k => $v){
$rows[$k]['selected_card'] = array('id'=>0,'name'=>'');
$rows[$k]['selected_edc'] = array('id'=>0,'name'=>'');
$rows[$k]['selected_account'] = array('id'=>0,'name'=>'');
if($v['chex'] == 'N')
$rows[$k]['chex'] = false;
else
$rows[$k]['chex'] = true;
}
$result = array(
"total" => count($rows) ,
"records" => $rows,
);
$this->sys_ok($result);
exit;
}
function selectpaymenttype(){
try {
//# cek token valid
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$rows = [];
$query =" SELECT *
FROM m_paymenttype
WHERE
M_PaymentTypeIsActive = 'Y'
";
//echo $query;
$rows['paymenttypes'] = $this->db_onedev->query($query)->result_array();
$result = array(
"total" => count($rows) ,
"records" => $rows,
);
$this->sys_ok($result);
} catch(Exception $exc) {
$message = $exc->getMessage();
$this->sys_error($message);
}
}
function selectbank(){
try {
//# cek token valid
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$rows = [];
$query =" SELECT *
FROM nat_bank
WHERE
Nat_BankIsActive = 'Y'
ORDER BY Nat_BankCode DESC
";
//echo $query;
$rows['banks'] = $this->db_onedev->query($query)->result_array();
$result = array(
"total" => count($rows) ,
"records" => $rows,
);
$this->sys_ok($result);
} catch(Exception $exc) {
$message = $exc->getMessage();
$this->sys_error($message);
}
}
function selectaccount(){
try {
//# cek token valid
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$rows = [];
$query =" SELECT M_BankAccountID as M_BankAccountID, CONCAT(Nat_BankCode,' (',M_BankAccountNo,')') as M_BankAccountName
FROM m_bank_account
JOIN nat_bank ON M_BankAccountNat_BankID = Nat_BankID
WHERE
M_BankAccountIsActive = 'Y'
ORDER BY Nat_BankCode DESC";
//echo $query;
$rows['accounts'] = $this->db_onedev->query($query)->result_array();
$result = array(
"total" => count($rows) ,
"records" => $rows,
);
$this->sys_ok($result);
} catch(Exception $exc) {
$message = $exc->getMessage();
$this->sys_error($message);
}
}
function lookup_banks()
{
//# cek token valid
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$query = "SELECT Nat_BankID as id, Nat_BankCode as name
FROM nat_bank
WHERE
Nat_BankIsActive = 'Y'
ORDER BY Nat_BankCode DESC";
$rows = $this->db_onedev->query($query)->result_array();
$result = array(
"total" => count($rows) ,
"records" => $rows,
);
$this->sys_ok($result);
exit;
}
function lookup_accounts()
{
//# cek token valid
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$query = "SELECT M_BankAccountID as id, CONCAT(Nat_BankCode,' (',M_BankAccountNo,')') as name
FROM m_bank_account
JOIN nat_bank ON M_BankAccountNat_BankID = Nat_BankID
WHERE
M_BankAccountIsActive = 'Y'
ORDER BY Nat_BankCode DESC";
$rows = $this->db_onedev->query($query)->result_array();
$result = array(
"total" => count($rows) ,
"records" => $rows,
);
$this->sys_ok($result);
exit;
}
function searchcard(){
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$prm = $this->sys_input;
$max_rst = 12;
$tot_count =0;
$q = [
'search' => '%'
];
if ($prm['search'] != '')
{
$q['search'] = "%{$prm['search']}%";
}
// QUERY TOTAL
if($prm['search'] != ''){
$sql = "
SELECT count(*) as total
FROM nat_bank
WHERE
Nat_BankName like ?
AND Nat_BankIsActive = 'Y'
ORDER BY Nat_BankName DESC
";
}
else{
$sql = "
SELECT count(*) as total
FROM nat_bank
WHERE
Nat_BankIsActive = 'Y'
ORDER BY Nat_BankName DESC
";
}
$query = $this->db_onedev->query($sql,$q['search']);
//echo $query;
if ($query) {
$tot_count = $query->result_array()[0]["total"];
}
else {
$this->sys_error_db("m_city count",$this->db_onedev);
exit;
}
if($prm['search'] != ''){
$sql = "
SELECT Nat_BankID as id, Nat_BankName as name
FROM nat_bank
WHERE
Nat_BankName like ?
AND Nat_BankIsActive = 'Y'
ORDER BY Nat_BankName DESC
";
}
else{
$sql = "
SELECT Nat_BankID as id, Nat_BankName as name
FROM nat_bank
WHERE
Nat_BankIsActive = 'Y'
ORDER BY Nat_BankName DESC
";
}
$query = $this->db_onedev->query($sql, array($q['search']));
if ($query) {
$rows = $query->result_array();
//echo $this->db_onedev->last_query();
$result = array("total" => $tot_count, "records" => $rows, "total_display" => sizeof($rows));
$this->sys_ok($result);
}
else {
$this->sys_error_db("m_city rows",$this->db_onedev);
exit;
}
}
function pay()
{
//# cek token valid
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
//# ambil parameter input
$xuserid = $this->sys_user['M_UserID'];
$prm = $this->sys_input;
$orderid = $prm['orderid'];
$payments = $prm['payments'];
//$xnumber = $this->db_onedev->query("SELECT `fn_numbering`('PAY') as numberx")->row()->numberx;
$sql = "INSERT INTO f_bill_payment
(F_BillPaymentF_BillID,F_BillPaymentDate,F_BillPaymentCreated,F_BillPaymentUserID)
VALUES (?,CURDATE(),NOW(),?)";
$query = $this->db_onedev->query($sql,
array(
$orderid, $xuserid
)
);
if (!$query) {
$this->sys_error_db("f_bill_payment insert");
exit;
}
$headerid = $this->db_onedev->insert_id();
//echo $headerid;
foreach($payments as $k => $v){
if($v['chex']){
$actual = 0;
$change = 0;
$amount = $v['leftvalue'];
if($v['code'] == 'CASH'){
$actual = $v['leftvalue'];
$change = $v['rightvalue'];
if($actual > 0){
$amount = intval($v['leftvalue']) - intval($v['rightvalue']);
}
else{
$amount = $actual;
}
$sql = "CALL `sp_bill_payment_add_cash`(".$orderid.",".$amount.",".$amount.",".$headerid.",".$v['id'].",".$xuserid.")";
$query = $this->db_onedev->query($sql);
if (!$query) {
$this->sys_error_db("f_bill_payment_detail cash insert");
exit;
}
}
else{
if(intval($v['leftvalue']) > 0){
$actual = 0;
$change = 0;
$amount = $v['leftvalue'];
$selected_card = 0;
$selected_edc = 0;
$selected_account = 0;
if($v['code'] == 'DEBIT' || $v['code'] == 'CREDIT' || $v['code'] == 'TRANSFER'){
$selected_card = $v['selected_card']['id'];
$selected_edc = $v['selected_edc']['id'];
$selected_account = $v['selected_account']['id'];
}
$sql = "CALL `sp_bill_payment_add_noncash`(".$orderid.",".$amount.",".$amount.",".$headerid.",".$v['id'].",".$xuserid.",".$selected_card.",".$selected_edc.",".$selected_account.")";
//echo $sql;
$query = $this->db_onedev->query($sql);
//echo $this->db_onedev->last_query();
if (!$query) {
$this->sys_error_db("f_bill_payment_detail non cash insert");
exit;
}
}
}
}
}
$query = "SELECT M_PaymentTypeID as id,
M_PaymentTypeCode as code,
IF(M_PaymentTypeCode = 'CASH','Y','N') as chex,
M_PaymentTypeName as chexlabel,
'Jumlah' as leftlabel,
CASE
WHEN M_PaymentTypeCode = 'CASH' THEN 'Kembali'
WHEN M_PaymentTypeCode = 'DEBIT' THEN 'Nomor Kartu'
WHEN M_PaymentTypeCode = 'CREDIT' THEN 'Nomor Kartu'
WHEN M_PaymentTypeCode = 'TRANSFER' THEN 'Nomor Rekening'
ELSE 'Nomor Voucher'
END as rightlabel,
0 as leftvalue,
0 as rightvalue
FROM m_paymenttype WHERE M_PaymentTypeIsActive = 'Y'";
$rows = $this->db_onedev->query($query)->result_array();
foreach($rows as $k => $v){
if($v['chex'] == 'N')
$rows[$k]['chex'] = false;
else
$rows[$k]['chex'] = true;
}
$xdata = $this->db_onedev->query("SELECT F_BillPaymentID as idx, F_BillPaymentNumber as numberx FROM f_bill_payment WHERE F_BillPaymentID = {$headerid}")->row();
$result = array(
"total" => count($rows) ,
"records" => array('types'=>$rows,'data'=>$xdata)
);
$this->sys_ok($result);
exit;
}
function paymanual()
{
//# cek token valid
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
//# ambil parameter input
$xuserid = $this->sys_user['M_UserID'];
$prm = $this->sys_input;
$orderid = $prm['orderid'];
$amount = $prm['amount'];
$paymenttype = $prm['paymenttype'];
if($prm['paymenttype'] == 1 || $prm['paymenttype'] == 5){
$card = 0;
$edc = 0;
$account = 0;
}elseif($prm['paymenttype'] == 4){
$card = 0;
$edc = 0;
$account = $prm['account'];
}else{
$card = $prm['card'];
$edc = $prm['edc'];
$account = 0;
}
$voucher = $prm['voucher'];
$bills = $prm['bills'];
//$xnumber = $this->db_onedev->query("SELECT `fn_numbering`('PAY') as numberx")->row()->numberx;
$sql = "INSERT INTO f_bill_payment
(F_BillPaymentF_BillID,
F_BillPaymentDate,
F_BillPaymentAmount,
F_BillPaymentM_PaymentTypeID,
F_BillPaymentEDCNat_BankID,
F_BillPaymentCardNat_BankID,
F_BillPaymentM_BankAccountID,
F_BillPaymentVoucherNumber,
F_BillPaymentCreated,
F_BillPaymentUserID)
VALUES (?,
CURDATE(),
?,
?,
?,
?,
?,
?,
NOW(),
?)";
$query = $this->db_onedev->query($sql,
array(
$orderid,
$amount,
$paymenttype,
$edc,
$card,
$account,
$voucher,
$xuserid
)
);
$headerid = $this->db_onedev->insert_id();
if (!$query) {
$this->sys_error_db("f_bill_payment insert");
exit;
} else{
$sqlbill = "UPDATE f_bill SET
F_BillUnpaid = F_BillUnpaid - $amount,
F_BillIsLunas = IF(F_BillUnpaid = 0,'Y','N')
WHERE F_BillID = $orderid";
$querybill = $this->db_onedev->query($sqlbill);
}
//echo $headerid;
foreach($bills as $k => $v){
if($v['tagihan_bayar'] > 0){
$F_BillDetailID = $v['F_BillDetailID'];
$tagihan_bayar = $v['tagihan_bayar'];
$F_BillDetailT_OrderHeaderID = $v['F_BillDetailT_OrderHeaderID'];
$sql = "INSERT INTO f_bill_payment_detail(
F_BillPaymentDetailF_BillPaymentID,
F_BillPaymentDetailF_BillID,
F_BillPaymentDetailF_BillDetailID,
F_BillPaymentDetailAmount,
F_BillPaymentDetailUserID,
F_BillPaymentDetailCreated,
F_BillPaymentDetailLastUpdated)
VALUES(
$headerid,
$orderid,
$F_BillDetailID,
$tagihan_bayar,
$xuserid,
now(),
now())";
$query = $this->db_onedev->query($sql);
$billpaymentdetailid = $this->db_onedev->insert_id();
if (!$query) {
$this->sys_error_db("f_bill_payment_detail cash insert");
exit;
}else{
$sqlbilldetail = "UPDATE f_bill_detail SET
F_BillDetailUnpaid = F_BillDetailUnpaid - $tagihan_bayar
WHERE F_BillDetailID = $F_BillDetailID";
$querybilldetail = $this->db_onedev->query($sqlbilldetail);
$sqlpayment = "INSERT INTO f_payment
(F_PaymentT_OrderHeaderID,
F_PaymentDate,
F_PaymentTotal,
F_PaymentCreated,
F_PaymentLastUpdated,
F_PaymentM_UserID)
VALUES(
$F_BillDetailT_OrderHeaderID,
now(),
$tagihan_bayar,
now(),
now(),
$xuserid)";
$querypayment = $this->db_onedev->query($sqlpayment);
$paymentid = $this->db_onedev->insert_id();
$sqlpaymentdetail = "INSERT INTO f_paymentdetail
(F_PaymentDetailF_PaymentID,
F_PaymentDetailM_PaymentTypeID,
F_PaymentDetailAmount,
F_PaymentDetailActual,
F_PaymentDetailChange,
F_PaymentDetailEDCNat_BankID,
F_PaymentDetailCardNat_BankID,
F_PaymentDetailM_BankAccountID,
F_PaymentDetailCreated,
F_PaymentDetailLastUpdated,
F_PaymentDetailUserID)
VALUES(
$paymentid,
$paymenttype,
$tagihan_bayar,
$tagihan_bayar,
0,
$edc,
$card,
$account,
now(),
now(),
$xuserid)";
//echo $sqlpaymentdetail;
$querypaymentdetail = $this->db_onedev->query($sqlpaymentdetail);
$sqleditbillpaymentdetail = "UPDATE f_bill_payment_detail SET
F_BillPaymentDetailF_PaymentID = $paymentid
WHERE F_BillPaymentDetailID = $billpaymentdetailid";
$queryeditbillpaymentdetail = $this->db_onedev->query($sqleditbillpaymentdetail);
}
}
}
$xdata = $this->db_onedev->query("SELECT F_BillPaymentID as idx, F_BillPaymentNumber as numberx FROM f_bill_payment WHERE F_BillPaymentID = {$headerid}")->row();
$result = array(
"total" => count($rows) ,
"records" => array('data'=>$xdata)
);
$this->sys_ok($result);
exit;
}
function delete_note()
{
//# cek token valid
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
//# ambil parameter input
$xuserid = $this->sys_user['M_UserID'];
$prm = $this->sys_input;
$prmnota = $prm['nota'];
$catatan = $prm['catatan'];
$sql = "UPDATE f_bill_payment SET F_BillPaymentIsActive = 'N', F_BillPaymentNote = '{$catatan}' WHERE F_BillPaymentID = {$prmnota['note_id']}";
//echo $sql;
$query = $this->db_onedev->query($sql);
if (!$query) {
$this->sys_error_db("f_bill_payment delete");
exit;
}
$sql = "UPDATE f_bill_payment_detail SET F_BillPaymentDetailIsActive = 'N' WHERE F_BillPaymentDetailF_BillPaymentID = {$prmnota['note_id']}";
//echo $sql;
$query = $this->db_onedev->query($sql);
if (!$query) {
$this->sys_error_db("f_bill_payment_detail delete");
exit;
}
$result = array(
"total" => 1 ,
"records" => array('prm'=>$prm)
);
$this->sys_ok($result);
exit;
}
}

View File

@@ -0,0 +1,213 @@
<?php
class Area extends MY_Controller
{
var $db_smartone;
public function index()
{
echo "AREA API";
}
public function __construct()
{
parent::__construct();
$this->db_smartone = $this->load->database("onedev", true);
}
public function search_province()
{
$prm = $this->sys_input;
$src = "%";
if ($prm['search'])
$src = "%{$prm['search']}%";
$max_rst = 40;
$tot_count =0;
// QUERY TOTAL
$sql = "select count(*) total
from m_province
where M_ProvinceName LIKE ?
and M_ProvinceIsActive = 'Y'";
$query = $this->db_smartone->query($sql, array($src));
if ($query) {
$tot_count = $query->result_array()[0]["total"];
}
else {
$this->sys_error_db("m_province count",$this->db_smartone);
exit;
}
$sql = "select M_ProvinceID, M_ProvinceName, IF(Conf_DefaultID IS NULL, 'N', 'Y') is_default
from m_province
left join conf_default on conf_defaultisactive = 'Y' and conf_defaultm_provinceid = M_ProvinceID
where M_ProvinceName LIKE ?
and M_ProvinceIsActive = 'Y'
order by M_ProvinceName
limit 0, {$max_rst}
";
$query = $this->db_smartone->query($sql, array($src));
if ($query) {
$rows = $query->result_array();
$result = array("total" => $tot_count, "records" => $rows, "total_display" => sizeof($rows));
$this->sys_ok($result);
}
else {
$this->sys_error_db("m_province rows",$this->db_smartone);
exit;
}
}
public function search_city()
{
$prm = $this->sys_input;
$src = "%";
if ($prm['search'])
$src = "%{$prm['search']}%";
$max_rst = 40;
$tot_count =0;
// QUERY TOTAL
$sql = "select count(*) total
from m_city
where M_CityName LIKE ?
and M_CityIsActive = 'Y'
and M_CityM_ProvinceID = ?";
$query = $this->db_smartone->query($sql, array($src, $prm['province_id']));
if ($query) {
$tot_count = $query->result_array()[0]["total"];
}
else {
$this->sys_error_db("m_city count",$this->db_smartone);
exit;
}
$sql = "select M_CityID, M_CityName, IF(Conf_DefaultID IS NULL, 'N', 'Y') is_default
from m_city
left join conf_default on conf_defaultisactive = 'Y' and conf_defaultm_cityid = M_CityID
where M_CityName LIKE ?
and M_CityIsActive = 'Y'
and M_CityM_ProvinceID = ?
order by M_CityName
limit 0, {$max_rst}
";
$query = $this->db_smartone->query($sql, array($src, $prm['province_id']));
if ($query) {
$rows = $query->result_array();
$result = array("total" => $tot_count, "records" => $rows, "total_display" => sizeof($rows));
$this->sys_ok($result);
}
else {
$this->sys_error_db("m_city rows",$this->db_smartone);
exit;
}
}
public function search_district()
{
$prm = $this->sys_input;
$src = "%";
if ($prm['search'])
$src = "%{$prm['search']}%";
$max_rst = 40;
$tot_count =0;
// QUERY TOTAL
$sql = "select count(*) total
from m_district
where M_DistrictName LIKE ?
and M_DistrictIsActive = 'Y'
and M_DistrictM_CityID = ?";
$query = $this->db_smartone->query($sql, array($src, $prm['city_id']));
if ($query) {
$tot_count = $query->result_array()[0]["total"];
}
else {
$this->sys_error_db("m_district count",$this->db_smartone);
exit;
}
$sql = "select M_DistrictID, M_DistrictName, IF(Conf_DefaultID IS NULL, 'N', 'Y') is_default
from m_district
left join conf_default on conf_defaultisactive = 'Y' and conf_defaultm_districtid = M_DistrictID
where M_DistrictName LIKE ?
and M_DistrictIsActive = 'Y'
and M_DistrictM_CityID = ?
order by M_DistrictName
-- limit 0, {$max_rst}
";
$query = $this->db_smartone->query($sql, array($src, $prm['city_id']));
if ($query) {
$rows = $query->result_array();
$result = array("total" => $tot_count, "records" => $rows, "total_display" => sizeof($rows));
$this->sys_ok($result);
}
else {
$this->sys_error_db("m_district rows",$this->db_smartone);
exit;
}
}
public function search_kelurahan()
{
$prm = $this->sys_input;
$src = "%";
if ($prm['search'])
$src = "%{$prm['search']}%";
$max_rst = 40;
$tot_count =0;
// QUERY TOTAL
$sql = "select count(*) total
from m_kelurahan
where M_KelurahanName LIKE ?
and M_KelurahanIsActive = 'Y'
and M_KelurahanM_DistrictID = ?";
$query = $this->db_smartone->query($sql, array($src, $prm['district_id']));
if ($query) {
$tot_count = $query->result_array()[0]["total"];
}
else {
$this->sys_error_db("m_kelurahan count",$this->db_smartone);
exit;
}
$sql = "select M_KelurahanID, M_KelurahanName, IF(Conf_DefaultID IS NULL, 'N', 'Y') is_default
from m_kelurahan
left join conf_default on conf_defaultisactive = 'Y' and conf_defaultm_kelurahanid = M_KelurahanID
where M_KelurahanName LIKE ?
and M_KelurahanIsActive = 'Y'
and M_KelurahanM_DistrictID = ?
order by M_KelurahanName
limit 0, {$max_rst}
";
$query = $this->db_smartone->query($sql, array($src, $prm['district_id']));
if ($query) {
$rows = $query->result_array();
$result = array("total" => $tot_count, "records" => $rows, "total_display" => sizeof($rows));
$this->sys_ok($result);
}
else {
$this->sys_error_db("m_kelurahan rows",$this->db_smartone);
exit;
}
}
}

View File

@@ -0,0 +1,36 @@
<?php
class Conf extends MY_Controller
{
var $db_smartone;
public function index()
{
echo "CONF API";
}
public function __construct()
{
parent::__construct();
$this->db_smartone = $this->load->database("onedev", true);
}
public function search()
{
$prm = $this->sys_input;
$tot_count = 1;
$sql = "SELECT * FROM conf_clinic";
$query = $this->db_smartone->query($sql);
if ($query) {
$rows = $query->row();
$result = array("total" => $tot_count, "records" => $rows, "total_display" => sizeof($rows));
$this->sys_ok($result);
}
else {
$this->sys_error_db("CONF rows",$this->db_smartone);
exit;
}
}
}

View File

@@ -0,0 +1,69 @@
<?php
class Diagnose extends MY_Controller
{
var $db_smartone;
public function index()
{
echo "Diagnose API";
}
public function __construct()
{
parent::__construct();
$this->db_smartone = $this->load->database("clinicdev", true);
}
public function search()
{
$prm = $this->sys_input;
$max_rst = 25;
$tot_count =0;
$q = [
'search' => '%'
];
if ($prm['search'] != '')
{
$q['search'] = "%{$prm['search']}%";
}
// QUERY TOTAL
$sql = "select count(*) total
from
m_diagnose
where M_DiagnoseIsActive = 'Y'
and M_DiagnoseName like ?";
$query = $this->db_smartone->query($sql, array($q['search']));
if ($query) {
$tot_count = $query->result_array()[0]["total"];
}
else {
$this->sys_error_db("m_diagnose count",$this->db_smartone);
exit;
}
$sql = "select M_DiagnoseID, M_DiagnoseName
from m_diagnose
where M_DiagnoseIsActive = 'Y'
and M_DiagnoseName like ?
limit {$max_rst}";
$query = $this->db_smartone->query($sql, array($q['search']));
if ($query) {
$rows = $query->result_array();
foreach ($rows as $k => $v)
$rows[$k]['mou'] = json_decode($v['mou']);
$result = array("total" => $tot_count, "records" => $rows, "total_display" => sizeof($rows));
$this->sys_ok($result);
}
else {
$this->sys_error_db("m_diagnose rows",$this->db_smartone);
exit;
}
}
}

View File

@@ -0,0 +1,78 @@
<?php
class Doctor extends MY_Controller
{
var $db_smartone;
public function index()
{
echo "Doctor API";
}
public function __construct()
{
parent::__construct();
$this->db_smartone = $this->load->database("onedev", true);
}
public function search()
{
$prm = $this->sys_input;
$max_rst = 12;
$tot_count =0;
$q = [
'search' => '%'
];
if ($prm['search'] != '')
{
$q['search'] = "%{$prm['search']}%";
}
// QUERY TOTAL
$sql = "select count(*) total
from
m_doctor
JOIN m_doctorpj ON M_DoctorID = M_DoctorPJM_DoctorID and M_DoctorIsActive = 'Y'
where M_DoctorIsActive = 'Y'
and M_DoctorPJIsClinic = 'Y'
and M_DoctorName like ?";
$query = $this->db_smartone->query($sql, array($q['search']));
if ($query) {
$tot_count = $query->result_array()[0]["total"];
}
else {
$this->sys_error_db("m_patient count",$this->db_smartone);
exit;
}
$sql = "select M_DoctorID, M_DoctorIsDefault, M_DoctorIsPJ,
concat(IFNULL(M_DoctorPrefix, ''),' ',M_DoctorName, ' ', IFNULL(M_DoctorSufix, '')) as M_DoctorName,
IFNULL( concat('[', group_concat(JSON_OBJECT('M_DoctorAddressDescription', M_DoctorAddressDescription, 'M_DoctorAddressID', M_DoctorAddressID) SEPARATOR ','), ']'), '[]') as address
from m_doctor
JOIN m_doctorpj ON M_DoctorID = M_DoctorPJM_DoctorID and M_DoctorIsActive = 'Y'
left join m_doctoraddress on M_DoctorAddressIsActive = 'Y'
and M_DoctorAddressM_DoctorID = M_DoctorID
where M_DoctorPJIsActive = 'Y'
and M_DoctorIsClinic = 'Y'
and concat(IFNULL(M_DoctorPrefix, ''),' ',M_DoctorName, ' ', IFNULL(M_DoctorSufix, '')) like ?
group by M_DoctorID";
$query = $this->db_smartone->query($sql, array($q['search']));
if ($query) {
$rows = $query->result_array();
foreach ($rows as $k => $v)
$rows[$k]['address'] = json_decode($v['address']);
$result = array("total" => $tot_count, "records" => $rows, "total_display" => sizeof($rows));
$this->sys_ok($result);
}
else {
$this->sys_error_db("m_doctor rows",$this->db_smartone);
exit;
}
}
}

View File

@@ -0,0 +1,67 @@
<?php
class Gcs extends MY_Controller
{
var $db_smartone;
public function index()
{
echo "GCS API";
}
public function __construct()
{
parent::__construct();
$this->db_smartone = $this->load->database("clinicdev", true);
}
public function search()
{
$prm = $this->sys_input;
$max_rst = 25;
$tot_count =0;
$q = [
'search' => '%'
];
if ($prm['search'] != '')
{
$q['search'] = "%{$prm['search']}%";
}
// QUERY TOTAL
$sql = "select count(*) total
from
m_gcs
where M_GcsIsActive = 'Y'
and M_GcsName like ?";
$query = $this->db_smartone->query($sql, array($q['search']));
if ($query) {
$tot_count = $query->result_array()[0]["total"];
}
else {
$this->sys_error_db("m_gcs count",$this->db_smartone);
exit;
}
$sql = "select M_GcsID, M_GcsName
from m_gcs
where M_GcsIsActive = 'Y'
and M_GcsName like ?
limit {$max_rst}";
$query = $this->db_smartone->query($sql, array($q['search']));
if ($query) {
$rows = $query->result_array();
$result = array("total" => $tot_count, "records" => $rows, "total_display" => sizeof($rows));
$this->sys_ok($result);
}
else {
$this->sys_error_db("m_gcs rows",$this->db_smartone);
exit;
}
}
}

View File

@@ -0,0 +1,67 @@
<?php
class Order extends MY_Controller
{
var $db_smartone;
public function index()
{
echo "ORDER API";
}
public function __construct()
{
parent::__construct();
$this->db_smartone = $this->load->database("clinicdev", true);
}
function save()
{
$prm = $this->sys_input;
$prm['header']['complaint'] = str_replace(PHP_EOL, '<br>', $prm['header']['complaint']);
$header_json = json_encode($prm['header']);
$payment_json = json_encode($prm['payment']);
$uid = $this->sys_user['M_UserID'];
$sql = "CALL sp_clinic_fo_save('{$prm['order_id']}', '{$header_json}', '{$payment_json}', '{$uid}');";
$query = $this->db_smartone->query($sql);
if ($query)
{
$rst = $query->row();
$rst->data = json_decode($rst->data);
// if ($rst->status == "OK")
// {
// // persiapkan curl
// $ch = curl_init();
// // set url
// curl_setopt($ch, CURLOPT_URL, "http://anggrek.aplikasi.web.id:9090/ticket/KLINIK");
// // return the transfer as a string
// curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
// // $output contains the output string
// $output = json_decode(curl_exec($ch));
// // tutup curl
// curl_close($ch);
// // menampilkan hasil curl
// // echo $output;
// if ($output != null)
// if ($output->status == "OK")
// $rst->data->queue = $output->data[0]->number;
// }
echo json_encode($rst);
}
else
{
$this->sys_error_db("save order", $this->db_smartone);
exit;
}
}
}

View File

@@ -0,0 +1,264 @@
<?php
/*
template function {
$this->sys_debug();
try {
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$prm = $this->sys_input;
} catch(Exception $exc) {
$message = $exc->getMessage();
$this->sys_error($message);
}
}
*/
class Patient extends MY_Controller
{
var $db_smartone;
public function index()
{
echo "Patient API";
}
public function __construct()
{
parent::__construct();
$this->db_smartone = $this->load->database("onedev", true);
}
public function search()
{
$prm = $this->sys_input;
$max_rst = 12;
$tot_count =0;
$q = [
'noreg' => '%',
'name' => '%',
'hp' => '%',
'dob' => '%',
'address' => '%'
];
if ($prm['noreg'] != '')
$q['noreg'] = "%{$prm['noreg']}%";
if ($prm['search'] != '')
{
$e = explode('+', $prm['search']);
if (isset($e[0]))
$q['name'] = "%{$e[0]}%";
if (isset($e[1]))
$q['hp'] = "%{$e[1]}%";
if (isset($e[2]))
$q['dob'] = "%{$e[2]}%";
if (isset($e[3]))
$q['address'] = "%{$e[3]}%";
}
// QUERY TOTAL
$sql = "select count(distinct m_patientid) total
from
m_patient join m_title on M_PatientM_TitleID = M_TitleID
join m_patientaddress on M_PatientAddressM_PatientID = M_PatientID and M_PatientAddressIsActive = 'Y'
where M_PatientNoReg like ?
and M_PatientName LIKE ?
and ((M_PatientHP LIKE ? and M_PatientHP IS NOT NULL) OR M_PatientHP IS NULL)
and ((DATE_FORMAT(M_PatientDOB, '%d-%m-%Y') LIKE ? and M_PatientDOB IS NOT NULL) OR M_PatientDOB IS NULL)
and M_PatientAddressDescription LIKE ?";
$query = $this->db_smartone->query($sql, array($q['noreg'], $q['name'], $q['hp'], $q['dob'], $q['address']));
if ($query) {
$tot_count = $query->result_array()[0]["total"];
}
else {
$this->sys_error_db("m_patient count",$this->db_smartone);
exit;
}
$sql = "SELECT M_PatientID, M_PatientNoReg,
concat(M_TitleName,' ',M_PatientName) M_PatientName,
M_PatientName M_PatientRealName, M_TitleID, M_TitleName, M_SexID, M_SexName,
M_PatientHP, M_PatientPOB, M_PatientDOB, M_PatientNote,
concat(M_PatientAddressDescription, '\n\n', m_kelurahanname, ', ', m_districtname,
'\n', m_cityname, ', ', m_provincename) as M_PatientAddress,
M_PatientAddressDescription, M_PatientM_IdTypeID, M_PatientIDNumber,
IFNULL(M_PatientNote, '') M_PatientNote, M_PatientPhoto, IF(M_PatientPhone IS NULL OR M_PatientPhone = '', M_PatientHP, M_PatientPhone) hp,
fn_fo_patient_visit(M_PatientID) info,
M_KelurahanID, M_DistrictID, M_CityID, M_ProvinceID, M_PatientM_ReligionID,
IFNULL(M_ReligionName, '-') M_ReligionName
from
m_patient join m_title on M_PatientM_TitleID = M_TitleID
join m_sex on M_PatientM_SexID = M_SexID
join m_patientaddress on M_PatientAddressM_PatientID = M_PatientID and M_PatientAddressIsActive = 'Y'
left join m_kelurahan on m_patientaddressm_kelurahanid = m_kelurahanid
left join m_district on m_kelurahanm_districtid = m_districtid
left join m_city on m_districtm_cityid = m_cityid
left join m_province on m_citym_provinceid = m_provinceid
left join m_religion on m_patientm_religionid = m_religionid
where M_PatientNoReg like ?
and M_PatientName LIKE ?
and ((M_PatientHP LIKE ? and M_PatientHP IS NOT NULL) OR M_PatientHP IS NULL)
and ((DATE_FORMAT(M_PatientDOB, '%d-%m-%Y') LIKE ? and M_PatientDOB IS NOT NULL) OR M_PatientDOB IS NULL)
and M_PatientAddressDescription LIKE ?
group by m_patientid
limit 0,{$max_rst}";
$query = $this->db_smartone->query($sql, array($q['noreg'], $q['name'], $q['hp'], $q['dob'], $q['address']));
if ($query) {
$rows = $query->result_array();
foreach ($rows as $k => $v)
$rows[$k]['info'] = json_decode($v['info']);
$result = array("total" => $tot_count, "records" => $rows, "total_display" => sizeof($rows), "query" => $this->db_smartone->last_query());
$this->sys_ok($result);
}
else {
$this->sys_error_db("m_patient rows",$this->db_smartone);
exit;
}
}
function add_new()
{
$prm = $this->sys_input;
$prm['M_PatientDOB'] = date('Y-m-d', strtotime($prm['M_PatientDOB']));
$ptn = [
'M_PatientName' => $prm['M_PatientName'],
'M_PatientM_TitleID' => $prm['M_PatientM_TitleID'],
'M_PatientSuffix' => $prm['M_PatientSuffix'],
'M_PatientM_SexID' => $prm['M_PatientM_SexID'],
'M_PatientM_ReligionID' => $prm['M_PatientM_ReligionID'],
'M_PatientDOB' => $prm['M_PatientDOB'],
'M_PatientPOB' => $prm['M_PatientPOB'],
'M_PatientHP' => $prm['M_PatientHP'],
'M_PatientPhone' => $prm['M_PatientPhone'],
'M_PatientEmail' => $prm['M_PatientEmail'],
'M_PatientM_IdTypeID' => $prm['M_PatientM_IdTypeID'],
'M_PatientIDNumber' => $prm['M_PatientIDNumber'],
'M_PatientNote' => $prm['M_PatientNote']
];
$this->db_smartone->insert('m_patient', $ptn);
$err = $this->db_smartone->error();
if ( $err['message'] != "" )
{
$this->sys_error_db("m_patient rows", $this->db_smartone);
return;
}
$id = $this->db_smartone->insert_id();
// LOG FO
$ptn = json_encode($ptn);
$this->db_smartone->query("CALL one_log.log_me('FO', 'FO.PATIENT.ADD', '{$ptn}', '0')");
// save address
$add = [
'M_PatientAddressM_PatientID' => $id,
'M_PatientAddressDescription' => $prm['M_PatientAddressDescription'],
'M_PatientAddressM_KelurahanID' => $prm['M_PatientAddressM_KelurahanID']
];
$this->db_smartone->insert('m_patientaddress', $add);
// LOG FO
$add = json_encode($add);
$this->db_smartone->query("CALL one_log.log_me('FO', 'FO.PATIENT.ADDRESS.ADD', '{$add}', '0')");
// get
$r = $this->db_smartone->where('M_PatientID', $id)
->get('m_patient')
->row();
$rst = array("id" => $id, 'noreg'=>$r->M_PatientNoReg);
$this->sys_ok($rst);
}
function edit()
{
$prm = $this->sys_input;
$prm['M_PatientDOB'] = date('Y-m-d', strtotime($prm['M_PatientDOB']));
$this->db_smartone->set('M_PatientName', $prm['M_PatientName'])
->set('M_PatientM_TitleID', $prm['M_PatientM_TitleID'])
->set('M_PatientSuffix', $prm['M_PatientSuffix'])
->set('M_PatientM_SexID', $prm['M_PatientM_SexID'])
->set('M_PatientM_ReligionID', $prm['M_PatientM_ReligionID'])
->set('M_PatientDOB', $prm['M_PatientDOB'])
->set('M_PatientPOB', $prm['M_PatientPOB'])
->set('M_PatientHP', $prm['M_PatientHP'])
->set('M_PatientPhone', $prm['M_PatientPhone'])
->set('M_PatientEmail', $prm['M_PatientEmail'])
->set('M_PatientM_IdTypeID', $prm['M_PatientM_IdTypeID'])
->set('M_PatientIDNumber', $prm['M_PatientIDNumber'])
->set('M_PatientNote', $prm['M_PatientNote'])
->where('M_PatientID', $prm['id'])
->update('m_patient');
$err = $this->db_smartone->error();
if ( $err['message'] != "" )
{
$this->sys_error_db("m_patient rows", $this->db_smartone);
return;
}
$id = $prm['id'];
// LOG FO
unset($prm['token']);
$ptn = json_encode($prm);
$this->db_smartone->query("CALL one_log.log_me('FO', 'FO.PATIENT.EDIT', '{$ptn}', '{$this->sys_user['M_UserID']}')");
// save address
// $add = [
// 'M_PatientAddressM_PatientID' => $id,
// 'M_PatientAddressDescription' => $prm['M_PatientAddressDescription'],
// 'M_PatientAddressM_KelurahanID' => $prm['M_PatientAddressM_KelurahanID']
// ];
// $this->db_smartone->insert('m_patientaddress', $add);
// LOG FO
// $add = json_encode($add);
// $this->db_smartone->query("CALL one_log.log_me('FO', 'FO.PATIENT.ADDRESS.ADD', '{$add}', '0')");
// get
$r = $this->db_smartone->where('M_PatientID', $id)
->get('m_patient')
->row();
$rst = array("id" => $id, 'noreg'=>$r->M_PatientNoReg);
$this->sys_ok($rst);
}
public function search_idtype()
{
$prm = $this->sys_input;
$sql = "SELECT M_IdTypeID, M_IdTypeName
FROM m_idtype
WHERE M_IdTypeIsActive = 'Y'
ORDER BY M_IdTypeName ASC";
$query = $this->db_smartone->query($sql);
if ($query) {
$rows = $query->result_array();
$result = array("records" => $rows);
$this->sys_ok($result);
}
else {
$this->sys_error_db("m_idtype rows",$this->db_smartone);
exit;
}
}
}

View File

@@ -0,0 +1,217 @@
<?php
class Payment extends MY_Controller
{
var $db_smartone;
public function index()
{
echo "Payment API";
}
public function __construct()
{
parent::__construct();
$this->db_smartone = $this->load->database("clinicdev", true);
}
public function get_order() {
$prm = $this->sys_input;
$rst = ["order_header"=>[], "order_detail"=>[]];
$sql = "
select T_OrderHeaderID as order_id,
T_OrderHeaderLabNumber as order_no,
T_OrderHeaderDate as order_date,
T_OrderHeaderSubTotal as order_subtotal,
T_OrderHeaderRounding as order_rounding,
T_OrderHeaderTotal as order_total,
M_PatientName as patient_name,
M_PatientNoReg as patient_mr,
M_MouName as order_mou,
M_CompanyName as order_company
from t_orderheader
join m_patient on T_OrderHeaderM_PatientID = M_PatientID
join m_company on T_OrderHeaderM_CompanyID = M_CompanyID
join m_mou on T_OrderHeaderM_MouID = M_MouID
where T_OrderHeaderID = ?";
$query = $this->db_smartone->query($sql, array($prm['id']));
if ($query) {
$rows = (array) $query->row();
$rst['order_header'] = $rows;
// $result = array("status" => "OK" , "data" => $rst);
// $this->sys_ok($result);
// exit;
} else {
$this->sys_error_db("m_doctoraddress ", $this->db_smartone);
exit;
}
// { n:1, d_id:1, t_id:1, t_name:'SGOT', t_price:80000, t_disctotal:7000, t_total:73000 },
// { n:2, d_id:2, t_id:2, t_name:'SGPT', t_price:75000, t_disctotal:8000, t_total:67000 }
// T_OrderDetailPrice double [0]
// T_OrderDetailPriceForDisc double [0]
// T_OrderDetailDisc double [0]
// T_OrderDetailDiscAmount double [0]
// T_OrderDetailTotal
$sql = "
select T_OrderDetailID as d_id,
T_OrderDetailT_TestID as t_id,
T_OrderDetailT_TestName as t_name,
T_OrderDetailPrice as t_price,
T_OrderDetailDiscTotal as t_disctotal,
T_OrderDetailTotal as t_total
from t_orderdetail
where T_OrderDetailT_OrderHeaderID = ?
and T_ORderDetailIsActive = 'Y'";
$query = $this->db_smartone->query($sql, array($prm['id']));
if ($query) {
$rows = $query->result_array();
$rst['order_detail'] = $rows;
$result = array("status" => "OK" , "data" => $rst);
$this->sys_ok($result);
exit;
} else {
$this->sys_error_db("m_doctoraddress ", $this->db_smartone);
exit;
}
}
public function search()
{
$this->db_smartone = $this->load->database("onedev", true);
$prm = $this->sys_input;
$max_rst = 100;
$tot_count =0;
$q = [
'search' => '%'
];
if ($prm['search'] != '')
{
$q['search'] = "%{$prm['search']}%";
}
// QUERY TOTAL
$sql = "select count(*) total
from
m_paymenttype
where M_PaymentTypeIsActive = 'Y'
and M_PaymentTypeName like ?";
$query = $this->db_smartone->query($sql, array($q['search']));
if ($query) {
$tot_count = $query->result_array()[0]["total"];
}
else {
$this->sys_error_db("m_paymenttype count",$this->db_smartone);
exit;
}
$sql = "select M_PaymentTypeID payment_type_id, M_PaymentTypeName payment_type_name, M_PaymentTypeCode payment_type_code,
0 payment_amount, '' payment_note, 'Nomor Kartu' payment_note_label, 'N' payment_enable,
0 payment_change, 0 payment_actual, 0 payment_card_id, 0 payment_edc_id, 0 payment_account_id
from m_paymenttype
where M_PaymentTypeIsActive = 'Y'
and M_PaymentTypeName like ?";
$query = $this->db_smartone->query($sql, array($q['search']));
if ($query) {
$rows = $query->result_array();
foreach($rows as $k => $v) {
if ($v['payment_type_code'] == 'CASH')
$v['payment_note_label'] = 'Kembali';
if ($v['payment_type_code'] == 'VOUCHER')
$v['payment_note_label'] = 'Nomor Voucher';
$rows[$k] = $v;
}
$result = $rows;
$this->sys_ok($result);
}
else {
$this->sys_error_db("m_paymenttype rows",$this->db_smartone);
exit;
}
}
function save()
{
$prm = $this->sys_input;
$payment_json = json_encode($prm['payments']);
$sql = "CALL sp_fo_payment('{$prm['order_id']}', '{$payment_json}');";
$query = $this->db_smartone->query($sql);
if ($query)
{
$rst = $query->row();
$rst->data = json_decode($rst->data);
echo json_encode($rst);
}
else
{
$this->sys_error_db("save payment", $this->db_smartone);
exit;
}
}
function log_nota()
{
$prm = $this->sys_input;
$dblog = $this->load->database('onelog', true);
$p = $this->db_smartone->where('c_orderheaderid', $prm['order_id'])
->get('c_orderheader')
->row();
$uid = $this->sys_user['M_UserID'];
$q = $dblog->set("Log_ClinicUserID", $uid)
->set("Log_ClinicJson", json_encode(["order_id"=>$prm['order_id'], "patient_id"=>$p->C_OrderHeaderM_PatientID]))
->set("Log_ClinicCode", "CLINIC.PRINT.RECEIPT")
->insert('log_clinic');
if ($q) {
$id = $dblog->insert_id();
$this->sys_ok($id);
}
else {
$this->sys_error_db("LOG Nota",$this->db_smartone);
exit;
}
}
public function search_bank()
{
$prm = $this->sys_input;
// QUERY TOTAL
$sql = "SELECT Nat_BankID, Nat_BankName
FROM nat_bank ORDER BY Nat_BankName ASC";
$query = $this->db_smartone->query($sql);
if ($query)
{
$rows = $query->result_array();
$this->sys_ok(["records"=>$rows, "total"=>sizeof($rows)]);
}
else
{
$this->sys_error_db("NAT BANK",$this->db_smartone);
exit;
}
}
}

View File

@@ -0,0 +1,144 @@
<?php
class Photo extends MY_Controller
{
var $db_smartone;
public function index()
{
echo "Photo API";
}
public function __construct()
{
parent::__construct();
$this->db_smartone = $this->load->database("onedev", true);
$this->load->library('ImageManipulator');
}
public function upload()
{
$inp = $this->sys_input;
$home_dir = "/home/one/Web/";
$target_dir = $home_dir . "one-media/one-photo/patient/" . date("Y") . "/";
$y = $this->regenerateOldPhoto($home_dir, $inp['id']);
// get patient mr
$p = $this->db_smartone->select("M_PatientNoReg")
->where("M_PatientID", $inp['id'])
->get('m_patient')
->row();
if (!file_exists($target_dir)) {
mkdir($target_dir, 0755, true);
}
$target_path = $target_dir . $p->M_PatientNoReg . ".jpg";
$this->base64_to_jpeg($inp['data'], $target_path);
// CROP Image
$im = new ImageManipulator($target_path);
$w = $im->getWidth();
$h = $im->getHeight();
$mw = ceil(3 * $h / 4);
if ($w <= $mw)
{
$x1 = 0;
$y1 = 0;
$x2 = $w;
$y2 = $h;
}
else
{
$x1 = floor(($w - $mw) / 2);
$y1 = 0;
$x2 = ceil($w - (($w - $mw) / 2));
$y2 = $h;
}
$im->crop($x1, $y1, $x2, $y2); // takes care of out of boundary conditions automatically
$im->save($target_path);
$x = $this->generateThumbnail($target_path, 75, 100);
// Save to DB
$this->db_smartone->set("M_PatientPhoto", "/" . str_replace($home_dir, "", $target_path))
->set("M_PatientPhotoThumb", "/" . str_replace($home_dir, "", $x))
->set('M_PatientPhotoCounter', '`M_PatientPhotoCounter` + 1', false)
->where('M_PatientID', $inp['id'])
->update('m_patient');
// LOGGING
$code = $y ? "PHOTO.PATIENT.EDIT" : "PHOTO.PATIENT.ADD";
$one_log = $this->load->database('onelog', true);
$one_log->set('Log_PhotoCode', $code)
->set('Log_PhotoM_PatientID', $inp['id'])
->set('Log_PhotoUrl', $y ? $y : "/" . str_replace($home_dir, "", $target_path))
->insert('log_photo');
$this->sys_ok(["rename"=>$y, "patient_id"=>$inp['id'], "patient_mr"=>$p->M_PatientNoReg, "photo_url"=>"http://" . $_SERVER['SERVER_NAME'] . "/" . str_replace($home_dir, "", $target_path) . "?d=" . date("YmdHis")]);
}
function base64_to_jpeg($base64_string, $output_file) {
// open the output file for writing
$ifp = fopen( $output_file, 'wb' );
// split the string on commas
// $data[ 0 ] == "data:image/png;base64"
// $data[ 1 ] == <actual base64 string>
$data = explode( ',', $base64_string );
// we could add validation here with ensuring count( $data ) > 1
fwrite( $ifp, base64_decode( $data[ 1 ] ) );
// clean up the file resource
fclose( $ifp );
return $output_file;
}
function generateThumbnail($img, $width, $height, $quality = 90)
{
if (is_file($img)) {
$imagick = new Imagick(realpath($img));
$imagick->setImageFormat('jpeg');
$imagick->setImageCompression(Imagick::COMPRESSION_JPEG);
$imagick->setImageCompressionQuality($quality);
$imagick->thumbnailImage($width, $height, false, false);
$filename_no_ext = reset(explode('.', $img));
if (file_put_contents($filename_no_ext . '_thumb' . '.jpg', $imagick) === false) {
throw new Exception("Could not put contents.");
}
return $filename_no_ext . '_thumb' . '.jpg';
}
else {
throw new Exception("No valid image provided with {$img}.");
}
}
function regenerateOldPhoto($home_dir, $id)
{
$r = $this->db_smartone->select('m_patientphoto, m_patientphotocounter', false)
->where('m_patientid', $id)
->get('m_patient')
->row();
if ($r->m_patientphoto != null && $r->m_patientphotocounter > 0) {
$full_path = substr_replace($home_dir ,"", -1) . $r->m_patientphoto;
$path_parts = pathinfo($full_path);
$rename = $path_parts['dirname'] . '/' . $path_parts['filename'] . '-' . $r->m_patientphotocounter . '.' . $path_parts['extension'];
rename($full_path, $rename);
// echo $path_parts['dirname'], "\n";
// echo $path_parts['extension'], "\n";
// echo $path_parts['filename'], "\n";
return "/" . str_replace($home_dir, "", $rename);
}
return false;
}
}

View File

@@ -0,0 +1,409 @@
<?php
//diberi tambahan pembeda IsFromPanel
//utk contoh kasus yg ndak bisa di delete
//sementara profile di ambilkan dari panel juga dengan IsFromPanel = N
class Px extends MY_Controller
{
var $db_smartone;
public function index()
{
echo "Px API";
}
public function __construct()
{
parent::__construct();
$this->db_smartone = $this->load->database("onedev", true);
}
public function profile() {
$prm = $this->sys_input;
$search = $prm["search"];
$mouCompanyID = $prm["mouCompanyID"];
$sql_param = array($mouCompanyID, "%$search%");
$sql = "select count(distinct T_TestPanelID) total
from
t_testpanel
join t_testpaneldetail on T_TestPanelID = T_TestPanelDetailT_TestPanelID
and T_TestPanelIsActive = 'Y' and T_TestPanelDetailIsActive = 'Y'
join t_test on T_TestPanelDetailT_TestID = T_TestID
and T_TestIsActive = 'Y'
join t_testprice on T_TestID = T_TestPriceT_TestID
and T_TestIsPrice = 'Y'
and T_TestPriceIsActive = 'Y'
and T_TestPriceM_MouCompanyID = ?
where
T_TestPanelName like ? ";
$query = $this->db_smartone->query($sql, $sql_param);
$tot_count =0;
if ($query) {
$tot_count = $query->result_array()[0]["total"];
} else {
$this->sys_error_db("m_testpanel count", $this->db_smartone);
exit;
}
$sql = "select distinct T_TestPanelID
from
t_testpanel
join t_testpaneldetail on T_TestPanelID = T_TestPanelDetailT_TestPanelID
and T_TestPanelIsActive = 'Y' and T_TestPanelDetailIsActive = 'Y'
join t_test on T_TestPanelDetailT_TestID = T_TestID
and T_TestIsActive = 'Y'
join t_testprice on T_TestID = T_TestPriceT_TestID
and T_TestIsPrice = 'Y'
and T_TestPriceIsActive = 'Y'
and T_TestPriceM_MouCompanyID = ?
where
T_TestPanelName like ?
limit 0,20";
$query = $this->db_smartone->query($sql,$sql_param);
$xrows = $query->result_array();
$a_tpid = "-1";
foreach($xrows as $r) {
$a_tpid .= "," . $r["T_TestPanelID"];
}
$sql = "select distinct T_TestPanelID,T_TestPanelName,
T_TestID,T_TestName, 'N' IsFromPanel, T_TestRequirement,
t_testprice.*
from
t_testpanel
join t_testpaneldetail on T_TestPanelID = T_TestPanelDetailT_TestPanelID
and T_TestPanelIsActive = 'Y' and T_TestPanelDetailIsActive = 'Y'
join t_test on T_TestPanelDetailT_TestID = T_TestID
and T_TestIsActive = 'Y'
join t_testprice on T_TestID = T_TestPriceT_TestID
and T_TestIsPrice = 'Y'
and T_TestPriceM_MouCompanyID = ?
and T_TestPriceIsActive = 'Y'
where
T_TestPanelID in ( $a_tpid ) ";
$query = $this->db_smartone->query($sql,array($mouCompanyID));
$xrows = $query->result_array();
$rows = array();
$prev_tpanel_id = 0;
foreach($xrows as $r) {
$tpanel_id = $r["T_TestPanelID"];
if ($tpanel_id != $prev_tpanel_id) {
$rows[] = array(
"T_TestPanelID" => $r["T_TestPanelID"],
"T_TestPanelName" => $r["T_TestPanelName"],
"test" => array()
);
}
$idx = count($rows) - 1;
$rows[$idx]["test"][] = $r;
$prev_tpanel_id = $tpanel_id;
}
$result = array("total" => $tot_count, "records" => $rows );
$this->sys_ok($result);
exit;
}
public function panel() {
$prm = $this->sys_input;
$search = $prm["search"];
$mouCompanyID = $prm["mouCompanyID"];
$sql_param = array($mouCompanyID, "%$search%");
$sql = "select count(distinct T_TestPanelID) total
from
t_testpanel
join t_testpaneldetail on T_TestPanelID = T_TestPanelDetailT_TestPanelID
and T_TestPanelIsActive = 'Y' and T_TestPanelDetailIsActive = 'Y'
join t_test on T_TestPanelDetailT_TestID = T_TestID
and T_TestIsActive = 'Y'
join t_testprice on T_TestID = T_TestPriceT_TestID
and T_TestIsPrice = 'Y'
and T_TestPriceIsActive = 'Y'
and T_TestPriceM_MouCompanyID = ?
where
T_TestPanelName like ? ";
$query = $this->db_smartone->query($sql, $sql_param);
$tot_count =0;
if ($query) {
$tot_count = $query->result_array()[0]["total"];
} else {
$this->sys_error_db("m_testpanel count", $this->db_smartone);
exit;
}
$sql = "select distinct T_TestPanelID
from
t_testpanel
join t_testpaneldetail on T_TestPanelID = T_TestPanelDetailT_TestPanelID
and T_TestPanelIsActive = 'Y' and T_TestPanelDetailIsActive = 'Y'
join t_test on T_TestPanelDetailT_TestID = T_TestID
and T_TestIsActive = 'Y'
join t_testprice on T_TestID = T_TestPriceT_TestID
and T_TestIsPrice = 'Y'
and T_TestPriceIsActive = 'Y'
and T_TestPriceM_MouCompanyID = ?
where
T_TestPanelName like ?
limit 0,20";
$query = $this->db_smartone->query($sql,$sql_param);
$xrows = $query->result_array();
$a_tpid = "-1";
foreach($xrows as $r) {
$a_tpid .= "," . $r["T_TestPanelID"];
}
$sql = "select distinct T_TestPanelID,T_TestPanelName,
T_TestID,T_TestName, 'Y' IsFromPanel,T_TestRequirement,
t_testprice.*
from
t_testpanel
join t_testpaneldetail on T_TestPanelID = T_TestPanelDetailT_TestPanelID
and T_TestPanelIsActive = 'Y' and T_TestPanelDetailIsActive = 'Y'
join t_test on T_TestPanelDetailT_TestID = T_TestID
and T_TestIsActive = 'Y'
join t_testprice on T_TestID = T_TestPriceT_TestID
and T_TestIsPrice = 'Y'
and T_TestPriceM_MouCompanyID = ?
and T_TestPriceIsActive = 'Y'
where
T_TestPanelID in ( $a_tpid )
order by T_TestPanelID";
$query = $this->db_smartone->query($sql,array($mouCompanyID));
$xrows = $query->result_array();
$rows = array();
$prev_tpanel_id = 0;
foreach($xrows as $r) {
$tpanel_id = $r["T_TestPanelID"];
if ($tpanel_id != $prev_tpanel_id) {
$rows[] = array(
"T_TestPanelID" => $r["T_TestPanelID"],
"T_TestPanelName" => $r["T_TestPanelName"],
"test" => array()
);
}
$idx = count($rows) - 1;
$rows[$idx]["test"][] = $r;
$prev_tpanel_id = $tpanel_id;
}
$result = array("total" => $tot_count, "records" => $rows );
$this->sys_ok($result);
exit;
}
public function search_old()
{
$prm = $this->sys_input;
$search = $prm["search"];
$sql_param = array("%$search%");
$sql = "select count(distinct T_TestID) total
from
t_test
where
T_TestIsActive = 'Y'
AND T_TestIsPrice = 'Y'
AND T_TestName like ? ";
$query = $this->db_smartone->query($sql, $sql_param);
$tot_count =0;
if ($query) {
$tot_count = $query->result_array()[0]["total"];
} else {
$this->sys_error_db("m_company count", $this->db_smartone);
exit;
}
$sql = "select distinct T_TestID,T_TestName, 'N' IsFromPanel, T_TestRequirement
from
t_test
where
T_TestIsActive = 'Y'
AND T_TestIsPrice = 'Y'
AND T_TestName like ?
limit 0,20
";
$query = $this->db_smartone->query($sql, $sql_param);
$rows = $query->result_array();
$result = array("total" => $tot_count, "records" => $rows );
$this->sys_ok($result);
exit;
}
public function search_v2()
{
$prm = $this->sys_input;
$search = $prm["search"];
$mouCompanyID = $prm["mouCompanyID"];
$sql_param = array($mouCompanyID, "%$search%");
$query = $this->db_smartone->query("CALL sp_fo_px_count_v2(?, ?)", $sql_param);
$this->clean_mysqli_connection($this->db_smartone->conn_id);
$tot_count = 0;
if ($query) {
$tot_count = $query->result_array()[0]["data"];
} else {
$this->sys_error_db("PX count", $this->db_smartone);
exit;
}
if (isset($prm['order_id']))
$query = $this->db_smartone->query("CALL sp_fo_px_search_byorder_v2(?, ?)", [$prm['order_id'], $mouCompanyID]);
else if ($search == "")
$query = $this->db_smartone->query("CALL sp_fo_px_search_favorite_v2(?, ?)", $sql_param);
else
$query = $this->db_smartone->query("CALL sp_fo_px_search_v2(?, ?)", $sql_param);
$this->clean_mysqli_connection($this->db_smartone->conn_id);
// echo $this->db_smartone->last_query();
// $query = $this->db_smartone->query($sql);
if ($query)
{
$rows = $query->result_array();
$id_to_remove = [];
// var_dump($rows);
foreach ($rows as $k => $v)
{
$rows[$k]['requirement'] = [];
$x = $this->db_smartone->query("SELECT fn_fo_requirement_get('{$v['T_TestID']}') x")
->row();
if ($x->x != null)
$rows[$k]['requirement'] = json_decode($x->x);
$rows[$k]['nat_test'] = json_decode($v['nat_test']);
$rows[$k]['child_test'] = json_decode($v['child_test']);
// IF PROFILE
if ($v['px_type'] == "PR" || $v['px_type'] == "PXR") {
if ($v['T_TestID'] == null)
{
$id_to_remove[] = $k;
continue;
}
else
{
foreach ($rows[$k]['child_test'] as $l => $w) {
$rows[$k]['child_test'][$l]->requirement = [];
$rows[$k]['child_test'][$l]->nat_test = json_decode($w->nat_test);
$x = $this->db_smartone->query("SELECT fn_fo_requirement_get('{$w->T_TestID}') x")
->row();
if ($x->x != null)
$rows[$k]['child_test'][$l]->requirement = json_decode($x->x);
}
}
}
}
// REMOVE INDEXES
foreach ($id_to_remove as $l => $w)
{ $x = $w - $l; array_splice($rows, $x, 1); }
$result = array("total" => $tot_count, "records" => (array) $rows, "query" => $sqlx, "query2" => $sqly );
$this->sys_ok($result);
exit;
}
}
public function search()
{
$prm = $this->sys_input;
$search = $prm["search"];
$mouCompanyID = $prm["mouCompanyID"];
$sql_param = array($mouCompanyID, "%$search%");
$query = $this->db_smartone->query("CALL sp_fo_px_count(?, ?)", $sql_param);
$this->clean_mysqli_connection($this->db_smartone->conn_id);
$tot_count = 0;
if ($query) {
$tot_count = $query->result_array()[0]["data"];
} else {
$this->sys_error_db("PX count", $this->db_smartone);
exit;
}
if (isset($prm['order_id']))
$query = $this->db_smartone->query("CALL sp_fo_px_search_byorder(?, ?)", [$prm['order_id'], $mouCompanyID]);
else if ($search == "")
$query = $this->db_smartone->query("CALL sp_fo_px_search_favorite(?, ?)", $sql_param);
else
$query = $this->db_smartone->query("CALL sp_fo_px_search(?, ?)", $sql_param);
$this->clean_mysqli_connection($this->db_smartone->conn_id);
// echo $this->db_smartone->last_query();
// $query = $this->db_smartone->query($sql);
if ($query)
{
$rows = $query->result_array();
$id_to_remove = [];
// var_dump($rows);
foreach ($rows as $k => $v)
{
$rows[$k]['requirement'] = [];
$x = $this->db_smartone->query("SELECT fn_fo_requirement_get('{$v['T_TestID']}') x")
->row();
if ($x->x != null)
$rows[$k]['requirement'] = json_decode($x->x);
$rows[$k]['nat_test'] = json_decode($v['nat_test']);
$rows[$k]['child_test'] = json_decode($v['child_test']);
// IF PROFILE
if ($v['px_type'] == "PR" || $v['px_type'] == "PXR") {
if ($v['T_TestID'] == null)
{
$id_to_remove[] = $k;
continue;
}
else
{
foreach ($rows[$k]['child_test'] as $l => $w) {
$rows[$k]['child_test'][$l]->requirement = [];
$rows[$k]['child_test'][$l]->nat_test = json_decode($w->nat_test);
$x = $this->db_smartone->query("SELECT fn_fo_requirement_get('{$w->T_TestID}') x")
->row();
if ($x->x != null)
$rows[$k]['child_test'][$l]->requirement = json_decode($x->x);
}
}
}
}
// REMOVE INDEXES
foreach ($id_to_remove as $l => $w)
{ $x = $w - $l; array_splice($rows, $x, 1); }
$result = array("total" => $tot_count, "records" => (array) $rows, "query" => $sqlx, "query2" => $sqly );
$this->sys_ok($result);
exit;
}
}
function get_price()
{
$prm = $this->sys_input;
$r = [];
$sql_param = array($prm['test_id'], date('Y-m-d'), $prm['cito'], $prm['mou_id']);
$sql = "select fn_price(?, ?, ?, ?) as price";
$query = $this->db_smartone->query($sql, $sql_param);
if ($query) {
$r = $query->result_array()[0];
$r = json_decode($r['price']);
$this->sys_ok($r);
exit;
} else {
$this->sys_error_db("get price", $this->db_smartone);
exit;
}
}
}

View File

@@ -0,0 +1,67 @@
<?php
class Religion extends MY_Controller
{
var $db_smartone;
public function index()
{
echo "Religion API";
}
public function __construct()
{
parent::__construct();
$this->db_smartone = $this->load->database("onedev", true);
}
public function search()
{
$prm = $this->sys_input;
$max_rst = 25;
$tot_count =0;
$q = [
'search' => '%'
];
if ($prm['search'] != '')
{
$q['search'] = "%{$prm['search']}%";
}
// QUERY TOTAL
$sql = "select count(*) total
from
m_religion
where M_ReligionIsActive = 'Y'
and M_ReligionName like ?";
$query = $this->db_smartone->query($sql, array($q['search']));
if ($query) {
$tot_count = $query->result_array()[0]["total"];
}
else {
$this->sys_error_db("m_religion count",$this->db_smartone);
exit;
}
$sql = "select M_ReligionID, M_ReligionName
from m_religion
where M_ReligionIsActive = 'Y'
and M_ReligionName like ?
limit {$max_rst}";
$query = $this->db_smartone->query($sql, array($q['search']));
if ($query) {
$rows = $query->result_array();
$result = array("total" => $tot_count, "records" => $rows, "total_display" => sizeof($rows));
$this->sys_ok($result);
}
else {
$this->sys_error_db("m_religion rows",$this->db_smartone);
exit;
}
}
}

View File

@@ -0,0 +1,72 @@
<?php
class Sex extends MY_Controller
{
var $db_smartone;
public function index()
{
echo "Sex API";
}
public function __construct()
{
parent::__construct();
$this->db_smartone = $this->load->database("onedev", true);
}
public function search()
{
$prm = $this->sys_input;
$max_rst = 25;
$tot_count =0;
$q = [
'search' => '%'
];
if ($prm['search'] != '')
{
$q['search'] = "%{$prm['search']}%";
}
// QUERY TOTAL
$sql = "select count(*) total
from
m_sex
where M_SexIsActive = 'Y'
and M_SexName like ?";
$query = $this->db_smartone->query($sql, array($q['search']));
if ($query) {
$tot_count = $query->result_array()[0]["total"];
}
else {
$this->sys_error_db("m_sex count",$this->db_smartone);
exit;
}
$sql = "select M_SexID, M_SexName, concat('[', group_concat(json_object('M_TitleID', M_TitleID, 'M_TitleName', M_TitleName) separator ','), ']') as title
from m_sex
left join m_title on m_titlem_sexid = m_sexid and m_titleisactive = 'Y'
where M_SexIsActive = 'Y'
and M_SexName like ?
group by m_sexid
limit {$max_rst}";
$query = $this->db_smartone->query($sql, array($q['search']));
if ($query) {
$rows = $query->result_array();
foreach ($rows as $k => $v)
$rows[$k]['title'] = json_decode($v['title']);
$result = array("total" => $tot_count, "records" => $rows, "total_display" => sizeof($rows));
$this->sys_ok($result);
}
else {
$this->sys_error_db("m_sex rows",$this->db_smartone);
exit;
}
}
}

View File

@@ -0,0 +1,71 @@
<?php
class Title extends MY_Controller
{
var $db_smartone;
public function index()
{
echo "Title API";
}
public function __construct()
{
parent::__construct();
$this->db_smartone = $this->load->database("onedev", true);
}
public function search()
{
$prm = $this->sys_input;
$max_rst = 25;
$tot_count =0;
$q = [
'search' => '%',
'sex_id' => 0
];
if ($prm['search'] != '')
$q['search'] = "%{$prm['search']}%";
if ($prm['sex_id'] != '')
$q['sex_id'] = $prm['sex_id'];
// QUERY TOTAL
$sql = "select count(*) total
from
m_title
where M_TitleIsActive = 'Y'
and M_TitleName like ?
and ((M_TitleM_SexID = {$q['sex_id']} and {$q['sex_id']} <> 0) or {$q['sex_id']} = 0)";
$query = $this->db_smartone->query($sql, array($q['search']));
if ($query) {
$tot_count = $query->result_array()[0]["total"];
}
else {
$this->sys_error_db("m_sex count",$this->db_smartone);
exit;
}
$sql = "select M_SexID, M_SexName
from m_sex
where M_SexIsActive = 'Y'
and M_SexName like ?
limit {$max_rst}";
$query = $this->db_smartone->query($sql, array($q['search']));
if ($query) {
$rows = $query->result_array();
$result = array("total" => $tot_count, "records" => $rows, "total_display" => sizeof($rows));
$this->sys_ok($result);
}
else {
$this->sys_error_db("m_sex rows",$this->db_smartone);
exit;
}
}
}

View File

@@ -0,0 +1,135 @@
<?php
class Order extends MY_Controller
{
var $db_smartone;
public function index()
{
echo "ORDER API";
}
public function __construct()
{
parent::__construct();
$this->db_smartone = $this->load->database("clinicdev", true);
}
function save()
{
$prm = $this->sys_input;
$prm['header']['complaint'] = str_replace(PHP_EOL, '<br>', $prm['header']['complaint']);
$prm['header']['suggestion'] = str_replace(PHP_EOL, '<br>', $prm['header']['suggestion']);
$header_json = json_encode($prm['header']);
$header_json = str_replace("\\", "\\\\", "$header_json");
$lab_json = json_encode($prm['lab']);
$med_json = json_encode($prm['med']);
$server = "http";
$uid = $this->sys_user['M_UserID'];
$sql = "CALL sp_clinic_poly_save('{$prm['order_id']}', '{$header_json}', '{$med_json}', '{$lab_json}', '{$uid}');";
$query = $this->db_smartone->query($sql);
$this->clean_mysqli_connection($this->db_smartone->conn_id);
if ($query)
{
$rst = $query->row();
$rst->data = json_decode($rst->data);
if ($rst->data->is_lab == "Y" && $rst->status == "OK")
{
// persiapkan curl
$ch = curl_init();
// set url
global $_SERVER;
$current_host = $_SERVER["SERVER_ADDR"];
if ($server == "https")
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_URL, "{$server}://{$current_host}:9090/ticket/UMUM");
//file_put_contents("/xtmp/url", "{$server}://{$current_host}:9090/ticket/UMUM" );
// return the transfer as a string
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
// $output contains the output string
$output = json_decode(curl_exec($ch));
// tutup curl
curl_close($ch);
// menampilkan hasil curl
// echo $output;
if ($output != null)
if ($output->status == "OK") {
$rst->data->queue = $output->data[0]->number;
$x = json_encode($output->data[0]);
$sql = "CALL sp_clinic_fo_labqueue('{$rst->data->id}', '{$rst->data->queue}', '{$x}');";
$query = $this->db_smartone->query($sql);
}
}
echo json_encode($rst);
}
else
{
$this->sys_error_db("save order", $this->db_smartone);
exit;
}
}
function process()
{
$prm = $this->sys_input;
$sql = "CALL sp_clinic_poly_process('{$prm['order_id']}');";
$query = $this->db_smartone->query($sql);
if ($query)
{
$rst = $query->row();
echo json_encode($rst);
}
else
{
$this->sys_error_db("save order", $this->db_smartone);
exit;
}
}
function get_one()
{
$prm = $this->sys_input;
$sql = "select *
from c_orderheader
where C_OrderHeaderID = ?";
$query = $this->db_smartone->query($sql, array($prm['id']));
if ($query) {
$rows = $query->row();
$rows->C_OrderHeaderQueueJSON = json_decode($rows->C_OrderHeaderQueueJSON);
$result = $rows;
$this->sys_ok($result);
}
else {
$this->sys_error_db("m_patient get",$this->db_smartone);
exit;
}
}
function clean_mysqli_connection( $dbc )
{
while( mysqli_more_results($dbc) )
{
if(mysqli_next_result($dbc))
{
$result = mysqli_use_result($dbc);
unset($result);
}
}
}
}

View File

@@ -0,0 +1,127 @@
<?php
/*
template function {
$this->sys_debug();
try {
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$prm = $this->sys_input;
} catch(Exception $exc) {
$message = $exc->getMessage();
$this->sys_error($message);
}
}
*/
class Patient extends MY_Controller
{
var $db_smartone;
public function index()
{
echo "Patient API";
}
public function __construct()
{
parent::__construct();
$this->db_smartone = $this->load->database("clinicdev", true);
}
public function search()
{
$prm = $this->sys_input;
$max_rst = 12;
$tot_count =0;
$q = [
'nolab' => '%',
'noreg' => '%',
'name' => '%',
'hp' => '%',
'dob' => '%',
'address' => '%',
'status' => 0
];
if ($prm['noreg'] != '')
$q['noreg'] = "%{$prm['noreg']}%";
if ($prm['nolab'] != '')
$q['nolab'] = "%{$prm['nolab']}%";
if ($prm['status'] != '')
$q['status'] = $prm['status'];
if ($prm['search'] != '')
{
$e = explode('+', $prm['search']);
if (isset($e[0]))
$q['name'] = "%{$e[0]}%";
if (isset($e[1]))
$q['hp'] = "%{$e[1]}%";
if (isset($e[2]))
$q['dob'] = "%{$e[2]}%";
if (isset($e[3]))
$q['address'] = "%{$e[3]}%";
}
// QUERY TOTAL
$sql = "select count(*) total
from c_orderheader
join one.m_patient on c_orderheaderm_patientid = m_patientid
join one.m_title on M_PatientM_TitleID = M_TitleID
where C_OrderHeaderNumber like ?
and M_PatientName LIKE ?
and M_PatientHP LIKE ?
and M_PatientDOB LIKE ?
and C_OrderHeaderIsActive = 'Y'
and ((C_OrderHeaderM_StatusID = ? and ? <> 0) or C_OrderHeaderM_StatusID = 0)";
$query = $this->db_smartone->query($sql, array($q['nolab'], $q['name'], $q['hp'], $q['dob'], $q['status'], $q['status']));
if ($query) {
$tot_count = $query->result_array()[0]["total"];
}
else {
$this->sys_error_db("m_patient count",$this->db_smartone);
exit;
}
// set locales
$this->db_smartone->query("SET @@lc_time_names = 'id_ID'");
$sql = "select M_PatientID, M_PatientNoReg,
concat(M_TitleName,' ',M_PatientName) M_PatientName,
M_PatientHP, M_PatientDOB, M_PatientNote, 'X' as M_PatientAddress,
M_PatientNote, C_OrderHeaderID, C_OrderHeaderNumber, M_StatusCode,
C_OrderHeaderM_PatientAge, C_OrderHeaderComplaint, C_OrderHeaderIsLab, C_OrderHeaderIsReceipt,
C_OrderHeaderDate, dayname(C_OrderHeaderDate) `day`
from c_orderheader
join one.m_patient on c_orderheaderm_patientid = m_patientid
join one.m_title on M_PatientM_TitleID = M_TitleID
join m_status on c_orderheaderm_statusid = m_statusid
where C_OrderHeaderNumber like ?
and M_PatientName LIKE ?
and ((M_PatientHP LIKE ? and M_PatientHP IS NOT NULL) OR M_PatientHP IS NULL)
and M_PatientDOB LIKE ?
and C_OrderHeaderIsActive = 'Y'
and ((C_OrderHeaderM_StatusID = ? and ? <> 0) or C_OrderHeaderM_StatusID = 0)
limit 0,{$max_rst}";
$query = $this->db_smartone->query($sql, array($q['nolab'], $q['name'], $q['hp'], $q['dob'], $q['status'], $q['status']));
if ($query) {
$rows = $query->result_array();
$result = array("total" => $tot_count, "records" => $rows, "total_display" => sizeof($rows));
$this->sys_ok($result);
}
else {
$this->sys_error_db("m_patient rows",$this->db_smartone);
exit;
}
}
}

View File

@@ -0,0 +1,67 @@
<?php
class Status extends MY_Controller
{
var $db_smartone;
public function index()
{
echo "STATUS API";
}
public function __construct()
{
parent::__construct();
$this->db_smartone = $this->load->database("clinicdev", true);
}
public function search()
{
$prm = $this->sys_input;
$max_rst = 25;
$tot_count =0;
$q = [
'search' => '%'
];
if ($prm['search'] != '')
{
$q['search'] = "%{$prm['search']}%";
}
// QUERY TOTAL
$sql = "select count(*) total
from
m_status
where M_StatusIsActive = 'Y'
and M_StatusName like ?";
$query = $this->db_smartone->query($sql, array($q['search']));
if ($query) {
$tot_count = $query->result_array()[0]["total"];
}
else {
$this->sys_error_db("m_status count",$this->db_smartone);
exit;
}
$sql = "select M_StatusID, M_StatusName
from m_status
where M_StatusIsActive = 'Y'
and M_StatusName like ?
limit {$max_rst}";
$query = $this->db_smartone->query($sql, array($q['search']));
if ($query) {
$rows = $query->result_array();
// $rows = $rows;
$result = array("total" => $tot_count, "records" => $rows, "total_display" => sizeof($rows));
$this->sys_ok($result);
}
else {
$this->sys_error_db("m_status rows",$this->db_smartone);
exit;
}
}
}

View File

@@ -0,0 +1,97 @@
<?php
/*
### Auth API
- Functions
- login x
- logout
template function {
$this->sys_debug();
try {
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$prm = $this->sys_input;
} catch(Exception $exc) {
$message = $exc->getMessage();
$this->sys_error($message);
}
}
*/
class Auth extends MY_Controller {
var $db_onedev;
public function index()
{
echo "AUTH API";
}
public function __construct()
{
parent::__construct();
$this->db_onedev = $this->load->database("onedev", true);
}
function isLogin() {
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
} else {
$prm = $this->sys_input;
$data = array(
"user" => $this->sys_user
);
$this->sys_ok($data);
}
}
function login() {
$prm = $this->sys_input;
try {
//existing password enc
$sm_password = md5($this->one_salt . $prm["password"] .
$this->one_salt);
$query = $this->db_onedev->query("select M_UserID, M_UserUsername,
M_UserGroupDashboard
from m_user
join m_usergroup on m_userm_usergroupid = m_usergroupid
where M_UserUsername=? and M_UserPassword=?
and M_UserIsActive = 'Y'
",array($prm["username"], $sm_password));
echo $query;
if (!$query) {
$message = $this->db_onedev->error();
$this->sys_error($message);
exit;
}
$rows = $query->result_array();
if (count($rows) > 0 ) {
$user = $rows[0];
$user['M_UserGroupDashboard'] = "https://{$_SERVER['SERVER_NAME']}/{$user['M_UserGroupDashboard']}";
$token = JWT::encode($user,$this->SECRET_KEY);
$data = array(
"user" => $user,
"token" => $token
);
$query = $this->db_onedev->query("update m_user SET M_UserIsLoggedIn = 'Y', M_UserLastAccess = now() WHERE M_UserID = ?
",array($user['M_UserID']));
if (!$query) {
$message = $this->db_onedev->error();
$this->sys_error($message);
exit;
}
$this->sys_ok($data);
exit;
}
$this->sys_error_db("Invalid UserName / Password");
} catch(Exception $exc) {
$message = $exc->getMessage();
$this->sys_error($message);
}
}
function logout() {
$this->sys_error("ok");
}
}
?>

View File

@@ -0,0 +1,134 @@
<?php
class Close extends MY_Controller
{
var $db_onedev;
public function index()
{
echo "Patient API";
}
public function __construct()
{
parent::__construct();
$this->db_onedev = $this->load->database("onedev", true);
}
public function add_notes($orderid){
}
public function search()
{
//# cek token valid
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$prm = $this->sys_input;
$startdate = $prm['startdate'] . " 00:00:01";
$enddate = $prm['enddate'] . " 23:59:59";
$search = $prm["search"];
$status = $prm["status"];
$number_limit = 10;
$number_offset = ($prm['current_page'] - 1) * $number_limit ;
$where = " ( F_PaymentKasirDate BETWEEN '{$startdate}' AND '{$enddate}' ) AND ";
if($search != '')
$where = "( F_PaymentKasirNumber LIKE '%{$search}%') AND ";
$sql = " SELECT count(*) as total
FROM f_payment_kasir
WHERE
$where
( ('{$status}' = 'N' AND (F_PaymentKasirIsReceived = 'N' )) OR ('{$status}' = 'Y' AND F_PaymentKasirIsReceived = 'Y') )";
$query = $this->db_onedev->query($sql, $sql_param);
$tot_count = 0;
$tot_page = 0;
if ($query) {
$tot_count = $query->result_array()[0]["total"];
$tot_page = ceil($tot_count/$number_limit);
} else {
$this->sys_error_db("t_samplestorage count", $this->db_onedev);
exit;
}
$sql = "SELECT F_PaymentKasirID ,
F_PaymentKasirNumber ,
date_format(F_PaymentKasirDate,'%d-%m-%Y %T') as F_PaymentKasirDate ,
F_PaymentKasirCreated ,
F_PaymentKasirLastUpdated ,M_StaffName,
if(F_PaymentKasirIsReceived = 'N','Belum Diterima' ,'Sudah diterima') as F_PaymentKasirIsReceived ,
F_PaymentKasirIsActive
FROM f_payment_kasir
JOIN m_user on F_PaymentKasirUserID = M_UserID
join m_staff on M_UserM_StaffID = M_StaffID
WHERE
$where
( ('{$status}' = 'N' AND (F_PaymentKasirIsReceived = 'N' )) OR ('{$status}' = 'Y' AND F_PaymentKasirIsReceived = 'Y') )
ORDER BY F_PaymentKasirID asc
limit $number_limit offset $number_offset";
//echo $sql;
$query = $this->db_onedev->query($sql, $sql_param);
$rows = $query->result_array();
if($rows){
foreach($rows as $k => $v){
$rows[$k]['notes'] = $this->add_notes($v['F_PaymentKasirID']);
}
}
$result = array("total" => $tot_page, "records" => $rows, "sql"=> $this->db_onedev->last_query());
$this->sys_ok($result);
exit;
}
public function save()
{
//# ambil parameter input
$prm = $this->sys_input;
$puserid = $prm['pUserID'];
$sql = "CALL sp_fo_send_to_cashier({$puserid})";
$query = $this->db_onedev->query($sql);
if ($query) {
$result = array();
$this->sys_ok($result);
}
else {
$this->sys_error_db("payment save rows", $this->db_onedev);
exit;
}
}
public function savetutup()
{
//# ambil parameter input
$prm = $this->sys_input;
$ppaymentkasirid = $prm['pPaymentKasirID'];
$puserid = $prm['pUserID'];
$sql = "CALL sp_fo_received_cashier('{$ppaymentkasirid}','{$puserid}')";
//$sql = "CALL sp_fo_send_to_cashier({$puserid})";
$query = $this->db_onedev->query($sql);
if ($query) {
$result = array();
$this->sys_ok($result);
}
else {
$this->sys_error_db("payment savetutup rows", $this->db_onedev);
exit;
}
}
}

View File

@@ -0,0 +1,144 @@
<?php
class Patient extends MY_Controller
{
var $db_onedev;
public function index()
{
echo "Patient API";
}
public function __construct()
{
parent::__construct();
$this->db_onedev = $this->load->database("onedev", true);
}
public function add_notes($orderid){
$sql = " SELECT F_PaymentT_OrderHeaderID as note_order_id,
F_PaymentID as note_id,
F_PaymentDate as note_date,
F_PaymentNumber as note_number,
GROUP_CONCAT(M_PaymentTypeName separator ' , ') as paymenttypes_name,
SUM(F_PaymentDetailAmount) as note_amount,
M_UserUsername as note_user,
F_PaymentDetailIsActive as note_active
FROM f_payment
JOIN f_paymentdetail ON F_PaymentDetailF_PaymentID = F_PaymentID
JOIN m_paymenttype ON F_PaymentDetailM_PaymentTypeID = M_PaymentTypeID
LEFT JOIN m_user ON F_PaymentDetailUserID = M_UserID
WHERE
F_PaymentT_OrderHeaderID = {$orderid}
GROUP BY F_PaymentID";
$query = $this->db_onedev->query($sql);
if ($query) {
$rows = $query->result_array();
return $rows;
} else {
$this->sys_error_db("get notes", $this->db_onedev);
exit;
}
}
public function search()
{
//# cek token valid
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$prm = $this->sys_input;
$startdate = $prm['startdate'] . " 00:00:01";
$enddate = $prm['enddate'] . " 23:59:59";
$search = $prm["search"];
$status = $prm["status"];
$number_limit = 10;
$number_offset = ($prm['current_page'] - 1) * $number_limit ;
$where = " ( T_OrderHeaderDate BETWEEN '{$startdate}' AND '{$enddate}' ) AND ";
if($search != '')
$where = "( M_PatientName LIKE '%{$search}%' OR T_OrderHeaderLabNumber LIKE '%{$search}%' ) AND ";
$sql = " SELECT count(*) as total
FROM t_orderheader
JOIN m_patient ON T_OrderHeaderM_PatientID = M_PatientID
JOIN m_title ON M_PatientM_TitleID = M_TitleID
JOIN m_sex ON M_PatientM_SexID = M_SexID
JOIN m_company ON T_OrderHeaderM_CompanyID = M_CompanyID
JOIN m_mou ON T_OrderHeaderM_MouID = M_MouID
LEFT JOIN last_statuspayment ON Last_StatusPaymentT_OrderHeaderID = T_OrderHeaderID AND Last_StatusPaymentIsActive = 'Y'
WHERE
$where
( ('{$status}' = 'N' AND (Last_StatusPaymentIsLunas = 'N' OR Last_StatusPaymentID IS NULL)) OR ('{$status}' = 'Y' AND Last_StatusPaymentIsLunas = 'Y') )";
$query = $this->db_onedev->query($sql, $sql_param);
$tot_count = 0;
$tot_page = 0;
if ($query) {
$tot_count = $query->result_array()[0]["total"];
$tot_page = ceil($tot_count/$number_limit);
} else {
$this->sys_error_db("t_samplestorage count", $this->db_onedev);
exit;
}
$janji = T_OrderPromiseDateTime;
$janji_hasil = Date_format($janji, "d-m-Y H:i:s");
$sql = "SELECT t_orderheader.*,T_OrderHeaderIsCito as cito,
M_PatientNoReg,
concat(M_TitleName,'. ',M_PatientName) as M_PatientName,
M_TitleName,
M_CompanyName,
M_MouName,
T_OrderHeaderTotal as totalbill,
IFNULL(Last_StatusPaymentPaid,0) as paid,
IFNULL(Last_StatusPaymentUnpaid,T_OrderHeaderTotal)as unpaid,
Last_StatusPaymentIsLunas as flaglunas,
'' as notes,
M_MouMinDP as mindp_percent,
GROUP_CONCAT(distinct concat(T_OrderDetailT_TestName,'^',T_OrderDetailIsCito) SEPARATOR ',') as test ,
fn_report_promise_list(T_OrderHeaderID) as janji,
(M_MouMinDP/100) * T_OrderHeaderTotal as mindp_amount,
case
when Last_StatusPaymentPaid = '0' then 'BELUM BAYAR'
when Last_StatusPaymentIsLunas = 'Y' then 'LUNAS'
when Last_StatusPaymentIsLunas = 'N' then 'BELUM LUNAS' ELSE '' END as status,
GROUP_CONCAT(distinct M_DeliveryName SEPARATOR ' , ') as delivery
FROM t_orderheader
JOIN m_patient ON T_OrderHeaderM_PatientID = M_PatientID
JOIN m_title ON M_PatientM_TitleID = M_TitleID
JOIN m_sex ON M_PatientM_SexID = M_SexID
JOIN m_company ON T_OrderHeaderM_CompanyID = M_CompanyID
JOIN m_mou ON T_OrderHeaderM_MouID = M_MouID
LEFT JOIN last_statuspayment ON Last_StatusPaymentT_OrderHeaderID = T_OrderHeaderID AND Last_StatusPaymentIsActive = 'Y'
JOIN t_orderdetail on T_OrderDetailT_OrderHeaderID = T_OrderHeaderID AND T_OrderDetailIsActive = 'Y' aND T_OrderDetailT_TestIsPrice = 'Y'
join t_orderpromise on T_OrderPromiseT_OrderHeaderID = T_OrderHeaderID AND T_OrderPromiseIsActive = 'Y'
join t_orderdelivery on T_OrderDeliveryT_OrderHeaderID = T_OrderHeaderID AND T_OrderDeliveryIsActive = 'Y'
join m_delivery on T_OrderDeliveryM_DeliveryID = M_DeliveryID AND M_DeliveryIsActive = 'Y'
WHERE
$where
( ('{$status}' = 'N' AND (Last_StatusPaymentIsLunas = 'N' OR Last_StatusPaymentID IS NULL)) OR ('{$status}' = 'Y' AND Last_StatusPaymentIsLunas = 'Y') )
group by T_OrderHeaderID
ORDER BY `fn_get_cito`(T_OrderHeaderID),T_OrderPromiseDateTime asc
limit $number_limit offset $number_offset";
//echo $sql;
$query = $this->db_onedev->query($sql, $sql_param);
$rows = $query->result_array();
if($rows){
foreach($rows as $k => $v){
$rows[$k]['notes'] = $this->add_notes($v['T_OrderHeaderID']);
}
}
$result = array("total" => $tot_page, "records" => $rows, "sql"=> $this->db_onedev->last_query());
$this->sys_ok($result);
exit;
}
}

View File

@@ -0,0 +1,201 @@
<?php
class Done extends MY_Controller
{
var $db_onedev;
public function index()
{
echo "SampleStorage API";
}
public function __construct()
{
parent::__construct();
$this->db_onedev = $this->load->database("onedev", true);
}
public function search()
{
$prm = $this->sys_input;
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$nolab = $prm["nolab"];
$groupid = $prm["groupid"];
//$subgroupid = $prm["subgroupid"];
$join_group = '';
if($groupid != '0'){
$join_group = "JOIN nat_group ON T_TestNat_GroupID = Nat_GroupID AND Nat_GroupID = {$groupid}";
}
/*$join_subgroup = '';
if($subgroupid != 0){
$join_group = "JOIN nat_subgroup ON T_TestNat_SubgroupID = Nat_SubgroupID AND Nat_SubgroupID = {$subgroupid}";
}*/
if(!isset($prm['current_page']))
$prm['current_page'] = 1;
$sql_where = "WHERE Result_CourierStatus = 'S' AND JSON_CONTAINS(Result_COurierIds,T_OrderDetailID)";
$number_limit = 10;
$number_offset = ($prm['current_page'] - 1) * $number_limit ;
//$sql_param = array();
if ($nolab != "" ) {
if ($sql_where != "") {
$sql_where .=" and ";
}
$sql_where .= " ( T_OrderHeaderLabNumber like '%$nolab%' OR M_PatientName like '%$nolab%' )";
}
/*if ($nama != "") {
if ($sql_where != "") {
$sql_where .=" and ";
}
$sql_where .= " M_PatientName like '%$nama%' ";
}*/
$sql = "SELECT Result_CourierID as xid,
T_OrderHeaderID as orderid,
T_OrderHeaderLabNumber as ordernumber,
UPPER(CONCAT(M_TitleName,' ',M_PatientName)) as patient_fullname,
Result_CourierT_TestName as test_name,
'N' as chex
FROM result_courier
join t_orderheader ON Result_CourierT_OrderHeaderID = T_OrderHeaderID
JOIN t_orderdetail ON T_OrderDetailT_OrderHeaderID = T_OrderHeaderID
JOIN t_test ON T_OrderDetailT_TestID = T_TestID AND JSON_CONTAINS(Result_CourierIds, T_OrderDetailID)
$join_group
JOIN m_patient ON T_OrderHeaderM_PatientID = M_PatientID
JOIN m_sex ON M_PatientM_SexID = M_SexID
LEFT JOIN m_title ON M_PatientM_TitleID = M_TitleID
$sql_where
GROUP BY Result_CourierID
";
//echo $sql;
$query = $this->db_onedev->query($sql);
$rows = $query->result_array();
foreach($rows as $k => $v){
if($v['chex'] == 'N')
$rows[$k]['chex'] = false;
else
$rows[$k]['chex'] = true;
}
$result = array("total" => count($rst), "records" => $rows, "sql"=> '');
$this->sys_ok($result);
exit;
}
function getkerajaan(){
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
//$rst = array(array('id'=>0,'name'=>'Semua'));
$sql = "SELECT 0 as id, 'Semua' as name UNION SELECT Nat_GroupID as id, Nat_GroupName as name FROM nat_group WHERE Nat_GroupIsActive = 'Y'";
$rst_db = $this->db_onedev->query($sql)->result_array();
//$c = array_combine($rst,$rst_db);
$result = array(
"total" => 1 ,
"records" => $rst_db
);
$this->sys_ok($result);
exit;
}
function dosend(){
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$prm = $this->sys_input;
$userid = $this->sys_user['M_UserID'];
$selected = $prm['selected'];
foreach($selected as $k => $v){
$sql = "UPDATE result_frontoffice SET Result_FrontOfficeStatus = 'R' WHERE Result_FrontOfficeID = {$v['xid']}";
$this->db_onedev->query($sql);
}
$result = array(
"total" => 1 ,
"records" => array('status'=>'OK'),
);
$this->sys_ok($result);
exit;
}
function sendemail(){
try {
//# cek token valid
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$prm = $this->sys_input;
$userid = $this->sys_user['M_UserID'];
$rows = array();
$ids = "(".$prm['ids'].")";
$sql = "UPDATE result_sendemail SET Result_SendEmailStatus = 'S', Result_SendEmailUserID = {$userid} WHERE Result_SendEmailID IN {$ids}";
//echo $sql;
$this->db_onedev->query($sql);
$sql = "SELECT * FROM result_sendemail WHERE Result_SendEmailID IN {$ids}";
$dt_rst = $this->db_onedev->query($sql)->result_array();
foreach($dt_rst as $k => $v){
$dt_log = json_encode($v);
$sql = "INSERT INTO one_log.log_resultsendemail (
Log_ResultSendEmailDatetime,
Log_ResultSendEmailJson,
Log_ResultSendEmailUserID
)
VALUES(
NOW(),
'{$dt_log}',
{$userid}
)";
$this->db_onedev->query($sql);
}
$result = array ("total" => 0, "records" => $rows);
$this->sys_ok($result);
} catch(Exception $exc) {
$message = $exc->getMessage();
$this->sys_error($message);
}
}
function updateemail(){
try {
//# cek token valid
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$prm = $this->sys_input;
$userid = $this->sys_user['M_UserID'];
$rows = array();
$id = $prm['id'];
$sql = "UPDATE t_orderdelivery SET T_OrderDeliveryDestination = '{$prm['edited_email']}', T_OrderDeliveryUserID = {$userid} WHERE T_OrderDeliveryID = {$id}";
//echo $sql;
$this->db_onedev->query($sql);
$result = array ("total" => 0, "records" => array());
$this->sys_ok($result);
} catch(Exception $exc) {
$message = $exc->getMessage();
$this->sys_error($message);
}
}
}

View File

@@ -0,0 +1,963 @@
<?php
class Patient extends MY_Controller
{
var $db_onedev;
public function index()
{
echo "Patient API";
}
public function __construct()
{
parent::__construct();
$this->db_onedev = $this->load->database("onedev", true);
}
function add_verifications_label($orderid){
$query = " SELECT Result_VerificationsID as id,
IFNULL(Result_VerificationsValueID,0) as xid,
IFNULL(Result_VerificationsValueCheck,'N') as chex,
IF(ISNULL(Result_VerificationsValueID),'',Result_VerificationsValueNote) as note,
Result_VerificationsLabel as label
FROM result_verifications
LEFT JOIN result_verifications_value ON Result_VerificationsValueResult_VerificationsID = Result_VerificationsID AND
Result_VerificationsValueSo_ResultEntryID = $orderid
WHERE
Result_VerificationIsActive = 'Y'
GROUP BY Result_VerificationsID
";
$rows = $this->db_onedev->query($query)->result_array();
foreach($rows as $k => $v){
if($v['chex'] == 'N')
$rows[$k]['chex'] = false;
else
$rows[$k]['chex'] = true;
}
return $rows;
}
public function search()
{
$prm = $this->sys_input;
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$nolab = $prm["nolab"];
$nama = $prm["name"];
$status = $prm["status"];
$datepromise = $prm["startdate"];
$filter = " AND Result_SendCourierStatus = '{$status}'";
$having = "HAVING not_ready_count = 0";
if($status == 'X'){
$filter = " AND ISNULL(Result_SendCourierID)";
$having = "HAVING not_ready_count > 0";
}
$filter_courier = '';
if($status == 'P' && isset($prm['selected_courier'])){
if(intval($prm['selected_courier']) != 0){
$filter_courier = " AND M_CourierID = {$prm['selected_courier']}";
}
}
if(!isset($prm['current_page']))
$prm['current_page'] = 1;
$sql_where = "WHERE T_OrderDetailIsActive = 'Y' ";
$number_limit = 10;
$number_offset = ($prm['current_page'] - 1) * $number_limit ;
//$sql_param = array();
if ($nolab != "") {
if ($sql_where != "") {
$sql_where .=" and ";
}
$sql_where .= " ( T_OrderHeaderLabNumber like '%$nolab%' AND M_PatientName like '%$nolab%' ) ";
//$prm['current_page'] = 1;
}
$sql = "SELECT COUNT(*) as total
FROM (
SELECT T_OrderHeaderID,
T_OrderPromiseID,
T_OrderHeaderDate,
T_OrderHeaderIsCito as iscito,
M_CompanyName,
T_OrderPromiseDateTime,
T_OrderHeaderLabNumber,
CONCAT(IFNULL(M_TitleName,''),' ',M_PatientName) as patient_fullname,
M_PatientHP as patient_hp,
M_PatientPhotoThumb as photo,
fn_fo_check_status_not_ready_courier(T_OrderHeaderID,T_OrderPromiseID) as not_ready_count
FROM t_orderdetail
JOIN t_orderheader ON T_OrderDetailT_OrderHeaderID = T_OrderHeaderID
JOIN t_orderdelivery ON T_OrderDeliveryT_OrderHeaderID = T_OrderHeaderID AND
T_OrderDeliveryM_DeliveryTypeID = 2 AND
T_OrderDeliveryIsActive = 'Y'
JOIN m_company ON T_OrderHeaderM_CompanyID = M_CompanyID
JOIN m_patient ON T_OrderHeaderM_PatientID = M_PatientID
LEFT JOIN m_title ON M_PatientM_TitleID = M_TitleID
JOIN t_orderpromise ON T_OrderDetailT_OrderPromiseID = T_OrderPromiseID AND T_OrderPromiseDateTime < '{$datepromise} 23:59:59'
LEFT JOIN result_sendcourier ON Result_SendCourierT_OrderHeaderID = T_OrderHeaderID AND
JSON_CONTAINS(Result_SendCourierIds,T_OrderDetailID)
LEFT JOIN result_courierspk_detail ON Result_CourierSPKDetailT_OrderDeliveryID = T_OrderDeliveryID AND
Result_CourierSPKDetailT_OrderPromiseID = T_OrderPromiseID AND Result_CourierSPKDetailIsActive = 'Y' AND
Result_CourierSPKDetailStatus = 'O'
LEFT JOIN result_courierspk ON Result_CourierSPKDetailResult_CourierSPKID = Result_CourierSPKID
LEFT JOIN m_courier ON Result_CourierSPKM_CourierID = M_CourierID $filter_courier
$sql_where $filter
GROUP BY T_OrderHeaderID, T_OrderPromiseID, T_OrderDeliveryID
$having
)x";
// echo $sql;
$query = $this->db_onedev->query($sql);
$tot_count = 0;
$tot_page = 0;
if ($query) {
$tot_count = $query->result_array()[0]["total"];
$tot_page = ceil($tot_count/$number_limit);
} else {
$this->sys_error_db("m_doctor count", $this->db_onedev);
exit;
}
$sql = "SELECT Result_SendCourierID as trx_id,
GROUP_CONCAT(IFNULL(Result_SendCourierID,0) separator ',') as ids,
T_OrderHeaderID,
T_OrderPromiseID,
T_OrderDeliveryID,
T_OrderHeaderDate,
T_OrderHeaderIsCito as iscito,
M_CompanyName,
DATE_FORMAT(T_OrderPromiseDateTime,'%d-%m-%Y %H:%i') as date_promise,
T_OrderHeaderLabNumber,
CONCAT(IFNULL(M_TitleName,''),' ',M_PatientName) as patient_fullname,
M_PatientHP as patient_hp,
M_PatientPhotoThumb as photo,
IFNULL(Result_SendCourierStatus,'X') as status,
fn_fo_check_status_not_ready_courier(T_OrderHeaderID,T_OrderPromiseID) as not_ready_count,
Last_StatusPaymentIsLunas as status_lunas,
M_MouIsBill as status_bill,
'N' as chex,
IFNULL(M_StaffName,'Belum ditentukan') as staff_name
FROM t_orderdetail
JOIN t_orderheader ON T_OrderDetailT_OrderHeaderID = T_OrderHeaderID
JOIN m_mou ON T_OrderHeaderM_MouID = M_MouID
JOIN last_statuspayment ON Last_StatusPaymentT_OrderHeaderID = T_OrderHeaderID
JOIN t_orderdelivery ON T_OrderDeliveryT_OrderHeaderID = T_OrderHeaderID AND
T_OrderDeliveryM_DeliveryTypeID = 2 AND
T_OrderDeliveryIsActive = 'Y'
JOIN m_company ON T_OrderHeaderM_CompanyID = M_CompanyID
JOIN m_patient ON T_OrderHeaderM_PatientID = M_PatientID
LEFT JOIN m_title ON M_PatientM_TitleID = M_TitleID
JOIN t_orderpromise ON T_OrderDetailT_OrderPromiseID = T_OrderPromiseID AND T_OrderPromiseDateTime < '{$datepromise} 23:59:59'
LEFT JOIN result_sendcourier ON Result_SendCourierT_OrderHeaderID = T_OrderHeaderID AND
JSON_CONTAINS(Result_SendCourierIds,T_OrderDetailID)
LEFT JOIN result_courierspk_detail ON Result_CourierSPKDetailT_OrderDeliveryID = T_OrderDeliveryID AND
Result_CourierSPKDetailT_OrderPromiseID = T_OrderPromiseID AND Result_CourierSPKDetailIsActive = 'Y' AND
Result_CourierSPKDetailForceDone = 'N'
LEFT JOIN result_courierspk ON Result_CourierSPKDetailResult_CourierSPKID = Result_CourierSPKID
LEFT JOIN m_courier ON Result_CourierSPKM_CourierID = M_CourierID $filter_courier
LEFT JOIN m_staff ON M_CourierM_StaffID = M_StaffID
$sql_where $filter
GROUP BY T_OrderHeaderID, T_OrderPromiseID, T_OrderDeliveryID
$having
limit $number_limit offset $number_offset";
//echo $sql;
$query = $this->db_onedev->query($sql);
$rows = $query->result_array();
//echo $this->db_onedev->last_query();
if($rows){
foreach($rows as $k => $v){
$rows[$k]['chex'] = false;
}
}
$result = array("total" => $tot_page, "records" => $rows, "sql"=> '');
$this->sys_ok($result);
exit;
}
public function getcourier()
{
$prm = $this->sys_input;
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$nolab = $prm["nolab"];
$nama = $prm["name"];
$status = $prm["status"];
$datepromise = $prm["startdate"];
$filter = " AND Result_SendCourierStatus = '{$status}'";
$having = "HAVING not_ready_count = 0";
if($status == 'X'){
$filter = " AND ISNULL(Result_SendCourierID)";
$having = "HAVING not_ready_count > 0";
}
$sql_where = "WHERE T_OrderDetailIsActive = 'Y' ";
$sql = " SELECT 0 as id, 'Semua' as staff_name, 0 as not_ready_count
UNION
SELECT M_CourierID as id,
M_StaffName as staff_name,
fn_fo_check_status_not_ready_courier(T_OrderHeaderID,T_OrderPromiseID) as not_ready_count
FROM t_orderdetail
JOIN t_orderheader ON T_OrderDetailT_OrderHeaderID = T_OrderHeaderID
JOIN m_mou ON T_OrderHeaderM_MouID = M_MouID
JOIN last_statuspayment ON Last_StatusPaymentT_OrderHeaderID = T_OrderHeaderID
JOIN t_orderdelivery ON T_OrderDeliveryT_OrderHeaderID = T_OrderHeaderID AND
T_OrderDeliveryM_DeliveryTypeID = 2 AND
T_OrderDeliveryIsActive = 'Y'
JOIN m_company ON T_OrderHeaderM_CompanyID = M_CompanyID
JOIN m_patient ON T_OrderHeaderM_PatientID = M_PatientID
LEFT JOIN m_title ON M_PatientM_TitleID = M_TitleID
JOIN t_orderpromise ON T_OrderDetailT_OrderPromiseID = T_OrderPromiseID AND T_OrderPromiseDateTime < '{$datepromise} 23:59:59'
JOIN result_sendcourier ON Result_SendCourierT_OrderHeaderID = T_OrderHeaderID AND
JSON_CONTAINS(Result_SendCourierIds,T_OrderDetailID)
JOIN result_courierspk_detail ON Result_CourierSPKDetailT_OrderDeliveryID = T_OrderDeliveryID AND
Result_CourierSPKDetailT_OrderPromiseID = T_OrderPromiseID AND Result_CourierSPKDetailIsActive = 'Y' AND
Result_CourierSPKDetailStatus = 'O'
JOIN result_courierspk ON Result_CourierSPKDetailResult_CourierSPKID = Result_CourierSPKID
JOIN m_courier ON Result_CourierSPKM_CourierID = M_CourierID
JOIN m_staff ON M_CourierM_StaffID = M_StaffID
$sql_where $filter
GROUP BY M_CourierID
$having";
//echo $sql;
$query = $this->db_onedev->query($sql);
$rows = $query->result_array();
//echo $this->db_onedev->last_query();
$result = array("total" => count($rows), "records" => $rows, "sql"=> '');
$this->sys_ok($result);
exit;
}
public function save()
{
try {
$xprm = $this->sys_input;
//# cek token valid
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$xuserid = $this->sys_user['M_UserID'];
//# ambil parameter input
//print_r($xprm);
$prm = $xprm['patient'];
$xstatus = $xprm['act'];
$fostatusid = 3;
$fologcode = 'FO.VERIFICATION.CONFIRM';
$id = $prm['T_OrderHeaderID'];
echo $xstatus;
if($xstatus == 'N'){
$fostatusid = 4;
$fologcode = 'FO.VERIFICATION.REJECT';
}else{
$this->save_barcode_new($id);
}
//print_r($prm);
$xverificationnote = $prm['verification_note'];
//echo $xverificationnote;
$sql = "update t_orderheader
set
T_OrderHeaderVerificationNote = '{$xverificationnote}'
where
T_OrderHeaderID = $id";
//echo $sql;
$query = $this->db_onedev->query($sql);
/*$xverification_patient = $this->saveverifications($id,$prm['verification_patient'],'PATIENT',$xuserid);
$xverification_doctor = $this->saveverifications($id,$prm['verification_doctor'],'DOCTOR',$xuserid);
$xverification_companymou = $this->saveverifications($id,$prm['verification_companymou'],'COMPANY',$xuserid);
$xverification_payment = $this->saveverifications($id,$prm['verification_payment'],'PAYMENT',$xuserid);
$xverification_info = $this->saveverifications($id,$prm['verification_info'],'INFO',$xuserid);
$xverification_delivery = $this->saveverification_delivery($id,$prm['verification_delivery'],$xuserid);
$xverification_px = $this->saveverification_px($id,$prm['verification_px'],$xuserid);*/
$sql = "insert into fo_status(
Fo_StatusDate,
Fo_StatusT_OrderHeaderID,
Fo_StatusM_StatusID,
Fo_StatusM_UserID,
Fo_StatusCreated,
Fo_StatusUpdated)
values( now(), ?, ?, ?, now(),now())";
//echo $sql;
$query = $this->db_onedev->query($sql,
array(
$id,
$fostatusid,
$xuserid
)
);
if (!$query) {
$this->sys_error_db("fo_status insert");
exit;
}
$data_log = array();
$data_log['orderid'] = $id;
/*$data_log['verification_patient'] = $prm['verification_patient'];
$data_log['verification_doctor'] = $prm['verification_doctor'];
$data_log['verification_companymou'] = $prm['verification_companymou'];
$data_log['verification_payment'] = $prm['verification_payment'];
$data_log['verification_info'] = $prm['verification_info'];
$data_log['verification_px'] = $prm['verification_px'];
$data_log['verification_delivery'] = $prm['verification_delivery'];*/
$json_dt_log = json_encode($data_log);
$sql = "insert into one_log.log_fo(
Log_FoDate,
Log_FoCode,
Log_FoJson,
Log_FoUserID)
values( now(), ?, ?, ?)";
//echo $sql;
$query = $this->db_onedev->query($sql,
array(
$fologcode,
$json_dt_log,
$xuserid
)
);
if (!$query) {
$this->sys_error_db("one_log.fo_log insert");
exit;
}
if($xstatus == 'Y'){
$msg = 'Verifikasi berhasil dilakukan';
}
else{
$msg = 'Tolak Verifikasi berhasil dilakukan';
$sql = "INSERT INTO t_ordermessage (
T_OrderMessageT_OrderHeaderID,
T_OrderMessageType,
T_OrderMessageMessage,
T_OrderMessageFromUserID,
T_OrderMessageCreated,
T_OrderMessageLastUpdated
)
VALUES(
{$id},
'FO.VERIFICATION.REJECT',
'{$xverificationnote}',
{$xuserid},
NOW(),
NOW()
)";
//echo $sql;
$query = $this->db_onedev->query($sql);
if (!$query) {
$this->sys_error_db("one_log.t_ordermessage insert");
exit;
}
}
$rows = array('message'=>$msg);
$result = array ("total" => 0, "records" => $rows);
$this->sys_ok($result);
} catch(Exception $exc) {
$message = $exc->getMessage();
$this->sys_error($message);
}
}
function save_barcode_new($orderid){
$xuserid = $this->sys_user['M_UserID'];
$query =" SELECT T_SampleTypeID as id,
T_SampleTypeName as name,
'' as children
FROM t_orderheader
JOIN t_orderdetail ON T_OrderDetailT_OrderHeaderID = T_OrderHeaderID
JOIN t_test ON T_OrderDetailT_TestID = T_TestID
JOIN t_sampletype ON T_TestT_SampleTypeID = T_SampleTypeID
WHERE
T_OrderHeaderID = {$orderid}
GROUP BY T_SampleTypeID
";
//echo $query ;
$barcodes = $this->db_onedev->query($query)->result();
foreach($barcodes as $k => $v){
$query = "SELECT T_SampleTypeID as id, IFNULL(T_BarcodeLabID,0) as xid,
IF(ISNULL(T_BarcodeLabID),'Y',T_BarcodeLabIsActive) as chex,
T_TestName as testname,
T_SampleTypeName as samplename,
IF(ISNULL(T_BarcodeLabID),CONCAT(T_OrderHeaderLabNumber,'.',T_SampleTypeID,'.',1),T_BarcodeLabBarcode) as barcodenumber
FROM t_orderdetail
JOIN t_orderheader ON T_OrderHeaderID = T_OrderDetailT_OrderHeaderID
JOIN t_test ON T_OrderDetailT_TestID = T_TestID
JOIN t_sampletype ON T_TestT_SampleTypeID = T_SampleTypeID
LEFT JOIN t_barcodelab ON T_BarcodeLabT_OrderHeaderID = T_OrderDetailT_OrderHeaderID AND
T_BarcodeLabT_SampleTypeID = T_TestT_SampleTypeID AND T_BarcodeLabIsActive = 'Y'
WHERE
T_OrderDetailT_OrderHeaderID = {$orderid} AND T_SampleTypeID = {$v->id}
GROUP BY T_BarcodeLabID ";
$v->children = $this->db_onedev->query($query)->result_array();
//$v->children = $barcode_data;
foreach($v->children as $ki => $vi){
if($vi['chex'] == 'N')
$v->children[$ki]['chex'] = false;
else
$v->children[$ki]['chex'] = true;
$sql = "insert into t_barcodelab(
T_BarcodeLabT_OrderHeaderID,
T_BarcodeLabBarcode,
T_BarcodeLabT_SampleTypeID,
T_BarcodeLabCreated,
T_BarcodeLabLastUpdated,
T_BarcodeLabUserID)
values( ?, ?, ?, now(),now(),?)";
$query = $this->db_onedev->query($sql,
array(
$orderid,
$v->children[$ki]['barcodenumber'],
$v->children[$ki]['id'],
$xuserid
)
);
// echo $this->db_onedev->last_query();
if (!$query) {
$this->sys_error_db("t_barcodelab insert");
exit;
}
}
}
//insert log
$supplies = array();
$query =" SELECT M_SuppliesID as id,
IFNULL(T_OrderSuppliesID,0) as xid,
IF(ISNULL(T_OrderSuppliesID),'N',T_OrderSuppliesIsActive) as chex,
IFNULL(T_OrderSuppliesQty,1) as qty,
M_SuppliesName as name,
IF(ISNULL(T_OrderSuppliesID),NOW(),T_OrderSuppliesLastUpdated) as lastupdated,
IF(ISNULL(T_OrderSuppliesID),NOW(),T_OrderSuppliesLastUpdated) as tx_lastupdated
FROM m_supplies
JOIN t_ordersupplies ON T_OrderSuppliesT_OrderHeaderID = $orderid AND T_OrderSuppliesM_SuppliesID = M_SuppliesID
WHERE
M_SuppliesIsActive = 'Y'
";
//echo $query ;
$supplies = $this->db_onedev->query($query)->result_array();
foreach($supplies as $k => $v){
if($v['chex'] == 'N')
$supplies[$k]['chex'] = false;
else
$supplies[$k]['chex'] = true;
}
$dt_log = array('orderid'=>$orderid,'supplies'=>$supplies,'barcode'=>$barcodes);
$fologcode = 'FO.Verification.BarcodeSupplies';
$json_dt_log = json_encode($dt_log);
$sql = "insert into one_log.log_supplies_barcode(
Log_SuppliesBarcodeDate,
Log_SuppliesBarcodeCode,
Log_SuppliesBarcodeJson,
Log_SuppliesBarcodeUserID)
values( now(), ?, ?, ?)";
//echo $sql;
$query = $this->db_onedev->query($sql,
array(
$fologcode,
$json_dt_log,
$xuserid
)
);
if (!$query) {
$this->sys_error_db("one_log.log_supplies_barcode insert");
exit;
}
}
function saveverifications($id,$verifications,$type,$userid)
{
try {
//$xverificationtypeid = $this->db_onedev->query("SELECT * FROM fo_verificationtype WHERE Fo_VerificationTypeGroup = '{$type}' AND Fo_VerificationTypeIsActive = 'Y'")->row()->Fo_VericationTypeID;
//echo $xverificationtypeid;
//print_r($verifications);
foreach($verifications as $k => $v){
//print_r($v);
if(intval($v['xid']) == 0){
$sql = "insert into fo_verification(
Fo_VerificationT_OrderHeaderID,
Fo_VerificationFo_VericationTypeID,
Fo_VerificationIsOK,
Fo_VerificationReason,
Fo_VerificationCreated,
Fo_VerificationLastUpdated,
Fo_VerificationUserID)
values( ?, ?, ?, ?, now(),now(),?)";
//echo $sql;
$query = $this->db_onedev->query($sql,
array(
$id,
$v['id'],
$v['chex'] == true ?'Y':'N',
$v['note'],
$userid
)
);
if (!$query) {
$this->sys_error_db("fo_verification insert");
exit;
}
}
}
return true;
} catch(Exception $exc) {
$message = $exc->getMessage();
$this->sys_error($message);
}
}
function saveverification_delivery($id,$deliveries,$userid)
{
try {
foreach($deliveries as $k => $v){
if($v['id'] === 0){
$sql = "insert into fo_verification_delivery_add(
Fo_VerificationDeliveryAddT_OrderHeaderID,
Fo_VerificationDeliveryAddM_DeliveryID,
Fo_VerificationDeliveryAddM_DeliveryTypeID,
Fo_VerificationDeliveryAddDestination,
Fo_VerificationDeliveryAddAddressID,
Fo_VerificationDeliveryAddM_KelurahanID,
Fo_VerificationDeliveryAddOK,
Fo_VerificationDeliveryAddReason,
Fo_VerificationDeliveryAddCreated,
Fo_VerificationDeliveryAddLastUpdated,
Fo_VerificationDeliveryAddUserID)
values( ?, ?, ?, ?,?,?,?,?, now(),now(),?)";
//echo $sql;
$query = $this->db_onedev->query($sql,
array(
$id,
$v['deliveryid'],
$v['typedeliveryid'],
$v['destination'],
$v['addressid'],
$v['vilageid'],
$v['chex'] == true ?'Y':'N',
$v['note'],
$userid
)
);
if (!$query) {
echo $this->db_onedev->last_query();
$this->sys_error_db("fo_verification_delivery_add insert");
exit;
}
}else{
$sql = "insert into fo_verification_delivery(
Fo_VerificationDeliveryT_OrderHeaderID,
Fo_VerificationDeliveryT_OrderDeliveryID,
Fo_VerificationDeliveryIsOK,
Fo_VerificationDeliveryReason,
Fo_VerificationDeliveryCreated,
Fo_VerificationDeliveryLastUpdated,
Fo_VerificationDeliveryUserID)
values( ?, ?, ?, ?, now(),now(),?)";
//echo $sql;
$query = $this->db_onedev->query($sql,
array(
$id,
$v['id'],
$v['chex'] == true ?'Y':'N',
$v['note'],
$userid
)
);
if (!$query) {
echo $this->db_onedev->last_query();
$this->sys_error_db("fo_verification_delivery insert");
exit;
}
//echo $this->db_onedev->last_query();
}
}
return true;
} catch(Exception $exc) {
$message = $exc->getMessage();
$this->sys_error($message);
}
}
function lookup_barcodes()
{
try {
$prm = $this->sys_input;
//# cek token valid
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$sql = "SELECT T_BarcodeLabID as id, 'barcode' as type,T_BarcodeLabID,T_BarcodeLabBarcode, T_BarcodeLabCounter, T_SampleTypeName, 'N' as chex
FROM t_barcodelab
JOIN t_sampletype ON T_BarcodeLabT_SampleTypeID = T_SampleTypeID
WHERE
T_BarcodeLabT_OrderHeaderID = {$prm['ohid']} AND T_BarcodeLabIsActive = 'Y'
UNION
SELECT T_OrderHeaderID as id, 'formulir' as type, 0,T_OrderHeaderLabNumber as T_BarcodeLabBarcode, 1, 'Formulir' as T_SampleTypeName, 'N' as chex
FROM t_orderheader
WHERE
T_OrderHeaderID = {$prm['ohid']}
";
//echo $sql;
$rows = $this->db_onedev->query($sql)->result_array();
if($rows){
foreach($rows as $k => $v){
if($v['chex'] == 'N')
$rows[$k]['chex'] = false;
else
$rows[$k]['chex'] = true;
}
}
$result = array ("total" => 0, "records" => $rows);
$this->sys_ok($result);
} catch(Exception $exc) {
$message = $exc->getMessage();
$this->sys_error($message);
}
}
function saveverification_px($id,$pxs,$userid)
{
try {
foreach($pxs as $k => $v){
if(intval($v['id']) == 0){
$cxh = $v['chex'] == true ?'Y':'N';
$sql = "insert into fo_verification_test_add(
Fo_VerificationTestAddT_OrderHeaderID,
Fo_VerificationTestAddT_TestID,
Fo_VerificationTestAddBruto,
Fo_VerificationTestAddDiscount,
Fo_VerificationTestAddTotal,
Fo_VerificationTestAddIsOK,
Fo_VerificationTestAddIsCito,
Fo_VerificationTestAddCreated,
Fo_VerificationTestAddLastUpdated,
Fo_VerificationTestAddUserID)
values( $id, {$v['pxid']}, {$v['bruto']}, {$v['discount']},{$v['total']},'{$cxh}','{$v['flagcito']}',now(),now(),{$userid})";
//echo $sql;
$query = $this->db_onedev->query($sql);
//echo $this->db_onedev->last_query();
if (!$query) {
$this->sys_error_db("fo_verification_test_add insert");
exit;
}
}else{
$sql = "insert into fo_verification_test(
Fo_VerificationTestT_OrderHeaderID,
Fo_VerificationTestT_OrderDetailID,
Fo_VerificationTestIsOK,
Fo_VerificationTestReason,
Fo_VerificationTestCreated,
Fo_VerificationTestLastUpdated,
Fo_VerificationTestUserID)
values( ?, ?, ?, ?, now(),now(),?)";
//echo $sql;
$query = $this->db_onedev->query($sql,
array(
$id,
$v['id'],
$v['chex'] == true ?'Y':'N',
$v['note'],
$userid
)
);
//echo $this->db_onedev->last_query();
if (!$query) {
$this->sys_error_db("fo_verification_test insert");
exit;
}
}
}
return true;
} catch(Exception $exc) {
$message = $exc->getMessage();
$this->sys_error($message);
}
}
function verify(){
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$prm = $this->sys_input;
$userid = $this->sys_user["M_UserID"];
$xstatus = $prm['act'];
if($xstatus == 'Y'){
$msg = "Berhasil melakukan verifikasi";
$query =" INSERT INTO result_verifications_value (
Result_VerificationsValueSo_ResultEntryID,
Result_VerificationsValueResult_VerificationsID,
Result_VerificationsValueCheck,
Result_VerificationsValueNote,
Result_VerificationsValueUserID,
Result_VerificationsValueCreated
)
SELECT {$prm['trx_id']},
Result_VerificationsID,
'Y',
'',
{$userid},
NOW()
FROM result_verifications
WHERE
Result_VerificationIsActive = 'Y'
ON DUPLICATE KEY UPDATE
Result_VerificationsValueCheck = 'Y',
Result_VerificationsValueNote = '',
Result_VerificationsValueUserID = {$userid},
Result_VerificationsValueLastUpdated = NOW()
";
//echo $query;
$this->db_onedev->query($query);
$sql = "UPDATE so_resultentry SET So_ResultEntryStatus = 'VAL2' , So_ResultEntryValidation2 = 'Y' WHERE So_ResultEntryID = {$prm['trx_id']}";
$this->db_onedev->query($sql);
}
else{
$msg = "Tolak untuk perbaikan";
$verifications = $prm['verifications'];
foreach($verifications as $k => $v){
$chx = $v['chex'] == true ?'Y':'N';
$query =" INSERT INTO result_verifications_value (
Result_VerificationsValueSo_ResultEntryID,
Result_VerificationsValueResult_VerificationsID,
Result_VerificationsValueCheck,
Result_VerificationsValueNote,
Result_VerificationsValueUserID,
Result_VerificationsValueCreated
)
values( {$prm['trx_id']},
{$v['id']},
'{$chx}',
'{$v['note']}',
{$userid},
NOW()
)
ON DUPLICATE KEY UPDATE
Result_VerificationsValueCheck = '{$chx}',
Result_VerificationsValueNote = '{$v['note']}',
Result_VerificationsValueUserID = {$userid},
Result_VerificationsValueLastUpdated = NOW()
";
//echo $query;
$this->db_onedev->query($query);
}
}
$result = array ("total" => 0, "records" => array('status'=>'OK','message'=>$msg));
$this->sys_ok($result);
}
public function getstatuspergroup()
{
try {
//# cek token valid
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$prm = $this->sys_input;
$rows = array();
$sql =" SELECT Last_StatusPaymentBillTotal as total_bill,
Last_StatusPaymentPaid as paid,
Last_StatusPaymentUnpaid as unpaid,
Last_StatusPaymentIsLunas as status
FROM last_statuspayment
WHERE
Last_StatusPaymentT_OrderHeaderID = {$prm['T_OrderHeaderID']} ";
$rows['info_bill'] = $this->db_onedev->query($sql)->row_array();
$sql =" SELECT T_OrderDeliveryID as id,
IFNULL(Fo_VerificationDeliveryID,0) as xid,
M_DeliveryTypeCode as code,
IF(ISNULL(Fo_VerificationDeliveryID),'N',Fo_VerificationDeliveryIsOK) as chex,
M_DeliveryID as deliveryid,
M_DeliveryTypeID as typedeliveryid,
T_OrderDeliveryM_KelurahanID as vilageid,
IF(ISNULL(Fo_VerificationDeliveryID),'',Fo_VerificationDeliveryReason) as note,
'reguler' as type,
CASE
WHEN T_OrderDeliveryM_DeliveryID = 1 THEN M_DeliveryName
WHEN T_OrderDeliveryM_DeliveryID = 4 THEN CONCAT(M_DeliveryName)
WHEN T_OrderDeliveryM_DeliveryID = 2 THEN CONCAT(M_DeliveryName)
WHEN ( T_OrderDeliveryM_DeliveryID = 7 OR T_OrderDeliveryM_DeliveryID = 9 ) THEN CONCAT(M_DeliveryName)
WHEN ( T_OrderDeliveryM_DeliveryID = 6 OR T_OrderDeliveryM_DeliveryID = 8 ) THEN CONCAT(M_DeliveryName)
ELSE
CONCAT(M_DeliveryName)
END as label,
CASE
WHEN T_OrderDeliveryM_DeliveryID = 1 THEN ''
WHEN T_OrderDeliveryM_DeliveryID = 4 THEN M_DoctorAddressDescription
WHEN T_OrderDeliveryM_DeliveryID = 2 THEN M_PatientAddressDescription
WHEN ( T_OrderDeliveryM_DeliveryID = 7 OR T_OrderDeliveryM_DeliveryID = 9 ) THEN M_DoctorHP
WHEN ( T_OrderDeliveryM_DeliveryID = 6 OR T_OrderDeliveryM_DeliveryID = 8 ) THEN M_PatientHP
ELSE
T_OrderDeliveryDestination
END as destination,
CASE
WHEN T_OrderDeliveryM_DeliveryID = 4 THEN M_DoctorAddressID
WHEN T_OrderDeliveryM_DeliveryID = 2 THEN M_PatientAddressID
ELSE
0
END as addressid
FROM t_orderdelivery
JOIN t_orderheader ON T_OrderDeliveryT_OrderHeaderID = T_OrderHeaderID
JOIN m_delivery ON T_OrderDeliveryM_DeliveryID = M_DeliveryID
JOIN m_deliverytype ON T_OrderDeliveryM_DeliveryTypeID = M_DeliveryTypeID
LEFT JOIN m_doctoraddress ON T_OrderDeliveryAddressID = M_DoctorAddressID AND T_OrderDeliveryM_DeliveryID = 4
LEFT JOIN m_patientaddress ON T_OrderDeliveryAddressID = M_PatientAddressID AND T_OrderDeliveryM_DeliveryID = 2
LEFT JOIN fo_verification_delivery ON Fo_VerificationDeliveryT_OrderHeaderID = T_OrderDeliveryT_OrderHeaderID AND Fo_VerificationDeliveryIsActive = 'Y'
LEFT JOIN m_doctor ON T_OrderHeaderSenderM_DoctorID = M_DoctorID AND ( T_OrderDeliveryM_DeliveryID = 7 OR T_OrderDeliveryM_DeliveryID = 9 )
LEFT JOIN m_patient ON T_OrderHeaderM_PatientID = M_PatientID AND ( T_OrderDeliveryM_DeliveryID = 6 OR T_OrderDeliveryM_DeliveryID = 8 )
WHERE
T_OrderDeliveryT_OrderHeaderID = {$prm['T_OrderHeaderID']} AND T_OrderDeliveryID = {$prm['T_OrderDeliveryID']} AND T_OrderDeliveryIsActive = 'Y'
GROUP BY T_OrderDeliveryID
";
//echo $query ;
$rows['info_deliveries'] = $this->db_onedev->query($sql)->result_array();
$sql = "
SELECT T_OrderHeaderID,
T_OrderPromiseID,
T_OrderPromiseDateTime,
T_OrderHeaderLabNumber,
UPPER(DocumentationGroupName) as DocumentationGroupName,
GROUP_CONCAT(DISTINCT CONCAT(T_TestName,'^',IFNULL(Result_SendCourierStatus,'X'))) as status_test_name,
GROUP_CONCAT(IFNULL(Result_SendCourierStatus,'X')) as status,
'' as status_pergroup,
'' as details
FROM t_orderdetail
JOIN t_orderheader ON T_OrderDetailT_OrderHeaderID = T_OrderHeaderID
JOIN t_orderpromise ON T_OrderDetailT_OrderPromiseID = T_OrderPromiseID
JOIN t_test ON T_OrderDetailT_TestID = T_TestID AND T_TestIsResult = 'Y'
LEFT JOIN result_sendcourier ON Result_SendCourierT_OrderHeaderID = T_OrderHeaderID AND
JSON_CONTAINS(Result_SendCourierIds,T_OrderDetailID)
JOIN documentation_group_detail ON DocumentationGroupDetailNat_SubGroupID = T_TestNat_SubGroupID
JOIN documentation_group ON DocumentationGroupDetailDocumentationGroupID = DocumentationGroupID
WHERE
T_OrderHeaderID = {$prm['T_OrderHeaderID']} AND T_OrderPromiseID = {$prm['T_OrderPromiseID']} AND T_OrderDetailIsActive = 'Y'
GROUP BY DocumentationGroupID
";
$rows['info_test'] = $this->db_onedev->query($sql)->result_array();
if($rows['info_test']){
foreach($rows['info_test'] as $k => $v){
$rows['info_test'][$k]['status_pergroup'] = 'R';
$x_arr = explode(',',$v['status']);
if(in_array('X',$x_arr)){
$rows['info_test'][$k]['status_pergroup'] = 'X';
}
if($v['DocumentationGroupName'] != 'LAB'){
$z_arr = explode(',',$v['status_test_name']);
$for_details = array();
foreach($z_arr as $i => $val){
$xx_arr = explode('^',$val);
array_push($for_details,array('testname'=>$xx_arr[0],'status'=>$xx_arr[1]));
}
$rows['info_test'][$k]['details'] = $for_details;
}
else{
$rows['info_test'][$k]['DocumentationGroupName'] = 'Laboratorium';
$rows['info_test'][$k]['details'] = array(array('testname'=>'Pemeriksaan Laboratorium','status'=>$rows['info_test'][$k]['status_pergroup']));
}
}
}
$result = array ("total" => 0, "records" => $rows);
$this->sys_ok($result);
} catch(Exception $exc) {
$message = $exc->getMessage();
$this->sys_error($message);
}
}
function receivedbycourier(){
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$prm = $this->sys_input;
$userid = $this->sys_user["M_UserID"];
$datas = $prm['selected'];
foreach($datas as $k => $v){
$sql = "SELECT result_sendcourier.*
FROM t_orderdetail
JOIN t_orderpromise ON T_OrderDetailT_OrderPromiseID = T_OrderPromiseID AND T_OrderPromiseID = {$v['T_OrderPromiseID']}
JOIN result_sendcourier ON Result_SendCourierT_OrderHeaderID = {$v['T_OrderHeaderID']} AND Result_SendCourierStatus = 'P' AND
JSON_CONTAINS(Result_SendCourierIds,T_OrderDetailID)
JOIN t_orderdelivery ON T_OrderDetailT_OrderHeaderID = Result_SendCourierT_OrderHeaderID AND T_OrderDeliveryID = {$v['T_OrderDeliveryID']}";
//echo $sql;
$data_going_save = $this->db_onedev->query($sql)->result_array();
foreach($data_going_save as $i => $val){
$sql = "UPDATE result_sendcourier SET Result_SendCourierStatus = 'S', Result_SendCourierUserID = {$userid}
WHERE
Result_SendCourierID = {$val['Result_SendCourierID']}";
$this->db_onedev->query($sql);
}
$sql = "UPDATE result_courierspk_detail SET Result_CourierSPKDetailStatus = 'S', Result_CourierSPKDetailsUserID = {$userid}
WHERE
Result_CourierSPKDetailT_OrderDeliveryID = {$v['T_OrderDeliveryID']} AND
Result_CourierSPKDetailT_OrderPromiseID = {$v['T_OrderPromiseID']}
";
$this->db_onedev->query($sql);
}
$result = array ("total" => 0, "records" => array('status'=>'OK','message'=>''));
$this->sys_ok($result);
}
}

View File

@@ -0,0 +1,201 @@
<?php
class Done extends MY_Controller
{
var $db_onedev;
public function index()
{
echo "SampleStorage API";
}
public function __construct()
{
parent::__construct();
$this->db_onedev = $this->load->database("onedev", true);
}
public function search()
{
$prm = $this->sys_input;
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$nolab = $prm["nolab"];
$groupid = $prm["groupid"];
//$subgroupid = $prm["subgroupid"];
$join_group = '';
if($groupid != '0'){
$join_group = "JOIN nat_group ON T_TestNat_GroupID = Nat_GroupID AND Nat_GroupID = {$groupid}";
}
/*$join_subgroup = '';
if($subgroupid != 0){
$join_group = "JOIN nat_subgroup ON T_TestNat_SubgroupID = Nat_SubgroupID AND Nat_SubgroupID = {$subgroupid}";
}*/
if(!isset($prm['current_page']))
$prm['current_page'] = 1;
$sql_where = "WHERE Result_FrontOfficeStatus = 'S' AND JSON_CONTAINS(Result_FrontOfficeIds,T_OrderDetailID)";
$number_limit = 10;
$number_offset = ($prm['current_page'] - 1) * $number_limit ;
//$sql_param = array();
if ($nolab != "" ) {
if ($sql_where != "") {
$sql_where .=" and ";
}
$sql_where .= " ( T_OrderHeaderLabNumber like '%$nolab%' OR M_PatientName like '%$nolab%' )";
}
/*if ($nama != "") {
if ($sql_where != "") {
$sql_where .=" and ";
}
$sql_where .= " M_PatientName like '%$nama%' ";
}*/
$sql = "SELECT Result_FrontOfficeID as xid,
T_OrderHeaderID as orderid,
T_OrderHeaderLabNumber as ordernumber,
UPPER(CONCAT(M_TitleName,' ',M_PatientName)) as patient_fullname,
Result_FrontOfficeTestName as test_name,
'N' as chex
FROM result_frontoffice
join t_orderheader ON Result_FrontOfficeT_OrderHeaderID = T_OrderHeaderID
JOIN t_orderdetail ON T_OrderDetailT_OrderHeaderID = T_OrderHeaderID
JOIN t_test ON T_OrderDetailT_TestID = T_TestID AND JSON_CONTAINS(Result_FrontOfficeIds, T_OrderDetailID)
$join_group
JOIN m_patient ON T_OrderHeaderM_PatientID = M_PatientID
JOIN m_sex ON M_PatientM_SexID = M_SexID
LEFT JOIN m_title ON M_PatientM_TitleID = M_TitleID
$sql_where
GROUP BY Result_FrontOfficeID
";
$query = $this->db_onedev->query($sql);
$rows = $query->result_array();
foreach($rows as $k => $v){
if($v['chex'] == 'N')
$rows[$k]['chex'] = false;
else
$rows[$k]['chex'] = true;
}
$result = array("total" => count($rst), "records" => $rows, "sql"=> '');
$this->sys_ok($result);
exit;
}
function getkerajaan(){
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
//$rst = array(array('id'=>0,'name'=>'Semua'));
$sql = "SELECT 0 as id, 'Semua' as name UNION SELECT Nat_GroupID as id, Nat_GroupName as name FROM nat_group WHERE Nat_GroupIsActive = 'Y'";
$rst_db = $this->db_onedev->query($sql)->result_array();
//$c = array_combine($rst,$rst_db);
$result = array(
"total" => 1 ,
"records" => $rst_db
);
$this->sys_ok($result);
exit;
}
function dosend(){
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$prm = $this->sys_input;
$userid = $this->sys_user['M_UserID'];
$selected = $prm['selected'];
foreach($selected as $k => $v){
$sql = "UPDATE result_frontoffice SET Result_FrontOfficeStatus = 'R' WHERE Result_FrontOfficeID = {$v['xid']}";
$this->db_onedev->query($sql);
}
$result = array(
"total" => 1 ,
"records" => array('status'=>'OK'),
);
$this->sys_ok($result);
exit;
}
function sendemail(){
try {
//# cek token valid
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$prm = $this->sys_input;
$userid = $this->sys_user['M_UserID'];
$rows = array();
$ids = "(".$prm['ids'].")";
$sql = "UPDATE result_sendemail SET Result_SendEmailStatus = 'S', Result_SendEmailUserID = {$userid} WHERE Result_SendEmailID IN {$ids}";
//echo $sql;
$this->db_onedev->query($sql);
$sql = "SELECT * FROM result_sendemail WHERE Result_SendEmailID IN {$ids}";
$dt_rst = $this->db_onedev->query($sql)->result_array();
foreach($dt_rst as $k => $v){
$dt_log = json_encode($v);
$sql = "INSERT INTO one_log.log_resultsendemail (
Log_ResultSendEmailDatetime,
Log_ResultSendEmailJson,
Log_ResultSendEmailUserID
)
VALUES(
NOW(),
'{$dt_log}',
{$userid}
)";
$this->db_onedev->query($sql);
}
$result = array ("total" => 0, "records" => $rows);
$this->sys_ok($result);
} catch(Exception $exc) {
$message = $exc->getMessage();
$this->sys_error($message);
}
}
function updateemail(){
try {
//# cek token valid
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$prm = $this->sys_input;
$userid = $this->sys_user['M_UserID'];
$rows = array();
$id = $prm['id'];
$sql = "UPDATE t_orderdelivery SET T_OrderDeliveryDestination = '{$prm['edited_email']}', T_OrderDeliveryUserID = {$userid} WHERE T_OrderDeliveryID = {$id}";
//echo $sql;
$this->db_onedev->query($sql);
$result = array ("total" => 0, "records" => array());
$this->sys_ok($result);
} catch(Exception $exc) {
$message = $exc->getMessage();
$this->sys_error($message);
}
}
}

View File

@@ -0,0 +1,848 @@
<?php
class Patient extends MY_Controller
{
var $db_onedev;
public function index()
{
echo "Patient API";
}
public function __construct()
{
parent::__construct();
$this->db_onedev = $this->load->database("onedev", true);
}
function add_verifications_label($orderid){
$query = " SELECT Result_VerificationsID as id,
IFNULL(Result_VerificationsValueID,0) as xid,
IFNULL(Result_VerificationsValueCheck,'N') as chex,
IF(ISNULL(Result_VerificationsValueID),'',Result_VerificationsValueNote) as note,
Result_VerificationsLabel as label
FROM result_verifications
LEFT JOIN result_verifications_value ON Result_VerificationsValueResult_VerificationsID = Result_VerificationsID AND
Result_VerificationsValueSo_ResultEntryID = $orderid
WHERE
Result_VerificationIsActive = 'Y'
GROUP BY Result_VerificationsID
";
$rows = $this->db_onedev->query($query)->result_array();
foreach($rows as $k => $v){
if($v['chex'] == 'N')
$rows[$k]['chex'] = false;
else
$rows[$k]['chex'] = true;
}
return $rows;
}
public function search()
{
$prm = $this->sys_input;
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$nolab = $prm["nolab"];
$nama = $prm["name"];
$status = $prm["status"];
$datepromise = $prm["startdate"];
$filter = " AND Result_SendEmailStatus = '{$status}'";
$having = "HAVING not_ready_count = 0";
if($status == 'X'){
$filter = " AND ISNULL(Result_SendEmailID)";
$having = "HAVING not_ready_count > 0";
}
if($status == 'P')
$filter .= " AND Result_SendEmailActionBy = 'MANUAL'";
if(!isset($prm['current_page']))
$prm['current_page'] = 1;
$sql_where = "WHERE T_OrderDetailIsActive = 'Y' ";
$number_limit = 10;
$number_offset = ($prm['current_page'] - 1) * $number_limit ;
//$sql_param = array();
if ($nolab != "") {
if ($sql_where != "") {
$sql_where .=" and ";
}
$sql_where .= " ( T_OrderHeaderLabNumber like '%$nolab%' AND M_PatientName like '%$nolab%' ) ";
//$prm['current_page'] = 1;
}
$sql = "SELECT COUNT(*) as total
FROM (
SELECT T_OrderHeaderID,
T_OrderPromiseID,
T_OrderHeaderDate,
T_OrderHeaderIsCito as iscito,
M_CompanyName,
T_OrderPromiseDateTime,
T_OrderHeaderLabNumber,
CONCAT(IFNULL(M_TitleName,''),' ',M_PatientName) as patient_fullname,
M_PatientHP as patient_hp,
M_PatientPhotoThumb as photo,
fn_fo_check_status_not_ready_email(T_OrderHeaderID,T_OrderPromiseID) as not_ready_count
FROM t_orderdetail
JOIN t_orderheader ON T_OrderDetailT_OrderHeaderID = T_OrderHeaderID
JOIN t_orderdelivery ON T_OrderDeliveryT_OrderHeaderID = T_OrderHeaderID AND
T_OrderDeliveryM_DeliveryTypeID = 3 AND
T_OrderDeliveryIsActive = 'Y'
JOIN m_company ON T_OrderHeaderM_CompanyID = M_CompanyID
JOIN m_patient ON T_OrderHeaderM_PatientID = M_PatientID
LEFT JOIN m_title ON M_PatientM_TitleID = M_TitleID
JOIN t_orderpromise ON T_OrderDetailT_OrderPromiseID = T_OrderPromiseID AND T_OrderPromiseDateTime < '{$datepromise} 23:59:59'
LEFT JOIN result_sendemail ON Result_SendEmailT_OrderHeaderID = T_OrderHeaderID AND
JSON_CONTAINS(Result_SendEmailIds,T_OrderDetailID)
$sql_where $filter
GROUP BY T_OrderHeaderID, T_OrderPromiseID, T_OrderDeliveryID
$having
)x";
//echo $sql;
$query = $this->db_onedev->query($sql);
$tot_count = 0;
$tot_page = 0;
if ($query) {
$tot_count = $query->result_array()[0]["total"];
$tot_page = ceil($tot_count/$number_limit);
} else {
$this->sys_error_db("m_doctor count", $this->db_onedev);
exit;
}
$sql = "SELECT GROUP_CONCAT(IFNULL(Result_SendEmailID,0) separator ',') as ids,
T_OrderHeaderID,
T_OrderPromiseID,
T_OrderHeaderDate,
T_OrderHeaderIsCito as iscito,
M_CompanyName,
DATE_FORMAT(T_OrderPromiseDateTime,'%d-%m-%Y %H:%i') as date_promise,
T_OrderHeaderLabNumber,
CONCAT(IFNULL(M_TitleName,''),' ',M_PatientName) as patient_fullname,
M_PatientHP as patient_hp,
M_PatientPhotoThumb as photo,
IFNULL(Result_SendEmailStatus,'X') as status,
fn_fo_check_status_not_ready_email(T_OrderHeaderID,T_OrderPromiseID) as not_ready_count,
Last_StatusPaymentIsLunas as status_lunas,
M_MouIsBill as status_bill
FROM t_orderdetail
JOIN t_orderheader ON T_OrderDetailT_OrderHeaderID = T_OrderHeaderID
JOIN m_mou ON T_OrderHeaderM_MouID = M_MouID
JOIN last_statuspayment ON Last_StatusPaymentT_OrderHeaderID = T_OrderHeaderID
JOIN t_orderdelivery ON T_OrderDeliveryT_OrderHeaderID = T_OrderHeaderID AND
T_OrderDeliveryM_DeliveryTypeID = 3 AND
T_OrderDeliveryIsActive = 'Y'
JOIN m_company ON T_OrderHeaderM_CompanyID = M_CompanyID
JOIN m_patient ON T_OrderHeaderM_PatientID = M_PatientID
LEFT JOIN m_title ON M_PatientM_TitleID = M_TitleID
JOIN t_orderpromise ON T_OrderDetailT_OrderPromiseID = T_OrderPromiseID AND T_OrderPromiseDateTime < '{$datepromise} 23:59:59'
LEFT JOIN result_sendemail ON Result_SendEmailT_OrderHeaderID = T_OrderHeaderID AND
JSON_CONTAINS(Result_SendEmailIds,T_OrderDetailID)
$sql_where $filter
GROUP BY T_OrderHeaderID, T_OrderPromiseID, T_OrderDeliveryID
$having
limit $number_limit offset $number_offset";
//echo $sql;
$query = $this->db_onedev->query($sql);
$rows = $query->result_array();
//echo $this->db_onedev->last_query();
if($rows){
/*foreach($rows as $k => $v){
$rows[$k]['verifications'] = $this->add_verifications_label($v['trx_id']);
}*/
}
$result = array("total" => $tot_page, "records" => $rows, "sql"=> '');
$this->sys_ok($result);
exit;
}
public function save()
{
try {
$xprm = $this->sys_input;
//# cek token valid
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$xuserid = $this->sys_user['M_UserID'];
//# ambil parameter input
//print_r($xprm);
$prm = $xprm['patient'];
$xstatus = $xprm['act'];
$fostatusid = 3;
$fologcode = 'FO.VERIFICATION.CONFIRM';
$id = $prm['T_OrderHeaderID'];
echo $xstatus;
if($xstatus == 'N'){
$fostatusid = 4;
$fologcode = 'FO.VERIFICATION.REJECT';
}else{
$this->save_barcode_new($id);
}
//print_r($prm);
$xverificationnote = $prm['verification_note'];
//echo $xverificationnote;
$sql = "update t_orderheader
set
T_OrderHeaderVerificationNote = '{$xverificationnote}'
where
T_OrderHeaderID = $id";
//echo $sql;
$query = $this->db_onedev->query($sql);
/*$xverification_patient = $this->saveverifications($id,$prm['verification_patient'],'PATIENT',$xuserid);
$xverification_doctor = $this->saveverifications($id,$prm['verification_doctor'],'DOCTOR',$xuserid);
$xverification_companymou = $this->saveverifications($id,$prm['verification_companymou'],'COMPANY',$xuserid);
$xverification_payment = $this->saveverifications($id,$prm['verification_payment'],'PAYMENT',$xuserid);
$xverification_info = $this->saveverifications($id,$prm['verification_info'],'INFO',$xuserid);
$xverification_delivery = $this->saveverification_delivery($id,$prm['verification_delivery'],$xuserid);
$xverification_px = $this->saveverification_px($id,$prm['verification_px'],$xuserid);*/
$sql = "insert into fo_status(
Fo_StatusDate,
Fo_StatusT_OrderHeaderID,
Fo_StatusM_StatusID,
Fo_StatusM_UserID,
Fo_StatusCreated,
Fo_StatusUpdated)
values( now(), ?, ?, ?, now(),now())";
//echo $sql;
$query = $this->db_onedev->query($sql,
array(
$id,
$fostatusid,
$xuserid
)
);
if (!$query) {
$this->sys_error_db("fo_status insert");
exit;
}
$data_log = array();
$data_log['orderid'] = $id;
/*$data_log['verification_patient'] = $prm['verification_patient'];
$data_log['verification_doctor'] = $prm['verification_doctor'];
$data_log['verification_companymou'] = $prm['verification_companymou'];
$data_log['verification_payment'] = $prm['verification_payment'];
$data_log['verification_info'] = $prm['verification_info'];
$data_log['verification_px'] = $prm['verification_px'];
$data_log['verification_delivery'] = $prm['verification_delivery'];*/
$json_dt_log = json_encode($data_log);
$sql = "insert into one_log.log_fo(
Log_FoDate,
Log_FoCode,
Log_FoJson,
Log_FoUserID)
values( now(), ?, ?, ?)";
//echo $sql;
$query = $this->db_onedev->query($sql,
array(
$fologcode,
$json_dt_log,
$xuserid
)
);
if (!$query) {
$this->sys_error_db("one_log.fo_log insert");
exit;
}
if($xstatus == 'Y'){
$msg = 'Verifikasi berhasil dilakukan';
}
else{
$msg = 'Tolak Verifikasi berhasil dilakukan';
$sql = "INSERT INTO t_ordermessage (
T_OrderMessageT_OrderHeaderID,
T_OrderMessageType,
T_OrderMessageMessage,
T_OrderMessageFromUserID,
T_OrderMessageCreated,
T_OrderMessageLastUpdated
)
VALUES(
{$id},
'FO.VERIFICATION.REJECT',
'{$xverificationnote}',
{$xuserid},
NOW(),
NOW()
)";
//echo $sql;
$query = $this->db_onedev->query($sql);
if (!$query) {
$this->sys_error_db("one_log.t_ordermessage insert");
exit;
}
}
$rows = array('message'=>$msg);
$result = array ("total" => 0, "records" => $rows);
$this->sys_ok($result);
} catch(Exception $exc) {
$message = $exc->getMessage();
$this->sys_error($message);
}
}
function save_barcode_new($orderid){
$xuserid = $this->sys_user['M_UserID'];
$query =" SELECT T_SampleTypeID as id,
T_SampleTypeName as name,
'' as children
FROM t_orderheader
JOIN t_orderdetail ON T_OrderDetailT_OrderHeaderID = T_OrderHeaderID
JOIN t_test ON T_OrderDetailT_TestID = T_TestID
JOIN t_sampletype ON T_TestT_SampleTypeID = T_SampleTypeID
WHERE
T_OrderHeaderID = {$orderid}
GROUP BY T_SampleTypeID
";
//echo $query ;
$barcodes = $this->db_onedev->query($query)->result();
foreach($barcodes as $k => $v){
$query = "SELECT T_SampleTypeID as id, IFNULL(T_BarcodeLabID,0) as xid,
IF(ISNULL(T_BarcodeLabID),'Y',T_BarcodeLabIsActive) as chex,
T_TestName as testname,
T_SampleTypeName as samplename,
IF(ISNULL(T_BarcodeLabID),CONCAT(T_OrderHeaderLabNumber,'.',T_SampleTypeID,'.',1),T_BarcodeLabBarcode) as barcodenumber
FROM t_orderdetail
JOIN t_orderheader ON T_OrderHeaderID = T_OrderDetailT_OrderHeaderID
JOIN t_test ON T_OrderDetailT_TestID = T_TestID
JOIN t_sampletype ON T_TestT_SampleTypeID = T_SampleTypeID
LEFT JOIN t_barcodelab ON T_BarcodeLabT_OrderHeaderID = T_OrderDetailT_OrderHeaderID AND
T_BarcodeLabT_SampleTypeID = T_TestT_SampleTypeID AND T_BarcodeLabIsActive = 'Y'
WHERE
T_OrderDetailT_OrderHeaderID = {$orderid} AND T_SampleTypeID = {$v->id}
GROUP BY T_BarcodeLabID ";
$v->children = $this->db_onedev->query($query)->result_array();
//$v->children = $barcode_data;
foreach($v->children as $ki => $vi){
if($vi['chex'] == 'N')
$v->children[$ki]['chex'] = false;
else
$v->children[$ki]['chex'] = true;
$sql = "insert into t_barcodelab(
T_BarcodeLabT_OrderHeaderID,
T_BarcodeLabBarcode,
T_BarcodeLabT_SampleTypeID,
T_BarcodeLabCreated,
T_BarcodeLabLastUpdated,
T_BarcodeLabUserID)
values( ?, ?, ?, now(),now(),?)";
$query = $this->db_onedev->query($sql,
array(
$orderid,
$v->children[$ki]['barcodenumber'],
$v->children[$ki]['id'],
$xuserid
)
);
// echo $this->db_onedev->last_query();
if (!$query) {
$this->sys_error_db("t_barcodelab insert");
exit;
}
}
}
//insert log
$supplies = array();
$query =" SELECT M_SuppliesID as id,
IFNULL(T_OrderSuppliesID,0) as xid,
IF(ISNULL(T_OrderSuppliesID),'N',T_OrderSuppliesIsActive) as chex,
IFNULL(T_OrderSuppliesQty,1) as qty,
M_SuppliesName as name,
IF(ISNULL(T_OrderSuppliesID),NOW(),T_OrderSuppliesLastUpdated) as lastupdated,
IF(ISNULL(T_OrderSuppliesID),NOW(),T_OrderSuppliesLastUpdated) as tx_lastupdated
FROM m_supplies
JOIN t_ordersupplies ON T_OrderSuppliesT_OrderHeaderID = $orderid AND T_OrderSuppliesM_SuppliesID = M_SuppliesID
WHERE
M_SuppliesIsActive = 'Y'
";
//echo $query ;
$supplies = $this->db_onedev->query($query)->result_array();
foreach($supplies as $k => $v){
if($v['chex'] == 'N')
$supplies[$k]['chex'] = false;
else
$supplies[$k]['chex'] = true;
}
$dt_log = array('orderid'=>$orderid,'supplies'=>$supplies,'barcode'=>$barcodes);
$fologcode = 'FO.Verification.BarcodeSupplies';
$json_dt_log = json_encode($dt_log);
$sql = "insert into one_log.log_supplies_barcode(
Log_SuppliesBarcodeDate,
Log_SuppliesBarcodeCode,
Log_SuppliesBarcodeJson,
Log_SuppliesBarcodeUserID)
values( now(), ?, ?, ?)";
//echo $sql;
$query = $this->db_onedev->query($sql,
array(
$fologcode,
$json_dt_log,
$xuserid
)
);
if (!$query) {
$this->sys_error_db("one_log.log_supplies_barcode insert");
exit;
}
}
function saveverifications($id,$verifications,$type,$userid)
{
try {
//$xverificationtypeid = $this->db_onedev->query("SELECT * FROM fo_verificationtype WHERE Fo_VerificationTypeGroup = '{$type}' AND Fo_VerificationTypeIsActive = 'Y'")->row()->Fo_VericationTypeID;
//echo $xverificationtypeid;
//print_r($verifications);
foreach($verifications as $k => $v){
//print_r($v);
if(intval($v['xid']) == 0){
$sql = "insert into fo_verification(
Fo_VerificationT_OrderHeaderID,
Fo_VerificationFo_VericationTypeID,
Fo_VerificationIsOK,
Fo_VerificationReason,
Fo_VerificationCreated,
Fo_VerificationLastUpdated,
Fo_VerificationUserID)
values( ?, ?, ?, ?, now(),now(),?)";
//echo $sql;
$query = $this->db_onedev->query($sql,
array(
$id,
$v['id'],
$v['chex'] == true ?'Y':'N',
$v['note'],
$userid
)
);
if (!$query) {
$this->sys_error_db("fo_verification insert");
exit;
}
}
}
return true;
} catch(Exception $exc) {
$message = $exc->getMessage();
$this->sys_error($message);
}
}
function saveverification_delivery($id,$deliveries,$userid)
{
try {
foreach($deliveries as $k => $v){
if($v['id'] === 0){
$sql = "insert into fo_verification_delivery_add(
Fo_VerificationDeliveryAddT_OrderHeaderID,
Fo_VerificationDeliveryAddM_DeliveryID,
Fo_VerificationDeliveryAddM_DeliveryTypeID,
Fo_VerificationDeliveryAddDestination,
Fo_VerificationDeliveryAddAddressID,
Fo_VerificationDeliveryAddM_KelurahanID,
Fo_VerificationDeliveryAddOK,
Fo_VerificationDeliveryAddReason,
Fo_VerificationDeliveryAddCreated,
Fo_VerificationDeliveryAddLastUpdated,
Fo_VerificationDeliveryAddUserID)
values( ?, ?, ?, ?,?,?,?,?, now(),now(),?)";
//echo $sql;
$query = $this->db_onedev->query($sql,
array(
$id,
$v['deliveryid'],
$v['typedeliveryid'],
$v['destination'],
$v['addressid'],
$v['vilageid'],
$v['chex'] == true ?'Y':'N',
$v['note'],
$userid
)
);
if (!$query) {
echo $this->db_onedev->last_query();
$this->sys_error_db("fo_verification_delivery_add insert");
exit;
}
}else{
$sql = "insert into fo_verification_delivery(
Fo_VerificationDeliveryT_OrderHeaderID,
Fo_VerificationDeliveryT_OrderDeliveryID,
Fo_VerificationDeliveryIsOK,
Fo_VerificationDeliveryReason,
Fo_VerificationDeliveryCreated,
Fo_VerificationDeliveryLastUpdated,
Fo_VerificationDeliveryUserID)
values( ?, ?, ?, ?, now(),now(),?)";
//echo $sql;
$query = $this->db_onedev->query($sql,
array(
$id,
$v['id'],
$v['chex'] == true ?'Y':'N',
$v['note'],
$userid
)
);
if (!$query) {
echo $this->db_onedev->last_query();
$this->sys_error_db("fo_verification_delivery insert");
exit;
}
//echo $this->db_onedev->last_query();
}
}
return true;
} catch(Exception $exc) {
$message = $exc->getMessage();
$this->sys_error($message);
}
}
function lookup_barcodes()
{
try {
$prm = $this->sys_input;
//# cek token valid
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$sql = "SELECT T_BarcodeLabID as id, 'barcode' as type,T_BarcodeLabID,T_BarcodeLabBarcode, T_BarcodeLabCounter, T_SampleTypeName, 'N' as chex
FROM t_barcodelab
JOIN t_sampletype ON T_BarcodeLabT_SampleTypeID = T_SampleTypeID
WHERE
T_BarcodeLabT_OrderHeaderID = {$prm['ohid']} AND T_BarcodeLabIsActive = 'Y'
UNION
SELECT T_OrderHeaderID as id, 'formulir' as type, 0,T_OrderHeaderLabNumber as T_BarcodeLabBarcode, 1, 'Formulir' as T_SampleTypeName, 'N' as chex
FROM t_orderheader
WHERE
T_OrderHeaderID = {$prm['ohid']}
";
//echo $sql;
$rows = $this->db_onedev->query($sql)->result_array();
if($rows){
foreach($rows as $k => $v){
if($v['chex'] == 'N')
$rows[$k]['chex'] = false;
else
$rows[$k]['chex'] = true;
}
}
$result = array ("total" => 0, "records" => $rows);
$this->sys_ok($result);
} catch(Exception $exc) {
$message = $exc->getMessage();
$this->sys_error($message);
}
}
function saveverification_px($id,$pxs,$userid)
{
try {
foreach($pxs as $k => $v){
if(intval($v['id']) == 0){
$cxh = $v['chex'] == true ?'Y':'N';
$sql = "insert into fo_verification_test_add(
Fo_VerificationTestAddT_OrderHeaderID,
Fo_VerificationTestAddT_TestID,
Fo_VerificationTestAddBruto,
Fo_VerificationTestAddDiscount,
Fo_VerificationTestAddTotal,
Fo_VerificationTestAddIsOK,
Fo_VerificationTestAddIsCito,
Fo_VerificationTestAddCreated,
Fo_VerificationTestAddLastUpdated,
Fo_VerificationTestAddUserID)
values( $id, {$v['pxid']}, {$v['bruto']}, {$v['discount']},{$v['total']},'{$cxh}','{$v['flagcito']}',now(),now(),{$userid})";
//echo $sql;
$query = $this->db_onedev->query($sql);
//echo $this->db_onedev->last_query();
if (!$query) {
$this->sys_error_db("fo_verification_test_add insert");
exit;
}
}else{
$sql = "insert into fo_verification_test(
Fo_VerificationTestT_OrderHeaderID,
Fo_VerificationTestT_OrderDetailID,
Fo_VerificationTestIsOK,
Fo_VerificationTestReason,
Fo_VerificationTestCreated,
Fo_VerificationTestLastUpdated,
Fo_VerificationTestUserID)
values( ?, ?, ?, ?, now(),now(),?)";
//echo $sql;
$query = $this->db_onedev->query($sql,
array(
$id,
$v['id'],
$v['chex'] == true ?'Y':'N',
$v['note'],
$userid
)
);
//echo $this->db_onedev->last_query();
if (!$query) {
$this->sys_error_db("fo_verification_test insert");
exit;
}
}
}
return true;
} catch(Exception $exc) {
$message = $exc->getMessage();
$this->sys_error($message);
}
}
function verify(){
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$prm = $this->sys_input;
$userid = $this->sys_user["M_UserID"];
$xstatus = $prm['act'];
if($xstatus == 'Y'){
$msg = "Berhasil melakukan verifikasi";
$query =" INSERT INTO result_verifications_value (
Result_VerificationsValueSo_ResultEntryID,
Result_VerificationsValueResult_VerificationsID,
Result_VerificationsValueCheck,
Result_VerificationsValueNote,
Result_VerificationsValueUserID,
Result_VerificationsValueCreated
)
SELECT {$prm['trx_id']},
Result_VerificationsID,
'Y',
'',
{$userid},
NOW()
FROM result_verifications
WHERE
Result_VerificationIsActive = 'Y'
ON DUPLICATE KEY UPDATE
Result_VerificationsValueCheck = 'Y',
Result_VerificationsValueNote = '',
Result_VerificationsValueUserID = {$userid},
Result_VerificationsValueLastUpdated = NOW()
";
//echo $query;
$this->db_onedev->query($query);
$sql = "UPDATE so_resultentry SET So_ResultEntryStatus = 'VAL2' , So_ResultEntryValidation2 = 'Y' WHERE So_ResultEntryID = {$prm['trx_id']}";
$this->db_onedev->query($sql);
}
else{
$msg = "Tolak untuk perbaikan";
$verifications = $prm['verifications'];
foreach($verifications as $k => $v){
$chx = $v['chex'] == true ?'Y':'N';
$query =" INSERT INTO result_verifications_value (
Result_VerificationsValueSo_ResultEntryID,
Result_VerificationsValueResult_VerificationsID,
Result_VerificationsValueCheck,
Result_VerificationsValueNote,
Result_VerificationsValueUserID,
Result_VerificationsValueCreated
)
values( {$prm['trx_id']},
{$v['id']},
'{$chx}',
'{$v['note']}',
{$userid},
NOW()
)
ON DUPLICATE KEY UPDATE
Result_VerificationsValueCheck = '{$chx}',
Result_VerificationsValueNote = '{$v['note']}',
Result_VerificationsValueUserID = {$userid},
Result_VerificationsValueLastUpdated = NOW()
";
//echo $query;
$this->db_onedev->query($query);
}
}
$result = array ("total" => 0, "records" => array('status'=>'OK','message'=>$msg));
$this->sys_ok($result);
}
public function getstatuspergroup()
{
try {
//# cek token valid
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$prm = $this->sys_input;
$rows = array();
$sql =" SELECT Last_StatusPaymentBillTotal as total_bill,
Last_StatusPaymentPaid as paid,
Last_StatusPaymentUnpaid as unpaid,
Last_StatusPaymentIsLunas as status
FROM last_statuspayment
WHERE
Last_StatusPaymentT_OrderHeaderID = {$prm['T_OrderHeaderID']} ";
$rows['info_bill'] = $this->db_onedev->query($sql)->row_array();
$sql =" SELECT T_OrderDeliveryID as id,
IFNULL(Fo_VerificationDeliveryID,0) as xid,
M_DeliveryTypeCode as code,
IF(ISNULL(Fo_VerificationDeliveryID),'N',Fo_VerificationDeliveryIsOK) as chex,
M_DeliveryID as deliveryid,
M_DeliveryTypeID as typedeliveryid,
T_OrderDeliveryM_KelurahanID as vilageid,
IF(ISNULL(Fo_VerificationDeliveryID),'',Fo_VerificationDeliveryReason) as note,
'reguler' as type,
CASE
WHEN T_OrderDeliveryM_DeliveryID = 1 THEN M_DeliveryName
WHEN T_OrderDeliveryM_DeliveryID = 4 THEN CONCAT(M_DeliveryName)
WHEN T_OrderDeliveryM_DeliveryID = 2 THEN CONCAT(M_DeliveryName)
WHEN ( T_OrderDeliveryM_DeliveryID = 7 OR T_OrderDeliveryM_DeliveryID = 9 ) THEN CONCAT(M_DeliveryName)
WHEN ( T_OrderDeliveryM_DeliveryID = 6 OR T_OrderDeliveryM_DeliveryID = 8 ) THEN CONCAT(M_DeliveryName)
ELSE
CONCAT(M_DeliveryName)
END as label,
CASE
WHEN T_OrderDeliveryM_DeliveryID = 1 THEN ''
WHEN T_OrderDeliveryM_DeliveryID = 4 THEN M_DoctorAddressDescription
WHEN T_OrderDeliveryM_DeliveryID = 2 THEN M_PatientAddressDescription
WHEN ( T_OrderDeliveryM_DeliveryID = 7 OR T_OrderDeliveryM_DeliveryID = 9 ) THEN M_DoctorHP
WHEN ( T_OrderDeliveryM_DeliveryID = 6 OR T_OrderDeliveryM_DeliveryID = 8 ) THEN M_PatientHP
ELSE
T_OrderDeliveryDestination
END as destination,
CASE
WHEN T_OrderDeliveryM_DeliveryID = 4 THEN M_DoctorAddressID
WHEN T_OrderDeliveryM_DeliveryID = 2 THEN M_PatientAddressID
ELSE
0
END as addressid
FROM t_orderdelivery
JOIN t_orderheader ON T_OrderDeliveryT_OrderHeaderID = T_OrderHeaderID
JOIN m_delivery ON T_OrderDeliveryM_DeliveryID = M_DeliveryID
JOIN m_deliverytype ON T_OrderDeliveryM_DeliveryTypeID = M_DeliveryTypeID
LEFT JOIN m_doctoraddress ON T_OrderDeliveryAddressID = M_DoctorAddressID AND T_OrderDeliveryM_DeliveryID = 4
LEFT JOIN m_patientaddress ON T_OrderDeliveryAddressID = M_PatientAddressID AND T_OrderDeliveryM_DeliveryID = 2
LEFT JOIN fo_verification_delivery ON Fo_VerificationDeliveryT_OrderHeaderID = T_OrderDeliveryT_OrderHeaderID AND Fo_VerificationDeliveryIsActive = 'Y'
LEFT JOIN m_doctor ON T_OrderHeaderSenderM_DoctorID = M_DoctorID AND ( T_OrderDeliveryM_DeliveryID = 7 OR T_OrderDeliveryM_DeliveryID = 9 )
LEFT JOIN m_patient ON T_OrderHeaderM_PatientID = M_PatientID AND ( T_OrderDeliveryM_DeliveryID = 6 OR T_OrderDeliveryM_DeliveryID = 8 )
WHERE
T_OrderDeliveryT_OrderHeaderID = {$prm['T_OrderHeaderID']} AND T_OrderDeliveryIsActive = 'Y'
GROUP BY T_OrderDeliveryID
";
//echo $query ;
$rows['info_deliveries'] = $this->db_onedev->query($sql)->result_array();
$sql = "
SELECT T_OrderHeaderID,
T_OrderPromiseID,
T_OrderPromiseDateTime,
T_OrderHeaderLabNumber,
UPPER(DocumentationGroupName) as DocumentationGroupName,
GROUP_CONCAT(CONCAT(T_TestName,'^',IFNULL(Result_SendEmailStatus,'X'))) as status_test_name,
GROUP_CONCAT(IFNULL(Result_SendEmailStatus,'X')) as status,
'' as status_pergroup,
'' as details
FROM t_orderdetail
JOIN t_orderheader ON T_OrderDetailT_OrderHeaderID = T_OrderHeaderID
JOIN t_orderpromise ON T_OrderDetailT_OrderPromiseID = T_OrderPromiseID
JOIN t_test ON T_OrderDetailT_TestID = T_TestID AND T_TestIsResult = 'Y'
LEFT JOIN result_sendemail ON Result_SendEmailT_OrderHeaderID = T_OrderHeaderID AND
JSON_CONTAINS(Result_SendEmailIds,T_OrderDetailID)
JOIN documentation_group_detail ON DocumentationGroupDetailNat_SubGroupID = T_TestNat_SubGroupID
JOIN documentation_group ON DocumentationGroupDetailDocumentationGroupID = DocumentationGroupID
WHERE
T_OrderHeaderID = {$prm['T_OrderHeaderID']} AND T_OrderPromiseID = {$prm['T_OrderPromiseID']} AND T_OrderDetailIsActive = 'Y'
GROUP BY DocumentationGroupID
";
$rows['info_test'] = $this->db_onedev->query($sql)->result_array();
if($rows['info_test']){
foreach($rows['info_test'] as $k => $v){
$rows['info_test'][$k]['status_pergroup'] = 'R';
$x_arr = explode(',',$v['status']);
if(in_array('X',$x_arr)){
$rows['info_test'][$k]['status_pergroup'] = 'X';
}
if($v['DocumentationGroupName'] != 'LAB'){
$z_arr = explode(',',$v['status_test_name']);
$for_details = array();
foreach($z_arr as $i => $val){
$xx_arr = explode('^',$val);
array_push($for_details,array('testname'=>$xx_arr[0],'status'=>$xx_arr[1]));
}
$rows['info_test'][$k]['details'] = $for_details;
}
else{
$rows['info_test'][$k]['DocumentationGroupName'] = 'Laboratorium';
$rows['info_test'][$k]['details'] = array(array('testname'=>'Pemeriksaan Laboratorium','status'=>$rows['info_test'][$k]['status_pergroup']));
}
}
}
$result = array ("total" => 0, "records" => $rows);
$this->sys_ok($result);
} catch(Exception $exc) {
$message = $exc->getMessage();
$this->sys_error($message);
}
}
}

View File

@@ -0,0 +1,128 @@
<?php
class Patient extends MY_Controller
{
var $db_onedev;
public function index()
{
echo "Patient API";
}
public function __construct()
{
parent::__construct();
$this->db_onedev = $this->load->database("onedev", true);
}
public function add_notes($orderid){
$sql = " SELECT F_PaymentT_OrderHeaderID as note_order_id,
F_PaymentID as note_id,
F_PaymentDate as note_date,
F_PaymentNumber as note_number,
GROUP_CONCAT(M_PaymentTypeName separator ' , ') as paymenttypes_name,
SUM(F_PaymentDetailAmount) as note_amount,
M_UserUsername as note_user,
F_PaymentDetailIsActive as note_active
FROM f_payment
JOIN f_paymentdetail ON F_PaymentDetailF_PaymentID = F_PaymentID
JOIN m_paymenttype ON F_PaymentDetailM_PaymentTypeID = M_PaymentTypeID
LEFT JOIN m_user ON F_PaymentDetailUserID = M_UserID
WHERE
F_PaymentT_OrderHeaderID = {$orderid}
GROUP BY F_PaymentID";
$query = $this->db_onedev->query($sql);
if ($query) {
$rows = $query->result_array();
return $rows;
} else {
$this->sys_error_db("get notes", $this->db_onedev);
exit;
}
}
public function search()
{
//# cek token valid
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$prm = $this->sys_input;
$startdate = $prm['startdate'] . " 00:00:01";
$enddate = $prm['enddate'] . " 23:59:59";
$search = $prm["search"];
$status = $prm["status"];
$number_limit = 10;
$number_offset = ($prm['current_page'] - 1) * $number_limit ;
$where = " ( T_OrderHeaderDate BETWEEN '{$startdate}' AND '{$enddate}' ) AND ";
if($search != '')
$where = "( M_PatientName LIKE '%{$search}%' OR T_OrderHeaderLabNumber LIKE '%{$search}%' ) AND ";
$sql = " SELECT count(*) as total
FROM t_orderheader
JOIN m_patient ON T_OrderHeaderM_PatientID = M_PatientID
JOIN m_title ON M_PatientM_TitleID = M_TitleID
JOIN m_sex ON M_PatientM_SexID = M_SexID
JOIN m_company ON T_OrderHeaderM_CompanyID = M_CompanyID
JOIN m_mou ON T_OrderHeaderM_MouID = M_MouID
LEFT JOIN last_statuspayment ON Last_StatusPaymentT_OrderHeaderID = T_OrderHeaderID AND Last_StatusPaymentIsActive = 'Y'
WHERE
$where
( ('{$status}' = 'N' AND (Last_StatusPaymentIsLunas = 'N' OR Last_StatusPaymentID IS NULL)) OR ('{$status}' = 'Y' AND Last_StatusPaymentIsLunas = 'Y') )";
$query = $this->db_onedev->query($sql, $sql_param);
$tot_count = 0;
$tot_page = 0;
if ($query) {
$tot_count = $query->result_array()[0]["total"];
$tot_page = ceil($tot_count/$number_limit);
} else {
$this->sys_error_db("t_samplestorage count", $this->db_onedev);
exit;
}
$sql = "SELECT t_orderheader.*,
M_PatientNoReg,
M_PatientName,
M_TitleName,
M_CompanyName,
M_MouName,
T_OrderHeaderTotal as totalbill,
IFNULL(Last_StatusPaymentPaid,0) as paid,
IFNULL(Last_StatusPaymentUnpaid,T_OrderHeaderTotal)as unpaid,
Last_StatusPaymentIsLunas as flaglunas,
'' as notes,
M_MouMinDP as mindp_percent,
(M_MouMinDP/100) * T_OrderHeaderTotal as mindp_amount
FROM t_orderheader
JOIN m_patient ON T_OrderHeaderM_PatientID = M_PatientID
JOIN m_title ON M_PatientM_TitleID = M_TitleID
JOIN m_sex ON M_PatientM_SexID = M_SexID
JOIN m_company ON T_OrderHeaderM_CompanyID = M_CompanyID
JOIN m_mou ON T_OrderHeaderM_MouID = M_MouID
LEFT JOIN last_statuspayment ON Last_StatusPaymentT_OrderHeaderID = T_OrderHeaderID AND Last_StatusPaymentIsActive = 'Y'
WHERE
$where
( ('{$status}' = 'N' AND (Last_StatusPaymentIsLunas = 'N' OR Last_StatusPaymentID IS NULL)) OR ('{$status}' = 'Y' AND Last_StatusPaymentIsLunas = 'Y') )
ORDER BY T_OrderHeaderID ASC
limit $number_limit offset $number_offset";
//echo $sql;
$query = $this->db_onedev->query($sql, $sql_param);
$rows = $query->result_array();
if($rows){
foreach($rows as $k => $v){
$rows[$k]['notes'] = $this->add_notes($v['T_OrderHeaderID']);
}
}
$result = array("total" => $tot_page, "records" => $rows, "sql"=> $this->db_onedev->last_query());
$this->sys_ok($result);
exit;
}
}

View File

@@ -0,0 +1,244 @@
<?php
class Payment extends MY_Controller
{
var $db_smartone;
public function index()
{
echo "API";
}
public function __construct()
{
parent::__construct();
$this->db_onedev = $this->load->database("onedev", true);
}
function lookup_type()
{
//# cek token valid
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$query = "SELECT M_PaymentTypeID as id,
M_PaymentTypeCode as code,
IF(M_PaymentTypeCode = 'CASH','Y','N') as chex,
M_PaymentTypeName as chexlabel,
'Jumlah' as leftlabel,
CASE
WHEN M_PaymentTypeCode = 'CASH' THEN 'Kembali'
WHEN M_PaymentTypeCode = 'DEBIT' THEN 'Nomor Kartu'
WHEN M_PaymentTypeCode = 'CREDIT' THEN 'Nomor Kartu'
ELSE 'Nomor Voucher'
END as rightlabel,
0 as leftvalue,
0 as rightvalue
FROM m_paymenttype WHERE M_PaymentTypeIsActive = 'Y'";
$rows = $this->db_onedev->query($query)->result_array();
foreach($rows as $k => $v){
if($v['chex'] == 'N')
$rows[$k]['chex'] = false;
else
$rows[$k]['chex'] = true;
}
$result = array(
"total" => count($rows) ,
"records" => $rows,
);
$this->sys_ok($result);
exit;
}
function pay()
{
//# cek token valid
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
//# ambil parameter input
$xuserid = $this->sys_user['M_UserID'];
$prm = $this->sys_input;
$orderid = $prm['orderid'];
$payments = $prm['payments'];
//$xnumber = $this->db_onedev->query("SELECT `fn_numbering`('PAY') as numberx")->row()->numberx;
$sql = "INSERT INTO f_payment(F_PaymentT_OrderHeaderID,F_PaymentDate,F_PaymentCreated,F_PaymentM_UserID) VALUES (?,CURDATE(),NOW(),?)";
$query = $this->db_onedev->query($sql,
array(
$orderid, $xuserid
)
);
if (!$query) {
$this->sys_error_db("f_payment insert");
exit;
}
$headerid = $this->db_onedev->insert_id();
foreach($payments as $k => $v){
$actual = 0;
$change = 0;
$amount = $v['leftvalue'];
if($v['code'] == 'CASH'){
$actual = $v['leftvalue'];
$change = $v['rightvalue'];
if($actual > 0){
$amount = intval($v['leftvalue']) - intval($v['rightvalue']);
}
else{
$amount = $actual;
}
$sql = "INSERT INTO f_paymentdetail(
F_PaymentDetailF_PaymentID,
F_PaymentDetailM_PaymentTypeID,
F_PaymentDetailAmount,
F_PaymentDetailActual,
F_PaymentDetailChange,
F_PaymentDetailCreated,
F_PaymentDetailLastUpdated,
F_PaymentDetailUserID)
VALUES (
?,
?,
?,
?,
?,
now(),
now(),
?
)";
//echo $sql;
$query = $this->db_onedev->query($sql,
array(
$headerid,
$v['id'],
$amount,
$actual,
$change,
$xuserid
)
);
if (!$query) {
$this->sys_error_db("f_paymentdetail cash insert");
exit;
}
}
else{
if(intval($v['leftvalue']) > 0){
$actual = 0;
$change = 0;
$amount = $v['leftvalue'];
$sql = "INSERT INTO f_paymentdetail(
F_PaymentDetailF_PaymentID,
F_PaymentDetailM_PaymentTypeID,
F_PaymentDetailAmount,
F_PaymentDetailActual,
F_PaymentDetailChange,
F_PaymentDetailCreated,
F_PaymentDetailLastUpdated,
F_PaymentDetailUserID)
VALUES (
?,
?,
?,
?,
?,
now(),
now(),
?
)";
//echo $sql;
$query = $this->db_onedev->query($sql,
array(
$headerid,
$v['id'],
$amount,
$actual,
$change,
$xuserid
)
);
if (!$query) {
$this->sys_error_db("f_paymentdetail non cash insert");
exit;
}
}
}
}
$query = "SELECT M_PaymentTypeID as id,
M_PaymentTypeCode as code,
IF(M_PaymentTypeCode = 'CASH','Y','N') as chex,
M_PaymentTypeName as chexlabel,
'Jumlah' as leftlabel,
CASE
WHEN M_PaymentTypeCode = 'CASH' THEN 'Kembali'
WHEN M_PaymentTypeCode = 'DEBIT' THEN 'Nomor Kartu'
WHEN M_PaymentTypeCode = 'CREDIT' THEN 'Nomor Kartu'
ELSE 'Nomor Voucher'
END as rightlabel,
0 as leftvalue,
0 as rightvalue
FROM m_paymenttype WHERE M_PaymentTypeIsActive = 'Y'";
$rows = $this->db_onedev->query($query)->result_array();
foreach($rows as $k => $v){
if($v['chex'] == 'N')
$rows[$k]['chex'] = false;
else
$rows[$k]['chex'] = true;
}
$xdata = $this->db_onedev->query("SELECT F_PaymentID as idx, F_PaymentNumber as numberx FROM f_payment WHERE F_PaymentID = {$headerid}")->row();
$result = array(
"total" => count($rows) ,
"records" => array('types'=>$rows,'data'=>$xdata)
);
$this->sys_ok($result);
exit;
}
function delete_note()
{
//# cek token valid
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
//# ambil parameter input
$xuserid = $this->sys_user['M_UserID'];
$prm = $this->sys_input;
$prmnota = $prm['nota'];
$catatan = $prm['catatan'];
$sql = "UPDATE f_payment SET F_PaymentIsActive = 'N', F_PaymentNote = '{$catatan}' WHERE F_PaymentID = {$prmnota['note_id']}";
//echo $sql;
$query = $this->db_onedev->query($sql);
if (!$query) {
$this->sys_error_db("f_payment delete");
exit;
}
$sql = "UPDATE f_paymentdetail SET F_PaymentDetailIsActive = 'N' WHERE F_PaymentDetailF_PaymentID = {$prmnota['note_id']}";
//echo $sql;
$query = $this->db_onedev->query($sql);
if (!$query) {
$this->sys_error_db("f_paymentdetail delete");
exit;
}
$result = array(
"total" => 1 ,
"records" => array('prm'=>$prm)
);
$this->sys_ok($result);
exit;
}
}

View File

@@ -0,0 +1,132 @@
<?php
class Patient extends MY_Controller
{
var $db_onedev;
public function index()
{
echo "Patient API";
}
public function __construct()
{
parent::__construct();
$this->db_onedev = $this->load->database("onedev", true);
}
public function add_notes($orderid){
$sql = " SELECT F_PaymentT_OrderHeaderID as note_order_id,
F_PaymentID as note_id,
F_PaymentDate as note_date,
F_PaymentNumber as note_number,
GROUP_CONCAT(M_PaymentTypeName separator ' , ') as paymenttypes_name,
SUM(F_PaymentDetailAmount) as note_amount,
M_UserUsername as note_user,
F_PaymentDetailIsActive as note_active
FROM f_payment
JOIN f_paymentdetail ON F_PaymentDetailF_PaymentID = F_PaymentID
JOIN m_paymenttype ON F_PaymentDetailM_PaymentTypeID = M_PaymentTypeID
LEFT JOIN m_user ON F_PaymentDetailUserID = M_UserID
WHERE
F_PaymentT_OrderHeaderID = {$orderid}
GROUP BY F_PaymentID";
$query = $this->db_onedev->query($sql);
if ($query) {
$rows = $query->result_array();
return $rows;
} else {
$this->sys_error_db("get notes", $this->db_onedev);
exit;
}
}
public function search()
{
//# cek token valid
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$prm = $this->sys_input;
$startdate = $prm['startdate'] . " 00:00:01";
$enddate = $prm['enddate'] . " 23:59:59";
$search = $prm["search"];
$status = $prm["status"];
$number_limit = 10;
$number_offset = ($prm['current_page'] - 1) * $number_limit ;
$where = " ( T_OrderHeaderDate BETWEEN '{$startdate}' AND '{$enddate}' ) AND ";
if($search != ''){
$where = "( M_PatientName LIKE '%{$search}%' OR T_OrderHeaderLabNumber LIKE '%{$search}%' ) AND ";
if(strlen($search) == 9){
$where = "T_OrderHeaderLabNumber = '{$search}' AND ";
}
}
$sql = " SELECT count(*) as total
FROM t_orderheader
JOIN m_patient ON T_OrderHeaderM_PatientID = M_PatientID
JOIN m_title ON M_PatientM_TitleID = M_TitleID
JOIN m_sex ON M_PatientM_SexID = M_SexID
JOIN m_company ON T_OrderHeaderM_CompanyID = M_CompanyID
JOIN m_mou ON T_OrderHeaderM_MouID = M_MouID
LEFT JOIN last_statuspayment ON Last_StatusPaymentT_OrderHeaderID = T_OrderHeaderID AND Last_StatusPaymentIsActive = 'Y'
WHERE
$where
( ('{$status}' = 'N' AND (Last_StatusPaymentIsLunas = 'N' OR Last_StatusPaymentID IS NULL)) OR ('{$status}' = 'Y' AND Last_StatusPaymentIsLunas = 'Y') )";
$query = $this->db_onedev->query($sql, $sql_param);
$tot_count = 0;
$tot_page = 0;
if ($query) {
$tot_count = $query->result_array()[0]["total"];
$tot_page = ceil($tot_count/$number_limit);
} else {
$this->sys_error_db("t_samplestorage count", $this->db_onedev);
exit;
}
$sql = "SELECT t_orderheader.*,
M_PatientNoReg,
CONCAT(M_TitleName,'. ',M_PatientName) as M_PatientName,
M_TitleName,
M_CompanyName,
M_MouName,
T_OrderHeaderTotal as totalbill,
IFNULL(Last_StatusPaymentPaid,0) as paid,
(T_OrderHeaderTotal + fn_fo_chasier_get_admin_charge(T_OrderHeaderID) )- ifnull(fn_fo_chasier_get_total_payment(T_OrderHeaderID),0) as unpaid,
Last_StatusPaymentIsLunas as flaglunas,
'' as notes,
M_MouMinDP as mindp_percent,
(M_MouMinDP/100) * T_OrderHeaderTotal as mindp_amount
FROM t_orderheader
JOIN m_patient ON T_OrderHeaderM_PatientID = M_PatientID
JOIN m_title ON M_PatientM_TitleID = M_TitleID
JOIN m_sex ON M_PatientM_SexID = M_SexID
JOIN m_company ON T_OrderHeaderM_CompanyID = M_CompanyID
JOIN m_mou ON T_OrderHeaderM_MouID = M_MouID
LEFT JOIN last_statuspayment ON Last_StatusPaymentT_OrderHeaderID = T_OrderHeaderID AND Last_StatusPaymentIsActive = 'Y'
WHERE
$where
( ('{$status}' = 'N' AND (Last_StatusPaymentIsLunas = 'N' OR Last_StatusPaymentID IS NULL)) OR ('{$status}' = 'Y' AND Last_StatusPaymentIsLunas = 'Y') )
ORDER BY T_OrderHeaderID ASC
limit $number_limit offset $number_offset";
//echo $sql;
$query = $this->db_onedev->query($sql, $sql_param);
$rows = $query->result_array();
if($rows){
foreach($rows as $k => $v){
$rows[$k]['notes'] = $this->add_notes($v['T_OrderHeaderID']);
}
}
$result = array("total" => $tot_page, "records" => $rows, "sql"=> $this->db_onedev->last_query());
$this->sys_ok($result);
exit;
}
}

View File

@@ -0,0 +1,400 @@
<?php
class Payment extends MY_Controller
{
var $db_smartone;
public function index()
{
echo "API";
}
public function __construct()
{
parent::__construct();
$this->db_onedev = $this->load->database("onedev", true);
}
function lookup_type()
{
//# cek token valid
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$query = "SELECT M_PaymentTypeID as id,
M_PaymentTypeCode as code,
'N' as chex,
M_PaymentTypeName as chexlabel,
'Jumlah' as leftlabel,
'' as selected_card,
'' as selected_edc,
'' as selected_account,
CASE
WHEN M_PaymentTypeCode = 'CASH' THEN 'Kembali'
WHEN M_PaymentTypeCode = 'DEBIT' THEN 'Nomor Kartu'
WHEN M_PaymentTypeCode = 'CREDIT' THEN 'Nomor Kartu'
WHEN M_PaymentTypeCode = 'TRANSFER' THEN 'No. Rekening'
ELSE 'Nomor Voucher'
END as rightlabel,
0 as leftvalue,
0 as rightvalue
FROM m_paymenttype WHERE M_PaymentTypeIsActive = 'Y'";
$rows = $this->db_onedev->query($query)->result_array();
foreach($rows as $k => $v){
$rows[$k]['selected_card'] = array('id'=>0,'name'=>'');
$rows[$k]['selected_edc'] = array('id'=>0,'name'=>'');
if($v['chex'] == 'N')
$rows[$k]['chex'] = false;
else
$rows[$k]['chex'] = true;
}
$result = array(
"total" => count($rows) ,
"records" => $rows,
);
$this->sys_ok($result);
exit;
}
function lookup_banks()
{
//# cek token valid
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$query = "SELECT Nat_BankID as id, Nat_BankCode as name
FROM nat_bank
WHERE
Nat_BankIsActive = 'Y'
ORDER BY Nat_BankCode DESC";
$rows = $this->db_onedev->query($query)->result_array();
$result = array(
"total" => count($rows) ,
"records" => $rows,
);
$this->sys_ok($result);
exit;
}
function lookup_accounts()
{
//# cek token valid
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$query = "SELECT M_BankAccountID as id, CONCAT(Nat_BankCode,' (',M_BankAccountNo,')') as name
FROM m_bank_account
JOIN nat_bank ON M_BankAccountNat_BankID = Nat_BankID
WHERE
M_BankAccountIsActive = 'Y'
ORDER BY Nat_BankCode DESC";
$rows = $this->db_onedev->query($query)->result_array();
$result = array(
"total" => count($rows) ,
"records" => $rows,
);
$this->sys_ok($result);
exit;
}
function searchcard(){
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$prm = $this->sys_input;
$max_rst = 12;
$tot_count =0;
$q = [
'search' => '%'
];
if ($prm['search'] != '')
{
$q['search'] = "%{$prm['search']}%";
}
// QUERY TOTAL
if($prm['search'] != ''){
$sql = "
SELECT count(*) as total
FROM nat_bank
WHERE
Nat_BankName like ?
AND Nat_BankIsActive = 'Y'
ORDER BY Nat_BankName DESC
";
}
else{
$sql = "
SELECT count(*) as total
FROM nat_bank
WHERE
Nat_BankIsActive = 'Y'
ORDER BY Nat_BankName DESC
";
}
$query = $this->db_onedev->query($sql,$q['search']);
//echo $query;
if ($query) {
$tot_count = $query->result_array()[0]["total"];
}
else {
$this->sys_error_db("m_city count",$this->db_onedev);
exit;
}
if($prm['search'] != ''){
$sql = "
SELECT Nat_BankID as id, Nat_BankName as name
FROM nat_bank
WHERE
Nat_BankName like ?
AND Nat_BankIsActive = 'Y'
ORDER BY Nat_BankName DESC
";
}
else{
$sql = "
SELECT Nat_BankID as id, Nat_BankName as name
FROM nat_bank
WHERE
Nat_BankIsActive = 'Y'
ORDER BY Nat_BankName DESC
";
}
$query = $this->db_onedev->query($sql, array($q['search']));
if ($query) {
$rows = $query->result_array();
//echo $this->db_onedev->last_query();
$result = array("total" => $tot_count, "records" => $rows, "total_display" => sizeof($rows));
$this->sys_ok($result);
}
else {
$this->sys_error_db("m_city rows",$this->db_onedev);
exit;
}
}
function pay()
{
//# cek token valid
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
//# ambil parameter input
$xuserid = $this->sys_user['M_UserID'];
$prm = $this->sys_input;
$orderid = $prm['orderid'];
$payments = $prm['payments'];
//$xnumber = $this->db_onedev->query("SELECT `fn_numbering`('PAY') as numberx")->row()->numberx;
$sql = "INSERT INTO f_payment(F_PaymentT_OrderHeaderID,F_PaymentDate,F_PaymentCreated,F_PaymentM_UserID) VALUES (?,CURDATE(),NOW(),?)";
$query = $this->db_onedev->query($sql,
array(
$orderid, $xuserid
)
);
if (!$query) {
$this->sys_error_db("f_payment insert");
exit;
}
$headerid = $this->db_onedev->insert_id();
foreach($payments as $k => $v){
if($v['chex']){
$actual = 0;
$change = 0;
$amount = $v['leftvalue'];
if($v['code'] == 'CASH'){
$actual = $v['leftvalue'];
$change = $v['rightvalue'];
if($actual > 0){
$amount = intval($v['leftvalue']) - intval($v['rightvalue']);
}
else{
$amount = $actual;
}
$sql = "INSERT INTO f_paymentdetail(
F_PaymentDetailF_PaymentID,
F_PaymentDetailM_PaymentTypeID,
F_PaymentDetailAmount,
F_PaymentDetailActual,
F_PaymentDetailChange,
F_PaymentDetailCreated,
F_PaymentDetailLastUpdated,
F_PaymentDetailUserID)
VALUES (
?,
?,
?,
?,
?,
now(),
now(),
?
)";
//echo $sql;
$query = $this->db_onedev->query($sql,
array(
$headerid,
$v['id'],
$amount,
$actual,
$change,
$xuserid
)
);
if (!$query) {
$this->sys_error_db("f_paymentdetail cash insert");
exit;
}
}
else{
if(intval($v['leftvalue']) > 0){
$actual = 0;
$change = 0;
$amount = $v['leftvalue'];
$selected_card = 0;
$selected_edc = 0;
$selected_account = 0;
if($v['code'] == 'DEBIT' || $v['code'] == 'CREDIT' || $v['code'] == 'TRANSFER'){
$selected_card = $v['selected_card']['id'];
$selected_edc = $v['selected_edc']['id'];
$selected_account = $v['selected_account']['id'];
}
$sql = "INSERT INTO f_paymentdetail(
F_PaymentDetailF_PaymentID,
F_PaymentDetailM_PaymentTypeID,
F_PaymentDetailAmount,
F_PaymentDetailActual,
F_PaymentDetailChange,
F_PaymentDetailCardNat_BankID,
F_PaymentDetailEDCNat_BankID,
F_PaymentDetailM_BankAccountID,
F_PaymentDetailCreated,
F_PaymentDetailLastUpdated,
F_PaymentDetailUserID)
VALUES (
?,
?,
?,
?,
?,
?,
?,
?,
now(),
now(),
?
)";
//echo $sql;
$query = $this->db_onedev->query($sql,
array(
$headerid,
$v['id'],
$amount,
$actual,
$change,
$selected_card,
$selected_edc,
$selected_account,
$xuserid
)
);
//echo $this->db_onedev->last_query();
if (!$query) {
$this->sys_error_db("f_paymentdetail non cash insert");
exit;
}
}
}
}
}
$query = "SELECT M_PaymentTypeID as id,
M_PaymentTypeCode as code,
IF(M_PaymentTypeCode = 'CASH','Y','N') as chex,
M_PaymentTypeName as chexlabel,
'Jumlah' as leftlabel,
CASE
WHEN M_PaymentTypeCode = 'CASH' THEN 'Kembali'
WHEN M_PaymentTypeCode = 'DEBIT' THEN 'Nomor Kartu'
WHEN M_PaymentTypeCode = 'CREDIT' THEN 'Nomor Kartu'
WHEN M_PaymentTypeCode = 'TRANSFER' THEN 'Nomor Rekening'
ELSE 'Nomor Voucher'
END as rightlabel,
0 as leftvalue,
0 as rightvalue
FROM m_paymenttype WHERE M_PaymentTypeIsActive = 'Y'";
$rows = $this->db_onedev->query($query)->result_array();
foreach($rows as $k => $v){
if($v['chex'] == 'N')
$rows[$k]['chex'] = false;
else
$rows[$k]['chex'] = true;
}
$xdata = $this->db_onedev->query("SELECT F_PaymentID as idx, F_PaymentNumber as numberx FROM f_payment WHERE F_PaymentID = {$headerid}")->row();
$result = array(
"total" => count($rows) ,
"records" => array('payments'=>$payments,'types'=>$rows,'data'=>$xdata)
);
$this->sys_ok($result);
exit;
}
function delete_note()
{
//# cek token valid
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
//# ambil parameter input
$xuserid = $this->sys_user['M_UserID'];
$prm = $this->sys_input;
$prmnota = $prm['nota'];
$catatan = $prm['catatan'];
$sql = "UPDATE f_payment SET F_PaymentIsActive = 'N', F_PaymentNote = '{$catatan}' WHERE F_PaymentID = {$prmnota['note_id']}";
//echo $sql;
$query = $this->db_onedev->query($sql);
if (!$query) {
$this->sys_error_db("f_payment delete");
exit;
}
$sql = "UPDATE f_paymentdetail SET F_PaymentDetailIsActive = 'N' WHERE F_PaymentDetailF_PaymentID = {$prmnota['note_id']}";
//echo $sql;
$query = $this->db_onedev->query($sql);
if (!$query) {
$this->sys_error_db("f_paymentdetail delete");
exit;
}
$result = array(
"total" => 1 ,
"records" => array('prm'=>$prm)
);
$this->sys_ok($result);
exit;
}
}

View File

@@ -0,0 +1,893 @@
<?php
class Promisenotok extends MY_Controller
{
var $db_onedev;
public function index()
{
echo "Samplingcall API";
}
public function __construct()
{
parent::__construct();
$this->db_onedev = $this->load->database("onedev", true);
}
function search()
{
$prm = $this->sys_input;
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$search = $prm["nolab"];
$sql_where = "WHERE ( T_OrderHeaderLabNumber LIKE CONCAT('%','{$search}','%') OR M_PatientName LIKE CONCAT('%','{$search}','%')) AND T_OrderHeaderIsActive = 'Y'";
$sql = " SELECT count(*) as total
FROM (
SELECT T_OrderHeaderID as orderid,
T_OrderHeaderLabNumber as labnumber,
CONCAT(M_TitleName,'. ',M_PatientName) as patient_fullname,
fn_fo_promise_not_ok(T_OrderHeaderID) as status
FROM t_orderheader
JOIN t_orderheaderaddon ON T_OrderHeaderAddOnT_OrderHeaderID = T_OrderHeaderID
JOIN m_patient ON T_OrderHeaderM_PatientID = M_PatientID
JOIN m_title ON M_PatientM_TitleID = M_TitleID
$sql_where
HAVING status = 'Y'
) a
";
//echo $sql;
$query = $this->db_onedev->query($sql);
$tot_count = 0;
//$tot_page = 0;
if ($query) {
$tot_count = $query->result_array()[0]["total"];
//$tot_page = ceil($tot_count/$number_limit);
} else {
$this->sys_error_db("m_doctor count", $this->db_onedev);
exit;
}
$sql = "SELECT T_OrderHeaderID as orderid,
T_OrderHeaderLabNumber as labnumber,
CONCAT(M_TitleName,'. ',M_PatientName) as patient_fullname,
fn_fo_promise_not_ok(T_OrderHeaderID) as status
FROM t_orderheader
JOIN t_orderheaderaddon ON T_OrderHeaderAddOnT_OrderHeaderID = T_OrderHeaderID
JOIN m_patient ON T_OrderHeaderM_PatientID = M_PatientID
JOIN m_title ON M_PatientM_TitleID = M_TitleID
$sql_where
HAVING status = 'Y'
ORDER BY T_OrderHeaderID ASC";
//echo $sql;
$query = $this->db_onedev->query($sql);
//echo $this->db_onedev->last_query();
$rows = $query->result_array();
//$this->_add_address($rows);
$result = array("total" => $tot_count, "records" => $rows, "sql"=> $this->db_onedev->last_query());
$this->sys_ok($result);
exit;
}
function searchcompany(){
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$prm = $this->sys_input;
$max_rst = 12;
$tot_count =0;
$q = [
'search' => '%'
];
if ($prm['search'] != '')
{
$q['search'] = "%{$prm['search']}%";
}
// QUERY TOTAL
$sql = "SELECT count(*) as total
FROM m_company
WHERE
M_CompanyName like ?
AND M_CompanyIsActive = 'Y'";
$query = $this->db_onedev->query($sql,$q['search']);
//echo $query;
if ($query) {
$tot_count = $query->result_array()[0]["total"];
}
else {
$this->sys_error_db("m_city count",$this->db_onedev);
exit;
}
$rows = array('id'=>0,'name'=>'Semua');
$sql = "
SELECT M_CompanyID as id, M_CompanyName as name
FROM m_company
WHERE
M_CompanyName like ?
AND M_CompanyIsActive = 'Y'
ORDER BY M_CompanyName DESC
";
$query = $this->db_onedev->query($sql, array($q['search']));
if ($query) {
$rows = $query->result_array();
array_push($rows,array('id'=>0,'name'=>'Semua'));
//echo $this->db_onedev->last_query();
$result = array("total" => $tot_count, "records" => $rows, "total_display" => sizeof($rows));
$this->sys_ok($result);
}
else {
$this->sys_error_db("m_company rows",$this->db_onedev);
exit;
}
}
function fajribagus(){
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
}
function getstationstatus(){
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$rows = [];
$query =" SELECT T_SampleStationID as id, T_SampleStationName as name
FROM t_samplestation
WHERE
T_SampleStationIsActive = 'Y' AND T_SampleStationIsNonLab = ''
";
//echo $query;
$rows['stations'] = $this->db_onedev->query($query)->result_array();
$rows['statuses'] = array(array('id'=>'NEW','name'=>'New'),array('id'=>'DONE','name'=>'Done'));
$result = array(
"total" => count($rows) ,
"records" => $rows,
);
$this->sys_ok($result);
exit;
}
function search_staff(){
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$prm = $this->sys_input;
$rows = [];
$query =" SELECT M_StaffID as id, M_StaffName as name, M_StaffCode as code, M_UserID as userid
FROM m_staff
JOIN m_user ON M_UserM_StaffID = M_StaffID AND M_UserIsActive = 'Y'
WHERE
M_StaffIsActive = 'Y' AND M_StaffCode = '{$prm['search']}' LIMIT 1
";
//echo $query;
$rows = $this->db_onedev->query($query)->row_array();
$result = array(
"total" => count($rows) ,
"records" => $rows,
);
$this->sys_ok($result);
exit;
}
function gettests(){
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$prm = $this->sys_input;
$query =" SELECT T_OrderDetailID as id,
T_OrderDetailT_TestName as testname,
T_OrderDetailT_TestCode as testcode,
T_OrderDetailT_TestSasCode as sascode
FROM t_orderheader
JOIN t_orderdetail ON T_OrderDetailT_OrderHeaderID = T_OrderHeaderID AND
T_OrderDetailIsActive = 'Y' AND
LENGTH(T_OrderDetailT_TestSasCode) = 8
WHERE
T_OrderHeaderID = {$prm['orderid']}
";
//echo $query;
$rows = $this->db_onedev->query($query)->result_array();
$result = array(
"total" => count($rows) ,
"records" => $rows,
);
$this->sys_ok($result);
exit;
}
function savenewpromise(){
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$prm = $this->sys_input;
$newpromise = $prm['newpromise'];
$xuserid = $this->sys_user['M_UserID'];
//print_r($newpromise);
foreach($newpromise as $k => $v){
$xdatetime = date('Y-m-d H:i',strtotime($v['promisedate'].' '.$v['promisetime']));
$xid = 0;
$sql = "SELECT * FROM t_orderpromise WHERE T_OrderPromiseT_OrderHeaderID = {$prm['orderid']} AND DATE_FORMAT(T_OrderPromiseDateTime,'%Y-%m-%d %H:%i') = '{$xdatetime}' AND T_OrderPromiseIsActive = 'Y' LIMIT 1";
//echo $sql;
$sql_xid = $this->db_onedev->query($sql)->row();
if($sql_xid){
$xid = $sql_xid->T_OrderPromiseID;
}
//echo $xid;
if($xid == 0){
$sql = "INSERT INTO t_orderpromise (
T_OrderPromiseT_OrderHeaderID,
T_OrderPromiseDateTime
)VALUES(
{$prm['orderid']},
'{$xdatetime}'
)";
//echo $sql;
$this->db_onedev->query($sql);
$xid = $this->db_onedev->insert_id();
}
$sql = "UPDATE t_orderdetail SET T_OrderDetailT_OrderPromiseID = {$xid} WHERE T_OrderDetailID = '{$v['id']}' ";
$this->db_onedev->query($sql);
//echo $sql;
}
$fologcode = 'FO.P3KPROMISE';
$data_log = array();
$data_log['orderid'] = $prm['orderid'];
$data_log['new_promise'] = $newpromise;
$json_dt_log = json_encode($data_log);
$sql = "insert into one_log.log_fo(
Log_FoDate,
Log_FoCode,
Log_FoJson,
Log_FoUserID)
values( now(), ?, ?, ?)";
//echo $sql;
$query = $this->db_onedev->query($sql,
array(
$fologcode,
$json_dt_log,
$xuserid
)
);
if (!$query) {
$this->sys_error_db("one_log.fo_log insert");
exit;
}
$result = array(
"total" => 1 ,
"records" => $prm
);
$this->sys_ok($result);
exit;
}
function getdatapromises(){
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$prm = $this->sys_input;
$rows = array();
if(isset($prm['act']) && $prm['act'] == 'save'){
$newpromise = $prm['newpromise'];
foreach($newpromise as $k => $v){
$xdatetime = date('Y-m-d H:i:s',strtotime($v['promisedate'].' '.$v['promisetime']));
$xid = 0;
$sql_xid = $this->db_onedev->query("SELECT * FROM t_orderpromise WHERE T_OrderPromiseT_OrderHeaderID = {$prm['orderid']} AND T_OrderPromiseDateTime = '{$xdatetime}' AND T_OrderPromiseIsActive = 'Y'")->row();
if($sql_xid){
$xid = $sql_xid->T_OrderPromiseID;
}
if($xid == 0){
$sql = "INSERT INTO t_orderpromise (
T_OrderPromiseT_OrderHeaderID,
T_OrderPromiseDateTime
)VALUES(
{$prm['orderid']},
'{$xdatetime}'
)";
$this->db_onedev->query($sql);
}
else{
$sql = "UPDATE t_orderpromise SET T_OrderPromiseT_OrderHeaderID = {$prm['orderid']}, T_OrderPromiseDateTime = '{$xdatetime}' ";
$this->db_onedev->query($sql);
}
}
}else{
$rows = array();
$query =" SELECT 0 as id,
GROUP_CONCAT(CONCAT(T_OrderDetailID,'-',T_OrderDetailT_TestName) separator ',') as testname,
'' as arr_test,
DATE_FORMAT(T_OrderPromiseDateTime,'%d%m%Y %H%i') as promisedatetime,
DATE_FORMAT(T_OrderPromiseDateTime,'%d%m%Y') as promisedate,
DATE_FORMAT(T_OrderPromiseDateTime,'%H%i') as promisetime
FROM t_orderheader
JOIN t_orderdetail ON T_OrderDetailT_OrderHeaderID = T_OrderHeaderID AND
T_OrderDetailIsActive = 'Y' and T_OrderDetailT_TestIsResult = 'Y'
JOIN t_orderpromise ON T_OrderPromiseT_OrderHeaderID = T_OrderHeaderID AND
T_OrderDetailT_OrderPromiseID = T_OrderPromiseID AND T_OrderPromiseIsActive = 'Y'
WHERE
T_OrderHeaderID = {$prm['orderid']}
GROUP BY T_OrderPromiseID
";
//echo $query;
$rows['ok'] = $this->db_onedev->query($query)->result_array();
if($rows['ok']){
foreach($rows['ok'] as $k => $v){
//echo $v{'testname'};
$arr_x = array();
$expl_x_1 = explode(",",$v['testname']);
//print_r($exp_x_1);
foreach($expl_x_1 as $i=>$j){
$expl_x_2 = explode("-",$j);
//print_r($expl_x_2);
array_push($arr_x,array('id'=>$expl_x_2[0],'name'=>$expl_x_2[1]));
}
$rows['ok'][$k]['arr_test'] = $arr_x;
}
}
$query ="
SELECT
T_OrderDetailID as id,
CONCAT(T_OrderDetailID,'-',T_OrderDetailT_TestName) as testname,
'' as arr_test,
DATE_FORMAT(fn_fo_p3k_promise(T_OrderHeaderID),'%d%m%Y %H%i') as promisedatetime,
DATE_FORMAT(fn_fo_p3k_promise(T_OrderHeaderID),'%d%m%Y') as promisedate,
DATE_FORMAT(fn_fo_p3k_promise(T_OrderHeaderID),'%H%i') as promisetime
FROM t_orderheader
JOIN t_orderdetail ON T_OrderDetailT_OrderHeaderID = T_OrderHeaderID AND
T_OrderDetailIsActive = 'Y' and T_OrderDetailT_TestIsResult = 'Y' AND T_OrderDetailT_OrderPromiseID = 0
WHERE
T_OrderHeaderID = {$prm['orderid']}
GROUP BY T_OrderDetailID
";
//echo $query;
$rows['notok'] = $this->db_onedev->query($query)->result_array();
if($rows['notok']){
foreach($rows['notok'] as $k => $v){
//echo $v{'testname'};
$arr_x = array();
$expl_x_1 = explode(",",$v['testname']);
//print_r($exp_x_1);
foreach($expl_x_1 as $i=>$j){
$expl_x_2 = explode("-",$j);
//print_r($expl_x_2);
array_push($arr_x,array('id'=>$expl_x_2[0],'name'=>$expl_x_2[1]));
}
$rows['notok'][$k]['arr_test'] = $arr_x;
}
}
}
$result = array(
"total" => count($rows) ,
"records" => $rows,
);
$this->sys_ok($result);
exit;
}
function search_patient(){
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$prm = $this->sys_input;
$search = '%'.$prm["search"].'%';
$stationid = $prm["stationid"];
$statusid = $prm["statusid"];
$patients = $prm["patients"];
$where_status = '';
if($statusid === 'NEW'){
$where_status = "AND (ISNULL(T_SamplingQueueLastStatusID) OR T_SamplingQueueLastStatusT_SamplingQueueStatusID <> 5 )";
}
else{
$where_status = "AND T_SamplingQueueLastStatusT_SamplingQueueStatusID = 5";
}
// echo $norm;
//$where_status = " AND {$where_status}";
$sql_where = "WHERE T_OrderHeaderLabNumber LIKE '{$search}' AND T_OrderHeaderIsActive = 'Y' {$where_status}";
$rows = [];
$query = "SELECT t_orderheader.*,m_patient.*, IFNULL(M_PatientPhoto,'') as M_PatientPhotoThumb,
M_SexName, M_TitleName, CONCAT(M_TitleName,' ',M_PatientName) as patient_fullname, M_CompanyName,
IF(ISNULL(T_SamplingQueueLastStatusID), 'New',T_SamplingQueueStatusName) as status, DATE_FORMAT(M_PatientDOB,'%d-%m-%Y') as patient_dob,
IF(ISNULL(T_SamplingQueueLastStatusID), 0,T_SamplingQueueLastStatusT_SamplingQueueStatusID) as statusid, T_SampleStationID, T_SampleTypeID,
{$stationid} as stationid,
fn_global_check_is_cito(T_OrderHeaderID) as iscito
FROM t_orderheader
JOIN m_company ON T_OrderHeaderM_CompanyID = M_CompanyID
JOIN m_patient ON T_OrderHeaderM_PatientID = M_PatientID
JOIN m_title ON M_PatientM_TitleID = M_TitleID
JOIN m_sex ON M_PatientM_SexID = M_SexID
JOIN t_orderdetail ON T_OrderDetailT_OrderHeaderID = T_OrderHeaderID
JOIN t_test ON T_OrderDetailT_TestID = T_TestID
JOIN t_sampletype ON T_TestT_SampleTypeID = T_SampleTypeID
JOIN t_bahan ON T_SampleTypeT_BahanID = T_BahanID
JOIN t_samplestation ON T_BahanT_SampleStationID = T_SampleStationID AND T_SampleStationID = {$stationid} AND T_SampleStationIsNonLab = ''
JOIN last_status ON Last_StatusT_OrderHeaderID = T_OrderHeaderID AND ( Last_StatusM_StatusID = 3 OR Last_StatusM_StatusID = 5 )
LEFT JOIN t_sampling_queue_last_status ON
T_SamplingQueueLastStatusT_SampleStationID = T_SampleStationID AND
T_SamplingQueueLastStatusT_OrderHeaderID = T_OrderHeaderID
LEFT JOIN t_sampling_queue_status ON T_SamplingQueueLastStatusT_SamplingQueueStatusID = T_SamplingQueueStatusID
LEFT JOIN t_ordersamplereq ON T_OrderSampleReqT_SampleStationID = T_SampleStationID AND T_OrderSampleReqT_OrderSampleID
$sql_where
GROUP BY T_OrderHeaderID
ORDER BY T_OrderHeaderID DESC
limit 1";
//echo $query;
$rows = $this->db_onedev->query($query)->row();
$result = array(
"total" => count($rows) ,
"records" => $rows,
);
$this->sys_ok($result);
exit;
}
/*function getrequirements($prm){
$query =" SELECT Nat_RequirementID as id,
Nat_RequirementName as name, '{$prm['status']}' as status,
if(ISNULL(T_SamplingSoRequirementID),'N', if(json_contains(T_SamplingSoRequirementRequirements,Nat_RequirementID),'Y','N') ) as chex,
Nat_RequirementPositionNat_PositionID as positionid
FROM nat_requirement
JOIN nat_testrequirement ON Nat_TestRequirementNat_RequirementID = Nat_RequirementID
JOIN nat_requirementposition ON Nat_RequirementPositionNat_RequirementID = Nat_RequirementID AND Nat_RequirementPositionNat_PositionID = 8 AND
Nat_RequirementPositionIsActive = 'Y'
JOIN t_test ON T_TestNat_TestID = Nat_TestRequirementNat_TestID
LEFT JOIN t_samplingso_requirement ON T_SamplingSoRequirementT_OrderHeaderID = {$prm['orderid']} AND
T_SamplingSoRequirementT_SampletypeID = {$prm['sampletypeid']} AND T_SamplingSoRequirementNat_PositionID = Nat_RequirementPositionNat_PositionID
WHERE
Nat_TestRequirementIsActive = 'Y'
";
//echo $query;
$rows = $this->db_onedev->query($query)->result_array();
return $rows;
}*/
function getrequirements($prm){
$rows = array();
$query = "
SELECT Nat_RequirementID as id,
Nat_RequirementName as name, 'P' as status,
if(ISNULL(T_OrderSampleReqID),'N', if(json_contains(T_OrderSampleReqs,Nat_RequirementID),'Y','N') ) as chex,
Nat_RequirementPositionNat_PositionID as positionid
FROM nat_requirement
JOIN nat_testrequirement ON Nat_TestRequirementNat_RequirementID = Nat_RequirementID
JOIN nat_requirementposition ON Nat_RequirementPositionNat_RequirementID = Nat_RequirementID AND Nat_RequirementPositionNat_PositionID = 2 AND
Nat_RequirementPositionIsActive = 'Y'
JOIN t_test ON T_TestNat_TestID = Nat_TestRequirementNat_TestID
JOIN t_barcodelab ON T_barcodeLabT_OrderHeaderID = {$prm['orderid']} AND T_BarcodeLabT_SampleTypeID = {$prm['sampletypeid']}
JOIN t_ordersample ON T_OrderSampleT_OrderHeaderID = {$prm['orderid']} AND T_OrderSampleT_SampleTypeID = {$prm['sampletypeid']} AND
T_OrderSampleT_BarcodeLabID = T_BarcodeLabID AND T_OrderSampleIsActive = 'Y'
LEFT JOIN t_ordersamplereq ON T_OrderSampleReqT_OrderSampleID = T_OrderSampleID AND T_OrderSampleReqT_OrderHeaderID = {$prm['orderid']} AND
T_OrderSampleReqNat_PositionID = Nat_RequirementPositionNat_PositionID
WHERE
Nat_TestRequirementIsActive = 'Y'
GROUP BY nat_requirementID
";
//echo $query;
$rows = $this->db_onedev->query($query)->result_array();
return $rows;
}
function saverequirement(){
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$prm = $this->sys_input;
$query = " INSERT INTO t_samplingso_requirement (
T_SamplingSoRequirementT_OrderHeaderID,
T_SamplingSoRequirementT_SampleStationID,
T_SamplingSoRequirementT_SampletypeID,
T_SamplingSoRequirementStatus,
T_SamplingSoRequirementRequirements,
T_SamplingSoRequirementNote,
T_SamplingSoRequirementNat_PositionID,
T_SamplingSoRequirementUserID,
T_SamplingSoRequirementCreated
)VALUES(
{$prm['T_OrderHeaderID']},
{$prm['stationid']},
{$prm['sample']['T_SampleTypeID']},
'N',
)";
//echo $query;
$rows = $this->db_onedev->query($query)->result_array();
$result = array(
"total" => count($rows) ,
"records" => $rows,
);
$this->sys_ok($result);
exit;
}
function doaction(){
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$rst_data = array('status'=>'OK');
$status_call = array('status'=>'OK','data'=>array());
$prm = $this->sys_input;
$userid = $this->sys_user["M_UserID"];
if($prm['staff']['id'] != 0 || $prm['staff']['id'] != '0' ){
$userid = $prm['staff']['userid'];
}
if($prm['act'] == 'call'){
$sql = "SELECT if(fn_sampling_available_call({$prm['id']},{$prm['stationid']})=0,'Y','N') as status_call";
$sql = "SELECT T_SamplingQueueLastStatusID, T_SamplingQueueStatusName, T_SampleStationName
FROM t_sampling_queue_last_status
JOIN t_sampling_queue_status ON T_SamplingQueueLastStatusT_SamplingQueueStatusID = T_SamplingQueueStatusID
JOIN t_samplestation ON T_SampleStationID = T_SamplingQueueLastStatusT_SampleStationID
WHERE
T_SamplingQueueLastStatusT_OrderHeaderID = {$prm['id']} AND
T_SamplingQueueLastStatusT_SampleStationID <> {$prm['stationid']} AND
T_SamplingQueueLastStatusT_SamplingQueueStatusID IN (1,3) LIMIT 1";
$data_status_call = $this->db_onedev->query($sql)->row_array();
if($data_status_call){
$status_call = array('status'=>'NOTCALL','data'=>$data_status_call);
}
}
$next_status = $prm['statusnextid'];
if($prm['act'] == 'process'){
$sql = "SELECT T_OrderDetailID, T_OrderHeaderID,T_OrderDetailID as id,
T_BarcodeLabID,
T_BarcodeLabBarcode,
T_OrderDetailT_TestCode,
T_OrderDetailT_TestName,
T_SampleTypeID,
T_SampleTypeName,
T_BahanName
FROM t_orderheader
JOIN t_orderdetail ON T_OrderDetailT_OrderHeaderID = T_OrderHeaderID AND T_OrderDetailIsActive = 'Y'
JOIN t_test ON T_OrderDetailT_TestID = T_TestID
JOIN t_sampletype ON T_TestT_SampleTypeID = T_SampleTypeID
JOIN t_barcodelab ON T_BarcodeLabT_OrderHeaderID = T_OrderHeaderID AND T_BarcodeLabT_SampleTypeID = T_SampleTypeID
JOIN t_bahan ON T_SampleTypeT_BahanID = T_BahanID
JOIN t_samplestation ON T_BahanT_SampleStationID = T_SampleStationID AND T_SampleStationID = {$prm['stationid']}
LEFT JOIN t_ordersample ON T_OrderSampleT_OrderHeaderID = T_OrderHeaderID AND T_OrderSampleT_BarcodeLabID = T_BarcodeLabID AND
T_OrderSampleT_SampleTypeID = T_SampleTypeID AND
T_OrderSampleReceive = 'N' AND T_OrderSampleIsActive = 'Y'
LEFT JOIN t_ordersamplereq ON T_OrderSampleReqT_OrderHeaderID = T_OrderHeaderID AND
T_OrderSampleReqT_OrderSampleID = T_OrderSampleID AND
T_OrderSampleReqNat_PositionID = 2 AND
T_OrderSampleReqT_SampleStationID = T_SampleStationID AND
T_OrderSampleReqIsActive = 'Y'
WHERE
T_OrderHeaderID = {$prm['id']} AND T_OrderHeaderIsActive = 'Y'
GROUP BY T_SampleTypeID";
//echo $sql;
$rows_all_sample = $this->db_onedev->query($sql)->result();
if($rows_all_sample){
foreach($rows_all_sample as $k => $v){
$sql = "INSERT INTO t_ordersample (
T_OrderSampleT_OrderHeaderID,
T_OrderSampleT_SampleTypeID,
T_OrderSampleT_BarcodeLabID,
T_OrderSampleCreated,
T_OrderSampleUserID
)
VALUES(
{$prm['id']},
{$v->T_SampleTypeID},
{$v->T_BarcodeLabID},
NOW(),
{$userid}
) ON DUPLICATE KEY UPDATE
T_OrderSampleSampling = 'Y',
T_OrderSampleSamplingDate = CURDATE(),
T_OrderSampleSamplingTime = CURTIME(),
T_OrderSampleSamplingUserID = {$userid},
T_OrderSampleIsActive = 'Y',
T_OrderSampleUserID = {$userid}";
//echo $sql;
$this->db_onedev->query($sql);
}
}
}
if($prm['act'] == 'samplingdone'){
$sql = "INSERT INTO t_ordersample (
T_OrderSampleT_OrderHeaderID,
T_OrderSampleT_SampleTypeID,
T_OrderSampleT_BarcodeLabID,
T_OrderSampleCreated,
T_OrderSampleUserID
)
VALUES(
{$prm['sample']['T_OrderHeaderID']},
{$prm['sample']['T_SampleTypeID']},
{$prm['sample']['T_BarcodeLabID']},
NOW(),
{$userid}
) ON DUPLICATE KEY UPDATE
T_OrderSampleReceiveDate = CURDATE(),
T_OrderSampleReceiveTime = CURTIME(),
T_OrderSampleReceiveUserID = {$userid},
T_OrderSampleReceive = 'Y',
T_OrderSampleIsActive = 'Y',
T_OrderSampleUserID = {$userid}";
$this->db_onedev->query($sql);
$sql = "SELECT * FROM t_ordersample
WHERE T_OrderSampleT_BarcodeLabID = {$prm['sample']['T_BarcodeLabID']} AND T_OrderSampleIsActive = 'Y'
ORDER BY T_OrderSampleID DESC LIMIT 1";
$dt_sampleorder = $this->db_onedev->query($sql)->row();
$sql = "SELECT * FROM t_sampletype WHERE T_SampleTypeID = {$prm['sample']['T_SampleTypeID']}";
$dt_sampletype = $this->db_onedev->query($sql)->row();
//echo $dt_sampleorder->T_OrderSampleReceiveDate;
//echo $dt_sampleorder->T_OrderSampleReceiveTime;
$readytime = date('Y-m-d H:i:s',strtotime($dt_sampleorder->T_OrderSampleReceiveDate.' '.$dt_sampleorder->T_OrderSampleReceiveTime));
//echo $readytime;
if($dt_sampletype->T_SampleTypeAgingOnHold == 'Y'){
$readytime = date('Y-m-d H:i:s',strtotime("+{$dt_sampletype->T_SampleTypeAgingOnHoldTime} minutes",strtotime($dt_sampleorder->T_OrderSampleReceiveDate.' '.$dt_sampleorder->T_OrderSampleReceiveTime)));
//echo $readytime;
}
//echo $readytime;
$sql = "UPDATE t_ordersample
SET T_OrderSampleReadyToProcessDateTime = '{$readytime}'
WHERE
T_OrderSampleT_BarcodeLabID = {$prm['sample']['T_BarcodeLabID']} AND T_OrderSampleIsActive = 'Y' ";
$this->db_onedev->query($sql);
//echo $sql;
$xreq = $prm['sample']['requirements'];
$arr_requirements = array();
foreach($xreq as $k=>$v){
if($v['chex'] == 'Y')
array_push($arr_requirements,$v['id']);
}
$requirements = '['.join(',',$arr_requirements).']';
$sql = "INSERT INTO t_ordersamplereq(
T_OrderSampleReqT_OrderHeaderID,
T_OrderSampleReqT_SampleStationID,
T_OrderSampleReqT_OrderSampleID,
T_OrderSampleReqNat_PositionID,
T_OrderSampleReqStatus,
T_OrderSampleReqs,
T_OrderSampleReqUserID,
T_OrderSampleReqCreated
)
VALUES(
{$prm['sample']['T_OrderHeaderID']},
{$prm['stationid']},
{$prm['sample']['T_OrderSampleID']},
{$prm['sample']['requirements'][0]['positionid']},
'{$prm['sample']['requirement_status']}',
'{$requirements}',
{$userid},
NOW()
)ON DUPLICATE KEY UPDATE
T_OrderSampleReqStatus = '{$prm['sample']['requirement_status']}',
T_OrderSampleReqs = '{$requirements}',
T_OrderSampleReqUserID = {$userid}";
//echo $sql;
$this->db_onedev->query($sql);
$sql = "SELECT count(*) as xcount
FROM (SELECT *
FROM t_orderheader
JOIN t_orderdetail ON T_OrderDetailT_OrderHeaderID = T_OrderHeaderID AND T_OrderDetailIsActive = 'Y'
JOIN t_test ON T_OrderDetailT_TestID = T_TestID
JOIN t_sampletype ON T_TestT_SampleTypeID = T_SampleTypeID
JOIN t_barcodelab ON T_BarcodeLabT_OrderHeaderID = T_OrderHeaderID AND T_BarcodeLabT_SampleTypeID = T_SampleTypeID
JOIN t_bahan ON T_SampleTypeT_BahanID = T_BahanID
JOIN t_samplestation ON T_BahanT_SampleStationID = T_SampleStationID AND T_SampleStationID = {$prm['stationid']}
LEFT JOIN t_ordersample ON T_OrderSampleT_OrderHeaderID = T_OrderHeaderID AND
T_OrderSampleT_SampleTypeID = T_SampleTypeID AND
T_OrderSampleT_BarcodeLabID = T_BarcodeLabID AND
T_OrderSampleIsActive = 'Y'
WHERE
T_OrderHeaderID = {$prm['id']} AND T_OrderSampleT_SampleTypeID <> {$prm['sample']['T_SampleTypeID']} AND
T_OrderSampleReceive = 'N' AND T_OrderHeaderIsActive = 'Y'
GROUP BY T_BarcodeLabID ) xx";
//echo $sql;
$xcount = $this->db_onedev->query($sql)->row()->xcount;
$rst_data = array('status'=>'PARTIAL');
if($xcount == 0){
$next_status = 5;
$rst_data = array('status'=>'OK');
}
}
if($prm['act'] !== 'samplingprocess' && $status_call['status'] == 'OK'){
$dt_json = json_encode(array('T_SampleStationID'=>$prm['stationid'],'T_OrderHeaderID'=>$prm['id'],'T_SamplingQueueStatusID'=>$next_status));
$query = "INSERT INTO one_log.log_sampling_queue (Log_SamplingQueueDate,Log_SamplingQueueJSON,Log_SamplingQueueUserID)
VALUES(NOW(),'{$dt_json}',{$userid})";
//echo $query;
$rows = $this->db_onedev->query($query);
$sql = "SELECT *
FROM t_sampling_queue_last_status
WHERE
T_SamplingQueueLastStatusT_SampleStationID = {$prm['stationid']} AND
T_SamplingQueueLastStatusT_OrderHeaderID = {$prm['id']} AND
T_SamplingQueueLastStatusIsActive = 'Y'";
$data_last = $this->db_onedev->query($sql)->row();
$query = "INSERT INTO t_sampling_queue_last_status (
T_SamplingQueueLastStatusT_SampleStationID,
T_SamplingQueueLastStatusT_OrderHeaderID,
T_SamplingQueueLastStatusT_SamplingQueueStatusID,
T_SamplingQueueLastStatusUserID)
VALUES(
{$prm['stationid']},
{$prm['id']},
{$next_status},
{$userid}) ON DUPLICATE KEY UPDATE T_SamplingQueueLastStatusT_SamplingQueueStatusID = {$next_status}";
//echo $query;
$rows = $this->db_onedev->query($query);
}
if($status_call['status'] == 'NOTCALL'){
$rst_data = $status_call;
}
$result = array(
"total" => 1 ,
"records" => $rst_data
);
$this->sys_ok($result);
exit;
}
function addnewlabel(){
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$rst_data = array('status'=>'OK');
$prm = $this->sys_input;
$userid = $this->sys_user["M_UserID"];
$exp_barcode = explode(".",$prm["sample"]["T_BarcodeLabBarcode"]);
$new_counter = intval($exp_barcode[2])+1;
$new_label = $exp_barcode[0].".".$exp_barcode[1].".".$new_counter ;
$sql = "INSERT INTO t_barcodelab (
T_BarcodeLabT_OrderHeaderID ,
T_BarcodeLabBarcode,
T_BarcodeLabT_SampleTypeID,
T_BarcodeLabUserID
)
VALUES(
{$prm['sample']['T_OrderHeaderID']},
'{$new_label}',
{$prm['sample']['T_SampleTypeID']},
{$userid}
)";
//echo $sql;
$this->db_onedev->query($sql);
$result = array(
"total" => 1 ,
"records" => $rst_data
);
$this->sys_ok($result);
exit;
}
function getdatanoterequirement(){
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$rst_data = array();
$prm = $this->sys_input;
$sql = "SELECT 'fo registration' as position,GROUP_CONCAT(DISTINCT Nat_RequirementName separator ',') as requirements
FROM t_orderheader
JOIN t_orderreq ON T_OrderReqT_OrderHeaderID = T_OrderHeaderID
JOIN nat_requirement ON json_contains(T_OrderReqs,Nat_RequirementID)
WHERE T_OrderHeaderID = {$prm['T_OrderHeaderID']}
GROUP BY T_OrderHeaderID";
//echo $sql;
$query = $this->db_onedev->query($sql)->row_array();
if($query){
array_push($rst_data,$query);
}
$sql = "SELECT 'fo verifikasi' as position, GROUP_CONCAT(DISTINCT Fo_VerificationsLabelName separator ',') as requirements
FROM fo_verificationsvalue
JOIN fo_verificationslabel ON Fo_VerificationsValueFo_VerificationsLabelID = Fo_VerificationsLabelID
WHERE
Fo_VerificationsValueCheck = 'N' AND
Fo_VerificationsValueT_OrderHeaderID = {$prm['T_OrderHeaderID']}
GROUP BY Fo_VerificationsValueT_OrderHeaderID
";
//echo $sql;
$query = $this->db_onedev->query($sql)->row_array();
if($query){
array_push($rst_data,$query);
}
$result = array(
"total" => 1 ,
"records" => $rst_data
);
$this->sys_ok($result);
exit;
}
function savenotesampling(){
if (! $this->isLogin) {
$this->sys_error("Invalid Token");
exit;
}
$rst_data = array();
$prm = $this->sys_input;
$sql = "UPDATE t_orderheader SET T_OrderHeaderSamplingNote = '{$prm['sampling_note']}' WHERE T_OrderHeaderID = {$prm['T_OrderHeaderID']}";
//echo $sql;
$query = $this->db_onedev->query($sql);
$result = array(
"total" => 1 ,
"records" => $rst_data
);
$this->sys_ok($result);
exit;
}
}

View File

@@ -0,0 +1 @@
{"php":"7.0.33-0ubuntu0.16.04.1","version":"2.14.2","rules":{"blank_line_after_namespace":true,"braces":true,"class_definition":true,"elseif":true,"function_declaration":true,"indentation_type":true,"line_ending":true,"lowercase_constants":true,"lowercase_keywords":true,"method_argument_space":{"on_multiline":"ensure_fully_multiline"},"no_break_comment":true,"no_closing_tag":true,"no_spaces_after_function_name":true,"no_spaces_inside_parenthesis":true,"no_trailing_whitespace":true,"no_trailing_whitespace_in_comment":true,"single_blank_line_at_eof":true,"single_class_element_per_statement":{"elements":["property"]},"single_import_per_statement":true,"single_line_after_imports":true,"switch_case_semicolon_to_colon":true,"switch_case_space":true,"visibility_required":true,"encoding":true,"full_opening_tag":true},"hashes":{"Patient.php":3362798707}}

View File

@@ -0,0 +1,62 @@
<?php
class Bank extends MY_Controller
{
var $db_smartone;
public function index()
{
echo "Bank API";
}
public function __construct()
{
parent::__construct();
$this->db_smartone = $this->load->database("onedev", true);
}
public function search()
{
$prm = $this->sys_input;
$sql = "select Nat_BankID, Nat_BankName
from nat_bank
where Nat_BankIsActive = 'Y'
ORDER BY Nat_BankName";
$query = $this->db_smartone->query($sql);
if ($query) {
$rows = $query->result_array();
$result = array("total" => 0, "records" => $rows, "total_display" => sizeof($rows));
$this->sys_ok($result);
}
else {
$this->sys_error_db("BANK rows",$this->db_smartone);
exit;
}
}
public function search_account()
{
$prm = $this->sys_input;
$sql = "select M_BankAccountID, CONCAT(Nat_BankCode, ' no ', M_BankAccountNo) M_BankAccountNo
from nat_bank
JOIN m_bank_account ON M_BankAccountNat_BankID = Nat_BankID AND M_BankAccountIsActive = 'Y'
where Nat_BankIsActive = 'Y'
ORDER BY Nat_BankName";
$query = $this->db_smartone->query($sql);
if ($query) {
$rows = $query->result_array();
$result = array("total" => 0, "records" => $rows, "total_display" => sizeof($rows));
$this->sys_ok($result);
}
else {
$this->sys_error_db("BANK rows",$this->db_smartone);
exit;
}
}
}

View File

@@ -0,0 +1,173 @@
<?php
class Company extends MY_Controller
{
var $db_smartone;
public function index()
{
echo "Company API";
}
public function __construct()
{
parent::__construct();
$this->db_smartone = $this->load->database("onedev", true);
}
function _add_mou(&$companies) {
if (count($companies) == 0) {
return;
}
$company_list= "-1";
foreach($companies as $idx => $c) {
$company_list .= ", " . $c["M_PatientTypeID"];
if (! isset($companies[$idx]["mou"])) $companies[$idx]["mou"] = array();
}
$sql = "select *
from
m_moucompany
where M_MouCompanyM_PatientTypeID in ( $company_list )
and ( M_MouCompanyStartDate <= now() and M_MouCompanyEndDate >= now() )
and M_MouCompanyIsActive = 'Y'";
$query = $this->db_smartone->query($sql);
if ($query) {
$rows= $query->result_array();
foreach($rows as $r) {
$patientTypeID= $r["M_MouCompanyM_PatientTypeID"];
foreach($companies as $idx => $c) {
if($c["M_PatientTypeID"] == $patientTypeID) {
$companies[$idx]["mou"][] = $r;
}
}
}
} else {
$this->sys_error_db("m_moucompany mou",$this->db_smartone);
exit;
}
}
public function search()
{
$prm = $this->sys_input;
$max_rst = 12;
$tot_count =0;
$q = [
'search' => '%'
];
if ($prm['search'] != '')
{
$q['search'] = "%{$prm['search']}%";
}
// QUERY TOTAL
$sql = "select count(*) total
from m_company
join m_mou on M_MouM_CompanyID = M_CompanyID and M_MouIsActive = 'Y'
and M_MouIsApproved = 'Y' and M_MouStartDate <= date(now()) and M_MouEndDate >= date(now()) AND M_MouIsReleased = 'Y'
where M_CompanyIsActive = 'Y'
and M_CompanyName like ?";
$query = $this->db_smartone->query($sql, array($q['search']));
if ($query) {
$tot_count = $query->result_array()[0]["total"];
}
else {
$this->sys_error_db("m_patient count",$this->db_smartone);
exit;
}
$sql = "select M_CompanyID, M_CompanyName,
IFNULL( concat('[', group_concat( json_object('M_MouID', M_MouID, 'M_MouName', M_MouName, 'M_MouStartDate', M_MouStartDate, 'M_MouEndDate', M_MouEndDate, 'M_MouNote', M_MouNote, 'M_MouIsBill', M_MouIsBill, 'M_MouEmail', M_MouEmail, 'M_MouIsDefault', M_MouIsDefault, 'M_MouEmailIsDefault', M_MouEmailIsDefault, 'delivery_email_code', `fn_fo_delivery_code`('MOU', 'EMAIL', '0')) ), ']'), '[]') as mou
from m_company
join m_mou on M_MouM_CompanyID = M_CompanyID and M_MouIsActive = 'Y'
and M_MouIsApproved = 'Y' and M_MouStartDate <= date(now()) and M_MouEndDate >= date(now()) AND M_MouIsReleased = 'Y'
where M_CompanyIsActive = 'Y'
and M_CompanyName like ?
group by m_companyid";
$query = $this->db_smartone->query($sql, array($q['search']));
if ($query) {
$rows = $query->result_array();
foreach ($rows as $k => $v)
$rows[$k]['mou'] = json_decode($v['mou']);
$result = array("total" => $tot_count, "records" => $rows, "total_display" => sizeof($rows));
$this->sys_ok($result);
}
else {
$this->sys_error_db("m_company rows",$this->db_smartone);
exit;
}
}
public function search_default()
{
$prm = $this->sys_input;
$sql = "SELECT M_MouID, M_MouM_CompanyID FROM m_mou
JOIN m_company ON M_CompanyID = M_MouM_CompanyID ANd M_CompanyIsDefault = 'Y' ANd M_CompanyIsActive = 'Y'
WHERE M_MouIsActive = 'Y' ANd M_MouIsDefault = 'Y' AND M_MouIsApproved = 'Y' AND M_MouIsReleased = 'Y'
AND M_MouStartDate <= date(now()) AND M_MouEndDate >= date(now())";
$query = $this->db_smartone->query($sql);
if ($query)
{
$rows = $query->row();
$sql = "select M_CompanyID, M_CompanyName,
IFNULL( concat('[', group_concat( json_object('M_MouID', M_MouID, 'M_MouName', M_MouName, 'M_MouStartDate', M_MouStartDate, 'M_MouEndDate', M_MouEndDate, 'M_MouNote', M_MouNote, 'M_MouIsBill', M_MouIsBill, 'M_MouEmail', M_MouEmail, 'M_MouIsDefault', M_MouIsDefault, 'M_MouEmailIsDefault', M_MouEmailIsDefault, 'delivery_email_code', `fn_fo_delivery_code`('MOU', 'EMAIL', '0')) ), ']'), '[]') as mou
from m_company
join m_mou on M_MouM_CompanyID = M_CompanyID and M_MouIsActive = 'Y'
and M_MouIsApproved = 'Y' and M_MouStartDate <= date(now()) and M_MouEndDate >= date(now()) AND M_MouIsReleased = 'Y'
where M_CompanyID = ?
group by m_companyid";
$query = $this->db_smartone->query($sql, array($rows->M_MouM_CompanyID));
$rows2 = $query->result_array();
foreach ($rows2 as $k => $v)
$rows2[$k]['mou'] = json_decode($v['mou']);
$result = array("total" => 1, "records" => $rows2, "total_display" => sizeof($rows));
$this->sys_ok($result);
}
else
{
$this->sys_error_db("m_company rows", $this->db_smartone);
exit;
}
}
public function search_()
{
$prm = $this->sys_input;
$search = $prm["search"];
$sql_param = array("%$search%");
$sql = "select count(*) total
from
m_patienttype
where
M_PatientTypeName like ? and
M_PatientTypeIsActive = 'Y'";
$query = $this->db_smartone->query($sql, $sql_param);
$tot_count =0;
if ($query) {
$tot_count = $query->result_array()[0]["total"];
} else {
$this->sys_error_db("m_patienttype count", $this->db_smartone);
exit;
}
$sql = "select M_PatientTypeID, M_PatientTypeName
from
m_patienttype
where
M_PatientTypeName like ? and
M_PatientTypeIsActive = 'Y'
limit 0,10";
$query = $this->db_smartone->query($sql,$sql_param);
$rows = $query->result_array();
$this->_add_mou($rows);
$result = array("total" => $tot_count, "records" => $rows );
$this->sys_ok($result);
exit;
}
}

View File

@@ -0,0 +1,55 @@
<?php
class Delivery extends MY_Controller
{
var $db_smartone;
public function index()
{
echo "Patient API";
}
public function __construct()
{
parent::__construct();
$this->db_smartone = $this->load->database("onedev", true);
}
public function search()
{
$prm = $this->sys_input;
$q = [
"patient_id" => 0,
"doctor_id" => 0,
"mou_id" => 0
];
if (isset($prm['patient_id']))
$q["patient_id"] = $prm['patient_id'];
if (isset($prm['doctor_id']))
$q["doctor_id"] = $prm['doctor_id'];
if (isset($prm['mou_id']))
$q["mou_id"] = $prm['mou_id'];
$sql = "CALL sp_fo_delivery_address('', '{$q['patient_id']}', '{$q['doctor_id']}', '{$q['mou_id']}')";
$query = $this->db_smartone->query($sql);
if ($query) {
$rows= $query->row();
$data = json_decode($rows->x);
$result = array("records" => $data);
$this->sys_ok($result);
exit;
} else {
$this->sys_error_db("delivery address",$this->db_smartone);
exit;
}
// $rows = array();
// $rows[] = array("id" =>1, "name" => "Ambil Sendiri", "selected" => false, "note" => "");
// $rows[] = array("id" =>2, "name" => "Kirim ke dokter", "selected" => false, "note" => "");
// $rows[] = array("id" =>3, "name" => "Kirim ke email pasien", "selected" => false, "note" => "");
// $rows[] = array("id" =>4, "name" => "Kirim ke email dokter", "selected" => false, "note" => "");
// $rows[] = array("id" =>5, "name" => "Kirim ke alamat utama pasien", "selected" => false, "note" => "");
// $rows[] = array("id" =>6, "name" => "Kirim ke alamat utama dokter", "selected" => false, "note" => "");
// $rows[] = array("id" =>7, "name" => "Kirim ke rekanan");
}
}

View File

@@ -0,0 +1,242 @@
<?php
class Doctor extends MY_Controller
{
var $db_smartone;
public function index()
{
echo "Doctor API";
}
public function __construct()
{
parent::__construct();
$this->db_smartone = $this->load->database("onedev", true);
}
function _add_address(&$doc) {
if (count($doc) == "0") {
return;
}
$doc_ids = "-1";
foreach($doc as $idx => $d ) {
$doc_ids .= "," . $d["M_DoctorID"];
$doc[$idx]["address"] = array();
}
$sql = "select M_DoctorAddressID,M_DoctorAddressM_DoctorID,
M_DoctorAddressDesc
from
m_doctoraddress
where
M_DoctorAddressM_DoctorID in ( $doc_ids )
and M_DoctorAddressIsActive = 'Y'";
$query = $this->db_smartone->query($sql);
if ($query) {
$rows = $query->result_array();
foreach($rows as $r) {
$doctorID= $r["M_DoctorAddressM_DoctorID"];
foreach($doc as $idx => $d) {
if($d["M_DoctorID"] == $doctorID) {
$doc[$idx]["address"][] = $r;
}
}
}
} else {
$this->sys_error_db("m_doctoraddress ", $this->db_smartone);
exit;
}
}
public function search_pj() {
//sipe : M_DoctorPjIsDefault diganti ke M_DoctorPjIsDefaultPJ
$sql = "select M_DoctorID, fn_global_doctor_name(M_DoctorID) M_DoctorName, M_DoctorPjIsDefaultPj M_DoctorIsDefaultPJ
from m_doctor
join m_doctorpj on M_DoctorPJM_DoctorID = M_DoctorID and M_DoctorPjIsactive = 'Y'
and M_DoctorPjIsPJ = 'Y'
where M_DoctorIsActive = 'Y' and
( M_DoctorPJID is not null ) ";
$query = $this->db_smartone->query($sql, array("%$search%"));
$rows = $query->result_array();
$result = array("total" => count($rows) , "records" => $rows);
$this->sys_ok($result);
exit;
}
public function search()
{
$prm = $this->sys_input;
$max_rst = 12;
$tot_count =0;
$q = [
'search' => '%'
];
if ($prm['search'] != '')
{
$q['search'] = "%{$prm['search']}%";
}
// QUERY TOTAL
$sql = "select count(*) total
from
m_doctor
where M_DoctorIsActive = 'Y'
and M_DoctorName like ?";
$query = $this->db_smartone->query($sql, array($q['search']));
if ($query) {
$tot_count = $query->result_array()[0]["total"];
}
else {
$this->sys_error_db("m_patient count",$this->db_smartone);
exit;
}
$sql = "select M_DoctorID, M_DoctorIsDefault, IF(M_DoctorPJID IS NULL, 'Y', 'N') M_DoctorIsPJ,
fn_global_doctor_name(M_DoctorID) as M_DoctorName, fn_fo_delivery_code('DOCTOR', 'EMAIL', 0) as delivery_email_code,
IF(M_DoctorEmail IS NULL OR M_DoctorEmail = '', 'N', M_DoctorEmailIsDefault) email_default,
IFNULL( concat('[', group_concat(JSON_OBJECT('M_DoctorAddressDescription', M_DoctorAddressDescription, 'M_DoctorAddressID', M_DoctorAddressID, 'delivery_default', M_DoctorAddressDeliveryDefault, 'delivery_code', fn_fo_delivery_code('DOCTOR', 'ADDRESS', M_DoctorAddressID)) SEPARATOR ','), ']'), '[]') as address,
M_DoctorNote
from m_doctor
left join m_doctoraddress on M_DoctorAddressIsActive = 'Y'
and M_DoctorAddressM_DoctorID = M_DoctorID
left join m_doctorpj on M_DoctorPJM_DoctorID = M_DoctorID and M_DoctorPjIsactive = 'Y'
where M_DoctorIsActive = 'Y'
and concat(IFNULL(M_DoctorPrefix, ''),' ',M_DoctorName, ' ', IFNULL(M_DoctorSufix, '')) like ?
group by M_DoctorID
limit 100";
$query = $this->db_smartone->query($sql, array($q['search']));
if ($query) {
$rows = $query->result_array();
foreach ($rows as $k => $v)
$rows[$k]['address'] = json_decode($v['address']);
$result = array("total" => $tot_count, "records" => $rows, "total_display" => sizeof($rows));
$this->sys_ok($result);
}
else {
$this->sys_error_db("m_doctor rows",$this->db_smartone);
exit;
}
}
public function search_()
{
$prm = $this->sys_input;
$search = $prm["search"];
$sql = "select count(*) total
from
m_doctor
join (
select distinct M_DoctorAddressM_DoctorID
from m_doctoraddress
where M_DoctorAddressIsActive = 'Y'
) ma on M_DoctorID = M_DoctorAddressM_DoctorID
where M_DoctorIsActive = 'Y' and M_DoctorName like ? ";
$query = $this->db_smartone->query($sql, array("%$search%"));
$tot_count =0;
if ($query) {
$tot_count = $query->result_array()[0]["total"];
} else {
$this->sys_error_db("m_patient count", $this->db_smartone);
exit;
}
$sql = "select M_DoctorID,M_DoctorName
from
m_doctor
join (
select distinct M_DoctorAddressM_DoctorID
from m_doctoraddress
where M_DoctorAddressIsActive = 'Y'
) ma on M_DoctorID = M_DoctorAddressM_DoctorID
where M_DoctorIsActive = 'Y' and M_DoctorName like ?
limit 0,10";
$query = $this->db_smartone->query($sql, array("%$search%"));
$rows = $query->result_array();
$this->_add_address($rows);
$result = array("total" => $tot_count, "records" => $rows);
$this->sys_ok($result);
exit;
}
public function save()
{
$prm = $this->sys_input;
$prm = $prm['data'];
$q = [
'name' => isset($prm['name']) ? $prm['name'] : '',
'prefix1' => isset($prm['prefix1']) ? $prm['prefix1'] : '',
'prefix2' => isset($prm['prefix2']) ? $prm['prefix2'] : '',
'sufix1' => isset($prm['sufix1']) ? $prm['sufix1'] : '',
'sufix2' => isset($prm['sufix2']) ? $prm['sufix2'] : '',
'sufix3' => isset($prm['sufix3']) ? $prm['sufix3'] : '',
'sex' => isset($prm['sex']) ? $prm['sex'] : '0',
'hp' => isset($prm['hp']) ? $prm['hp'] : '',
'note' => isset($prm['note']) ? $prm['note'] : '',
'address' => isset($prm['address']) ? $prm['address'] : '',
'province' => isset($prm['province']) ? $prm['province'] : '',
'city' => isset($prm['city']) ? $prm['city'] : '',
'district' => isset($prm['district']) ? $prm['district'] : '',
'village' => isset($prm['village']) ? $prm['village'] : ''
];
$sql = "INSERT INTO m_doctor(M_DoctorPrefix,
M_DoctorPrefix2,
M_DoctorName,
M_DoctorSufix,
M_DoctorSufix2,
M_DoctorSufix3,
M_DoctorM_SexID,
M_DoctorHP,
M_DoctorNote)
VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?)";
$query = $this->db_smartone->query($sql, [$q['prefix1'], $q['prefix2'], $q['name'], $q['sufix1'], $q['sufix2'], $q['sufix3'], $q['sex'], $q['hp'], $q['note']]);
if ($query)
{
$id = $this->db_smartone->insert_id();
$sql = "INSERT INTO m_doctoraddress(M_DoctorAddressM_DoctorID,
M_DoctorAddressNote,
M_DoctorAddressDescription,
M_DoctorAddressM_KelurahanID)
VALUES(?, 'Utama', ?, ?)";
$query = $this->db_smartone->query($sql, [$id, $q['address'], $q['village']]);
if ($query)
{
$result = $this->get_one($id);
$this->sys_ok($result);
exit;
}
}
$this->sys_error_db("DOCTOR SAVE", $this->db_smartone);
}
private function get_one($id)
{
$sql = "SELECT M_DoctorID, M_DoctorIsDefault, 'N' M_DoctorIsPJ,
fn_global_doctor_name(M_DoctorID) as M_DoctorName, M_DoctorName M_DoctorRealName,
IFNULL( concat('[', group_concat(JSON_OBJECT('M_DoctorAddressDescription', M_DoctorAddressDescription, 'M_DoctorAddressID', M_DoctorAddressID) SEPARATOR ','), ']'), '[]') as address
FROM m_doctor
LEFT JOIN m_doctoraddress ON M_DoctorAddressM_DoctorID = M_DoctorID AND M_DoctorAddressIsActive = 'Y'
WHERE M_DoctorID = ?";
$query = $this->db_smartone->query($sql, $id);
if ($query)
{
$row = $query->result_array();
foreach ($row as $k => $v)
$row[$k]['address'] = json_decode($v['address']);
$result = array("total" => 1, "records" => $row, "total_display" => 1);
return $result;
}
return false;
}
}

Some files were not shown because too many files have changed in this diff Show More