From 09188c68d9ef62c3f8f1fc6ee675c6bc3f24583a Mon Sep 17 00:00:00 2001 From: Ronald-pro <36841157+Ronald-pro@users.noreply.github.com> Date: Tue, 18 Jan 2022 09:21:23 +0300 Subject: [PATCH 001/171] updated helpdesk contact --- composer.lock | 1994 ++++++++++++++++---------- resources/views/auth/login.blade.php | 208 +-- 2 files changed, 1310 insertions(+), 892 deletions(-) diff --git a/composer.lock b/composer.lock index e6a9ae4..06c0d71 100644 --- a/composer.lock +++ b/composer.lock @@ -8,16 +8,16 @@ "packages": [ { "name": "acaronlex/laravel-calendar", - "version": "1.3", + "version": "1.6", "source": { "type": "git", "url": "https://github.com/acaronlex/laravel-calendar.git", - "reference": "b12cfb7ad1104dd02d3cd2ecc3f391c188e487cb" + "reference": "03490c4990187b1191e2d6686a881502b8cb7439" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/acaronlex/laravel-calendar/zipball/b12cfb7ad1104dd02d3cd2ecc3f391c188e487cb", - "reference": "b12cfb7ad1104dd02d3cd2ecc3f391c188e487cb", + "url": "https://api.github.com/repos/acaronlex/laravel-calendar/zipball/03490c4990187b1191e2d6686a881502b8cb7439", + "reference": "03490c4990187b1191e2d6686a881502b8cb7439", "shasum": "" }, "require": { @@ -51,7 +51,7 @@ } ], "description": "Laravel helper for FullCalendar.io", - "time": "2021-01-18T21:34:10+00:00" + "time": "2021-11-14T19:32:18+00:00" }, { "name": "africastalking/africastalking", @@ -107,22 +107,22 @@ }, { "name": "asm89/stack-cors", - "version": "v2.0.3", + "version": "v2.0.5", "source": { "type": "git", "url": "https://github.com/asm89/stack-cors.git", - "reference": "9cb795bf30988e8c96dd3c40623c48a877bc6714" + "reference": "7a198ec737e926eab15d29368fc6fff66772b0e2" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/asm89/stack-cors/zipball/9cb795bf30988e8c96dd3c40623c48a877bc6714", - "reference": "9cb795bf30988e8c96dd3c40623c48a877bc6714", + "url": "https://api.github.com/repos/asm89/stack-cors/zipball/7a198ec737e926eab15d29368fc6fff66772b0e2", + "reference": "7a198ec737e926eab15d29368fc6fff66772b0e2", "shasum": "" }, "require": { "php": "^7.0|^8.0", - "symfony/http-foundation": "~2.7|~3.0|~4.0|~5.0", - "symfony/http-kernel": "~2.7|~3.0|~4.0|~5.0" + "symfony/http-foundation": "~2.7|~3.0|~4.0|~5.0|~6.0", + "symfony/http-kernel": "~2.7|~3.0|~4.0|~5.0|~6.0" }, "require-dev": { "phpunit/phpunit": "^6|^7|^8|^9", @@ -155,20 +155,20 @@ "cors", "stack" ], - "time": "2021-03-11T06:42:03+00:00" + "time": "2022-01-03T15:27:13+00:00" }, { "name": "brick/math", - "version": "0.9.2", + "version": "0.9.3", "source": { "type": "git", "url": "https://github.com/brick/math.git", - "reference": "dff976c2f3487d42c1db75a3b180e2b9f0e72ce0" + "reference": "ca57d18f028f84f777b2168cd1911b0dee2343ae" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/brick/math/zipball/dff976c2f3487d42c1db75a3b180e2b9f0e72ce0", - "reference": "dff976c2f3487d42c1db75a3b180e2b9f0e72ce0", + "url": "https://api.github.com/repos/brick/math/zipball/ca57d18f028f84f777b2168cd1911b0dee2343ae", + "reference": "ca57d18f028f84f777b2168cd1911b0dee2343ae", "shasum": "" }, "require": { @@ -178,7 +178,7 @@ "require-dev": { "php-coveralls/php-coveralls": "^2.2", "phpunit/phpunit": "^7.5.15 || ^8.5 || ^9.0", - "vimeo/psalm": "4.3.2" + "vimeo/psalm": "4.9.2" }, "type": "library", "autoload": { @@ -201,38 +201,105 @@ "brick", "math" ], - "time": "2021-01-20T22:51:39+00:00" + "time": "2021-08-15T20:50:18+00:00" }, { - "name": "doctrine/inflector", - "version": "2.0.3", + "name": "dflydev/dot-access-data", + "version": "v3.0.1", "source": { "type": "git", - "url": "https://github.com/doctrine/inflector.git", - "reference": "9cf661f4eb38f7c881cac67c75ea9b00bf97b210" + "url": "https://github.com/dflydev/dflydev-dot-access-data.git", + "reference": "0992cc19268b259a39e86f296da5f0677841f42c" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/doctrine/inflector/zipball/9cf661f4eb38f7c881cac67c75ea9b00bf97b210", - "reference": "9cf661f4eb38f7c881cac67c75ea9b00bf97b210", + "url": "https://api.github.com/repos/dflydev/dflydev-dot-access-data/zipball/0992cc19268b259a39e86f296da5f0677841f42c", + "reference": "0992cc19268b259a39e86f296da5f0677841f42c", "shasum": "" }, "require": { - "php": "^7.2 || ^8.0" + "php": "^7.1 || ^8.0" }, "require-dev": { - "doctrine/coding-standard": "^7.0", - "phpstan/phpstan": "^0.11", - "phpstan/phpstan-phpunit": "^0.11", - "phpstan/phpstan-strict-rules": "^0.11", - "phpunit/phpunit": "^7.0 || ^8.0 || ^9.0" + "phpstan/phpstan": "^0.12.42", + "phpunit/phpunit": "^7.5 || ^8.5 || ^9.3", + "scrutinizer/ocular": "1.6.0", + "squizlabs/php_codesniffer": "^3.5", + "vimeo/psalm": "^3.14" }, "type": "library", "extra": { "branch-alias": { - "dev-master": "2.0.x-dev" + "dev-main": "3.x-dev" } }, + "autoload": { + "psr-4": { + "Dflydev\\DotAccessData\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Dragonfly Development Inc.", + "email": "info@dflydev.com", + "homepage": "http://dflydev.com" + }, + { + "name": "Beau Simensen", + "email": "beau@dflydev.com", + "homepage": "http://beausimensen.com" + }, + { + "name": "Carlos Frutos", + "email": "carlos@kiwing.it", + "homepage": "https://github.com/cfrutos" + }, + { + "name": "Colin O'Dell", + "email": "colinodell@gmail.com", + "homepage": "https://www.colinodell.com" + } + ], + "description": "Given a deep data structure, access data by dot notation.", + "homepage": "https://github.com/dflydev/dflydev-dot-access-data", + "keywords": [ + "access", + "data", + "dot", + "notation" + ], + "time": "2021-08-13T13:06:58+00:00" + }, + { + "name": "doctrine/inflector", + "version": "2.0.4", + "source": { + "type": "git", + "url": "https://github.com/doctrine/inflector.git", + "reference": "8b7ff3e4b7de6b2c84da85637b59fd2880ecaa89" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/doctrine/inflector/zipball/8b7ff3e4b7de6b2c84da85637b59fd2880ecaa89", + "reference": "8b7ff3e4b7de6b2c84da85637b59fd2880ecaa89", + "shasum": "" + }, + "require": { + "php": "^7.2 || ^8.0" + }, + "require-dev": { + "doctrine/coding-standard": "^8.2", + "phpstan/phpstan": "^0.12", + "phpstan/phpstan-phpunit": "^0.12", + "phpstan/phpstan-strict-rules": "^0.12", + "phpunit/phpunit": "^7.0 || ^8.0 || ^9.0", + "vimeo/psalm": "^4.10" + }, + "type": "library", "autoload": { "psr-4": { "Doctrine\\Inflector\\": "lib/Doctrine/Inflector" @@ -278,36 +345,32 @@ "uppercase", "words" ], - "time": "2020-05-29T15:13:26+00:00" + "time": "2021-10-22T20:16:43+00:00" }, { "name": "doctrine/lexer", - "version": "1.2.1", + "version": "1.2.2", "source": { "type": "git", "url": "https://github.com/doctrine/lexer.git", - "reference": "e864bbf5904cb8f5bb334f99209b48018522f042" + "reference": "9c50f840f257bbb941e6f4a0e94ccf5db5c3f76c" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/doctrine/lexer/zipball/e864bbf5904cb8f5bb334f99209b48018522f042", - "reference": "e864bbf5904cb8f5bb334f99209b48018522f042", + "url": "https://api.github.com/repos/doctrine/lexer/zipball/9c50f840f257bbb941e6f4a0e94ccf5db5c3f76c", + "reference": "9c50f840f257bbb941e6f4a0e94ccf5db5c3f76c", "shasum": "" }, "require": { - "php": "^7.2 || ^8.0" + "php": "^7.1 || ^8.0" }, "require-dev": { - "doctrine/coding-standard": "^6.0", - "phpstan/phpstan": "^0.11.8", - "phpunit/phpunit": "^8.2" + "doctrine/coding-standard": "^9.0", + "phpstan/phpstan": "1.3", + "phpunit/phpunit": "^7.5 || ^8.5 || ^9.5", + "vimeo/psalm": "^4.11" }, "type": "library", - "extra": { - "branch-alias": { - "dev-master": "1.2.x-dev" - } - }, "autoload": { "psr-4": { "Doctrine\\Common\\Lexer\\": "lib/Doctrine/Common/Lexer" @@ -340,33 +403,33 @@ "parser", "php" ], - "time": "2020-05-25T17:44:05+00:00" + "time": "2022-01-12T08:27:12+00:00" }, { "name": "dragonmantank/cron-expression", - "version": "v3.1.0", + "version": "v3.3.0", "source": { "type": "git", "url": "https://github.com/dragonmantank/cron-expression.git", - "reference": "7a8c6e56ab3ffcc538d05e8155bb42269abf1a0c" + "reference": "63f2a76a045bac6ec93cc2daf2b534b412aa0313" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/dragonmantank/cron-expression/zipball/7a8c6e56ab3ffcc538d05e8155bb42269abf1a0c", - "reference": "7a8c6e56ab3ffcc538d05e8155bb42269abf1a0c", + "url": "https://api.github.com/repos/dragonmantank/cron-expression/zipball/63f2a76a045bac6ec93cc2daf2b534b412aa0313", + "reference": "63f2a76a045bac6ec93cc2daf2b534b412aa0313", "shasum": "" }, "require": { "php": "^7.2|^8.0", - "webmozart/assert": "^1.7.0" + "webmozart/assert": "^1.0" }, "replace": { "mtdowling/cron-expression": "^1.0" }, "require-dev": { "phpstan/extension-installer": "^1.0", - "phpstan/phpstan": "^0.12", - "phpstan/phpstan-webmozart-assert": "^0.12.7", + "phpstan/phpstan": "^1.0", + "phpstan/phpstan-webmozart-assert": "^1.0", "phpunit/phpunit": "^7.0|^8.0|^9.0" }, "type": "library", @@ -391,7 +454,7 @@ "cron", "schedule" ], - "time": "2020-11-24T19:55:57+00:00" + "time": "2022-01-14T16:02:05+00:00" }, { "name": "egulias/email-validator", @@ -453,24 +516,21 @@ }, { "name": "ezyang/htmlpurifier", - "version": "v4.13.0", + "version": "v4.14.0", "source": { "type": "git", "url": "https://github.com/ezyang/htmlpurifier.git", - "reference": "08e27c97e4c6ed02f37c5b2b20488046c8d90d75" + "reference": "12ab42bd6e742c70c0a52f7b82477fcd44e64b75" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/ezyang/htmlpurifier/zipball/08e27c97e4c6ed02f37c5b2b20488046c8d90d75", - "reference": "08e27c97e4c6ed02f37c5b2b20488046c8d90d75", + "url": "https://api.github.com/repos/ezyang/htmlpurifier/zipball/12ab42bd6e742c70c0a52f7b82477fcd44e64b75", + "reference": "12ab42bd6e742c70c0a52f7b82477fcd44e64b75", "shasum": "" }, "require": { "php": ">=5.2" }, - "require-dev": { - "simpletest/simpletest": "dev-master#72de02a7b80c6bb8864ef9bf66d41d2f58f826bd" - }, "type": "library", "autoload": { "psr-0": { @@ -499,7 +559,7 @@ "keywords": [ "html" ], - "time": "2020-06-29T00:56:53+00:00" + "time": "2021-12-25T01:21:49+00:00" }, { "name": "fideloper/proxy", @@ -557,16 +617,16 @@ }, { "name": "fruitcake/laravel-cors", - "version": "v2.0.4", + "version": "v2.0.5", "source": { "type": "git", "url": "https://github.com/fruitcake/laravel-cors.git", - "reference": "a8ccedc7ca95189ead0e407c43b530dc17791d6a" + "reference": "3a066e5cac32e2d1cdaacd6b961692778f37b5fc" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/fruitcake/laravel-cors/zipball/a8ccedc7ca95189ead0e407c43b530dc17791d6a", - "reference": "a8ccedc7ca95189ead0e407c43b530dc17791d6a", + "url": "https://api.github.com/repos/fruitcake/laravel-cors/zipball/3a066e5cac32e2d1cdaacd6b961692778f37b5fc", + "reference": "3a066e5cac32e2d1cdaacd6b961692778f37b5fc", "shasum": "" }, "require": { @@ -574,11 +634,11 @@ "illuminate/contracts": "^6|^7|^8|^9", "illuminate/support": "^6|^7|^8|^9", "php": ">=7.2", - "symfony/http-foundation": "^4|^5", - "symfony/http-kernel": "^4.3.4|^5" + "symfony/http-foundation": "^4|^5|^6", + "symfony/http-kernel": "^4.3.4|^5|^6" }, "require-dev": { - "laravel/framework": "^6|^7|^8", + "laravel/framework": "^6|^7.24|^8", "orchestra/testbench-dusk": "^4|^5|^6|^7", "phpunit/phpunit": "^6|^7|^8|^9", "squizlabs/php_codesniffer": "^3.5" @@ -620,35 +680,30 @@ "crossdomain", "laravel" ], - "time": "2021-04-26T11:24:25+00:00" + "time": "2022-01-03T14:53:04+00:00" }, { "name": "graham-campbell/result-type", - "version": "v1.0.1", + "version": "v1.0.4", "source": { "type": "git", "url": "https://github.com/GrahamCampbell/Result-Type.git", - "reference": "7e279d2cd5d7fbb156ce46daada972355cea27bb" + "reference": "0690bde05318336c7221785f2a932467f98b64ca" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/GrahamCampbell/Result-Type/zipball/7e279d2cd5d7fbb156ce46daada972355cea27bb", - "reference": "7e279d2cd5d7fbb156ce46daada972355cea27bb", + "url": "https://api.github.com/repos/GrahamCampbell/Result-Type/zipball/0690bde05318336c7221785f2a932467f98b64ca", + "reference": "0690bde05318336c7221785f2a932467f98b64ca", "shasum": "" }, "require": { - "php": "^7.0|^8.0", - "phpoption/phpoption": "^1.7.3" + "php": "^7.0 || ^8.0", + "phpoption/phpoption": "^1.8" }, "require-dev": { - "phpunit/phpunit": "^6.5|^7.5|^8.5|^9.0" + "phpunit/phpunit": "^6.5.14 || ^7.5.20 || ^8.5.19 || ^9.5.8" }, "type": "library", - "extra": { - "branch-alias": { - "dev-master": "1.0-dev" - } - }, "autoload": { "psr-4": { "GrahamCampbell\\ResultType\\": "src/" @@ -661,7 +716,8 @@ "authors": [ { "name": "Graham Campbell", - "email": "graham@alt-three.com" + "email": "hello@gjcampbell.co.uk", + "homepage": "https://github.com/GrahamCampbell" } ], "description": "An Implementation Of The Result Type", @@ -672,28 +728,29 @@ "Result-Type", "result" ], - "time": "2020-04-13T13:17:36+00:00" + "time": "2021-11-21T21:41:47+00:00" }, { "name": "guzzlehttp/guzzle", - "version": "7.3.0", + "version": "7.4.1", "source": { "type": "git", "url": "https://github.com/guzzle/guzzle.git", - "reference": "7008573787b430c1c1f650e3722d9bba59967628" + "reference": "ee0a041b1760e6a53d2a39c8c34115adc2af2c79" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/guzzle/guzzle/zipball/7008573787b430c1c1f650e3722d9bba59967628", - "reference": "7008573787b430c1c1f650e3722d9bba59967628", + "url": "https://api.github.com/repos/guzzle/guzzle/zipball/ee0a041b1760e6a53d2a39c8c34115adc2af2c79", + "reference": "ee0a041b1760e6a53d2a39c8c34115adc2af2c79", "shasum": "" }, "require": { "ext-json": "*", - "guzzlehttp/promises": "^1.4", - "guzzlehttp/psr7": "^1.7 || ^2.0", + "guzzlehttp/promises": "^1.5", + "guzzlehttp/psr7": "^1.8.3 || ^2.1", "php": "^7.2.5 || ^8.0", - "psr/http-client": "^1.0" + "psr/http-client": "^1.0", + "symfony/deprecation-contracts": "^2.2 || ^3.0" }, "provide": { "psr/http-client-implementation": "1.0" @@ -703,7 +760,7 @@ "ext-curl": "*", "php-http/client-integration-tests": "^3.0", "phpunit/phpunit": "^8.5.5 || ^9.3.5", - "psr/log": "^1.1" + "psr/log": "^1.1 || ^2.0 || ^3.0" }, "suggest": { "ext-curl": "Required for CURL handler support", @@ -713,7 +770,7 @@ "type": "library", "extra": { "branch-alias": { - "dev-master": "7.3-dev" + "dev-master": "7.4-dev" } }, "autoload": { @@ -729,19 +786,43 @@ "MIT" ], "authors": [ + { + "name": "Graham Campbell", + "email": "hello@gjcampbell.co.uk", + "homepage": "https://github.com/GrahamCampbell" + }, { "name": "Michael Dowling", "email": "mtdowling@gmail.com", "homepage": "https://github.com/mtdowling" }, + { + "name": "Jeremy Lindblom", + "email": "jeremeamia@gmail.com", + "homepage": "https://github.com/jeremeamia" + }, + { + "name": "George Mponos", + "email": "gmponos@gmail.com", + "homepage": "https://github.com/gmponos" + }, + { + "name": "Tobias Nyholm", + "email": "tobias.nyholm@gmail.com", + "homepage": "https://github.com/Nyholm" + }, { "name": "Márk Sági-Kazár", "email": "mark.sagikazar@gmail.com", - "homepage": "https://sagikazarmark.hu" + "homepage": "https://github.com/sagikazarmark" + }, + { + "name": "Tobias Schultze", + "email": "webmaster@tubo-world.de", + "homepage": "https://github.com/Tobion" } ], "description": "Guzzle is a PHP HTTP client library", - "homepage": "http://guzzlephp.org/", "keywords": [ "client", "curl", @@ -753,20 +834,20 @@ "rest", "web service" ], - "time": "2021-03-23T11:33:13+00:00" + "time": "2021-12-06T18:43:05+00:00" }, { "name": "guzzlehttp/promises", - "version": "1.4.1", + "version": "1.5.1", "source": { "type": "git", "url": "https://github.com/guzzle/promises.git", - "reference": "8e7d04f1f6450fef59366c399cfad4b9383aa30d" + "reference": "fe752aedc9fd8fcca3fe7ad05d419d32998a06da" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/guzzle/promises/zipball/8e7d04f1f6450fef59366c399cfad4b9383aa30d", - "reference": "8e7d04f1f6450fef59366c399cfad4b9383aa30d", + "url": "https://api.github.com/repos/guzzle/promises/zipball/fe752aedc9fd8fcca3fe7ad05d419d32998a06da", + "reference": "fe752aedc9fd8fcca3fe7ad05d419d32998a06da", "shasum": "" }, "require": { @@ -778,7 +859,7 @@ "type": "library", "extra": { "branch-alias": { - "dev-master": "1.4-dev" + "dev-master": "1.5-dev" } }, "autoload": { @@ -794,30 +875,45 @@ "MIT" ], "authors": [ + { + "name": "Graham Campbell", + "email": "hello@gjcampbell.co.uk", + "homepage": "https://github.com/GrahamCampbell" + }, { "name": "Michael Dowling", "email": "mtdowling@gmail.com", "homepage": "https://github.com/mtdowling" + }, + { + "name": "Tobias Nyholm", + "email": "tobias.nyholm@gmail.com", + "homepage": "https://github.com/Nyholm" + }, + { + "name": "Tobias Schultze", + "email": "webmaster@tubo-world.de", + "homepage": "https://github.com/Tobion" } ], "description": "Guzzle promises library", "keywords": [ "promise" ], - "time": "2021-03-07T09:25:29+00:00" + "time": "2021-10-22T20:56:57+00:00" }, { "name": "guzzlehttp/psr7", - "version": "2.0.0", + "version": "2.1.0", "source": { "type": "git", "url": "https://github.com/guzzle/psr7.git", - "reference": "1dc8d9cba3897165e16d12bb13d813afb1eb3fe7" + "reference": "089edd38f5b8abba6cb01567c2a8aaa47cec4c72" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/guzzle/psr7/zipball/1dc8d9cba3897165e16d12bb13d813afb1eb3fe7", - "reference": "1dc8d9cba3897165e16d12bb13d813afb1eb3fe7", + "url": "https://api.github.com/repos/guzzle/psr7/zipball/089edd38f5b8abba6cb01567c2a8aaa47cec4c72", + "reference": "089edd38f5b8abba6cb01567c2a8aaa47cec4c72", "shasum": "" }, "require": { @@ -841,7 +937,7 @@ "type": "library", "extra": { "branch-alias": { - "dev-master": "2.0-dev" + "dev-master": "2.1-dev" } }, "autoload": { @@ -854,13 +950,34 @@ "MIT" ], "authors": [ + { + "name": "Graham Campbell", + "email": "hello@gjcampbell.co.uk", + "homepage": "https://github.com/GrahamCampbell" + }, { "name": "Michael Dowling", "email": "mtdowling@gmail.com", "homepage": "https://github.com/mtdowling" }, + { + "name": "George Mponos", + "email": "gmponos@gmail.com", + "homepage": "https://github.com/gmponos" + }, + { + "name": "Tobias Nyholm", + "email": "tobias.nyholm@gmail.com", + "homepage": "https://github.com/Nyholm" + }, + { + "name": "Márk Sági-Kazár", + "email": "mark.sagikazar@gmail.com", + "homepage": "https://github.com/sagikazarmark" + }, { "name": "Tobias Schultze", + "email": "webmaster@tubo-world.de", "homepage": "https://github.com/Tobion" }, { @@ -880,20 +997,20 @@ "uri", "url" ], - "time": "2021-06-30T20:03:07+00:00" + "time": "2021-10-06T17:43:30+00:00" }, { "name": "laravel/framework", - "version": "v8.49.2", + "version": "v8.79.0", "source": { "type": "git", "url": "https://github.com/laravel/framework.git", - "reference": "d9b43ee080b4d51344b2e578aa667f85040471a2" + "reference": "8091f07558ff4a890435ff9d25fa9aca0189ad63" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/laravel/framework/zipball/d9b43ee080b4d51344b2e578aa667f85040471a2", - "reference": "d9b43ee080b4d51344b2e578aa667f85040471a2", + "url": "https://api.github.com/repos/laravel/framework/zipball/8091f07558ff4a890435ff9d25fa9aca0189ad63", + "reference": "8091f07558ff4a890435ff9d25fa9aca0189ad63", "shasum": "" }, "require": { @@ -903,34 +1020,37 @@ "ext-json": "*", "ext-mbstring": "*", "ext-openssl": "*", - "league/commonmark": "^1.3", + "laravel/serializable-closure": "^1.0", + "league/commonmark": "^1.3|^2.0.2", "league/flysystem": "^1.1", "monolog/monolog": "^2.0", - "nesbot/carbon": "^2.31", + "nesbot/carbon": "^2.53.1", "opis/closure": "^3.6", "php": "^7.3|^8.0", "psr/container": "^1.0", + "psr/log": "^1.0|^2.0", "psr/simple-cache": "^1.0", - "ramsey/uuid": "^4.0", - "swiftmailer/swiftmailer": "^6.0", - "symfony/console": "^5.1.4", - "symfony/error-handler": "^5.1.4", - "symfony/finder": "^5.1.4", - "symfony/http-foundation": "^5.1.4", - "symfony/http-kernel": "^5.1.4", - "symfony/mime": "^5.1.4", - "symfony/process": "^5.1.4", - "symfony/routing": "^5.1.4", - "symfony/var-dumper": "^5.1.4", + "ramsey/uuid": "^4.2.2", + "swiftmailer/swiftmailer": "^6.3", + "symfony/console": "^5.4", + "symfony/error-handler": "^5.4", + "symfony/finder": "^5.4", + "symfony/http-foundation": "^5.4", + "symfony/http-kernel": "^5.4", + "symfony/mime": "^5.4", + "symfony/process": "^5.4", + "symfony/routing": "^5.4", + "symfony/var-dumper": "^5.4", "tijsverkoyen/css-to-inline-styles": "^2.2.2", - "vlucas/phpdotenv": "^5.2", + "vlucas/phpdotenv": "^5.4.1", "voku/portable-ascii": "^1.4.8" }, "conflict": { "tightenco/collect": "<5.5.33" }, "provide": { - "psr/container-implementation": "1.0" + "psr/container-implementation": "1.0", + "psr/simple-cache-implementation": "1.0" }, "replace": { "illuminate/auth": "self.version", @@ -966,22 +1086,24 @@ "illuminate/view": "self.version" }, "require-dev": { - "aws/aws-sdk-php": "^3.155", - "doctrine/dbal": "^2.6|^3.0", - "filp/whoops": "^2.8", + "aws/aws-sdk-php": "^3.198.1", + "doctrine/dbal": "^2.13.3|^3.1.4", + "filp/whoops": "^2.14.3", "guzzlehttp/guzzle": "^6.5.5|^7.0.1", "league/flysystem-cached-adapter": "^1.0", - "mockery/mockery": "^1.4.2", - "orchestra/testbench-core": "^6.23", + "mockery/mockery": "^1.4.4", + "orchestra/testbench-core": "^6.27", "pda/pheanstalk": "^4.0", - "phpunit/phpunit": "^8.5.8|^9.3.3", - "predis/predis": "^1.1.2", - "symfony/cache": "^5.1.4" + "phpunit/phpunit": "^8.5.19|^9.5.8", + "predis/predis": "^1.1.9", + "symfony/cache": "^5.4" }, "suggest": { - "aws/aws-sdk-php": "Required to use the SQS queue driver, DynamoDb failed job storage and SES mail driver (^3.155).", + "ably/ably-php": "Required to use the Ably broadcast driver (^1.0).", + "aws/aws-sdk-php": "Required to use the SQS queue driver, DynamoDb failed job storage and SES mail driver (^3.198.1).", "brianium/paratest": "Required to run tests in parallel (^6.0).", - "doctrine/dbal": "Required to rename columns and drop SQLite columns (^2.6|^3.0).", + "doctrine/dbal": "Required to rename columns and drop SQLite columns (^2.13.3|^3.1.4).", + "ext-bcmath": "Required to use the multiple_of validation rule.", "ext-ftp": "Required to use the Flysystem FTP driver.", "ext-gd": "Required to use Illuminate\\Http\\Testing\\FileFactory::image().", "ext-memcached": "Required to use the memcache cache driver.", @@ -989,21 +1111,21 @@ "ext-posix": "Required to use all features of the queue worker.", "ext-redis": "Required to use the Redis cache and queue drivers (^4.0|^5.0).", "fakerphp/faker": "Required to use the eloquent factory builder (^1.9.1).", - "filp/whoops": "Required for friendly error pages in development (^2.8).", + "filp/whoops": "Required for friendly error pages in development (^2.14.3).", "guzzlehttp/guzzle": "Required to use the HTTP Client, Mailgun mail driver and the ping methods on schedules (^6.5.5|^7.0.1).", "laravel/tinker": "Required to use the tinker console command (^2.0).", "league/flysystem-aws-s3-v3": "Required to use the Flysystem S3 driver (^1.0).", "league/flysystem-cached-adapter": "Required to use the Flysystem cache (^1.0).", "league/flysystem-sftp": "Required to use the Flysystem SFTP driver (^1.0).", - "mockery/mockery": "Required to use mocking (^1.4.2).", + "mockery/mockery": "Required to use mocking (^1.4.4).", "nyholm/psr7": "Required to use PSR-7 bridging features (^1.2).", "pda/pheanstalk": "Required to use the beanstalk queue driver (^4.0).", - "phpunit/phpunit": "Required to use assertions and run tests (^8.5.8|^9.3.3).", - "predis/predis": "Required to use the predis connector (^1.1.2).", + "phpunit/phpunit": "Required to use assertions and run tests (^8.5.19|^9.5.8).", + "predis/predis": "Required to use the predis connector (^1.1.9).", "psr/http-message": "Required to allow Storage::put to accept a StreamInterface (^1.0).", - "pusher/pusher-php-server": "Required to use the Pusher broadcast driver (^4.0|^5.0|^6.0).", - "symfony/cache": "Required to PSR-6 cache bridge (^5.1.4).", - "symfony/filesystem": "Required to enable support for relative symbolic links (^5.1.4).", + "pusher/pusher-php-server": "Required to use the Pusher broadcast driver (^4.0|^5.0|^6.0|^7.0).", + "symfony/cache": "Required to PSR-6 cache bridge (^5.4).", + "symfony/filesystem": "Required to enable support for relative symbolic links (^5.4).", "symfony/psr-http-message-bridge": "Required to use PSR-7 bridging features (^2.0).", "wildbit/swiftmailer-postmark": "Required to use Postmark mail driver (^3.0)." }, @@ -1044,36 +1166,91 @@ "framework", "laravel" ], - "time": "2021-07-06T14:06:38+00:00" + "time": "2022-01-12T16:12:41+00:00" + }, + { + "name": "laravel/serializable-closure", + "version": "v1.0.5", + "source": { + "type": "git", + "url": "https://github.com/laravel/serializable-closure.git", + "reference": "25de3be1bca1b17d52ff0dc02b646c667ac7266c" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/laravel/serializable-closure/zipball/25de3be1bca1b17d52ff0dc02b646c667ac7266c", + "reference": "25de3be1bca1b17d52ff0dc02b646c667ac7266c", + "shasum": "" + }, + "require": { + "php": "^7.3|^8.0" + }, + "require-dev": { + "pestphp/pest": "^1.18", + "phpstan/phpstan": "^0.12.98", + "symfony/var-dumper": "^5.3" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.x-dev" + } + }, + "autoload": { + "psr-4": { + "Laravel\\SerializableClosure\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Taylor Otwell", + "email": "taylor@laravel.com" + }, + { + "name": "Nuno Maduro", + "email": "nuno@laravel.com" + } + ], + "description": "Laravel Serializable Closure provides an easy and secure way to serialize closures in PHP.", + "keywords": [ + "closure", + "laravel", + "serializable" + ], + "time": "2021-11-30T15:53:04+00:00" }, { "name": "laravel/tinker", - "version": "v2.6.1", + "version": "v2.7.0", "source": { "type": "git", "url": "https://github.com/laravel/tinker.git", - "reference": "04ad32c1a3328081097a181875733fa51f402083" + "reference": "5f2f9815b7631b9f586a3de7933c25f9327d4073" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/laravel/tinker/zipball/04ad32c1a3328081097a181875733fa51f402083", - "reference": "04ad32c1a3328081097a181875733fa51f402083", + "url": "https://api.github.com/repos/laravel/tinker/zipball/5f2f9815b7631b9f586a3de7933c25f9327d4073", + "reference": "5f2f9815b7631b9f586a3de7933c25f9327d4073", "shasum": "" }, "require": { - "illuminate/console": "^6.0|^7.0|^8.0", - "illuminate/contracts": "^6.0|^7.0|^8.0", - "illuminate/support": "^6.0|^7.0|^8.0", + "illuminate/console": "^6.0|^7.0|^8.0|^9.0", + "illuminate/contracts": "^6.0|^7.0|^8.0|^9.0", + "illuminate/support": "^6.0|^7.0|^8.0|^9.0", "php": "^7.2.5|^8.0", - "psy/psysh": "^0.10.4", - "symfony/var-dumper": "^4.3.4|^5.0" + "psy/psysh": "^0.10.4|^0.11.1", + "symfony/var-dumper": "^4.3.4|^5.0|^6.0" }, "require-dev": { "mockery/mockery": "~1.3.3|^1.4.2", "phpunit/phpunit": "^8.5.8|^9.3.3" }, "suggest": { - "illuminate/database": "The Illuminate Database package (^6.0|^7.0|^8.0)." + "illuminate/database": "The Illuminate Database package (^6.0|^7.0|^8.0|^9.0)." }, "type": "library", "extra": { @@ -1108,29 +1285,32 @@ "laravel", "psysh" ], - "time": "2021-03-02T16:53:12+00:00" + "time": "2022-01-10T08:52:49+00:00" }, { "name": "laravel/ui", - "version": "v3.3.0", + "version": "v3.4.1", "source": { "type": "git", "url": "https://github.com/laravel/ui.git", - "reference": "07d725813350c695c779382cbd6dac0ab8665537" + "reference": "9a1e52442dd238647905b98d773d59e438eb9f9d" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/laravel/ui/zipball/07d725813350c695c779382cbd6dac0ab8665537", - "reference": "07d725813350c695c779382cbd6dac0ab8665537", + "url": "https://api.github.com/repos/laravel/ui/zipball/9a1e52442dd238647905b98d773d59e438eb9f9d", + "reference": "9a1e52442dd238647905b98d773d59e438eb9f9d", "shasum": "" }, "require": { - "illuminate/console": "^8.42", - "illuminate/filesystem": "^8.42", - "illuminate/support": "^8.42", - "illuminate/validation": "^8.42", + "illuminate/console": "^8.42|^9.0", + "illuminate/filesystem": "^8.42|^9.0", + "illuminate/support": "^8.42|^9.0", + "illuminate/validation": "^8.42|^9.0", "php": "^7.3|^8.0" }, + "require-dev": { + "orchestra/testbench": "^6.23|^7.0" + }, "type": "library", "extra": { "branch-alias": { @@ -1163,46 +1343,55 @@ "laravel", "ui" ], - "time": "2021-05-25T16:45:33+00:00" + "time": "2021-12-22T10:40:50+00:00" }, { "name": "league/commonmark", - "version": "1.6.5", + "version": "2.1.1", "source": { "type": "git", "url": "https://github.com/thephpleague/commonmark.git", - "reference": "44ffd8d3c4a9133e4bd0548622b09c55af39db5f" + "reference": "17d2b9cb5161a2ea1a8dd30e6991d668e503fb9d" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/thephpleague/commonmark/zipball/44ffd8d3c4a9133e4bd0548622b09c55af39db5f", - "reference": "44ffd8d3c4a9133e4bd0548622b09c55af39db5f", + "url": "https://api.github.com/repos/thephpleague/commonmark/zipball/17d2b9cb5161a2ea1a8dd30e6991d668e503fb9d", + "reference": "17d2b9cb5161a2ea1a8dd30e6991d668e503fb9d", "shasum": "" }, "require": { "ext-mbstring": "*", - "php": "^7.1 || ^8.0" - }, - "conflict": { - "scrutinizer/ocular": "1.7.*" + "league/config": "^1.1.1", + "php": "^7.4 || ^8.0", + "psr/event-dispatcher": "^1.0", + "symfony/polyfill-php80": "^1.15" }, "require-dev": { - "cebe/markdown": "~1.0", - "commonmark/commonmark.js": "0.29.2", - "erusev/parsedown": "~1.0", + "cebe/markdown": "^1.0", + "commonmark/cmark": "0.30.0", + "commonmark/commonmark.js": "0.30.0", + "composer/package-versions-deprecated": "^1.8", + "erusev/parsedown": "^1.0", "ext-json": "*", "github/gfm": "0.29.0", - "michelf/php-markdown": "~1.4", - "mikehaertl/php-shellcommand": "^1.4", - "phpstan/phpstan": "^0.12.90", - "phpunit/phpunit": "^7.5 || ^8.5 || ^9.2", - "scrutinizer/ocular": "^1.5", - "symfony/finder": "^4.2" + "michelf/php-markdown": "^1.4", + "phpstan/phpstan": "^0.12.88 || ^1.0.0", + "phpunit/phpunit": "^9.5.5", + "scrutinizer/ocular": "^1.8.1", + "symfony/finder": "^5.3", + "symfony/yaml": "^2.3 | ^3.0 | ^4.0 | ^5.0 | ^6.0", + "unleashedtech/php-coding-standard": "^3.1", + "vimeo/psalm": "^4.7.3" + }, + "suggest": { + "symfony/yaml": "v2.3+ required if using the Front Matter extension" }, - "bin": [ - "bin/commonmark" - ], "type": "library", + "extra": { + "branch-alias": { + "dev-main": "2.2-dev" + } + }, "autoload": { "psr-4": { "League\\CommonMark\\": "src" @@ -1220,7 +1409,7 @@ "role": "Lead Developer" } ], - "description": "Highly-extensible PHP Markdown parser which fully supports the CommonMark spec and Github-Flavored Markdown (GFM)", + "description": "Highly-extensible PHP Markdown parser which fully supports the CommonMark spec and GitHub-Flavored Markdown (GFM)", "homepage": "https://commonmark.thephpleague.com", "keywords": [ "commonmark", @@ -1232,20 +1421,82 @@ "md", "parser" ], - "time": "2021-06-26T11:57:13+00:00" + "time": "2022-01-02T18:25:06+00:00" + }, + { + "name": "league/config", + "version": "v1.1.1", + "source": { + "type": "git", + "url": "https://github.com/thephpleague/config.git", + "reference": "a9d39eeeb6cc49d10a6e6c36f22c4c1f4a767f3e" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/thephpleague/config/zipball/a9d39eeeb6cc49d10a6e6c36f22c4c1f4a767f3e", + "reference": "a9d39eeeb6cc49d10a6e6c36f22c4c1f4a767f3e", + "shasum": "" + }, + "require": { + "dflydev/dot-access-data": "^3.0.1", + "nette/schema": "^1.2", + "php": "^7.4 || ^8.0" + }, + "require-dev": { + "phpstan/phpstan": "^0.12.90", + "phpunit/phpunit": "^9.5.5", + "scrutinizer/ocular": "^1.8.1", + "unleashedtech/php-coding-standard": "^3.1", + "vimeo/psalm": "^4.7.3" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-main": "1.2-dev" + } + }, + "autoload": { + "psr-4": { + "League\\Config\\": "src" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Colin O'Dell", + "email": "colinodell@gmail.com", + "homepage": "https://www.colinodell.com", + "role": "Lead Developer" + } + ], + "description": "Define configuration arrays with strict schemas and access values with dot notation", + "homepage": "https://config.thephpleague.com", + "keywords": [ + "array", + "config", + "configuration", + "dot", + "dot-access", + "nested", + "schema" + ], + "time": "2021-08-14T12:15:32+00:00" }, { "name": "league/flysystem", - "version": "1.1.4", + "version": "1.1.9", "source": { "type": "git", "url": "https://github.com/thephpleague/flysystem.git", - "reference": "f3ad69181b8afed2c9edf7be5a2918144ff4ea32" + "reference": "094defdb4a7001845300334e7c1ee2335925ef99" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/thephpleague/flysystem/zipball/f3ad69181b8afed2c9edf7be5a2918144ff4ea32", - "reference": "f3ad69181b8afed2c9edf7be5a2918144ff4ea32", + "url": "https://api.github.com/repos/thephpleague/flysystem/zipball/094defdb4a7001845300334e7c1ee2335925ef99", + "reference": "094defdb4a7001845300334e7c1ee2335925ef99", "shasum": "" }, "require": { @@ -1316,20 +1567,20 @@ "sftp", "storage" ], - "time": "2021-06-23T21:56:05+00:00" + "time": "2021-12-09T09:40:50+00:00" }, { "name": "league/mime-type-detection", - "version": "1.7.0", + "version": "1.9.0", "source": { "type": "git", "url": "https://github.com/thephpleague/mime-type-detection.git", - "reference": "3b9dff8aaf7323590c1d2e443db701eb1f9aa0d3" + "reference": "aa70e813a6ad3d1558fc927863d47309b4c23e69" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/thephpleague/mime-type-detection/zipball/3b9dff8aaf7323590c1d2e443db701eb1f9aa0d3", - "reference": "3b9dff8aaf7323590c1d2e443db701eb1f9aa0d3", + "url": "https://api.github.com/repos/thephpleague/mime-type-detection/zipball/aa70e813a6ad3d1558fc927863d47309b4c23e69", + "reference": "aa70e813a6ad3d1558fc927863d47309b4c23e69", "shasum": "" }, "require": { @@ -1337,7 +1588,7 @@ "php": "^7.2 || ^8.0" }, "require-dev": { - "friendsofphp/php-cs-fixer": "^2.18", + "friendsofphp/php-cs-fixer": "^3.2", "phpstan/phpstan": "^0.12.68", "phpunit/phpunit": "^8.5.8 || ^9.3" }, @@ -1358,20 +1609,20 @@ } ], "description": "Mime-type detection for Flysystem", - "time": "2021-01-18T20:58:21+00:00" + "time": "2021-11-21T11:48:40+00:00" }, { "name": "maatwebsite/excel", - "version": "3.1.32", + "version": "3.1.35", "source": { "type": "git", - "url": "https://github.com/Maatwebsite/Laravel-Excel.git", - "reference": "9dc29b63a77fb7f2f514ef754af3a1b57e83cadf" + "url": "https://github.com/SpartnerNL/Laravel-Excel.git", + "reference": "6f171c8b79e1c0fb254f3ec40f7a11ac79289eaa" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/Maatwebsite/Laravel-Excel/zipball/9dc29b63a77fb7f2f514ef754af3a1b57e83cadf", - "reference": "9dc29b63a77fb7f2f514ef754af3a1b57e83cadf", + "url": "https://api.github.com/repos/SpartnerNL/Laravel-Excel/zipball/6f171c8b79e1c0fb254f3ec40f7a11ac79289eaa", + "reference": "6f171c8b79e1c0fb254f3ec40f7a11ac79289eaa", "shasum": "" }, "require": { @@ -1407,7 +1658,7 @@ "authors": [ { "name": "Patrick Brouwers", - "email": "patrick@maatwebsite.nl" + "email": "patrick@spartner.nl" } ], "description": "Supercharged Excel exports and imports in Laravel", @@ -1422,7 +1673,7 @@ "php", "phpspreadsheet" ], - "time": "2021-07-08T10:11:21+00:00" + "time": "2022-01-04T15:05:43+00:00" }, { "name": "maennchen/zipstream-php", @@ -1487,16 +1738,16 @@ }, { "name": "markbaker/complex", - "version": "2.0.3", + "version": "3.0.1", "source": { "type": "git", "url": "https://github.com/MarkBaker/PHPComplex.git", - "reference": "6f724d7e04606fd8adaa4e3bb381c3e9db09c946" + "reference": "ab8bc271e404909db09ff2d5ffa1e538085c0f22" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/MarkBaker/PHPComplex/zipball/6f724d7e04606fd8adaa4e3bb381c3e9db09c946", - "reference": "6f724d7e04606fd8adaa4e3bb381c3e9db09c946", + "url": "https://api.github.com/repos/MarkBaker/PHPComplex/zipball/ab8bc271e404909db09ff2d5ffa1e538085c0f22", + "reference": "ab8bc271e404909db09ff2d5ffa1e538085c0f22", "shasum": "" }, "require": { @@ -1512,51 +1763,7 @@ "autoload": { "psr-4": { "Complex\\": "classes/src/" - }, - "files": [ - "classes/src/functions/abs.php", - "classes/src/functions/acos.php", - "classes/src/functions/acosh.php", - "classes/src/functions/acot.php", - "classes/src/functions/acoth.php", - "classes/src/functions/acsc.php", - "classes/src/functions/acsch.php", - "classes/src/functions/argument.php", - "classes/src/functions/asec.php", - "classes/src/functions/asech.php", - "classes/src/functions/asin.php", - "classes/src/functions/asinh.php", - "classes/src/functions/atan.php", - "classes/src/functions/atanh.php", - "classes/src/functions/conjugate.php", - "classes/src/functions/cos.php", - "classes/src/functions/cosh.php", - "classes/src/functions/cot.php", - "classes/src/functions/coth.php", - "classes/src/functions/csc.php", - "classes/src/functions/csch.php", - "classes/src/functions/exp.php", - "classes/src/functions/inverse.php", - "classes/src/functions/ln.php", - "classes/src/functions/log2.php", - "classes/src/functions/log10.php", - "classes/src/functions/negative.php", - "classes/src/functions/pow.php", - "classes/src/functions/rho.php", - "classes/src/functions/sec.php", - "classes/src/functions/sech.php", - "classes/src/functions/sin.php", - "classes/src/functions/sinh.php", - "classes/src/functions/sqrt.php", - "classes/src/functions/tan.php", - "classes/src/functions/tanh.php", - "classes/src/functions/theta.php", - "classes/src/operations/add.php", - "classes/src/operations/subtract.php", - "classes/src/operations/multiply.php", - "classes/src/operations/divideby.php", - "classes/src/operations/divideinto.php" - ] + } }, "notification-url": "https://packagist.org/downloads/", "license": [ @@ -1574,20 +1781,20 @@ "complex", "mathematics" ], - "time": "2021-06-02T09:44:11+00:00" + "time": "2021-06-29T15:32:53+00:00" }, { "name": "markbaker/matrix", - "version": "2.1.3", + "version": "3.0.0", "source": { "type": "git", "url": "https://github.com/MarkBaker/PHPMatrix.git", - "reference": "174395a901b5ba0925f1d790fa91bab531074b61" + "reference": "c66aefcafb4f6c269510e9ac46b82619a904c576" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/MarkBaker/PHPMatrix/zipball/174395a901b5ba0925f1d790fa91bab531074b61", - "reference": "174395a901b5ba0925f1d790fa91bab531074b61", + "url": "https://api.github.com/repos/MarkBaker/PHPMatrix/zipball/c66aefcafb4f6c269510e9ac46b82619a904c576", + "reference": "c66aefcafb4f6c269510e9ac46b82619a904c576", "shasum": "" }, "require": { @@ -1607,25 +1814,7 @@ "autoload": { "psr-4": { "Matrix\\": "classes/src/" - }, - "files": [ - "classes/src/Functions/adjoint.php", - "classes/src/Functions/antidiagonal.php", - "classes/src/Functions/cofactors.php", - "classes/src/Functions/determinant.php", - "classes/src/Functions/diagonal.php", - "classes/src/Functions/identity.php", - "classes/src/Functions/inverse.php", - "classes/src/Functions/minors.php", - "classes/src/Functions/trace.php", - "classes/src/Functions/transpose.php", - "classes/src/Operations/add.php", - "classes/src/Operations/directsum.php", - "classes/src/Operations/subtract.php", - "classes/src/Operations/multiply.php", - "classes/src/Operations/divideby.php", - "classes/src/Operations/divideinto.php" - ] + } }, "notification-url": "https://packagist.org/downloads/", "license": [ @@ -1644,28 +1833,28 @@ "matrix", "vector" ], - "time": "2021-05-25T15:42:17+00:00" + "time": "2021-07-01T19:01:15+00:00" }, { "name": "monolog/monolog", - "version": "2.3.0", + "version": "2.3.5", "source": { "type": "git", "url": "https://github.com/Seldaek/monolog.git", - "reference": "df991fd88693ab703aa403413d83e15f688dae33" + "reference": "fd4380d6fc37626e2f799f29d91195040137eba9" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/Seldaek/monolog/zipball/df991fd88693ab703aa403413d83e15f688dae33", - "reference": "df991fd88693ab703aa403413d83e15f688dae33", + "url": "https://api.github.com/repos/Seldaek/monolog/zipball/fd4380d6fc37626e2f799f29d91195040137eba9", + "reference": "fd4380d6fc37626e2f799f29d91195040137eba9", "shasum": "" }, "require": { "php": ">=7.2", - "psr/log": "^1.0.1" + "psr/log": "^1.0.1 || ^2.0 || ^3.0" }, "provide": { - "psr/log-implementation": "1.0.0" + "psr/log-implementation": "1.0.0 || 2.0.0 || 3.0.0" }, "require-dev": { "aws/aws-sdk-php": "^2.4.9 || ^3.0", @@ -1673,14 +1862,14 @@ "elasticsearch/elasticsearch": "^7", "graylog2/gelf-php": "^1.4.2", "mongodb/mongodb": "^1.8", - "php-amqplib/php-amqplib": "~2.4", + "php-amqplib/php-amqplib": "~2.4 || ^3", "php-console/php-console": "^3.1.3", "phpspec/prophecy": "^1.6.1", "phpstan/phpstan": "^0.12.91", "phpunit/phpunit": "^8.5", "predis/predis": "^1.1", "rollbar/rollbar": "^1.3", - "ruflin/elastica": ">=0.90 <7.0.1", + "ruflin/elastica": ">=0.90@dev", "swiftmailer/swiftmailer": "^5.3|^6.0" }, "suggest": { @@ -1688,8 +1877,11 @@ "doctrine/couchdb": "Allow sending log messages to a CouchDB server", "elasticsearch/elasticsearch": "Allow sending log messages to an Elasticsearch server via official client", "ext-amqp": "Allow sending log messages to an AMQP server (1.0+ required)", + "ext-curl": "Required to send log messages using the IFTTTHandler, the LogglyHandler, the SendGridHandler, the SlackWebhookHandler or the TelegramBotHandler", "ext-mbstring": "Allow to work properly with unicode symbols", "ext-mongodb": "Allow sending log messages to a MongoDB server (via driver)", + "ext-openssl": "Required to send log messages using SSL", + "ext-sockets": "Allow sending log messages to a Syslog server (via UDP driver)", "graylog2/gelf-php": "Allow sending log messages to a GrayLog2 server", "mongodb/mongodb": "Allow sending log messages to a MongoDB server (via library)", "php-amqplib/php-amqplib": "Allow sending log messages to an AMQP server using php-amqplib", @@ -1726,7 +1918,7 @@ "logging", "psr-3" ], - "time": "2021-07-05T11:34:13+00:00" + "time": "2021-10-01T21:08:31+00:00" }, { "name": "myclabs/php-enum", @@ -1776,27 +1968,29 @@ }, { "name": "nesbot/carbon", - "version": "2.50.0", + "version": "2.55.2", "source": { "type": "git", "url": "https://github.com/briannesbitt/Carbon.git", - "reference": "f47f17d17602b2243414a44ad53d9f8b9ada5fdb" + "reference": "8c2a18ce3e67c34efc1b29f64fe61304368259a2" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/briannesbitt/Carbon/zipball/f47f17d17602b2243414a44ad53d9f8b9ada5fdb", - "reference": "f47f17d17602b2243414a44ad53d9f8b9ada5fdb", + "url": "https://api.github.com/repos/briannesbitt/Carbon/zipball/8c2a18ce3e67c34efc1b29f64fe61304368259a2", + "reference": "8c2a18ce3e67c34efc1b29f64fe61304368259a2", "shasum": "" }, "require": { "ext-json": "*", "php": "^7.1.8 || ^8.0", "symfony/polyfill-mbstring": "^1.0", - "symfony/translation": "^3.4 || ^4.0 || ^5.0" + "symfony/polyfill-php80": "^1.16", + "symfony/translation": "^3.4 || ^4.0 || ^5.0 || ^6.0" }, "require-dev": { + "doctrine/dbal": "^2.0 || ^3.0", "doctrine/orm": "^2.7", - "friendsofphp/php-cs-fixer": "^2.14 || ^3.0", + "friendsofphp/php-cs-fixer": "^3.0", "kylekatarnls/multi-tester": "^2.0", "phpmd/phpmd": "^2.9", "phpstan/extension-installer": "^1.0", @@ -1810,8 +2004,8 @@ "type": "library", "extra": { "branch-alias": { - "dev-master": "2.x-dev", - "dev-3.x": "3.x-dev" + "dev-3.x": "3.x-dev", + "dev-master": "2.x-dev" }, "laravel": { "providers": [ @@ -1851,20 +2045,159 @@ "datetime", "time" ], - "time": "2021-06-28T22:38:45+00:00" + "time": "2021-12-03T14:59:52+00:00" + }, + { + "name": "nette/schema", + "version": "v1.2.2", + "source": { + "type": "git", + "url": "https://github.com/nette/schema.git", + "reference": "9a39cef03a5b34c7de64f551538cbba05c2be5df" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/nette/schema/zipball/9a39cef03a5b34c7de64f551538cbba05c2be5df", + "reference": "9a39cef03a5b34c7de64f551538cbba05c2be5df", + "shasum": "" + }, + "require": { + "nette/utils": "^2.5.7 || ^3.1.5 || ^4.0", + "php": ">=7.1 <8.2" + }, + "require-dev": { + "nette/tester": "^2.3 || ^2.4", + "phpstan/phpstan-nette": "^0.12", + "tracy/tracy": "^2.7" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.2-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause", + "GPL-2.0-only", + "GPL-3.0-only" + ], + "authors": [ + { + "name": "David Grudl", + "homepage": "https://davidgrudl.com" + }, + { + "name": "Nette Community", + "homepage": "https://nette.org/contributors" + } + ], + "description": "📐 Nette Schema: validating data structures against a given Schema.", + "homepage": "https://nette.org", + "keywords": [ + "config", + "nette" + ], + "time": "2021-10-15T11:40:02+00:00" + }, + { + "name": "nette/utils", + "version": "v3.2.6", + "source": { + "type": "git", + "url": "https://github.com/nette/utils.git", + "reference": "2f261e55bd6a12057442045bf2c249806abc1d02" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/nette/utils/zipball/2f261e55bd6a12057442045bf2c249806abc1d02", + "reference": "2f261e55bd6a12057442045bf2c249806abc1d02", + "shasum": "" + }, + "require": { + "php": ">=7.2 <8.2" + }, + "conflict": { + "nette/di": "<3.0.6" + }, + "require-dev": { + "nette/tester": "~2.0", + "phpstan/phpstan": "^1.0", + "tracy/tracy": "^2.3" + }, + "suggest": { + "ext-gd": "to use Image", + "ext-iconv": "to use Strings::webalize(), toAscii(), chr() and reverse()", + "ext-intl": "to use Strings::webalize(), toAscii(), normalize() and compare()", + "ext-json": "to use Nette\\Utils\\Json", + "ext-mbstring": "to use Strings::lower() etc...", + "ext-tokenizer": "to use Nette\\Utils\\Reflection::getUseStatements()", + "ext-xml": "to use Strings::length() etc. when mbstring is not available" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "3.2-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause", + "GPL-2.0-only", + "GPL-3.0-only" + ], + "authors": [ + { + "name": "David Grudl", + "homepage": "https://davidgrudl.com" + }, + { + "name": "Nette Community", + "homepage": "https://nette.org/contributors" + } + ], + "description": "🛠 Nette Utils: lightweight utilities for string & array manipulation, image handling, safe JSON encoding/decoding, validation, slug or strong password generating etc.", + "homepage": "https://nette.org", + "keywords": [ + "array", + "core", + "datetime", + "images", + "json", + "nette", + "paginator", + "password", + "slugify", + "string", + "unicode", + "utf-8", + "utility", + "validation" + ], + "time": "2021-11-24T15:47:23+00:00" }, { "name": "nikic/php-parser", - "version": "v4.11.0", + "version": "v4.13.2", "source": { "type": "git", "url": "https://github.com/nikic/PHP-Parser.git", - "reference": "fe14cf3672a149364fb66dfe11bf6549af899f94" + "reference": "210577fe3cf7badcc5814d99455df46564f3c077" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/nikic/PHP-Parser/zipball/fe14cf3672a149364fb66dfe11bf6549af899f94", - "reference": "fe14cf3672a149364fb66dfe11bf6549af899f94", + "url": "https://api.github.com/repos/nikic/PHP-Parser/zipball/210577fe3cf7badcc5814d99455df46564f3c077", + "reference": "210577fe3cf7badcc5814d99455df46564f3c077", "shasum": "" }, "require": { @@ -1903,7 +2236,7 @@ "parser", "php" ], - "time": "2021-07-03T13:36:55+00:00" + "time": "2021-11-30T19:35:32+00:00" }, { "name": "opis/closure", @@ -1968,16 +2301,16 @@ }, { "name": "phpoffice/phpspreadsheet", - "version": "1.18.0", + "version": "1.21.0", "source": { "type": "git", "url": "https://github.com/PHPOffice/PhpSpreadsheet.git", - "reference": "418cd304e8e6b417ea79c3b29126a25dc4b1170c" + "reference": "1a359d2ccbb89c05f5dffb32711a95f4afc67964" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/PHPOffice/PhpSpreadsheet/zipball/418cd304e8e6b417ea79c3b29126a25dc4b1170c", - "reference": "418cd304e8e6b417ea79c3b29126a25dc4b1170c", + "url": "https://api.github.com/repos/PHPOffice/PhpSpreadsheet/zipball/1a359d2ccbb89c05f5dffb32711a95f4afc67964", + "reference": "1a359d2ccbb89c05f5dffb32711a95f4afc67964", "shasum": "" }, "require": { @@ -1996,9 +2329,9 @@ "ext-zlib": "*", "ezyang/htmlpurifier": "^4.13", "maennchen/zipstream-php": "^2.1", - "markbaker/complex": "^2.0", - "markbaker/matrix": "^2.0", - "php": "^7.2 || ^8.0", + "markbaker/complex": "^3.0", + "markbaker/matrix": "^3.0", + "php": "^7.3 || ^8.0", "psr/http-client": "^1.0", "psr/http-factory": "^1.0", "psr/simple-cache": "^1.0" @@ -2006,15 +2339,15 @@ "require-dev": { "dealerdirect/phpcodesniffer-composer-installer": "dev-master", "dompdf/dompdf": "^1.0", - "friendsofphp/php-cs-fixer": "^2.18", + "friendsofphp/php-cs-fixer": "^3.2", "jpgraph/jpgraph": "^4.0", "mpdf/mpdf": "^8.0", "phpcompatibility/php-compatibility": "^9.3", - "phpstan/phpstan": "^0.12.82", - "phpstan/phpstan-phpunit": "^0.12.18", - "phpunit/phpunit": "^8.5", - "squizlabs/php_codesniffer": "^3.5", - "tecnickcom/tcpdf": "^6.3" + "phpstan/phpstan": "^1.1", + "phpstan/phpstan-phpunit": "^1.0", + "phpunit/phpunit": "^8.5 || ^9.0", + "squizlabs/php_codesniffer": "^3.6", + "tecnickcom/tcpdf": "^6.4" }, "suggest": { "dompdf/dompdf": "Option for rendering PDF with PDF Writer (doesn't yet support PHP8)", @@ -2064,33 +2397,33 @@ "xls", "xlsx" ], - "time": "2021-05-31T18:21:15+00:00" + "time": "2022-01-06T11:10:08+00:00" }, { "name": "phpoption/phpoption", - "version": "1.7.5", + "version": "1.8.1", "source": { "type": "git", "url": "https://github.com/schmittjoh/php-option.git", - "reference": "994ecccd8f3283ecf5ac33254543eb0ac946d525" + "reference": "eab7a0df01fe2344d172bff4cd6dbd3f8b84ad15" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/schmittjoh/php-option/zipball/994ecccd8f3283ecf5ac33254543eb0ac946d525", - "reference": "994ecccd8f3283ecf5ac33254543eb0ac946d525", + "url": "https://api.github.com/repos/schmittjoh/php-option/zipball/eab7a0df01fe2344d172bff4cd6dbd3f8b84ad15", + "reference": "eab7a0df01fe2344d172bff4cd6dbd3f8b84ad15", "shasum": "" }, "require": { - "php": "^5.5.9 || ^7.0 || ^8.0" + "php": "^7.0 || ^8.0" }, "require-dev": { "bamarni/composer-bin-plugin": "^1.4.1", - "phpunit/phpunit": "^4.8.35 || ^5.7.27 || ^6.5.6 || ^7.0 || ^8.0 || ^9.0" + "phpunit/phpunit": "^6.5.14 || ^7.5.20 || ^8.5.19 || ^9.5.8" }, "type": "library", "extra": { "branch-alias": { - "dev-master": "1.7-dev" + "dev-master": "1.8-dev" } }, "autoload": { @@ -2105,11 +2438,13 @@ "authors": [ { "name": "Johannes M. Schmitt", - "email": "schmittjoh@gmail.com" + "email": "schmittjoh@gmail.com", + "homepage": "https://github.com/schmittjoh" }, { "name": "Graham Campbell", - "email": "graham@alt-three.com" + "email": "hello@gjcampbell.co.uk", + "homepage": "https://github.com/GrahamCampbell" } ], "description": "Option Type for PHP", @@ -2119,24 +2454,24 @@ "php", "type" ], - "time": "2020-07-20T17:29:33+00:00" + "time": "2021-12-04T23:24:31+00:00" }, { "name": "psr/container", - "version": "1.1.1", + "version": "1.1.2", "source": { "type": "git", "url": "https://github.com/php-fig/container.git", - "reference": "8622567409010282b7aeebe4bb841fe98b58dcaf" + "reference": "513e0666f7216c7459170d56df27dfcefe1689ea" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/php-fig/container/zipball/8622567409010282b7aeebe4bb841fe98b58dcaf", - "reference": "8622567409010282b7aeebe4bb841fe98b58dcaf", + "url": "https://api.github.com/repos/php-fig/container/zipball/513e0666f7216c7459170d56df27dfcefe1689ea", + "reference": "513e0666f7216c7459170d56df27dfcefe1689ea", "shasum": "" }, "require": { - "php": ">=7.2.0" + "php": ">=7.4.0" }, "type": "library", "autoload": { @@ -2163,7 +2498,7 @@ "container-interop", "psr" ], - "time": "2021-03-05T17:36:06+00:00" + "time": "2021-11-05T16:50:12+00:00" }, { "name": "psr/event-dispatcher", @@ -2459,29 +2794,29 @@ }, { "name": "psy/psysh", - "version": "v0.10.8", + "version": "v0.11.1", "source": { "type": "git", "url": "https://github.com/bobthecow/psysh.git", - "reference": "e4573f47750dd6c92dca5aee543fa77513cbd8d3" + "reference": "570292577277f06f590635381a7f761a6cf4f026" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/bobthecow/psysh/zipball/e4573f47750dd6c92dca5aee543fa77513cbd8d3", - "reference": "e4573f47750dd6c92dca5aee543fa77513cbd8d3", + "url": "https://api.github.com/repos/bobthecow/psysh/zipball/570292577277f06f590635381a7f761a6cf4f026", + "reference": "570292577277f06f590635381a7f761a6cf4f026", "shasum": "" }, "require": { "ext-json": "*", "ext-tokenizer": "*", - "nikic/php-parser": "~4.0|~3.0|~2.0|~1.3", - "php": "^8.0 || ^7.0 || ^5.5.9", - "symfony/console": "~5.0|~4.0|~3.0|^2.4.2|~2.3.10", - "symfony/var-dumper": "~5.0|~4.0|~3.0|~2.7" + "nikic/php-parser": "^4.0 || ^3.1", + "php": "^8.0 || ^7.0.8", + "symfony/console": "^6.0 || ^5.0 || ^4.0 || ^3.4", + "symfony/var-dumper": "^6.0 || ^5.0 || ^4.0 || ^3.4" }, "require-dev": { "bamarni/composer-bin-plugin": "^1.2", - "hoa/console": "3.17.*" + "hoa/console": "3.17.05.02" }, "suggest": { "ext-pcntl": "Enabling the PCNTL extension makes PsySH a lot happier :)", @@ -2496,7 +2831,7 @@ "type": "library", "extra": { "branch-alias": { - "dev-main": "0.10.x-dev" + "dev-main": "0.11.x-dev" } }, "autoload": { @@ -2526,7 +2861,7 @@ "interactive", "shell" ], - "time": "2021-04-10T16:23:39+00:00" + "time": "2022-01-03T13:58:38+00:00" }, { "name": "ralouphie/getallheaders", @@ -2570,20 +2905,21 @@ }, { "name": "ramsey/collection", - "version": "1.1.3", + "version": "1.2.2", "source": { "type": "git", "url": "https://github.com/ramsey/collection.git", - "reference": "28a5c4ab2f5111db6a60b2b4ec84057e0f43b9c1" + "reference": "cccc74ee5e328031b15640b51056ee8d3bb66c0a" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/ramsey/collection/zipball/28a5c4ab2f5111db6a60b2b4ec84057e0f43b9c1", - "reference": "28a5c4ab2f5111db6a60b2b4ec84057e0f43b9c1", + "url": "https://api.github.com/repos/ramsey/collection/zipball/cccc74ee5e328031b15640b51056ee8d3bb66c0a", + "reference": "cccc74ee5e328031b15640b51056ee8d3bb66c0a", "shasum": "" }, "require": { - "php": "^7.2 || ^8" + "php": "^7.3 || ^8", + "symfony/polyfill-php81": "^1.23" }, "require-dev": { "captainhook/captainhook": "^5.3", @@ -2593,6 +2929,7 @@ "hamcrest/hamcrest-php": "^2", "jangregor/phpstan-prophecy": "^0.8", "mockery/mockery": "^1.3", + "phpspec/prophecy-phpunit": "^2.0", "phpstan/extension-installer": "^1", "phpstan/phpstan": "^0.12.32", "phpstan/phpstan-mockery": "^0.12.5", @@ -2620,7 +2957,7 @@ "homepage": "https://benramsey.com" } ], - "description": "A PHP 7.2+ library for representing and manipulating collections.", + "description": "A PHP library for representing and manipulating collections.", "keywords": [ "array", "collection", @@ -2629,53 +2966,54 @@ "queue", "set" ], - "time": "2021-01-21T17:40:04+00:00" + "time": "2021-10-10T03:01:02+00:00" }, { "name": "ramsey/uuid", - "version": "4.1.1", + "version": "4.2.3", "source": { "type": "git", "url": "https://github.com/ramsey/uuid.git", - "reference": "cd4032040a750077205918c86049aa0f43d22947" + "reference": "fc9bb7fb5388691fd7373cd44dcb4d63bbcf24df" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/ramsey/uuid/zipball/cd4032040a750077205918c86049aa0f43d22947", - "reference": "cd4032040a750077205918c86049aa0f43d22947", + "url": "https://api.github.com/repos/ramsey/uuid/zipball/fc9bb7fb5388691fd7373cd44dcb4d63bbcf24df", + "reference": "fc9bb7fb5388691fd7373cd44dcb4d63bbcf24df", "shasum": "" }, "require": { "brick/math": "^0.8 || ^0.9", "ext-json": "*", - "php": "^7.2 || ^8", + "php": "^7.2 || ^8.0", "ramsey/collection": "^1.0", - "symfony/polyfill-ctype": "^1.8" + "symfony/polyfill-ctype": "^1.8", + "symfony/polyfill-php80": "^1.14" }, "replace": { "rhumsaa/uuid": "self.version" }, "require-dev": { - "codeception/aspect-mock": "^3", - "dealerdirect/phpcodesniffer-composer-installer": "^0.6.2 || ^0.7.0", + "captainhook/captainhook": "^5.10", + "captainhook/plugin-composer": "^5.3", + "dealerdirect/phpcodesniffer-composer-installer": "^0.7.0", "doctrine/annotations": "^1.8", - "goaop/framework": "^2", + "ergebnis/composer-normalize": "^2.15", "mockery/mockery": "^1.3", "moontoast/math": "^1.1", "paragonie/random-lib": "^2", + "php-mock/php-mock": "^2.2", "php-mock/php-mock-mockery": "^1.3", - "php-mock/php-mock-phpunit": "^2.5", "php-parallel-lint/php-parallel-lint": "^1.1", - "phpbench/phpbench": "^0.17.1", + "phpbench/phpbench": "^1.0", "phpstan/extension-installer": "^1.0", "phpstan/phpstan": "^0.12", "phpstan/phpstan-mockery": "^0.12", "phpstan/phpstan-phpunit": "^0.12", - "phpunit/phpunit": "^8.5", - "psy/psysh": "^0.10.0", - "slevomat/coding-standard": "^6.0", + "phpunit/phpunit": "^8.5 || ^9", + "slevomat/coding-standard": "^7.0", "squizlabs/php_codesniffer": "^3.5", - "vimeo/psalm": "3.9.4" + "vimeo/psalm": "^4.9" }, "suggest": { "ext-bcmath": "Enables faster math with arbitrary-precision integers using BCMath.", @@ -2688,7 +3026,10 @@ "type": "library", "extra": { "branch-alias": { - "dev-master": "4.x-dev" + "dev-main": "4.x-dev" + }, + "captainhook": { + "force-install": true } }, "autoload": { @@ -2704,26 +3045,25 @@ "MIT" ], "description": "A PHP library for generating and working with universally unique identifiers (UUIDs).", - "homepage": "https://github.com/ramsey/uuid", "keywords": [ "guid", "identifier", "uuid" ], - "time": "2020-08-18T17:17:46+00:00" + "time": "2021-09-25T23:10:38+00:00" }, { "name": "swiftmailer/swiftmailer", - "version": "v6.2.7", + "version": "v6.3.0", "source": { "type": "git", "url": "https://github.com/swiftmailer/swiftmailer.git", - "reference": "15f7faf8508e04471f666633addacf54c0ab5933" + "reference": "8a5d5072dca8f48460fce2f4131fcc495eec654c" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/swiftmailer/swiftmailer/zipball/15f7faf8508e04471f666633addacf54c0ab5933", - "reference": "15f7faf8508e04471f666633addacf54c0ab5933", + "url": "https://api.github.com/repos/swiftmailer/swiftmailer/zipball/8a5d5072dca8f48460fce2f4131fcc495eec654c", + "reference": "8a5d5072dca8f48460fce2f4131fcc495eec654c", "shasum": "" }, "require": { @@ -2735,7 +3075,7 @@ }, "require-dev": { "mockery/mockery": "^1.0", - "symfony/phpunit-bridge": "^4.4|^5.0" + "symfony/phpunit-bridge": "^4.4|^5.4" }, "suggest": { "ext-intl": "Needed to support internationalized email addresses" @@ -2771,32 +3111,34 @@ "mail", "mailer" ], - "time": "2021-03-09T12:30:35+00:00" + "abandoned": "symfony/mailer", + "time": "2021-10-18T15:26:12+00:00" }, { "name": "symfony/console", - "version": "v5.3.2", + "version": "v5.4.2", "source": { "type": "git", "url": "https://github.com/symfony/console.git", - "reference": "649730483885ff2ca99ca0560ef0e5f6b03f2ac1" + "reference": "a2c6b7ced2eb7799a35375fb9022519282b5405e" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/console/zipball/649730483885ff2ca99ca0560ef0e5f6b03f2ac1", - "reference": "649730483885ff2ca99ca0560ef0e5f6b03f2ac1", + "url": "https://api.github.com/repos/symfony/console/zipball/a2c6b7ced2eb7799a35375fb9022519282b5405e", + "reference": "a2c6b7ced2eb7799a35375fb9022519282b5405e", "shasum": "" }, "require": { "php": ">=7.2.5", - "symfony/deprecation-contracts": "^2.1", + "symfony/deprecation-contracts": "^2.1|^3", "symfony/polyfill-mbstring": "~1.0", - "symfony/polyfill-php73": "^1.8", - "symfony/polyfill-php80": "^1.15", - "symfony/service-contracts": "^1.1|^2", - "symfony/string": "^5.1" + "symfony/polyfill-php73": "^1.9", + "symfony/polyfill-php80": "^1.16", + "symfony/service-contracts": "^1.1|^2|^3", + "symfony/string": "^5.1|^6.0" }, "conflict": { + "psr/log": ">=3", "symfony/dependency-injection": "<4.4", "symfony/dotenv": "<5.1", "symfony/event-dispatcher": "<4.4", @@ -2804,16 +3146,16 @@ "symfony/process": "<4.4" }, "provide": { - "psr/log-implementation": "1.0" + "psr/log-implementation": "1.0|2.0" }, "require-dev": { - "psr/log": "~1.0", - "symfony/config": "^4.4|^5.0", - "symfony/dependency-injection": "^4.4|^5.0", - "symfony/event-dispatcher": "^4.4|^5.0", - "symfony/lock": "^4.4|^5.0", - "symfony/process": "^4.4|^5.0", - "symfony/var-dumper": "^4.4|^5.0" + "psr/log": "^1|^2", + "symfony/config": "^4.4|^5.0|^6.0", + "symfony/dependency-injection": "^4.4|^5.0|^6.0", + "symfony/event-dispatcher": "^4.4|^5.0|^6.0", + "symfony/lock": "^4.4|^5.0|^6.0", + "symfony/process": "^4.4|^5.0|^6.0", + "symfony/var-dumper": "^4.4|^5.0|^6.0" }, "suggest": { "psr/log": "For using the console logger", @@ -2852,24 +3194,25 @@ "console", "terminal" ], - "time": "2021-06-12T09:42:48+00:00" + "time": "2021-12-20T16:11:12+00:00" }, { "name": "symfony/css-selector", - "version": "v5.3.0", + "version": "v5.4.2", "source": { "type": "git", "url": "https://github.com/symfony/css-selector.git", - "reference": "fcd0b29a7a0b1bb5bfbedc6231583d77fea04814" + "reference": "cfcbee910e159df402603502fe387e8b677c22fd" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/css-selector/zipball/fcd0b29a7a0b1bb5bfbedc6231583d77fea04814", - "reference": "fcd0b29a7a0b1bb5bfbedc6231583d77fea04814", + "url": "https://api.github.com/repos/symfony/css-selector/zipball/cfcbee910e159df402603502fe387e8b677c22fd", + "reference": "cfcbee910e159df402603502fe387e8b677c22fd", "shasum": "" }, "require": { - "php": ">=7.2.5" + "php": ">=7.2.5", + "symfony/polyfill-php80": "^1.16" }, "type": "library", "autoload": { @@ -2900,20 +3243,20 @@ ], "description": "Converts CSS selectors to XPath expressions", "homepage": "https://symfony.com", - "time": "2021-05-26T17:40:38+00:00" + "time": "2021-12-16T21:58:21+00:00" }, { "name": "symfony/deprecation-contracts", - "version": "v2.4.0", + "version": "v2.5.0", "source": { "type": "git", "url": "https://github.com/symfony/deprecation-contracts.git", - "reference": "5f38c8804a9e97d23e0c8d63341088cd8a22d627" + "reference": "6f981ee24cf69ee7ce9736146d1c57c2780598a8" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/deprecation-contracts/zipball/5f38c8804a9e97d23e0c8d63341088cd8a22d627", - "reference": "5f38c8804a9e97d23e0c8d63341088cd8a22d627", + "url": "https://api.github.com/repos/symfony/deprecation-contracts/zipball/6f981ee24cf69ee7ce9736146d1c57c2780598a8", + "reference": "6f981ee24cf69ee7ce9736146d1c57c2780598a8", "shasum": "" }, "require": { @@ -2922,7 +3265,7 @@ "type": "library", "extra": { "branch-alias": { - "dev-main": "2.4-dev" + "dev-main": "2.5-dev" }, "thanks": { "name": "symfony/contracts", @@ -2950,33 +3293,35 @@ ], "description": "A generic function and convention to trigger deprecation notices", "homepage": "https://symfony.com", - "time": "2021-03-23T23:28:01+00:00" + "time": "2021-07-12T14:48:14+00:00" }, { "name": "symfony/error-handler", - "version": "v5.3.3", + "version": "v5.4.2", "source": { "type": "git", "url": "https://github.com/symfony/error-handler.git", - "reference": "43323e79c80719e8a4674e33484bca98270d223f" + "reference": "e0c0dd0f9d4120a20158fc9aec2367d07d38bc56" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/error-handler/zipball/43323e79c80719e8a4674e33484bca98270d223f", - "reference": "43323e79c80719e8a4674e33484bca98270d223f", + "url": "https://api.github.com/repos/symfony/error-handler/zipball/e0c0dd0f9d4120a20158fc9aec2367d07d38bc56", + "reference": "e0c0dd0f9d4120a20158fc9aec2367d07d38bc56", "shasum": "" }, "require": { "php": ">=7.2.5", - "psr/log": "^1.0", - "symfony/polyfill-php80": "^1.15", - "symfony/var-dumper": "^4.4|^5.0" + "psr/log": "^1|^2|^3", + "symfony/var-dumper": "^4.4|^5.0|^6.0" }, "require-dev": { - "symfony/deprecation-contracts": "^2.1", - "symfony/http-kernel": "^4.4|^5.0", - "symfony/serializer": "^4.4|^5.0" + "symfony/deprecation-contracts": "^2.1|^3", + "symfony/http-kernel": "^4.4|^5.0|^6.0", + "symfony/serializer": "^4.4|^5.0|^6.0" }, + "bin": [ + "Resources/bin/patch-type-declarations" + ], "type": "library", "autoload": { "psr-4": { @@ -3002,27 +3347,27 @@ ], "description": "Provides tools to manage errors and ease debugging PHP code", "homepage": "https://symfony.com", - "time": "2021-06-24T08:13:00+00:00" + "time": "2021-12-19T20:02:00+00:00" }, { "name": "symfony/event-dispatcher", - "version": "v5.3.0", + "version": "v5.4.0", "source": { "type": "git", "url": "https://github.com/symfony/event-dispatcher.git", - "reference": "67a5f354afa8e2f231081b3fa11a5912f933c3ce" + "reference": "27d39ae126352b9fa3be5e196ccf4617897be3eb" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/event-dispatcher/zipball/67a5f354afa8e2f231081b3fa11a5912f933c3ce", - "reference": "67a5f354afa8e2f231081b3fa11a5912f933c3ce", + "url": "https://api.github.com/repos/symfony/event-dispatcher/zipball/27d39ae126352b9fa3be5e196ccf4617897be3eb", + "reference": "27d39ae126352b9fa3be5e196ccf4617897be3eb", "shasum": "" }, "require": { "php": ">=7.2.5", - "symfony/deprecation-contracts": "^2.1", - "symfony/event-dispatcher-contracts": "^2", - "symfony/polyfill-php80": "^1.15" + "symfony/deprecation-contracts": "^2.1|^3", + "symfony/event-dispatcher-contracts": "^2|^3", + "symfony/polyfill-php80": "^1.16" }, "conflict": { "symfony/dependency-injection": "<4.4" @@ -3032,14 +3377,14 @@ "symfony/event-dispatcher-implementation": "2.0" }, "require-dev": { - "psr/log": "~1.0", - "symfony/config": "^4.4|^5.0", - "symfony/dependency-injection": "^4.4|^5.0", - "symfony/error-handler": "^4.4|^5.0", - "symfony/expression-language": "^4.4|^5.0", - "symfony/http-foundation": "^4.4|^5.0", - "symfony/service-contracts": "^1.1|^2", - "symfony/stopwatch": "^4.4|^5.0" + "psr/log": "^1|^2|^3", + "symfony/config": "^4.4|^5.0|^6.0", + "symfony/dependency-injection": "^4.4|^5.0|^6.0", + "symfony/error-handler": "^4.4|^5.0|^6.0", + "symfony/expression-language": "^4.4|^5.0|^6.0", + "symfony/http-foundation": "^4.4|^5.0|^6.0", + "symfony/service-contracts": "^1.1|^2|^3", + "symfony/stopwatch": "^4.4|^5.0|^6.0" }, "suggest": { "symfony/dependency-injection": "", @@ -3070,20 +3415,20 @@ ], "description": "Provides tools that allow your application components to communicate with each other by dispatching events and listening to them", "homepage": "https://symfony.com", - "time": "2021-05-26T17:43:10+00:00" + "time": "2021-11-23T10:19:22+00:00" }, { "name": "symfony/event-dispatcher-contracts", - "version": "v2.4.0", + "version": "v2.5.0", "source": { "type": "git", "url": "https://github.com/symfony/event-dispatcher-contracts.git", - "reference": "69fee1ad2332a7cbab3aca13591953da9cdb7a11" + "reference": "66bea3b09be61613cd3b4043a65a8ec48cfa6d2a" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/event-dispatcher-contracts/zipball/69fee1ad2332a7cbab3aca13591953da9cdb7a11", - "reference": "69fee1ad2332a7cbab3aca13591953da9cdb7a11", + "url": "https://api.github.com/repos/symfony/event-dispatcher-contracts/zipball/66bea3b09be61613cd3b4043a65a8ec48cfa6d2a", + "reference": "66bea3b09be61613cd3b4043a65a8ec48cfa6d2a", "shasum": "" }, "require": { @@ -3096,7 +3441,7 @@ "type": "library", "extra": { "branch-alias": { - "dev-main": "2.4-dev" + "dev-main": "2.5-dev" }, "thanks": { "name": "symfony/contracts", @@ -3132,24 +3477,26 @@ "interoperability", "standards" ], - "time": "2021-03-23T23:28:01+00:00" + "time": "2021-07-12T14:48:14+00:00" }, { "name": "symfony/finder", - "version": "v5.3.0", + "version": "v5.4.2", "source": { "type": "git", "url": "https://github.com/symfony/finder.git", - "reference": "0ae3f047bed4edff6fd35b26a9a6bfdc92c953c6" + "reference": "e77046c252be48c48a40816187ed527703c8f76c" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/finder/zipball/0ae3f047bed4edff6fd35b26a9a6bfdc92c953c6", - "reference": "0ae3f047bed4edff6fd35b26a9a6bfdc92c953c6", + "url": "https://api.github.com/repos/symfony/finder/zipball/e77046c252be48c48a40816187ed527703c8f76c", + "reference": "e77046c252be48c48a40816187ed527703c8f76c", "shasum": "" }, "require": { - "php": ">=7.2.5" + "php": ">=7.2.5", + "symfony/deprecation-contracts": "^2.1|^3", + "symfony/polyfill-php80": "^1.16" }, "type": "library", "autoload": { @@ -3176,94 +3523,33 @@ ], "description": "Finds files and directories via an intuitive fluent interface", "homepage": "https://symfony.com", - "time": "2021-05-26T12:52:38+00:00" - }, - { - "name": "symfony/http-client-contracts", - "version": "v2.4.0", - "source": { - "type": "git", - "url": "https://github.com/symfony/http-client-contracts.git", - "reference": "7e82f6084d7cae521a75ef2cb5c9457bbda785f4" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/symfony/http-client-contracts/zipball/7e82f6084d7cae521a75ef2cb5c9457bbda785f4", - "reference": "7e82f6084d7cae521a75ef2cb5c9457bbda785f4", - "shasum": "" - }, - "require": { - "php": ">=7.2.5" - }, - "suggest": { - "symfony/http-client-implementation": "" - }, - "type": "library", - "extra": { - "branch-alias": { - "dev-main": "2.4-dev" - }, - "thanks": { - "name": "symfony/contracts", - "url": "https://github.com/symfony/contracts" - } - }, - "autoload": { - "psr-4": { - "Symfony\\Contracts\\HttpClient\\": "" - } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "Nicolas Grekas", - "email": "p@tchwork.com" - }, - { - "name": "Symfony Community", - "homepage": "https://symfony.com/contributors" - } - ], - "description": "Generic abstractions related to HTTP clients", - "homepage": "https://symfony.com", - "keywords": [ - "abstractions", - "contracts", - "decoupling", - "interfaces", - "interoperability", - "standards" - ], - "time": "2021-04-11T23:07:08+00:00" + "time": "2021-12-15T11:06:13+00:00" }, { "name": "symfony/http-foundation", - "version": "v5.3.3", + "version": "v5.4.2", "source": { "type": "git", "url": "https://github.com/symfony/http-foundation.git", - "reference": "0e45ab1574caa0460d9190871a8ce47539e40ccf" + "reference": "ce952af52877eaf3eab5d0c08cc0ea865ed37313" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/http-foundation/zipball/0e45ab1574caa0460d9190871a8ce47539e40ccf", - "reference": "0e45ab1574caa0460d9190871a8ce47539e40ccf", + "url": "https://api.github.com/repos/symfony/http-foundation/zipball/ce952af52877eaf3eab5d0c08cc0ea865ed37313", + "reference": "ce952af52877eaf3eab5d0c08cc0ea865ed37313", "shasum": "" }, "require": { "php": ">=7.2.5", - "symfony/deprecation-contracts": "^2.1", + "symfony/deprecation-contracts": "^2.1|^3", "symfony/polyfill-mbstring": "~1.1", - "symfony/polyfill-php80": "^1.15" + "symfony/polyfill-php80": "^1.16" }, "require-dev": { "predis/predis": "~1.0", - "symfony/cache": "^4.4|^5.0", - "symfony/expression-language": "^4.4|^5.0", - "symfony/mime": "^4.4|^5.0" + "symfony/cache": "^4.4|^5.0|^6.0", + "symfony/expression-language": "^4.4|^5.0|^6.0", + "symfony/mime": "^4.4|^5.0|^6.0" }, "suggest": { "symfony/mime": "To use the file extension guesser" @@ -3293,36 +3579,35 @@ ], "description": "Defines an object-oriented layer for the HTTP specification", "homepage": "https://symfony.com", - "time": "2021-06-27T09:19:40+00:00" + "time": "2021-12-28T17:15:56+00:00" }, { "name": "symfony/http-kernel", - "version": "v5.3.3", + "version": "v5.4.2", "source": { "type": "git", "url": "https://github.com/symfony/http-kernel.git", - "reference": "90ad9f4b21ddcb8ebe9faadfcca54929ad23f9f8" + "reference": "35b7e9868953e0d1df84320bb063543369e43ef5" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/http-kernel/zipball/90ad9f4b21ddcb8ebe9faadfcca54929ad23f9f8", - "reference": "90ad9f4b21ddcb8ebe9faadfcca54929ad23f9f8", + "url": "https://api.github.com/repos/symfony/http-kernel/zipball/35b7e9868953e0d1df84320bb063543369e43ef5", + "reference": "35b7e9868953e0d1df84320bb063543369e43ef5", "shasum": "" }, "require": { "php": ">=7.2.5", - "psr/log": "~1.0", - "symfony/deprecation-contracts": "^2.1", - "symfony/error-handler": "^4.4|^5.0", - "symfony/event-dispatcher": "^5.0", - "symfony/http-client-contracts": "^1.1|^2", - "symfony/http-foundation": "^5.3", + "psr/log": "^1|^2", + "symfony/deprecation-contracts": "^2.1|^3", + "symfony/error-handler": "^4.4|^5.0|^6.0", + "symfony/event-dispatcher": "^5.0|^6.0", + "symfony/http-foundation": "^5.3.7|^6.0", "symfony/polyfill-ctype": "^1.8", "symfony/polyfill-php73": "^1.9", - "symfony/polyfill-php80": "^1.15" + "symfony/polyfill-php80": "^1.16" }, "conflict": { - "symfony/browser-kit": "<4.4", + "symfony/browser-kit": "<5.4", "symfony/cache": "<5.0", "symfony/config": "<5.0", "symfony/console": "<4.4", @@ -3338,23 +3623,24 @@ "twig/twig": "<2.13" }, "provide": { - "psr/log-implementation": "1.0" + "psr/log-implementation": "1.0|2.0" }, "require-dev": { "psr/cache": "^1.0|^2.0|^3.0", - "symfony/browser-kit": "^4.4|^5.0", - "symfony/config": "^5.0", - "symfony/console": "^4.4|^5.0", - "symfony/css-selector": "^4.4|^5.0", - "symfony/dependency-injection": "^5.3", - "symfony/dom-crawler": "^4.4|^5.0", - "symfony/expression-language": "^4.4|^5.0", - "symfony/finder": "^4.4|^5.0", - "symfony/process": "^4.4|^5.0", - "symfony/routing": "^4.4|^5.0", - "symfony/stopwatch": "^4.4|^5.0", - "symfony/translation": "^4.4|^5.0", - "symfony/translation-contracts": "^1.1|^2", + "symfony/browser-kit": "^5.4|^6.0", + "symfony/config": "^5.0|^6.0", + "symfony/console": "^4.4|^5.0|^6.0", + "symfony/css-selector": "^4.4|^5.0|^6.0", + "symfony/dependency-injection": "^5.3|^6.0", + "symfony/dom-crawler": "^4.4|^5.0|^6.0", + "symfony/expression-language": "^4.4|^5.0|^6.0", + "symfony/finder": "^4.4|^5.0|^6.0", + "symfony/http-client-contracts": "^1.1|^2|^3", + "symfony/process": "^4.4|^5.0|^6.0", + "symfony/routing": "^4.4|^5.0|^6.0", + "symfony/stopwatch": "^4.4|^5.0|^6.0", + "symfony/translation": "^4.4|^5.0|^6.0", + "symfony/translation-contracts": "^1.1|^2|^3", "twig/twig": "^2.13|^3.0.4" }, "suggest": { @@ -3388,28 +3674,28 @@ ], "description": "Provides a structured process for converting a Request into a Response", "homepage": "https://symfony.com", - "time": "2021-06-30T08:27:49+00:00" + "time": "2021-12-29T13:20:26+00:00" }, { "name": "symfony/mime", - "version": "v5.3.2", + "version": "v5.4.2", "source": { "type": "git", "url": "https://github.com/symfony/mime.git", - "reference": "47dd7912152b82d0d4c8d9040dbc93d6232d472a" + "reference": "1bfd938cf9562822c05c4d00e8f92134d3c8e42d" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/mime/zipball/47dd7912152b82d0d4c8d9040dbc93d6232d472a", - "reference": "47dd7912152b82d0d4c8d9040dbc93d6232d472a", + "url": "https://api.github.com/repos/symfony/mime/zipball/1bfd938cf9562822c05c4d00e8f92134d3c8e42d", + "reference": "1bfd938cf9562822c05c4d00e8f92134d3c8e42d", "shasum": "" }, "require": { "php": ">=7.2.5", - "symfony/deprecation-contracts": "^2.1", + "symfony/deprecation-contracts": "^2.1|^3", "symfony/polyfill-intl-idn": "^1.10", "symfony/polyfill-mbstring": "^1.0", - "symfony/polyfill-php80": "^1.15" + "symfony/polyfill-php80": "^1.16" }, "conflict": { "egulias/email-validator": "~3.0.0", @@ -3420,10 +3706,10 @@ "require-dev": { "egulias/email-validator": "^2.1.10|^3.1", "phpdocumentor/reflection-docblock": "^3.0|^4.0|^5.0", - "symfony/dependency-injection": "^4.4|^5.0", - "symfony/property-access": "^4.4|^5.1", - "symfony/property-info": "^4.4|^5.1", - "symfony/serializer": "^5.2" + "symfony/dependency-injection": "^4.4|^5.0|^6.0", + "symfony/property-access": "^4.4|^5.1|^6.0", + "symfony/property-info": "^4.4|^5.1|^6.0", + "symfony/serializer": "^5.2|^6.0" }, "type": "library", "autoload": { @@ -3454,25 +3740,28 @@ "mime", "mime-type" ], - "time": "2021-06-09T10:58:01+00:00" + "time": "2021-12-28T17:15:56+00:00" }, { "name": "symfony/polyfill-ctype", - "version": "v1.23.0", + "version": "v1.24.0", "source": { "type": "git", "url": "https://github.com/symfony/polyfill-ctype.git", - "reference": "46cd95797e9df938fdd2b03693b5fca5e64b01ce" + "reference": "30885182c981ab175d4d034db0f6f469898070ab" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/polyfill-ctype/zipball/46cd95797e9df938fdd2b03693b5fca5e64b01ce", - "reference": "46cd95797e9df938fdd2b03693b5fca5e64b01ce", + "url": "https://api.github.com/repos/symfony/polyfill-ctype/zipball/30885182c981ab175d4d034db0f6f469898070ab", + "reference": "30885182c981ab175d4d034db0f6f469898070ab", "shasum": "" }, "require": { "php": ">=7.1" }, + "provide": { + "ext-ctype": "*" + }, "suggest": { "ext-ctype": "For best performance" }, @@ -3516,25 +3805,28 @@ "polyfill", "portable" ], - "time": "2021-02-19T12:13:01+00:00" + "time": "2021-10-20T20:35:02+00:00" }, { "name": "symfony/polyfill-iconv", - "version": "v1.23.0", + "version": "v1.24.0", "source": { "type": "git", "url": "https://github.com/symfony/polyfill-iconv.git", - "reference": "63b5bb7db83e5673936d6e3b8b3e022ff6474933" + "reference": "f1aed619e28cb077fc83fac8c4c0383578356e40" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/polyfill-iconv/zipball/63b5bb7db83e5673936d6e3b8b3e022ff6474933", - "reference": "63b5bb7db83e5673936d6e3b8b3e022ff6474933", + "url": "https://api.github.com/repos/symfony/polyfill-iconv/zipball/f1aed619e28cb077fc83fac8c4c0383578356e40", + "reference": "f1aed619e28cb077fc83fac8c4c0383578356e40", "shasum": "" }, "require": { "php": ">=7.1" }, + "provide": { + "ext-iconv": "*" + }, "suggest": { "ext-iconv": "For best performance" }, @@ -3579,20 +3871,20 @@ "portable", "shim" ], - "time": "2021-05-27T09:27:20+00:00" + "time": "2022-01-04T09:04:05+00:00" }, { "name": "symfony/polyfill-intl-grapheme", - "version": "v1.23.0", + "version": "v1.24.0", "source": { "type": "git", "url": "https://github.com/symfony/polyfill-intl-grapheme.git", - "reference": "24b72c6baa32c746a4d0840147c9715e42bb68ab" + "reference": "81b86b50cf841a64252b439e738e97f4a34e2783" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/polyfill-intl-grapheme/zipball/24b72c6baa32c746a4d0840147c9715e42bb68ab", - "reference": "24b72c6baa32c746a4d0840147c9715e42bb68ab", + "url": "https://api.github.com/repos/symfony/polyfill-intl-grapheme/zipball/81b86b50cf841a64252b439e738e97f4a34e2783", + "reference": "81b86b50cf841a64252b439e738e97f4a34e2783", "shasum": "" }, "require": { @@ -3643,20 +3935,20 @@ "portable", "shim" ], - "time": "2021-05-27T09:17:38+00:00" + "time": "2021-11-23T21:10:46+00:00" }, { "name": "symfony/polyfill-intl-idn", - "version": "v1.23.0", + "version": "v1.24.0", "source": { "type": "git", "url": "https://github.com/symfony/polyfill-intl-idn.git", - "reference": "65bd267525e82759e7d8c4e8ceea44f398838e65" + "reference": "749045c69efb97c70d25d7463abba812e91f3a44" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/polyfill-intl-idn/zipball/65bd267525e82759e7d8c4e8ceea44f398838e65", - "reference": "65bd267525e82759e7d8c4e8ceea44f398838e65", + "url": "https://api.github.com/repos/symfony/polyfill-intl-idn/zipball/749045c69efb97c70d25d7463abba812e91f3a44", + "reference": "749045c69efb97c70d25d7463abba812e91f3a44", "shasum": "" }, "require": { @@ -3713,11 +4005,11 @@ "portable", "shim" ], - "time": "2021-05-27T09:27:20+00:00" + "time": "2021-09-14T14:02:44+00:00" }, { "name": "symfony/polyfill-intl-normalizer", - "version": "v1.23.0", + "version": "v1.24.0", "source": { "type": "git", "url": "https://github.com/symfony/polyfill-intl-normalizer.git", @@ -3784,21 +4076,24 @@ }, { "name": "symfony/polyfill-mbstring", - "version": "v1.23.0", + "version": "v1.24.0", "source": { "type": "git", "url": "https://github.com/symfony/polyfill-mbstring.git", - "reference": "2df51500adbaebdc4c38dea4c89a2e131c45c8a1" + "reference": "0abb51d2f102e00a4eefcf46ba7fec406d245825" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/polyfill-mbstring/zipball/2df51500adbaebdc4c38dea4c89a2e131c45c8a1", - "reference": "2df51500adbaebdc4c38dea4c89a2e131c45c8a1", + "url": "https://api.github.com/repos/symfony/polyfill-mbstring/zipball/0abb51d2f102e00a4eefcf46ba7fec406d245825", + "reference": "0abb51d2f102e00a4eefcf46ba7fec406d245825", "shasum": "" }, "require": { "php": ">=7.1" }, + "provide": { + "ext-mbstring": "*" + }, "suggest": { "ext-mbstring": "For best performance" }, @@ -3843,11 +4138,11 @@ "portable", "shim" ], - "time": "2021-05-27T09:27:20+00:00" + "time": "2021-11-30T18:21:41+00:00" }, { "name": "symfony/polyfill-php72", - "version": "v1.23.0", + "version": "v1.24.0", "source": { "type": "git", "url": "https://github.com/symfony/polyfill-php72.git", @@ -3906,16 +4201,16 @@ }, { "name": "symfony/polyfill-php73", - "version": "v1.23.0", + "version": "v1.24.0", "source": { "type": "git", "url": "https://github.com/symfony/polyfill-php73.git", - "reference": "fba8933c384d6476ab14fb7b8526e5287ca7e010" + "reference": "cc5db0e22b3cb4111010e48785a97f670b350ca5" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/polyfill-php73/zipball/fba8933c384d6476ab14fb7b8526e5287ca7e010", - "reference": "fba8933c384d6476ab14fb7b8526e5287ca7e010", + "url": "https://api.github.com/repos/symfony/polyfill-php73/zipball/cc5db0e22b3cb4111010e48785a97f670b350ca5", + "reference": "cc5db0e22b3cb4111010e48785a97f670b350ca5", "shasum": "" }, "require": { @@ -3964,20 +4259,20 @@ "portable", "shim" ], - "time": "2021-02-19T12:13:01+00:00" + "time": "2021-06-05T21:20:04+00:00" }, { "name": "symfony/polyfill-php80", - "version": "v1.23.0", + "version": "v1.24.0", "source": { "type": "git", "url": "https://github.com/symfony/polyfill-php80.git", - "reference": "eca0bf41ed421bed1b57c4958bab16aa86b757d0" + "reference": "57b712b08eddb97c762a8caa32c84e037892d2e9" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/polyfill-php80/zipball/eca0bf41ed421bed1b57c4958bab16aa86b757d0", - "reference": "eca0bf41ed421bed1b57c4958bab16aa86b757d0", + "url": "https://api.github.com/repos/symfony/polyfill-php80/zipball/57b712b08eddb97c762a8caa32c84e037892d2e9", + "reference": "57b712b08eddb97c762a8caa32c84e037892d2e9", "shasum": "" }, "require": { @@ -4030,25 +4325,87 @@ "portable", "shim" ], - "time": "2021-02-19T12:13:01+00:00" + "time": "2021-09-13T13:58:33+00:00" + }, + { + "name": "symfony/polyfill-php81", + "version": "v1.24.0", + "source": { + "type": "git", + "url": "https://github.com/symfony/polyfill-php81.git", + "reference": "5de4ba2d41b15f9bd0e19b2ab9674135813ec98f" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/symfony/polyfill-php81/zipball/5de4ba2d41b15f9bd0e19b2ab9674135813ec98f", + "reference": "5de4ba2d41b15f9bd0e19b2ab9674135813ec98f", + "shasum": "" + }, + "require": { + "php": ">=7.1" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-main": "1.23-dev" + }, + "thanks": { + "name": "symfony/polyfill", + "url": "https://github.com/symfony/polyfill" + } + }, + "autoload": { + "psr-4": { + "Symfony\\Polyfill\\Php81\\": "" + }, + "files": [ + "bootstrap.php" + ], + "classmap": [ + "Resources/stubs" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Nicolas Grekas", + "email": "p@tchwork.com" + }, + { + "name": "Symfony Community", + "homepage": "https://symfony.com/contributors" + } + ], + "description": "Symfony polyfill backporting some PHP 8.1+ features to lower PHP versions", + "homepage": "https://symfony.com", + "keywords": [ + "compatibility", + "polyfill", + "portable", + "shim" + ], + "time": "2021-09-13T13:58:11+00:00" }, { "name": "symfony/process", - "version": "v5.3.2", + "version": "v5.4.2", "source": { "type": "git", "url": "https://github.com/symfony/process.git", - "reference": "714b47f9196de61a196d86c4bad5f09201b307df" + "reference": "2b3ba8722c4aaf3e88011be5e7f48710088fb5e4" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/process/zipball/714b47f9196de61a196d86c4bad5f09201b307df", - "reference": "714b47f9196de61a196d86c4bad5f09201b307df", + "url": "https://api.github.com/repos/symfony/process/zipball/2b3ba8722c4aaf3e88011be5e7f48710088fb5e4", + "reference": "2b3ba8722c4aaf3e88011be5e7f48710088fb5e4", "shasum": "" }, "require": { "php": ">=7.2.5", - "symfony/polyfill-php80": "^1.15" + "symfony/polyfill-php80": "^1.16" }, "type": "library", "autoload": { @@ -4075,26 +4432,26 @@ ], "description": "Executes commands in sub-processes", "homepage": "https://symfony.com", - "time": "2021-06-12T10:15:01+00:00" + "time": "2021-12-27T21:01:00+00:00" }, { "name": "symfony/routing", - "version": "v5.3.0", + "version": "v5.4.0", "source": { "type": "git", "url": "https://github.com/symfony/routing.git", - "reference": "368e81376a8e049c37cb80ae87dbfbf411279199" + "reference": "9eeae93c32ca86746e5d38f3679e9569981038b1" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/routing/zipball/368e81376a8e049c37cb80ae87dbfbf411279199", - "reference": "368e81376a8e049c37cb80ae87dbfbf411279199", + "url": "https://api.github.com/repos/symfony/routing/zipball/9eeae93c32ca86746e5d38f3679e9569981038b1", + "reference": "9eeae93c32ca86746e5d38f3679e9569981038b1", "shasum": "" }, "require": { "php": ">=7.2.5", - "symfony/deprecation-contracts": "^2.1", - "symfony/polyfill-php80": "^1.15" + "symfony/deprecation-contracts": "^2.1|^3", + "symfony/polyfill-php80": "^1.16" }, "conflict": { "doctrine/annotations": "<1.12", @@ -4104,12 +4461,12 @@ }, "require-dev": { "doctrine/annotations": "^1.12", - "psr/log": "~1.0", - "symfony/config": "^5.3", - "symfony/dependency-injection": "^4.4|^5.0", - "symfony/expression-language": "^4.4|^5.0", - "symfony/http-foundation": "^4.4|^5.0", - "symfony/yaml": "^4.4|^5.0" + "psr/log": "^1|^2|^3", + "symfony/config": "^5.3|^6.0", + "symfony/dependency-injection": "^4.4|^5.0|^6.0", + "symfony/expression-language": "^4.4|^5.0|^6.0", + "symfony/http-foundation": "^4.4|^5.0|^6.0", + "symfony/yaml": "^4.4|^5.0|^6.0" }, "suggest": { "symfony/config": "For using the all-in-one router or any loader", @@ -4148,25 +4505,29 @@ "uri", "url" ], - "time": "2021-05-26T17:43:10+00:00" + "time": "2021-11-23T10:19:22+00:00" }, { "name": "symfony/service-contracts", - "version": "v2.4.0", + "version": "v2.5.0", "source": { "type": "git", "url": "https://github.com/symfony/service-contracts.git", - "reference": "f040a30e04b57fbcc9c6cbcf4dbaa96bd318b9bb" + "reference": "1ab11b933cd6bc5464b08e81e2c5b07dec58b0fc" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/service-contracts/zipball/f040a30e04b57fbcc9c6cbcf4dbaa96bd318b9bb", - "reference": "f040a30e04b57fbcc9c6cbcf4dbaa96bd318b9bb", + "url": "https://api.github.com/repos/symfony/service-contracts/zipball/1ab11b933cd6bc5464b08e81e2c5b07dec58b0fc", + "reference": "1ab11b933cd6bc5464b08e81e2c5b07dec58b0fc", "shasum": "" }, "require": { "php": ">=7.2.5", - "psr/container": "^1.1" + "psr/container": "^1.1", + "symfony/deprecation-contracts": "^2.1" + }, + "conflict": { + "ext-psr": "<1.1|>=2" }, "suggest": { "symfony/service-implementation": "" @@ -4174,7 +4535,7 @@ "type": "library", "extra": { "branch-alias": { - "dev-main": "2.4-dev" + "dev-main": "2.5-dev" }, "thanks": { "name": "symfony/contracts", @@ -4210,20 +4571,20 @@ "interoperability", "standards" ], - "time": "2021-04-01T10:43:52+00:00" + "time": "2021-11-04T16:48:04+00:00" }, { "name": "symfony/string", - "version": "v5.3.3", + "version": "v5.4.2", "source": { "type": "git", "url": "https://github.com/symfony/string.git", - "reference": "bd53358e3eccec6a670b5f33ab680d8dbe1d4ae1" + "reference": "e6a5d5ecf6589c5247d18e0e74e30b11dfd51a3d" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/string/zipball/bd53358e3eccec6a670b5f33ab680d8dbe1d4ae1", - "reference": "bd53358e3eccec6a670b5f33ab680d8dbe1d4ae1", + "url": "https://api.github.com/repos/symfony/string/zipball/e6a5d5ecf6589c5247d18e0e74e30b11dfd51a3d", + "reference": "e6a5d5ecf6589c5247d18e0e74e30b11dfd51a3d", "shasum": "" }, "require": { @@ -4234,11 +4595,14 @@ "symfony/polyfill-mbstring": "~1.0", "symfony/polyfill-php80": "~1.15" }, + "conflict": { + "symfony/translation-contracts": ">=3.0" + }, "require-dev": { - "symfony/error-handler": "^4.4|^5.0", - "symfony/http-client": "^4.4|^5.0", + "symfony/error-handler": "^4.4|^5.0|^6.0", + "symfony/http-client": "^4.4|^5.0|^6.0", "symfony/translation-contracts": "^1.1|^2", - "symfony/var-exporter": "^4.4|^5.0" + "symfony/var-exporter": "^4.4|^5.0|^6.0" }, "type": "library", "autoload": { @@ -4276,31 +4640,32 @@ "utf-8", "utf8" ], - "time": "2021-06-27T11:44:38+00:00" + "time": "2021-12-16T21:52:00+00:00" }, { "name": "symfony/translation", - "version": "v5.3.3", + "version": "v5.4.2", "source": { "type": "git", "url": "https://github.com/symfony/translation.git", - "reference": "380b8c9e944d0e364b25f28e8e555241eb49c01c" + "reference": "ff8bb2107b6a549dc3c5dd9c498dcc82c9c098ca" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/translation/zipball/380b8c9e944d0e364b25f28e8e555241eb49c01c", - "reference": "380b8c9e944d0e364b25f28e8e555241eb49c01c", + "url": "https://api.github.com/repos/symfony/translation/zipball/ff8bb2107b6a549dc3c5dd9c498dcc82c9c098ca", + "reference": "ff8bb2107b6a549dc3c5dd9c498dcc82c9c098ca", "shasum": "" }, "require": { "php": ">=7.2.5", - "symfony/deprecation-contracts": "^2.1", + "symfony/deprecation-contracts": "^2.1|^3", "symfony/polyfill-mbstring": "~1.0", - "symfony/polyfill-php80": "^1.15", + "symfony/polyfill-php80": "^1.16", "symfony/translation-contracts": "^2.3" }, "conflict": { "symfony/config": "<4.4", + "symfony/console": "<5.3", "symfony/dependency-injection": "<5.0", "symfony/http-kernel": "<5.0", "symfony/twig-bundle": "<5.0", @@ -4310,16 +4675,17 @@ "symfony/translation-implementation": "2.3" }, "require-dev": { - "psr/log": "~1.0", - "symfony/config": "^4.4|^5.0", - "symfony/console": "^4.4|^5.0", - "symfony/dependency-injection": "^5.0", - "symfony/finder": "^4.4|^5.0", - "symfony/http-kernel": "^5.0", - "symfony/intl": "^4.4|^5.0", + "psr/log": "^1|^2|^3", + "symfony/config": "^4.4|^5.0|^6.0", + "symfony/console": "^5.4|^6.0", + "symfony/dependency-injection": "^5.0|^6.0", + "symfony/finder": "^4.4|^5.0|^6.0", + "symfony/http-client-contracts": "^1.1|^2.0|^3.0", + "symfony/http-kernel": "^5.0|^6.0", + "symfony/intl": "^4.4|^5.0|^6.0", "symfony/polyfill-intl-icu": "^1.21", - "symfony/service-contracts": "^1.1.2|^2", - "symfony/yaml": "^4.4|^5.0" + "symfony/service-contracts": "^1.1.2|^2|^3", + "symfony/yaml": "^4.4|^5.0|^6.0" }, "suggest": { "psr/log-implementation": "To use logging capability in translator", @@ -4354,20 +4720,20 @@ ], "description": "Provides tools to internationalize your application", "homepage": "https://symfony.com", - "time": "2021-06-27T12:22:47+00:00" + "time": "2021-12-25T19:45:36+00:00" }, { "name": "symfony/translation-contracts", - "version": "v2.4.0", + "version": "v2.5.0", "source": { "type": "git", "url": "https://github.com/symfony/translation-contracts.git", - "reference": "95c812666f3e91db75385749fe219c5e494c7f95" + "reference": "d28150f0f44ce854e942b671fc2620a98aae1b1e" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/translation-contracts/zipball/95c812666f3e91db75385749fe219c5e494c7f95", - "reference": "95c812666f3e91db75385749fe219c5e494c7f95", + "url": "https://api.github.com/repos/symfony/translation-contracts/zipball/d28150f0f44ce854e942b671fc2620a98aae1b1e", + "reference": "d28150f0f44ce854e942b671fc2620a98aae1b1e", "shasum": "" }, "require": { @@ -4379,7 +4745,7 @@ "type": "library", "extra": { "branch-alias": { - "dev-main": "2.4-dev" + "dev-main": "2.5-dev" }, "thanks": { "name": "symfony/contracts", @@ -4415,26 +4781,26 @@ "interoperability", "standards" ], - "time": "2021-03-23T23:28:01+00:00" + "time": "2021-08-17T14:20:01+00:00" }, { "name": "symfony/var-dumper", - "version": "v5.3.3", + "version": "v5.4.2", "source": { "type": "git", "url": "https://github.com/symfony/var-dumper.git", - "reference": "46aa709affb9ad3355bd7a810f9662d71025c384" + "reference": "1b56c32c3679002b3a42384a580e16e2600f41c1" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/var-dumper/zipball/46aa709affb9ad3355bd7a810f9662d71025c384", - "reference": "46aa709affb9ad3355bd7a810f9662d71025c384", + "url": "https://api.github.com/repos/symfony/var-dumper/zipball/1b56c32c3679002b3a42384a580e16e2600f41c1", + "reference": "1b56c32c3679002b3a42384a580e16e2600f41c1", "shasum": "" }, "require": { "php": ">=7.2.5", "symfony/polyfill-mbstring": "~1.0", - "symfony/polyfill-php80": "^1.15" + "symfony/polyfill-php80": "^1.16" }, "conflict": { "phpunit/phpunit": "<5.4.3", @@ -4442,8 +4808,9 @@ }, "require-dev": { "ext-iconv": "*", - "symfony/console": "^4.4|^5.0", - "symfony/process": "^4.4|^5.0", + "symfony/console": "^4.4|^5.0|^6.0", + "symfony/process": "^4.4|^5.0|^6.0", + "symfony/uid": "^5.1|^6.0", "twig/twig": "^2.13|^3.0.4" }, "suggest": { @@ -4486,30 +4853,30 @@ "debug", "dump" ], - "time": "2021-06-24T08:13:00+00:00" + "time": "2021-12-29T10:10:35+00:00" }, { "name": "tijsverkoyen/css-to-inline-styles", - "version": "2.2.3", + "version": "2.2.4", "source": { "type": "git", "url": "https://github.com/tijsverkoyen/CssToInlineStyles.git", - "reference": "b43b05cf43c1b6d849478965062b6ef73e223bb5" + "reference": "da444caae6aca7a19c0c140f68c6182e337d5b1c" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/tijsverkoyen/CssToInlineStyles/zipball/b43b05cf43c1b6d849478965062b6ef73e223bb5", - "reference": "b43b05cf43c1b6d849478965062b6ef73e223bb5", + "url": "https://api.github.com/repos/tijsverkoyen/CssToInlineStyles/zipball/da444caae6aca7a19c0c140f68c6182e337d5b1c", + "reference": "da444caae6aca7a19c0c140f68c6182e337d5b1c", "shasum": "" }, "require": { "ext-dom": "*", "ext-libxml": "*", "php": "^5.5 || ^7.0 || ^8.0", - "symfony/css-selector": "^2.7 || ^3.0 || ^4.0 || ^5.0" + "symfony/css-selector": "^2.7 || ^3.0 || ^4.0 || ^5.0 || ^6.0" }, "require-dev": { - "phpunit/phpunit": "^4.8.35 || ^5.7 || ^6.0 || ^7.5" + "phpunit/phpunit": "^4.8.35 || ^5.7 || ^6.0 || ^7.5 || ^8.5.21 || ^9.5.10" }, "type": "library", "extra": { @@ -4535,35 +4902,35 @@ ], "description": "CssToInlineStyles is a class that enables you to convert HTML-pages/files into HTML-pages/files with inline styles. This is very useful when you're sending emails.", "homepage": "https://github.com/tijsverkoyen/CssToInlineStyles", - "time": "2020-07-13T06:12:54+00:00" + "time": "2021-12-08T09:12:39+00:00" }, { "name": "vlucas/phpdotenv", - "version": "v5.3.0", + "version": "v5.4.1", "source": { "type": "git", "url": "https://github.com/vlucas/phpdotenv.git", - "reference": "b3eac5c7ac896e52deab4a99068e3f4ab12d9e56" + "reference": "264dce589e7ce37a7ba99cb901eed8249fbec92f" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/vlucas/phpdotenv/zipball/b3eac5c7ac896e52deab4a99068e3f4ab12d9e56", - "reference": "b3eac5c7ac896e52deab4a99068e3f4ab12d9e56", + "url": "https://api.github.com/repos/vlucas/phpdotenv/zipball/264dce589e7ce37a7ba99cb901eed8249fbec92f", + "reference": "264dce589e7ce37a7ba99cb901eed8249fbec92f", "shasum": "" }, "require": { "ext-pcre": "*", - "graham-campbell/result-type": "^1.0.1", + "graham-campbell/result-type": "^1.0.2", "php": "^7.1.3 || ^8.0", - "phpoption/phpoption": "^1.7.4", - "symfony/polyfill-ctype": "^1.17", - "symfony/polyfill-mbstring": "^1.17", - "symfony/polyfill-php80": "^1.17" + "phpoption/phpoption": "^1.8", + "symfony/polyfill-ctype": "^1.23", + "symfony/polyfill-mbstring": "^1.23.1", + "symfony/polyfill-php80": "^1.23.1" }, "require-dev": { "bamarni/composer-bin-plugin": "^1.4.1", "ext-filter": "*", - "phpunit/phpunit": "^7.5.20 || ^8.5.14 || ^9.5.1" + "phpunit/phpunit": "^7.5.20 || ^8.5.21 || ^9.5.10" }, "suggest": { "ext-filter": "Required to use the boolean validator." @@ -4571,7 +4938,7 @@ "type": "library", "extra": { "branch-alias": { - "dev-master": "5.3-dev" + "dev-master": "5.4-dev" } }, "autoload": { @@ -4586,13 +4953,13 @@ "authors": [ { "name": "Graham Campbell", - "email": "graham@alt-three.com", - "homepage": "https://gjcampbell.co.uk/" + "email": "hello@gjcampbell.co.uk", + "homepage": "https://github.com/GrahamCampbell" }, { "name": "Vance Lucas", "email": "vance@vancelucas.com", - "homepage": "https://vancelucas.com/" + "homepage": "https://github.com/vlucas" } ], "description": "Loads environment variables from `.env` to `getenv()`, `$_ENV` and `$_SERVER` automagically.", @@ -4601,7 +4968,7 @@ "env", "environment" ], - "time": "2021-01-20T15:23:13+00:00" + "time": "2021-12-12T23:22:04+00:00" }, { "name": "voku/portable-ascii", @@ -4709,16 +5076,16 @@ "packages-dev": [ { "name": "composer/package-versions-deprecated", - "version": "1.11.99.2", + "version": "1.11.99.5", "source": { "type": "git", "url": "https://github.com/composer/package-versions-deprecated.git", - "reference": "c6522afe5540d5fc46675043d3ed5a45a740b27c" + "reference": "b4f54f74ef3453349c24a845d22392cd31e65f1d" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/composer/package-versions-deprecated/zipball/c6522afe5540d5fc46675043d3ed5a45a740b27c", - "reference": "c6522afe5540d5fc46675043d3ed5a45a740b27c", + "url": "https://api.github.com/repos/composer/package-versions-deprecated/zipball/b4f54f74ef3453349c24a845d22392cd31e65f1d", + "reference": "b4f54f74ef3453349c24a845d22392cd31e65f1d", "shasum": "" }, "require": { @@ -4760,28 +5127,27 @@ } ], "description": "Composer plugin that provides efficient querying for installed package versions (no runtime IO)", - "time": "2021-05-24T07:46:03+00:00" + "time": "2022-01-17T14:14:24+00:00" }, { "name": "doctrine/cache", - "version": "2.0.3", + "version": "2.1.1", "source": { "type": "git", "url": "https://github.com/doctrine/cache.git", - "reference": "c9622c6820d3ede1e2315a6a377ea1076e421d88" + "reference": "331b4d5dbaeab3827976273e9356b3b453c300ce" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/doctrine/cache/zipball/c9622c6820d3ede1e2315a6a377ea1076e421d88", - "reference": "c9622c6820d3ede1e2315a6a377ea1076e421d88", + "url": "https://api.github.com/repos/doctrine/cache/zipball/331b4d5dbaeab3827976273e9356b3b453c300ce", + "reference": "331b4d5dbaeab3827976273e9356b3b453c300ce", "shasum": "" }, "require": { "php": "~7.1 || ^8.0" }, "conflict": { - "doctrine/common": ">2.2,<2.4", - "psr/cache": ">=3" + "doctrine/common": ">2.2,<2.4" }, "require-dev": { "alcaeus/mongo-php-adapter": "^1.1", @@ -4790,8 +5156,9 @@ "mongodb/mongodb": "^1.1", "phpunit/phpunit": "^7.0 || ^8.0 || ^9.0", "predis/predis": "~1.0", - "psr/cache": "^1.0 || ^2.0", - "symfony/cache": "^4.4 || ^5.2" + "psr/cache": "^1.0 || ^2.0 || ^3.0", + "symfony/cache": "^4.4 || ^5.2 || ^6.0@dev", + "symfony/var-exporter": "^4.4 || ^5.2 || ^6.0@dev" }, "suggest": { "alcaeus/mongo-php-adapter": "Required to use legacy MongoDB driver" @@ -4841,40 +5208,42 @@ "redis", "xcache" ], - "time": "2021-05-25T09:43:04+00:00" + "time": "2021-07-17T14:49:29+00:00" }, { "name": "doctrine/dbal", - "version": "3.1.1", + "version": "3.2.1", "source": { "type": "git", "url": "https://github.com/doctrine/dbal.git", - "reference": "8e0fde2b90e3f61361013d1e928621beeea07bc0" + "reference": "4caf37acf14b513a91dd4f087f7eda424fa25542" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/doctrine/dbal/zipball/8e0fde2b90e3f61361013d1e928621beeea07bc0", - "reference": "8e0fde2b90e3f61361013d1e928621beeea07bc0", + "url": "https://api.github.com/repos/doctrine/dbal/zipball/4caf37acf14b513a91dd4f087f7eda424fa25542", + "reference": "4caf37acf14b513a91dd4f087f7eda424fa25542", "shasum": "" }, "require": { "composer/package-versions-deprecated": "^1.11.99", - "doctrine/cache": "^1.0|^2.0", + "doctrine/cache": "^1.11|^2.0", "doctrine/deprecations": "^0.5.3", "doctrine/event-manager": "^1.0", - "php": "^7.3 || ^8.0" + "php": "^7.3 || ^8.0", + "psr/cache": "^1|^2|^3", + "psr/log": "^1|^2|^3" }, "require-dev": { "doctrine/coding-standard": "9.0.0", - "jetbrains/phpstorm-stubs": "2020.2", - "phpstan/phpstan": "0.12.81", - "phpstan/phpstan-strict-rules": "^0.12.2", - "phpunit/phpunit": "9.5.5", - "psalm/plugin-phpunit": "0.13.0", - "squizlabs/php_codesniffer": "3.6.0", + "jetbrains/phpstorm-stubs": "2021.1", + "phpstan/phpstan": "1.3.0", + "phpstan/phpstan-strict-rules": "^1.1", + "phpunit/phpunit": "9.5.11", + "psalm/plugin-phpunit": "0.16.1", + "squizlabs/php_codesniffer": "3.6.2", "symfony/cache": "^5.2|^6.0", "symfony/console": "^2.0.5|^3.0|^4.0|^5.0|^6.0", - "vimeo/psalm": "4.6.4" + "vimeo/psalm": "4.16.1" }, "suggest": { "symfony/console": "For helpful console commands such as SQL execution and import of files." @@ -4932,7 +5301,7 @@ "sqlserver", "sqlsrv" ], - "time": "2021-06-19T17:59:55+00:00" + "time": "2022-01-05T08:52:06+00:00" }, { "name": "doctrine/deprecations", @@ -5102,16 +5471,16 @@ }, { "name": "facade/flare-client-php", - "version": "1.8.1", + "version": "1.9.1", "source": { "type": "git", "url": "https://github.com/facade/flare-client-php.git", - "reference": "47b639dc02bcfdfc4ebb83de703856fa01e35f5f" + "reference": "b2adf1512755637d0cef4f7d1b54301325ac78ed" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/facade/flare-client-php/zipball/47b639dc02bcfdfc4ebb83de703856fa01e35f5f", - "reference": "47b639dc02bcfdfc4ebb83de703856fa01e35f5f", + "url": "https://api.github.com/repos/facade/flare-client-php/zipball/b2adf1512755637d0cef4f7d1b54301325ac78ed", + "reference": "b2adf1512755637d0cef4f7d1b54301325ac78ed", "shasum": "" }, "require": { @@ -5153,26 +5522,27 @@ "flare", "reporting" ], - "time": "2021-05-31T19:23:29+00:00" + "time": "2021-09-13T12:16:46+00:00" }, { "name": "facade/ignition", - "version": "2.11.0", + "version": "2.17.4", "source": { "type": "git", "url": "https://github.com/facade/ignition.git", - "reference": "dc6818335f50ccf0b90284784718ea9a82604286" + "reference": "95c80bd35ee6858e9e1439b2f6a698295eeb2070" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/facade/ignition/zipball/dc6818335f50ccf0b90284784718ea9a82604286", - "reference": "dc6818335f50ccf0b90284784718ea9a82604286", + "url": "https://api.github.com/repos/facade/ignition/zipball/95c80bd35ee6858e9e1439b2f6a698295eeb2070", + "reference": "95c80bd35ee6858e9e1439b2f6a698295eeb2070", "shasum": "" }, "require": { + "ext-curl": "*", "ext-json": "*", "ext-mbstring": "*", - "facade/flare-client-php": "^1.6", + "facade/flare-client-php": "^1.9.1", "facade/ignition-contracts": "^1.0.2", "illuminate/support": "^7.0|^8.0", "monolog/monolog": "^2.0", @@ -5182,6 +5552,7 @@ }, "require-dev": { "friendsofphp/php-cs-fixer": "^2.14", + "livewire/livewire": "^2.4", "mockery/mockery": "^1.3", "orchestra/testbench": "^5.0|^6.0", "psalm/plugin-laravel": "^1.2" @@ -5223,7 +5594,7 @@ "laravel", "page" ], - "time": "2021-07-12T15:55:51+00:00" + "time": "2021-12-27T15:11:24+00:00" }, { "name": "facade/ignition-contracts", @@ -5276,21 +5647,21 @@ }, { "name": "filp/whoops", - "version": "2.13.0", + "version": "2.14.5", "source": { "type": "git", "url": "https://github.com/filp/whoops.git", - "reference": "2edbc73a4687d9085c8f20f398eebade844e8424" + "reference": "a63e5e8f26ebbebf8ed3c5c691637325512eb0dc" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/filp/whoops/zipball/2edbc73a4687d9085c8f20f398eebade844e8424", - "reference": "2edbc73a4687d9085c8f20f398eebade844e8424", + "url": "https://api.github.com/repos/filp/whoops/zipball/a63e5e8f26ebbebf8ed3c5c691637325512eb0dc", + "reference": "a63e5e8f26ebbebf8ed3c5c691637325512eb0dc", "shasum": "" }, "require": { "php": "^5.5.9 || ^7.0 || ^8.0", - "psr/log": "^1.0.1" + "psr/log": "^1.0.1 || ^2.0 || ^3.0" }, "require-dev": { "mockery/mockery": "^0.9 || ^1.0", @@ -5333,7 +5704,7 @@ "throwable", "whoops" ], - "time": "2021-06-04T12:00:00+00:00" + "time": "2022-01-07T12:00:00+00:00" }, { "name": "fzaninotto/faker", @@ -5435,16 +5806,16 @@ }, { "name": "mockery/mockery", - "version": "1.4.3", + "version": "1.4.4", "source": { "type": "git", "url": "https://github.com/mockery/mockery.git", - "reference": "d1339f64479af1bee0e82a0413813fe5345a54ea" + "reference": "e01123a0e847d52d186c5eb4b9bf58b0c6d00346" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/mockery/mockery/zipball/d1339f64479af1bee0e82a0413813fe5345a54ea", - "reference": "d1339f64479af1bee0e82a0413813fe5345a54ea", + "url": "https://api.github.com/repos/mockery/mockery/zipball/e01123a0e847d52d186c5eb4b9bf58b0c6d00346", + "reference": "e01123a0e847d52d186c5eb4b9bf58b0c6d00346", "shasum": "" }, "require": { @@ -5499,7 +5870,7 @@ "test double", "testing" ], - "time": "2021-02-24T09:51:49+00:00" + "time": "2021-09-13T15:28:59+00:00" }, { "name": "myclabs/deep-copy", @@ -5551,33 +5922,32 @@ }, { "name": "nunomaduro/collision", - "version": "v5.5.0", + "version": "v5.11.0", "source": { "type": "git", "url": "https://github.com/nunomaduro/collision.git", - "reference": "b5cb36122f1c142c3c3ee20a0ae778439ef0244b" + "reference": "8b610eef8582ccdc05d8f2ab23305e2d37049461" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/nunomaduro/collision/zipball/b5cb36122f1c142c3c3ee20a0ae778439ef0244b", - "reference": "b5cb36122f1c142c3c3ee20a0ae778439ef0244b", + "url": "https://api.github.com/repos/nunomaduro/collision/zipball/8b610eef8582ccdc05d8f2ab23305e2d37049461", + "reference": "8b610eef8582ccdc05d8f2ab23305e2d37049461", "shasum": "" }, "require": { "facade/ignition-contracts": "^1.0", - "filp/whoops": "^2.7.2", + "filp/whoops": "^2.14.3", "php": "^7.3 || ^8.0", "symfony/console": "^5.0" }, "require-dev": { "brianium/paratest": "^6.1", "fideloper/proxy": "^4.4.1", - "friendsofphp/php-cs-fixer": "^2.17.3", "fruitcake/laravel-cors": "^2.0.3", - "laravel/framework": "^9.0", + "laravel/framework": "8.x-dev", "nunomaduro/larastan": "^0.6.2", "nunomaduro/mock-final-classes": "^1.0", - "orchestra/testbench": "^7.0", + "orchestra/testbench": "^6.0", "phpstan/phpstan": "^0.12.64", "phpunit/phpunit": "^9.5.0" }, @@ -5617,20 +5987,20 @@ "php", "symfony" ], - "time": "2021-06-22T20:47:22+00:00" + "time": "2022-01-10T16:22:52+00:00" }, { "name": "phar-io/manifest", - "version": "2.0.1", + "version": "2.0.3", "source": { "type": "git", "url": "https://github.com/phar-io/manifest.git", - "reference": "85265efd3af7ba3ca4b2a2c34dbfc5788dd29133" + "reference": "97803eca37d319dfa7826cc2437fc020857acb53" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/phar-io/manifest/zipball/85265efd3af7ba3ca4b2a2c34dbfc5788dd29133", - "reference": "85265efd3af7ba3ca4b2a2c34dbfc5788dd29133", + "url": "https://api.github.com/repos/phar-io/manifest/zipball/97803eca37d319dfa7826cc2437fc020857acb53", + "reference": "97803eca37d319dfa7826cc2437fc020857acb53", "shasum": "" }, "require": { @@ -5673,7 +6043,7 @@ } ], "description": "Component for reading phar.io manifest information from a PHP Archive (PHAR)", - "time": "2020-06-27T14:33:11+00:00" + "time": "2021-07-20T11:28:43+00:00" }, { "name": "phar-io/version", @@ -5773,16 +6143,16 @@ }, { "name": "phpdocumentor/reflection-docblock", - "version": "5.2.2", + "version": "5.3.0", "source": { "type": "git", "url": "https://github.com/phpDocumentor/ReflectionDocBlock.git", - "reference": "069a785b2141f5bcf49f3e353548dc1cce6df556" + "reference": "622548b623e81ca6d78b721c5e029f4ce664f170" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/phpDocumentor/ReflectionDocBlock/zipball/069a785b2141f5bcf49f3e353548dc1cce6df556", - "reference": "069a785b2141f5bcf49f3e353548dc1cce6df556", + "url": "https://api.github.com/repos/phpDocumentor/ReflectionDocBlock/zipball/622548b623e81ca6d78b721c5e029f4ce664f170", + "reference": "622548b623e81ca6d78b721c5e029f4ce664f170", "shasum": "" }, "require": { @@ -5793,7 +6163,8 @@ "webmozart/assert": "^1.9.1" }, "require-dev": { - "mockery/mockery": "~1.3.2" + "mockery/mockery": "~1.3.2", + "psalm/phar": "^4.8" }, "type": "library", "extra": { @@ -5821,20 +6192,20 @@ } ], "description": "With this component, a library can provide support for annotations via DocBlocks or otherwise retrieve information that is embedded in a DocBlock.", - "time": "2020-09-03T19:13:55+00:00" + "time": "2021-10-19T17:43:47+00:00" }, { "name": "phpdocumentor/type-resolver", - "version": "1.4.0", + "version": "1.6.0", "source": { "type": "git", "url": "https://github.com/phpDocumentor/TypeResolver.git", - "reference": "6a467b8989322d92aa1c8bf2bebcc6e5c2ba55c0" + "reference": "93ebd0014cab80c4ea9f5e297ea48672f1b87706" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/phpDocumentor/TypeResolver/zipball/6a467b8989322d92aa1c8bf2bebcc6e5c2ba55c0", - "reference": "6a467b8989322d92aa1c8bf2bebcc6e5c2ba55c0", + "url": "https://api.github.com/repos/phpDocumentor/TypeResolver/zipball/93ebd0014cab80c4ea9f5e297ea48672f1b87706", + "reference": "93ebd0014cab80c4ea9f5e297ea48672f1b87706", "shasum": "" }, "require": { @@ -5842,7 +6213,8 @@ "phpdocumentor/reflection-common": "^2.0" }, "require-dev": { - "ext-tokenizer": "*" + "ext-tokenizer": "*", + "psalm/phar": "^4.8" }, "type": "library", "extra": { @@ -5866,37 +6238,37 @@ } ], "description": "A PSR-5 based resolver of Class names, Types and Structural Element Names", - "time": "2020-09-17T18:55:26+00:00" + "time": "2022-01-04T19:58:01+00:00" }, { "name": "phpspec/prophecy", - "version": "1.13.0", + "version": "v1.15.0", "source": { "type": "git", "url": "https://github.com/phpspec/prophecy.git", - "reference": "be1996ed8adc35c3fd795488a653f4b518be70ea" + "reference": "bbcd7380b0ebf3961ee21409db7b38bc31d69a13" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/phpspec/prophecy/zipball/be1996ed8adc35c3fd795488a653f4b518be70ea", - "reference": "be1996ed8adc35c3fd795488a653f4b518be70ea", + "url": "https://api.github.com/repos/phpspec/prophecy/zipball/bbcd7380b0ebf3961ee21409db7b38bc31d69a13", + "reference": "bbcd7380b0ebf3961ee21409db7b38bc31d69a13", "shasum": "" }, "require": { "doctrine/instantiator": "^1.2", - "php": "^7.2 || ~8.0, <8.1", + "php": "^7.2 || ~8.0, <8.2", "phpdocumentor/reflection-docblock": "^5.2", "sebastian/comparator": "^3.0 || ^4.0", "sebastian/recursion-context": "^3.0 || ^4.0" }, "require-dev": { - "phpspec/phpspec": "^6.0", + "phpspec/phpspec": "^6.0 || ^7.0", "phpunit/phpunit": "^8.0 || ^9.0" }, "type": "library", "extra": { "branch-alias": { - "dev-master": "1.11.x-dev" + "dev-master": "1.x-dev" } }, "autoload": { @@ -5929,27 +6301,27 @@ "spy", "stub" ], - "time": "2021-03-17T13:42:18+00:00" + "time": "2021-12-08T12:19:24+00:00" }, { "name": "phpunit/php-code-coverage", - "version": "9.2.6", + "version": "9.2.10", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/php-code-coverage.git", - "reference": "f6293e1b30a2354e8428e004689671b83871edde" + "reference": "d5850aaf931743067f4bfc1ae4cbd06468400687" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/php-code-coverage/zipball/f6293e1b30a2354e8428e004689671b83871edde", - "reference": "f6293e1b30a2354e8428e004689671b83871edde", + "url": "https://api.github.com/repos/sebastianbergmann/php-code-coverage/zipball/d5850aaf931743067f4bfc1ae4cbd06468400687", + "reference": "d5850aaf931743067f4bfc1ae4cbd06468400687", "shasum": "" }, "require": { "ext-dom": "*", "ext-libxml": "*", "ext-xmlwriter": "*", - "nikic/php-parser": "^4.10.2", + "nikic/php-parser": "^4.13.0", "php": ">=7.3", "phpunit/php-file-iterator": "^3.0.3", "phpunit/php-text-template": "^2.0.2", @@ -5996,20 +6368,20 @@ "testing", "xunit" ], - "time": "2021-03-28T07:26:59+00:00" + "time": "2021-12-05T09:12:13+00:00" }, { "name": "phpunit/php-file-iterator", - "version": "3.0.5", + "version": "3.0.6", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/php-file-iterator.git", - "reference": "aa4be8575f26070b100fccb67faabb28f21f66f8" + "reference": "cf1c2e7c203ac650e352f4cc675a7021e7d1b3cf" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/php-file-iterator/zipball/aa4be8575f26070b100fccb67faabb28f21f66f8", - "reference": "aa4be8575f26070b100fccb67faabb28f21f66f8", + "url": "https://api.github.com/repos/sebastianbergmann/php-file-iterator/zipball/cf1c2e7c203ac650e352f4cc675a7021e7d1b3cf", + "reference": "cf1c2e7c203ac650e352f4cc675a7021e7d1b3cf", "shasum": "" }, "require": { @@ -6046,7 +6418,7 @@ "filesystem", "iterator" ], - "time": "2020-09-28T05:57:25+00:00" + "time": "2021-12-02T12:48:52+00:00" }, { "name": "phpunit/php-invoker", @@ -6201,16 +6573,16 @@ }, { "name": "phpunit/phpunit", - "version": "9.5.6", + "version": "9.5.11", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/phpunit.git", - "reference": "fb9b8333f14e3dce976a60ef6a7e05c7c7ed8bfb" + "reference": "2406855036db1102126125537adb1406f7242fdd" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/fb9b8333f14e3dce976a60ef6a7e05c7c7ed8bfb", - "reference": "fb9b8333f14e3dce976a60ef6a7e05c7c7ed8bfb", + "url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/2406855036db1102126125537adb1406f7242fdd", + "reference": "2406855036db1102126125537adb1406f7242fdd", "shasum": "" }, "require": { @@ -6222,11 +6594,11 @@ "ext-xml": "*", "ext-xmlwriter": "*", "myclabs/deep-copy": "^1.10.1", - "phar-io/manifest": "^2.0.1", + "phar-io/manifest": "^2.0.3", "phar-io/version": "^3.0.2", "php": ">=7.3", "phpspec/prophecy": "^1.12.1", - "phpunit/php-code-coverage": "^9.2.3", + "phpunit/php-code-coverage": "^9.2.7", "phpunit/php-file-iterator": "^3.0.5", "phpunit/php-invoker": "^3.1.1", "phpunit/php-text-template": "^2.0.3", @@ -6286,7 +6658,53 @@ "testing", "xunit" ], - "time": "2021-06-23T05:14:38+00:00" + "time": "2021-12-25T07:07:57+00:00" + }, + { + "name": "psr/cache", + "version": "1.0.1", + "source": { + "type": "git", + "url": "https://github.com/php-fig/cache.git", + "reference": "d11b50ad223250cf17b86e38383413f5a6764bf8" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/php-fig/cache/zipball/d11b50ad223250cf17b86e38383413f5a6764bf8", + "reference": "d11b50ad223250cf17b86e38383413f5a6764bf8", + "shasum": "" + }, + "require": { + "php": ">=5.3.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.0.x-dev" + } + }, + "autoload": { + "psr-4": { + "Psr\\Cache\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "PHP-FIG", + "homepage": "http://www.php-fig.org/" + } + ], + "description": "Common interface for caching libraries", + "keywords": [ + "cache", + "psr", + "psr-6" + ], + "time": "2016-08-06T20:24:11+00:00" }, { "name": "reliese/laravel", @@ -6706,16 +7124,16 @@ }, { "name": "sebastian/exporter", - "version": "4.0.3", + "version": "4.0.4", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/exporter.git", - "reference": "d89cc98761b8cb5a1a235a6b703ae50d34080e65" + "reference": "65e8b7db476c5dd267e65eea9cab77584d3cfff9" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/exporter/zipball/d89cc98761b8cb5a1a235a6b703ae50d34080e65", - "reference": "d89cc98761b8cb5a1a235a6b703ae50d34080e65", + "url": "https://api.github.com/repos/sebastianbergmann/exporter/zipball/65e8b7db476c5dd267e65eea9cab77584d3cfff9", + "reference": "65e8b7db476c5dd267e65eea9cab77584d3cfff9", "shasum": "" }, "require": { @@ -6764,12 +7182,12 @@ } ], "description": "Provides the functionality to export PHP variables for visualization", - "homepage": "http://www.github.com/sebastianbergmann/exporter", + "homepage": "https://www.github.com/sebastianbergmann/exporter", "keywords": [ "export", "exporter" ], - "time": "2020-09-28T05:24:23+00:00" + "time": "2021-11-11T14:18:36+00:00" }, { "name": "sebastian/global-state", @@ -7153,16 +7571,16 @@ }, { "name": "theseer/tokenizer", - "version": "1.2.0", + "version": "1.2.1", "source": { "type": "git", "url": "https://github.com/theseer/tokenizer.git", - "reference": "75a63c33a8577608444246075ea0af0d052e452a" + "reference": "34a41e998c2183e22995f158c581e7b5e755ab9e" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/theseer/tokenizer/zipball/75a63c33a8577608444246075ea0af0d052e452a", - "reference": "75a63c33a8577608444246075ea0af0d052e452a", + "url": "https://api.github.com/repos/theseer/tokenizer/zipball/34a41e998c2183e22995f158c581e7b5e755ab9e", + "reference": "34a41e998c2183e22995f158c581e7b5e755ab9e", "shasum": "" }, "require": { @@ -7189,7 +7607,7 @@ } ], "description": "A small library for converting tokenized PHP source code into XML and potentially other formats", - "time": "2020-07-12T23:59:07+00:00" + "time": "2021-07-28T10:34:58+00:00" } ], "aliases": [], diff --git a/resources/views/auth/login.blade.php b/resources/views/auth/login.blade.php index 12ecf8c..ec6b79e 100644 --- a/resources/views/auth/login.blade.php +++ b/resources/views/auth/login.blade.php @@ -1,134 +1,134 @@ - - - - - - Ushauri - Getting better one text at a time - - - - - -
-
-
-
-
-
- + + + + + + Ushauri - Getting better one text at a time + + + + + +
+
+
+
+
+
+ -
- @csrf -
- - - @error('email') - - {{ $message }} - - @enderror -
-
- - - @error('password') - - {{ $message }} - - @enderror -
+ + @csrf +
+ + + @error('email') + + {{ $message }} + + @enderror +
+
+ + + @error('password') + + {{ $message }} + + @enderror +
-
-
-
- +
+
+
+ - -
+
+
- + - - @if (Route::has('password.request')) + + @if (Route::has('password.request')) -
+ @endif -
- ushauri - ushauri - ushauri -
- +
+ ushauri + ushauri + ushauri +
+
+

+

HelpDesk Contact: Toll Free 0800722440
+

+
+
+
+ + + + + + + + + + + - - - - - - - + this.submit(); - + }); + - + \ No newline at end of file From 2b33d9a1e623e4c45dc48583ab255152ba230930 Mon Sep 17 00:00:00 2001 From: Ronald-pro <36841157+Ronald-pro@users.noreply.github.com> Date: Wed, 19 Jan 2022 13:21:43 +0300 Subject: [PATCH 002/171] added sms report controller --- app/Http/Controllers/SMSReportController.php | 41 ++++++++++++++++++++ app/Models/ClientOutgoing.php | 13 +++++++ 2 files changed, 54 insertions(+) create mode 100644 app/Http/Controllers/SMSReportController.php create mode 100644 app/Models/ClientOutgoing.php diff --git a/app/Http/Controllers/SMSReportController.php b/app/Http/Controllers/SMSReportController.php new file mode 100644 index 0000000..55b9b0e --- /dev/null +++ b/app/Http/Controllers/SMSReportController.php @@ -0,0 +1,41 @@ +where('failure_reason', '=', 'UserInBlacklist') + ->get(); + } + // Failed Inactive sms function + + public function failed_sms_inactive() + { + $failed_inactive = ClientOutgoing::select('*')->where('failure_reason', '=', 'UserInactive') + ->get(); + } + // Failed Inactive sms function + + public function failed_sms_deliveryfailure() + { + $failed_deliveryfailure = ClientOutgoing::select('*')->where('failure_reason', '=', 'DeliveryFailure') + ->get(); + } + // Success sms + public function success_sms() + { + $success = ClientOutgoing::select('*')->where('callback_status', '=', 'Success') + ->get(); + } + + // Rejected sms + public function rejected_sms() + {} +} diff --git a/app/Models/ClientOutgoing.php b/app/Models/ClientOutgoing.php new file mode 100644 index 0000000..8f7037f --- /dev/null +++ b/app/Models/ClientOutgoing.php @@ -0,0 +1,13 @@ + Date: Thu, 20 Jan 2022 23:15:04 +0300 Subject: [PATCH 003/171] added sms status analytics views --- app/Http/Controllers/SMSReportController.php | 73 +- app/Models/ClientOutgoing.php | 4 + resources/views/auth/login.blade.php | 2 +- .../views/layouts/common/footer.blade.php | 2 +- .../large-vertical-sidebar/sidebar.blade.php | 718 +++++++++--------- resources/views/sms/sms_report.blade.php | 318 ++++++++ routes/web.php | 4 + 7 files changed, 740 insertions(+), 381 deletions(-) create mode 100644 resources/views/sms/sms_report.blade.php diff --git a/app/Http/Controllers/SMSReportController.php b/app/Http/Controllers/SMSReportController.php index 55b9b0e..3a2c732 100644 --- a/app/Http/Controllers/SMSReportController.php +++ b/app/Http/Controllers/SMSReportController.php @@ -4,38 +4,63 @@ use Illuminate\Http\Request; use App\Models\ClientOutgoing; +use App\Models\Partner; +use DB; class SMSReportController extends Controller { - // Failed Blacklist sms function - - public function failed_sms_blacklist() + public function index() { - $failed_blacklist = ClientOutgoing::select('*')->where('failure_reason', '=', 'UserInBlacklist') - ->get(); + $all_partners = Partner::where('status', '=', 'Active') + ->pluck('name', 'id'); + return view('sms.sms_report', compact('all_partners')); } - // Failed Inactive sms function - public function failed_sms_inactive() - { - $failed_inactive = ClientOutgoing::select('*')->where('failure_reason', '=', 'UserInactive') - ->get(); - } - // Failed Inactive sms function - - public function failed_sms_deliveryfailure() - { - $failed_deliveryfailure = ClientOutgoing::select('*')->where('failure_reason', '=', 'DeliveryFailure') - ->get(); - } - // Success sms public function success_sms() { - $success = ClientOutgoing::select('*')->where('callback_status', '=', 'Success') + $success = ClientOutgoing::select(\DB::raw("COUNT(status) as count")) + ->where('callback_status', '=', 'Success') + ->pluck('count'); + + $failed_blacklist = ClientOutgoing::select('*') + ->where('callback_status', '=', 'Failed') + ->where('failure_reason', '=', 'UserInBlacklist') + ->count(); + + $failed_inactive = ClientOutgoing::select('*') + ->where('callback_status', '=', 'Failed') + ->where('failure_reason', '=', 'UserInactive') + ->count(); + + $failed_deliveryfailure = ClientOutgoing::select('*') + ->where('callback_status', '=', 'Failed') + ->where('failure_reason', '=', 'DeliveryFailure') + ->count(); + + $rejected_blacklist = ClientOutgoing::select('*') + ->where('callback_status', '=', 'Rejected') + ->where('failure_reason', '=', 'UserInBlacklist') + ->count(); + + $rejected_inactive = ClientOutgoing::select('*') + ->where('callback_status', '=', 'Rejected') + ->where('failure_reason', '=', 'UserInactive') + ->count(); + + $rejected_deliveryfailure = ClientOutgoing::select('*') + ->where('callback_status', '=', 'Rejected') + ->where('failure_reason', '=', 'DeliveryFailure') + ->count(); + $get_cost = ClientOutgoing::select('cost') ->get(); - } + $all_cost = str_replace("KES", "", $get_cost); - // Rejected sms - public function rejected_sms() - {} + $success_cost = ClientOutgoing::select(DB::raw("SUM(cost) as count")) + ->where('callback_status', '=', 'Success') + ->pluck('count'); + + $all_partners = Partner::where('status', '=', 'Active') + ->pluck('name', 'id'); + return view('sms.sms_report', compact('success', 'all_partners', 'failed_blacklist', 'failed_inactive', 'failed_deliveryfailure', 'rejected_blacklist', 'rejected_inactive', 'rejected_deliveryfailure', 'success_cost')); + } } diff --git a/app/Models/ClientOutgoing.php b/app/Models/ClientOutgoing.php index 8f7037f..9a1ba09 100644 --- a/app/Models/ClientOutgoing.php +++ b/app/Models/ClientOutgoing.php @@ -10,4 +10,8 @@ class ClientOutgoing extends Model use HasFactory; public $table = 'tbl_clnt_outgoing'; + public $timestamps = false; + public $incrementing = false; + + protected $fillable = []; } diff --git a/resources/views/auth/login.blade.php b/resources/views/auth/login.blade.php index ec6b79e..9c8c47b 100644 --- a/resources/views/auth/login.blade.php +++ b/resources/views/auth/login.blade.php @@ -79,7 +79,7 @@

diff --git a/resources/views/layouts/common/footer.blade.php b/resources/views/layouts/common/footer.blade.php index d7581bb..ad7000a 100644 --- a/resources/views/layouts/common/footer.blade.php +++ b/resources/views/layouts/common/footer.blade.php @@ -12,7 +12,7 @@
-

© 2019 mHealth Kenya, All rights reserved

+

© 2022 Palladium Kenya, All rights reserved

diff --git a/resources/views/layouts/large-vertical-sidebar/sidebar.blade.php b/resources/views/layouts/large-vertical-sidebar/sidebar.blade.php index 2742ed6..9be54eb 100644 --- a/resources/views/layouts/large-vertical-sidebar/sidebar.blade.php +++ b/resources/views/layouts/large-vertical-sidebar/sidebar.blade.php @@ -19,7 +19,7 @@ @if (Auth::user()->access_level == 'Facility') - + - - + + - + - @endif - @if (Auth::user()->access_level == 'Facility') + @endif + @if (Auth::user()->access_level == 'Facility') - @endif + @endif -
diff --git a/resources/views/sms/sms_report.blade.php b/resources/views/sms/sms_report.blade.php new file mode 100644 index 0000000..cf478e6 --- /dev/null +++ b/resources/views/sms/sms_report.blade.php @@ -0,0 +1,318 @@ +@extends('layouts.master') +@section('page-css') + +@endsection + +@section('main-content') + + + + +
+ +
+ {{ csrf_field() }} +
+
+
+ + +
+
+
+
+ +
+
+
+
+ + +
+
+
+
+ + + +
+
+
+
+ + +
+
+
+ +
+ +
+
+ + + +
+
+
+
+ +

+ +
+
+
+
+ + @endsection + + @section('page-js') + + +
+ + + + + + + + + + + + + + + + + @endsection + + + + + + \ No newline at end of file diff --git a/routes/web.php b/routes/web.php index aee70ba..36e3a5d 100644 --- a/routes/web.php +++ b/routes/web.php @@ -191,6 +191,10 @@ //Broadcast routes Route::get('/broadcast', ['uses' => 'App\Http\Controllers\BroadcastController@broadcast_form', 'as' => 'broadcast']); Route::post('/send-broadcast', ['uses' => 'App\Http\Controllers\BroadcastController@sendSMS', 'as' => 'send-broadcast']); + + // SMS Report routes + //Route::get('/sms/analytics', ['uses' => 'App\Http\Controllers\SMSReportController@index', 'as' => 'sms-analytics']); + Route::get('/sms/analytics', ['uses' => 'App\Http\Controllers\SMSReportController@success_sms', 'as' => 'sms-analytics']); }); From 827324a00675a753c105c6a8245dc83a7afce39f Mon Sep 17 00:00:00 2001 From: Ronald-pro <36841157+Ronald-pro@users.noreply.github.com> Date: Fri, 21 Jan 2022 12:58:14 +0300 Subject: [PATCH 004/171] set queries for cost calculation for each sms status --- app/Http/Controllers/SMSReportController.php | 39 +++++++++++++++++--- resources/views/sms/sms_report.blade.php | 11 +++++- 2 files changed, 42 insertions(+), 8 deletions(-) diff --git a/app/Http/Controllers/SMSReportController.php b/app/Http/Controllers/SMSReportController.php index 3a2c732..add2c43 100644 --- a/app/Http/Controllers/SMSReportController.php +++ b/app/Http/Controllers/SMSReportController.php @@ -51,16 +51,43 @@ public function success_sms() ->where('callback_status', '=', 'Rejected') ->where('failure_reason', '=', 'DeliveryFailure') ->count(); - $get_cost = ClientOutgoing::select('cost') - ->get(); - $all_cost = str_replace("KES", "", $get_cost); - $success_cost = ClientOutgoing::select(DB::raw("SUM(cost) as count")) + // cost calculation for all the status + $success_cost = ClientOutgoing::select(\DB::raw("SUM(SUBSTRING(cost, 5)) as total_cost")) ->where('callback_status', '=', 'Success') - ->pluck('count'); + ->pluck('total_cost'); + $failed_blacklist_cost = ClientOutgoing::select(\DB::raw("SUM(SUBSTRING(cost, 5)) as total_cost")) + ->where('callback_status', '=', 'Failed') + ->where('failure_reason', '=', 'UserInBlacklist') + ->pluck('total_cost'); + $failed_inactive_cost = ClientOutgoing::select(\DB::raw("SUM(SUBSTRING(cost, 5)) as total_cost")) + ->where('callback_status', '=', 'Failed') + ->where('failure_reason', '=', 'UserInactive') + ->pluck('total_cost'); + $failed_deliveryfailure_cost = ClientOutgoing::select(\DB::raw("SUM(SUBSTRING(cost, 5)) as total_cost")) + ->where('callback_status', '=', 'Failed') + ->where('failure_reason', '=', 'DeliveryFailure') + ->pluck('total_cost'); + $rejected_blacklist_cost = ClientOutgoing::select(\DB::raw("SUM(SUBSTRING(cost, 5)) as total_cost")) + ->where('callback_status', '=', 'Rejected') + ->where('failure_reason', '=', 'UserInBlacklist') + ->pluck('total_cost'); + $rejected_inactive_cost = ClientOutgoing::select(\DB::raw("SUM(SUBSTRING(cost, 5)) as total_cost")) + ->where('callback_status', '=', 'Rejected') + ->where('failure_reason', '=', 'UserInactive') + ->pluck('total_cost'); + $rejected_deliveryfailure_cost = ClientOutgoing::select(\DB::raw("SUM(SUBSTRING(cost, 5)) as total_cost")) + ->where('callback_status', '=', 'Rejected') + ->where('failure_reason', '=', 'DeliveryFailure') + ->pluck('total_cost'); $all_partners = Partner::where('status', '=', 'Active') ->pluck('name', 'id'); - return view('sms.sms_report', compact('success', 'all_partners', 'failed_blacklist', 'failed_inactive', 'failed_deliveryfailure', 'rejected_blacklist', 'rejected_inactive', 'rejected_deliveryfailure', 'success_cost')); + + return view('sms.sms_report', compact('success', 'all_partners', 'failed_blacklist', 'failed_inactive', 'failed_deliveryfailure', 'rejected_blacklist', 'rejected_inactive', 'rejected_deliveryfailure', + 'success_cost', 'failed_blacklist_cost', 'failed_inactive_cost', 'failed_deliveryfailure_cost', 'rejected_blacklist_cost', 'rejected_inactive_cost', 'rejected_deliveryfailure_cost')); } + + public function filter_sms() + {} } diff --git a/resources/views/sms/sms_report.blade.php b/resources/views/sms/sms_report.blade.php index cf478e6..fea7956 100644 --- a/resources/views/sms/sms_report.blade.php +++ b/resources/views/sms/sms_report.blade.php @@ -245,7 +245,14 @@ var Rejected_blacklist = ; var Rejected_inactive = ; var Rejected_deliveryfailure = ; + var Success_cost = ; + var Failed_backlist_cost = ; + var Failed_inactive_cost = ; + var Failed_delivery_cost = ; + var Rejected_blacklist_cost = ; + var Rejected_inactive_cost = ; + var Rejected_delivery_cost = ; console.log(Success_cost); Highcharts.chart('container', { @@ -253,7 +260,7 @@ type: 'column' }, title: { - text: 'SMS Status Analytics' + text: 'SMS Status & Cost Analytics' }, xAxis: { categories: ['Delivered', 'Failed Inactive', 'Failed Blacklist', 'Failed DeliveryFailure', 'Rejected Inactive', 'Rejected Blacklist', 'Rejected DeliveryFailure'] @@ -293,7 +300,7 @@ { type: 'spline', name: 'Cost(Ksh)', - data: [Success_cost, 2.67, 3, 6.33, 3.33], + data: [Success_cost, Failed_inactive_cost, Failed_backlist_cost, Failed_delivery_cost, Rejected_inactive_cost, Rejected_blacklist_cost, Rejected_delivery_cost], marker: { lineWidth: 2, lineColor: Highcharts.getOptions().colors[3], From a02e5a7602da56a07598b47a9d2b8cd6b9c4ad5e Mon Sep 17 00:00:00 2001 From: Ronald-pro <36841157+Ronald-pro@users.noreply.github.com> Date: Mon, 24 Jan 2022 13:37:41 +0300 Subject: [PATCH 005/171] added sms analytic filters --- app/Http/Controllers/SMSReportController.php | 196 ++++- .../views/pmtct/pmtct_dashboard.blade.php | 802 +++++++++--------- resources/views/sms/sms_report.blade.php | 413 ++++----- 3 files changed, 801 insertions(+), 610 deletions(-) diff --git a/app/Http/Controllers/SMSReportController.php b/app/Http/Controllers/SMSReportController.php index add2c43..1994f25 100644 --- a/app/Http/Controllers/SMSReportController.php +++ b/app/Http/Controllers/SMSReportController.php @@ -84,10 +84,198 @@ public function success_sms() $all_partners = Partner::where('status', '=', 'Active') ->pluck('name', 'id'); - return view('sms.sms_report', compact('success', 'all_partners', 'failed_blacklist', 'failed_inactive', 'failed_deliveryfailure', 'rejected_blacklist', 'rejected_inactive', 'rejected_deliveryfailure', - 'success_cost', 'failed_blacklist_cost', 'failed_inactive_cost', 'failed_deliveryfailure_cost', 'rejected_blacklist_cost', 'rejected_inactive_cost', 'rejected_deliveryfailure_cost')); + return view('sms.sms_report', compact( + 'success', + 'all_partners', + 'failed_blacklist', + 'failed_inactive', + 'failed_deliveryfailure', + 'rejected_blacklist', + 'rejected_inactive', + 'rejected_deliveryfailure', + 'success_cost', + 'failed_blacklist_cost', + 'failed_inactive_cost', + 'failed_deliveryfailure_cost', + 'rejected_blacklist_cost', + 'rejected_inactive_cost', + 'rejected_deliveryfailure_cost' + )); } - public function filter_sms() - {} + public function filter_sms(Request $request) + { + $data = []; + + $selected_partners = $request->partners; + $selected_counties = $request->counties; + $selected_subcounties = $request->subcounties; + $selected_facilites = $request->facilities; + + $success = ClientOutgoing::join('tbl_client', 'tbl_clnt_outgoing.clnt_usr_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select(\DB::raw("COUNT(status)")) + ->where('callback_status', '=', 'Success'); + + $failed_blacklist = ClientOutgoing::join('tbl_client', 'tbl_clnt_outgoing.clnt_usr_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select('*') + ->where('callback_status', '=', 'Failed') + ->where('failure_reason', '=', 'UserInBlacklist'); + + $failed_inactive = ClientOutgoing::join('tbl_client', 'tbl_clnt_outgoing.clnt_usr_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select('*') + ->where('callback_status', '=', 'Failed') + ->where('failure_reason', '=', 'UserInactive'); + + $failed_deliveryfailure = ClientOutgoing::join('tbl_client', 'tbl_clnt_outgoing.clnt_usr_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select('*') + ->where('callback_status', '=', 'Failed') + ->where('failure_reason', '=', 'DeliveryFailure'); + + $rejected_blacklist = ClientOutgoing::join('tbl_client', 'tbl_clnt_outgoing.clnt_usr_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select('*') + ->where('callback_status', '=', 'Rejected') + ->where('failure_reason', '=', 'UserInBlacklist'); + + $rejected_inactive = ClientOutgoing::join('tbl_client', 'tbl_clnt_outgoing.clnt_usr_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select('*') + ->where('callback_status', '=', 'Rejected') + ->where('failure_reason', '=', 'UserInactive'); + + $rejected_deliveryfailure = ClientOutgoing::join('tbl_client', 'tbl_clnt_outgoing.clnt_usr_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select('*') + ->where('callback_status', '=', 'Rejected') + ->where('failure_reason', '=', 'DeliveryFailure'); + + // cost calculation for all the status + $success_cost = ClientOutgoing::join('tbl_client', 'tbl_clnt_outgoing.clnt_usr_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select(\DB::raw("SUM(SUBSTRING(cost, 5)) as total_cost")) + ->where('callback_status', '=', 'Success') + ->pluck('total_cost'); + $failed_blacklist_cost = ClientOutgoing::join('tbl_client', 'tbl_clnt_outgoing.clnt_usr_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select(\DB::raw("SUM(SUBSTRING(cost, 5)) as total_cost")) + ->where('callback_status', '=', 'Failed') + ->where('failure_reason', '=', 'UserInBlacklist') + ->pluck('total_cost'); + $failed_inactive_cost = ClientOutgoing::join('tbl_client', 'tbl_clnt_outgoing.clnt_usr_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select(\DB::raw("SUM(SUBSTRING(cost, 5)) as total_cost")) + ->where('callback_status', '=', 'Failed') + ->where('failure_reason', '=', 'UserInactive') + ->pluck('total_cost'); + $failed_deliveryfailure_cost = ClientOutgoing::join('tbl_client', 'tbl_clnt_outgoing.clnt_usr_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select(\DB::raw("SUM(SUBSTRING(cost, 5)) as total_cost")) + ->where('callback_status', '=', 'Failed') + ->where('failure_reason', '=', 'DeliveryFailure') + ->pluck('total_cost'); + $rejected_blacklist_cost = ClientOutgoing::join('tbl_client', 'tbl_clnt_outgoing.clnt_usr_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select(\DB::raw("SUM(SUBSTRING(cost, 5)) as total_cost")) + ->where('callback_status', '=', 'Rejected') + ->where('failure_reason', '=', 'UserInBlacklist') + ->pluck('total_cost'); + $rejected_inactive_cost = ClientOutgoing::join('tbl_client', 'tbl_clnt_outgoing.clnt_usr_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select(\DB::raw("SUM(SUBSTRING(cost, 5)) as total_cost")) + ->where('callback_status', '=', 'Rejected') + ->where('failure_reason', '=', 'UserInactive') + ->pluck('total_cost'); + $rejected_deliveryfailure_cost = ClientOutgoing::join('tbl_client', 'tbl_clnt_outgoing.clnt_usr_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select(\DB::raw("SUM(SUBSTRING(cost, 5)) as total_cost")) + ->where('callback_status', '=', 'Rejected') + ->where('failure_reason', '=', 'DeliveryFailure') + ->pluck('total_cost'); + + if (!empty($selected_partners)) { + $success = $success->where('tbl_partner_facility.partner_id', $selected_partners); + $failed_blacklist = $failed_blacklist->where('tbl_partner_facility.partner_id', $selected_partners); + $failed_inactive = $failed_inactive->where('tbl_partner_facility.partner_id', $selected_partners); + $failed_deliveryfailure = $failed_deliveryfailure->where('tbl_partner_facility.partner_id', $selected_partners); + $rejected_blacklist = $rejected_blacklist->where('tbl_partner_facility.partner_id', $selected_partners); + $rejected_inactive = $rejected_inactive->where('tbl_partner_facility.partner_id', $selected_partners); + $rejected_deliveryfailure = $rejected_deliveryfailure->where('tbl_partner_facility.partner_id', $selected_partners); + $success_cost = $success_cost->where('tbl_partner_facility.partner_id', $selected_partners); + $failed_blacklist_cost = $failed_blacklist_cost->where('tbl_partner_facility.partner_id', $selected_partners); + $failed_inactive_cost = $failed_inactive_cost->where('tbl_partner_facility.partner_id', $selected_partners); + $failed_deliveryfailure_cost = $failed_deliveryfailure_cost->where('tbl_partner_facility.partner_id', $selected_partners); + $rejected_blacklist_cost = $rejected_blacklist_cost->where('tbl_partner_facility.partner_id', $selected_partners); + $rejected_inactive_cost = $rejected_inactive_cost->where('tbl_partner_facility.partner_id', $selected_partners); + $rejected_deliveryfailure_cost = $rejected_deliveryfailure_cost->where('tbl_partner_facility.partner_id', $selected_partners); + } + if (!empty($selected_counties)) { + $success = $success->where('tbl_partner_facility.county_id', $selected_counties); + $failed_blacklist = $failed_blacklist->where('tbl_partner_facility.county_id', $selected_counties); + $failed_inactive = $failed_inactive->where('tbl_partner_facility.county_id', $selected_counties); + $failed_deliveryfailure = $failed_deliveryfailure->where('tbl_partner_facility.county_id', $selected_counties); + $rejected_blacklist = $rejected_blacklist->where('tbl_partner_facility.county_id', $selected_counties); + $rejected_inactive = $rejected_inactive->where('tbl_partner_facility.county_id', $selected_counties); + $rejected_deliveryfailure = $rejected_deliveryfailure->where('tbl_partner_facility.county_id', $selected_counties); + $success_cost = $success_cost->where('tbl_partner_facility.county_id', $selected_counties); + $failed_blacklist_cost = $failed_blacklist_cost->where('tbl_partner_facility.county_id', $selected_counties); + $failed_inactive_cost = $failed_inactive_cost->where('tbl_partner_facility.county_id', $selected_counties); + $failed_deliveryfailure_cost = $failed_deliveryfailure_cost->where('tbl_partner_facility.county_id', $selected_counties); + $rejected_blacklist_cost = $rejected_blacklist_cost->where('tbl_partner_facility.county_id', $selected_counties); + $rejected_inactive_cost = $rejected_inactive_cost->where('tbl_partner_facility.county_id', $selected_counties); + $rejected_deliveryfailure_cost = $rejected_deliveryfailure_cost->where('tbl_partner_facility.county_id', $selected_counties); + } + if (!empty($selected_subcounties)) { + $success = $success->where('tbl_partner_facility.sub_county_id', $selected_subcounties); + $failed_blacklist = $failed_blacklist->where('tbl_partner_facility.sub_county_id', $selected_subcounties); + $failed_inactive = $failed_inactive->where('tbl_partner_facility.sub_county_id', $selected_subcounties); + $failed_deliveryfailure = $failed_deliveryfailure->where('tbl_partner_facility.sub_county_id', $selected_subcounties); + $rejected_blacklist = $rejected_blacklist->where('tbl_partner_facility.sub_county_id', $selected_subcounties); + $rejected_inactive = $rejected_inactive->where('tbl_partner_facility.sub_county_id', $selected_subcounties); + $rejected_deliveryfailure = $rejected_deliveryfailure->where('tbl_partner_facility.sub_county_id', $selected_subcounties); + $success_cost = $success_cost->where('tbl_partner_facility.sub_county_id', $selected_subcounties); + $failed_blacklist_cost = $failed_blacklist_cost->where('tbl_partner_facility.sub_county_id', $selected_subcounties); + $failed_inactive_cost = $failed_inactive_cost->where('tbl_partner_facility.sub_county_id', $selected_subcounties); + $failed_deliveryfailure_cost = $failed_deliveryfailure_cost->where('tbl_partner_facility.sub_county_id', $selected_subcounties); + $rejected_blacklist_cost = $rejected_blacklist_cost->where('tbl_partner_facility.sub_county_id', $selected_subcounties); + $rejected_inactive_cost = $rejected_inactive_cost->where('tbl_partner_facility.sub_county_id', $selected_subcounties); + $rejected_deliveryfailure_cost = $rejected_deliveryfailure_cost->where('tbl_partner_facility.sub_county_id', $selected_subcounties); + } + if (!empty($selected_facilites)) { + $success = $success->where('tbl_partner_facility.mfl_code', $selected_facilites); + $failed_blacklist = $failed_blacklist->where('tbl_partner_facility.mfl_code', $selected_facilites); + $failed_inactive = $failed_inactive->where('tbl_partner_facility.mfl_code', $selected_facilites); + $failed_deliveryfailure = $failed_deliveryfailure->where('tbl_partner_facility.mfl_code', $selected_facilites); + $rejected_blacklist = $rejected_blacklist->where('tbl_partner_facility.mfl_code', $selected_facilites); + $rejected_inactive = $rejected_inactive->where('tbl_partner_facility.mfl_code', $selected_facilites); + $rejected_deliveryfailure = $rejected_deliveryfailure->where('tbl_partner_facility.mfl_code', $selected_facilites); + $success_cost = $success_cost->where('tbl_partner_facility.mfl_code', $selected_facilites); + $failed_blacklist_cost = $failed_blacklist_cost->where('tbl_partner_facility.mfl_code', $selected_facilites); + $failed_inactive_cost = $failed_inactive_cost->where('tbl_partner_facility.mfl_code', $selected_facilites); + $failed_deliveryfailure_cost = $failed_deliveryfailure_cost->where('tbl_partner_facility.mfl_code', $selected_facilites); + $rejected_blacklist_cost = $rejected_blacklist_cost->where('tbl_partner_facility.mfl_code', $selected_facilites); + $rejected_inactive_cost = $rejected_inactive_cost->where('tbl_partner_facility.mfl_code', $selected_facilites); + $rejected_deliveryfailure_cost = $rejected_deliveryfailure_cost->where('tbl_partner_facility.mfl_code', $selected_facilites); + } + + $data["success"] = $success->count(); + $data["failed_blacklist"] = $failed_blacklist->count(); + $data["failed_inactive"] = $failed_inactive->count(); + $data["failed_deliveryfailure"] = $failed_deliveryfailure->count(); + $data["rejected_blacklist"] = $rejected_blacklist->count(); + $data["rejected_inactive"] = $rejected_inactive->count(); + $data["rejected_deliveryfailure"] = $rejected_deliveryfailure->count(); + $data["success_cost"] = $success_cost; + $data["failed_blacklist_cost"] = $failed_blacklist_cost; + $data["failed_inactive_cost"] = $failed_inactive_cost; + $data["failed_deliveryfailure_cost"] = $failed_deliveryfailure_cost; + $data["rejected_blacklist_cost"] = $rejected_blacklist_cost; + $data["rejected_inactive_cost"] = $rejected_inactive_cost; + $data["rejected_deliveryfailure_cost"] = $rejected_deliveryfailure_cost; + + return $data; + } } diff --git a/resources/views/pmtct/pmtct_dashboard.blade.php b/resources/views/pmtct/pmtct_dashboard.blade.php index aa63a88..c3132d4 100644 --- a/resources/views/pmtct/pmtct_dashboard.blade.php +++ b/resources/views/pmtct/pmtct_dashboard.blade.php @@ -5,458 +5,458 @@ @section('main-content') + +
-
- -
-
-
-
- -

-
- {{ csrf_field() }} -
- -
-
-
-
+
+ +
+
+
+
+ +

+ + {{ csrf_field() }} +
+ +
+
+
+
-
-
- -
-
- -
-
+
+
+ +
+
+
+
+
-
-
-
-
+
+
+
+
-
-
- - -
-
- -
-
-
+
+ +
+
+ +
+
- - +
+
-
+ +
+
+
-
- - - - - - - +
+ + + + + + + -
+
-
-
+
+
-
-

-
+
+

+
+
-
+
-
- + }); + -
-
- +
+
+ -@endsection + @endsection \ No newline at end of file diff --git a/resources/views/sms/sms_report.blade.php b/resources/views/sms/sms_report.blade.php index fea7956..cba2144 100644 --- a/resources/views/sms/sms_report.blade.php +++ b/resources/views/sms/sms_report.blade.php @@ -60,6 +60,7 @@
+
@@ -74,252 +75,254 @@
- + -
-
-
-
+
+
+
+
-

+

-
+
- @endsection - - @section('page-js') - - -
- - - - - - - - - - - - - - - + + + + + + + + + + + + + + var colors = Highcharts.getOptions().colors; + - @endsection +@endsection - \ No newline at end of file + \ No newline at end of file From 3be02ce2fa77246068a6f823bd599edd30c0756f Mon Sep 17 00:00:00 2001 From: Ronald-pro <36841157+Ronald-pro@users.noreply.github.com> Date: Thu, 27 Jan 2022 09:31:02 +0300 Subject: [PATCH 006/171] added filter by partner,county,subcounty,facility on sms analytics --- app/Http/Controllers/SMSReportController.php | 28 ++++++++++---------- resources/views/sms/sms_report.blade.php | 24 ++++++++++++++--- routes/web.php | 1 + 3 files changed, 35 insertions(+), 18 deletions(-) diff --git a/app/Http/Controllers/SMSReportController.php b/app/Http/Controllers/SMSReportController.php index 1994f25..80d4a58 100644 --- a/app/Http/Controllers/SMSReportController.php +++ b/app/Http/Controllers/SMSReportController.php @@ -53,30 +53,30 @@ public function success_sms() ->count(); // cost calculation for all the status - $success_cost = ClientOutgoing::select(\DB::raw("SUM(SUBSTRING(cost, 5)) as total_cost")) + $success_cost = ClientOutgoing::select(\DB::raw("ROUND(SUM(SUBSTRING(cost, 5)), 2) as total_cost")) ->where('callback_status', '=', 'Success') ->pluck('total_cost'); - $failed_blacklist_cost = ClientOutgoing::select(\DB::raw("SUM(SUBSTRING(cost, 5)) as total_cost")) + $failed_blacklist_cost = ClientOutgoing::select(\DB::raw("ROUND(SUM(SUBSTRING(cost, 5)), 2) as total_cost")) ->where('callback_status', '=', 'Failed') ->where('failure_reason', '=', 'UserInBlacklist') ->pluck('total_cost'); - $failed_inactive_cost = ClientOutgoing::select(\DB::raw("SUM(SUBSTRING(cost, 5)) as total_cost")) + $failed_inactive_cost = ClientOutgoing::select(\DB::raw("ROUND(SUM(SUBSTRING(cost, 5)), 2) as total_cost")) ->where('callback_status', '=', 'Failed') ->where('failure_reason', '=', 'UserInactive') ->pluck('total_cost'); - $failed_deliveryfailure_cost = ClientOutgoing::select(\DB::raw("SUM(SUBSTRING(cost, 5)) as total_cost")) + $failed_deliveryfailure_cost = ClientOutgoing::select(\DB::raw("ROUND(SUM(SUBSTRING(cost, 5)), 2) as total_cost")) ->where('callback_status', '=', 'Failed') ->where('failure_reason', '=', 'DeliveryFailure') ->pluck('total_cost'); - $rejected_blacklist_cost = ClientOutgoing::select(\DB::raw("SUM(SUBSTRING(cost, 5)) as total_cost")) + $rejected_blacklist_cost = ClientOutgoing::select(\DB::raw("ROUND(SUM(SUBSTRING(cost, 5)), 2) as total_cost")) ->where('callback_status', '=', 'Rejected') ->where('failure_reason', '=', 'UserInBlacklist') ->pluck('total_cost'); - $rejected_inactive_cost = ClientOutgoing::select(\DB::raw("SUM(SUBSTRING(cost, 5)) as total_cost")) + $rejected_inactive_cost = ClientOutgoing::select(\DB::raw("ROUND(SUM(SUBSTRING(cost, 5)), 2) as total_cost")) ->where('callback_status', '=', 'Rejected') ->where('failure_reason', '=', 'UserInactive') ->pluck('total_cost'); - $rejected_deliveryfailure_cost = ClientOutgoing::select(\DB::raw("SUM(SUBSTRING(cost, 5)) as total_cost")) + $rejected_deliveryfailure_cost = ClientOutgoing::select(\DB::raw("ROUND(SUM(SUBSTRING(cost, 5)), 2) as total_cost")) ->where('callback_status', '=', 'Rejected') ->where('failure_reason', '=', 'DeliveryFailure') ->pluck('total_cost'); @@ -156,42 +156,42 @@ public function filter_sms(Request $request) // cost calculation for all the status $success_cost = ClientOutgoing::join('tbl_client', 'tbl_clnt_outgoing.clnt_usr_id', '=', 'tbl_client.id') ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') - ->select(\DB::raw("SUM(SUBSTRING(cost, 5)) as total_cost")) + ->select(\DB::raw("ROUND(SUM(SUBSTRING(cost, 5)), 2) as total_cost")) ->where('callback_status', '=', 'Success') ->pluck('total_cost'); $failed_blacklist_cost = ClientOutgoing::join('tbl_client', 'tbl_clnt_outgoing.clnt_usr_id', '=', 'tbl_client.id') ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') - ->select(\DB::raw("SUM(SUBSTRING(cost, 5)) as total_cost")) + ->select(\DB::raw("ROUND(SUM(SUBSTRING(cost, 5)), 2) as total_cost")) ->where('callback_status', '=', 'Failed') ->where('failure_reason', '=', 'UserInBlacklist') ->pluck('total_cost'); $failed_inactive_cost = ClientOutgoing::join('tbl_client', 'tbl_clnt_outgoing.clnt_usr_id', '=', 'tbl_client.id') ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') - ->select(\DB::raw("SUM(SUBSTRING(cost, 5)) as total_cost")) + ->select(\DB::raw("ROUND(SUM(SUBSTRING(cost, 5)), 2) as total_cost")) ->where('callback_status', '=', 'Failed') ->where('failure_reason', '=', 'UserInactive') ->pluck('total_cost'); $failed_deliveryfailure_cost = ClientOutgoing::join('tbl_client', 'tbl_clnt_outgoing.clnt_usr_id', '=', 'tbl_client.id') ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') - ->select(\DB::raw("SUM(SUBSTRING(cost, 5)) as total_cost")) + ->select(\DB::raw("ROUND(SUM(SUBSTRING(cost, 5)), 2) as total_cost")) ->where('callback_status', '=', 'Failed') ->where('failure_reason', '=', 'DeliveryFailure') ->pluck('total_cost'); $rejected_blacklist_cost = ClientOutgoing::join('tbl_client', 'tbl_clnt_outgoing.clnt_usr_id', '=', 'tbl_client.id') ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') - ->select(\DB::raw("SUM(SUBSTRING(cost, 5)) as total_cost")) + ->select(\DB::raw("ROUND(SUM(SUBSTRING(cost, 5)), 2) as total_cost")) ->where('callback_status', '=', 'Rejected') ->where('failure_reason', '=', 'UserInBlacklist') ->pluck('total_cost'); $rejected_inactive_cost = ClientOutgoing::join('tbl_client', 'tbl_clnt_outgoing.clnt_usr_id', '=', 'tbl_client.id') ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') - ->select(\DB::raw("SUM(SUBSTRING(cost, 5)) as total_cost")) + ->select(\DB::raw("ROUND(SUM(SUBSTRING(cost, 5)), 2) as total_cost")) ->where('callback_status', '=', 'Rejected') ->where('failure_reason', '=', 'UserInactive') ->pluck('total_cost'); $rejected_deliveryfailure_cost = ClientOutgoing::join('tbl_client', 'tbl_clnt_outgoing.clnt_usr_id', '=', 'tbl_client.id') ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') - ->select(\DB::raw("SUM(SUBSTRING(cost, 5)) as total_cost")) + ->select(\DB::raw("ROUND(SUM(SUBSTRING(cost, 5)), 2) as total_cost")) ->where('callback_status', '=', 'Rejected') ->where('failure_reason', '=', 'DeliveryFailure') ->pluck('total_cost'); diff --git a/resources/views/sms/sms_report.blade.php b/resources/views/sms/sms_report.blade.php index cba2144..4ecc945 100644 --- a/resources/views/sms/sms_report.blade.php +++ b/resources/views/sms/sms_report.blade.php @@ -82,7 +82,7 @@
-

+

@@ -229,11 +229,27 @@ "subcounties": subcounties, "facilities": facilities }, - url: "{{ route('filter_ildashboard') }}", + url: "{{ route('filter_sms') }}", success: function(data) { - $("#il_appointments").html(data.il_appointments); + Success = parseInt(data.success) + Failed_blacklist = parseInt(data.failed_blacklist) + Failed_inactive = parseInt(data.failed_inactive) + Failed_deliveryfailure = parseInt(data.failed_deliveryfailure) + Rejected_blacklist = parseInt(data.rejected_blacklist) + Rejected_inactive = parseInt(data.rejected_inactive) + Rejected_deliveryfailure = parseInt(data.rejected_deliveryfailure) + + Success_cost = parseInt(data.success_cost) + Failed_blacklist_cost = parseInt(data.failed_blacklist_cost) + Failed_inactive_cost = parseInt(data.failed_inactive_cost) + Failed_deliveryfailure_cost = parseInt(data.failed_deliveryfailure_cost) + Rejected_blacklist_cost = parseInt(data.rejected_blacklist_cost) + Rejected_inactive_cost = parseInt(data.rejected_inactive_cost) + Rejected_deliveryfailure_cost = parseInt(data.rejected_deliveryfailure_cost) + + smsAnalytics.series[0].setData([Success, Failed_blacklist, Failed_inactive, Failed_deliveryfailure, Rejected_blacklist, Rejected_inactive, Rejected_deliveryfailure, Success_cost, Failed_backlist_cost, Failed_inactive_cost, Failed_delivery_cost, Rejected_blacklist_cost, Rejected_inactive_cost, Rejected_delivery_cost]); } }); @@ -256,7 +272,7 @@ var Rejected_delivery_cost = ; console.log(Success_cost); - Highcharts.chart('container', { + var smsAnalytics = Highcharts.chart('sms_analytics', { chart: { type: 'column' }, diff --git a/routes/web.php b/routes/web.php index 36e3a5d..a8faae3 100644 --- a/routes/web.php +++ b/routes/web.php @@ -195,6 +195,7 @@ // SMS Report routes //Route::get('/sms/analytics', ['uses' => 'App\Http\Controllers\SMSReportController@index', 'as' => 'sms-analytics']); Route::get('/sms/analytics', ['uses' => 'App\Http\Controllers\SMSReportController@success_sms', 'as' => 'sms-analytics']); + Route::get('/filter_sms', ['uses' => 'App\Http\Controllers\SMSReportController@filter_sms', 'as' => 'filter_sms']); }); From 27ceb6f641fa89855e79de6893bfcc1895c2a2ad Mon Sep 17 00:00:00 2001 From: Ronald-pro <36841157+Ronald-pro@users.noreply.github.com> Date: Mon, 7 Feb 2022 13:58:10 +0300 Subject: [PATCH 007/171] optimized admin level queries --- app/Http/Controllers/DashboardController.php | 780 ++++++++++--------- app/Http/Controllers/SMSReportController.php | 254 +++--- resources/views/sms/sms_report.blade.php | 77 +- 3 files changed, 575 insertions(+), 536 deletions(-) diff --git a/app/Http/Controllers/DashboardController.php b/app/Http/Controllers/DashboardController.php index 130af29..10f515f 100644 --- a/app/Http/Controllers/DashboardController.php +++ b/app/Http/Controllers/DashboardController.php @@ -40,13 +40,11 @@ public function user_level() { $facility_all = Facility::all()->where('code', Auth::user()->facility_id); - if (Auth::user()->access_level == 'Partner') - { - $partner_all = Partner::all()->where('id', Auth::user()->partner_id); + if (Auth::user()->access_level == 'Partner') { + $partner_all = Partner::all()->where('id', Auth::user()->partner_id); } - if (Auth::user()->access_level == 'Donor') - { - $donor_all = Donor::all()->where('id', Auth::user()->donor_id); + if (Auth::user()->access_level == 'Donor') { + $donor_all = Donor::all()->where('id', Auth::user()->donor_id); } return view('layouts.large-vertical-sidebar.header', compact('facility_all', 'partner_all', 'donor_all')); @@ -154,67 +152,81 @@ public function main_graph_dashboard() if (Auth::user()->access_level == 'Admin' || Auth::user()->access_level == 'Donor') { - $all_partners = Partner::where('status', '=', 'Active') - ->pluck('name', 'id'); - - //$all_counties = County::select('id', 'name')->distinct('id')->whereIn('id', $counties_with_data)->get(); - - - $all_clients_number = ClientPerformance::whereNotNull('actual_clients')->sum('actual_clients'); - $pec_client_sum = ClientRegistration::select('total_percentage')->sum('total_percentage'); - $pec_client_count = ClientRegistration::whereNotNull('total_percentage')->avg('total_percentage'); - $all_target_clients = ClientPerformance::whereNotNull('target_clients')->sum('target_clients'); - $all_consented_clients = ClientRegistration::whereNotNull('consented')->sum('consented'); - $all_future_appointments = FutureApp::join('tbl_partner_facility', 'tbl_future_appointments_query.mfl_code', '=', 'tbl_partner_facility.mfl_code')->count(); - $number_of_facilities = ClientPerformance::whereNotNull('mfl_code')->count(); - - $bar_appointments_data = BarAppointment::all(); - $bar_clients_data = BarClient::all(); - - - $registered_clients_count = ClientRegistration::select('clients')->sum('clients'); - $consented_clients_count = ClientRegistration::select('consented')->sum('consented'); + $all_partners = Partner::where('status', '=', 'Active') + ->pluck('name', 'id'); + + $all_clients_number = Client::whereNotNull('clinic_number')->count(); + $pec_client_sum = Client::whereNotNull('id')->count(); + $pec_client = Client::where('status', '=', 'Active')->count(); + $pec_client_count = round(($pec_client / $pec_client_sum * 100), 1); + $all_target_clients = PartnerFacility::select('avg_clients')->where('is_approved', '=', 'Yes')->sum('avg_clients'); + $all_consented_clients = Client::where('smsenable', '=', 'Yes')->count(); + $all_future_appointments = FutureApp::join('tbl_partner_facility', 'tbl_future_appointments_query.mfl_code', '=', 'tbl_partner_facility.mfl_code')->count(); + $number_of_facilities = PartnerFacility::select('mfl_code')->where('is_approved', '=', 'Yes')->count(); + $registered_clients_count = Client::whereNotNull('clinic_number')->count(); + $consented_clients_count = Client::where('smsenable', '=', 'Yes')->count(); } - if (Auth::user()->access_level == 'Partner'){ + if (Auth::user()->access_level == 'Partner') { $all_partners = Partner::where('status', '=', 'Active') - ->where('id', Auth::user()->partner_id) - ->pluck('name', 'id'); + ->where('id', Auth::user()->partner_id) + ->pluck('name', 'id'); //$all_counties = County::select('id', 'name')->distinct('id')->whereIn('id', $counties_with_data)->get(); - $all_clients_number = ClientPerformance::whereNotNull('actual_clients') - ->where('partner_id', Auth::user()->partner_id) - ->sum('actual_clients'); - $pec_client_sum = ClientRegistration::select('total_percentage') - ->where('partner_id', Auth::user()->partner_id) - ->sum('total_percentage'); - $pec_client_count = ClientRegistration::whereNotNull('total_percentage') - ->where('partner_id', Auth::user()->partner_id) - ->avg('total_percentage'); - $all_target_clients = ClientPerformance::whereNotNull('target_clients') - ->where('partner_id', Auth::user()->partner_id) - ->sum('target_clients'); - $all_consented_clients = ClientRegistration::whereNotNull('consented') - ->where('partner_id', Auth::user()->partner_id) - ->sum('consented'); - $all_future_appointments = FutureApp::join('tbl_partner_facility', 'tbl_future_appointments_query.mfl_code', '=', 'tbl_partner_facility.mfl_code') - ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) - ->count(); - $number_of_facilities = ClientPerformance::whereNotNull('mfl_code') - ->where('partner_id', Auth::user()->partner_id) - ->count(); - - - $registered_clients_count = ClientRegistration::select('clients') - ->where('partner_id', Auth::user()->partner_id)->sum('clients'); - $consented_clients_count = ClientRegistration::select('consented') - ->where('partner_id', Auth::user()->partner_id)->sum('consented'); - $bar_appointments_data = BarAppointment::all()->where('partner_id', Auth::user()->partner_id); - $bar_clients_data = BarClient::all()->where('partner_id', Auth::user()->partner_id); - } + $all_clients_number = cache()->remember('all_clients_number', now()->addMinutes(5), function () { + return ClientPerformance::whereNotNull('actual_clients') + ->where('partner_id', Auth::user()->partner_id) + ->sum('actual_clients'); + }); + $pec_client_sum = cache()->remember('pec_client_sum', now()->addMinutes(5), function () { + return ClientRegistration::select('total_percentage') + ->where('partner_id', Auth::user()->partner_id) + ->sum('total_percentage'); + }); + $pec_client_count = cache()->remember('pec_client_count', now()->addMinutes(5), function () { + return ClientRegistration::whereNotNull('total_percentage') + ->where('partner_id', Auth::user()->partner_id) + ->avg('total_percentage'); + }); + $all_target_clients = cache()->remember('all_target_clients', now()->addMinutes(5), function () { + return ClientPerformance::whereNotNull('target_clients') + ->where('partner_id', Auth::user()->partner_id) + ->sum('target_clients'); + }); + $all_consented_clients = cache()->remember('all_consented_clients', now()->addMinutes(5), function () { + return ClientRegistration::whereNotNull('consented') + ->where('partner_id', Auth::user()->partner_id) + ->sum('consented'); + }); + $all_future_appointments = cache()->remember('all_future_appointments', now()->addMinutes(5), function () { + return FutureApp::join('tbl_partner_facility', 'tbl_future_appointments_query.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) + ->count(); + }); + $number_of_facilities = cache()->remember('number_of_facilities', now()->addMinutes(5), function () { + return ClientPerformance::whereNotNull('mfl_code') + ->where('partner_id', Auth::user()->partner_id) + ->count(); + }); + + $registered_clients_count = cache()->remember('registered_clients_count', now()->addMinutes(5), function () { + return ClientRegistration::select('clients') + ->where('partner_id', Auth::user()->partner_id)->sum('clients'); + }); + $consented_clients_count = cache()->remember('consented_clients_count', now()->addMinutes(5), function () { + return ClientRegistration::select('consented') + ->where('partner_id', Auth::user()->partner_id)->sum('consented'); + }); + $bar_appointments_data = cache()->remember('bar_appointments_data', now()->addMinutes(5), function () { + return BarAppointment::all()->where('partner_id', Auth::user()->partner_id); + }); + $bar_clients_data = cache()->remember('bar_clients_data', now()->addMinutes(5), function () { + return BarClient::all()->where('partner_id', Auth::user()->partner_id); + }); + } $data["all_clients_number"] = $all_clients_number; @@ -224,14 +236,10 @@ public function main_graph_dashboard() $data["all_future_appointments"] = $all_future_appointments; $data["number_of_facilities"] = $number_of_facilities; $data["all_partners"] = $all_partners; - $data["bar_appointments_data"] = $bar_appointments_data; - $data["bar_clients_data"] = $bar_clients_data; $data["registered_clients_count"] = $registered_clients_count; $data["consented_clients_count"] = $consented_clients_count; - - return view('dashboard.dashboardv1', compact( 'all_partners', 'all_clients_number', @@ -241,8 +249,6 @@ public function main_graph_dashboard() 'number_of_facilities', 'pec_client_count', 'registered_clients_count', - 'bar_clients_data', - 'bar_appointments_data', 'consented_clients_count' )); } @@ -381,12 +387,12 @@ public function get_dashboard_sub_counties($id) ->where("tbl_partner_facility.county_id", $id) ->pluck("tbl_sub_county.name", "tbl_sub_county.id"); - if (Auth::user()->access_level == 'Partner'){ - $subcounties = PartnerFacility::join('tbl_sub_county', 'tbl_partner_facility.sub_county_id', '=', 'tbl_sub_county.id') - ->where("tbl_partner_facility.county_id", $id) - ->where("tbl_partner_facility.partner_id", '=', Auth::user()->partner_id) - ->pluck("tbl_sub_county.name", "tbl_sub_county.id"); - } + if (Auth::user()->access_level == 'Partner') { + $subcounties = PartnerFacility::join('tbl_sub_county', 'tbl_partner_facility.sub_county_id', '=', 'tbl_sub_county.id') + ->where("tbl_partner_facility.county_id", $id) + ->where("tbl_partner_facility.partner_id", '=', Auth::user()->partner_id) + ->pluck("tbl_sub_county.name", "tbl_sub_county.id"); + } return json_encode($subcounties); } @@ -394,15 +400,15 @@ public function get_dashboard_facilities($id) { $facilities = PartnerFacility::join('tbl_master_facility', 'tbl_partner_facility.mfl_code', '=', 'tbl_master_facility.code') ->where("tbl_partner_facility.sub_county_id", $id) - // ->where("tbl_partner_facility.partner_id", $id) + // ->where("tbl_partner_facility.partner_id", $id) ->pluck("tbl_master_facility.name", "tbl_master_facility.code"); - if (Auth::user()->access_level == 'Partner'){ - $facilities = PartnerFacility::join('tbl_master_facility', 'tbl_partner_facility.mfl_code', '=', 'tbl_master_facility.code') - ->where("tbl_partner_facility.sub_county_id", $id) - ->where("tbl_partner_facility.partner_id", '=', Auth::user()->partner_id) - ->pluck("tbl_master_facility.name", "tbl_master_facility.code"); - } + if (Auth::user()->access_level == 'Partner') { + $facilities = PartnerFacility::join('tbl_master_facility', 'tbl_partner_facility.mfl_code', '=', 'tbl_master_facility.code') + ->where("tbl_partner_facility.sub_county_id", $id) + ->where("tbl_partner_facility.partner_id", '=', Auth::user()->partner_id) + ->pluck("tbl_master_facility.name", "tbl_master_facility.code"); + } return json_encode($facilities); } @@ -643,331 +649,328 @@ public function client_dashboard() if (Auth::user()->access_level == 'Admin') { $all_partners = Partner::where('status', '=', 'Active') - ->pluck('name', 'id'); - // registration by age group - $consented_nine = Client::select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 0) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 9)) then `tbl_client`.`id` end)) AS count")) - ->where('smsenable', '=', 'Yes') - ->pluck('count'); + ->pluck('name', 'id'); + // registration by age group + $consented_nine = Client::select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 0) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 9)) then `tbl_client`.`id` end)) AS count")) + ->where('smsenable', '=', 'Yes') + ->pluck('count'); - $consented_forteen = Client::select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 10) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 14)) then `tbl_client`.`id` end)) AS count")) - ->where('smsenable', '=', 'Yes') - ->pluck('count'); + $consented_forteen = Client::select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 10) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 14)) then `tbl_client`.`id` end)) AS count")) + ->where('smsenable', '=', 'Yes') + ->pluck('count'); - $consented_nineteen = Client::select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 15) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 19)) then `tbl_client`.`id` end)) AS count")) - ->where('smsenable', '=', 'Yes') - ->pluck('count'); + $consented_nineteen = Client::select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 15) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 19)) then `tbl_client`.`id` end)) AS count")) + ->where('smsenable', '=', 'Yes') + ->pluck('count'); - $consented_twenty_four = Client::select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 20) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 24)) then `tbl_client`.`id` end)) AS count")) - ->where('smsenable', '=', 'Yes') - ->pluck('count'); + $consented_twenty_four = Client::select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 20) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 24)) then `tbl_client`.`id` end)) AS count")) + ->where('smsenable', '=', 'Yes') + ->pluck('count'); - $consented_over_twenty_five = Client::select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 25)) then `tbl_client`.`id` end)) AS count")) - ->where('smsenable', '=', 'Yes') - ->pluck('count'); + $consented_over_twenty_five = Client::select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 25)) then `tbl_client`.`id` end)) AS count")) + ->where('smsenable', '=', 'Yes') + ->pluck('count'); - $registered_nine = Client::select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 0) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 9)) then `tbl_client`.`id` end)) AS count")) - ->pluck('count'); + $registered_nine = Client::select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 0) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 9)) then `tbl_client`.`id` end)) AS count")) + ->pluck('count'); - $registered_forteen = Client::select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 10) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 14)) then `tbl_client`.`id` end)) AS count")) - ->pluck('count'); + $registered_forteen = Client::select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 10) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 14)) then `tbl_client`.`id` end)) AS count")) + ->pluck('count'); - $registered_nineteen = Client::select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 15) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 19)) then `tbl_client`.`id` end)) AS count")) - ->pluck('count'); + $registered_nineteen = Client::select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 15) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 19)) then `tbl_client`.`id` end)) AS count")) + ->pluck('count'); - $registered_twenty_four = Client::select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 20) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 24)) then `tbl_client`.`id` end)) AS count")) - ->pluck('count'); + $registered_twenty_four = Client::select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 20) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 24)) then `tbl_client`.`id` end)) AS count")) + ->pluck('count'); - $registered_over_twenty_five = Client::select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 25)) then `tbl_client`.`id` end)) AS count")) - ->pluck('count'); + $registered_over_twenty_five = Client::select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 25)) then `tbl_client`.`id` end)) AS count")) + ->pluck('count'); - //registration by marital status - $single_consented = Client::select(\DB::raw("COUNT(marital) as count")) - ->where('marital', '=', '1') - ->where('smsenable', '=', 'Yes') - ->pluck('count'); - $monogamous_consented = Client::select(\DB::raw("COUNT(marital) as count")) - ->where('marital', '=', '2') - ->where('smsenable', '=', 'Yes') - ->pluck('count'); - $divorced_consented = Client::select(\DB::raw("COUNT(marital) as count")) - ->where('marital', '=', '3') - ->where('smsenable', '=', 'Yes') - ->pluck('count'); - $widowed_consented = Client::select(\DB::raw("COUNT(marital) as count")) - ->where('marital', '=', '4') - ->where('smsenable', '=', 'Yes') - ->pluck('count'); - $cohabating_consented = Client::select(\DB::raw("COUNT(marital) as count")) - ->where('marital', '=', '5') - ->where('smsenable', '=', 'Yes') - ->pluck('count'); - $unavailable_consented = Client::select(\DB::raw("COUNT(marital) as count")) - ->where('marital', '=', '6') - ->where('smsenable', '=', 'Yes') - ->pluck('count'); - $notapplicable_consented = Client::select(\DB::raw("COUNT(marital) as count")) - ->where('marital', '=', '7') - ->where('smsenable', '=', 'Yes') - ->pluck('count'); - $polygamous_consented = Client::select(\DB::raw("COUNT(marital) as count")) - ->where('marital', '=', '8') - ->where('smsenable', '=', 'Yes') - ->pluck('count'); - - $single_registered = Client::select(\DB::raw("COUNT(marital) as count")) - ->where('marital', '=', '1') - ->pluck('count'); - $monogamous_registered = Client::select(\DB::raw("COUNT(marital) as count")) - ->where('marital', '=', '2') - ->pluck('count'); - $divorced_registered = Client::select(\DB::raw("COUNT(marital) as count")) - ->where('marital', '=', '3') - ->pluck('count'); - $widowed_registered = Client::select(\DB::raw("COUNT(marital) as count")) - ->where('marital', '=', '4') - ->pluck('count'); - $cohabating_registered = Client::select(\DB::raw("COUNT(marital) as count")) - ->where('marital', '=', '5') - ->pluck('count'); - $unavailable_registered = Client::select(\DB::raw("COUNT(marital) as count")) - ->where('marital', '=', '6') - ->pluck('count'); - $notapplicable_registered = Client::select(\DB::raw("COUNT(marital) as count")) - ->where('marital', '=', '7') - ->pluck('count'); - $polygamous_registered = Client::select(\DB::raw("COUNT(marital) as count")) - ->where('marital', '=', '8') - ->pluck('count'); + //registration by marital status + $single_consented = Client::select(\DB::raw("COUNT(marital) as count")) + ->where('marital', '=', '1') + ->where('smsenable', '=', 'Yes') + ->pluck('count'); + $monogamous_consented = Client::select(\DB::raw("COUNT(marital) as count")) + ->where('marital', '=', '2') + ->where('smsenable', '=', 'Yes') + ->pluck('count'); + $divorced_consented = Client::select(\DB::raw("COUNT(marital) as count")) + ->where('marital', '=', '3') + ->where('smsenable', '=', 'Yes') + ->pluck('count'); + $widowed_consented = Client::select(\DB::raw("COUNT(marital) as count")) + ->where('marital', '=', '4') + ->where('smsenable', '=', 'Yes') + ->pluck('count'); + $cohabating_consented = Client::select(\DB::raw("COUNT(marital) as count")) + ->where('marital', '=', '5') + ->where('smsenable', '=', 'Yes') + ->pluck('count'); + $unavailable_consented = Client::select(\DB::raw("COUNT(marital) as count")) + ->where('marital', '=', '6') + ->where('smsenable', '=', 'Yes') + ->pluck('count'); + $notapplicable_consented = Client::select(\DB::raw("COUNT(marital) as count")) + ->where('marital', '=', '7') + ->where('smsenable', '=', 'Yes') + ->pluck('count'); + $polygamous_consented = Client::select(\DB::raw("COUNT(marital) as count")) + ->where('marital', '=', '8') + ->where('smsenable', '=', 'Yes') + ->pluck('count'); + $single_registered = Client::select(\DB::raw("COUNT(marital) as count")) + ->where('marital', '=', '1') + ->pluck('count'); + $monogamous_registered = Client::select(\DB::raw("COUNT(marital) as count")) + ->where('marital', '=', '2') + ->pluck('count'); + $divorced_registered = Client::select(\DB::raw("COUNT(marital) as count")) + ->where('marital', '=', '3') + ->pluck('count'); + $widowed_registered = Client::select(\DB::raw("COUNT(marital) as count")) + ->where('marital', '=', '4') + ->pluck('count'); + $cohabating_registered = Client::select(\DB::raw("COUNT(marital) as count")) + ->where('marital', '=', '5') + ->pluck('count'); + $unavailable_registered = Client::select(\DB::raw("COUNT(marital) as count")) + ->where('marital', '=', '6') + ->pluck('count'); + $notapplicable_registered = Client::select(\DB::raw("COUNT(marital) as count")) + ->where('marital', '=', '7') + ->pluck('count'); + $polygamous_registered = Client::select(\DB::raw("COUNT(marital) as count")) + ->where('marital', '=', '8') + ->pluck('count'); } if (Auth::user()->access_level == 'Donor') { $all_partners = Partner::where('status', '=', 'Active') - ->pluck('name', 'id'); - // registration by age group - $consented_nine = Client::select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 0) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 9)) then `tbl_client`.`id` end)) AS count")) - ->where('smsenable', '=', 'Yes') - ->pluck('count'); + ->pluck('name', 'id'); + // registration by age group + $consented_nine = Client::select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 0) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 9)) then `tbl_client`.`id` end)) AS count")) + ->where('smsenable', '=', 'Yes') + ->pluck('count'); - $consented_forteen = Client::select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 10) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 14)) then `tbl_client`.`id` end)) AS count")) - ->where('smsenable', '=', 'Yes') - ->pluck('count'); + $consented_forteen = Client::select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 10) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 14)) then `tbl_client`.`id` end)) AS count")) + ->where('smsenable', '=', 'Yes') + ->pluck('count'); - $consented_nineteen = Client::select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 15) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 19)) then `tbl_client`.`id` end)) AS count")) - ->where('smsenable', '=', 'Yes') - ->pluck('count'); + $consented_nineteen = Client::select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 15) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 19)) then `tbl_client`.`id` end)) AS count")) + ->where('smsenable', '=', 'Yes') + ->pluck('count'); - $consented_twenty_four = Client::select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 20) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 24)) then `tbl_client`.`id` end)) AS count")) - ->where('smsenable', '=', 'Yes') - ->pluck('count'); + $consented_twenty_four = Client::select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 20) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 24)) then `tbl_client`.`id` end)) AS count")) + ->where('smsenable', '=', 'Yes') + ->pluck('count'); - $consented_over_twenty_five = Client::select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 25)) then `tbl_client`.`id` end)) AS count")) - ->where('smsenable', '=', 'Yes') - ->pluck('count'); + $consented_over_twenty_five = Client::select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 25)) then `tbl_client`.`id` end)) AS count")) + ->where('smsenable', '=', 'Yes') + ->pluck('count'); - $registered_nine = Client::select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 0) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 9)) then `tbl_client`.`id` end)) AS count")) - ->pluck('count'); + $registered_nine = Client::select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 0) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 9)) then `tbl_client`.`id` end)) AS count")) + ->pluck('count'); - $registered_forteen = Client::select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 10) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 14)) then `tbl_client`.`id` end)) AS count")) - ->pluck('count'); + $registered_forteen = Client::select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 10) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 14)) then `tbl_client`.`id` end)) AS count")) + ->pluck('count'); - $registered_nineteen = Client::select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 15) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 19)) then `tbl_client`.`id` end)) AS count")) - ->pluck('count'); + $registered_nineteen = Client::select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 15) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 19)) then `tbl_client`.`id` end)) AS count")) + ->pluck('count'); - $registered_twenty_four = Client::select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 20) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 24)) then `tbl_client`.`id` end)) AS count")) - ->pluck('count'); + $registered_twenty_four = Client::select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 20) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 24)) then `tbl_client`.`id` end)) AS count")) + ->pluck('count'); - $registered_over_twenty_five = Client::select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 25)) then `tbl_client`.`id` end)) AS count")) - ->pluck('count'); + $registered_over_twenty_five = Client::select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 25)) then `tbl_client`.`id` end)) AS count")) + ->pluck('count'); - //registration by marital status - $single_consented = Client::select(\DB::raw("COUNT(marital) as count")) - ->where('marital', '=', '1') - ->where('smsenable', '=', 'Yes') - ->pluck('count'); - $monogamous_consented = Client::select(\DB::raw("COUNT(marital) as count")) - ->where('marital', '=', '2') - ->where('smsenable', '=', 'Yes') - ->pluck('count'); - $divorced_consented = Client::select(\DB::raw("COUNT(marital) as count")) - ->where('marital', '=', '3') - ->where('smsenable', '=', 'Yes') - ->pluck('count'); - $widowed_consented = Client::select(\DB::raw("COUNT(marital) as count")) - ->where('marital', '=', '4') - ->where('smsenable', '=', 'Yes') - ->pluck('count'); - $cohabating_consented = Client::select(\DB::raw("COUNT(marital) as count")) - ->where('marital', '=', '5') - ->where('smsenable', '=', 'Yes') - ->pluck('count'); - $unavailable_consented = Client::select(\DB::raw("COUNT(marital) as count")) - ->where('marital', '=', '6') - ->where('smsenable', '=', 'Yes') - ->pluck('count'); - $notapplicable_consented = Client::select(\DB::raw("COUNT(marital) as count")) - ->where('marital', '=', '7') - ->where('smsenable', '=', 'Yes') - ->pluck('count'); - $polygamous_consented = Client::select(\DB::raw("COUNT(marital) as count")) - ->where('marital', '=', '8') - ->where('smsenable', '=', 'Yes') - ->pluck('count'); - - $single_registered = Client::select(\DB::raw("COUNT(marital) as count")) - ->where('marital', '=', '1') - ->pluck('count'); - $monogamous_registered = Client::select(\DB::raw("COUNT(marital) as count")) - ->where('marital', '=', '2') - ->pluck('count'); - $divorced_registered = Client::select(\DB::raw("COUNT(marital) as count")) - ->where('marital', '=', '3') - ->pluck('count'); - $widowed_registered = Client::select(\DB::raw("COUNT(marital) as count")) - ->where('marital', '=', '4') - ->pluck('count'); - $cohabating_registered = Client::select(\DB::raw("COUNT(marital) as count")) - ->where('marital', '=', '5') - ->pluck('count'); - $unavailable_registered = Client::select(\DB::raw("COUNT(marital) as count")) - ->where('marital', '=', '6') - ->pluck('count'); - $notapplicable_registered = Client::select(\DB::raw("COUNT(marital) as count")) - ->where('marital', '=', '7') - ->pluck('count'); - $polygamous_registered = Client::select(\DB::raw("COUNT(marital) as count")) - ->where('marital', '=', '8') - ->pluck('count'); + //registration by marital status + $single_consented = Client::select(\DB::raw("COUNT(marital) as count")) + ->where('marital', '=', '1') + ->where('smsenable', '=', 'Yes') + ->pluck('count'); + $monogamous_consented = Client::select(\DB::raw("COUNT(marital) as count")) + ->where('marital', '=', '2') + ->where('smsenable', '=', 'Yes') + ->pluck('count'); + $divorced_consented = Client::select(\DB::raw("COUNT(marital) as count")) + ->where('marital', '=', '3') + ->where('smsenable', '=', 'Yes') + ->pluck('count'); + $widowed_consented = Client::select(\DB::raw("COUNT(marital) as count")) + ->where('marital', '=', '4') + ->where('smsenable', '=', 'Yes') + ->pluck('count'); + $cohabating_consented = Client::select(\DB::raw("COUNT(marital) as count")) + ->where('marital', '=', '5') + ->where('smsenable', '=', 'Yes') + ->pluck('count'); + $unavailable_consented = Client::select(\DB::raw("COUNT(marital) as count")) + ->where('marital', '=', '6') + ->where('smsenable', '=', 'Yes') + ->pluck('count'); + $notapplicable_consented = Client::select(\DB::raw("COUNT(marital) as count")) + ->where('marital', '=', '7') + ->where('smsenable', '=', 'Yes') + ->pluck('count'); + $polygamous_consented = Client::select(\DB::raw("COUNT(marital) as count")) + ->where('marital', '=', '8') + ->where('smsenable', '=', 'Yes') + ->pluck('count'); + $single_registered = Client::select(\DB::raw("COUNT(marital) as count")) + ->where('marital', '=', '1') + ->pluck('count'); + $monogamous_registered = Client::select(\DB::raw("COUNT(marital) as count")) + ->where('marital', '=', '2') + ->pluck('count'); + $divorced_registered = Client::select(\DB::raw("COUNT(marital) as count")) + ->where('marital', '=', '3') + ->pluck('count'); + $widowed_registered = Client::select(\DB::raw("COUNT(marital) as count")) + ->where('marital', '=', '4') + ->pluck('count'); + $cohabating_registered = Client::select(\DB::raw("COUNT(marital) as count")) + ->where('marital', '=', '5') + ->pluck('count'); + $unavailable_registered = Client::select(\DB::raw("COUNT(marital) as count")) + ->where('marital', '=', '6') + ->pluck('count'); + $notapplicable_registered = Client::select(\DB::raw("COUNT(marital) as count")) + ->where('marital', '=', '7') + ->pluck('count'); + $polygamous_registered = Client::select(\DB::raw("COUNT(marital) as count")) + ->where('marital', '=', '8') + ->pluck('count'); } if (Auth::user()->access_level == 'Partner') { $all_partners = Partner::where('status', '=', 'Active') - ->where('id', Auth::user()->partner_id) - ->pluck('name', 'id'); + ->where('id', Auth::user()->partner_id) + ->pluck('name', 'id'); // registration by age group $consented_nine = Client::select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 0) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 9)) then `tbl_client`.`id` end)) AS count")) - ->where('smsenable', '=', 'Yes') - ->where('partner_id', Auth::user()->partner_id) - ->pluck('count'); + ->where('smsenable', '=', 'Yes') + ->where('partner_id', Auth::user()->partner_id) + ->pluck('count'); $consented_forteen = Client::select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 10) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 14)) then `tbl_client`.`id` end)) AS count")) - ->where('smsenable', '=', 'Yes') - ->where('partner_id', Auth::user()->partner_id) - ->pluck('count'); + ->where('smsenable', '=', 'Yes') + ->where('partner_id', Auth::user()->partner_id) + ->pluck('count'); $consented_nineteen = Client::select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 15) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 19)) then `tbl_client`.`id` end)) AS count")) - ->where('smsenable', '=', 'Yes') - ->where('partner_id', Auth::user()->partner_id) - ->pluck('count'); + ->where('smsenable', '=', 'Yes') + ->where('partner_id', Auth::user()->partner_id) + ->pluck('count'); $consented_twenty_four = Client::select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 20) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 24)) then `tbl_client`.`id` end)) AS count")) - ->where('smsenable', '=', 'Yes') - ->where('partner_id', Auth::user()->partner_id) - ->pluck('count'); + ->where('smsenable', '=', 'Yes') + ->where('partner_id', Auth::user()->partner_id) + ->pluck('count'); $consented_over_twenty_five = Client::select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 25)) then `tbl_client`.`id` end)) AS count")) - ->where('smsenable', '=', 'Yes') - ->where('partner_id', Auth::user()->partner_id) - ->pluck('count'); + ->where('smsenable', '=', 'Yes') + ->where('partner_id', Auth::user()->partner_id) + ->pluck('count'); $registered_nine = Client::select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 0) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 9)) then `tbl_client`.`id` end)) AS count")) - ->where('partner_id', Auth::user()->partner_id) - ->pluck('count'); + ->where('partner_id', Auth::user()->partner_id) + ->pluck('count'); $registered_forteen = Client::select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 10) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 14)) then `tbl_client`.`id` end)) AS count")) - ->where('partner_id', Auth::user()->partner_id) - ->pluck('count'); + ->where('partner_id', Auth::user()->partner_id) + ->pluck('count'); $registered_nineteen = Client::select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 15) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 19)) then `tbl_client`.`id` end)) AS count")) - ->where('partner_id', Auth::user()->partner_id) - ->pluck('count'); + ->where('partner_id', Auth::user()->partner_id) + ->pluck('count'); $registered_twenty_four = Client::select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 20) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 24)) then `tbl_client`.`id` end)) AS count")) - ->where('partner_id', Auth::user()->partner_id) - ->pluck('count'); + ->where('partner_id', Auth::user()->partner_id) + ->pluck('count'); $registered_over_twenty_five = Client::select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 25)) then `tbl_client`.`id` end)) AS count")) - ->where('partner_id', Auth::user()->partner_id) - ->pluck('count'); + ->where('partner_id', Auth::user()->partner_id) + ->pluck('count'); //registration by marital status $single_consented = Client::select(\DB::raw("COUNT(marital) as count")) - ->where('marital', '=', '1') - ->where('smsenable', '=', 'Yes') - ->where('partner_id', Auth::user()->partner_id) - ->pluck('count'); + ->where('marital', '=', '1') + ->where('smsenable', '=', 'Yes') + ->where('partner_id', Auth::user()->partner_id) + ->pluck('count'); $monogamous_consented = Client::select(\DB::raw("COUNT(marital) as count")) - ->where('marital', '=', '2') - ->where('smsenable', '=', 'Yes') - ->where('partner_id', Auth::user()->partner_id) - ->pluck('count'); + ->where('marital', '=', '2') + ->where('smsenable', '=', 'Yes') + ->where('partner_id', Auth::user()->partner_id) + ->pluck('count'); $divorced_consented = Client::select(\DB::raw("COUNT(marital) as count")) - ->where('marital', '=', '3') - ->where('smsenable', '=', 'Yes') - ->where('partner_id', Auth::user()->partner_id) - ->pluck('count'); + ->where('marital', '=', '3') + ->where('smsenable', '=', 'Yes') + ->where('partner_id', Auth::user()->partner_id) + ->pluck('count'); $widowed_consented = Client::select(\DB::raw("COUNT(marital) as count")) - ->where('marital', '=', '4') - ->where('smsenable', '=', 'Yes') - ->where('partner_id', Auth::user()->partner_id) - ->pluck('count'); + ->where('marital', '=', '4') + ->where('smsenable', '=', 'Yes') + ->where('partner_id', Auth::user()->partner_id) + ->pluck('count'); $cohabating_consented = Client::select(\DB::raw("COUNT(marital) as count")) - ->where('marital', '=', '5') - ->where('smsenable', '=', 'Yes') - ->where('partner_id', Auth::user()->partner_id) - ->pluck('count'); + ->where('marital', '=', '5') + ->where('smsenable', '=', 'Yes') + ->where('partner_id', Auth::user()->partner_id) + ->pluck('count'); $unavailable_consented = Client::select(\DB::raw("COUNT(marital) as count")) - ->where('marital', '=', '6') - ->where('smsenable', '=', 'Yes') - ->where('partner_id', Auth::user()->partner_id) - ->pluck('count'); + ->where('marital', '=', '6') + ->where('smsenable', '=', 'Yes') + ->where('partner_id', Auth::user()->partner_id) + ->pluck('count'); $notapplicable_consented = Client::select(\DB::raw("COUNT(marital) as count")) - ->where('marital', '=', '7') - ->where('smsenable', '=', 'Yes') - ->where('partner_id', Auth::user()->partner_id) - ->pluck('count'); + ->where('marital', '=', '7') + ->where('smsenable', '=', 'Yes') + ->where('partner_id', Auth::user()->partner_id) + ->pluck('count'); $polygamous_consented = Client::select(\DB::raw("COUNT(marital) as count")) - ->where('marital', '=', '8') - ->where('smsenable', '=', 'Yes') - ->where('partner_id', Auth::user()->partner_id) - ->pluck('count'); + ->where('marital', '=', '8') + ->where('smsenable', '=', 'Yes') + ->where('partner_id', Auth::user()->partner_id) + ->pluck('count'); $single_registered = Client::select(\DB::raw("COUNT(marital) as count")) - ->where('marital', '=', '1') - ->where('partner_id', Auth::user()->partner_id) - ->pluck('count'); + ->where('marital', '=', '1') + ->where('partner_id', Auth::user()->partner_id) + ->pluck('count'); $monogamous_registered = Client::select(\DB::raw("COUNT(marital) as count")) - ->where('marital', '=', '2') - ->where('partner_id', Auth::user()->partner_id) - ->pluck('count'); + ->where('marital', '=', '2') + ->where('partner_id', Auth::user()->partner_id) + ->pluck('count'); $divorced_registered = Client::select(\DB::raw("COUNT(marital) as count")) - ->where('marital', '=', '3') - ->where('partner_id', Auth::user()->partner_id) - ->pluck('count'); + ->where('marital', '=', '3') + ->where('partner_id', Auth::user()->partner_id) + ->pluck('count'); $widowed_registered = Client::select(\DB::raw("COUNT(marital) as count")) - ->where('marital', '=', '4') - ->where('partner_id', Auth::user()->partner_id) - ->pluck('count'); + ->where('marital', '=', '4') + ->where('partner_id', Auth::user()->partner_id) + ->pluck('count'); $cohabating_registered = Client::select(\DB::raw("COUNT(marital) as count")) - ->where('marital', '=', '5') - ->where('partner_id', Auth::user()->partner_id) - ->pluck('count'); + ->where('marital', '=', '5') + ->where('partner_id', Auth::user()->partner_id) + ->pluck('count'); $unavailable_registered = Client::select(\DB::raw("COUNT(marital) as count")) - ->where('marital', '=', '6') - ->where('partner_id', Auth::user()->partner_id) - ->pluck('count'); + ->where('marital', '=', '6') + ->where('partner_id', Auth::user()->partner_id) + ->pluck('count'); $notapplicable_registered = Client::select(\DB::raw("COUNT(marital) as count")) - ->where('marital', '=', '7') - ->where('partner_id', Auth::user()->partner_id) - ->pluck('count'); + ->where('marital', '=', '7') + ->where('partner_id', Auth::user()->partner_id) + ->pluck('count'); $polygamous_registered = Client::select(\DB::raw("COUNT(marital) as count")) - ->where('marital', '=', '8') - ->where('partner_id', Auth::user()->partner_id) - ->pluck('count'); - - } + ->where('marital', '=', '8') + ->where('partner_id', Auth::user()->partner_id) + ->pluck('count'); + } return view('dashboard.clients_dashboard', compact( @@ -1010,98 +1013,98 @@ public function filter_client_dashboard(Request $request) // registration by age group $consented_nine = Client::select(\DB::raw("case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 0) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 9)) then `tbl_client`.`id` end")) - ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') - ->where('tbl_client.smsenable', '=', 'Yes'); + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->where('tbl_client.smsenable', '=', 'Yes'); $consented_forteen = Client::select(\DB::raw("case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 10) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 14)) then `tbl_client`.`id` end")) - ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') - ->where('tbl_client.smsenable', '=', 'Yes'); + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->where('tbl_client.smsenable', '=', 'Yes'); $consented_nineteen = Client::select(\DB::raw("case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 15) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 19)) then `tbl_client`.`id` end")) - ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') - ->where('tbl_client.smsenable', '=', 'Yes'); + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->where('tbl_client.smsenable', '=', 'Yes'); $consented_twenty_four = Client::select(\DB::raw("case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 20) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 24)) then `tbl_client`.`id` end")) - ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') - ->where('tbl_client.smsenable', '=', 'Yes'); + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->where('tbl_client.smsenable', '=', 'Yes'); $consented_over_twenty_five = Client::select(\DB::raw("case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 25)) then `tbl_client`.`id` end")) - ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') - ->where('tbl_client.smsenable', '=', 'Yes'); + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->where('tbl_client.smsenable', '=', 'Yes'); $registered_nine = Client::select(\DB::raw("case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 0) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 9)) then `tbl_client`.`id` end")) - ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code'); + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code'); $registered_forteen = Client::select(\DB::raw("case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 10) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 14)) then `tbl_client`.`id` end")) - ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code'); + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code'); $registered_nineteen = Client::select(\DB::raw("case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 15) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 19)) then `tbl_client`.`id` end")) - ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code'); + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code'); $registered_twenty_four = Client::select(\DB::raw("case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 20) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 24)) then `tbl_client`.`id` end")) - ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code'); + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code'); $registered_over_twenty_five = Client::select(\DB::raw("case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 25)) then `tbl_client`.`id` end")) - ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code'); + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code'); //registration by marital status $single_consented = Client::select(\DB::raw("tbl_client.marital")) - ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') - ->where('tbl_client.marital', '=', '1') - ->where('tbl_client.smsenable', '=', 'Yes'); + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->where('tbl_client.marital', '=', '1') + ->where('tbl_client.smsenable', '=', 'Yes'); $monogamous_consented = Client::select(\DB::raw("tbl_client.marital")) - ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') - ->where('tbl_client.marital', '=', '2') - ->where('tbl_client.smsenable', '=', 'Yes'); + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->where('tbl_client.marital', '=', '2') + ->where('tbl_client.smsenable', '=', 'Yes'); $divorced_consented = Client::select(\DB::raw("tbl_client.marital")) - ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') - ->where('tbl_client.marital', '=', '3') - ->where('smsenable', '=', 'Yes'); + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->where('tbl_client.marital', '=', '3') + ->where('smsenable', '=', 'Yes'); $widowed_consented = Client::select(\DB::raw("tbl_client.marital")) - ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') - ->where('tbl_client.marital', '=', '4') - ->where('tbl_client.smsenable', '=', 'Yes'); + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->where('tbl_client.marital', '=', '4') + ->where('tbl_client.smsenable', '=', 'Yes'); $cohabating_consented = Client::select(\DB::raw("tbl_client.marital")) - ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') - ->where('marital', '=', '5') - ->where('tbl_client.smsenable', '=', 'Yes'); + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->where('marital', '=', '5') + ->where('tbl_client.smsenable', '=', 'Yes'); $unavailable_consented = Client::select(\DB::raw("tbl_client.marital")) - ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') - ->where('tbl_client.marital', '=', '6') - ->where('tbl_client.smsenable', '=', 'Yes'); + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->where('tbl_client.marital', '=', '6') + ->where('tbl_client.smsenable', '=', 'Yes'); $notapplicable_consented = Client::select(\DB::raw("tbl_client.marital")) - ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') - ->where('tbl_client.marital', '=', '7') - ->where('tbl_client.smsenable', '=', 'Yes'); + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->where('tbl_client.marital', '=', '7') + ->where('tbl_client.smsenable', '=', 'Yes'); $polygamous_consented = Client::select(\DB::raw("tbl_client.marital")) - ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') - ->where('tbl_client.marital', '=', '8') - ->where('tbl_client.smsenable', '=', 'Yes'); + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->where('tbl_client.marital', '=', '8') + ->where('tbl_client.smsenable', '=', 'Yes'); $single_registered = Client::select(\DB::raw("tbl_client.marital")) - ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') - ->where('tbl_client.marital', '=', '1'); + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->where('tbl_client.marital', '=', '1'); $monogamous_registered = Client::select(\DB::raw("tbl_client.marital")) - ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') - ->where('tbl_client.marital', '=', '2'); + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->where('tbl_client.marital', '=', '2'); $divorced_registered = Client::select(\DB::raw("tbl_client.marital")) - ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') - ->where('marital', '=', '3'); + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->where('marital', '=', '3'); $widowed_registered = Client::select(\DB::raw("tbl_client.marital")) - ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') - ->where('tbl_client.marital', '=', '4'); + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->where('tbl_client.marital', '=', '4'); $cohabating_registered = Client::select(\DB::raw("tbl_client.marital")) - ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') - ->where('tbl_client.marital', '=', '5'); + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->where('tbl_client.marital', '=', '5'); $unavailable_registered = Client::select(\DB::raw("tbl_client.marital")) - ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') - ->where('tbl_client.marital', '=', '6'); + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->where('tbl_client.marital', '=', '6'); $notapplicable_registered = Client::select(\DB::raw("tbl_client.marital")) - ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') - ->where('tbl_client.marital', '=', '7'); + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->where('tbl_client.marital', '=', '7'); $polygamous_registered = Client::select(\DB::raw("tbl_client.marital")) - ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') - ->where('tbl_client.marital', '=', '8'); + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->where('tbl_client.marital', '=', '8'); if (!empty($selected_partners)) { $consented_nine = $consented_nine->where('tbl_partner_facility.partner_id', $selected_partners); @@ -1247,6 +1250,5 @@ public function filter_client_dashboard(Request $request) $data["polygamous_registered"] = $polygamous_registered->count(); return $data; - } } diff --git a/app/Http/Controllers/SMSReportController.php b/app/Http/Controllers/SMSReportController.php index 80d4a58..3a31c82 100644 --- a/app/Http/Controllers/SMSReportController.php +++ b/app/Http/Controllers/SMSReportController.php @@ -113,169 +113,183 @@ public function filter_sms(Request $request) $selected_facilites = $request->facilities; $success = ClientOutgoing::join('tbl_client', 'tbl_clnt_outgoing.clnt_usr_id', '=', 'tbl_client.id') - ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') - ->select(\DB::raw("COUNT(status)")) - ->where('callback_status', '=', 'Success'); + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select(\DB::raw("COUNT(tbl_clnt_outgoing.status)")) + ->whereDate('tbl_clnt_outgoing.updated_at', '>=', date($request->from))->whereDate('tbl_clnt_outgoing.updated_at', '<=', date($request->to)) + ->where('tbl_clnt_outgoing.callback_status', '=', 'Success'); $failed_blacklist = ClientOutgoing::join('tbl_client', 'tbl_clnt_outgoing.clnt_usr_id', '=', 'tbl_client.id') ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') - ->select('*') - ->where('callback_status', '=', 'Failed') - ->where('failure_reason', '=', 'UserInBlacklist'); + ->select('tbl_clnt_outgoing.status') + ->where('tbl_clnt_outgoing.callback_status', '=', 'Failed') + ->whereDate('tbl_clnt_outgoing.updated_at', '>=', date($request->from))->whereDate('tbl_clnt_outgoing.updated_at', '<=', date($request->to)) + ->where('tbl_clnt_outgoing.failure_reason', '=', 'UserInBlacklist'); $failed_inactive = ClientOutgoing::join('tbl_client', 'tbl_clnt_outgoing.clnt_usr_id', '=', 'tbl_client.id') ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') - ->select('*') - ->where('callback_status', '=', 'Failed') - ->where('failure_reason', '=', 'UserInactive'); + ->select('tbl_clnt_outgoing.status') + ->where('tbl_clnt_outgoing.callback_status', '=', 'Failed') + ->whereDate('tbl_clnt_outgoing.updated_at', '>=', date($request->from))->whereDate('tbl_clnt_outgoing.updated_at', '<=', date($request->to)) + ->where('tbl_clnt_outgoing.failure_reason', '=', 'UserInactive'); $failed_deliveryfailure = ClientOutgoing::join('tbl_client', 'tbl_clnt_outgoing.clnt_usr_id', '=', 'tbl_client.id') ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') - ->select('*') - ->where('callback_status', '=', 'Failed') - ->where('failure_reason', '=', 'DeliveryFailure'); + ->select('tbl_clnt_outgoing.status') + ->where('tbl_clnt_outgoing.callback_status', '=', 'Failed') + ->whereDate('tbl_clnt_outgoing.updated_at', '>=', date($request->from))->whereDate('tbl_clnt_outgoing.updated_at', '<=', date($request->to)) + ->where('tbl_clnt_outgoing.failure_reason', '=', 'DeliveryFailure'); $rejected_blacklist = ClientOutgoing::join('tbl_client', 'tbl_clnt_outgoing.clnt_usr_id', '=', 'tbl_client.id') ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') - ->select('*') - ->where('callback_status', '=', 'Rejected') - ->where('failure_reason', '=', 'UserInBlacklist'); + ->select('tbl_clnt_outgoing.status') + ->where('tbl_clnt_outgoing.callback_status', '=', 'Rejected') + ->whereDate('tbl_clnt_outgoing.updated_at', '>=', date($request->from))->whereDate('tbl_clnt_outgoing.updated_at', '<=', date($request->to)) + ->where('tbl_clnt_outgoing.failure_reason', '=', 'UserInBlacklist'); $rejected_inactive = ClientOutgoing::join('tbl_client', 'tbl_clnt_outgoing.clnt_usr_id', '=', 'tbl_client.id') ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') - ->select('*') - ->where('callback_status', '=', 'Rejected') - ->where('failure_reason', '=', 'UserInactive'); + ->select('tbl_clnt_outgoing.status') + ->where('tbl_clnt_outgoing.callback_status', '=', 'Rejected') + ->whereDate('tbl_clnt_outgoing.updated_at', '>=', date($request->from))->whereDate('tbl_clnt_outgoing.updated_at', '<=', date($request->to)) + ->where('tbl_clnt_outgoing.failure_reason', '=', 'UserInactive'); $rejected_deliveryfailure = ClientOutgoing::join('tbl_client', 'tbl_clnt_outgoing.clnt_usr_id', '=', 'tbl_client.id') ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') - ->select('*') - ->where('callback_status', '=', 'Rejected') - ->where('failure_reason', '=', 'DeliveryFailure'); + ->select('tbl_clnt_outgoing.status') + ->where('tbl_clnt_outgoing.callback_status', '=', 'Rejected') + ->whereDate('tbl_clnt_outgoing.updated_at', '>=', date($request->from))->whereDate('tbl_clnt_outgoing.updated_at', '<=', date($request->to)) + ->where('tbl_clnt_outgoing.failure_reason', '=', 'DeliveryFailure'); // cost calculation for all the status $success_cost = ClientOutgoing::join('tbl_client', 'tbl_clnt_outgoing.clnt_usr_id', '=', 'tbl_client.id') ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') - ->select(\DB::raw("ROUND(SUM(SUBSTRING(cost, 5)), 2) as total_cost")) - ->where('callback_status', '=', 'Success') + ->select(\DB::raw("ROUND(SUM(SUBSTRING(tbl_clnt_outgoing.cost, 5)), 2) as total_cost")) + ->where('tbl_clnt_outgoing.callback_status', '=', 'Success') + ->whereDate('tbl_clnt_outgoing.updated_at', '>=', date($request->from))->whereDate('tbl_clnt_outgoing.updated_at', '<=', date($request->to)) ->pluck('total_cost'); $failed_blacklist_cost = ClientOutgoing::join('tbl_client', 'tbl_clnt_outgoing.clnt_usr_id', '=', 'tbl_client.id') ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') - ->select(\DB::raw("ROUND(SUM(SUBSTRING(cost, 5)), 2) as total_cost")) - ->where('callback_status', '=', 'Failed') - ->where('failure_reason', '=', 'UserInBlacklist') + ->select(\DB::raw("ROUND(SUM(SUBSTRING(tbl_clnt_outgoing.cost, 5)), 2) as total_cost")) + ->where('tbl_clnt_outgoing.callback_status', '=', 'Failed') + ->where('tbl_clnt_outgoing.failure_reason', '=', 'UserInBlacklist') + ->whereDate('tbl_clnt_outgoing.updated_at', '>=', date($request->from))->whereDate('tbl_clnt_outgoing.updated_at', '<=', date($request->to)) ->pluck('total_cost'); $failed_inactive_cost = ClientOutgoing::join('tbl_client', 'tbl_clnt_outgoing.clnt_usr_id', '=', 'tbl_client.id') ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') - ->select(\DB::raw("ROUND(SUM(SUBSTRING(cost, 5)), 2) as total_cost")) - ->where('callback_status', '=', 'Failed') - ->where('failure_reason', '=', 'UserInactive') + ->select(\DB::raw("ROUND(SUM(SUBSTRING(tbl_clnt_outgoing.cost, 5)), 2) as total_cost")) + ->where('tbl_clnt_outgoing.callback_status', '=', 'Failed') + ->where('tbl_clnt_outgoing.failure_reason', '=', 'UserInactive') + ->whereDate('tbl_clnt_outgoing.updated_at', '>=', date($request->from))->whereDate('tbl_clnt_outgoing.updated_at', '<=', date($request->to)) ->pluck('total_cost'); $failed_deliveryfailure_cost = ClientOutgoing::join('tbl_client', 'tbl_clnt_outgoing.clnt_usr_id', '=', 'tbl_client.id') ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') - ->select(\DB::raw("ROUND(SUM(SUBSTRING(cost, 5)), 2) as total_cost")) - ->where('callback_status', '=', 'Failed') - ->where('failure_reason', '=', 'DeliveryFailure') + ->select(\DB::raw("ROUND(SUM(SUBSTRING(tbl_clnt_outgoing.cost, 5)), 2) as total_cost")) + ->where('tbl_clnt_outgoing.callback_status', '=', 'Failed') + ->where('tbl_clnt_outgoing.failure_reason', '=', 'DeliveryFailure') + ->whereDate('tbl_clnt_outgoing.updated_at', '>=', date($request->from))->whereDate('tbl_clnt_outgoing.updated_at', '<=', date($request->to)) ->pluck('total_cost'); $rejected_blacklist_cost = ClientOutgoing::join('tbl_client', 'tbl_clnt_outgoing.clnt_usr_id', '=', 'tbl_client.id') ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') - ->select(\DB::raw("ROUND(SUM(SUBSTRING(cost, 5)), 2) as total_cost")) - ->where('callback_status', '=', 'Rejected') - ->where('failure_reason', '=', 'UserInBlacklist') + ->select(\DB::raw("ROUND(SUM(SUBSTRING(tbl_clnt_outgoing.cost, 5)), 2) as total_cost")) + ->where('tbl_clnt_outgoing.callback_status', '=', 'Rejected') + ->where('tbl_clnt_outgoing.failure_reason', '=', 'UserInBlacklist') + ->whereDate('tbl_clnt_outgoing.updated_at', '>=', date($request->from))->whereDate('tbl_clnt_outgoing.updated_at', '<=', date($request->to)) ->pluck('total_cost'); $rejected_inactive_cost = ClientOutgoing::join('tbl_client', 'tbl_clnt_outgoing.clnt_usr_id', '=', 'tbl_client.id') ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') - ->select(\DB::raw("ROUND(SUM(SUBSTRING(cost, 5)), 2) as total_cost")) - ->where('callback_status', '=', 'Rejected') - ->where('failure_reason', '=', 'UserInactive') + ->select(\DB::raw("ROUND(SUM(SUBSTRING(tbl_clnt_outgoing.cost, 5)), 2) as total_cost")) + ->where('tbl_clnt_outgoing.callback_status', '=', 'Rejected') + ->where('tbl_clnt_outgoing.failure_reason', '=', 'UserInactive') + ->whereDate('tbl_clnt_outgoing.updated_at', '>=', date($request->from))->whereDate('tbl_clnt_outgoing.updated_at', '<=', date($request->to)) ->pluck('total_cost'); $rejected_deliveryfailure_cost = ClientOutgoing::join('tbl_client', 'tbl_clnt_outgoing.clnt_usr_id', '=', 'tbl_client.id') ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') - ->select(\DB::raw("ROUND(SUM(SUBSTRING(cost, 5)), 2) as total_cost")) - ->where('callback_status', '=', 'Rejected') - ->where('failure_reason', '=', 'DeliveryFailure') + ->select(\DB::raw("ROUND(SUM(SUBSTRING(tbl_clnt_outgoing.cost, 5)), 2) as total_cost")) + ->where('tbl_clnt_outgoing.callback_status', '=', 'Rejected') + ->where('tbl_clnt_outgoing.failure_reason', '=', 'DeliveryFailure') + ->whereDate('tbl_clnt_outgoing.updated_at', '>=', date($request->from))->whereDate('tbl_clnt_outgoing.updated_at', '<=', date($request->to)) ->pluck('total_cost'); - if (!empty($selected_partners)) { - $success = $success->where('tbl_partner_facility.partner_id', $selected_partners); - $failed_blacklist = $failed_blacklist->where('tbl_partner_facility.partner_id', $selected_partners); - $failed_inactive = $failed_inactive->where('tbl_partner_facility.partner_id', $selected_partners); - $failed_deliveryfailure = $failed_deliveryfailure->where('tbl_partner_facility.partner_id', $selected_partners); - $rejected_blacklist = $rejected_blacklist->where('tbl_partner_facility.partner_id', $selected_partners); - $rejected_inactive = $rejected_inactive->where('tbl_partner_facility.partner_id', $selected_partners); - $rejected_deliveryfailure = $rejected_deliveryfailure->where('tbl_partner_facility.partner_id', $selected_partners); - $success_cost = $success_cost->where('tbl_partner_facility.partner_id', $selected_partners); - $failed_blacklist_cost = $failed_blacklist_cost->where('tbl_partner_facility.partner_id', $selected_partners); - $failed_inactive_cost = $failed_inactive_cost->where('tbl_partner_facility.partner_id', $selected_partners); - $failed_deliveryfailure_cost = $failed_deliveryfailure_cost->where('tbl_partner_facility.partner_id', $selected_partners); - $rejected_blacklist_cost = $rejected_blacklist_cost->where('tbl_partner_facility.partner_id', $selected_partners); - $rejected_inactive_cost = $rejected_inactive_cost->where('tbl_partner_facility.partner_id', $selected_partners); - $rejected_deliveryfailure_cost = $rejected_deliveryfailure_cost->where('tbl_partner_facility.partner_id', $selected_partners); - } - if (!empty($selected_counties)) { - $success = $success->where('tbl_partner_facility.county_id', $selected_counties); - $failed_blacklist = $failed_blacklist->where('tbl_partner_facility.county_id', $selected_counties); - $failed_inactive = $failed_inactive->where('tbl_partner_facility.county_id', $selected_counties); - $failed_deliveryfailure = $failed_deliveryfailure->where('tbl_partner_facility.county_id', $selected_counties); - $rejected_blacklist = $rejected_blacklist->where('tbl_partner_facility.county_id', $selected_counties); - $rejected_inactive = $rejected_inactive->where('tbl_partner_facility.county_id', $selected_counties); - $rejected_deliveryfailure = $rejected_deliveryfailure->where('tbl_partner_facility.county_id', $selected_counties); - $success_cost = $success_cost->where('tbl_partner_facility.county_id', $selected_counties); - $failed_blacklist_cost = $failed_blacklist_cost->where('tbl_partner_facility.county_id', $selected_counties); - $failed_inactive_cost = $failed_inactive_cost->where('tbl_partner_facility.county_id', $selected_counties); - $failed_deliveryfailure_cost = $failed_deliveryfailure_cost->where('tbl_partner_facility.county_id', $selected_counties); - $rejected_blacklist_cost = $rejected_blacklist_cost->where('tbl_partner_facility.county_id', $selected_counties); - $rejected_inactive_cost = $rejected_inactive_cost->where('tbl_partner_facility.county_id', $selected_counties); - $rejected_deliveryfailure_cost = $rejected_deliveryfailure_cost->where('tbl_partner_facility.county_id', $selected_counties); - } - if (!empty($selected_subcounties)) { - $success = $success->where('tbl_partner_facility.sub_county_id', $selected_subcounties); - $failed_blacklist = $failed_blacklist->where('tbl_partner_facility.sub_county_id', $selected_subcounties); - $failed_inactive = $failed_inactive->where('tbl_partner_facility.sub_county_id', $selected_subcounties); - $failed_deliveryfailure = $failed_deliveryfailure->where('tbl_partner_facility.sub_county_id', $selected_subcounties); - $rejected_blacklist = $rejected_blacklist->where('tbl_partner_facility.sub_county_id', $selected_subcounties); - $rejected_inactive = $rejected_inactive->where('tbl_partner_facility.sub_county_id', $selected_subcounties); - $rejected_deliveryfailure = $rejected_deliveryfailure->where('tbl_partner_facility.sub_county_id', $selected_subcounties); - $success_cost = $success_cost->where('tbl_partner_facility.sub_county_id', $selected_subcounties); - $failed_blacklist_cost = $failed_blacklist_cost->where('tbl_partner_facility.sub_county_id', $selected_subcounties); - $failed_inactive_cost = $failed_inactive_cost->where('tbl_partner_facility.sub_county_id', $selected_subcounties); - $failed_deliveryfailure_cost = $failed_deliveryfailure_cost->where('tbl_partner_facility.sub_county_id', $selected_subcounties); - $rejected_blacklist_cost = $rejected_blacklist_cost->where('tbl_partner_facility.sub_county_id', $selected_subcounties); - $rejected_inactive_cost = $rejected_inactive_cost->where('tbl_partner_facility.sub_county_id', $selected_subcounties); - $rejected_deliveryfailure_cost = $rejected_deliveryfailure_cost->where('tbl_partner_facility.sub_county_id', $selected_subcounties); - } - if (!empty($selected_facilites)) { - $success = $success->where('tbl_partner_facility.mfl_code', $selected_facilites); - $failed_blacklist = $failed_blacklist->where('tbl_partner_facility.mfl_code', $selected_facilites); - $failed_inactive = $failed_inactive->where('tbl_partner_facility.mfl_code', $selected_facilites); - $failed_deliveryfailure = $failed_deliveryfailure->where('tbl_partner_facility.mfl_code', $selected_facilites); - $rejected_blacklist = $rejected_blacklist->where('tbl_partner_facility.mfl_code', $selected_facilites); - $rejected_inactive = $rejected_inactive->where('tbl_partner_facility.mfl_code', $selected_facilites); - $rejected_deliveryfailure = $rejected_deliveryfailure->where('tbl_partner_facility.mfl_code', $selected_facilites); - $success_cost = $success_cost->where('tbl_partner_facility.mfl_code', $selected_facilites); - $failed_blacklist_cost = $failed_blacklist_cost->where('tbl_partner_facility.mfl_code', $selected_facilites); - $failed_inactive_cost = $failed_inactive_cost->where('tbl_partner_facility.mfl_code', $selected_facilites); - $failed_deliveryfailure_cost = $failed_deliveryfailure_cost->where('tbl_partner_facility.mfl_code', $selected_facilites); - $rejected_blacklist_cost = $rejected_blacklist_cost->where('tbl_partner_facility.mfl_code', $selected_facilites); - $rejected_inactive_cost = $rejected_inactive_cost->where('tbl_partner_facility.mfl_code', $selected_facilites); - $rejected_deliveryfailure_cost = $rejected_deliveryfailure_cost->where('tbl_partner_facility.mfl_code', $selected_facilites); - } + if (!empty($selected_partners)) { + $success = $success->where('tbl_partner_facility.partner_id', $selected_partners); + $failed_blacklist = $failed_blacklist->where('tbl_partner_facility.partner_id', $selected_partners); + $failed_inactive = $failed_inactive->where('tbl_partner_facility.partner_id', $selected_partners); + $failed_deliveryfailure = $failed_deliveryfailure->where('tbl_partner_facility.partner_id', $selected_partners); + $rejected_blacklist = $rejected_blacklist->where('tbl_partner_facility.partner_id', $selected_partners); + $rejected_inactive = $rejected_inactive->where('tbl_partner_facility.partner_id', $selected_partners); + $rejected_deliveryfailure = $rejected_deliveryfailure->where('tbl_partner_facility.partner_id', $selected_partners); + $success_cost = $success_cost->where('tbl_partner_facility.partner_id', $selected_partners); + $failed_blacklist_cost = $failed_blacklist_cost->where('tbl_partner_facility.partner_id', $selected_partners); + $failed_inactive_cost = $failed_inactive_cost->where('tbl_partner_facility.partner_id', $selected_partners); + $failed_deliveryfailure_cost = $failed_deliveryfailure_cost->where('tbl_partner_facility.partner_id', $selected_partners); + $rejected_blacklist_cost = $rejected_blacklist_cost->where('tbl_partner_facility.partner_id', $selected_partners); + $rejected_inactive_cost = $rejected_inactive_cost->where('tbl_partner_facility.partner_id', $selected_partners); + $rejected_deliveryfailure_cost = $rejected_deliveryfailure_cost->where('tbl_partner_facility.partner_id', $selected_partners); + } + if (!empty($selected_counties)) { + $success = $success->where('tbl_partner_facility.county_id', $selected_counties); + $failed_blacklist = $failed_blacklist->where('tbl_partner_facility.county_id', $selected_counties); + $failed_inactive = $failed_inactive->where('tbl_partner_facility.county_id', $selected_counties); + $failed_deliveryfailure = $failed_deliveryfailure->where('tbl_partner_facility.county_id', $selected_counties); + $rejected_blacklist = $rejected_blacklist->where('tbl_partner_facility.county_id', $selected_counties); + $rejected_inactive = $rejected_inactive->where('tbl_partner_facility.county_id', $selected_counties); + $rejected_deliveryfailure = $rejected_deliveryfailure->where('tbl_partner_facility.county_id', $selected_counties); + $success_cost = $success_cost->where('tbl_partner_facility.county_id', $selected_counties); + $failed_blacklist_cost = $failed_blacklist_cost->where('tbl_partner_facility.county_id', $selected_counties); + $failed_inactive_cost = $failed_inactive_cost->where('tbl_partner_facility.county_id', $selected_counties); + $failed_deliveryfailure_cost = $failed_deliveryfailure_cost->where('tbl_partner_facility.county_id', $selected_counties); + $rejected_blacklist_cost = $rejected_blacklist_cost->where('tbl_partner_facility.county_id', $selected_counties); + $rejected_inactive_cost = $rejected_inactive_cost->where('tbl_partner_facility.county_id', $selected_counties); + $rejected_deliveryfailure_cost = $rejected_deliveryfailure_cost->where('tbl_partner_facility.county_id', $selected_counties); + } + if (!empty($selected_subcounties)) { + $success = $success->where('tbl_partner_facility.sub_county_id', $selected_subcounties); + $failed_blacklist = $failed_blacklist->where('tbl_partner_facility.sub_county_id', $selected_subcounties); + $failed_inactive = $failed_inactive->where('tbl_partner_facility.sub_county_id', $selected_subcounties); + $failed_deliveryfailure = $failed_deliveryfailure->where('tbl_partner_facility.sub_county_id', $selected_subcounties); + $rejected_blacklist = $rejected_blacklist->where('tbl_partner_facility.sub_county_id', $selected_subcounties); + $rejected_inactive = $rejected_inactive->where('tbl_partner_facility.sub_county_id', $selected_subcounties); + $rejected_deliveryfailure = $rejected_deliveryfailure->where('tbl_partner_facility.sub_county_id', $selected_subcounties); + $success_cost = $success_cost->where('tbl_partner_facility.sub_county_id', $selected_subcounties); + $failed_blacklist_cost = $failed_blacklist_cost->where('tbl_partner_facility.sub_county_id', $selected_subcounties); + $failed_inactive_cost = $failed_inactive_cost->where('tbl_partner_facility.sub_county_id', $selected_subcounties); + $failed_deliveryfailure_cost = $failed_deliveryfailure_cost->where('tbl_partner_facility.sub_county_id', $selected_subcounties); + $rejected_blacklist_cost = $rejected_blacklist_cost->where('tbl_partner_facility.sub_county_id', $selected_subcounties); + $rejected_inactive_cost = $rejected_inactive_cost->where('tbl_partner_facility.sub_county_id', $selected_subcounties); + $rejected_deliveryfailure_cost = $rejected_deliveryfailure_cost->where('tbl_partner_facility.sub_county_id', $selected_subcounties); + } + if (!empty($selected_facilites)) { + $success = $success->where('tbl_partner_facility.mfl_code', $selected_facilites); + $failed_blacklist = $failed_blacklist->where('tbl_partner_facility.mfl_code', $selected_facilites); + $failed_inactive = $failed_inactive->where('tbl_partner_facility.mfl_code', $selected_facilites); + $failed_deliveryfailure = $failed_deliveryfailure->where('tbl_partner_facility.mfl_code', $selected_facilites); + $rejected_blacklist = $rejected_blacklist->where('tbl_partner_facility.mfl_code', $selected_facilites); + $rejected_inactive = $rejected_inactive->where('tbl_partner_facility.mfl_code', $selected_facilites); + $rejected_deliveryfailure = $rejected_deliveryfailure->where('tbl_partner_facility.mfl_code', $selected_facilites); + $success_cost = $success_cost->where('tbl_partner_facility.mfl_code', $selected_facilites); + $failed_blacklist_cost = $failed_blacklist_cost->where('tbl_partner_facility.mfl_code', $selected_facilites); + $failed_inactive_cost = $failed_inactive_cost->where('tbl_partner_facility.mfl_code', $selected_facilites); + $failed_deliveryfailure_cost = $failed_deliveryfailure_cost->where('tbl_partner_facility.mfl_code', $selected_facilites); + $rejected_blacklist_cost = $rejected_blacklist_cost->where('tbl_partner_facility.mfl_code', $selected_facilites); + $rejected_inactive_cost = $rejected_inactive_cost->where('tbl_partner_facility.mfl_code', $selected_facilites); + $rejected_deliveryfailure_cost = $rejected_deliveryfailure_cost->where('tbl_partner_facility.mfl_code', $selected_facilites); + } - $data["success"] = $success->count(); - $data["failed_blacklist"] = $failed_blacklist->count(); - $data["failed_inactive"] = $failed_inactive->count(); - $data["failed_deliveryfailure"] = $failed_deliveryfailure->count(); - $data["rejected_blacklist"] = $rejected_blacklist->count(); - $data["rejected_inactive"] = $rejected_inactive->count(); - $data["rejected_deliveryfailure"] = $rejected_deliveryfailure->count(); - $data["success_cost"] = $success_cost; - $data["failed_blacklist_cost"] = $failed_blacklist_cost; - $data["failed_inactive_cost"] = $failed_inactive_cost; - $data["failed_deliveryfailure_cost"] = $failed_deliveryfailure_cost; - $data["rejected_blacklist_cost"] = $rejected_blacklist_cost; - $data["rejected_inactive_cost"] = $rejected_inactive_cost; - $data["rejected_deliveryfailure_cost"] = $rejected_deliveryfailure_cost; + $data["success"] = $success->count(); + $data["failed_blacklist"] = $failed_blacklist->count(); + $data["failed_inactive"] = $failed_inactive->count(); + $data["failed_deliveryfailure"] = $failed_deliveryfailure->count(); + $data["rejected_blacklist"] = $rejected_blacklist->count(); + $data["rejected_inactive"] = $rejected_inactive->count(); + $data["rejected_deliveryfailure"] = $rejected_deliveryfailure->count(); + $data["success_cost"] = $success_cost; + $data["failed_blacklist_cost"] = $failed_blacklist_cost; + $data["failed_inactive_cost"] = $failed_inactive_cost; + $data["failed_deliveryfailure_cost"] = $failed_deliveryfailure_cost; + $data["rejected_blacklist_cost"] = $rejected_blacklist_cost; + $data["rejected_inactive_cost"] = $rejected_inactive_cost; + $data["rejected_deliveryfailure_cost"] = $rejected_deliveryfailure_cost; - return $data; + return $data; } } diff --git a/resources/views/sms/sms_report.blade.php b/resources/views/sms/sms_report.blade.php index 4ecc945..743089a 100644 --- a/resources/views/sms/sms_report.blade.php +++ b/resources/views/sms/sms_report.blade.php @@ -18,7 +18,7 @@
{{ csrf_field() }}
-
+
-
+
-
+
-
+
@@ -61,7 +61,48 @@
-
+ + +
+
+
+
+ +
+
+ +
+
+ +
+
+
+
+ +
+
+
+
+ +
+
+ + +
+
+ +
+
+
+
+ + + +
-
-
+
+
-

+

-
+
+
+
+
+ +

+ +
+
+
+
@endsection @@ -365,7 +375,7 @@ series: [{ name: 'SMS Count', data: [Success, Failed_blacklist, Failed_absent, Failed_deliveryfailure, Failed_inactive, Rejected_inactive, Rejected_blacklist, Rejected_deliveryfailure] - } + } // { // type: 'spline', // name: 'Cost(Ksh)', @@ -431,55 +441,102 @@ }); - $(function () { - var partner_data_array = []; - var partner_delivery = ; + $(function() { + var partner_delivered_array = []; + var partner_failed_array = []; + var partner_delivery = ; + var partner_failed = ; + + $.each(partner_delivery, function(key, value) { + + var total_value = value.total; + delete value.total; //remove the attribute total + value.y = total_value; //add a new attribute "y" for plotting values on y-axis + partner_delivered_array.push(value); + }); - $.each(partner_delivery, function(key, value){ + $.each(partner_failed, function(key, value) { - var total_value = value.total; - delete value.total;//remove the attribute total - value.y = total_value;//add a new attribute "y" for plotting values on y-axis - partner_data_array.push(value); - }); + var total_value = value.total; + delete value.total; //remove the attribute total + value.y = total_value; //add a new attribute "y" for plotting values on y-axis + partner_failed_array.push(value); + }); - $('#partner_analytic').highcharts({ - chart: { - type: 'column', + $('#partner_analytic_delivered').highcharts({ + chart: { + type: 'column', - }, - title: { - text: 'Partners Delivered SMS ' - }, - xAxis: { - type: 'category' - }, + }, + title: { + text: 'Partners Delivered SMS ' + }, + xAxis: { + type: 'category' + }, - legend: { - enabled: false - }, + legend: { + enabled: false + }, - plotOptions: { - series: { - borderWidth: 0, - dataLabels: { - enabled: true, + plotOptions: { + series: { + borderWidth: 0, + dataLabels: { + enabled: true, + } } + }, + + series: [{ + name: 'Delivered Sms Count', + colorByPoint: true, + data: partner_delivered_array + + }], + + drilldown: { + series: [] } - }, + }); - series: [{ - name: 'Delivered Sms Count', - colorByPoint: true, - data:partner_data_array + $('#partner_analytic_failed').highcharts({ + chart: { + type: 'column', - }], + }, + title: { + text: 'Partners Failed SMS ' + }, + xAxis: { + type: 'category' + }, + + legend: { + enabled: false + }, + + plotOptions: { + series: { + borderWidth: 0, + dataLabels: { + enabled: true, + } + } + }, + + series: [{ + name: 'Failed Sms Count', + colorByPoint: true, + data: partner_failed_array - drilldown: { - series: [] - } - }) -}); + }], + + drilldown: { + series: [] + } + }) + }); var colors = Highcharts.getOptions().colors; From d9a2ba133be2dc80fc03368100d6f47e71972868 Mon Sep 17 00:00:00 2001 From: Ronald-pro <36841157+Ronald-pro@users.noreply.github.com> Date: Thu, 10 Feb 2022 15:10:58 +0300 Subject: [PATCH 013/171] added sms cost per partners analytics --- app/Http/Controllers/SMSReportController.php | 27 +++++---- resources/views/sms/sms_report.blade.php | 59 ++++++++++++++++++++ 2 files changed, 76 insertions(+), 10 deletions(-) diff --git a/app/Http/Controllers/SMSReportController.php b/app/Http/Controllers/SMSReportController.php index 0c5bd16..ffc8f8e 100644 --- a/app/Http/Controllers/SMSReportController.php +++ b/app/Http/Controllers/SMSReportController.php @@ -35,10 +35,16 @@ public function success_sms() ->groupBy('tbl_partner.name') ->get(); + $cost_partners = ClientOutgoing::join('tbl_client', 'tbl_clnt_outgoing.clnt_usr_id', '=', 'tbl_client.id') + ->join('tbl_partner', 'tbl_client.partner_id', '=', 'tbl_partner.id') + ->select('tbl_partner.name', DB::raw("ROUND(SUM(SUBSTRING(tbl_clnt_outgoing.cost, 5)), 0) as total_cost")) + ->groupBy('tbl_partner.name') + ->get(); + $success = ClientOutgoing::select("callback_status") ->where('callback_status', '=', 'Success') ->count(); - //dd($success); + $failed_blacklist = ClientOutgoing::select('callback_status') ->where('callback_status', '=', 'Failed') @@ -75,34 +81,34 @@ public function success_sms() ->count(); // cost calculation for all the status - $success_cost = ClientOutgoing::select(\DB::raw("ROUND(SUM(SUBSTRING(cost, 5)), 2) as total_cost")) + $success_cost = ClientOutgoing::select(\DB::raw("ROUND(SUM(SUBSTRING(cost, 5)), 0) as total_cost")) ->where('callback_status', '=', 'Success') ->pluck('total_cost'); - $failed_blacklist_cost = ClientOutgoing::select(\DB::raw("ROUND(SUM(SUBSTRING(cost, 5)), 2) as total_cost")) + $failed_blacklist_cost = ClientOutgoing::select(\DB::raw("ROUND(SUM(SUBSTRING(cost, 5)), 0) as total_cost")) ->where('callback_status', '=', 'Failed') ->where('failure_reason', '=', 'UserInBlacklist') ->pluck('total_cost'); - $failed_absent_cost = ClientOutgoing::select(\DB::raw("ROUND(SUM(SUBSTRING(cost, 5)), 2) as total_cost")) + $failed_absent_cost = ClientOutgoing::select(\DB::raw("ROUND(SUM(SUBSTRING(cost, 5)), 0) as total_cost")) ->where('callback_status', '=', 'Failed') ->where('failure_reason', '=', 'AbsentSubscriber') ->pluck('total_cost'); - $failed_inactive_cost = ClientOutgoing::select(\DB::raw("ROUND(SUM(SUBSTRING(cost, 5)), 2) as total_cost")) + $failed_inactive_cost = ClientOutgoing::select(\DB::raw("ROUND(SUM(SUBSTRING(cost, 5)), 0) as total_cost")) ->where('callback_status', '=', 'Failed') ->where('failure_reason', '=', 'UserInactive') ->pluck('total_cost'); - $failed_deliveryfailure_cost = ClientOutgoing::select(\DB::raw("ROUND(SUM(SUBSTRING(cost, 5)), 2) as total_cost")) + $failed_deliveryfailure_cost = ClientOutgoing::select(\DB::raw("ROUND(SUM(SUBSTRING(cost, 5)), 0) as total_cost")) ->where('callback_status', '=', 'Failed') ->where('failure_reason', '=', 'DeliveryFailure') ->pluck('total_cost'); - $rejected_blacklist_cost = ClientOutgoing::select(\DB::raw("ROUND(SUM(SUBSTRING(cost, 5)), 2) as total_cost")) + $rejected_blacklist_cost = ClientOutgoing::select(\DB::raw("ROUND(SUM(SUBSTRING(cost, 5)), 0) as total_cost")) ->where('callback_status', '=', 'Rejected') ->where('failure_reason', '=', 'UserInBlacklist') ->pluck('total_cost'); - $rejected_inactive_cost = ClientOutgoing::select(\DB::raw("ROUND(SUM(SUBSTRING(cost, 5)), 2) as total_cost")) + $rejected_inactive_cost = ClientOutgoing::select(\DB::raw("ROUND(SUM(SUBSTRING(cost, 5)), 0) as total_cost")) ->where('callback_status', '=', 'Rejected') ->where('failure_reason', '=', 'UserInactive') ->pluck('total_cost'); - $rejected_deliveryfailure_cost = ClientOutgoing::select(\DB::raw("ROUND(SUM(SUBSTRING(cost, 5)), 2) as total_cost")) + $rejected_deliveryfailure_cost = ClientOutgoing::select(\DB::raw("ROUND(SUM(SUBSTRING(cost, 5)), 0) as total_cost")) ->where('callback_status', '=', 'Rejected') ->where('failure_reason', '=', 'DeliveryFailure') ->pluck('total_cost'); @@ -129,7 +135,8 @@ public function success_sms() 'rejected_inactive_cost', 'rejected_deliveryfailure_cost', 'delivered_partners', - 'failed_partners' + 'failed_partners', + 'cost_partners' )); } diff --git a/resources/views/sms/sms_report.blade.php b/resources/views/sms/sms_report.blade.php index f0768ee..7a528f8 100644 --- a/resources/views/sms/sms_report.blade.php +++ b/resources/views/sms/sms_report.blade.php @@ -160,6 +160,17 @@
+
+
+
+ +

+ +
+
+
+
+ @endsection @@ -444,8 +455,11 @@ $(function() { var partner_delivered_array = []; var partner_failed_array = []; + var partner_cost_array = []; + var partner_delivery = ; var partner_failed = ; + var partner_cost = ; $.each(partner_delivery, function(key, value) { @@ -463,6 +477,14 @@ partner_failed_array.push(value); }); + $.each(partner_cost, function(key, value) { + + var total_value = value.total_cost; + delete value.total_cost; //remove the attribute total + value.y = total_value; //add a new attribute "y" for plotting values on y-axis + partner_cost_array.push(value); + }); + $('#partner_analytic_delivered').highcharts({ chart: { type: 'column', @@ -532,6 +554,43 @@ }], + drilldown: { + series: [] + } + }); + + $('#partner_analytic_cost').highcharts({ + chart: { + type: 'column', + + }, + title: { + text: 'Partners SMS Cost Distribution ' + }, + xAxis: { + type: 'category' + }, + + legend: { + enabled: false + }, + + plotOptions: { + series: { + borderWidth: 0, + dataLabels: { + enabled: true, + } + } + }, + + series: [{ + name: 'SMS Cost(Ksh)', + colorByPoint: true, + data: partner_cost_array + + }], + drilldown: { series: [] } From 9e875a87a0f61e62470cdcedf44a3224be492f46 Mon Sep 17 00:00:00 2001 From: Ronald-pro <36841157+Ronald-pro@users.noreply.github.com> Date: Mon, 14 Feb 2022 12:51:37 +0300 Subject: [PATCH 014/171] included counties sms cost analytics --- app/Http/Controllers/SMSReportController.php | 12 ++++- resources/views/sms/sms_report.blade.php | 56 ++++++++++++++++++++ 2 files changed, 67 insertions(+), 1 deletion(-) diff --git a/app/Http/Controllers/SMSReportController.php b/app/Http/Controllers/SMSReportController.php index ffc8f8e..486a2b2 100644 --- a/app/Http/Controllers/SMSReportController.php +++ b/app/Http/Controllers/SMSReportController.php @@ -41,6 +41,15 @@ public function success_sms() ->groupBy('tbl_partner.name') ->get(); + $cost_counties = ClientOutgoing::join('tbl_client', 'tbl_clnt_outgoing.clnt_usr_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->join('tbl_county', 'tbl_partner_facility.county_id', '=', 'tbl_county.id') + ->select('tbl_county.name', DB::raw("ROUND(SUM(SUBSTRING(tbl_clnt_outgoing.cost, 5)), 0) as total_cost")) + ->groupBy('tbl_county.name') + ->get(); + + //dd($cost_counties); + $success = ClientOutgoing::select("callback_status") ->where('callback_status', '=', 'Success') ->count(); @@ -136,7 +145,8 @@ public function success_sms() 'rejected_deliveryfailure_cost', 'delivered_partners', 'failed_partners', - 'cost_partners' + 'cost_partners', + 'cost_counties' )); } diff --git a/resources/views/sms/sms_report.blade.php b/resources/views/sms/sms_report.blade.php index 7a528f8..1a5bade 100644 --- a/resources/views/sms/sms_report.blade.php +++ b/resources/views/sms/sms_report.blade.php @@ -117,6 +117,15 @@
+
+
+
+ +

+ +
+
+
@@ -456,10 +465,12 @@ var partner_delivered_array = []; var partner_failed_array = []; var partner_cost_array = []; + var county_cost_array = []; var partner_delivery = ; var partner_failed = ; var partner_cost = ; + var county_cost = ; $.each(partner_delivery, function(key, value) { @@ -485,6 +496,14 @@ partner_cost_array.push(value); }); + $.each(county_cost, function(key, value) { + + var total_value = value.total_cost; + delete value.total_cost; //remove the attribute total + value.y = total_value; //add a new attribute "y" for plotting values on y-axis + county_cost_array.push(value); + }); + $('#partner_analytic_delivered').highcharts({ chart: { type: 'column', @@ -591,6 +610,43 @@ }], + drilldown: { + series: [] + } + }); + + $('#county_analytic_cost').highcharts({ + chart: { + type: 'column', + + }, + title: { + text: 'Counties SMS Cost Distribution ' + }, + xAxis: { + type: 'category' + }, + + legend: { + enabled: false + }, + + plotOptions: { + series: { + borderWidth: 0, + dataLabels: { + enabled: true, + } + } + }, + + series: [{ + name: 'SMS Cost(Ksh)', + colorByPoint: true, + data: county_cost_array + + }], + drilldown: { series: [] } From 7782f8c22b48045529d940610469bd62b4e302f8 Mon Sep 17 00:00:00 2001 From: Ronald-pro <36841157+Ronald-pro@users.noreply.github.com> Date: Mon, 14 Feb 2022 14:06:27 +0300 Subject: [PATCH 015/171] date filters for sms analytics --- app/Http/Controllers/SMSReportController.php | 148 +++++++++++++++++++ resources/views/sms/sms_report.blade.php | 45 +----- routes/web.php | 1 + 3 files changed, 150 insertions(+), 44 deletions(-) diff --git a/app/Http/Controllers/SMSReportController.php b/app/Http/Controllers/SMSReportController.php index 486a2b2..d693dfd 100644 --- a/app/Http/Controllers/SMSReportController.php +++ b/app/Http/Controllers/SMSReportController.php @@ -353,4 +353,152 @@ public function filter_sms(Request $request) return $data; } + + public function filtering_sms(Request $request) + { + $delivered_partners = ClientOutgoing::join('tbl_client', 'tbl_clnt_outgoing.clnt_usr_id', '=', 'tbl_client.id') + ->join('tbl_partner', 'tbl_client.partner_id', '=', 'tbl_partner.id') + ->select('tbl_partner.name', DB::raw('count(tbl_clnt_outgoing.callback_status) as total')) + ->where('tbl_clnt_outgoing.callback_status', '=', 'Success') + ->whereDate('tbl_clnt_outgoing.created_at', '>=', date($request->from))->whereDate('tbl_clnt_outgoing.created_at', '<=', date($request->to)) + ->groupBy('tbl_partner.name') + // ->groupBy(DB::raw("DATE_FORMAT(tbl_clnt_outgoing.created_at, '%m-%Y')")) + ->get(); + // dd($delivered_partners); + $failed_partners = ClientOutgoing::join('tbl_client', 'tbl_clnt_outgoing.clnt_usr_id', '=', 'tbl_client.id') + ->join('tbl_partner', 'tbl_client.partner_id', '=', 'tbl_partner.id') + ->select('tbl_partner.name', DB::raw('count(tbl_clnt_outgoing.callback_status) as total')) + ->where('tbl_clnt_outgoing.callback_status', '=', 'Failed') + ->whereDate('tbl_clnt_outgoing.created_at', '>=', date($request->from))->whereDate('tbl_clnt_outgoing.created_at', '<=', date($request->to)) + ->groupBy('tbl_partner.name') + ->get(); + + $cost_partners = ClientOutgoing::join('tbl_client', 'tbl_clnt_outgoing.clnt_usr_id', '=', 'tbl_client.id') + ->join('tbl_partner', 'tbl_client.partner_id', '=', 'tbl_partner.id') + ->select('tbl_partner.name', DB::raw("ROUND(SUM(SUBSTRING(tbl_clnt_outgoing.cost, 5)), 0) as total_cost")) + ->whereDate('tbl_clnt_outgoing.created_at', '>=', date($request->from))->whereDate('tbl_clnt_outgoing.created_at', '<=', date($request->to)) + ->groupBy('tbl_partner.name') + ->get(); + + $cost_counties = ClientOutgoing::join('tbl_client', 'tbl_clnt_outgoing.clnt_usr_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->join('tbl_county', 'tbl_partner_facility.county_id', '=', 'tbl_county.id') + ->select('tbl_county.name', DB::raw("ROUND(SUM(SUBSTRING(tbl_clnt_outgoing.cost, 5)), 0) as total_cost")) + ->whereDate('tbl_clnt_outgoing.created_at', '>=', date($request->from))->whereDate('tbl_clnt_outgoing.created_at', '<=', date($request->to)) + ->groupBy('tbl_county.name') + ->get(); + + //dd($cost_counties); + + $success = ClientOutgoing::select("callback_status") + ->where('callback_status', '=', 'Success') + ->whereDate('tbl_clnt_outgoing.created_at', '>=', date($request->from))->whereDate('tbl_clnt_outgoing.created_at', '<=', date($request->to)) + ->count(); + + + $failed_blacklist = ClientOutgoing::select('callback_status') + ->where('callback_status', '=', 'Failed') + ->where('failure_reason', '=', 'UserInBlacklist') + ->whereDate('tbl_clnt_outgoing.created_at', '>=', date($request->from))->whereDate('tbl_clnt_outgoing.created_at', '<=', date($request->to)) + ->count(); + $failed_absent = ClientOutgoing::select('callback_status') + ->where('callback_status', '=', 'Failed') + ->where('failure_reason', '=', 'AbsentSubscriber') + ->whereDate('tbl_clnt_outgoing.created_at', '>=', date($request->from))->whereDate('tbl_clnt_outgoing.created_at', '<=', date($request->to)) + ->count(); + + $failed_inactive = ClientOutgoing::select('callback_status') + ->where('callback_status', '=', 'Failed') + ->where('failure_reason', '=', 'UserInactive') + ->whereDate('tbl_clnt_outgoing.created_at', '>=', date($request->from))->whereDate('tbl_clnt_outgoing.created_at', '<=', date($request->to)) + ->count(); + + $failed_deliveryfailure = ClientOutgoing::select('callback_status') + ->where('callback_status', '=', 'Failed') + ->where('failure_reason', '=', 'DeliveryFailure') + ->whereDate('tbl_clnt_outgoing.created_at', '>=', date($request->from))->whereDate('tbl_clnt_outgoing.created_at', '<=', date($request->to)) + ->count(); + + $rejected_blacklist = ClientOutgoing::select('callback_status') + ->where('callback_status', '=', 'Rejected') + ->where('failure_reason', '=', 'UserInBlacklist') + ->whereDate('tbl_clnt_outgoing.created_at', '>=', date($request->from))->whereDate('tbl_clnt_outgoing.created_at', '<=', date($request->to)) + ->count(); + + $rejected_inactive = ClientOutgoing::select('callback_status') + ->where('callback_status', '=', 'Rejected') + ->where('failure_reason', '=', 'UserInactive') + ->whereDate('tbl_clnt_outgoing.created_at', '>=', date($request->from))->whereDate('tbl_clnt_outgoing.created_at', '<=', date($request->to)) + ->count(); + + $rejected_deliveryfailure = ClientOutgoing::select('callback_status') + ->where('callback_status', '=', 'Rejected') + ->where('failure_reason', '=', 'DeliveryFailure') + ->whereDate('tbl_clnt_outgoing.created_at', '>=', date($request->from))->whereDate('tbl_clnt_outgoing.created_at', '<=', date($request->to)) + ->count(); + + // cost calculation for all the status + $success_cost = ClientOutgoing::select(\DB::raw("ROUND(SUM(SUBSTRING(cost, 5)), 0) as total_cost")) + ->where('callback_status', '=', 'Success') + ->whereDate('tbl_clnt_outgoing.created_at', '>=', date($request->from))->whereDate('tbl_clnt_outgoing.created_at', '<=', date($request->to)) + ->pluck('total_cost'); + $failed_blacklist_cost = ClientOutgoing::select(\DB::raw("ROUND(SUM(SUBSTRING(cost, 5)), 0) as total_cost")) + ->where('callback_status', '=', 'Failed') + ->where('failure_reason', '=', 'UserInBlacklist') + ->whereDate('tbl_clnt_outgoing.created_at', '>=', date($request->from))->whereDate('tbl_clnt_outgoing.created_at', '<=', date($request->to)) + ->pluck('total_cost'); + $failed_absent_cost = ClientOutgoing::select(\DB::raw("ROUND(SUM(SUBSTRING(cost, 5)), 0) as total_cost")) + ->where('callback_status', '=', 'Failed') + ->where('failure_reason', '=', 'AbsentSubscriber') + ->whereDate('tbl_clnt_outgoing.created_at', '>=', date($request->from))->whereDate('tbl_clnt_outgoing.created_at', '<=', date($request->to)) + ->pluck('total_cost'); + $failed_inactive_cost = ClientOutgoing::select(\DB::raw("ROUND(SUM(SUBSTRING(cost, 5)), 0) as total_cost")) + ->where('callback_status', '=', 'Failed') + ->where('failure_reason', '=', 'UserInactive') + ->whereDate('tbl_clnt_outgoing.created_at', '>=', date($request->from))->whereDate('tbl_clnt_outgoing.created_at', '<=', date($request->to)) + ->pluck('total_cost'); + $failed_deliveryfailure_cost = ClientOutgoing::select(\DB::raw("ROUND(SUM(SUBSTRING(cost, 5)), 0) as total_cost")) + ->where('callback_status', '=', 'Failed') + ->where('failure_reason', '=', 'DeliveryFailure') + ->whereDate('tbl_clnt_outgoing.created_at', '>=', date($request->from))->whereDate('tbl_clnt_outgoing.created_at', '<=', date($request->to)) + ->pluck('total_cost'); + $rejected_blacklist_cost = ClientOutgoing::select(\DB::raw("ROUND(SUM(SUBSTRING(cost, 5)), 0) as total_cost")) + ->where('callback_status', '=', 'Rejected') + ->where('failure_reason', '=', 'UserInBlacklist') + ->whereDate('tbl_clnt_outgoing.created_at', '>=', date($request->from))->whereDate('tbl_clnt_outgoing.created_at', '<=', date($request->to)) + ->pluck('total_cost'); + $rejected_inactive_cost = ClientOutgoing::select(\DB::raw("ROUND(SUM(SUBSTRING(cost, 5)), 0) as total_cost")) + ->where('callback_status', '=', 'Rejected') + ->where('failure_reason', '=', 'UserInactive') + ->whereDate('tbl_clnt_outgoing.created_at', '>=', date($request->from))->whereDate('tbl_clnt_outgoing.created_at', '<=', date($request->to)) + ->pluck('total_cost'); + $rejected_deliveryfailure_cost = ClientOutgoing::select(\DB::raw("ROUND(SUM(SUBSTRING(cost, 5)), 0) as total_cost")) + ->where('callback_status', '=', 'Rejected') + ->where('failure_reason', '=', 'DeliveryFailure') + ->whereDate('tbl_clnt_outgoing.created_at', '>=', date($request->from))->whereDate('tbl_clnt_outgoing.created_at', '<=', date($request->to)) + ->pluck('total_cost'); + + return view('sms.sms_report', compact( + 'success', + 'failed_blacklist', + 'failed_absent', + 'failed_inactive', + 'failed_deliveryfailure', + 'rejected_blacklist', + 'rejected_inactive', + 'rejected_deliveryfailure', + 'success_cost', + 'failed_blacklist_cost', + 'failed_absent_cost', + 'failed_inactive_cost', + 'failed_deliveryfailure_cost', + 'rejected_blacklist_cost', + 'rejected_inactive_cost', + 'rejected_deliveryfailure_cost', + 'delivered_partners', + 'failed_partners', + 'cost_partners', + 'cost_counties' + )); + } } diff --git a/resources/views/sms/sms_report.blade.php b/resources/views/sms/sms_report.blade.php index 1a5bade..aba93b2 100644 --- a/resources/views/sms/sms_report.blade.php +++ b/resources/views/sms/sms_report.blade.php @@ -15,52 +15,9 @@
- + {{ csrf_field() }}
-
-
- - -
-
-
-
- -
-
-
-
- - -
-
-
-
- - - -
-
-
diff --git a/routes/web.php b/routes/web.php index a8faae3..f1db35a 100644 --- a/routes/web.php +++ b/routes/web.php @@ -196,6 +196,7 @@ //Route::get('/sms/analytics', ['uses' => 'App\Http\Controllers\SMSReportController@index', 'as' => 'sms-analytics']); Route::get('/sms/analytics', ['uses' => 'App\Http\Controllers\SMSReportController@success_sms', 'as' => 'sms-analytics']); Route::get('/filter_sms', ['uses' => 'App\Http\Controllers\SMSReportController@filter_sms', 'as' => 'filter_sms']); + Route::get('/filters_sms', ['uses' => 'App\Http\Controllers\SMSReportController@filtering_sms', 'as' => 'filtering_sms']); }); From dfe14fbf800a3c2b43a218a53078077584c30585 Mon Sep 17 00:00:00 2001 From: Ronald-pro <36841157+Ronald-pro@users.noreply.github.com> Date: Mon, 14 Feb 2022 21:58:56 +0300 Subject: [PATCH 016/171] updated landing page filters --- app/Http/Controllers/DashboardController.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/app/Http/Controllers/DashboardController.php b/app/Http/Controllers/DashboardController.php index 7b48590..a1a936d 100644 --- a/app/Http/Controllers/DashboardController.php +++ b/app/Http/Controllers/DashboardController.php @@ -281,7 +281,7 @@ public function filter_dashboard(Request $request) if (!empty($selected_partners)) { $all_clients_number = $all_clients_number->where('tbl_partner_facility.partner_id', $selected_partners); - $pec_client_count = $pec_client_count->where('tbl_partner_facility.partner_id', $selected_partners); + // $pec_client_count = $pec_client_count->where('tbl_partner_facility.partner_id', $selected_partners); $all_target_clients = $all_target_clients->where('partner_id', $selected_partners); $all_consented_clients = $all_consented_clients->where('tbl_partner_facility.partner_id', $selected_partners); $number_of_facilities = $number_of_facilities->where('partner_id', $selected_partners); @@ -291,7 +291,7 @@ public function filter_dashboard(Request $request) } if (!empty($selected_counties)) { $all_clients_number = $all_clients_number->where('tbl_partner_facility.county_id', $selected_counties); - $pec_client_count = $pec_client_count->where('tbl_partner_facility.county_id', $selected_counties); + // $pec_client_count = $pec_client_count->where('tbl_partner_facility.county_id', $selected_counties); $all_target_clients = $all_target_clients->where('county_id', $selected_counties); $all_consented_clients = $all_consented_clients->where('tbl_partner_facility.county_id', $selected_counties); $number_of_facilities = $number_of_facilities->where('county_id', $selected_counties); @@ -301,7 +301,7 @@ public function filter_dashboard(Request $request) } if (!empty($selected_subcounties)) { $all_clients_number = $all_clients_number->where('tbl_partner_facility.sub_county_id', $selected_subcounties); - $pec_client_count = $pec_client_count->where('tbl_partner_facility.sub_county_id', $selected_subcounties); + // $pec_client_count = $pec_client_count->where('tbl_partner_facility.sub_county_id', $selected_subcounties); $all_target_clients = $all_target_clients->where('sub_county_id', $selected_subcounties); $all_consented_clients = $all_consented_clients->where('tbl_partner_facility.sub_county_id', $selected_subcounties); $number_of_facilities = $number_of_facilities->where('sub_county_id', $selected_subcounties); @@ -311,7 +311,7 @@ public function filter_dashboard(Request $request) } if (!empty($selected_facilites)) { $all_clients_number = $all_clients_number->where('tbl_partner_facility.mfl_code', $selected_facilites); - $pec_client_count = $pec_client_count->where('tbl_partner_facility.mfl_code', $selected_facilites); + // $pec_client_count = $pec_client_count->where('tbl_partner_facility.mfl_code', $selected_facilites); $all_target_clients = $all_target_clients->where('mfl_code', $selected_facilites); $all_consented_clients = $all_consented_clients->where('tbl_partner_facility.mfl_code', $selected_facilites); $number_of_facilities = $number_of_facilities->where('mfl_code', $selected_facilites); From ed7405eca9ff863a167308c239e15cf71bf76922 Mon Sep 17 00:00:00 2001 From: Ronald-pro <36841157+Ronald-pro@users.noreply.github.com> Date: Mon, 21 Feb 2022 11:07:39 +0300 Subject: [PATCH 017/171] fixed error on message extract --- app/Http/Controllers/DashboardController.php | 22 ++++++------ app/Http/Controllers/ReportController.php | 38 ++++++++++---------- resources/views/sms/sms_report.blade.php | 22 ++++++------ 3 files changed, 44 insertions(+), 38 deletions(-) diff --git a/app/Http/Controllers/DashboardController.php b/app/Http/Controllers/DashboardController.php index a1a936d..c1fc594 100644 --- a/app/Http/Controllers/DashboardController.php +++ b/app/Http/Controllers/DashboardController.php @@ -186,6 +186,8 @@ public function main_graph_dashboard() $all_target_clients = PartnerFacility::select('avg_clients')->where('is_approved', '=', 'Yes') ->where('partner_id', Auth::user()->partner_id) ->sum('avg_clients'); + + // dd($all_target_clients); $all_consented_clients = Client::where('smsenable', '=', 'Yes') ->where('partner_id', Auth::user()->partner_id) ->count(); @@ -203,16 +205,16 @@ public function main_graph_dashboard() ->count(); - $all_clients_number = cache()->remember('all_clients_number', now()->addMinutes(5), function () { - return ClientPerformance::whereNotNull('actual_clients') - ->where('partner_id', Auth::user()->partner_id) - ->sum('actual_clients'); - }); - $pec_client_sum = cache()->remember('pec_client_sum', now()->addMinutes(5), function () { - return ClientRegistration::select('total_percentage') - ->where('partner_id', Auth::user()->partner_id) - ->sum('total_percentage'); - }); + // $all_clients_number = cache()->remember('all_clients_number', now()->addMinutes(5), function () { + // return ClientPerformance::whereNotNull('actual_clients') + // ->where('partner_id', Auth::user()->partner_id) + // ->sum('actual_clients'); + // }); + // $pec_client_sum = cache()->remember('pec_client_sum', now()->addMinutes(5), function () { + // return ClientRegistration::select('total_percentage') + // ->where('partner_id', Auth::user()->partner_id) + // ->sum('total_percentage'); + // }); } diff --git a/app/Http/Controllers/ReportController.php b/app/Http/Controllers/ReportController.php index f36e4a1..4bfd4f3 100644 --- a/app/Http/Controllers/ReportController.php +++ b/app/Http/Controllers/ReportController.php @@ -40,8 +40,8 @@ public function deactivated_clients() if (Auth::user()->access_level == 'Partner') { $all_partners = Partner::where('status', '=', 'Active') - ->where('id', Auth::user()->partner_id) - ->pluck('name', 'id'); + ->where('id', Auth::user()->partner_id) + ->pluck('name', 'id'); $all_deactivated_clients = Client::join('tbl_groups', 'tbl_groups.id', 'tbl_client.group_id') ->select('tbl_client.clinic_number', 'tbl_client.file_no', DB::raw("CONCAT(`tbl_client`.`f_name`, ' ', `tbl_client`.`m_name`, ' ', `tbl_client`.`l_name`) as full_name"), 'tbl_client.phone_no', 'tbl_client.dob', 'tbl_client.client_type', 'tbl_groups.name', 'tbl_client.created_at') ->where('tbl_client.status', '=', 'Disabled') @@ -55,13 +55,13 @@ public function deactivated_clients() public function transfer_out() { $all_partners = Partner::where('status', '=', 'Active') - ->pluck('name', 'id'); + ->pluck('name', 'id'); if (Auth::user()->access_level == 'Admin' || Auth::user()->access_level == 'Donor') { $all_transfer_clients = Client::join('tbl_groups', 'tbl_groups.id', 'tbl_client.group_id') ->join('tbl_master_facility', 'tbl_master_facility.code', '=', 'tbl_client.mfl_code') ->select('tbl_client.clinic_number', 'tbl_client.file_no', DB::raw("CONCAT(`tbl_client`.`f_name`, ' ', `tbl_client`.`m_name`, ' ', `tbl_client`.`l_name`) as full_name"), DB::raw("CONCAT(`tbl_client`.`prev_clinic`, ' ', `tbl_master_facility`.`name`) as clinic_previous"), 'tbl_client.phone_no', 'tbl_client.dob', 'tbl_client.client_status', 'tbl_groups.name', 'tbl_client.created_at') - // ->where('tbl_client.prev_clinic', '=', 'tbl_master_facility.code') + // ->where('tbl_client.prev_clinic', '=', 'tbl_master_facility.code') ->where('tbl_client.status', '=', 'Transfer Out') ->get(); @@ -76,7 +76,7 @@ public function transfer_out() $all_transfer_clients = Client::join('tbl_groups', 'tbl_groups.id', 'tbl_client.group_id') ->join('tbl_master_facility', 'tbl_master_facility.code', '=', 'tbl_client.mfl_code') ->select('tbl_client.clinic_number', 'tbl_client.file_no', DB::raw("CONCAT(`tbl_client`.`f_name`, ' ', `tbl_client`.`m_name`, ' ', `tbl_client`.`l_name`) as full_name"), DB::raw("CONCAT(`tbl_client`.`prev_clinic`, ' ', `tbl_master_facility`.`name`) as clinic_previous"), 'tbl_client.phone_no', 'tbl_client.dob', 'tbl_client.client_status', 'tbl_groups.name', 'tbl_client.created_at') - ->where('tbl_client.status', '=', 'Transfer Out') + ->where('tbl_client.status', '=', 'Transfer Out') ->where('tbl_client.prev_clinic', Auth::user()->facility_id) ->get(); @@ -90,8 +90,8 @@ public function transfer_out() if (Auth::user()->access_level == 'Partner') { $all_partners = Partner::where('status', '=', 'Active') - ->where('id', Auth::user()->partner_id) - ->pluck('name', 'id'); + ->where('id', Auth::user()->partner_id) + ->pluck('name', 'id'); $all_transfer_clients = Client::join('tbl_groups', 'tbl_groups.id', 'tbl_client.group_id') ->join('tbl_master_facility', 'tbl_master_facility.code', '=', 'tbl_client.mfl_code') ->select('tbl_client.clinic_number', 'tbl_client.file_no', DB::raw("CONCAT(`tbl_client`.`f_name`, ' ', `tbl_client`.`m_name`, ' ', `tbl_client`.`l_name`) as full_name"), DB::raw("CONCAT(`tbl_client`.`prev_clinic`, ' ', `tbl_master_facility`.`name`) as clinic_previous"), 'tbl_client.phone_no', 'tbl_client.dob', 'tbl_client.client_status', 'tbl_groups.name', 'tbl_client.created_at') @@ -129,11 +129,11 @@ public function today_appointments() return view('reports.today_appointment', compact('all_today_appointments', 'all_partners')); } - + public function consented_report() { $all_partners = Partner::where('status', '=', 'Active') - ->pluck('name', 'id'); + ->pluck('name', 'id'); if (Auth::user()->access_level == 'Admin' || Auth::user()->access_level == 'Donor') { $consented_clients = Client::join('tbl_groups', 'tbl_groups.id', 'tbl_client.group_id') @@ -152,7 +152,7 @@ public function consented_report() if (Auth::user()->access_level == 'Partner') { $all_partners = Partner::where('status', '=', 'Active') - ->pluck('name', 'id'); + ->pluck('name', 'id'); $consented_clients = Client::join('tbl_groups', 'tbl_groups.id', 'tbl_client.group_id') ->select('tbl_client.clinic_number', 'tbl_client.file_no', 'tbl_client.f_name', 'tbl_client.m_name', 'tbl_client.l_name', 'tbl_client.phone_no', 'tbl_client.dob', 'tbl_client.client_status', 'tbl_groups.name', 'tbl_client.created_at', 'tbl_client.smsenable', 'tbl_client.enrollment_date', 'tbl_client.art_date', 'tbl_client.updated_at', 'tbl_client.status', 'tbl_client.consent_date') ->where('tbl_client.smsenable', '=', 'Yes') @@ -166,7 +166,7 @@ public function consented_report() public function tracing_outcome() { $all_partners = Partner::where('status', '=', 'Active') - ->pluck('name', 'id'); + ->pluck('name', 'id'); if (Auth::user()->access_level == 'Admin' || Auth::user()->access_level == 'Donor') { $outcome_report = OutcomeReport::select( @@ -237,7 +237,7 @@ public function messages_extract_report() { if (Auth::user()->access_level == 'Admin' || Auth::user()->access_level == 'Donor') { $all_partners = Partner::where('status', '=', 'Active') - ->pluck('name', 'id'); + ->pluck('name', 'id'); $message_extract = MessageExtract::select( 'clinic_number', @@ -258,6 +258,8 @@ public function messages_extract_report() ->get(); } if (Auth::user()->access_level == 'Facility') { + $all_partners = Partner::where('status', '=', 'Active') + ->pluck('name', 'id'); $message_extract = MessageExtract::select( 'clinic_number', 'gender', @@ -279,8 +281,8 @@ public function messages_extract_report() } if (Auth::user()->access_level == 'Partner') { $all_partners = Partner::where('status', '=', 'Active') - ->where('id', Auth::user()->partner_id) - ->pluck('name', 'id'); + ->where('id', Auth::user()->partner_id) + ->pluck('name', 'id'); $message_extract = MessageExtract::select( 'clinic_number', @@ -329,8 +331,8 @@ public function client_report() if (Auth::user()->access_level == 'Partner') { $all_partners = Partner::where('status', '=', 'Active') - ->where('id', Auth::user()->partner_id) - ->pluck('name', 'id'); + ->where('id', Auth::user()->partner_id) + ->pluck('name', 'id'); $client_summary = Summary::all() ->where('partner_id', Auth::user()->partner_id); } @@ -354,8 +356,8 @@ public function monthly_appointments() if (Auth::user()->access_level == 'Partner') { $all_partners = Partner::where('status', '=', 'Active') - ->where('id', Auth::user()->partner_id) - ->pluck('name', 'id'); + ->where('id', Auth::user()->partner_id) + ->pluck('name', 'id'); $monthly_app_summary = MonthlyApp::all() ->where('partner_id', Auth::user()->partner_id); } diff --git a/resources/views/sms/sms_report.blade.php b/resources/views/sms/sms_report.blade.php index aba93b2..e9edadf 100644 --- a/resources/views/sms/sms_report.blade.php +++ b/resources/views/sms/sms_report.blade.php @@ -15,7 +15,7 @@
- + {{ csrf_field() }}
@@ -74,15 +74,6 @@
-
-
-
- -

- -
-
-
@@ -105,6 +96,17 @@
+ +
+
+
+ +

+ +
+
+
+
From c1ac01ef7d530ac5df0f2d14a4fac6ae116fc1fa Mon Sep 17 00:00:00 2001 From: Ronald-pro <36841157+Ronald-pro@users.noreply.github.com> Date: Thu, 3 Mar 2022 08:33:13 +0300 Subject: [PATCH 018/171] Populated facility user table with partner id --- app/Http/Controllers/ReportController.php | 42 +++++++- app/Http/Controllers/UserController.php | 117 +++++++++++++++------- resources/views/users/adduser.blade.php | 2 +- resources/views/users/edituser.blade.php | 2 +- resources/views/users/users.blade.php | 4 +- 5 files changed, 126 insertions(+), 41 deletions(-) diff --git a/app/Http/Controllers/ReportController.php b/app/Http/Controllers/ReportController.php index 4bfd4f3..a421894 100644 --- a/app/Http/Controllers/ReportController.php +++ b/app/Http/Controllers/ReportController.php @@ -15,6 +15,7 @@ use App\Models\Partner; use DB; use Auth; +use Cache; class ReportController extends Controller { @@ -239,6 +240,44 @@ public function messages_extract_report() $all_partners = Partner::where('status', '=', 'Active') ->pluck('name', 'id'); + // $message_extract = Client::chunk(100, function ($message_extract) { + // foreach ($message_extract as $message_extracts) { + // $message_extract = Client::JOIN('tbl_groups', 'tbl_groups.id', 'tbl_client.group_id') + // ->JOIN('tbl_master_facility', `tbl_master_facility` . `code`, `tbl_partner_facility` . `mfl_code`) + // ->JOIN('tbl_gender', `tbl_gender` . `id`, `tbl_client` . `gender`) + // ->JOIN('tbl_partner_facility', `tbl_partner_facility` . `mfl_code`, `tbl_client` . `mfl_code`) + // ->JOIN('tbl_marital_status', `tbl_marital_status` . `id`, `tbl_client` . `marital`) + // ->JOIN('tbl_partner', `tbl_partner` . `id`, `tbl_partner_facility` . `partner_id`) + // // ->JOIN('tbl_time`, `tbl_time' . `id`, `tbl_client` . `txt_time`) + // ->JOIN('tbl_language', `tbl_language` . `id`, `tbl_client` . `language_id`) + // ->JOIN('tbl_clnt_outgoing', `tbl_clnt_outgoing` . `clnt_usr_id`, `tbl_client` . `id`) + // ->JOIN('tbl_message_types', `tbl_message_types` . `id`, `tbl_clnt_outgoing` . `message_type_id`) + // ->JOIN('tbl_county', `tbl_county` . `id`, `tbl_partner_facility` . `county_id`) + // ->JOIN('tbl_sub_county', `tbl_sub_county` . `id`, `tbl_partner_facility` . `sub_county_id`) + // ->select( + // 'tbl_client.clinic_number as clinic_number', + // 'tbl_client.mfl_code as mfl_code', + // 'tbl_master_facility.name as facility_name', + // 'tbl_gender.name as gender', + // 'tbl_groups.name as group_name', + // 'tbl_marital_status.marital as marital', + // 'tbl_partner_facility.partner_id as partner_id', + // 'tbl_partner.name as partner_name', + // 'tbl_client.created_at as created_at', + // DB::raw("date_format( `tbl_client`.`created_at`, '%M %Y' ) as month_year"), + // // '(date_format( `tbl_client`.`created_at`, '%M %Y' ) AS month_year)', + // 'tbl_language.name as language', + // 'tbl_message_types.name as message_type', + // 'tbl_clnt_outgoing.msg as msg', + // 'tbl_client.language_id as language_id', + // 'tbl_client.txt_time as preferred_time', + // 'tbl_county.name as county', + // 'tbl_sub_county.name as sub_county', + // 'tbl_sub_county.id as sub_county_id' + // )->get(); + // } + // }); + $message_extract = MessageExtract::select( 'clinic_number', 'gender', @@ -254,8 +293,7 @@ public function messages_extract_report() 'sub_county', 'mfl_code', 'facility_name' - ) - ->get(); + )->get(); } if (Auth::user()->access_level == 'Facility') { $all_partners = Partner::where('status', '=', 'Active') diff --git a/app/Http/Controllers/UserController.php b/app/Http/Controllers/UserController.php index d29284c..587b3c8 100644 --- a/app/Http/Controllers/UserController.php +++ b/app/Http/Controllers/UserController.php @@ -23,26 +23,75 @@ class UserController extends Controller // public function showUsers() { - if (Auth::user()->access_level == 'Partner'){ - $all_users = User::join('tbl_clinic', 'tbl_clinic.id', '=', 'tbl_users.clinic_id') - ->join('tbl_role', 'tbl_role.id', '=', 'tbl_users.role_id') - ->select(DB::raw("CONCAT(`tbl_users`.`f_name`, ' ', `tbl_users`.`m_name`, ' ', `tbl_users`.`l_name`) as user_name"), 'tbl_users.f_name', 'tbl_users.m_name', 'tbl_users.l_name', 'tbl_users.dob', 'tbl_users.phone_no', 'tbl_users.e_mail', 'tbl_users.access_level', 'tbl_users.status', - 'tbl_users.created_at', 'tbl_users.updated_at', 'tbl_clinic.name AS clinic_name', 'tbl_role.id AS role_id', 'tbl_users.view_client', 'tbl_users.rcv_app_list', 'tbl_users.daily_report', 'tbl_users.monthly_report', 'tbl_users.month3_report', 'tbl_users.month6_report', 'tbl_users.yearly_report', 'tbl_users.status', - 'tbl_users.id as id', 'tbl_users.facility_id', 'tbl_clinic.id as clinic_id') - ->where('tbl_users.status', '=', 'Active') - ->where('tbl_users.partner_id', Auth::user()->partner_id) - ->get(); - } - - if (Auth::user()->access_level == 'Admin'){ - $all_users = User::join('tbl_clinic', 'tbl_clinic.id', '=', 'tbl_users.clinic_id') - ->join('tbl_role', 'tbl_role.id', '=', 'tbl_users.role_id') - ->select(DB::raw("CONCAT(`tbl_users`.`f_name`, ' ', `tbl_users`.`m_name`, ' ', `tbl_users`.`l_name`) as user_name"), 'tbl_users.f_name', 'tbl_users.m_name', 'tbl_users.l_name', 'tbl_users.dob', 'tbl_users.phone_no', 'tbl_users.e_mail', 'tbl_users.access_level', 'tbl_users.status', - 'tbl_users.created_at', 'tbl_users.updated_at', 'tbl_clinic.name AS clinic_name', 'tbl_role.id AS role_id', 'tbl_users.view_client', 'tbl_users.rcv_app_list', 'tbl_users.daily_report', 'tbl_users.monthly_report', 'tbl_users.month3_report', 'tbl_users.month6_report', 'tbl_users.yearly_report', 'tbl_users.status', - 'tbl_users.id as id', 'tbl_users.facility_id', 'tbl_clinic.id as clinic_id', 'tbl_users.partner_id', 'tbl_users.county_id', 'tbl_users.donor_id') - ->where('tbl_users.status', '=', 'Active') - ->get(); - } + if (Auth::user()->access_level == 'Partner') { + $all_users = User::join('tbl_clinic', 'tbl_clinic.id', '=', 'tbl_users.clinic_id') + ->join('tbl_role', 'tbl_role.id', '=', 'tbl_users.role_id') + ->select( + DB::raw("CONCAT(`tbl_users`.`f_name`, ' ', `tbl_users`.`m_name`, ' ', `tbl_users`.`l_name`) as user_name"), + 'tbl_users.f_name', + 'tbl_users.m_name', + 'tbl_users.l_name', + 'tbl_users.dob', + 'tbl_users.phone_no', + 'tbl_users.e_mail', + 'tbl_users.access_level', + 'tbl_users.status', + 'tbl_users.created_at', + 'tbl_users.updated_at', + 'tbl_clinic.name AS clinic_name', + 'tbl_role.id AS role_id', + 'tbl_users.view_client', + 'tbl_users.rcv_app_list', + 'tbl_users.daily_report', + 'tbl_users.monthly_report', + 'tbl_users.month3_report', + 'tbl_users.month6_report', + 'tbl_users.yearly_report', + 'tbl_users.status', + 'tbl_users.id as id', + 'tbl_users.facility_id', + 'tbl_clinic.id as clinic_id' + ) + ->where('tbl_users.status', '=', 'Active') + ->where('tbl_users.partner_id', Auth::user()->partner_id) + ->get(); + } + + if (Auth::user()->access_level == 'Admin') { + $all_users = User::join('tbl_clinic', 'tbl_clinic.id', '=', 'tbl_users.clinic_id') + ->join('tbl_role', 'tbl_role.id', '=', 'tbl_users.role_id') + ->select( + DB::raw("CONCAT(`tbl_users`.`f_name`, ' ', `tbl_users`.`m_name`, ' ', `tbl_users`.`l_name`) as user_name"), + 'tbl_users.f_name', + 'tbl_users.m_name', + 'tbl_users.l_name', + 'tbl_users.dob', + 'tbl_users.phone_no', + 'tbl_users.e_mail', + 'tbl_users.access_level', + 'tbl_users.status', + 'tbl_users.created_at', + 'tbl_users.updated_at', + 'tbl_clinic.name AS clinic_name', + 'tbl_role.id AS role_id', + 'tbl_users.view_client', + 'tbl_users.rcv_app_list', + 'tbl_users.daily_report', + 'tbl_users.monthly_report', + 'tbl_users.month3_report', + 'tbl_users.month6_report', + 'tbl_users.yearly_report', + 'tbl_users.status', + 'tbl_users.id as id', + 'tbl_users.facility_id', + 'tbl_clinic.id as clinic_id', + 'tbl_users.partner_id', + 'tbl_users.county_id', + 'tbl_users.donor_id' + ) + ->where('tbl_users.status', '=', 'Active') + ->get(); + } $access_level = AccessLevel::all()->where('status', '=', 'Active'); $partners = Partner::all(); $donors = Donor::all(); @@ -52,12 +101,12 @@ public function showUsers() ->get(); $counties = County::all(); $clinics = Clinic::all(); - if (Auth::user()->access_level == 'Partner'){ + if (Auth::user()->access_level == 'Partner') { $roles = Role::all()->where('status', '=', 'Active') - ->where('access_level', '=', 'Facility'); + ->where('access_level', '=', 'Facility'); } - if (Auth::user()->access_level == 'Admin'){ - $roles = Role::all()->where('status', '=', 'Active'); + if (Auth::user()->access_level == 'Admin') { + $roles = Role::all()->where('status', '=', 'Active'); } $sub_counties = SubCounty::all(); @@ -73,22 +122,22 @@ public function adduserform(Request $request) ->orderBy('tbl_master_facility.name', 'asc') // ->where('tbl_partner_facility.mfl_code', '=', 'tbl_master_facility.code') ->get(); - if (Auth::user()->access_level == 'Partner'){ - $facilities = PartnerFacility::join('tbl_master_facility', 'tbl_partner_facility.mfl_code', '=', 'tbl_master_facility.code') + if (Auth::user()->access_level == 'Partner') { + $facilities = PartnerFacility::join('tbl_master_facility', 'tbl_partner_facility.mfl_code', '=', 'tbl_master_facility.code') ->select('tbl_partner_facility.id', 'tbl_master_facility.name', 'tbl_partner_facility.mfl_code as code') ->orderBy('tbl_master_facility.name', 'asc') - ->where('tbl_partner_facility.partner_id', '=', Auth::user()->partner_id) + ->where('tbl_partner_facility.partner_id', '=', Auth::user()->partner_id) ->get(); - } + } $counties = County::all(); $clinics = Clinic::all(); $roles = Role::all()->where('status', '=', 'Active'); $sub_counties = SubCounty::all(); $access_level = AccessLevel::all()->where('status', '=', 'Active'); - if (Auth::user()->access_level == 'Partner'){ + if (Auth::user()->access_level == 'Partner') { $access_level = AccessLevel::all()->where('status', '=', 'Active') - // ->where('name', '=', 'Partner') - ->where('name', '=', 'Facility'); + // ->where('name', '=', 'Partner') + ->where('name', '=', 'Facility'); } $clients = Client::select('tbl_client.clinic_number', 'tbl_clinic.name') @@ -209,7 +258,7 @@ public function adduser(Request $request) $user->role_id = $request->rolename; $user->facility_id = $request->facilityname; $user->clinic_id = $request->clinicname; - $user->partner_id = Auth::user()->partner_id; + $user->partner_id = $request->partner; } $user->view_client = $request->bio_data; $user->rcv_app_list = $request->app_receive; @@ -267,7 +316,7 @@ public function edituser(Request $request) 'month3_report' => $request->month3_report, 'month6_report' => $request->month6_report, 'yearly_report' => $request->yearly_report, - 'created_by' => Auth::user()->id, + 'created_by' => Auth::user()->id, ]); if ($user) { Session::flash('statuscode', 'success'); @@ -293,7 +342,6 @@ public function resetuser(Request $request) if ($user->save()) { Session::flash('statuscode', 'success'); return redirect('admin/users')->with('status', 'User has been reset successfull'); - } else { Session::flash('statuscode', 'error'); return redirect('admin/users')->with('status', 'An error has occurred please try again later'); @@ -334,5 +382,4 @@ public function changepass(Request $request) return back(); } } - } diff --git a/resources/views/users/adduser.blade.php b/resources/views/users/adduser.blade.php index cf0f045..f45aa82 100644 --- a/resources/views/users/adduser.blade.php +++ b/resources/views/users/adduser.blade.php @@ -364,7 +364,7 @@ $('#add_facility_div').show(); $('#add_county_div').hide(); $('#add_subcounty_div').hide(); - $('#add_partner_div').hide(); + $('#add_partner_div').show(); $('#add_clinic_div').show(); $('#add_bio_div').show(); diff --git a/resources/views/users/edituser.blade.php b/resources/views/users/edituser.blade.php index 9ca8c9b..e0ebf8a 100644 --- a/resources/views/users/edituser.blade.php +++ b/resources/views/users/edituser.blade.php @@ -363,7 +363,7 @@ $('#add_facility_div').show(); $('#add_county_div').hide(); $('#add_subcounty_div').hide(); - $('#add_partner_div').hide(); + $('#add_partner_div').show(); $('#add_clinic_div').show(); $('#add_bio_div').show(); diff --git a/resources/views/users/users.blade.php b/resources/views/users/users.blade.php index 2c81c5b..3f5c34f 100644 --- a/resources/views/users/users.blade.php +++ b/resources/views/users/users.blade.php @@ -461,7 +461,7 @@ function edituser(user) { $('#add_facility_div').show(); $('#add_county_div').hide(); $('#add_subcounty_div').hide(); - $('#add_partner_div').hide(); + $('#add_partner_div').show(); $('#add_clinic_div').show(); $('#add_bio_div').show(); @@ -758,7 +758,7 @@ function resetUser(id) { $('#add_facility_div').show(); $('#add_county_div').hide(); $('#add_subcounty_div').hide(); - $('#add_partner_div').hide(); + $('#add_partner_div').show(); $('#add_clinic_div').show(); $('#add_bio_div').show(); From b1c8504cd8eedc999de68494c93e3ee1cc58397c Mon Sep 17 00:00:00 2001 From: Ronald-pro <36841157+Ronald-pro@users.noreply.github.com> Date: Fri, 18 Mar 2022 10:35:51 +0300 Subject: [PATCH 019/171] all active clients count and distribution by gender --- app/Http/Controllers/BulkUploadController.php | 75 +++++++++---------- .../Controllers/NewDashboardController.php | 70 +++++++++++++++++ 2 files changed, 105 insertions(+), 40 deletions(-) create mode 100644 app/Http/Controllers/NewDashboardController.php diff --git a/app/Http/Controllers/BulkUploadController.php b/app/Http/Controllers/BulkUploadController.php index 5a882a8..7e3b139 100644 --- a/app/Http/Controllers/BulkUploadController.php +++ b/app/Http/Controllers/BulkUploadController.php @@ -4,6 +4,7 @@ ini_set('max_execution_time', 0); ini_set('memory_limit', '1024M'); + use Illuminate\Http\Request; use Maatwebsite\Excel\Concerns\ToModel; use Maatwebsite\Excel\Concerns\WithHeadingRow; @@ -14,12 +15,14 @@ class BulkUploadController extends Controller { - public function uploadClientForm(){ + public function uploadClientForm() + { return view('clients.upload-clients-form'); } - public function importClients(Request $request){ + public function importClients(Request $request) + { $file = request()->file('file'); @@ -28,31 +31,29 @@ public function importClients(Request $request){ for ($i = 0; $i < count($receivedArr); $i++) { $gender_value = trim(strtolower($receivedArr[$i]['Gender'])); - if($gender_value == 'm'){ + if ($gender_value == 'm') { $gender = 2; - } - elseif ($gender_value=='f') { - $gender =1; - }else { - $gender= 5; + } elseif ($gender_value == 'f') { + $gender = 1; + } else { + $gender = 5; } $marital_value = trim(strtolower($receivedArr[$i]['MaritalStatus'])); - if($marital_value == 'divorced'){ + if ($marital_value == 'divorced') { $marital = 3; - }elseif ($marital_value == 'living with partner') { + } elseif ($marital_value == 'living with partner') { $marital = 5; - }elseif ($marital_value == 'married') { + } elseif ($marital_value == 'married') { $marital = 2; - }elseif ($marital_value == 'never married') { + } elseif ($marital_value == 'never married') { $marital = 1; - } - elseif ($marital_value == 'polygamous') { + } elseif ($marital_value == 'polygamous') { $marital = 8; - }elseif ($marital_value == 'widowed') { + } elseif ($marital_value == 'widowed') { $marital = 4; - }else{ + } else { $marital = 6; } @@ -70,11 +71,11 @@ public function importClients(Request $request){ $age_value = (float)$receivedArr[$i]['ageInYears']; - if($age_value >=20){ + if ($age_value >= 20) { $group_id = 1; - }elseif ($age_value >=13) { + } elseif ($age_value >= 13) { $group_id = 2; - }else{ + } else { $group_id = 4; } @@ -132,27 +133,25 @@ public function importClients(Request $request){ // return $res; // } - if($existing){ + if ($existing) { echo ('Client' . $clinic_number . ' already exists in the system
'); - - }elseif(strlen($clinic_number) < 10 || strlen($clinic_number) > 10){ + } elseif (strlen($clinic_number) < 10 || strlen($clinic_number) > 10) { echo ('Client' . $clinic_number . ' has less or more than 10 digit ccc number
'); - }else{ + } else { if ($client->save()) { - echo ('Insert Client Record successfully for client.' . $clinic_number. '
'); - }else{ - echo ('Could not insert record for client.' . $clinic_number. '
'); + echo ('Insert Client Record successfully for client.' . $clinic_number . '
'); + } else { + echo ('Could not insert record for client.' . $clinic_number . '
'); } } - - } } echo "Done"; } - public function importSecondClients(Request $request){ + public function importSecondClients(Request $request) + { $file = request()->file('file'); @@ -229,21 +228,18 @@ public function importSecondClients(Request $request){ // return $res; // } - if($existing){ + if ($existing) { echo ('Client' . $clinic_number . ' already exists in the system
'); - - }elseif(strlen($clinic_number) < 10 || strlen($clinic_number) > 10){ + } elseif (strlen($clinic_number) < 10 || strlen($clinic_number) > 10) { echo ('Client' . $clinic_number . ' has less or more than 10 digit ccc number
'); - }else{ + } else { if ($client->save()) { - echo ('Insert Client Record successfully for client.' . $clinic_number. '
'); - }else{ - echo ('Could not insert record for client.' . $clinic_number. '
'); + echo ('Insert Client Record successfully for client.' . $clinic_number . '
'); + } else { + echo ('Could not insert record for client.' . $clinic_number . '
'); } } - - } } echo "Done"; @@ -260,7 +256,7 @@ function csvToArray($filename = '', $delimiter = ',') $data = array(); if (($handle = fopen($filename, 'r')) !== false) { - while (($row = fgetcsv($handle, 5000, $delimiter)) !== false) { + while (($row = fgetcsv($handle, 10000, $delimiter)) !== false) { if (!$header) { // print_r("header not empty"); $header = $row; @@ -274,5 +270,4 @@ function csvToArray($filename = '', $delimiter = ',') return $data; } - } diff --git a/app/Http/Controllers/NewDashboardController.php b/app/Http/Controllers/NewDashboardController.php new file mode 100644 index 0000000..51477a3 --- /dev/null +++ b/app/Http/Controllers/NewDashboardController.php @@ -0,0 +1,70 @@ +access_level == 'Facility'){ + $client = Client::where('status', '=', 'Active') + ->where('mfl_code', Auth::user()->facility_id) + ->count(); + } + if (Auth::user()->access_level == 'Partner'){ + $client = Client::join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->where('tbl_client.status', '=', 'Active') + ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) + ->count(); + } + if (Auth::user()->access_level == 'Admin' || Auth::user()->access_level == 'Donor'){ + $client = Client::where('status', '=', 'Active') + ->count(); + } + + } + + public function client_charts(){ + + // active clients by gender + if (Auth::user()->access_level == 'Admin' || Auth::user()->access_level == 'Donor'){ + $clients_male = Client::where('gender', '=', '2') + ->count() + + $clients_female = Client::where('gender', '=', '1') + ->count() + + } + if (Auth::user()->access_level == 'Facility'){ + $clients_male = Client::where('gender', '=', '2') + ->where('mfl_code', Auth::user()->facility_id) + ->count() + + $clients_female = Client::where('gender', '=', '1') + ->where('mfl_code', Auth::user()->facility_id) + ->count() + } + if (Auth::user()->access_level == 'Partner'){ + $clients_male = Client::join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->where('tbl_client.gender', '=', '2') + ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) + ->count() + + $clients_female = Client::join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->where('tbl_client.gender', '=', '1') + ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) + ->count() + } + + } +} From daa1162bda2df03fb42da8b15bc3c89df602ec48 Mon Sep 17 00:00:00 2001 From: Ronald-pro <36841157+Ronald-pro@users.noreply.github.com> Date: Fri, 18 Mar 2022 12:34:46 +0300 Subject: [PATCH 020/171] consented and nonconsented clients count and distribution by gender&age --- .../Controllers/NewDashboardController.php | 352 ++++++++++++++++-- 1 file changed, 317 insertions(+), 35 deletions(-) diff --git a/app/Http/Controllers/NewDashboardController.php b/app/Http/Controllers/NewDashboardController.php index 51477a3..fffa4e4 100644 --- a/app/Http/Controllers/NewDashboardController.php +++ b/app/Http/Controllers/NewDashboardController.php @@ -13,58 +13,340 @@ class NewDashboardController extends Controller { - public function dashboard(){ - - // showing all the active clients - if (Auth::user()->access_level == 'Facility'){ - $client = Client::where('status', '=', 'Active') - ->where('mfl_code', Auth::user()->facility_id) - ->count(); - } - if (Auth::user()->access_level == 'Partner'){ - $client = Client::join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') - ->where('tbl_client.status', '=', 'Active') - ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) - ->count(); - } - if (Auth::user()->access_level == 'Admin' || Auth::user()->access_level == 'Donor'){ - $client = Client::where('status', '=', 'Active') - ->count(); - } + public function dashboard() + { + // showing all the active clients + if (Auth::user()->access_level == 'Facility') { + $client = Client::where('status', '=', 'Active') + ->where('mfl_code', Auth::user()->facility_id) + ->count(); + } + if (Auth::user()->access_level == 'Partner') { + $client = Client::join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->where('tbl_client.status', '=', 'Active') + ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) + ->count(); + } + if (Auth::user()->access_level == 'Admin' || Auth::user()->access_level == 'Donor') { + $client = Client::where('status', '=', 'Active') + ->count(); + } + + // showing all consented clients + if (Auth::user()->access_level == 'Admin' || Auth::user()->access_level == 'Donor') { + $client_consented = Client::where('smsenable', '=', 'Yes') + ->count(); + } + if (Auth::user()->access_level == 'Facility') { + $client_consented = Client::where('smsenable', '=', 'Yes') + ->where('mfl_code', Auth::user()->facility_id) + ->count(); + } + if (Auth::user()->access_level == 'Partner') { + $client_consented = Client::join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->where('tbl_client.smsenable', '=', 'Yes') + ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) + ->count(); + } + + // showing all non consented clients + if (Auth::user()->access_level == 'Admin' || Auth::user()->access_level == 'Donor') { + $client_nonconsented = Client::where('smsenable', '!=', 'Yes') + ->count(); + } + if (Auth::user()->access_level == 'Facility') { + $client_nonconsented = Client::where('smsenable', '!=', 'Yes') + ->where('mfl_code', Auth::user()->facility_id) + ->count(); + } + if (Auth::user()->access_level == 'Partner') { + $client_nonconsented = Client::join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->where('tbl_client.smsenable', '!=', 'Yes') + ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) + ->count(); + } } - public function client_charts(){ + public function client_charts() + { // active clients by gender - if (Auth::user()->access_level == 'Admin' || Auth::user()->access_level == 'Donor'){ + if (Auth::user()->access_level == 'Admin' || Auth::user()->access_level == 'Donor') { $clients_male = Client::where('gender', '=', '2') - ->count() + ->where('status', '=', 'Active') + ->count(); $clients_female = Client::where('gender', '=', '1') - ->count() - + ->where('status', '=', 'Active') + ->count(); } - if (Auth::user()->access_level == 'Facility'){ + if (Auth::user()->access_level == 'Facility') { $clients_male = Client::where('gender', '=', '2') - ->where('mfl_code', Auth::user()->facility_id) - ->count() + ->where('status', '=', 'Active') + ->where('mfl_code', Auth::user()->facility_id) + ->count(); $clients_female = Client::where('gender', '=', '1') - ->where('mfl_code', Auth::user()->facility_id) - ->count() + ->where('status', '=', 'Active') + ->where('mfl_code', Auth::user()->facility_id) + ->count(); } - if (Auth::user()->access_level == 'Partner'){ + if (Auth::user()->access_level == 'Partner') { $clients_male = Client::join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') - ->where('tbl_client.gender', '=', '2') - ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) - ->count() + ->where('tbl_client.gender', '=', '2') + ->where('tbl_client.status', '=', 'Active') + ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) + ->count(); $clients_female = Client::join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') - ->where('tbl_client.gender', '=', '1') - ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) - ->count() + ->where('tbl_client.gender', '=', '1') + ->where('tbl_client.status', '=', 'Active') + ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) + ->count(); + } + + // active clients by age distribution + + if (Auth::user()->access_level == 'Admin' || Auth::user()->access_level == 'Donor') { + $client_to_nine = Client::select(\DB::raw("case when (((year(curdate()) - year(`dob`)) > 0) and ((year(curdate()) - year(`dob`)) <= 9)) then `dob` end")) + ->where('status', '=', 'Active') + ->count(); + + $client_to_nineteen = Client::select(\DB::raw("case when (((year(curdate()) - year(`dob`)) >= 10) and ((year(curdate()) - year(`dob`)) <= 19)) then `dob` end")) + ->where('status', '=', 'Active') + ->count(); + + $client_to_twentyfour = Client::select(\DB::raw("case when (((year(curdate()) - year(`dob`)) >= 20) and ((year(curdate()) - year(`dob`)) <= 24)) then `dob` end")) + ->where('status', '=', 'Active') + ->count(); + + $client_to_twentyfive_above = Client::select(\DB::raw("case when (((year(curdate()) - year(`dob`)) >= 25) then `dob` end")) + ->where('status', '=', 'Active') + ->count(); + } + if (Auth::user()->access_level == 'Facility') { + $client_to_nine = Client::select(\DB::raw("case when (((year(curdate()) - year(`dob`)) > 0) and ((year(curdate()) - year(`dob`)) <= 9)) then `dob` end")) + ->where('status', '=', 'Active') + ->where('mfl_code', Auth::user()->facility_id) + ->count(); + + $client_to_nineteen = Client::select(\DB::raw("case when (((year(curdate()) - year(`dob`)) >= 10) and ((year(curdate()) - year(`dob`)) <= 19)) then `dob` end")) + ->where('status', '=', 'Active') + ->where('mfl_code', Auth::user()->facility_id) + ->count(); + + $client_to_twentyfour = Client::select(\DB::raw("case when (((year(curdate()) - year(`dob`)) >= 20) and ((year(curdate()) - year(`dob`)) <= 24)) then `dob` end")) + ->where('status', '=', 'Active') + ->where('mfl_code', Auth::user()->facility_id) + ->count(); + + $client_to_twentyfive_above = Client::select(\DB::raw("case when (((year(curdate()) - year(`dob`)) >= 25) then `dob` end")) + ->where('status', '=', 'Active') + ->where('mfl_code', Auth::user()->facility_id) + ->count(); + } + if (Auth::user()->access_level == 'Partner') { + $client_to_nine = Client::join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select(\DB::raw("case when (((year(curdate()) - year(`tbl_client`.`dob`)) > 0) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 9)) then `tbl_client`.`dob` end")) + ->where('tbl_client.status', '=', 'Active') + ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) + ->count(); + + $client_to_nineteen = Client::join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select(\DB::raw("case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 10) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 19)) then `tbl_client`.`dob` end")) + ->where('tbl_client.status', '=', 'Active') + ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) + ->count(); + + $client_to_twentyfour = Client::join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select(\DB::raw("case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 20) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 24)) then `tbl_client`.`dob` end")) + ->where('tbl_client.status', '=', 'Active') + ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) + ->count(); + + $client_to_twentyfive_above = Client::join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select(\DB::raw("case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 25) then `tbl_client`.`dob` end")) + ->where('tbl_client.status', '=', 'Active') + ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) + ->count(); } + // consented clients by gender + + if (Auth::user()->access_level == 'Admin' || Auth::user()->access_level == 'Donor') { + $client_consented_male = Client::where('smsenable', '=', 'Yes') + ->where('gender', '=', '2') + ->count(); + $client_consented_female = Client::where('smsenable', '=', 'Yes') + ->where('gender', '=', '1') + ->count(); + } + if (Auth::user()->access_level == 'Facility') { + $client_consented_male = Client::where('smsenable', '=', 'Yes') + ->where('gender', '=', '2') + ->where('mfl_code', Auth::user()->facility_id) + ->count(); + $client_consented_female = Client::where('smsenable', '=', 'Yes') + ->where('gender', '=', '1') + ->where('mfl_code', Auth::user()->facility_id) + ->count(); + } + if (Auth::user()->access_level == 'Partner') { + $client_consented_male = Client::join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->where('tbl_client.smsenable', '=', 'Yes') + ->where('gender', '=', '2') + ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) + ->count(); + $client_consented_female = Client::join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->where('tbl_client.smsenable', '=', 'Yes') + ->where('gender', '=', '1') + ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) + ->count(); + } + // non consented clients by gender + + if (Auth::user()->access_level == 'Admin' || Auth::user()->access_level == 'Donor') { + $client_nonconsented_male = Client::where('smsenable', '!=', 'Yes') + ->where('gender', '=', '2') + ->count(); + $client_nonconsented_female = Client::where('smsenable', '!=', 'Yes') + ->where('gender', '=', '1') + ->count(); + } + if (Auth::user()->access_level == 'Facility') { + $client_nonconsented_male = Client::where('smsenable', '!=', 'Yes') + ->where('gender', '=', '2') + ->where('mfl_code', Auth::user()->facility_id) + ->count(); + $client_nonconsented_female = Client::where('smsenable', '!=', 'Yes') + ->where('gender', '=', '1') + ->where('mfl_code', Auth::user()->facility_id) + ->count(); + } + if (Auth::user()->access_level == 'Partner') { + $client_nonconsented_male = Client::join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->where('tbl_client.smsenable', '!=', 'Yes') + ->where('gender', '=', '2') + ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) + ->count(); + $client_nonconsented_female = Client::join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->where('tbl_client.smsenable', '!=', 'Yes') + ->where('gender', '=', '1') + ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) + ->count(); + } + + // consented clients by age distribution + if (Auth::user()->access_level == 'Admin' || Auth::user()->access_level == 'Donor') { + $client_consented_to_nine = Client::select(\DB::raw("case when (((year(curdate()) - year(`dob`)) > 0) and ((year(curdate()) - year(`dob`)) <= 9)) then `dob` end")) + ->where('smsenable', '=', 'Yes') + ->count(); + $client_consented_to_nineteen = Client::select(\DB::raw("case when (((year(curdate()) - year(`dob`)) >= 10) and ((year(curdate()) - year(`dob`)) <= 19)) then `dob` end")) + ->where('smsenable', '=', 'Yes') + ->count(); + $client_consented_to_twentyfour = Client::select(\DB::raw("case when (((year(curdate()) - year(`dob`)) >= 20) and ((year(curdate()) - year(`dob`)) <= 24)) then `dob` end")) + ->where('smsenable', '=', 'Yes') + ->count(); + $client_consented_to_twentyfive_above = Client::select(\DB::raw("case when ((year(curdate()) - year(`dob`)) >= 25) then `dob` end")) + ->where('smsenable', '=', 'Yes') + ->count(); + } + if (Auth::user()->access_level == 'Facility') { + $client_consented_to_nine = Client::select(\DB::raw("case when (((year(curdate()) - year(`dob`)) > 0) and ((year(curdate()) - year(`dob`)) <= 9)) then `dob` end")) + ->where('smsenable', '=', 'Yes') + ->where('mfl_code', Auth::user()->facility_id) + ->count(); + $client_consented_to_nineteen = Client::select(\DB::raw("case when (((year(curdate()) - year(`dob`)) >= 10) and ((year(curdate()) - year(`dob`)) <= 19)) then `dob` end")) + ->where('smsenable', '=', 'Yes') + ->where('mfl_code', Auth::user()->facility_id) + ->count(); + $client_consented_to_twentyfour = Client::select(\DB::raw("case when (((year(curdate()) - year(`dob`)) >= 20) and ((year(curdate()) - year(`dob`)) <= 24)) then `dob` end")) + ->where('smsenable', '=', 'Yes') + ->where('mfl_code', Auth::user()->facility_id) + ->count(); + $client_consented_to_twentyfive_above = Client::select(\DB::raw("case when ((year(curdate()) - year(`dob`)) >= 25) then `dob` end")) + ->where('smsenable', '=', 'Yes') + ->where('mfl_code', Auth::user()->facility_id) + ->count(); + } + if (Auth::user()->access_level == 'Partner') { + $client_consented_to_nine = Client::join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select(\DB::raw("case when (((year(curdate()) - year(`tbl_client`.`dob`)) > 0) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 9)) then `tbl_client`.`dob` end")) + ->where('tbl_client.smsenable', '=', 'Yes') + ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) + ->count(); + $client_consented_to_nineteen = Client::join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select(\DB::raw("case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 10) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 19)) then `tbl_client`.`dob` end")) + ->where('tbl_client.smsenable', '=', 'Yes') + ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) + ->count(); + $client_consented_to_twentyfour = Client::join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select(\DB::raw("case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 20) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 24)) then `tbl_client`.`dob` end")) + ->where('tbl_client.smsenable', '=', 'Yes') + ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) + ->count(); + $client_consented_to_twentyfive_above = Client::join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select(\DB::raw("case when ((year(curdate()) - year(`tbl_client`.`dob`)) >= 25) then `tbl_client`.`dob` end")) + ->where('tbl_client.smsenable', '=', 'Yes') + ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) + ->count(); + } + + // non consented clients by age distribution + if (Auth::user()->access_level == 'Admin' || Auth::user()->access_level == 'Donor') { + $client_nonconsented_to_nine = Client::select(\DB::raw("case when (((year(curdate()) - year(`dob`)) > 0) and ((year(curdate()) - year(`dob`)) <= 9)) then `dob` end")) + ->where('smsenable', '!=', 'Yes') + ->count(); + $client_nonconsented_to_nineteen = Client::select(\DB::raw("case when (((year(curdate()) - year(`dob`)) >= 10) and ((year(curdate()) - year(`dob`)) <= 19)) then `dob` end")) + ->where('smsenable', '!=', 'Yes') + ->count(); + $client_nonconsented_to_twentyfour = Client::select(\DB::raw("case when (((year(curdate()) - year(`dob`)) >= 20) and ((year(curdate()) - year(`dob`)) <= 24)) then `dob` end")) + ->where('smsenable', '!=', 'Yes') + ->count(); + $client_nonconsented_to_twentyfive_above = Client::select(\DB::raw("case when ((year(curdate()) - year(`dob`)) >= 25) then `dob` end")) + ->where('smsenable', '!=', 'Yes') + ->count(); + } + if (Auth::user()->access_level == 'Facility') { + $client_nonconsented_to_nine = Client::select(\DB::raw("case when (((year(curdate()) - year(`dob`)) > 0) and ((year(curdate()) - year(`dob`)) <= 9)) then `dob` end")) + ->where('smsenable', '!=', 'Yes') + ->where('mfl_code', Auth::user()->facility_id) + ->count(); + $client_nonconsented_to_nineteen = Client::select(\DB::raw("case when (((year(curdate()) - year(`dob`)) >= 10) and ((year(curdate()) - year(`dob`)) <= 19)) then `dob` end")) + ->where('smsenable', '!=', 'Yes') + ->where('mfl_code', Auth::user()->facility_id) + ->count(); + $client_nonconsented_to_twentyfour = Client::select(\DB::raw("case when (((year(curdate()) - year(`dob`)) >= 20) and ((year(curdate()) - year(`dob`)) <= 24)) then `dob` end")) + ->where('smsenable', '!=', 'Yes') + ->where('mfl_code', Auth::user()->facility_id) + ->count(); + $client_nonconsented_to_twentyfive_above = Client::select(\DB::raw("case when ((year(curdate()) - year(`dob`)) >= 25) then `dob` end")) + ->where('smsenable', '!=', 'Yes') + ->where('mfl_code', Auth::user()->facility_id) + ->count(); + } + if (Auth::user()->access_level == 'Partner') { + $client_nonconsented_to_nine = Client::join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select(\DB::raw("case when (((year(curdate()) - year(`tbl_client`.`dob`)) > 0) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 9)) then `tbl_client`.`dob` end")) + ->where('tbl_client.smsenable', '!=', 'Yes') + ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) + ->count(); + $client_nonconsented_to_nineteen = Client::join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select(\DB::raw("case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 10) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 19)) then `tbl_client`.`dob` end")) + ->where('tbl_client.smsenable', '!=', 'Yes') + ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) + ->count(); + $client_nonconsented_to_twentyfour = Client::join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select(\DB::raw("case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 20) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 24)) then `tbl_client`.`dob` end")) + ->where('tbl_client.smsenable', '!=', 'Yes') + ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) + ->count(); + $client_nonconsented_to_twentyfive_above = Client::join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select(\DB::raw("case when ((year(curdate()) - year(`tbl_client`.`dob`)) >= 25) then `tbl_client`.`dob` end")) + ->where('tbl_client.smsenable', '!=', 'Yes') + ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) + ->count(); + } } } From 58721d99d174047573ab7ce1faf1c21d89851d11 Mon Sep 17 00:00:00 2001 From: Ronald-pro <36841157+Ronald-pro@users.noreply.github.com> Date: Mon, 21 Mar 2022 15:01:26 +0300 Subject: [PATCH 021/171] added total appointment missed counts for each level --- .../Controllers/NewDashboardController.php | 32 ++++++++++++++++++- 1 file changed, 31 insertions(+), 1 deletion(-) diff --git a/app/Http/Controllers/NewDashboardController.php b/app/Http/Controllers/NewDashboardController.php index fffa4e4..20a3f1a 100644 --- a/app/Http/Controllers/NewDashboardController.php +++ b/app/Http/Controllers/NewDashboardController.php @@ -4,6 +4,7 @@ use Illuminate\Http\Request; use App\Models\Client; +use App\Models\Appointment; use App\Models\Facility; use App\Models\Gender; use App\Models\Partner; @@ -16,21 +17,50 @@ class NewDashboardController extends Controller public function dashboard() { - // showing all the active clients + // showing all the active clients, all appointments, missed appointments if (Auth::user()->access_level == 'Facility') { $client = Client::where('status', '=', 'Active') ->where('mfl_code', Auth::user()->facility_id) ->count(); + $appointment = Appointment::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->select('tbl_appointment.id') + ->where('tbl_client.mfl_code', Auth::user()->facility_id) + ->count(); + $missed_appointment = Appointment::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->select('tbl_appointment.id') + ->where('tbl_appointment.app_status', '!=', 'Booked') + ->orwhere('tbl_appointment.app_status', '!=', 'Notified') + ->where('tbl_client.mfl_code', Auth::user()->facility_id) + ->count(); } if (Auth::user()->access_level == 'Partner') { $client = Client::join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') ->where('tbl_client.status', '=', 'Active') ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) ->count(); + $appointment = Appointment::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select('tbl_appointment.id') + ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) + ->count(); + $missed_appointment = Appointment::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select('tbl_appointment.id') + ->where('tbl_appointment.app_status', '!=', 'Booked') + ->orwhere('tbl_appointment.app_status', '!=', 'Notified') + ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) + ->count(); } if (Auth::user()->access_level == 'Admin' || Auth::user()->access_level == 'Donor') { $client = Client::where('status', '=', 'Active') ->count(); + $appointment = Appointment::select('id') + ->count(); + $missed_appointment = Appointment::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->select('tbl_appointment.id') + ->where('tbl_appointment.app_status', '!=', 'Booked') + ->orwhere('tbl_appointment.app_status', '!=', 'Notified') + ->count(); } // showing all consented clients From 6318e2d85a97bc900a1d6f2ea43b22878bb3d9c0 Mon Sep 17 00:00:00 2001 From: Ronald-pro <36841157+Ronald-pro@users.noreply.github.com> Date: Wed, 23 Mar 2022 12:35:51 +0300 Subject: [PATCH 022/171] rearrange the code base --- .../Controllers/NewDashboardController.php | 270 ++++++++---------- .../facility_dashboard.blade.php | 0 2 files changed, 125 insertions(+), 145 deletions(-) create mode 100644 resources/views/new_dashboard/facility_dashboard.blade.php diff --git a/app/Http/Controllers/NewDashboardController.php b/app/Http/Controllers/NewDashboardController.php index 20a3f1a..7142006 100644 --- a/app/Http/Controllers/NewDashboardController.php +++ b/app/Http/Controllers/NewDashboardController.php @@ -101,8 +101,9 @@ public function dashboard() public function client_charts() { - // active clients by gender + if (Auth::user()->access_level == 'Admin' || Auth::user()->access_level == 'Donor') { + // active clients by gender $clients_male = Client::where('gender', '=', '2') ->where('status', '=', 'Active') ->count(); @@ -110,35 +111,8 @@ public function client_charts() $clients_female = Client::where('gender', '=', '1') ->where('status', '=', 'Active') ->count(); - } - if (Auth::user()->access_level == 'Facility') { - $clients_male = Client::where('gender', '=', '2') - ->where('status', '=', 'Active') - ->where('mfl_code', Auth::user()->facility_id) - ->count(); - $clients_female = Client::where('gender', '=', '1') - ->where('status', '=', 'Active') - ->where('mfl_code', Auth::user()->facility_id) - ->count(); - } - if (Auth::user()->access_level == 'Partner') { - $clients_male = Client::join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') - ->where('tbl_client.gender', '=', '2') - ->where('tbl_client.status', '=', 'Active') - ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) - ->count(); - - $clients_female = Client::join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') - ->where('tbl_client.gender', '=', '1') - ->where('tbl_client.status', '=', 'Active') - ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) - ->count(); - } - - // active clients by age distribution - - if (Auth::user()->access_level == 'Admin' || Auth::user()->access_level == 'Donor') { + // active clients by age distribution $client_to_nine = Client::select(\DB::raw("case when (((year(curdate()) - year(`dob`)) > 0) and ((year(curdate()) - year(`dob`)) <= 9)) then `dob` end")) ->where('status', '=', 'Active') ->count(); @@ -154,8 +128,60 @@ public function client_charts() $client_to_twentyfive_above = Client::select(\DB::raw("case when (((year(curdate()) - year(`dob`)) >= 25) then `dob` end")) ->where('status', '=', 'Active') ->count(); + // consented clients by gender + + $client_consented_male = Client::where('smsenable', '=', 'Yes') + ->where('gender', '=', '2') + ->count(); + $client_consented_female = Client::where('smsenable', '=', 'Yes') + ->where('gender', '=', '1') + ->count(); + // non consented clients by gender + $client_nonconsented_male = Client::where('smsenable', '!=', 'Yes') + ->where('gender', '=', '2') + ->count(); + $client_nonconsented_female = Client::where('smsenable', '!=', 'Yes') + ->where('gender', '=', '1') + ->count(); + // consented clients by age distribution + $client_consented_to_nine = Client::select(\DB::raw("case when (((year(curdate()) - year(`dob`)) > 0) and ((year(curdate()) - year(`dob`)) <= 9)) then `dob` end")) + ->where('smsenable', '=', 'Yes') + ->count(); + $client_consented_to_nineteen = Client::select(\DB::raw("case when (((year(curdate()) - year(`dob`)) >= 10) and ((year(curdate()) - year(`dob`)) <= 19)) then `dob` end")) + ->where('smsenable', '=', 'Yes') + ->count(); + $client_consented_to_twentyfour = Client::select(\DB::raw("case when (((year(curdate()) - year(`dob`)) >= 20) and ((year(curdate()) - year(`dob`)) <= 24)) then `dob` end")) + ->where('smsenable', '=', 'Yes') + ->count(); + $client_consented_to_twentyfive_above = Client::select(\DB::raw("case when ((year(curdate()) - year(`dob`)) >= 25) then `dob` end")) + ->where('smsenable', '=', 'Yes') + ->count(); + // non consented clients by age distribution + $client_nonconsented_to_nine = Client::select(\DB::raw("case when (((year(curdate()) - year(`dob`)) > 0) and ((year(curdate()) - year(`dob`)) <= 9)) then `dob` end")) + ->where('smsenable', '!=', 'Yes') + ->count(); + $client_nonconsented_to_nineteen = Client::select(\DB::raw("case when (((year(curdate()) - year(`dob`)) >= 10) and ((year(curdate()) - year(`dob`)) <= 19)) then `dob` end")) + ->where('smsenable', '!=', 'Yes') + ->count(); + $client_nonconsented_to_twentyfour = Client::select(\DB::raw("case when (((year(curdate()) - year(`dob`)) >= 20) and ((year(curdate()) - year(`dob`)) <= 24)) then `dob` end")) + ->where('smsenable', '!=', 'Yes') + ->count(); + $client_nonconsented_to_twentyfive_above = Client::select(\DB::raw("case when ((year(curdate()) - year(`dob`)) >= 25) then `dob` end")) + ->where('smsenable', '!=', 'Yes') + ->count(); } if (Auth::user()->access_level == 'Facility') { + $clients_male = Client::where('gender', '=', '2') + ->where('status', '=', 'Active') + ->where('mfl_code', Auth::user()->facility_id) + ->count(); + + $clients_female = Client::where('gender', '=', '1') + ->where('status', '=', 'Active') + ->where('mfl_code', Auth::user()->facility_id) + ->count(); + // active clients by age distribution + $client_to_nine = Client::select(\DB::raw("case when (((year(curdate()) - year(`dob`)) > 0) and ((year(curdate()) - year(`dob`)) <= 9)) then `dob` end")) ->where('status', '=', 'Active') ->where('mfl_code', Auth::user()->facility_id) @@ -175,8 +201,74 @@ public function client_charts() ->where('status', '=', 'Active') ->where('mfl_code', Auth::user()->facility_id) ->count(); + + // consented clients by gender + $client_consented_male = Client::where('smsenable', '=', 'Yes') + ->where('gender', '=', '2') + ->where('mfl_code', Auth::user()->facility_id) + ->count(); + $client_consented_female = Client::where('smsenable', '=', 'Yes') + ->where('gender', '=', '1') + ->where('mfl_code', Auth::user()->facility_id) + ->count(); + // non consented clients by gender + $client_nonconsented_male = Client::where('smsenable', '!=', 'Yes') + ->where('gender', '=', '2') + ->where('mfl_code', Auth::user()->facility_id) + ->count(); + $client_nonconsented_female = Client::where('smsenable', '!=', 'Yes') + ->where('gender', '=', '1') + ->where('mfl_code', Auth::user()->facility_id) + ->count(); + // consented clients by age distribution + $client_consented_to_nine = Client::select(\DB::raw("case when (((year(curdate()) - year(`dob`)) > 0) and ((year(curdate()) - year(`dob`)) <= 9)) then `dob` end")) + ->where('smsenable', '=', 'Yes') + ->where('mfl_code', Auth::user()->facility_id) + ->count(); + $client_consented_to_nineteen = Client::select(\DB::raw("case when (((year(curdate()) - year(`dob`)) >= 10) and ((year(curdate()) - year(`dob`)) <= 19)) then `dob` end")) + ->where('smsenable', '=', 'Yes') + ->where('mfl_code', Auth::user()->facility_id) + ->count(); + $client_consented_to_twentyfour = Client::select(\DB::raw("case when (((year(curdate()) - year(`dob`)) >= 20) and ((year(curdate()) - year(`dob`)) <= 24)) then `dob` end")) + ->where('smsenable', '=', 'Yes') + ->where('mfl_code', Auth::user()->facility_id) + ->count(); + $client_consented_to_twentyfive_above = Client::select(\DB::raw("case when ((year(curdate()) - year(`dob`)) >= 25) then `dob` end")) + ->where('smsenable', '=', 'Yes') + ->where('mfl_code', Auth::user()->facility_id) + ->count(); + // non consented clients by age distribution + $client_nonconsented_to_nine = Client::select(\DB::raw("case when (((year(curdate()) - year(`dob`)) > 0) and ((year(curdate()) - year(`dob`)) <= 9)) then `dob` end")) + ->where('smsenable', '!=', 'Yes') + ->where('mfl_code', Auth::user()->facility_id) + ->count(); + $client_nonconsented_to_nineteen = Client::select(\DB::raw("case when (((year(curdate()) - year(`dob`)) >= 10) and ((year(curdate()) - year(`dob`)) <= 19)) then `dob` end")) + ->where('smsenable', '!=', 'Yes') + ->where('mfl_code', Auth::user()->facility_id) + ->count(); + $client_nonconsented_to_twentyfour = Client::select(\DB::raw("case when (((year(curdate()) - year(`dob`)) >= 20) and ((year(curdate()) - year(`dob`)) <= 24)) then `dob` end")) + ->where('smsenable', '!=', 'Yes') + ->where('mfl_code', Auth::user()->facility_id) + ->count(); + $client_nonconsented_to_twentyfive_above = Client::select(\DB::raw("case when ((year(curdate()) - year(`dob`)) >= 25) then `dob` end")) + ->where('smsenable', '!=', 'Yes') + ->where('mfl_code', Auth::user()->facility_id) + ->count(); } if (Auth::user()->access_level == 'Partner') { + $clients_male = Client::join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->where('tbl_client.gender', '=', '2') + ->where('tbl_client.status', '=', 'Active') + ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) + ->count(); + + $clients_female = Client::join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->where('tbl_client.gender', '=', '1') + ->where('tbl_client.status', '=', 'Active') + ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) + ->count(); + // active clients by age distribution + $client_to_nine = Client::join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') ->select(\DB::raw("case when (((year(curdate()) - year(`tbl_client`.`dob`)) > 0) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 9)) then `tbl_client`.`dob` end")) ->where('tbl_client.status', '=', 'Active') @@ -200,29 +292,8 @@ public function client_charts() ->where('tbl_client.status', '=', 'Active') ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) ->count(); - } - - // consented clients by gender + // consented clients by gender - if (Auth::user()->access_level == 'Admin' || Auth::user()->access_level == 'Donor') { - $client_consented_male = Client::where('smsenable', '=', 'Yes') - ->where('gender', '=', '2') - ->count(); - $client_consented_female = Client::where('smsenable', '=', 'Yes') - ->where('gender', '=', '1') - ->count(); - } - if (Auth::user()->access_level == 'Facility') { - $client_consented_male = Client::where('smsenable', '=', 'Yes') - ->where('gender', '=', '2') - ->where('mfl_code', Auth::user()->facility_id) - ->count(); - $client_consented_female = Client::where('smsenable', '=', 'Yes') - ->where('gender', '=', '1') - ->where('mfl_code', Auth::user()->facility_id) - ->count(); - } - if (Auth::user()->access_level == 'Partner') { $client_consented_male = Client::join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') ->where('tbl_client.smsenable', '=', 'Yes') ->where('gender', '=', '2') @@ -233,28 +304,7 @@ public function client_charts() ->where('gender', '=', '1') ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) ->count(); - } - // non consented clients by gender - - if (Auth::user()->access_level == 'Admin' || Auth::user()->access_level == 'Donor') { - $client_nonconsented_male = Client::where('smsenable', '!=', 'Yes') - ->where('gender', '=', '2') - ->count(); - $client_nonconsented_female = Client::where('smsenable', '!=', 'Yes') - ->where('gender', '=', '1') - ->count(); - } - if (Auth::user()->access_level == 'Facility') { - $client_nonconsented_male = Client::where('smsenable', '!=', 'Yes') - ->where('gender', '=', '2') - ->where('mfl_code', Auth::user()->facility_id) - ->count(); - $client_nonconsented_female = Client::where('smsenable', '!=', 'Yes') - ->where('gender', '=', '1') - ->where('mfl_code', Auth::user()->facility_id) - ->count(); - } - if (Auth::user()->access_level == 'Partner') { + // non consented clients by gender $client_nonconsented_male = Client::join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') ->where('tbl_client.smsenable', '!=', 'Yes') ->where('gender', '=', '2') @@ -265,42 +315,7 @@ public function client_charts() ->where('gender', '=', '1') ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) ->count(); - } - - // consented clients by age distribution - if (Auth::user()->access_level == 'Admin' || Auth::user()->access_level == 'Donor') { - $client_consented_to_nine = Client::select(\DB::raw("case when (((year(curdate()) - year(`dob`)) > 0) and ((year(curdate()) - year(`dob`)) <= 9)) then `dob` end")) - ->where('smsenable', '=', 'Yes') - ->count(); - $client_consented_to_nineteen = Client::select(\DB::raw("case when (((year(curdate()) - year(`dob`)) >= 10) and ((year(curdate()) - year(`dob`)) <= 19)) then `dob` end")) - ->where('smsenable', '=', 'Yes') - ->count(); - $client_consented_to_twentyfour = Client::select(\DB::raw("case when (((year(curdate()) - year(`dob`)) >= 20) and ((year(curdate()) - year(`dob`)) <= 24)) then `dob` end")) - ->where('smsenable', '=', 'Yes') - ->count(); - $client_consented_to_twentyfive_above = Client::select(\DB::raw("case when ((year(curdate()) - year(`dob`)) >= 25) then `dob` end")) - ->where('smsenable', '=', 'Yes') - ->count(); - } - if (Auth::user()->access_level == 'Facility') { - $client_consented_to_nine = Client::select(\DB::raw("case when (((year(curdate()) - year(`dob`)) > 0) and ((year(curdate()) - year(`dob`)) <= 9)) then `dob` end")) - ->where('smsenable', '=', 'Yes') - ->where('mfl_code', Auth::user()->facility_id) - ->count(); - $client_consented_to_nineteen = Client::select(\DB::raw("case when (((year(curdate()) - year(`dob`)) >= 10) and ((year(curdate()) - year(`dob`)) <= 19)) then `dob` end")) - ->where('smsenable', '=', 'Yes') - ->where('mfl_code', Auth::user()->facility_id) - ->count(); - $client_consented_to_twentyfour = Client::select(\DB::raw("case when (((year(curdate()) - year(`dob`)) >= 20) and ((year(curdate()) - year(`dob`)) <= 24)) then `dob` end")) - ->where('smsenable', '=', 'Yes') - ->where('mfl_code', Auth::user()->facility_id) - ->count(); - $client_consented_to_twentyfive_above = Client::select(\DB::raw("case when ((year(curdate()) - year(`dob`)) >= 25) then `dob` end")) - ->where('smsenable', '=', 'Yes') - ->where('mfl_code', Auth::user()->facility_id) - ->count(); - } - if (Auth::user()->access_level == 'Partner') { + // consented clients by age distribution $client_consented_to_nine = Client::join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') ->select(\DB::raw("case when (((year(curdate()) - year(`tbl_client`.`dob`)) > 0) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 9)) then `tbl_client`.`dob` end")) ->where('tbl_client.smsenable', '=', 'Yes') @@ -321,42 +336,7 @@ public function client_charts() ->where('tbl_client.smsenable', '=', 'Yes') ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) ->count(); - } - - // non consented clients by age distribution - if (Auth::user()->access_level == 'Admin' || Auth::user()->access_level == 'Donor') { - $client_nonconsented_to_nine = Client::select(\DB::raw("case when (((year(curdate()) - year(`dob`)) > 0) and ((year(curdate()) - year(`dob`)) <= 9)) then `dob` end")) - ->where('smsenable', '!=', 'Yes') - ->count(); - $client_nonconsented_to_nineteen = Client::select(\DB::raw("case when (((year(curdate()) - year(`dob`)) >= 10) and ((year(curdate()) - year(`dob`)) <= 19)) then `dob` end")) - ->where('smsenable', '!=', 'Yes') - ->count(); - $client_nonconsented_to_twentyfour = Client::select(\DB::raw("case when (((year(curdate()) - year(`dob`)) >= 20) and ((year(curdate()) - year(`dob`)) <= 24)) then `dob` end")) - ->where('smsenable', '!=', 'Yes') - ->count(); - $client_nonconsented_to_twentyfive_above = Client::select(\DB::raw("case when ((year(curdate()) - year(`dob`)) >= 25) then `dob` end")) - ->where('smsenable', '!=', 'Yes') - ->count(); - } - if (Auth::user()->access_level == 'Facility') { - $client_nonconsented_to_nine = Client::select(\DB::raw("case when (((year(curdate()) - year(`dob`)) > 0) and ((year(curdate()) - year(`dob`)) <= 9)) then `dob` end")) - ->where('smsenable', '!=', 'Yes') - ->where('mfl_code', Auth::user()->facility_id) - ->count(); - $client_nonconsented_to_nineteen = Client::select(\DB::raw("case when (((year(curdate()) - year(`dob`)) >= 10) and ((year(curdate()) - year(`dob`)) <= 19)) then `dob` end")) - ->where('smsenable', '!=', 'Yes') - ->where('mfl_code', Auth::user()->facility_id) - ->count(); - $client_nonconsented_to_twentyfour = Client::select(\DB::raw("case when (((year(curdate()) - year(`dob`)) >= 20) and ((year(curdate()) - year(`dob`)) <= 24)) then `dob` end")) - ->where('smsenable', '!=', 'Yes') - ->where('mfl_code', Auth::user()->facility_id) - ->count(); - $client_nonconsented_to_twentyfive_above = Client::select(\DB::raw("case when ((year(curdate()) - year(`dob`)) >= 25) then `dob` end")) - ->where('smsenable', '!=', 'Yes') - ->where('mfl_code', Auth::user()->facility_id) - ->count(); - } - if (Auth::user()->access_level == 'Partner') { + // non consented clients by age distribution $client_nonconsented_to_nine = Client::join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') ->select(\DB::raw("case when (((year(curdate()) - year(`tbl_client`.`dob`)) > 0) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 9)) then `tbl_client`.`dob` end")) ->where('tbl_client.smsenable', '!=', 'Yes') diff --git a/resources/views/new_dashboard/facility_dashboard.blade.php b/resources/views/new_dashboard/facility_dashboard.blade.php new file mode 100644 index 0000000..e69de29 From 3b6e1b00a18c7fb8270875aefabbd9816024432a Mon Sep 17 00:00:00 2001 From: Ronald-pro <36841157+Ronald-pro@users.noreply.github.com> Date: Mon, 28 Mar 2022 15:32:45 +0300 Subject: [PATCH 023/171] created queries missed appointment for missed,defaulted,ltfu --- app/Http/Controllers/BulkUploadController.php | 10 +- .../Controllers/NewDashboardController.php | 550 +++++++++++++++++- .../views/partners/new_partner.blade.php | 35 +- 3 files changed, 564 insertions(+), 31 deletions(-) diff --git a/app/Http/Controllers/BulkUploadController.php b/app/Http/Controllers/BulkUploadController.php index 7e3b139..eeac911 100644 --- a/app/Http/Controllers/BulkUploadController.php +++ b/app/Http/Controllers/BulkUploadController.php @@ -186,11 +186,11 @@ public function importSecondClients(Request $request) $client_status = trim($receivedArr[$i]['client_status']); $clinic_id = trim($receivedArr[$i]['clinic_id']); $text_frequency = 168; - $text_time = 7; - $wellness = "Yes"; - $motivational = "Yes"; - $smsenable = "Yes"; - $language = trim($receivedArr[$i]['language_id']);; + $text_time = 19; + $wellness = "No"; + $motivational = "No"; + $smsenable = trim($receivedArr[$i]['smsenable']); + $language = trim($receivedArr[$i]['language_id']); $client = new Client; diff --git a/app/Http/Controllers/NewDashboardController.php b/app/Http/Controllers/NewDashboardController.php index 7142006..6e7b4c8 100644 --- a/app/Http/Controllers/NewDashboardController.php +++ b/app/Http/Controllers/NewDashboardController.php @@ -4,7 +4,7 @@ use Illuminate\Http\Request; use App\Models\Client; -use App\Models\Appointment; +use App\Models\Appointments; use App\Models\Facility; use App\Models\Gender; use App\Models\Partner; @@ -22,11 +22,11 @@ public function dashboard() $client = Client::where('status', '=', 'Active') ->where('mfl_code', Auth::user()->facility_id) ->count(); - $appointment = Appointment::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + $appointment = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') ->select('tbl_appointment.id') ->where('tbl_client.mfl_code', Auth::user()->facility_id) ->count(); - $missed_appointment = Appointment::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + $missed_appointment = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') ->select('tbl_appointment.id') ->where('tbl_appointment.app_status', '!=', 'Booked') ->orwhere('tbl_appointment.app_status', '!=', 'Notified') @@ -38,12 +38,12 @@ public function dashboard() ->where('tbl_client.status', '=', 'Active') ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) ->count(); - $appointment = Appointment::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + $appointment = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') ->select('tbl_appointment.id') ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) ->count(); - $missed_appointment = Appointment::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + $missed_appointment = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') ->select('tbl_appointment.id') ->where('tbl_appointment.app_status', '!=', 'Booked') @@ -54,9 +54,9 @@ public function dashboard() if (Auth::user()->access_level == 'Admin' || Auth::user()->access_level == 'Donor') { $client = Client::where('status', '=', 'Active') ->count(); - $appointment = Appointment::select('id') + $appointment = Appointments::select('id') ->count(); - $missed_appointment = Appointment::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + $missed_appointment = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') ->select('tbl_appointment.id') ->where('tbl_appointment.app_status', '!=', 'Booked') ->orwhere('tbl_appointment.app_status', '!=', 'Notified') @@ -101,7 +101,6 @@ public function dashboard() public function client_charts() { - if (Auth::user()->access_level == 'Admin' || Auth::user()->access_level == 'Donor') { // active clients by gender $clients_male = Client::where('gender', '=', '2') @@ -359,4 +358,539 @@ public function client_charts() ->count(); } } + + public function appointment_chart() + { + if (Auth::user()->access_level == 'Admin' || Auth::user()->access_level == 'Donor') { + // main appointments + $appointment = Appointments::select('id') + ->count(); + $appointment_honoured = Appointments::where('date_attended', '=', 'appntmnt_date') + ->count(); + $appointment_not_honoured = Appointments::where('date_attended', '!=', 'appntmnt_date') + ->count(); + // appointment by gender + $appointment_male = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->select('tbl_appointment.id') + ->where('tbl_client.gender', '=', '2') + ->count(); + $appointment_female = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->select('tbl_appointment.id') + ->where('tbl_client.gender', '=', '1') + ->count(); + // appointment by age + $appointment_to_nine = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select(\DB::raw("case when (((year(curdate()) - year(`tbl_client`.`dob`)) > 0) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 9)) then `tbl_client`.`dob` end")) + ->count(); + $appointment_to_fourteen = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select(\DB::raw("case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 10) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 14)) then `tbl_client`.`dob` end")) + ->count(); + $appointment_to_nineteen = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select(\DB::raw("case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 15) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 19)) then `tbl_client`.`dob` end")) + ->count(); + $appointment_to_twentyfour = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select(\DB::raw("case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 20) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 24)) then `tbl_client`.`dob` end")) + ->count(); + $appointment_to_twentyfive_above = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select(\DB::raw("case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 25) then `tbl_client`.`dob` end")) + ->count(); + // appointment honored by gender + $appointment_honoured_male = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->where('tbl_client.gender', '=', '2') + ->where('tbl_appointment.date_attended', '=', 'tbl_appointment.appntmnt_date') + ->count(); + $appointment_honoured_female = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->where('tbl_client.gender', '=', '1') + ->where('tbl_appointment.date_attended', '=', 'tbl_appointment.appntmnt_date') + ->count(); + // appointment honored by age + $appointment_honored_to_nine = Appointment::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select(\DB::raw("case when (((year(curdate()) - year(`tbl_client`.`dob`)) > 0) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 9)) then `tbl_client`.`dob` end")) + ->where('tbl_appointment.date_attended', '=', 'tbl_appointment.appntmnt_date') + ->count(); + $appointment_honored_to_fourteen = Appointment::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select(\DB::raw("case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 10) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 14)) then `tbl_client`.`dob` end")) + ->where('tbl_appointment.date_attended', '=', 'tbl_appointment.appntmnt_date') + ->count(); + $appointment_honored_to_nineteen = Appointment::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select(\DB::raw("case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 15) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 19)) then `tbl_client`.`dob` end")) + ->where('tbl_appointment.date_attended', '=', 'tbl_appointment.appntmnt_date') + ->count(); + $appointment_honored_to_twentyfour = Appointment::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select(\DB::raw("case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 20) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 24)) then `tbl_client`.`dob` end")) + ->where('tbl_appointment.date_attended', '=', 'tbl_appointment.appntmnt_date') + ->count(); + $appointment_honored_to_twentyfive_above = Appointment::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select(\DB::raw("case when ((year(curdate()) - year(`tbl_client`.`dob`)) >= 25) then `tbl_client`.`dob` end")) + ->where('tbl_appointment.date_attended', '=', 'tbl_appointment.appntmnt_date') + ->count(); + + // appointment not honored by gender + $appointment_not_honoured_male = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->where('tbl_client.gender', '=', '2') + ->where('tbl_appointment.date_attended', '!=', 'tbl_appointment.appntmnt_date') + ->count(); + $appointment_not_honoured_female = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->where('tbl_client.gender', '=', '1') + ->where('tbl_appointment.date_attended', '!=', 'tbl_appointment.appntmnt_date') + ->count(); + // appointment not honored by age + $appointment_not_honored_to_nine = Appointment::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select(\DB::raw("case when (((year(curdate()) - year(`tbl_client`.`dob`)) > 0) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 9)) then `tbl_client`.`dob` end")) + ->where('tbl_appointment.date_attended', '!=', 'tbl_appointment.appntmnt_date') + ->count(); + $appointment_not_honored_to_fourteen = Appointment::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select(\DB::raw("case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 10) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 14)) then `tbl_client`.`dob` end")) + ->where('tbl_appointment.date_attended', '!=', 'tbl_appointment.appntmnt_date') + ->count(); + $appointment_not_honored_to_nineteen = Appointment::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select(\DB::raw("case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 15) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 19)) then `tbl_client`.`dob` end")) + ->where('tbl_appointment.date_attended', '!=', 'tbl_appointment.appntmnt_date') + ->count(); + $appointment_not_honored_to_twentyfour = Appointment::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select(\DB::raw("case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 20) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 24)) then `tbl_client`.`dob` end")) + ->where('tbl_appointment.date_attended', '!=', 'tbl_appointment.appntmnt_date') + ->count(); + $appointment_not_honored_to_twentyfive_above = Appointment::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select(\DB::raw("case when ((year(curdate()) - year(`tbl_client`.`dob`)) >= 25) then `tbl_client`.`dob` end")) + ->where('tbl_appointment.date_attended', '=', 'tbl_appointment.appntmnt_date') + ->count(); + } + if (Auth::user()->access_level == 'Facility') { + $appointment = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->select('tbl_appointment.id') + ->where('tbl_client.mfl_code', Auth::user()->facility_id) + ->count(); + $appointment_honoured = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->where('tbl_appointment.date_attended', '=', 'tbl_appointment.appntmnt_date') + ->where('tbl_client.mfl_code', Auth::user()->facility_id) + ->count(); + $appointment_not_honoured = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->where('date_attended', '!=', 'appntmnt_date') + ->where('tbl_client.mfl_code', Auth::user()->facility_id) + ->count(); + // appointment by gender + $appointment_male = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->select('tbl_appointment.id') + ->where('tbl_client.gender', '=', '2') + ->where('tbl_client.mfl_code', Auth::user()->facility_id) + ->count(); + $appointment_female = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->select('tbl_appointment.id') + ->where('tbl_client.gender', '=', '1') + ->where('tbl_client.mfl_code', Auth::user()->facility_id) + ->count(); + // appointment by age + $appointment_to_nine = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select(\DB::raw("case when (((year(curdate()) - year(`tbl_client`.`dob`)) > 0) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 9)) then `tbl_client`.`dob` end")) + ->where('tbl_client.mfl_code', Auth::user()->facility_id) + ->count(); + $appointment_to_fourteen = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select(\DB::raw("case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 10) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 14)) then `tbl_client`.`dob` end")) + ->where('tbl_client.mfl_code', Auth::user()->facility_id) + ->count(); + $appointment_to_nineteen = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select(\DB::raw("case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 15) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 19)) then `tbl_client`.`dob` end")) + ->where('tbl_client.mfl_code', Auth::user()->facility_id) + ->count(); + $appointment_to_twentyfour = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select(\DB::raw("case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 20) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 24)) then `tbl_client`.`dob` end")) + ->where('tbl_client.mfl_code', Auth::user()->facility_id) + ->count(); + $appointment_to_twentyfive_above = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select(\DB::raw("case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 25) then `tbl_client`.`dob` end")) + ->where('tbl_client.mfl_code', Auth::user()->facility_id) + ->count(); + // appointment honored by gender + $appointment_honoured_male = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->where('tbl_client.gender', '=', '2') + ->where('tbl_appointment.date_attended', '=', 'tbl_appointment.appntmnt_date') + ->where('tbl_client.mfl_code', Auth::user()->facility_id) + ->count(); + $appointment_honoured_female = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->where('tbl_client.gender', '=', '1') + ->where('tbl_appointment.date_attended', '=', 'tbl_appointment.appntmnt_date') + ->where('tbl_client.mfl_code', Auth::user()->facility_id) + ->count(); + // appointment honored by age + $appointment_honored_to_nine = Appointment::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select(\DB::raw("case when (((year(curdate()) - year(`tbl_client`.`dob`)) > 0) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 9)) then `tbl_client`.`dob` end")) + ->where('tbl_appointment.date_attended', '=', 'tbl_appointment.appntmnt_date') + ->where('tbl_client.mfl_code', Auth::user()->facility_id) + ->count(); + $appointment_honored_to_fourteen = Appointment::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select(\DB::raw("case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 10) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 14)) then `tbl_client`.`dob` end")) + ->where('tbl_appointment.date_attended', '=', 'tbl_appointment.appntmnt_date') + ->where('tbl_client.mfl_code', Auth::user()->facility_id) + ->count(); + $appointment_honored_to_nineteen = Appointment::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select(\DB::raw("case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 15) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 19)) then `tbl_client`.`dob` end")) + ->where('tbl_appointment.date_attended', '=', 'tbl_appointment.appntmnt_date') + ->where('tbl_client.mfl_code', Auth::user()->facility_id) + ->count(); + $appointment_honored_to_twentyfour = Appointment::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select(\DB::raw("case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 20) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 24)) then `tbl_client`.`dob` end")) + ->where('tbl_appointment.date_attended', '=', 'tbl_appointment.appntmnt_date') + ->where('tbl_client.mfl_code', Auth::user()->facility_id) + ->count(); + $appointment_honored_to_twentyfive_above = Appointment::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select(\DB::raw("case when ((year(curdate()) - year(`tbl_client`.`dob`)) >= 25) then `tbl_client`.`dob` end")) + ->where('tbl_appointment.date_attended', '=', 'tbl_appointment.appntmnt_date') + ->where('tbl_client.mfl_code', Auth::user()->facility_id) + ->count(); + + // appointment not honored by gender + $appointment_not_honoured_male = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->where('tbl_client.gender', '=', '2') + ->where('tbl_appointment.date_attended', '!=', 'tbl_appointment.appntmnt_date') + ->where('tbl_client.mfl_code', Auth::user()->facility_id) + ->count(); + $appointment_not_honoured_female = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->where('tbl_client.gender', '=', '1') + ->where('tbl_appointment.date_attended', '!=', 'tbl_appointment.appntmnt_date') + ->where('tbl_client.mfl_code', Auth::user()->facility_id) + ->count(); + // appointment not honored by age + $appointment_not_honored_to_nine = Appointment::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select(\DB::raw("case when (((year(curdate()) - year(`tbl_client`.`dob`)) > 0) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 9)) then `tbl_client`.`dob` end")) + ->where('tbl_appointment.date_attended', '!=', 'tbl_appointment.appntmnt_date') + ->where('tbl_client.mfl_code', Auth::user()->facility_id) + ->count(); + $appointment_not_honored_to_fourteen = Appointment::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select(\DB::raw("case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 10) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 14)) then `tbl_client`.`dob` end")) + ->where('tbl_appointment.date_attended', '!=', 'tbl_appointment.appntmnt_date') + ->where('tbl_client.mfl_code', Auth::user()->facility_id) + ->count(); + $appointment_not_honored_to_nineteen = Appointment::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select(\DB::raw("case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 15) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 19)) then `tbl_client`.`dob` end")) + ->where('tbl_appointment.date_attended', '!=', 'tbl_appointment.appntmnt_date') + ->where('tbl_client.mfl_code', Auth::user()->facility_id) + ->count(); + $appointment_not_honored_to_twentyfour = Appointment::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select(\DB::raw("case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 20) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 24)) then `tbl_client`.`dob` end")) + ->where('tbl_appointment.date_attended', '!=', 'tbl_appointment.appntmnt_date') + ->where('tbl_client.mfl_code', Auth::user()->facility_id) + ->count(); + $appointment_not_honored_to_twentyfive_above = Appointment::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select(\DB::raw("case when ((year(curdate()) - year(`tbl_client`.`dob`)) >= 25) then `tbl_client`.`dob` end")) + ->where('tbl_appointment.date_attended', '=', 'tbl_appointment.appntmnt_date') + ->where('tbl_client.mfl_code', Auth::user()->facility_id) + ->count(); + } + if (Auth::user()->access_level == 'Partner') { + $appointment = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select('tbl_appointment.id') + ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) + ->count(); + $appointment_honoured = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->where('tbl_appointment.date_attended', '=', 'tbl_appointment.appntmnt_date') + ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) + ->count(); + $appointment_not_honoured = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->where('date_attended', '!=', 'appntmnt_date') + ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) + ->count(); + // appointment by gender + $appointment_male = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select('tbl_appointment.id') + ->where('tbl_client.gender', '=', '2') + ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) + ->count(); + $appointment_female = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select('tbl_appointment.id') + ->where('tbl_client.gender', '=', '1') + ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) + ->count(); + // appointment by age + $appointment_to_nine = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select(\DB::raw("case when (((year(curdate()) - year(`tbl_client`.`dob`)) > 0) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 9)) then `tbl_client`.`dob` end")) + ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) + ->count(); + $appointment_to_fourteen = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select(\DB::raw("case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 10) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 14)) then `tbl_client`.`dob` end")) + ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) + ->count(); + $appointment_to_nineteen = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select(\DB::raw("case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 15) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 19)) then `tbl_client`.`dob` end")) + ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) + ->count(); + $appointment_to_twentyfour = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select(\DB::raw("case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 20) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 24)) then `tbl_client`.`dob` end")) + ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) + ->count(); + $appointment_to_twentyfive_above = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select(\DB::raw("case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 25) then `tbl_client`.`dob` end")) + ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) + ->count(); + // appointment honored by gender + $appointment_honoured_male = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->where('tbl_client.gender', '=', '2') + ->where('tbl_appointment.date_attended', '=', 'tbl_appointment.appntmnt_date') + ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) + ->count(); + $appointment_honoured_female = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->where('tbl_client.gender', '=', '1') + ->where('tbl_appointment.date_attended', '=', 'tbl_appointment.appntmnt_date') + ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) + ->count(); + // appointment honored by age + $appointment_honored_to_nine = Appointment::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select(\DB::raw("case when (((year(curdate()) - year(`tbl_client`.`dob`)) > 0) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 9)) then `tbl_client`.`dob` end")) + ->where('tbl_appointment.date_attended', '=', 'tbl_appointment.appntmnt_date') + ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) + ->count(); + $appointment_honored_to_fourteen = Appointment::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select(\DB::raw("case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 10) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 14)) then `tbl_client`.`dob` end")) + ->where('tbl_appointment.date_attended', '=', 'tbl_appointment.appntmnt_date') + ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) + ->count(); + $appointment_honored_to_nineteen = Appointment::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select(\DB::raw("case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 15) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 19)) then `tbl_client`.`dob` end")) + ->where('tbl_appointment.date_attended', '=', 'tbl_appointment.appntmnt_date') + ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) + ->count(); + $appointment_honored_to_twentyfour = Appointment::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select(\DB::raw("case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 20) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 24)) then `tbl_client`.`dob` end")) + ->where('tbl_appointment.date_attended', '=', 'tbl_appointment.appntmnt_date') + ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) + ->count(); + $appointment_honored_to_twentyfive_above = Appointment::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select(\DB::raw("case when ((year(curdate()) - year(`tbl_client`.`dob`)) >= 25) then `tbl_client`.`dob` end")) + ->where('tbl_appointment.date_attended', '=', 'tbl_appointment.appntmnt_date') + ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) + ->count(); + + // appointment not honored by gender + $appointment_not_honoured_male = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->where('tbl_client.gender', '=', '2') + ->where('tbl_appointment.date_attended', '!=', 'tbl_appointment.appntmnt_date') + ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) + ->count(); + $appointment_not_honoured_female = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->where('tbl_client.gender', '=', '1') + ->where('tbl_appointment.date_attended', '!=', 'tbl_appointment.appntmnt_date') + ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) + ->count(); + // appointment not honored by age + $appointment_not_honored_to_nine = Appointment::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select(\DB::raw("case when (((year(curdate()) - year(`tbl_client`.`dob`)) > 0) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 9)) then `tbl_client`.`dob` end")) + ->where('tbl_appointment.date_attended', '!=', 'tbl_appointment.appntmnt_date') + ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) + ->count(); + $appointment_not_honored_to_fourteen = Appointment::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select(\DB::raw("case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 10) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 14)) then `tbl_client`.`dob` end")) + ->where('tbl_appointment.date_attended', '!=', 'tbl_appointment.appntmnt_date') + ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) + ->count(); + $appointment_not_honored_to_nineteen = Appointment::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select(\DB::raw("case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 15) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 19)) then `tbl_client`.`dob` end")) + ->where('tbl_appointment.date_attended', '!=', 'tbl_appointment.appntmnt_date') + ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) + ->count(); + $appointment_not_honored_to_twentyfour = Appointment::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select(\DB::raw("case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 20) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 24)) then `tbl_client`.`dob` end")) + ->where('tbl_appointment.date_attended', '!=', 'tbl_appointment.appntmnt_date') + ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) + ->count(); + $appointment_not_honored_to_twentyfive_above = Appointment::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select(\DB::raw("case when ((year(curdate()) - year(`tbl_client`.`dob`)) >= 25) then `tbl_client`.`dob` end")) + ->where('tbl_appointment.date_attended', '=', 'tbl_appointment.appntmnt_date') + ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) + ->count(); + } + } + public function missed_appointment_chart() + { + // main dashboard all + $appointment_total_missed = Appointments::where('date_attended', '!=', 'appntmnt_date') + ->count(); + $appointment_missed = Appointments::where('app_status', '=', 'Missed') + ->count(); + $appointment_defaulted = Appointments::where('app_status', '=', 'Defaulted') + ->count(); + $appointment_lftu = Appointments::where('app_status', '=', 'LTFU') + ->count(); + + // Total missed appointment by gender + $appointment_total_missed_female = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->where('tbl_appointment.date_attended', '!=', 'tbl_appointment.appntmnt_date') + ->where('tbl_client.gender', '=', '1') + ->count(); + $appointment_total_missed_male = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->where('tbl_appointment.date_attended', '!=', 'tbl_appointment.appntmnt_date') + ->where('tbl_client.gender', '=', '2') + ->count(); + + // Total missed appointment by age + $appointment_total_missed_to_nine = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->select(\DB::raw("case when (((year(curdate()) - year(`tbl_client`.`dob`)) > 0) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 9)) then `tbl_client`.`dob` end")) + ->where('tbl_appointment.date_attended', '!=', 'tbl_appointment.appntmnt_date') + ->count(); + $appointment_total_missed_to_fourteen = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->select(\DB::raw("case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 10) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 14)) then `tbl_client`.`dob` end")) + ->where('tbl_appointment.date_attended', '!=', 'tbl_appointment.appntmnt_date') + ->count(); + $appointment_total_missed_to_nineteen = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->select(\DB::raw("case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 15) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 19)) then `tbl_client`.`dob` end")) + ->where('tbl_appointment.date_attended', '!=', 'tbl_appointment.appntmnt_date') + ->count(); + $appointment_total_missed_to_twentyfour = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->select(\DB::raw("case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 20) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 24)) then `tbl_client`.`dob` end")) + ->where('tbl_appointment.date_attended', '!=', 'tbl_appointment.appntmnt_date') + ->count(); + $appointment_total_missed_to_twentyfive_above = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->select(\DB::raw("case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 25) then `tbl_client`.`dob` end")) + ->where('tbl_appointment.date_attended', '!=', 'tbl_appointment.appntmnt_date') + ->count(); + + // missed appointment by gender + $appointment_missed_female = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->where('tbl_appointment.app_status', '=', 'Missed') + ->where('tbl_client.gender', '=', '1') + ->count(); + $appointment_missed_male = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->where('tbl_appointment.app_status', '=', 'Missed') + ->where('tbl_client.gender', '=', '1') + ->count(); + + // missed appointment by age + $appointment_missed_to_nine = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->select(\DB::raw("case when (((year(curdate()) - year(`tbl_client`.`dob`)) > 0) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 9)) then `tbl_client`.`dob` end")) + ->where('tbl_appointment.app_status', '=', 'Missed') + ->count(); + $appointment_missed_to_fourteen = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->select(\DB::raw("case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 10) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 14)) then `tbl_client`.`dob` end")) + ->where('tbl_appointment.app_status', '=', 'Missed') + ->count(); + $appointment_missed_to_nineteen = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->select(\DB::raw("case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 15) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 19)) then `tbl_client`.`dob` end")) + ->where('tbl_appointment.app_status', '=', 'Missed') + ->count(); + $appointment_missed_to_twentyfour = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->select(\DB::raw("case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 20) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 24)) then `tbl_client`.`dob` end")) + ->where('tbl_appointment.app_status', '=', 'Missed') + ->count(); + $appointment_missed_to_twentyfive_above = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->select(\DB::raw("case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 25) then `tbl_client`.`dob` end")) + ->where('tbl_appointment.app_status', '=', 'Missed') + ->count(); + + // defaulted appointment by gender + $appointment_defaulted_female = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->where('tbl_appointment.app_status', '=', 'Defaulted') + ->where('tbl_client.gender', '=', '1') + ->count(); + $appointment_defaulted_female = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->where('tbl_appointment.app_status', '=', 'Defaulted') + ->where('tbl_client.gender', '=', '2') + ->count(); + + // defaulted appointment by age + $appointment_defaulted_to_nine = join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->select(\DB::raw("case when (((year(curdate()) - year(`tbl_client`.`dob`)) > 0) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 9)) then `tbl_client`.`dob` end")) + ->where('tbl_appointment.app_status', '=', 'Defaulted') + ->count(); + $appointment_defaulted_to_fourteen = join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->select(\DB::raw("case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 10) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 14)) then `tbl_client`.`dob` end")) + ->where('tbl_appointment.app_status', '=', 'Defaulted') + ->count(); + $appointment_defaulted_to_nineteen = join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->select(\DB::raw("case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 15) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 19)) then `tbl_client`.`dob` end")) + ->where('tbl_appointment.app_status', '=', 'Defaulted') + ->count(); + $appointment_defaulted_to_twentyfour = join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->select(\DB::raw("case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 20) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 24)) then `tbl_client`.`dob` end")) + ->where('tbl_appointment.app_status', '=', 'Defaulted') + ->count(); + $appointment_defaulted_to_twentyfive_above = join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->select(\DB::raw("case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 25) then `tbl_client`.`dob` end")) + ->where('tbl_appointment.app_status', '=', 'Defaulted') + ->count(); + + // ltfu appointment by gender + $appointment_ltfu_female = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->where('tbl_appointment.app_status', '=', 'LTFU') + ->where('tbl_client.gender', '=', '1') + ->count(); + $appointment_ltfu_female = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->where('tbl_appointment.app_status', '=', 'LTFU') + ->where('tbl_client.gender', '=', '2') + ->count(); + + // ltfu appointment by age + $appointment_ltfu_to_nine = join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->select(\DB::raw("case when (((year(curdate()) - year(`tbl_client`.`dob`)) > 0) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 9)) then `tbl_client`.`dob` end")) + ->where('tbl_appointment.app_status', '=', 'LTFU') + ->count(); + $appointment_ltfu_to_fourteen = join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->select(\DB::raw("case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 10) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 14)) then `tbl_client`.`dob` end")) + ->where('tbl_appointment.app_status', '=', 'LTFU') + ->count(); + $appointment_ltfu_to_nineteen = join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->select(\DB::raw("case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 15) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 19)) then `tbl_client`.`dob` end")) + ->where('tbl_appointment.app_status', '=', 'LTFU') + ->count(); + $appointment_ltfu_to_twentyfour = join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->select(\DB::raw("case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 20) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 24)) then `tbl_client`.`dob` end")) + ->where('tbl_appointment.app_status', '=', 'LTFU') + ->count(); + $appointment_ltfu_to_twentyfive_above = join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->select(\DB::raw("case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 25) then `tbl_client`.`dob` end")) + ->where('tbl_appointment.app_status', '=', 'LTFU') + ->count(); + } } diff --git a/resources/views/partners/new_partner.blade.php b/resources/views/partners/new_partner.blade.php index b2c884d..0b15988 100644 --- a/resources/views/partners/new_partner.blade.php +++ b/resources/views/partners/new_partner.blade.php @@ -101,7 +101,7 @@
- @if (count($partner_type) > 0) @foreach($partner_type as $type) @@ -220,31 +220,30 @@ function deletePartner(id) { "ordering": true, "info": true, dom: 'Bfrtip', - buttons: [ - { - extend: 'copy', - title: 'List Of Partners', - filename: 'List Of Partners' + buttons: [{ + extend: 'copy', + title: 'List Of Partners', + filename: 'List Of Partners' }, { - extend: 'csv', - title: 'List Of Partners', - filename: 'List Of Partners' + extend: 'csv', + title: 'List Of Partners', + filename: 'List Of Partners' }, { - extend: 'excel', - title: 'List Of Partners', - filename: 'List Of Partners' + extend: 'excel', + title: 'List Of Partners', + filename: 'List Of Partners' }, { - extend: 'pdf', - title: 'List Of Partners', - filename: 'List Of Partners' + extend: 'pdf', + title: 'List Of Partners', + filename: 'List Of Partners' }, { - extend: 'print', - title: 'List Of Partners', - filename: 'List Of Partners' + extend: 'print', + title: 'List Of Partners', + filename: 'List Of Partners' } ] }); From 20b334cdab4900a9f9109e4f7d56adecec5c7933 Mon Sep 17 00:00:00 2001 From: Ronald-pro <36841157+Ronald-pro@users.noreply.github.com> Date: Wed, 6 Apr 2022 14:37:37 +0300 Subject: [PATCH 024/171] changes on user creation and added charts for main dashboard --- app/Http/Controllers/BulkUploadController.php | 10 +- .../Controllers/NewDashboardController.php | 838 ++++++++++++++---- app/Http/Controllers/PartnerController.php | 11 +- app/Http/Controllers/UserController.php | 6 +- app/Models/ActiveFacilities.php | 18 + .../new_dashboard/main_dashbaord.blade.php | 651 ++++++++++++++ resources/views/users/adduser.blade.php | 2 + routes/web.php | 9 +- 8 files changed, 1364 insertions(+), 181 deletions(-) create mode 100644 app/Models/ActiveFacilities.php create mode 100644 resources/views/new_dashboard/main_dashbaord.blade.php diff --git a/app/Http/Controllers/BulkUploadController.php b/app/Http/Controllers/BulkUploadController.php index eeac911..043a4f4 100644 --- a/app/Http/Controllers/BulkUploadController.php +++ b/app/Http/Controllers/BulkUploadController.php @@ -88,13 +88,13 @@ public function importClients(Request $request) $mfl_code = trim($receivedArr[$i]['MFL']); $partner_id = trim($receivedArr[$i]['PartnerID']); $status = "Active"; - $client_status = "Art"; + $client_status = "ART"; $clinic_id = 1; $text_frequency = 168; $text_time = 7; - $wellness = "Yes"; - $motivational = "Yes"; - $smsenable = "Yes"; + $wellness = "No"; + $motivational = "No"; + $smsenable = trim($receivedArr[$i]['smsenable']); $language = 2; @@ -122,6 +122,7 @@ public function importClients(Request $request) $client->txt_time = $text_time; $client->wellness_enable = $wellness; $client->motivational_enable = $motivational; + $client->smsenable = $smsenable; $client->created_by = Auth::user()->id; $client->updated_by = Auth::user()->id; @@ -217,6 +218,7 @@ public function importSecondClients(Request $request) $client->txt_time = $text_time; $client->wellness_enable = $wellness; $client->motivational_enable = $motivational; + $client->smsenable = $smsenable; $client->created_by = Auth::user()->id; $client->updated_by = Auth::user()->id; diff --git a/app/Http/Controllers/NewDashboardController.php b/app/Http/Controllers/NewDashboardController.php index 6e7b4c8..9bccda4 100644 --- a/app/Http/Controllers/NewDashboardController.php +++ b/app/Http/Controllers/NewDashboardController.php @@ -10,7 +10,10 @@ use App\Models\Partner; use App\Models\County; use App\Models\SubCounty; +use App\Models\PartnerFacility; +use App\Models\ActiveFacilities; use Auth; +use Carbon\Carbon; class NewDashboardController extends Controller { @@ -52,50 +55,169 @@ public function dashboard() ->count(); } if (Auth::user()->access_level == 'Admin' || Auth::user()->access_level == 'Donor') { + $all_partners = Partner::where('status', '=', 'Active')->pluck('name', 'id'); $client = Client::where('status', '=', 'Active') + ->whereNull('hei_no') ->count(); $appointment = Appointments::select('id') ->count(); $missed_appointment = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') - ->select('tbl_appointment.id') - ->where('tbl_appointment.app_status', '!=', 'Booked') - ->orwhere('tbl_appointment.app_status', '!=', 'Notified') + ->where('tbl_appointment.app_status', '=', 'Missed') + ->orwhere('tbl_appointment.app_status', '=', 'LTFU') + ->orwhere('tbl_appointment.app_status', '=', 'Defaulted') + ->count(); + $active_facilities = PartnerFacility::join('tbl_client', 'tbl_partner_facility.mfl_code', '=', 'tbl_client.mfl_code') + ->join('tbl_appointment', 'tbl_client.id', '=', 'tbl_appointment.client_id') + ->where() + ->count(); + // active clients by gender + $clients_male = Client::where('gender', '=', '2') + ->where('status', '=', 'Active') + ->whereNull('hei_no') ->count(); - } - // showing all consented clients - if (Auth::user()->access_level == 'Admin' || Auth::user()->access_level == 'Donor') { - $client_consented = Client::where('smsenable', '=', 'Yes') + $clients_female = Client::where('gender', '=', '1') + ->where('status', '=', 'Active') + ->whereNull('hei_no') ->count(); - } - if (Auth::user()->access_level == 'Facility') { - $client_consented = Client::where('smsenable', '=', 'Yes') - ->where('mfl_code', Auth::user()->facility_id) + $unknown_gender = Client::where('gender', '!=', '1') + ->where('gender', '!=', '2') + ->where('status', '=', 'Active') + ->whereNull('hei_no') ->count(); - } - if (Auth::user()->access_level == 'Partner') { - $client_consented = Client::join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') - ->where('tbl_client.smsenable', '=', 'Yes') - ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) + + // active clients by age distribution + $client_to_nine = Client::select(\DB::raw("count((case when (((year(curdate()) - year(`dob`)) > 0) and ((year(curdate()) - year(`dob`)) <= 9)) then `dob` end)) AS count")) + ->where('status', '=', 'Active') + ->whereNull('hei_no') + ->pluck('count'); + $client_to_fourteen = Client::select(\DB::raw("count((case when (((year(curdate()) - year(`dob`)) >= 10) and ((year(curdate()) - year(`dob`)) <= 14)) then `dob` end)) AS count")) + ->where('status', '=', 'Active') + ->whereNull('hei_no') + ->pluck('count'); + + $client_to_nineteen = Client::select(\DB::raw("count((case when (((year(curdate()) - year(`dob`)) >= 15) and ((year(curdate()) - year(`dob`)) <= 19)) then `dob` end)) AS count")) + ->where('status', '=', 'Active') + ->whereNull('hei_no') + ->pluck('count'); + + $client_to_twentyfour = Client::select(\DB::raw("count((case when (((year(curdate()) - year(`dob`)) >= 20) and ((year(curdate()) - year(`dob`)) <= 24)) then `id` end)) AS count")) + ->where('status', '=', 'Active') + ->whereNull('hei_no') + ->pluck('count'); + + $client_to_twentyfive_above = Client::select(\DB::raw("count((case when (((year(curdate()) - year(`dob`)) >= 25)) then `id` end)) AS count")) + ->where('status', '=', 'Active') + ->whereNull('hei_no') + ->pluck('count'); + $client_unknown_age = Client::where('dob', '=', '') + ->orWhereNull('dob') + ->where('status', '=', 'Active') + ->whereNull('hei_no') ->count(); - } - // showing all non consented clients - if (Auth::user()->access_level == 'Admin' || Auth::user()->access_level == 'Donor') { - $client_nonconsented = Client::where('smsenable', '!=', 'Yes') + // appointment by gender + $appointment_male = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->select('tbl_appointment.id') + ->where('tbl_client.gender', '=', '2') ->count(); - } - if (Auth::user()->access_level == 'Facility') { - $client_nonconsented = Client::where('smsenable', '!=', 'Yes') - ->where('mfl_code', Auth::user()->facility_id) + $appointment_female = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->select('tbl_appointment.id') + ->where('tbl_client.gender', '=', '1') ->count(); - } - if (Auth::user()->access_level == 'Partner') { - $client_nonconsented = Client::join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') - ->where('tbl_client.smsenable', '!=', 'Yes') - ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) + $appointment_uknown_gender = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->select('tbl_appointment.id') + ->where('tbl_client.gender', '!=', '1') + ->where('tbl_client.gender', '!=', '2') + ->count(); + // appointment by age + $appointment_to_nine = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) > 0) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 9)) then `tbl_client`.`id` end)) AS count")) + ->pluck('count'); + $appointment_to_fourteen = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 10) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 14)) then `tbl_client`.`id` end)) AS count")) + ->pluck('count'); + $appointment_to_nineteen = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 15) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 19)) then `tbl_client`.`id` end)) AS count")) + ->pluck('count'); + $appointment_to_twentyfour = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 20) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 24)) then `tbl_client`.`id` end)) AS count")) + ->pluck('count'); + $appointment_to_twentyfive_above = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 25)) then `tbl_client`.`id` end)) AS count")) + ->pluck('count'); + $appointment_uknown_age = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->where('tbl_client.dob', '=', '') + ->orWhereNull('tbl_client.dob') + ->count(); + + // Total missed appointment by gender + $appointment_total_missed_female = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->where('tbl_appointment.app_status', '=', 'Missed') + ->orwhere('tbl_appointment.app_status', '=', 'LTFU') + ->orwhere('tbl_appointment.app_status', '=', 'Defaulted') + ->where('tbl_client.gender', '=', '1') + ->count(); + $appointment_total_missed_male = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->where('tbl_appointment.app_status', '=', 'Missed') + ->orwhere('tbl_appointment.app_status', '=', 'LTFU') + ->orwhere('tbl_appointment.app_status', '=', 'Defaulted') + ->where('tbl_client.gender', '=', '2') + ->count(); + $appointment_total_missed_uknown_gender = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->where('tbl_appointment.app_status', '=', 'Missed') + ->orwhere('tbl_appointment.app_status', '=', 'LTFU') + ->orwhere('tbl_appointment.app_status', '=', 'Defaulted') + ->where('tbl_client.gender', '!=', '1') + ->where('tbl_client.gender', '!=', '2') + ->count(); + + // Total missed appointment by age + $appointment_total_missed_to_nine = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) > 0) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 9)) then `tbl_client`.`id` end)) AS count")) + ->where('tbl_appointment.app_status', '=', 'Missed') + ->orwhere('tbl_appointment.app_status', '=', 'LTFU') + ->orwhere('tbl_appointment.app_status', '=', 'Defaulted') + ->pluck('count'); + $appointment_total_missed_to_fourteen = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 10) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 14)) then `tbl_client`.`id` end)) AS count")) + ->where('tbl_appointment.app_status', '=', 'Missed') + ->orwhere('tbl_appointment.app_status', '=', 'LTFU') + ->orwhere('tbl_appointment.app_status', '=', 'Defaulted') + ->pluck('count'); + $appointment_total_missed_to_nineteen = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 15) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 19)) then `tbl_client`.`id` end)) AS count")) + ->where('tbl_appointment.date_attended', '!=', 'tbl_appointment.appntmnt_date') + ->pluck('count'); + $appointment_total_missed_to_twentyfour = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 20) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 24)) then `tbl_client`.`id` end)) AS count")) + ->where('tbl_appointment.date_attended', '!=', 'tbl_appointment.appntmnt_date') + ->pluck('count'); + $appointment_total_missed_to_twentyfive_above = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 25)) then `tbl_client`.`id` end)) AS count")) + ->where('tbl_appointment.app_status', '=', 'Missed') + ->orwhere('tbl_appointment.app_status', '=', 'LTFU') + ->orwhere('tbl_appointment.app_status', '=', 'Defaulted') + ->pluck('count'); + $appointment_total_missed_uknown_age = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->where('tbl_client.dob', '=', '') + ->orWhereNull('tbl_client.dob') + ->where('tbl_appointment.app_status', '=', 'Missed') + ->orwhere('tbl_appointment.app_status', '=', 'LTFU') + ->orwhere('tbl_appointment.app_status', '=', 'Defaulted') ->count(); } + + + // dd($active_facilities); + + return view('new_dashboard.main_dashbaord', compact('all_partners', 'client', 'appointment', 'missed_appointment', 'clients_male', 'clients_female', 'unknown_gender', 'client_to_nine', 'client_to_fourteen', 'client_to_nineteen', 'client_to_twentyfour', 'client_to_twentyfive_above', 'client_unknown_age', 'appointment_male', 'appointment_female', 'appointment_uknown_gender', 'appointment_to_nine', 'appointment_to_fourteen', 'appointment_to_nineteen', 'appointment_to_twentyfour', 'appointment_to_twentyfive_above', 'appointment_uknown_age', 'appointment_total_missed_female', 'appointment_total_missed_male', 'appointment_total_missed_uknown_gender', 'appointment_total_missed_to_nine', 'appointment_total_missed_to_fourteen', 'appointment_total_missed_to_nineteen', 'appointment_total_missed_to_twentyfour', 'appointment_total_missed_to_twentyfive_above', 'appointment_total_missed_uknown_age')); } public function client_charts() @@ -755,142 +877,526 @@ public function appointment_chart() } public function missed_appointment_chart() { - // main dashboard all - $appointment_total_missed = Appointments::where('date_attended', '!=', 'appntmnt_date') - ->count(); - $appointment_missed = Appointments::where('app_status', '=', 'Missed') - ->count(); - $appointment_defaulted = Appointments::where('app_status', '=', 'Defaulted') - ->count(); - $appointment_lftu = Appointments::where('app_status', '=', 'LTFU') - ->count(); - - // Total missed appointment by gender - $appointment_total_missed_female = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') - ->where('tbl_appointment.date_attended', '!=', 'tbl_appointment.appntmnt_date') - ->where('tbl_client.gender', '=', '1') - ->count(); - $appointment_total_missed_male = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') - ->where('tbl_appointment.date_attended', '!=', 'tbl_appointment.appntmnt_date') - ->where('tbl_client.gender', '=', '2') - ->count(); - - // Total missed appointment by age - $appointment_total_missed_to_nine = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') - ->select(\DB::raw("case when (((year(curdate()) - year(`tbl_client`.`dob`)) > 0) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 9)) then `tbl_client`.`dob` end")) - ->where('tbl_appointment.date_attended', '!=', 'tbl_appointment.appntmnt_date') - ->count(); - $appointment_total_missed_to_fourteen = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') - ->select(\DB::raw("case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 10) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 14)) then `tbl_client`.`dob` end")) - ->where('tbl_appointment.date_attended', '!=', 'tbl_appointment.appntmnt_date') - ->count(); - $appointment_total_missed_to_nineteen = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') - ->select(\DB::raw("case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 15) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 19)) then `tbl_client`.`dob` end")) - ->where('tbl_appointment.date_attended', '!=', 'tbl_appointment.appntmnt_date') - ->count(); - $appointment_total_missed_to_twentyfour = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') - ->select(\DB::raw("case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 20) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 24)) then `tbl_client`.`dob` end")) - ->where('tbl_appointment.date_attended', '!=', 'tbl_appointment.appntmnt_date') - ->count(); - $appointment_total_missed_to_twentyfive_above = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') - ->select(\DB::raw("case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 25) then `tbl_client`.`dob` end")) - ->where('tbl_appointment.date_attended', '!=', 'tbl_appointment.appntmnt_date') - ->count(); - - // missed appointment by gender - $appointment_missed_female = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') - ->where('tbl_appointment.app_status', '=', 'Missed') - ->where('tbl_client.gender', '=', '1') - ->count(); - $appointment_missed_male = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') - ->where('tbl_appointment.app_status', '=', 'Missed') - ->where('tbl_client.gender', '=', '1') - ->count(); - - // missed appointment by age - $appointment_missed_to_nine = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') - ->select(\DB::raw("case when (((year(curdate()) - year(`tbl_client`.`dob`)) > 0) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 9)) then `tbl_client`.`dob` end")) - ->where('tbl_appointment.app_status', '=', 'Missed') - ->count(); - $appointment_missed_to_fourteen = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') - ->select(\DB::raw("case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 10) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 14)) then `tbl_client`.`dob` end")) - ->where('tbl_appointment.app_status', '=', 'Missed') - ->count(); - $appointment_missed_to_nineteen = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') - ->select(\DB::raw("case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 15) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 19)) then `tbl_client`.`dob` end")) - ->where('tbl_appointment.app_status', '=', 'Missed') - ->count(); - $appointment_missed_to_twentyfour = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') - ->select(\DB::raw("case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 20) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 24)) then `tbl_client`.`dob` end")) - ->where('tbl_appointment.app_status', '=', 'Missed') - ->count(); - $appointment_missed_to_twentyfive_above = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') - ->select(\DB::raw("case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 25) then `tbl_client`.`dob` end")) - ->where('tbl_appointment.app_status', '=', 'Missed') - ->count(); - - // defaulted appointment by gender - $appointment_defaulted_female = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') - ->where('tbl_appointment.app_status', '=', 'Defaulted') - ->where('tbl_client.gender', '=', '1') - ->count(); - $appointment_defaulted_female = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') - ->where('tbl_appointment.app_status', '=', 'Defaulted') - ->where('tbl_client.gender', '=', '2') - ->count(); - - // defaulted appointment by age - $appointment_defaulted_to_nine = join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') - ->select(\DB::raw("case when (((year(curdate()) - year(`tbl_client`.`dob`)) > 0) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 9)) then `tbl_client`.`dob` end")) - ->where('tbl_appointment.app_status', '=', 'Defaulted') - ->count(); - $appointment_defaulted_to_fourteen = join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') - ->select(\DB::raw("case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 10) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 14)) then `tbl_client`.`dob` end")) - ->where('tbl_appointment.app_status', '=', 'Defaulted') - ->count(); - $appointment_defaulted_to_nineteen = join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') - ->select(\DB::raw("case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 15) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 19)) then `tbl_client`.`dob` end")) - ->where('tbl_appointment.app_status', '=', 'Defaulted') - ->count(); - $appointment_defaulted_to_twentyfour = join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') - ->select(\DB::raw("case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 20) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 24)) then `tbl_client`.`dob` end")) - ->where('tbl_appointment.app_status', '=', 'Defaulted') - ->count(); - $appointment_defaulted_to_twentyfive_above = join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') - ->select(\DB::raw("case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 25) then `tbl_client`.`dob` end")) - ->where('tbl_appointment.app_status', '=', 'Defaulted') - ->count(); - - // ltfu appointment by gender - $appointment_ltfu_female = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') - ->where('tbl_appointment.app_status', '=', 'LTFU') - ->where('tbl_client.gender', '=', '1') - ->count(); - $appointment_ltfu_female = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') - ->where('tbl_appointment.app_status', '=', 'LTFU') - ->where('tbl_client.gender', '=', '2') - ->count(); - - // ltfu appointment by age - $appointment_ltfu_to_nine = join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') - ->select(\DB::raw("case when (((year(curdate()) - year(`tbl_client`.`dob`)) > 0) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 9)) then `tbl_client`.`dob` end")) - ->where('tbl_appointment.app_status', '=', 'LTFU') - ->count(); - $appointment_ltfu_to_fourteen = join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') - ->select(\DB::raw("case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 10) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 14)) then `tbl_client`.`dob` end")) - ->where('tbl_appointment.app_status', '=', 'LTFU') - ->count(); - $appointment_ltfu_to_nineteen = join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') - ->select(\DB::raw("case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 15) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 19)) then `tbl_client`.`dob` end")) - ->where('tbl_appointment.app_status', '=', 'LTFU') - ->count(); - $appointment_ltfu_to_twentyfour = join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') - ->select(\DB::raw("case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 20) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 24)) then `tbl_client`.`dob` end")) - ->where('tbl_appointment.app_status', '=', 'LTFU') - ->count(); - $appointment_ltfu_to_twentyfive_above = join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') - ->select(\DB::raw("case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 25) then `tbl_client`.`dob` end")) - ->where('tbl_appointment.app_status', '=', 'LTFU') - ->count(); + if (Auth::user()->access_level == 'Admin' || Auth::user()->access_level == 'Donor') { + // main dashboard all + $appointment_total_missed = Appointments::where('date_attended', '!=', 'appntmnt_date') + ->count(); + $appointment_missed = Appointments::where('app_status', '=', 'Missed') + ->count(); + $appointment_defaulted = Appointments::where('app_status', '=', 'Defaulted') + ->count(); + $appointment_lftu = Appointments::where('app_status', '=', 'LTFU') + ->count(); + + // Total missed appointment by gender + $appointment_total_missed_female = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->where('tbl_appointment.date_attended', '!=', 'tbl_appointment.appntmnt_date') + ->where('tbl_client.gender', '=', '1') + ->count(); + $appointment_total_missed_male = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->where('tbl_appointment.date_attended', '!=', 'tbl_appointment.appntmnt_date') + ->where('tbl_client.gender', '=', '2') + ->count(); + + // Total missed appointment by age + $appointment_total_missed_to_nine = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->select(\DB::raw("case when (((year(curdate()) - year(`tbl_client`.`dob`)) > 0) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 9)) then `tbl_client`.`dob` end")) + ->where('tbl_appointment.date_attended', '!=', 'tbl_appointment.appntmnt_date') + ->count(); + $appointment_total_missed_to_fourteen = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->select(\DB::raw("case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 10) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 14)) then `tbl_client`.`dob` end")) + ->where('tbl_appointment.date_attended', '!=', 'tbl_appointment.appntmnt_date') + ->count(); + $appointment_total_missed_to_nineteen = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->select(\DB::raw("case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 15) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 19)) then `tbl_client`.`dob` end")) + ->where('tbl_appointment.date_attended', '!=', 'tbl_appointment.appntmnt_date') + ->count(); + $appointment_total_missed_to_twentyfour = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->select(\DB::raw("case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 20) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 24)) then `tbl_client`.`dob` end")) + ->where('tbl_appointment.date_attended', '!=', 'tbl_appointment.appntmnt_date') + ->count(); + $appointment_total_missed_to_twentyfive_above = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->select(\DB::raw("case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 25) then `tbl_client`.`dob` end")) + ->where('tbl_appointment.date_attended', '!=', 'tbl_appointment.appntmnt_date') + ->count(); + + // missed appointment by gender + $appointment_missed_female = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->where('tbl_appointment.app_status', '=', 'Missed') + ->where('tbl_client.gender', '=', '1') + ->count(); + $appointment_missed_male = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->where('tbl_appointment.app_status', '=', 'Missed') + ->where('tbl_client.gender', '=', '1') + ->count(); + + // missed appointment by age + $appointment_missed_to_nine = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->select(\DB::raw("case when (((year(curdate()) - year(`tbl_client`.`dob`)) > 0) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 9)) then `tbl_client`.`dob` end")) + ->where('tbl_appointment.app_status', '=', 'Missed') + ->count(); + $appointment_missed_to_fourteen = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->select(\DB::raw("case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 10) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 14)) then `tbl_client`.`dob` end")) + ->where('tbl_appointment.app_status', '=', 'Missed') + ->count(); + $appointment_missed_to_nineteen = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->select(\DB::raw("case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 15) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 19)) then `tbl_client`.`dob` end")) + ->where('tbl_appointment.app_status', '=', 'Missed') + ->count(); + $appointment_missed_to_twentyfour = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->select(\DB::raw("case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 20) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 24)) then `tbl_client`.`dob` end")) + ->where('tbl_appointment.app_status', '=', 'Missed') + ->count(); + $appointment_missed_to_twentyfive_above = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->select(\DB::raw("case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 25) then `tbl_client`.`dob` end")) + ->where('tbl_appointment.app_status', '=', 'Missed') + ->count(); + + // defaulted appointment by gender + $appointment_defaulted_female = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->where('tbl_appointment.app_status', '=', 'Defaulted') + ->where('tbl_client.gender', '=', '1') + ->count(); + $appointment_defaulted_female = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->where('tbl_appointment.app_status', '=', 'Defaulted') + ->where('tbl_client.gender', '=', '2') + ->count(); + + // defaulted appointment by age + $appointment_defaulted_to_nine = join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->select(\DB::raw("case when (((year(curdate()) - year(`tbl_client`.`dob`)) > 0) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 9)) then `tbl_client`.`dob` end")) + ->where('tbl_appointment.app_status', '=', 'Defaulted') + ->count(); + $appointment_defaulted_to_fourteen = join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->select(\DB::raw("case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 10) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 14)) then `tbl_client`.`dob` end")) + ->where('tbl_appointment.app_status', '=', 'Defaulted') + ->count(); + $appointment_defaulted_to_nineteen = join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->select(\DB::raw("case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 15) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 19)) then `tbl_client`.`dob` end")) + ->where('tbl_appointment.app_status', '=', 'Defaulted') + ->count(); + $appointment_defaulted_to_twentyfour = join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->select(\DB::raw("case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 20) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 24)) then `tbl_client`.`dob` end")) + ->where('tbl_appointment.app_status', '=', 'Defaulted') + ->count(); + $appointment_defaulted_to_twentyfive_above = join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->select(\DB::raw("case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 25) then `tbl_client`.`dob` end")) + ->where('tbl_appointment.app_status', '=', 'Defaulted') + ->count(); + + // ltfu appointment by gender + $appointment_ltfu_female = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->where('tbl_appointment.app_status', '=', 'LTFU') + ->where('tbl_client.gender', '=', '1') + ->count(); + $appointment_ltfu_female = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->where('tbl_appointment.app_status', '=', 'LTFU') + ->where('tbl_client.gender', '=', '2') + ->count(); + + // ltfu appointment by age + $appointment_ltfu_to_nine = join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->select(\DB::raw("case when (((year(curdate()) - year(`tbl_client`.`dob`)) > 0) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 9)) then `tbl_client`.`dob` end")) + ->where('tbl_appointment.app_status', '=', 'LTFU') + ->count(); + $appointment_ltfu_to_fourteen = join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->select(\DB::raw("case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 10) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 14)) then `tbl_client`.`dob` end")) + ->where('tbl_appointment.app_status', '=', 'LTFU') + ->count(); + $appointment_ltfu_to_nineteen = join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->select(\DB::raw("case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 15) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 19)) then `tbl_client`.`dob` end")) + ->where('tbl_appointment.app_status', '=', 'LTFU') + ->count(); + $appointment_ltfu_to_twentyfour = join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->select(\DB::raw("case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 20) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 24)) then `tbl_client`.`dob` end")) + ->where('tbl_appointment.app_status', '=', 'LTFU') + ->count(); + $appointment_ltfu_to_twentyfive_above = join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->select(\DB::raw("case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 25) then `tbl_client`.`dob` end")) + ->where('tbl_appointment.app_status', '=', 'LTFU') + ->count(); + } + if (Auth::user()->access_level == 'Facility') { + // main dashboard all + $appointment_total_missed = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->where('tbl_appointment.date_attended', '!=', 'tbl_appointment.appntmnt_date') + ->where('tbl_client.mfl_code', Auth::user()->facility_id) + ->count(); + $appointment_missed = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->where('tbl_appointment.app_status', '=', 'Missed') + ->where('tbl_client.mfl_code', Auth::user()->facility_id) + ->count(); + $appointment_defaulted = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->where('tbl_appointment.app_status', '=', 'Defaulted') + ->where('tbl_client.mfl_code', Auth::user()->facility_id) + ->count(); + $appointment_lftu = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->where('tbl_appointment.app_status', '=', 'LTFU') + ->where('tbl_client.mfl_code', Auth::user()->facility_id) + ->count(); + + // Total missed appointment by gender + $appointment_total_missed_female = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->where('tbl_appointment.date_attended', '!=', 'tbl_appointment.appntmnt_date') + ->where('tbl_client.gender', '=', '1') + ->where('tbl_client.mfl_code', Auth::user()->facility_id) + ->count(); + $appointment_total_missed_male = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->where('tbl_appointment.date_attended', '!=', 'tbl_appointment.appntmnt_date') + ->where('tbl_client.gender', '=', '2') + ->where('tbl_client.mfl_code', Auth::user()->facility_id) + ->count(); + + // Total missed appointment by age + $appointment_total_missed_to_nine = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->select(\DB::raw("case when (((year(curdate()) - year(`tbl_client`.`dob`)) > 0) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 9)) then `tbl_client`.`dob` end")) + ->where('tbl_appointment.date_attended', '!=', 'tbl_appointment.appntmnt_date') + ->where('tbl_client.mfl_code', Auth::user()->facility_id) + ->count(); + $appointment_total_missed_to_fourteen = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->select(\DB::raw("case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 10) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 14)) then `tbl_client`.`dob` end")) + ->where('tbl_appointment.date_attended', '!=', 'tbl_appointment.appntmnt_date') + ->where('tbl_client.mfl_code', Auth::user()->facility_id) + ->count(); + $appointment_total_missed_to_nineteen = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->select(\DB::raw("case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 15) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 19)) then `tbl_client`.`dob` end")) + ->where('tbl_appointment.date_attended', '!=', 'tbl_appointment.appntmnt_date') + ->where('tbl_client.mfl_code', Auth::user()->facility_id) + ->count(); + $appointment_total_missed_to_twentyfour = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->select(\DB::raw("case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 20) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 24)) then `tbl_client`.`dob` end")) + ->where('tbl_appointment.date_attended', '!=', 'tbl_appointment.appntmnt_date') + ->where('tbl_client.mfl_code', Auth::user()->facility_id) + ->count(); + $appointment_total_missed_to_twentyfive_above = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->select(\DB::raw("case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 25) then `tbl_client`.`dob` end")) + ->where('tbl_appointment.date_attended', '!=', 'tbl_appointment.appntmnt_date') + ->where('tbl_client.mfl_code', Auth::user()->facility_id) + ->count(); + + // missed appointment by gender + $appointment_missed_female = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->where('tbl_appointment.app_status', '=', 'Missed') + ->where('tbl_client.gender', '=', '1') + ->where('tbl_client.mfl_code', Auth::user()->facility_id) + ->count(); + $appointment_missed_male = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->where('tbl_appointment.app_status', '=', 'Missed') + ->where('tbl_client.gender', '=', '1') + ->where('tbl_client.mfl_code', Auth::user()->facility_id) + ->count(); + + // missed appointment by age + $appointment_missed_to_nine = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->select(\DB::raw("case when (((year(curdate()) - year(`tbl_client`.`dob`)) > 0) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 9)) then `tbl_client`.`dob` end")) + ->where('tbl_appointment.app_status', '=', 'Missed') + ->where('tbl_client.mfl_code', Auth::user()->facility_id) + ->count(); + $appointment_missed_to_fourteen = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->select(\DB::raw("case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 10) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 14)) then `tbl_client`.`dob` end")) + ->where('tbl_appointment.app_status', '=', 'Missed') + ->where('tbl_client.mfl_code', Auth::user()->facility_id) + ->count(); + $appointment_missed_to_nineteen = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->select(\DB::raw("case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 15) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 19)) then `tbl_client`.`dob` end")) + ->where('tbl_appointment.app_status', '=', 'Missed') + ->where('tbl_client.mfl_code', Auth::user()->facility_id) + ->count(); + $appointment_missed_to_twentyfour = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->select(\DB::raw("case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 20) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 24)) then `tbl_client`.`dob` end")) + ->where('tbl_appointment.app_status', '=', 'Missed') + ->where('tbl_client.mfl_code', Auth::user()->facility_id) + ->count(); + $appointment_missed_to_twentyfive_above = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->select(\DB::raw("case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 25) then `tbl_client`.`dob` end")) + ->where('tbl_appointment.app_status', '=', 'Missed') + ->where('tbl_client.mfl_code', Auth::user()->facility_id) + ->count(); + + // defaulted appointment by gender + $appointment_defaulted_female = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->where('tbl_appointment.app_status', '=', 'Defaulted') + ->where('tbl_client.gender', '=', '1') + ->where('tbl_client.mfl_code', Auth::user()->facility_id) + ->count(); + $appointment_defaulted_female = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->where('tbl_appointment.app_status', '=', 'Defaulted') + ->where('tbl_client.gender', '=', '2') + ->where('tbl_client.mfl_code', Auth::user()->facility_id) + ->count(); + + // defaulted appointment by age + $appointment_defaulted_to_nine = join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->select(\DB::raw("case when (((year(curdate()) - year(`tbl_client`.`dob`)) > 0) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 9)) then `tbl_client`.`dob` end")) + ->where('tbl_appointment.app_status', '=', 'Defaulted') + ->where('tbl_client.mfl_code', Auth::user()->facility_id) + ->count(); + $appointment_defaulted_to_fourteen = join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->select(\DB::raw("case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 10) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 14)) then `tbl_client`.`dob` end")) + ->where('tbl_appointment.app_status', '=', 'Defaulted') + ->where('tbl_client.mfl_code', Auth::user()->facility_id) + ->count(); + $appointment_defaulted_to_nineteen = join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->select(\DB::raw("case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 15) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 19)) then `tbl_client`.`dob` end")) + ->where('tbl_appointment.app_status', '=', 'Defaulted') + ->where('tbl_client.mfl_code', Auth::user()->facility_id) + ->count(); + $appointment_defaulted_to_twentyfour = join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->select(\DB::raw("case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 20) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 24)) then `tbl_client`.`dob` end")) + ->where('tbl_appointment.app_status', '=', 'Defaulted') + ->where('tbl_client.mfl_code', Auth::user()->facility_id) + ->count(); + $appointment_defaulted_to_twentyfive_above = join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->select(\DB::raw("case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 25) then `tbl_client`.`dob` end")) + ->where('tbl_appointment.app_status', '=', 'Defaulted') + ->where('tbl_client.mfl_code', Auth::user()->facility_id) + ->count(); + + // ltfu appointment by gender + $appointment_ltfu_female = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->where('tbl_appointment.app_status', '=', 'LTFU') + ->where('tbl_client.gender', '=', '1') + ->where('tbl_client.mfl_code', Auth::user()->facility_id) + ->count(); + $appointment_ltfu_female = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->where('tbl_appointment.app_status', '=', 'LTFU') + ->where('tbl_client.gender', '=', '2') + ->where('tbl_client.mfl_code', Auth::user()->facility_id) + ->count(); + + // ltfu appointment by age + $appointment_ltfu_to_nine = join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->select(\DB::raw("case when (((year(curdate()) - year(`tbl_client`.`dob`)) > 0) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 9)) then `tbl_client`.`dob` end")) + ->where('tbl_appointment.app_status', '=', 'LTFU') + ->where('tbl_client.mfl_code', Auth::user()->facility_id) + ->count(); + $appointment_ltfu_to_fourteen = join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->select(\DB::raw("case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 10) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 14)) then `tbl_client`.`dob` end")) + ->where('tbl_appointment.app_status', '=', 'LTFU') + ->where('tbl_client.mfl_code', Auth::user()->facility_id) + ->count(); + $appointment_ltfu_to_nineteen = join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->select(\DB::raw("case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 15) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 19)) then `tbl_client`.`dob` end")) + ->where('tbl_appointment.app_status', '=', 'LTFU') + ->where('tbl_client.mfl_code', Auth::user()->facility_id) + ->count(); + $appointment_ltfu_to_twentyfour = join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->select(\DB::raw("case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 20) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 24)) then `tbl_client`.`dob` end")) + ->where('tbl_appointment.app_status', '=', 'LTFU') + ->where('tbl_client.mfl_code', Auth::user()->facility_id) + ->count(); + $appointment_ltfu_to_twentyfive_above = join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->select(\DB::raw("case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 25) then `tbl_client`.`dob` end")) + ->where('tbl_appointment.app_status', '=', 'LTFU') + ->where('tbl_client.mfl_code', Auth::user()->facility_id) + ->count(); + } + if (Auth::user()->access_level == 'Partner') { + // main dashboard all + $appointment_total_missed = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->where('tbl_appointment.date_attended', '!=', 'tbl_appointment.appntmnt_date') + ->where('tbl_client.partner_id', Auth::user()->partner_id) + ->count(); + $appointment_missed = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->where('tbl_appointment.app_status', '=', 'Missed') + ->where('tbl_client.partner_id', Auth::user()->partner_id) + ->count(); + $appointment_defaulted = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->where('tbl_appointment.app_status', '=', 'Defaulted') + ->where('tbl_client.partner_id', Auth::user()->partner_id) + ->count(); + $appointment_lftu = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->where('tbl_appointment.app_status', '=', 'LTFU') + ->where('tbl_client.partner_id', Auth::user()->partner_id) + ->count(); + + // Total missed appointment by gender + $appointment_total_missed_female = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->where('tbl_appointment.date_attended', '!=', 'tbl_appointment.appntmnt_date') + ->where('tbl_client.gender', '=', '1') + ->where('tbl_client.partner_id', Auth::user()->partner_id) + ->count(); + $appointment_total_missed_male = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->where('tbl_appointment.date_attended', '!=', 'tbl_appointment.appntmnt_date') + ->where('tbl_client.gender', '=', '2') + ->where('tbl_client.partner_id', Auth::user()->partner_id) + ->count(); + + // Total missed appointment by age + $appointment_total_missed_to_nine = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select(\DB::raw("case when (((year(curdate()) - year(`tbl_client`.`dob`)) > 0) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 9)) then `tbl_client`.`dob` end")) + ->where('tbl_appointment.date_attended', '!=', 'tbl_appointment.appntmnt_date') + ->where('tbl_client.partner_id', Auth::user()->partner_id) + ->count(); + $appointment_total_missed_to_fourteen = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select(\DB::raw("case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 10) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 14)) then `tbl_client`.`dob` end")) + ->where('tbl_appointment.date_attended', '!=', 'tbl_appointment.appntmnt_date') + ->where('tbl_client.partner_id', Auth::user()->partner_id) + ->count(); + $appointment_total_missed_to_nineteen = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select(\DB::raw("case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 15) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 19)) then `tbl_client`.`dob` end")) + ->where('tbl_appointment.date_attended', '!=', 'tbl_appointment.appntmnt_date') + ->where('tbl_client.partner_id', Auth::user()->partner_id) + ->count(); + $appointment_total_missed_to_twentyfour = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select(\DB::raw("case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 20) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 24)) then `tbl_client`.`dob` end")) + ->where('tbl_appointment.date_attended', '!=', 'tbl_appointment.appntmnt_date') + ->where('tbl_client.partner_id', Auth::user()->partner_id) + ->count(); + $appointment_total_missed_to_twentyfive_above = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select(\DB::raw("case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 25) then `tbl_client`.`dob` end")) + ->where('tbl_appointment.date_attended', '!=', 'tbl_appointment.appntmnt_date') + ->where('tbl_client.partner_id', Auth::user()->partner_id) + ->count(); + + // missed appointment by gender + $appointment_missed_female = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->where('tbl_appointment.app_status', '=', 'Missed') + ->where('tbl_client.gender', '=', '1') + ->where('tbl_client.partner_id', Auth::user()->partner_id) + ->count(); + $appointment_missed_male = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->where('tbl_appointment.app_status', '=', 'Missed') + ->where('tbl_client.gender', '=', '1') + ->where('tbl_client.partner_id', Auth::user()->partner_id) + ->count(); + + // missed appointment by age + $appointment_missed_to_nine = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select(\DB::raw("case when (((year(curdate()) - year(`tbl_client`.`dob`)) > 0) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 9)) then `tbl_client`.`dob` end")) + ->where('tbl_appointment.app_status', '=', 'Missed') + ->where('tbl_client.partner_id', Auth::user()->partner_id) + ->count(); + $appointment_missed_to_fourteen = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select(\DB::raw("case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 10) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 14)) then `tbl_client`.`dob` end")) + ->where('tbl_appointment.app_status', '=', 'Missed') + ->where('tbl_client.partner_id', Auth::user()->partner_id) + ->count(); + $appointment_missed_to_nineteen = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select(\DB::raw("case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 15) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 19)) then `tbl_client`.`dob` end")) + ->where('tbl_appointment.app_status', '=', 'Missed') + ->where('tbl_client.partner_id', Auth::user()->partner_id) + ->count(); + $appointment_missed_to_twentyfour = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select(\DB::raw("case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 20) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 24)) then `tbl_client`.`dob` end")) + ->where('tbl_appointment.app_status', '=', 'Missed') + ->where('tbl_client.partner_id', Auth::user()->partner_id) + ->count(); + $appointment_missed_to_twentyfive_above = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select(\DB::raw("case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 25) then `tbl_client`.`dob` end")) + ->where('tbl_appointment.app_status', '=', 'Missed') + ->where('tbl_client.partner_id', Auth::user()->partner_id) + ->count(); + + // defaulted appointment by gender + $appointment_defaulted_female = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->where('tbl_appointment.app_status', '=', 'Defaulted') + ->where('tbl_client.gender', '=', '1') + ->where('tbl_client.partner_id', Auth::user()->partner_id) + ->count(); + $appointment_defaulted_female = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->where('tbl_appointment.app_status', '=', 'Defaulted') + ->where('tbl_client.gender', '=', '2') + ->where('tbl_client.partner_id', Auth::user()->partner_id) + ->count(); + + // defaulted appointment by age + $appointment_defaulted_to_nine = join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select(\DB::raw("case when (((year(curdate()) - year(`tbl_client`.`dob`)) > 0) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 9)) then `tbl_client`.`dob` end")) + ->where('tbl_appointment.app_status', '=', 'Defaulted') + ->where('tbl_client.partner_id', Auth::user()->partner_id) + ->count(); + $appointment_defaulted_to_fourteen = join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select(\DB::raw("case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 10) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 14)) then `tbl_client`.`dob` end")) + ->where('tbl_appointment.app_status', '=', 'Defaulted') + ->where('tbl_client.partner_id', Auth::user()->partner_id) + ->count(); + $appointment_defaulted_to_nineteen = join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select(\DB::raw("case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 15) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 19)) then `tbl_client`.`dob` end")) + ->where('tbl_appointment.app_status', '=', 'Defaulted') + ->where('tbl_client.partner_id', Auth::user()->partner_id) + ->count(); + $appointment_defaulted_to_twentyfour = join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select(\DB::raw("case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 20) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 24)) then `tbl_client`.`dob` end")) + ->where('tbl_appointment.app_status', '=', 'Defaulted') + ->where('tbl_client.partner_id', Auth::user()->partner_id) + ->count(); + $appointment_defaulted_to_twentyfive_above = join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select(\DB::raw("case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 25) then `tbl_client`.`dob` end")) + ->where('tbl_appointment.app_status', '=', 'Defaulted') + ->where('tbl_client.partner_id', Auth::user()->partner_id) + ->count(); + + // ltfu appointment by gender + $appointment_ltfu_female = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->where('tbl_appointment.app_status', '=', 'LTFU') + ->where('tbl_client.gender', '=', '1') + ->where('tbl_client.partner_id', Auth::user()->partner_id) + ->count(); + $appointment_ltfu_female = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->where('tbl_appointment.app_status', '=', 'LTFU') + ->where('tbl_client.gender', '=', '2') + ->where('tbl_client.partner_id', Auth::user()->partner_id) + ->count(); + + // ltfu appointment by age + $appointment_ltfu_to_nine = join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select(\DB::raw("case when (((year(curdate()) - year(`tbl_client`.`dob`)) > 0) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 9)) then `tbl_client`.`dob` end")) + ->where('tbl_appointment.app_status', '=', 'LTFU') + ->where('tbl_client.partner_id', Auth::user()->partner_id) + ->count(); + $appointment_ltfu_to_fourteen = join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select(\DB::raw("case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 10) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 14)) then `tbl_client`.`dob` end")) + ->where('tbl_appointment.app_status', '=', 'LTFU') + ->where('tbl_client.partner_id', Auth::user()->partner_id) + ->count(); + $appointment_ltfu_to_nineteen = join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select(\DB::raw("case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 15) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 19)) then `tbl_client`.`dob` end")) + ->where('tbl_appointment.app_status', '=', 'LTFU') + ->where('tbl_client.partner_id', Auth::user()->partner_id) + ->count(); + $appointment_ltfu_to_twentyfour = join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select(\DB::raw("case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 20) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 24)) then `tbl_client`.`dob` end")) + ->where('tbl_appointment.app_status', '=', 'LTFU') + ->where('tbl_client.partner_id', Auth::user()->partner_id) + ->count(); + $appointment_ltfu_to_twentyfive_above = join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select(\DB::raw("case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 25) then `tbl_client`.`dob` end")) + ->where('tbl_appointment.app_status', '=', 'LTFU') + ->where('tbl_client.partner_id', Auth::user()->partner_id) + ->count(); + } } } diff --git a/app/Http/Controllers/PartnerController.php b/app/Http/Controllers/PartnerController.php index 11d8e30..1f88d53 100644 --- a/app/Http/Controllers/PartnerController.php +++ b/app/Http/Controllers/PartnerController.php @@ -24,18 +24,19 @@ public function addpartnerform() { $partner_type = PartnerType::all(); return view('partners.addpartner', compact('partner_type')); + } public function addpartner(Request $request) { try { $partner = new Partner; - $validate = Partner::where('phone_no', $request->phone)->first(); + // $validate = Partner::where('phone_no', $request->phone)->first(); - if ($validate) { - Session::flash('statuscode', 'error'); - return redirect('admin/partners/form')->with('status', 'Phone Number is already used in the system!'); - } + // if ($validate) { + // Session::flash('statuscode', 'error'); + // return redirect('admin/partners/form')->with('status', 'Phone Number is already used in the system!'); + // } $partner->name = $request->name; $partner->description = $request->description; diff --git a/app/Http/Controllers/UserController.php b/app/Http/Controllers/UserController.php index 587b3c8..18c7bd4 100644 --- a/app/Http/Controllers/UserController.php +++ b/app/Http/Controllers/UserController.php @@ -53,7 +53,7 @@ public function showUsers() 'tbl_clinic.id as clinic_id' ) ->where('tbl_users.status', '=', 'Active') - ->where('tbl_users.partner_id', Auth::user()->partner_id) + ->where('tbl_users.partner_id', '=', Auth::user()->partner_id) ->get(); } @@ -93,7 +93,6 @@ public function showUsers() ->get(); } $access_level = AccessLevel::all()->where('status', '=', 'Active'); - $partners = Partner::all(); $donors = Donor::all(); $facilities = PartnerFacility::join('tbl_master_facility', 'tbl_partner_facility.mfl_code', '=', 'tbl_master_facility.code') ->select('tbl_partner_facility.id', 'tbl_master_facility.name', 'tbl_partner_facility.mfl_code as code') @@ -104,9 +103,11 @@ public function showUsers() if (Auth::user()->access_level == 'Partner') { $roles = Role::all()->where('status', '=', 'Active') ->where('access_level', '=', 'Facility'); + $partners = Partner::all()->where('status', '=', 'Active')->where('id', Auth::user()->partner_id); } if (Auth::user()->access_level == 'Admin') { $roles = Role::all()->where('status', '=', 'Active'); + $partners = Partner::all()->where('status', '=', 'Active'); } $sub_counties = SubCounty::all(); @@ -135,6 +136,7 @@ public function adduserform(Request $request) $sub_counties = SubCounty::all(); $access_level = AccessLevel::all()->where('status', '=', 'Active'); if (Auth::user()->access_level == 'Partner') { + $partners = Partner::all()->where('status', '=', 'Active')->where('id', Auth::user()->partner_id); $access_level = AccessLevel::all()->where('status', '=', 'Active') // ->where('name', '=', 'Partner') ->where('name', '=', 'Facility'); diff --git a/app/Models/ActiveFacilities.php b/app/Models/ActiveFacilities.php new file mode 100644 index 0000000..9637eff --- /dev/null +++ b/app/Models/ActiveFacilities.php @@ -0,0 +1,18 @@ + + +
--> +@if (Auth::user()->access_level == 'Admin' || Auth::user()->access_level == 'Partner' || Auth::user()->access_level == 'Donor') + + +
+ + + {{ csrf_field() }} +
+
+
+ + +
+
+
+
+ +
+
+
+
+ + +
+
+
+
+ + + +
+
+
+
+ + + +
+
+ +
+
+
+ + +
+ +
+ +
+
+ +
+
+
+
+
+ + +
+
+
+ + + +
+@endif + + + + + + + + + + + + + + + + + + + + + + + + +@endsection \ No newline at end of file diff --git a/resources/views/users/adduser.blade.php b/resources/views/users/adduser.blade.php index f45aa82..5c621a6 100644 --- a/resources/views/users/adduser.blade.php +++ b/resources/views/users/adduser.blade.php @@ -55,6 +55,7 @@
@@ -239,6 +240,7 @@ $('select[name="rolename"]').empty(); + $('select[name="rolename"]').append(''); $.each(data, function(key, value) { $('select[name="rolename"]').append(''); }); diff --git a/routes/web.php b/routes/web.php index f1db35a..b4fabc1 100644 --- a/routes/web.php +++ b/routes/web.php @@ -56,8 +56,8 @@ // Dashboard routes Route::get('/main_graph_dashboard', ['uses' => 'App\Http\Controllers\DashboardController@main_graph_dashboard', 'as' => 'main_graph_dashboard']); - Route::get('/filter_client_dashboard', ['uses'=>'App\Http\Controllers\DashboardController@filter_client_dashboard', 'as' => 'filter_client_dashboard']); - Route::get('/filter_appointment_dashboard', ['uses'=>'App\Http\Controllers\AppointmentController@filter_appointment_dashboard', 'as' => 'filter_appointment_dashboard']); + Route::get('/filter_client_dashboard', ['uses' => 'App\Http\Controllers\DashboardController@filter_client_dashboard', 'as' => 'filter_client_dashboard']); + Route::get('/filter_appointment_dashboard', ['uses' => 'App\Http\Controllers\AppointmentController@filter_appointment_dashboard', 'as' => 'filter_appointment_dashboard']); Route::get('/filter_dashboard', ['uses' => 'App\Http\Controllers\DashboardController@filter_dashboard', 'as' => 'filter_dashboard']); Route::get('/get_dashboard_counties/{id}', ['uses' => 'App\Http\Controllers\DashboardController@get_counties', 'as' => 'get_counties']); Route::get('/get_dashboard_sub_counties/{id}', ['uses' => 'App\Http\Controllers\DashboardController@get_dashboard_sub_counties', 'as' => 'get_dashboard_sub_counties']); @@ -197,6 +197,7 @@ Route::get('/sms/analytics', ['uses' => 'App\Http\Controllers\SMSReportController@success_sms', 'as' => 'sms-analytics']); Route::get('/filter_sms', ['uses' => 'App\Http\Controllers\SMSReportController@filter_sms', 'as' => 'filter_sms']); Route::get('/filters_sms', ['uses' => 'App\Http\Controllers\SMSReportController@filtering_sms', 'as' => 'filtering_sms']); -}); - + // new dashbaord routes + Route::get('/admin/dashboard', ['uses' => 'App\Http\Controllers\NewDashboardController@dashboard', 'as' => 'dashboard']); +}); From a56e74c635bce5eebea0b288cfec9e4e212a4712 Mon Sep 17 00:00:00 2001 From: Ronald-pro <36841157+Ronald-pro@users.noreply.github.com> Date: Fri, 22 Apr 2022 15:54:33 +0300 Subject: [PATCH 025/171] added date filter --- .../Controllers/FinalDashboardController.php | 34 + .../Controllers/NewDashboardController.php | 2335 +++++++++-------- app/Models/AgeDashboard.php | 18 + app/Models/Appointments.php | 4 +- app/Models/Client.php | 9 +- app/Models/GenderDashboard.php | 11 + app/Models/Indicator.php | 18 + app/Models/User.php | 6 + composer.json | 4 +- composer.lock | 242 +- config/app.php | 1 + .../new_dashboard/main_dashbaord.blade.php | 993 ++++++- routes/web.php | 1 + storage/debugbar/.gitignore | 2 + 14 files changed, 2605 insertions(+), 1073 deletions(-) create mode 100644 app/Http/Controllers/FinalDashboardController.php create mode 100644 app/Models/AgeDashboard.php create mode 100644 app/Models/GenderDashboard.php create mode 100644 app/Models/Indicator.php create mode 100644 storage/debugbar/.gitignore diff --git a/app/Http/Controllers/FinalDashboardController.php b/app/Http/Controllers/FinalDashboardController.php new file mode 100644 index 0000000..93eaea1 --- /dev/null +++ b/app/Http/Controllers/FinalDashboardController.php @@ -0,0 +1,34 @@ +where('status', '=', 'Active') + // ->whereNull('hei_no') + // ->pluck('age'); + + // dd($dob); + $tonine = AgeDashboard::select('ToNinenonconsented')->sum('ToNinenonconsented'); + dd(json_encode($tonine)); + } +} diff --git a/app/Http/Controllers/NewDashboardController.php b/app/Http/Controllers/NewDashboardController.php index 9bccda4..7f7c71b 100644 --- a/app/Http/Controllers/NewDashboardController.php +++ b/app/Http/Controllers/NewDashboardController.php @@ -1,8 +1,10 @@ access_level == 'Facility') { - $client = Client::where('status', '=', 'Active') - ->where('mfl_code', Auth::user()->facility_id) - ->count(); - $appointment = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') - ->select('tbl_appointment.id') - ->where('tbl_client.mfl_code', Auth::user()->facility_id) - ->count(); - $missed_appointment = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') - ->select('tbl_appointment.id') - ->where('tbl_appointment.app_status', '!=', 'Booked') - ->orwhere('tbl_appointment.app_status', '!=', 'Notified') - ->where('tbl_client.mfl_code', Auth::user()->facility_id) - ->count(); + } if (Auth::user()->access_level == 'Partner') { - $client = Client::join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') - ->where('tbl_client.status', '=', 'Active') - ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) - ->count(); - $appointment = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') - ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') - ->select('tbl_appointment.id') - ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) - ->count(); - $missed_appointment = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') - ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') - ->select('tbl_appointment.id') - ->where('tbl_appointment.app_status', '!=', 'Booked') - ->orwhere('tbl_appointment.app_status', '!=', 'Notified') - ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) - ->count(); + } if (Auth::user()->access_level == 'Admin' || Auth::user()->access_level == 'Donor') { + $all_partners = Partner::where('status', '=', 'Active')->pluck('name', 'id'); - $client = Client::where('status', '=', 'Active') + $client = Client::select('id')->where('status', '=', 'Active') ->whereNull('hei_no') ->count(); + + $indicator = Indicator::all(); $appointment = Appointments::select('id') ->count(); - $missed_appointment = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') - ->where('tbl_appointment.app_status', '=', 'Missed') - ->orwhere('tbl_appointment.app_status', '=', 'LTFU') - ->orwhere('tbl_appointment.app_status', '=', 'Defaulted') + + + $missed_appointment = Appointments::select('id') + ->where('app_status', '=', 'Missed') + ->orwhere('app_status', '=', 'LTFU') + ->orwhere('app_status', '=', 'Defaulted') ->count(); + // dd($missed_appointment); $active_facilities = PartnerFacility::join('tbl_client', 'tbl_partner_facility.mfl_code', '=', 'tbl_client.mfl_code') ->join('tbl_appointment', 'tbl_client.id', '=', 'tbl_appointment.client_id') - ->where() - ->count(); + ->select(\DB::raw('COUNT(tbl_partner_facility.mfl_code) as facilities')) + ->where('tbl_appointment.created_at', '>=', Carbon::now()->subMonths(6)) + ->orderBy('tbl_appointment.created_at', 'DESC') + ->groupBy('tbl_partner_facility.mfl_code') + ->get(); + + + // dd($active_facilities); // active clients by gender - $clients_male = Client::where('gender', '=', '2') - ->where('status', '=', 'Active') + $clients_male = Client::select('id')->where([['gender', '=', '2'], ['status', '=', 'Active'],]) ->whereNull('hei_no') ->count(); @@ -86,1317 +74,1580 @@ public function dashboard() ->whereNull('hei_no') ->count(); - // active clients by age distribution - $client_to_nine = Client::select(\DB::raw("count((case when (((year(curdate()) - year(`dob`)) > 0) and ((year(curdate()) - year(`dob`)) <= 9)) then `dob` end)) AS count")) + $client_to_nine = Cache::remember('client-nine', 10, function () { + return Client::select(\DB::raw("count((case when (((year(curdate()) - year(`dob`)) > 0) and ((year(curdate()) - year(`dob`)) <= 9)) then `dob` end)) AS count")) ->where('status', '=', 'Active') ->whereNull('hei_no') ->pluck('count'); - $client_to_fourteen = Client::select(\DB::raw("count((case when (((year(curdate()) - year(`dob`)) >= 10) and ((year(curdate()) - year(`dob`)) <= 14)) then `dob` end)) AS count")) + }); + + $client_to_fourteen = Cache::remember('client-fourteen', 10, function () { + return Client::select(\DB::raw("count((case when (((year(curdate()) - year(`dob`)) >= 10) and ((year(curdate()) - year(`dob`)) <= 14)) then `dob` end)) AS count")) ->where('status', '=', 'Active') ->whereNull('hei_no') ->pluck('count'); + }); - $client_to_nineteen = Client::select(\DB::raw("count((case when (((year(curdate()) - year(`dob`)) >= 15) and ((year(curdate()) - year(`dob`)) <= 19)) then `dob` end)) AS count")) + $client_to_nineteen = Cache::remember('client-nineteen', 10, function () { + return Client::select(\DB::raw("count((case when (((year(curdate()) - year(`dob`)) >= 15) and ((year(curdate()) - year(`dob`)) <= 19)) then `dob` end)) AS count")) ->where('status', '=', 'Active') ->whereNull('hei_no') ->pluck('count'); + }); - $client_to_twentyfour = Client::select(\DB::raw("count((case when (((year(curdate()) - year(`dob`)) >= 20) and ((year(curdate()) - year(`dob`)) <= 24)) then `id` end)) AS count")) + $client_to_twentyfour = Cache::remember('client-twentyfour', 10, function () { + return Client::select(\DB::raw("count((case when (((year(curdate()) - year(`dob`)) >= 20) and ((year(curdate()) - year(`dob`)) <= 24)) then `id` end)) AS count")) ->where('status', '=', 'Active') ->whereNull('hei_no') ->pluck('count'); + }); - $client_to_twentyfive_above = Client::select(\DB::raw("count((case when (((year(curdate()) - year(`dob`)) >= 25)) then `id` end)) AS count")) + $client_to_twentyfive_above = Cache::remember('client-twentyfive-above', 10, function () { + return Client::select(\DB::raw("count((case when (((year(curdate()) - year(`dob`)) >= 25)) then `id` end)) AS count")) ->where('status', '=', 'Active') ->whereNull('hei_no') ->pluck('count'); - $client_unknown_age = Client::where('dob', '=', '') + }); + + $client_unknown_age = Cache::remember('client-unknown-age', 10, function () { + return Client::where('dob', '=', '') ->orWhereNull('dob') ->where('status', '=', 'Active') ->whereNull('hei_no') ->count(); + }); // appointment by gender - $appointment_male = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + $appointment_male = Cache::remember('appointment-male', 10, function () { + return Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') ->select('tbl_appointment.id') ->where('tbl_client.gender', '=', '2') ->count(); - $appointment_female = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + }); + $appointment_female = Cache::remember('appointment-female', 10, function () { + return Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') ->select('tbl_appointment.id') ->where('tbl_client.gender', '=', '1') ->count(); - $appointment_uknown_gender = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + }); + $appointment_uknown_gender = Cache::remember('appointment-uknown-gender', 10, function () { + return Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') ->select('tbl_appointment.id') ->where('tbl_client.gender', '!=', '1') ->where('tbl_client.gender', '!=', '2') ->count(); + }); // appointment by age - $appointment_to_nine = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + $appointment_to_nine = Cache::remember('appointment-to-nine', 10, function () { + return Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) > 0) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 9)) then `tbl_client`.`id` end)) AS count")) ->pluck('count'); - $appointment_to_fourteen = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + }); + $appointment_to_fourteen = Cache::remember('appointment-to-fourteen', 10, function () { + return Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 10) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 14)) then `tbl_client`.`id` end)) AS count")) ->pluck('count'); - $appointment_to_nineteen = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + }); + $appointment_to_nineteen = Cache::remember('appointment-to-nineteen', 10, function () { + return Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 15) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 19)) then `tbl_client`.`id` end)) AS count")) ->pluck('count'); - $appointment_to_twentyfour = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + }); + $appointment_to_twentyfour = Cache::remember('appointment-to-twentyfour', 10, function () { + return Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 20) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 24)) then `tbl_client`.`id` end)) AS count")) ->pluck('count'); - $appointment_to_twentyfive_above = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + }); + $appointment_to_twentyfive_above = Cache::remember('appointment-to-twentyfive-above', 10, function () { + return Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 25)) then `tbl_client`.`id` end)) AS count")) ->pluck('count'); - $appointment_uknown_age = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + }); + $appointment_uknown_age = Cache::remember('appointment-uknown-age', 10, function () { + return Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') ->where('tbl_client.dob', '=', '') ->orWhereNull('tbl_client.dob') ->count(); + }); // Total missed appointment by gender - $appointment_total_missed_female = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + $appointment_total_missed_female = Cache::remember('appointment-total-missed-female', 10, function () { + return Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->where('tbl_client.gender', '=', '1') ->where('tbl_appointment.app_status', '=', 'Missed') ->orwhere('tbl_appointment.app_status', '=', 'LTFU') ->orwhere('tbl_appointment.app_status', '=', 'Defaulted') - ->where('tbl_client.gender', '=', '1') ->count(); - $appointment_total_missed_male = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + }); + $appointment_total_missed_male = Cache::remember('appointment-total-missed-male', 10, function () { + return Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->where('tbl_client.gender', '=', '2') ->where('tbl_appointment.app_status', '=', 'Missed') ->orwhere('tbl_appointment.app_status', '=', 'LTFU') ->orwhere('tbl_appointment.app_status', '=', 'Defaulted') - ->where('tbl_client.gender', '=', '2') ->count(); - $appointment_total_missed_uknown_gender = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + }); + $appointment_total_missed_uknown_gender = Cache::remember('appointment-total-missed-uknown-gender', 10, function () { + return Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->where('tbl_client.gender', '!=', '1') + ->where('tbl_client.gender', '!=', '2') ->where('tbl_appointment.app_status', '=', 'Missed') ->orwhere('tbl_appointment.app_status', '=', 'LTFU') ->orwhere('tbl_appointment.app_status', '=', 'Defaulted') - ->where('tbl_client.gender', '!=', '1') - ->where('tbl_client.gender', '!=', '2') ->count(); + }); // Total missed appointment by age - $appointment_total_missed_to_nine = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + $appointment_total_missed_to_nine = Cache::remember('appointment-total-missed-to-nine', 10, function () { + return Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) > 0) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 9)) then `tbl_client`.`id` end)) AS count")) ->where('tbl_appointment.app_status', '=', 'Missed') ->orwhere('tbl_appointment.app_status', '=', 'LTFU') ->orwhere('tbl_appointment.app_status', '=', 'Defaulted') ->pluck('count'); - $appointment_total_missed_to_fourteen = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + }); + $appointment_total_missed_to_fourteen = Cache::remember('appointment-total-missed-to-fourteen', 10, function () { + return Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 10) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 14)) then `tbl_client`.`id` end)) AS count")) ->where('tbl_appointment.app_status', '=', 'Missed') ->orwhere('tbl_appointment.app_status', '=', 'LTFU') ->orwhere('tbl_appointment.app_status', '=', 'Defaulted') ->pluck('count'); - $appointment_total_missed_to_nineteen = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + }); + $appointment_total_missed_to_nineteen = Cache::remember('appointment-total-missed-to-nineteen', 10, function () { + return Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 15) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 19)) then `tbl_client`.`id` end)) AS count")) ->where('tbl_appointment.date_attended', '!=', 'tbl_appointment.appntmnt_date') ->pluck('count'); - $appointment_total_missed_to_twentyfour = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + }); + $appointment_total_missed_to_twentyfour = Cache::remember('appointment-total-missed-to-twentyfour', 10, function () { + return Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 20) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 24)) then `tbl_client`.`id` end)) AS count")) ->where('tbl_appointment.date_attended', '!=', 'tbl_appointment.appntmnt_date') ->pluck('count'); - $appointment_total_missed_to_twentyfive_above = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + }); + $appointment_total_missed_to_twentyfive_above = Cache::remember('appointment-total-missed-to-twentyfive_above', 10, function () { + return Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 25)) then `tbl_client`.`id` end)) AS count")) ->where('tbl_appointment.app_status', '=', 'Missed') ->orwhere('tbl_appointment.app_status', '=', 'LTFU') ->orwhere('tbl_appointment.app_status', '=', 'Defaulted') ->pluck('count'); - $appointment_total_missed_uknown_age = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + }); + $appointment_total_missed_uknown_age = Cache::remember('appointment-total-missed-uknown-age', 10, function () { + return Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') ->where('tbl_client.dob', '=', '') ->orWhereNull('tbl_client.dob') ->where('tbl_appointment.app_status', '=', 'Missed') ->orwhere('tbl_appointment.app_status', '=', 'LTFU') ->orwhere('tbl_appointment.app_status', '=', 'Defaulted') ->count(); - } - - - // dd($active_facilities); - - return view('new_dashboard.main_dashbaord', compact('all_partners', 'client', 'appointment', 'missed_appointment', 'clients_male', 'clients_female', 'unknown_gender', 'client_to_nine', 'client_to_fourteen', 'client_to_nineteen', 'client_to_twentyfour', 'client_to_twentyfive_above', 'client_unknown_age', 'appointment_male', 'appointment_female', 'appointment_uknown_gender', 'appointment_to_nine', 'appointment_to_fourteen', 'appointment_to_nineteen', 'appointment_to_twentyfour', 'appointment_to_twentyfive_above', 'appointment_uknown_age', 'appointment_total_missed_female', 'appointment_total_missed_male', 'appointment_total_missed_uknown_gender', 'appointment_total_missed_to_nine', 'appointment_total_missed_to_fourteen', 'appointment_total_missed_to_nineteen', 'appointment_total_missed_to_twentyfour', 'appointment_total_missed_to_twentyfive_above', 'appointment_total_missed_uknown_age')); - } - - public function client_charts() - { - - if (Auth::user()->access_level == 'Admin' || Auth::user()->access_level == 'Donor') { - // active clients by gender - $clients_male = Client::where('gender', '=', '2') + }); + // client charts + $client_consented = Cache::remember('client-consented', 10, function () { + return Client::select('smsenable') ->where('status', '=', 'Active') + ->whereNull('hei_no') + ->where('smsenable', '=', 'Yes') ->count(); - - $clients_female = Client::where('gender', '=', '1') + }); + $client_nonconsented = Cache::remember('client-nonconsented', 10, function () { + return Client::select('smsenable') ->where('status', '=', 'Active') + ->whereNull('hei_no') + ->where('smsenable', '!=', 'Yes') ->count(); + }); + // consented clients by gender - // active clients by age distribution - $client_to_nine = Client::select(\DB::raw("case when (((year(curdate()) - year(`dob`)) > 0) and ((year(curdate()) - year(`dob`)) <= 9)) then `dob` end")) + $client_consented_male = Cache::remember('client-consented-male', 10, function () { + return Client::where('smsenable', '=', 'Yes') ->where('status', '=', 'Active') + ->whereNull('hei_no') + ->where('gender', '=', '2') ->count(); - - $client_to_nineteen = Client::select(\DB::raw("case when (((year(curdate()) - year(`dob`)) >= 10) and ((year(curdate()) - year(`dob`)) <= 19)) then `dob` end")) + }); + $client_consented_female = Cache::remember('client-consented-female', 10, function () { + return Client::where('smsenable', '=', 'Yes') ->where('status', '=', 'Active') + ->whereNull('hei_no') + ->where('gender', '=', '1') ->count(); - - $client_to_twentyfour = Client::select(\DB::raw("case when (((year(curdate()) - year(`dob`)) >= 20) and ((year(curdate()) - year(`dob`)) <= 24)) then `dob` end")) + }); + $client_consented_uknown_gender = Cache::remember('client-consented-uknown-gender', 10, function () { + return Client::where('smsenable', '=', 'Yes') ->where('status', '=', 'Active') + ->whereNull('hei_no') + ->where('gender', '!=', '1') + ->where('gender', '!=', '2') ->count(); - - $client_to_twentyfive_above = Client::select(\DB::raw("case when (((year(curdate()) - year(`dob`)) >= 25) then `dob` end")) + }); + // non consented clients by gender + $client_nonconsented_male = Cache::remember('client-nonconsented-male', 10, function () { + return Client::where('smsenable', '!=', 'Yes') ->where('status', '=', 'Active') - ->count(); - // consented clients by gender - - $client_consented_male = Client::where('smsenable', '=', 'Yes') + ->whereNull('hei_no') ->where('gender', '=', '2') ->count(); - $client_consented_female = Client::where('smsenable', '=', 'Yes') + }); + $client_nonconsented_female = Cache::remember('client-nonconsented-female', 10, function () { + return Client::where('smsenable', '!=', 'Yes') + ->where('status', '=', 'Active') + ->whereNull('hei_no') ->where('gender', '=', '1') ->count(); - // non consented clients by gender - $client_nonconsented_male = Client::where('smsenable', '!=', 'Yes') - ->where('gender', '=', '2') - ->count(); - $client_nonconsented_female = Client::where('smsenable', '!=', 'Yes') - ->where('gender', '=', '1') + }); + $client_nonconsented_uknown_gender = Cache::remember('client-nonconsented-uknown-gender', 10, function () { + return Client::where('smsenable', '!=', 'Yes') + ->where('gender', '!=', '1') + ->where('gender', '!=', '2') ->count(); + }); // consented clients by age distribution - $client_consented_to_nine = Client::select(\DB::raw("case when (((year(curdate()) - year(`dob`)) > 0) and ((year(curdate()) - year(`dob`)) <= 9)) then `dob` end")) + $client_consented_to_nine = Cache::remember('client-consented-to-nine', 10, function () { + return Client::select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) > 0) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 9)) then `tbl_client`.`id` end)) AS count")) ->where('smsenable', '=', 'Yes') - ->count(); - $client_consented_to_nineteen = Client::select(\DB::raw("case when (((year(curdate()) - year(`dob`)) >= 10) and ((year(curdate()) - year(`dob`)) <= 19)) then `dob` end")) + ->where('status', '=', 'Active') + ->whereNull('hei_no') + ->pluck('count'); + }); + $client_consented_to_fourteen = Cache::remember('tbl-client', 10, function () { + return Client::select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 10) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 14)) then `tbl_client`.`id` end)) AS count")) ->where('smsenable', '=', 'Yes') - ->count(); - $client_consented_to_twentyfour = Client::select(\DB::raw("case when (((year(curdate()) - year(`dob`)) >= 20) and ((year(curdate()) - year(`dob`)) <= 24)) then `dob` end")) + ->where('status', '=', 'Active') + ->whereNull('hei_no') + ->pluck('count'); + }); + $client_consented_to_nineteen = Cache::remember('client-consented-to-nineteen', 10, function () { + return Client::select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 15) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 19)) then `tbl_client`.`id` end)) AS count")) ->where('smsenable', '=', 'Yes') - ->count(); - $client_consented_to_twentyfive_above = Client::select(\DB::raw("case when ((year(curdate()) - year(`dob`)) >= 25) then `dob` end")) + ->where('status', '=', 'Active') + ->whereNull('hei_no') + ->pluck('count'); + }); + $client_consented_to_twentyfour = Cache::remember('client-consented-to-twentyfour', 10, function () { + return Client::select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 20) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 24)) then `tbl_client`.`id` end)) AS count")) + ->where('smsenable', '=', 'Yes') + ->where('status', '=', 'Active') + ->whereNull('hei_no') + ->pluck('count'); + }); + $client_consented_to_twentyfive_above = Cache::remember('client-consented-to-twentyfive-above', 10, function () { + return Client::select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 25)) then `tbl_client`.`id` end)) AS count")) + ->where('smsenable', '=', 'Yes') + ->where('status', '=', 'Active') + ->whereNull('hei_no') + ->pluck('count'); + }); + $client_consented_uknown_age = Cache::remember('client-consented-uknown-age', 10, function () { + return Client::select('smsenable') + ->where('dob', '=', '') + ->where('status', '=', 'Active') + ->whereNull('hei_no') + ->orWhereNull('dob') ->where('smsenable', '=', 'Yes') ->count(); + }); // non consented clients by age distribution - $client_nonconsented_to_nine = Client::select(\DB::raw("case when (((year(curdate()) - year(`dob`)) > 0) and ((year(curdate()) - year(`dob`)) <= 9)) then `dob` end")) - ->where('smsenable', '!=', 'Yes') - ->count(); - $client_nonconsented_to_nineteen = Client::select(\DB::raw("case when (((year(curdate()) - year(`dob`)) >= 10) and ((year(curdate()) - year(`dob`)) <= 19)) then `dob` end")) + $client_nonconsented_to_nine = Cache::remember('client-nonconsented-to-nine', 10, function () { + return Client::select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) > 0) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 9)) then `tbl_client`.`id` end)) AS count")) ->where('smsenable', '!=', 'Yes') - ->count(); - $client_nonconsented_to_twentyfour = Client::select(\DB::raw("case when (((year(curdate()) - year(`dob`)) >= 20) and ((year(curdate()) - year(`dob`)) <= 24)) then `dob` end")) - ->where('smsenable', '!=', 'Yes') - ->count(); - $client_nonconsented_to_twentyfive_above = Client::select(\DB::raw("case when ((year(curdate()) - year(`dob`)) >= 25) then `dob` end")) + ->where('status', '=', 'Active') + ->whereNull('hei_no') + ->pluck('count'); + }); + $client_nonconsented_to_fourteen = Cache::remember('client-nonconsented-to-fourteen', 10, function () { + return Client::select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 10) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 14)) then `tbl_client`.`id` end)) AS count")) ->where('smsenable', '!=', 'Yes') - ->count(); - } - if (Auth::user()->access_level == 'Facility') { - $clients_male = Client::where('gender', '=', '2') ->where('status', '=', 'Active') - ->where('mfl_code', Auth::user()->facility_id) - ->count(); - - $clients_female = Client::where('gender', '=', '1') + ->whereNull('hei_no') + ->pluck('count'); + }); + $client_nonconsented_to_nineteen = Cache::remember('client-nonconsented-to-nineteen', 10, function () { + return Client::select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 15) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 19)) then `tbl_client`.`id` end)) AS count")) + ->where('smsenable', '!=', 'Yes') ->where('status', '=', 'Active') - ->where('mfl_code', Auth::user()->facility_id) - ->count(); - // active clients by age distribution - - $client_to_nine = Client::select(\DB::raw("case when (((year(curdate()) - year(`dob`)) > 0) and ((year(curdate()) - year(`dob`)) <= 9)) then `dob` end")) + ->whereNull('hei_no') + ->pluck('count'); + }); + $client_nonconsented_to_twentyfour = Cache::remember('client-nonconsented-to-twentyfour', 10, function () { + return Client::select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 20) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 24)) then `tbl_client`.`id` end)) AS count")) + ->where('smsenable', '!=', 'Yes') ->where('status', '=', 'Active') - ->where('mfl_code', Auth::user()->facility_id) - ->count(); - - $client_to_nineteen = Client::select(\DB::raw("case when (((year(curdate()) - year(`dob`)) >= 10) and ((year(curdate()) - year(`dob`)) <= 19)) then `dob` end")) + ->whereNull('hei_no') + ->pluck('count'); + }); + $client_nonconsented_to_twentyfive_above = Cache::remember('client-nonconsented-to-twentyfive-above', 10, function () { + return Client::select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 25)) then `tbl_client`.`id` end)) AS count")) + ->where('smsenable', '!=', 'Yes') ->where('status', '=', 'Active') - ->where('mfl_code', Auth::user()->facility_id) - ->count(); - - $client_to_twentyfour = Client::select(\DB::raw("case when (((year(curdate()) - year(`dob`)) >= 20) and ((year(curdate()) - year(`dob`)) <= 24)) then `dob` end")) + ->whereNull('hei_no') + ->pluck('count'); + }); + $client_nonconsented_uknown_age = Cache::remember('client-nonconsented-uknown-age', 10, function () { + return Client::select('smsenable') ->where('status', '=', 'Active') - ->where('mfl_code', Auth::user()->facility_id) + ->whereNull('hei_no') + ->where('dob', '=', '') + ->orWhereNull('dob') + ->where('smsenable', '!=', 'Yes') ->count(); + }); - $client_to_twentyfive_above = Client::select(\DB::raw("case when (((year(curdate()) - year(`dob`)) >= 25) then `dob` end")) - ->where('status', '=', 'Active') - ->where('mfl_code', Auth::user()->facility_id) + // main appointments + $appointment_honoured = Cache::remember('appointment-honoured', 10, function () { + return Appointments::select('id')->where('appntmnt_date', '=', 'date_attended') + ->count(); + }); + // dd($appointment_honoured); + $appointment_not_honoured = Cache::remember('appointment-not-honoured', 10, function () { + return Appointments::select('id') + ->where('tbl_appointment.app_status', '=', 'Missed') + ->orwhere('tbl_appointment.app_status', '=', 'LTFU') + ->orwhere('tbl_appointment.app_status', '=', 'Defaulted') ->count(); + }); - // consented clients by gender - $client_consented_male = Client::where('smsenable', '=', 'Yes') - ->where('gender', '=', '2') - ->where('mfl_code', Auth::user()->facility_id) - ->count(); - $client_consented_female = Client::where('smsenable', '=', 'Yes') - ->where('gender', '=', '1') - ->where('mfl_code', Auth::user()->facility_id) - ->count(); - // non consented clients by gender - $client_nonconsented_male = Client::where('smsenable', '!=', 'Yes') - ->where('gender', '=', '2') - ->where('mfl_code', Auth::user()->facility_id) - ->count(); - $client_nonconsented_female = Client::where('smsenable', '!=', 'Yes') - ->where('gender', '=', '1') - ->where('mfl_code', Auth::user()->facility_id) - ->count(); - // consented clients by age distribution - $client_consented_to_nine = Client::select(\DB::raw("case when (((year(curdate()) - year(`dob`)) > 0) and ((year(curdate()) - year(`dob`)) <= 9)) then `dob` end")) - ->where('smsenable', '=', 'Yes') - ->where('mfl_code', Auth::user()->facility_id) - ->count(); - $client_consented_to_nineteen = Client::select(\DB::raw("case when (((year(curdate()) - year(`dob`)) >= 10) and ((year(curdate()) - year(`dob`)) <= 19)) then `dob` end")) - ->where('smsenable', '=', 'Yes') - ->where('mfl_code', Auth::user()->facility_id) - ->count(); - $client_consented_to_twentyfour = Client::select(\DB::raw("case when (((year(curdate()) - year(`dob`)) >= 20) and ((year(curdate()) - year(`dob`)) <= 24)) then `dob` end")) - ->where('smsenable', '=', 'Yes') - ->where('mfl_code', Auth::user()->facility_id) - ->count(); - $client_consented_to_twentyfive_above = Client::select(\DB::raw("case when ((year(curdate()) - year(`dob`)) >= 25) then `dob` end")) - ->where('smsenable', '=', 'Yes') - ->where('mfl_code', Auth::user()->facility_id) - ->count(); - // non consented clients by age distribution - $client_nonconsented_to_nine = Client::select(\DB::raw("case when (((year(curdate()) - year(`dob`)) > 0) and ((year(curdate()) - year(`dob`)) <= 9)) then `dob` end")) - ->where('smsenable', '!=', 'Yes') - ->where('mfl_code', Auth::user()->facility_id) - ->count(); - $client_nonconsented_to_nineteen = Client::select(\DB::raw("case when (((year(curdate()) - year(`dob`)) >= 10) and ((year(curdate()) - year(`dob`)) <= 19)) then `dob` end")) - ->where('smsenable', '!=', 'Yes') - ->where('mfl_code', Auth::user()->facility_id) - ->count(); - $client_nonconsented_to_twentyfour = Client::select(\DB::raw("case when (((year(curdate()) - year(`dob`)) >= 20) and ((year(curdate()) - year(`dob`)) <= 24)) then `dob` end")) - ->where('smsenable', '!=', 'Yes') - ->where('mfl_code', Auth::user()->facility_id) - ->count(); - $client_nonconsented_to_twentyfive_above = Client::select(\DB::raw("case when ((year(curdate()) - year(`dob`)) >= 25) then `dob` end")) - ->where('smsenable', '!=', 'Yes') - ->where('mfl_code', Auth::user()->facility_id) - ->count(); - } - if (Auth::user()->access_level == 'Partner') { - $clients_male = Client::join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + // appointment honored by gender + $appointment_honoured_male = Cache::remember('appointment-honoured-male', 10, function () { + return Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') ->where('tbl_client.gender', '=', '2') - ->where('tbl_client.status', '=', 'Active') - ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) + ->where('tbl_appointment.date_attended', '=', 'tbl_appointment.appntmnt_date') ->count(); - - $clients_female = Client::join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + }); + $appointment_honoured_female = Cache::remember('appointment-honoured-female', 10, function () { + return Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') ->where('tbl_client.gender', '=', '1') - ->where('tbl_client.status', '=', 'Active') - ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) - ->count(); - // active clients by age distribution - - $client_to_nine = Client::join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') - ->select(\DB::raw("case when (((year(curdate()) - year(`tbl_client`.`dob`)) > 0) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 9)) then `tbl_client`.`dob` end")) - ->where('tbl_client.status', '=', 'Active') - ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) - ->count(); - - $client_to_nineteen = Client::join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') - ->select(\DB::raw("case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 10) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 19)) then `tbl_client`.`dob` end")) - ->where('tbl_client.status', '=', 'Active') - ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) + ->where('tbl_appointment.date_attended', '=', 'tbl_appointment.appntmnt_date') ->count(); - - $client_to_twentyfour = Client::join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') - ->select(\DB::raw("case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 20) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 24)) then `tbl_client`.`dob` end")) - ->where('tbl_client.status', '=', 'Active') - ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) + }); + $appointment_honoured_uknown_gender = Cache::remember('appointment-honoured-uknown-gender', 10, function () { + return Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->where('tbl_client.gender', '!=', '1') + ->where('tbl_client.gender', '!=', '2') + ->where('tbl_appointment.date_attended', '=', 'tbl_appointment.appntmnt_date') ->count(); - - $client_to_twentyfive_above = Client::join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') - ->select(\DB::raw("case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 25) then `tbl_client`.`dob` end")) - ->where('tbl_client.status', '=', 'Active') - ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) + }); + // appointment honored by age + $appointment_honored_to_nine = Cache::remember('appointment-honored-to-nine', 10, function () { + return Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) > 0) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 9)) then `tbl_client`.`id` end)) AS count")) + ->where('tbl_appointment.date_attended', '=', 'tbl_appointment.appntmnt_date') + ->pluck('count'); + }); + $appointment_honored_to_fourteen = Cache::remember('appointment-honored-to-fourteen', 10, function () { + return Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 10) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 14)) then `tbl_client`.`id` end)) AS count")) + ->where('tbl_appointment.date_attended', '=', 'tbl_appointment.appntmnt_date') + ->pluck('count'); + }); + $appointment_honored_to_nineteen = Cache::remember('appointment-honored-to-nineteen', 10, function () { + return Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 15) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 19)) then `tbl_client`.`id` end)) AS count")) + ->where('tbl_appointment.date_attended', '=', 'tbl_appointment.appntmnt_date') + ->pluck('count'); + }); + $appointment_honored_to_twentyfour = Cache::remember('appointment-honored-to-twentyfour', 10, function () { + return Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 20) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 24)) then `tbl_client`.`id` end)) AS count")) + ->where('tbl_appointment.date_attended', '=', 'tbl_appointment.appntmnt_date') + ->pluck('count'); + }); + $appointment_honored_to_twentyfive_above = Cache::remember('appointment-honored-to-twentyfive_above', 10, function () { + return Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 25)) then `tbl_client`.`id` end)) AS count")) + ->where('tbl_appointment.date_attended', '=', 'tbl_appointment.appntmnt_date') + ->pluck('count'); + }); + $appointment_honored_to_uknown_age = Cache::remember('appointment_honored-to-uknown-age', 10, function () { + return Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->select('tbl_client.dob') + ->where('tbl_client.dob', '=', '') + ->orWhereNull('tbl_client.dob') + ->where('tbl_appointment.date_attended', '=', 'tbl_appointment.appntmnt_date') ->count(); - // consented clients by gender + }); - $client_consented_male = Client::join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') - ->where('tbl_client.smsenable', '=', 'Yes') - ->where('gender', '=', '2') - ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) - ->count(); - $client_consented_female = Client::join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') - ->where('tbl_client.smsenable', '=', 'Yes') - ->where('gender', '=', '1') - ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) + // appointment not honored by gender + $appointment_not_honoured_male = Cache::remember('appointment-not-honoured-male', 10, function () { + return Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->where('tbl_client.gender', '=', '2') + ->where('tbl_appointment.app_status', '=', 'Missed') + ->orwhere('tbl_appointment.app_status', '=', 'LTFU') + ->orwhere('tbl_appointment.app_status', '=', 'Defaulted') ->count(); - // non consented clients by gender - $client_nonconsented_male = Client::join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') - ->where('tbl_client.smsenable', '!=', 'Yes') - ->where('gender', '=', '2') - ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) + }); + $appointment_not_honoured_female = Cache::remember('appointment-not-honoured-female', 10, function () { + return Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->where('tbl_client.gender', '=', '1') + ->where('tbl_appointment.app_status', '=', 'Missed') + ->orwhere('tbl_appointment.app_status', '=', 'LTFU') + ->orwhere('tbl_appointment.app_status', '=', 'Defaulted') ->count(); - $client_nonconsented_female = Client::join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') - ->where('tbl_client.smsenable', '!=', 'Yes') - ->where('gender', '=', '1') - ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) + }); + $appointment_not_honoured_uknown_gender = Cache::remember('appointment-not-honoured-uknown-gender', 10, function () { + return Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->where('tbl_client.gender', '!=', '1') + ->where('tbl_client.gender', '!=', '2') + ->where('tbl_appointment.app_status', '=', 'Missed') + ->orwhere('tbl_appointment.app_status', '=', 'LTFU') + ->orwhere('tbl_appointment.app_status', '=', 'Defaulted') ->count(); - // consented clients by age distribution - $client_consented_to_nine = Client::join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') - ->select(\DB::raw("case when (((year(curdate()) - year(`tbl_client`.`dob`)) > 0) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 9)) then `tbl_client`.`dob` end")) - ->where('tbl_client.smsenable', '=', 'Yes') - ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) - ->count(); - $client_consented_to_nineteen = Client::join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') - ->select(\DB::raw("case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 10) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 19)) then `tbl_client`.`dob` end")) - ->where('tbl_client.smsenable', '=', 'Yes') - ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) - ->count(); - $client_consented_to_twentyfour = Client::join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') - ->select(\DB::raw("case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 20) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 24)) then `tbl_client`.`dob` end")) - ->where('tbl_client.smsenable', '=', 'Yes') - ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) - ->count(); - $client_consented_to_twentyfive_above = Client::join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') - ->select(\DB::raw("case when ((year(curdate()) - year(`tbl_client`.`dob`)) >= 25) then `tbl_client`.`dob` end")) - ->where('tbl_client.smsenable', '=', 'Yes') - ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) - ->count(); - // non consented clients by age distribution - $client_nonconsented_to_nine = Client::join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') - ->select(\DB::raw("case when (((year(curdate()) - year(`tbl_client`.`dob`)) > 0) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 9)) then `tbl_client`.`dob` end")) - ->where('tbl_client.smsenable', '!=', 'Yes') - ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) - ->count(); - $client_nonconsented_to_nineteen = Client::join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') - ->select(\DB::raw("case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 10) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 19)) then `tbl_client`.`dob` end")) - ->where('tbl_client.smsenable', '!=', 'Yes') - ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) - ->count(); - $client_nonconsented_to_twentyfour = Client::join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') - ->select(\DB::raw("case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 20) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 24)) then `tbl_client`.`dob` end")) - ->where('tbl_client.smsenable', '!=', 'Yes') - ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) - ->count(); - $client_nonconsented_to_twentyfive_above = Client::join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') - ->select(\DB::raw("case when ((year(curdate()) - year(`tbl_client`.`dob`)) >= 25) then `tbl_client`.`dob` end")) - ->where('tbl_client.smsenable', '!=', 'Yes') - ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) + }); + // appointment not honored by age + $appointment_not_honored_to_nine = Cache::remember('appointment-not-honored-to-nine', 10, function () { + return Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) > 0) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 9)) then `tbl_client`.`id` end)) AS count")) + ->where('tbl_appointment.app_status', '=', 'Missed') + ->orwhere('tbl_appointment.app_status', '=', 'LTFU') + ->orwhere('tbl_appointment.app_status', '=', 'Defaulted') + ->pluck('count'); + }); + $appointment_not_honored_to_fourteen = Cache::remember('appointment-not-honored-to-fourteen', 10, function () { + return Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 10) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 14)) then `tbl_client`.`id` end)) AS count")) + ->where('tbl_appointment.app_status', '=', 'Missed') + ->orwhere('tbl_appointment.app_status', '=', 'LTFU') + ->orwhere('tbl_appointment.app_status', '=', 'Defaulted') + ->pluck('count'); + }); + $appointment_not_honored_to_nineteen = Cache::remember('appointment_not_honored_to_nineteen', 10, function () { + return Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 15) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 19)) then `tbl_client`.`id` end)) AS count")) + ->where('tbl_appointment.app_status', '=', 'Missed') + ->orwhere('tbl_appointment.app_status', '=', 'LTFU') + ->orwhere('tbl_appointment.app_status', '=', 'Defaulted') + ->pluck('count'); + }); + $appointment_not_honored_to_twentyfour = Cache::remember('appointment_not_honored_to_twentyfour', 10, function () { + return Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 20) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 24)) then `tbl_client`.`id` end)) AS count")) + ->where('tbl_appointment.app_status', '=', 'Missed') + ->orwhere('tbl_appointment.app_status', '=', 'LTFU') + ->orwhere('tbl_appointment.app_status', '=', 'Defaulted') + ->pluck('count'); + }); + $appointment_not_honored_to_twentyfive_above = Cache::remember('appointment_not_honored_to_twentyfive_above', 10, function () { + return Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 25)) then `tbl_client`.`id` end)) AS count")) + ->where('tbl_appointment.app_status', '=', 'Missed') + ->orwhere('tbl_appointment.app_status', '=', 'LTFU') + ->orwhere('tbl_appointment.app_status', '=', 'Defaulted') + ->pluck('count'); + }); + $appointment_not_honored_to_uknown_age = Cache::remember('appointment_not_honored_to_uknown_age', 10, function () { + return Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->select('tbl_client.dob') + ->where('tbl_client.dob', '=', '') + ->orWhereNull('tbl_client.dob') + ->where('tbl_appointment.app_status', '=', 'Missed') + ->orwhere('tbl_appointment.app_status', '=', 'LTFU') + ->orwhere('tbl_appointment.app_status', '=', 'Defaulted') ->count(); - } - } + }); - public function appointment_chart() - { - if (Auth::user()->access_level == 'Admin' || Auth::user()->access_level == 'Donor') { - // main appointments - $appointment = Appointments::select('id') - ->count(); - $appointment_honoured = Appointments::where('date_attended', '=', 'appntmnt_date') + // missed appointments + + $appointment_missed = Cache::remember('appointment_missed', 10, function () { + return Appointments::where('app_status', '=', 'Missed') ->count(); - $appointment_not_honoured = Appointments::where('date_attended', '!=', 'appntmnt_date') + }); + $appointment_defaulted = Cache::remember('appointment_defaulted', 10, function () { + return Appointments::where('app_status', '=', 'Defaulted') ->count(); - // appointment by gender - $appointment_male = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') - ->select('tbl_appointment.id') - ->where('tbl_client.gender', '=', '2') + }); + $appointment_lftu = Cache::remember('appointment_lftu', 10, function () { + return Appointments::where('app_status', '=', 'LTFU') ->count(); - $appointment_female = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') - ->select('tbl_appointment.id') + }); + + // missed appointment by gender + $appointment_missed_female = Cache::remember('appointment_missed_female', 10, function () { + return Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->where('tbl_appointment.app_status', '=', 'Missed') ->where('tbl_client.gender', '=', '1') ->count(); - // appointment by age - $appointment_to_nine = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') - ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') - ->select(\DB::raw("case when (((year(curdate()) - year(`tbl_client`.`dob`)) > 0) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 9)) then `tbl_client`.`dob` end")) - ->count(); - $appointment_to_fourteen = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') - ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') - ->select(\DB::raw("case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 10) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 14)) then `tbl_client`.`dob` end")) - ->count(); - $appointment_to_nineteen = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') - ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') - ->select(\DB::raw("case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 15) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 19)) then `tbl_client`.`dob` end")) - ->count(); - $appointment_to_twentyfour = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') - ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') - ->select(\DB::raw("case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 20) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 24)) then `tbl_client`.`dob` end")) + }); + $appointment_missed_male = Cache::remember('appointment_missed_male', 10, function () { + return Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->where('tbl_appointment.app_status', '=', 'Missed') + ->where('tbl_client.gender', '=', '2') ->count(); - $appointment_to_twentyfive_above = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') - ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') - ->select(\DB::raw("case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 25) then `tbl_client`.`dob` end")) + }); + $appointment_missed_uknown_gender = Cache::remember('appointment_missed_uknown_gender', 10, function () { + return Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->where('tbl_appointment.app_status', '=', 'Missed') + ->where('tbl_client.gender', '!=', '1') + ->where('tbl_client.gender', '!=', '2') ->count(); - // appointment honored by gender - $appointment_honoured_male = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') - ->where('tbl_client.gender', '=', '2') - ->where('tbl_appointment.date_attended', '=', 'tbl_appointment.appntmnt_date') + }); + // missed appointment by age + $appointment_missed_to_nine = Cache::remember('appointment_missed_to_nine', 10, function () { + return Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) > 0) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 9)) then `tbl_client`.`id` end)) AS count")) + ->where('tbl_appointment.app_status', '=', 'Missed') + ->pluck('count'); + }); + $appointment_missed_to_fourteen = Cache::remember('appointment_missed_to_fourteen', 10, function () { + return Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 10) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 14)) then `tbl_client`.`id` end)) AS count")) + ->where('tbl_appointment.app_status', '=', 'Missed') + ->pluck('count'); + }); + $appointment_missed_to_nineteen = Cache::remember('appointment_missed_to_nineteen', 10, function () { + return Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 15) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 19)) then `tbl_client`.`id` end)) AS count")) + ->where('tbl_appointment.app_status', '=', 'Missed') + ->pluck('count'); + }); + $appointment_missed_to_twentyfour = Cache::remember('appointment_missed_to_twentyfour', 10, function () { + return Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 20) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 24)) then `tbl_client`.`id` end)) AS count")) + ->where('tbl_appointment.app_status', '=', 'Missed') + ->pluck('count'); + }); + $appointment_missed_to_twentyfive_above = Cache::remember('appointment_missed_to_twentyfive_above', 10, function () { + return Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 25)) then `tbl_client`.`id` end)) AS count")) + ->where('tbl_appointment.app_status', '=', 'Missed') + ->pluck('count'); + }); + $appointment_missed_to_uknown_age = Cache::remember('appointment_missed_to_uknown_age', 10, function () { + return Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->select('tbl_client.dob') + ->where('tbl_client.dob', '=', '') + ->orWhereNull('tbl_client.dob') + ->where('tbl_appointment.app_status', '=', 'Missed') ->count(); - $appointment_honoured_female = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + }); + + // defaulted appointment by gender + $appointment_defaulted_female = Cache::remember('appointment_defaulted_female', 10, function () { + return Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->where('tbl_appointment.app_status', '=', 'Defaulted') ->where('tbl_client.gender', '=', '1') - ->where('tbl_appointment.date_attended', '=', 'tbl_appointment.appntmnt_date') - ->count(); - // appointment honored by age - $appointment_honored_to_nine = Appointment::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') - ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') - ->select(\DB::raw("case when (((year(curdate()) - year(`tbl_client`.`dob`)) > 0) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 9)) then `tbl_client`.`dob` end")) - ->where('tbl_appointment.date_attended', '=', 'tbl_appointment.appntmnt_date') ->count(); - $appointment_honored_to_fourteen = Appointment::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') - ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') - ->select(\DB::raw("case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 10) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 14)) then `tbl_client`.`dob` end")) - ->where('tbl_appointment.date_attended', '=', 'tbl_appointment.appntmnt_date') + }); + $appointment_defaulted_male = Cache::remember('appointment_defaulted_male', 10, function () { + return Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->where('tbl_appointment.app_status', '=', 'Defaulted') + ->where('tbl_client.gender', '=', '2') ->count(); - $appointment_honored_to_nineteen = Appointment::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') - ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') - ->select(\DB::raw("case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 15) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 19)) then `tbl_client`.`dob` end")) - ->where('tbl_appointment.date_attended', '=', 'tbl_appointment.appntmnt_date') + }); + $appointment_defaulted_uknown_gender = Cache::remember('appointment_defaulted_uknown_gender', 10, function () { + return Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->where('tbl_appointment.app_status', '=', 'Defaulted') + ->where('tbl_client.gender', '!=', '1') + ->where('tbl_client.gender', '!=', '2') ->count(); - $appointment_honored_to_twentyfour = Appointment::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') - ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') - ->select(\DB::raw("case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 20) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 24)) then `tbl_client`.`dob` end")) - ->where('tbl_appointment.date_attended', '=', 'tbl_appointment.appntmnt_date') + }); + + // defaulted appointment by age + $appointment_defaulted_to_nine = Cache::remember('appointment_defaulted_to_nine', 10, function () { + return Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) > 0) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 9)) then `tbl_client`.`id` end)) AS count")) + ->where('tbl_appointment.app_status', '=', 'Defaulted') + ->pluck('count'); + }); + $appointment_defaulted_to_fourteen = Cache::remember('appointment_defaulted_to_fourteen', 10, function () { + return Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 10) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 14)) then `tbl_client`.`id` end)) AS count")) + ->where('tbl_appointment.app_status', '=', 'Defaulted') + ->pluck('count'); + }); + $appointment_defaulted_to_nineteen = Cache::remember('appointment_defaulted_to_nineteen', 10, function () { + return Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 15) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 19)) then `tbl_client`.`id` end)) AS count")) + ->where('tbl_appointment.app_status', '=', 'Defaulted') + ->pluck('count'); + }); + $appointment_defaulted_to_twentyfour = Cache::remember('appointment_defaulted_to_twentyfour', 10, function () { + return Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 20) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 24)) then `tbl_client`.`id` end)) AS count")) + ->where('tbl_appointment.app_status', '=', 'Defaulted') + ->pluck('count'); + }); + $appointment_defaulted_to_twentyfive_above = Cache::remember('appointment_defaulted_to_twentyfive_above', 10, function () { + return Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 25)) then `tbl_client`.`id` end)) AS count")) + ->where('tbl_appointment.app_status', '=', 'Defaulted') + ->pluck('count'); + }); + $appointment_defaulted_to_uknown_age = Cache::remember('appointment_defaulted_to_uknown_age', 10, function () { + return Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->select('tbl_client.dob') + ->where('tbl_client.dob', '=', '') + ->orWhereNull('tbl_client.dob') + ->where('tbl_appointment.app_status', '=', 'Defaulted') ->count(); - $appointment_honored_to_twentyfive_above = Appointment::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') - ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') - ->select(\DB::raw("case when ((year(curdate()) - year(`tbl_client`.`dob`)) >= 25) then `tbl_client`.`dob` end")) - ->where('tbl_appointment.date_attended', '=', 'tbl_appointment.appntmnt_date') + }); + // ltfu appointment by gender + $appointment_ltfu_female = Cache::remember('appointment_ltfu_female', 10, function () { + return Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->where('tbl_appointment.app_status', '=', 'LTFU') + ->where('tbl_client.gender', '=', '1') ->count(); - - // appointment not honored by gender - $appointment_not_honoured_male = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + }); + $appointment_ltfu_male = Cache::remember('appointment_ltfu_male', 10, function () { + return Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->where('tbl_appointment.app_status', '=', 'LTFU') ->where('tbl_client.gender', '=', '2') - ->where('tbl_appointment.date_attended', '!=', 'tbl_appointment.appntmnt_date') ->count(); - $appointment_not_honoured_female = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') - ->where('tbl_client.gender', '=', '1') - ->where('tbl_appointment.date_attended', '!=', 'tbl_appointment.appntmnt_date') + }); + $appointment_ltfu_uknown_gender = Cache::remember('appointment_ltfu_uknown_gender', 10, function () { + return Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->where('tbl_appointment.app_status', '=', 'LTFU') + ->where('tbl_client.gender', '!=', '1') + ->where('tbl_client.gender', '!=', '2') ->count(); - // appointment not honored by age - $appointment_not_honored_to_nine = Appointment::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') - ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') - ->select(\DB::raw("case when (((year(curdate()) - year(`tbl_client`.`dob`)) > 0) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 9)) then `tbl_client`.`dob` end")) - ->where('tbl_appointment.date_attended', '!=', 'tbl_appointment.appntmnt_date') + }); + + // ltfu appointment by age + $appointment_ltfu_to_nine = Cache::remember('appointment_ltfu_to_nine', 10, function () { + return Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) > 0) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 9)) then `tbl_client`.`id` end)) AS count")) + ->where('tbl_appointment.app_status', '=', 'LTFU') + ->pluck('count'); + }); + $appointment_ltfu_to_fourteen = Cache::remember('appointment_ltfu_to_fourteen', 10, function () { + return Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 10) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 14)) then `tbl_client`.`id` end)) AS count")) + ->where('tbl_appointment.app_status', '=', 'LTFU') + ->pluck('count'); + }); + $appointment_ltfu_to_nineteen = Cache::remember('appointment_ltfu_to_nineteen', 10, function () { + return Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 15) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 19)) then `tbl_client`.`id` end)) AS count")) + ->where('tbl_appointment.app_status', '=', 'LTFU') + ->pluck('count'); + }); + $appointment_ltfu_to_twentyfour = Cache::remember('appointment_ltfu_to_twentyfour', 10, function () { + return Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 20) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 24)) then `tbl_client`.`id` end)) AS count")) + ->where('tbl_appointment.app_status', '=', 'LTFU') + ->pluck('count'); + }); + $appointment_ltfu_to_twentyfive_above = Cache::remember('appointment_ltfu_to_twentyfive_above', 10, function () { + return Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 25)) then `tbl_client`.`id` end)) AS count")) + ->where('tbl_appointment.app_status', '=', 'LTFU') + ->pluck('count'); + }); + $appointment_ltfu_to_uknown_age = Cache::remember('appointment_ltfu_to_uknown_age', 10, function () { + return Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->select('tbl_client.dob') + ->where('tbl_client.dob', '=', '') + ->orWhereNull('tbl_client.dob') + ->where('tbl_appointment.app_status', '=', 'LTFU') ->count(); - $appointment_not_honored_to_fourteen = Appointment::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') - ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') - ->select(\DB::raw("case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 10) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 14)) then `tbl_client`.`dob` end")) - ->where('tbl_appointment.date_attended', '!=', 'tbl_appointment.appntmnt_date') + }); + } + + + // dd($active_facilities); + + return view('new_dashboard.main_dashbaord', compact( + 'all_partners', + 'active_facilities', + 'indicator', + 'client', + 'appointment', + 'missed_appointment', + 'clients_male', + 'clients_female', + 'unknown_gender', + 'client_to_nine', + 'client_to_fourteen', + 'client_to_nineteen', + 'client_to_twentyfour', + 'client_to_twentyfive_above', + 'client_unknown_age', + 'appointment_male', + 'appointment_female', + 'appointment_uknown_gender', + 'appointment_to_nine', + 'appointment_to_fourteen', + 'appointment_to_nineteen', + 'appointment_to_twentyfour', + 'appointment_to_twentyfive_above', + 'appointment_uknown_age', + 'appointment_total_missed_female', + 'appointment_total_missed_male', + 'appointment_total_missed_uknown_gender', + 'appointment_total_missed_to_nine', + 'appointment_total_missed_to_fourteen', + 'appointment_total_missed_to_nineteen', + 'appointment_total_missed_to_twentyfour', + 'appointment_total_missed_to_twentyfive_above', + 'appointment_total_missed_uknown_age', + 'client_consented', + 'client_nonconsented', + 'client_consented_male', + 'client_consented_female', + 'client_consented_uknown_gender', + 'client_nonconsented_male', + 'client_nonconsented_female', + 'client_nonconsented_uknown_gender', + 'client_consented_to_nine', + 'client_consented_to_fourteen', + 'client_consented_to_nineteen', + 'client_consented_to_twentyfour', + 'client_consented_to_twentyfive_above', + 'client_consented_uknown_age', + 'client_nonconsented_to_nine', + 'client_nonconsented_to_fourteen', + 'client_nonconsented_to_nineteen', + 'client_nonconsented_to_twentyfour', + 'client_nonconsented_to_twentyfive_above', + 'client_nonconsented_uknown_age', + 'appointment_honoured', + 'appointment_not_honoured', + 'appointment_honoured_male', + 'appointment_honoured_female', + 'appointment_honoured_uknown_gender', + 'appointment_honored_to_nine', + 'appointment_honored_to_fourteen', + 'appointment_honored_to_nineteen', + 'appointment_honored_to_twentyfour', + 'appointment_honored_to_twentyfive_above', + 'appointment_honored_to_uknown_age', + 'appointment_not_honoured_male', + 'appointment_not_honoured_female', + 'appointment_not_honoured_uknown_gender', + 'appointment_not_honored_to_nine', + 'appointment_not_honored_to_fourteen', + 'appointment_not_honored_to_nineteen', + 'appointment_not_honored_to_twentyfour', + 'appointment_not_honored_to_twentyfive_above', + 'appointment_not_honored_to_uknown_age', + 'appointment_missed', + 'appointment_defaulted', + 'appointment_lftu', + 'appointment_missed_female', + 'appointment_missed_male', + 'appointment_missed_uknown_gender', + 'appointment_missed_to_nine', + 'appointment_missed_to_fourteen', + 'appointment_missed_to_nineteen', + 'appointment_missed_to_twentyfour', + 'appointment_missed_to_twentyfive_above', + 'appointment_missed_to_uknown_age', + 'appointment_defaulted_female', + 'appointment_defaulted_male', + 'appointment_defaulted_uknown_gender', + 'appointment_defaulted_to_nine', + 'appointment_defaulted_to_fourteen', + 'appointment_defaulted_to_nineteen', + 'appointment_defaulted_to_twentyfour', + 'appointment_defaulted_to_twentyfive_above', + 'appointment_defaulted_to_uknown_age', + 'appointment_ltfu_female', + 'appointment_ltfu_male', + 'appointment_ltfu_uknown_gender', + 'appointment_ltfu_to_nine', + 'appointment_ltfu_to_fourteen', + 'appointment_ltfu_to_nineteen', + 'appointment_ltfu_to_twentyfour', + 'appointment_ltfu_to_twentyfive_above', + 'appointment_ltfu_to_uknown_age' + + )); + } + + public function filter_charts(Request $request) + { + // $data = []; + + // $selected_counties = $request->partners; + // $selected_counties = $request->counties; + // $selected_subcounties = $request->subcounties; + // $selected_facilites = $request->facilities; + + if (Auth::user()->access_level == 'Admin' || Auth::user()->access_level == 'Donor') { + + $all_partners = Partner::where('status', '=', 'Active')->pluck('name', 'id'); + $client = Client::select('id')->where('status', '=', 'Active') + ->whereNull('hei_no') + ->where('created_at', '>=', date($request->from))->where('created_at', '<=', date($request->to)) ->count(); - $appointment_not_honored_to_nineteen = Appointment::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') - ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') - ->select(\DB::raw("case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 15) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 19)) then `tbl_client`.`dob` end")) - ->where('tbl_appointment.date_attended', '!=', 'tbl_appointment.appntmnt_date') + $indicator = Indicator::all(); + $appointment = Appointments::select('id') + ->where('created_at', '>=', date($request->from))->where('created_at', '<=', date($request->to)) ->count(); - $appointment_not_honored_to_twentyfour = Appointment::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') - ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') - ->select(\DB::raw("case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 20) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 24)) then `tbl_client`.`dob` end")) - ->where('tbl_appointment.date_attended', '!=', 'tbl_appointment.appntmnt_date') + + $missed_appointment = Appointments::select('id') + ->where('app_status', '=', 'Missed') + ->orwhere('app_status', '=', 'LTFU') + ->orwhere('app_status', '=', 'Defaulted') + ->where('created_at', '>=', date($request->from))->where('created_at', '<=', date($request->to)) ->count(); - $appointment_not_honored_to_twentyfive_above = Appointment::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') - ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') - ->select(\DB::raw("case when ((year(curdate()) - year(`tbl_client`.`dob`)) >= 25) then `tbl_client`.`dob` end")) - ->where('tbl_appointment.date_attended', '=', 'tbl_appointment.appntmnt_date') + $active_facilities = PartnerFacility::join('tbl_client', 'tbl_partner_facility.mfl_code', '=', 'tbl_client.mfl_code') + ->join('tbl_appointment', 'tbl_client.id', '=', 'tbl_appointment.client_id') + ->select(\DB::raw('COUNT(tbl_partner_facility.mfl_code) as facilities')) + ->where('tbl_appointment.created_at', '>=', Carbon::now()->subMonths(6)) + ->where('tbl_appointment.created_at', '>=', date($request->from))->where('tbl_appointment.created_at', '<=', date($request->to)) + ->orderBy('tbl_appointment.created_at', 'DESC') + ->groupBy('tbl_partner_facility.mfl_code') + ->get(); + // dd($active_facilities); + + // dd($active_facilities); + // active clients by gender + $clients_male = Client::select('id')->where([['gender', '=', '2'], ['status', '=', 'Active'],]) + ->whereNull('hei_no') + ->where('created_at', '>=', date($request->from))->where('created_at', '<=', date($request->to)) ->count(); - } - if (Auth::user()->access_level == 'Facility') { - $appointment = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') - ->select('tbl_appointment.id') - ->where('tbl_client.mfl_code', Auth::user()->facility_id) + + $clients_female = Client::where('gender', '=', '1') + ->where('status', '=', 'Active') + ->whereNull('hei_no') + ->where('created_at', '>=', date($request->from))->where('created_at', '<=', date($request->to)) ->count(); - $appointment_honoured = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') - ->where('tbl_appointment.date_attended', '=', 'tbl_appointment.appntmnt_date') - ->where('tbl_client.mfl_code', Auth::user()->facility_id) + $unknown_gender = Client::where('gender', '!=', '1') + ->where('gender', '!=', '2') + ->where('status', '=', 'Active') + ->whereNull('hei_no') + ->where('created_at', '>=', date($request->from))->where('created_at', '<=', date($request->to)) ->count(); - $appointment_not_honoured = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') - ->where('date_attended', '!=', 'appntmnt_date') - ->where('tbl_client.mfl_code', Auth::user()->facility_id) + + $client_to_nine = Client::select(\DB::raw("count((case when (((year(curdate()) - year(`dob`)) > 0) and ((year(curdate()) - year(`dob`)) <= 9)) then `dob` end)) AS count")) + ->where('status', '=', 'Active') + ->whereNull('hei_no') + ->where('created_at', '>=', date($request->from))->where('created_at', '<=', date($request->to)) + ->pluck('count'); + + + $client_to_fourteen = Client::select(\DB::raw("count((case when (((year(curdate()) - year(`dob`)) >= 10) and ((year(curdate()) - year(`dob`)) <= 14)) then `dob` end)) AS count")) + ->where('status', '=', 'Active') + ->whereNull('hei_no') + ->where('created_at', '>=', date($request->from))->where('created_at', '<=', date($request->to)) + ->pluck('count'); + + + $client_to_nineteen = Client::select(\DB::raw("count((case when (((year(curdate()) - year(`dob`)) >= 15) and ((year(curdate()) - year(`dob`)) <= 19)) then `dob` end)) AS count")) + ->where('status', '=', 'Active') + ->whereNull('hei_no') + ->where('created_at', '>=', date($request->from))->where('created_at', '<=', date($request->to)) + ->pluck('count'); + + $client_to_twentyfour = Client::select(\DB::raw("count((case when (((year(curdate()) - year(`dob`)) >= 20) and ((year(curdate()) - year(`dob`)) <= 24)) then `id` end)) AS count")) + ->where('status', '=', 'Active') + ->whereNull('hei_no') + ->where('created_at', '>=', date($request->from))->where('created_at', '<=', date($request->to)) + ->pluck('count'); + + $client_to_twentyfive_above = Client::select(\DB::raw("count((case when (((year(curdate()) - year(`dob`)) >= 25)) then `id` end)) AS count")) + ->where('status', '=', 'Active') + ->whereNull('hei_no') + ->where('created_at', '>=', date($request->from))->where('created_at', '<=', date($request->to)) + ->pluck('count'); + + $client_unknown_age = Client::where('dob', '=', '') + ->orWhereNull('dob') + ->where('status', '=', 'Active') + ->whereNull('hei_no') + ->where('created_at', '>=', date($request->from))->where('created_at', '<=', date($request->to)) ->count(); + // appointment by gender $appointment_male = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') ->select('tbl_appointment.id') ->where('tbl_client.gender', '=', '2') - ->where('tbl_client.mfl_code', Auth::user()->facility_id) + ->where('tbl_appointment.created_at', '>=', date($request->from))->where('tbl_appointment.created_at', '<=', date($request->to)) ->count(); + $appointment_female = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') ->select('tbl_appointment.id') ->where('tbl_client.gender', '=', '1') - ->where('tbl_client.mfl_code', Auth::user()->facility_id) + ->where('tbl_appointment.created_at', '>=', date($request->from))->where('tbl_appointment.created_at', '<=', date($request->to)) + ->count(); + + $appointment_uknown_gender = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->select('tbl_appointment.id') + ->where('tbl_client.gender', '!=', '1') + ->where('tbl_client.gender', '!=', '2') + ->where('tbl_appointment.created_at', '>=', date($request->from))->where('tbl_appointment.created_at', '<=', date($request->to)) ->count(); // appointment by age $appointment_to_nine = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') - ->select(\DB::raw("case when (((year(curdate()) - year(`tbl_client`.`dob`)) > 0) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 9)) then `tbl_client`.`dob` end")) - ->where('tbl_client.mfl_code', Auth::user()->facility_id) - ->count(); + ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) > 0) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 9)) then `tbl_client`.`id` end)) AS count")) + ->where('tbl_appointment.created_at', '>=', date($request->from))->where('tbl_appointment.created_at', '<=', date($request->to)) + ->pluck('count'); + $appointment_to_fourteen = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') - ->select(\DB::raw("case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 10) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 14)) then `tbl_client`.`dob` end")) - ->where('tbl_client.mfl_code', Auth::user()->facility_id) - ->count(); + ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 10) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 14)) then `tbl_client`.`id` end)) AS count")) + ->where('tbl_appointment.created_at', '>=', date($request->from))->where('tbl_appointment.created_at', '<=', date($request->to)) + ->pluck('count'); + $appointment_to_nineteen = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') - ->select(\DB::raw("case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 15) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 19)) then `tbl_client`.`dob` end")) - ->where('tbl_client.mfl_code', Auth::user()->facility_id) - ->count(); + ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 15) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 19)) then `tbl_client`.`id` end)) AS count")) + ->where('tbl_appointment.created_at', '>=', date($request->from))->where('tbl_appointment.created_at', '<=', date($request->to)) + ->pluck('count'); + $appointment_to_twentyfour = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') - ->select(\DB::raw("case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 20) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 24)) then `tbl_client`.`dob` end")) - ->where('tbl_client.mfl_code', Auth::user()->facility_id) - ->count(); - $appointment_to_twentyfive_above = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') - ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') - ->select(\DB::raw("case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 25) then `tbl_client`.`dob` end")) - ->where('tbl_client.mfl_code', Auth::user()->facility_id) - ->count(); - // appointment honored by gender - $appointment_honoured_male = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') - ->where('tbl_client.gender', '=', '2') - ->where('tbl_appointment.date_attended', '=', 'tbl_appointment.appntmnt_date') - ->where('tbl_client.mfl_code', Auth::user()->facility_id) - ->count(); - $appointment_honoured_female = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') - ->where('tbl_client.gender', '=', '1') - ->where('tbl_appointment.date_attended', '=', 'tbl_appointment.appntmnt_date') - ->where('tbl_client.mfl_code', Auth::user()->facility_id) - ->count(); - // appointment honored by age - $appointment_honored_to_nine = Appointment::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') - ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') - ->select(\DB::raw("case when (((year(curdate()) - year(`tbl_client`.`dob`)) > 0) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 9)) then `tbl_client`.`dob` end")) - ->where('tbl_appointment.date_attended', '=', 'tbl_appointment.appntmnt_date') - ->where('tbl_client.mfl_code', Auth::user()->facility_id) - ->count(); - $appointment_honored_to_fourteen = Appointment::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') - ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') - ->select(\DB::raw("case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 10) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 14)) then `tbl_client`.`dob` end")) - ->where('tbl_appointment.date_attended', '=', 'tbl_appointment.appntmnt_date') - ->where('tbl_client.mfl_code', Auth::user()->facility_id) - ->count(); - $appointment_honored_to_nineteen = Appointment::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') - ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') - ->select(\DB::raw("case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 15) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 19)) then `tbl_client`.`dob` end")) - ->where('tbl_appointment.date_attended', '=', 'tbl_appointment.appntmnt_date') - ->where('tbl_client.mfl_code', Auth::user()->facility_id) - ->count(); - $appointment_honored_to_twentyfour = Appointment::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') - ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') - ->select(\DB::raw("case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 20) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 24)) then `tbl_client`.`dob` end")) - ->where('tbl_appointment.date_attended', '=', 'tbl_appointment.appntmnt_date') - ->where('tbl_client.mfl_code', Auth::user()->facility_id) - ->count(); - $appointment_honored_to_twentyfive_above = Appointment::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') - ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') - ->select(\DB::raw("case when ((year(curdate()) - year(`tbl_client`.`dob`)) >= 25) then `tbl_client`.`dob` end")) - ->where('tbl_appointment.date_attended', '=', 'tbl_appointment.appntmnt_date') - ->where('tbl_client.mfl_code', Auth::user()->facility_id) - ->count(); + ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 20) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 24)) then `tbl_client`.`id` end)) AS count")) + ->where('tbl_appointment.created_at', '>=', date($request->from))->where('tbl_appointment.created_at', '<=', date($request->to)) + ->pluck('count'); - // appointment not honored by gender - $appointment_not_honoured_male = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') - ->where('tbl_client.gender', '=', '2') - ->where('tbl_appointment.date_attended', '!=', 'tbl_appointment.appntmnt_date') - ->where('tbl_client.mfl_code', Auth::user()->facility_id) - ->count(); - $appointment_not_honoured_female = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') - ->where('tbl_client.gender', '=', '1') - ->where('tbl_appointment.date_attended', '!=', 'tbl_appointment.appntmnt_date') - ->where('tbl_client.mfl_code', Auth::user()->facility_id) - ->count(); - // appointment not honored by age - $appointment_not_honored_to_nine = Appointment::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') - ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') - ->select(\DB::raw("case when (((year(curdate()) - year(`tbl_client`.`dob`)) > 0) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 9)) then `tbl_client`.`dob` end")) - ->where('tbl_appointment.date_attended', '!=', 'tbl_appointment.appntmnt_date') - ->where('tbl_client.mfl_code', Auth::user()->facility_id) - ->count(); - $appointment_not_honored_to_fourteen = Appointment::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') - ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') - ->select(\DB::raw("case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 10) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 14)) then `tbl_client`.`dob` end")) - ->where('tbl_appointment.date_attended', '!=', 'tbl_appointment.appntmnt_date') - ->where('tbl_client.mfl_code', Auth::user()->facility_id) - ->count(); - $appointment_not_honored_to_nineteen = Appointment::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') - ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') - ->select(\DB::raw("case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 15) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 19)) then `tbl_client`.`dob` end")) - ->where('tbl_appointment.date_attended', '!=', 'tbl_appointment.appntmnt_date') - ->where('tbl_client.mfl_code', Auth::user()->facility_id) - ->count(); - $appointment_not_honored_to_twentyfour = Appointment::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') - ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') - ->select(\DB::raw("case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 20) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 24)) then `tbl_client`.`dob` end")) - ->where('tbl_appointment.date_attended', '!=', 'tbl_appointment.appntmnt_date') - ->where('tbl_client.mfl_code', Auth::user()->facility_id) - ->count(); - $appointment_not_honored_to_twentyfive_above = Appointment::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') - ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') - ->select(\DB::raw("case when ((year(curdate()) - year(`tbl_client`.`dob`)) >= 25) then `tbl_client`.`dob` end")) - ->where('tbl_appointment.date_attended', '=', 'tbl_appointment.appntmnt_date') - ->where('tbl_client.mfl_code', Auth::user()->facility_id) - ->count(); - } - if (Auth::user()->access_level == 'Partner') { - $appointment = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') - ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') - ->select('tbl_appointment.id') - ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) - ->count(); - $appointment_honoured = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') - ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') - ->where('tbl_appointment.date_attended', '=', 'tbl_appointment.appntmnt_date') - ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) - ->count(); - $appointment_not_honoured = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') - ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') - ->where('date_attended', '!=', 'appntmnt_date') - ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) - ->count(); - // appointment by gender - $appointment_male = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') - ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') - ->select('tbl_appointment.id') - ->where('tbl_client.gender', '=', '2') - ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) - ->count(); - $appointment_female = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') - ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') - ->select('tbl_appointment.id') - ->where('tbl_client.gender', '=', '1') - ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) - ->count(); - // appointment by age - $appointment_to_nine = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') - ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') - ->select(\DB::raw("case when (((year(curdate()) - year(`tbl_client`.`dob`)) > 0) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 9)) then `tbl_client`.`dob` end")) - ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) - ->count(); - $appointment_to_fourteen = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') - ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') - ->select(\DB::raw("case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 10) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 14)) then `tbl_client`.`dob` end")) - ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) - ->count(); - $appointment_to_nineteen = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') - ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') - ->select(\DB::raw("case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 15) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 19)) then `tbl_client`.`dob` end")) - ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) - ->count(); - $appointment_to_twentyfour = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') - ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') - ->select(\DB::raw("case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 20) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 24)) then `tbl_client`.`dob` end")) - ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) - ->count(); $appointment_to_twentyfive_above = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') - ->select(\DB::raw("case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 25) then `tbl_client`.`dob` end")) - ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) - ->count(); - // appointment honored by gender - $appointment_honoured_male = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') - ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') - ->where('tbl_client.gender', '=', '2') - ->where('tbl_appointment.date_attended', '=', 'tbl_appointment.appntmnt_date') - ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) - ->count(); - $appointment_honoured_female = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') - ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') - ->where('tbl_client.gender', '=', '1') - ->where('tbl_appointment.date_attended', '=', 'tbl_appointment.appntmnt_date') - ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) - ->count(); - // appointment honored by age - $appointment_honored_to_nine = Appointment::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') - ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') - ->select(\DB::raw("case when (((year(curdate()) - year(`tbl_client`.`dob`)) > 0) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 9)) then `tbl_client`.`dob` end")) - ->where('tbl_appointment.date_attended', '=', 'tbl_appointment.appntmnt_date') - ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) - ->count(); - $appointment_honored_to_fourteen = Appointment::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') - ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') - ->select(\DB::raw("case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 10) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 14)) then `tbl_client`.`dob` end")) - ->where('tbl_appointment.date_attended', '=', 'tbl_appointment.appntmnt_date') - ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) - ->count(); - $appointment_honored_to_nineteen = Appointment::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') - ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') - ->select(\DB::raw("case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 15) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 19)) then `tbl_client`.`dob` end")) - ->where('tbl_appointment.date_attended', '=', 'tbl_appointment.appntmnt_date') - ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) - ->count(); - $appointment_honored_to_twentyfour = Appointment::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') - ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') - ->select(\DB::raw("case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 20) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 24)) then `tbl_client`.`dob` end")) - ->where('tbl_appointment.date_attended', '=', 'tbl_appointment.appntmnt_date') - ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) - ->count(); - $appointment_honored_to_twentyfive_above = Appointment::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') - ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') - ->select(\DB::raw("case when ((year(curdate()) - year(`tbl_client`.`dob`)) >= 25) then `tbl_client`.`dob` end")) - ->where('tbl_appointment.date_attended', '=', 'tbl_appointment.appntmnt_date') - ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) - ->count(); + ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 25)) then `tbl_client`.`id` end)) AS count")) + ->where('tbl_appointment.created_at', '>=', date($request->from))->where('tbl_appointment.created_at', '<=', date($request->to)) + ->pluck('count'); - // appointment not honored by gender - $appointment_not_honoured_male = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') - ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') - ->where('tbl_client.gender', '=', '2') - ->where('tbl_appointment.date_attended', '!=', 'tbl_appointment.appntmnt_date') - ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) - ->count(); - $appointment_not_honoured_female = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') - ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') - ->where('tbl_client.gender', '=', '1') - ->where('tbl_appointment.date_attended', '!=', 'tbl_appointment.appntmnt_date') - ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) - ->count(); - // appointment not honored by age - $appointment_not_honored_to_nine = Appointment::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') - ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') - ->select(\DB::raw("case when (((year(curdate()) - year(`tbl_client`.`dob`)) > 0) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 9)) then `tbl_client`.`dob` end")) - ->where('tbl_appointment.date_attended', '!=', 'tbl_appointment.appntmnt_date') - ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) - ->count(); - $appointment_not_honored_to_fourteen = Appointment::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') - ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') - ->select(\DB::raw("case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 10) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 14)) then `tbl_client`.`dob` end")) - ->where('tbl_appointment.date_attended', '!=', 'tbl_appointment.appntmnt_date') - ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) - ->count(); - $appointment_not_honored_to_nineteen = Appointment::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') - ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') - ->select(\DB::raw("case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 15) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 19)) then `tbl_client`.`dob` end")) - ->where('tbl_appointment.date_attended', '!=', 'tbl_appointment.appntmnt_date') - ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) - ->count(); - $appointment_not_honored_to_twentyfour = Appointment::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') - ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') - ->select(\DB::raw("case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 20) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 24)) then `tbl_client`.`dob` end")) - ->where('tbl_appointment.date_attended', '!=', 'tbl_appointment.appntmnt_date') - ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) - ->count(); - $appointment_not_honored_to_twentyfive_above = Appointment::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + $appointment_uknown_age = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') - ->select(\DB::raw("case when ((year(curdate()) - year(`tbl_client`.`dob`)) >= 25) then `tbl_client`.`dob` end")) - ->where('tbl_appointment.date_attended', '=', 'tbl_appointment.appntmnt_date') - ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) - ->count(); - } - } - public function missed_appointment_chart() - { - if (Auth::user()->access_level == 'Admin' || Auth::user()->access_level == 'Donor') { - // main dashboard all - $appointment_total_missed = Appointments::where('date_attended', '!=', 'appntmnt_date') - ->count(); - $appointment_missed = Appointments::where('app_status', '=', 'Missed') - ->count(); - $appointment_defaulted = Appointments::where('app_status', '=', 'Defaulted') - ->count(); - $appointment_lftu = Appointments::where('app_status', '=', 'LTFU') + ->where('tbl_client.dob', '=', '') + ->orWhereNull('tbl_client.dob') + ->where('tbl_appointment.created_at', '>=', date($request->from))->where('tbl_appointment.created_at', '<=', date($request->to)) ->count(); // Total missed appointment by gender $appointment_total_missed_female = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') - ->where('tbl_appointment.date_attended', '!=', 'tbl_appointment.appntmnt_date') ->where('tbl_client.gender', '=', '1') + ->where('tbl_appointment.app_status', '=', 'Missed') + ->orwhere('tbl_appointment.app_status', '=', 'LTFU') + ->orwhere('tbl_appointment.app_status', '=', 'Defaulted') + ->where('tbl_appointment.created_at', '>=', date($request->from))->where('tbl_appointment.created_at', '<=', date($request->to)) ->count(); + $appointment_total_missed_male = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') - ->where('tbl_appointment.date_attended', '!=', 'tbl_appointment.appntmnt_date') ->where('tbl_client.gender', '=', '2') + ->where('tbl_appointment.app_status', '=', 'Missed') + ->orwhere('tbl_appointment.app_status', '=', 'LTFU') + ->orwhere('tbl_appointment.app_status', '=', 'Defaulted') + ->where('tbl_appointment.created_at', '>=', date($request->from))->where('tbl_appointment.created_at', '<=', date($request->to)) + ->count(); + + $appointment_total_missed_uknown_gender = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->where('tbl_client.gender', '!=', '1') + ->where('tbl_client.gender', '!=', '2') + ->where('tbl_appointment.app_status', '=', 'Missed') + ->orwhere('tbl_appointment.app_status', '=', 'LTFU') + ->orwhere('tbl_appointment.app_status', '=', 'Defaulted') + ->where('tbl_appointment.created_at', '>=', date($request->from))->where('tbl_appointment.created_at', '<=', date($request->to)) ->count(); // Total missed appointment by age $appointment_total_missed_to_nine = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') - ->select(\DB::raw("case when (((year(curdate()) - year(`tbl_client`.`dob`)) > 0) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 9)) then `tbl_client`.`dob` end")) - ->where('tbl_appointment.date_attended', '!=', 'tbl_appointment.appntmnt_date') - ->count(); + ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) > 0) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 9)) then `tbl_client`.`id` end)) AS count")) + ->where('tbl_appointment.app_status', '=', 'Missed') + ->orwhere('tbl_appointment.app_status', '=', 'LTFU') + ->orwhere('tbl_appointment.app_status', '=', 'Defaulted') + ->where('tbl_appointment.created_at', '>=', date($request->from))->where('tbl_appointment.created_at', '<=', date($request->to)) + ->pluck('count'); + $appointment_total_missed_to_fourteen = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') - ->select(\DB::raw("case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 10) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 14)) then `tbl_client`.`dob` end")) - ->where('tbl_appointment.date_attended', '!=', 'tbl_appointment.appntmnt_date') - ->count(); + ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 10) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 14)) then `tbl_client`.`id` end)) AS count")) + ->where('tbl_appointment.app_status', '=', 'Missed') + ->orwhere('tbl_appointment.app_status', '=', 'LTFU') + ->orwhere('tbl_appointment.app_status', '=', 'Defaulted') + ->where('tbl_appointment.created_at', '>=', date($request->from))->where('tbl_appointment.created_at', '<=', date($request->to)) + ->pluck('count'); + $appointment_total_missed_to_nineteen = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') - ->select(\DB::raw("case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 15) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 19)) then `tbl_client`.`dob` end")) + ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 15) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 19)) then `tbl_client`.`id` end)) AS count")) ->where('tbl_appointment.date_attended', '!=', 'tbl_appointment.appntmnt_date') - ->count(); + ->where('tbl_appointment.created_at', '>=', date($request->from))->where('tbl_appointment.created_at', '<=', date($request->to)) + ->pluck('count'); + $appointment_total_missed_to_twentyfour = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') - ->select(\DB::raw("case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 20) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 24)) then `tbl_client`.`dob` end")) - ->where('tbl_appointment.date_attended', '!=', 'tbl_appointment.appntmnt_date') - ->count(); - $appointment_total_missed_to_twentyfive_above = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') - ->select(\DB::raw("case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 25) then `tbl_client`.`dob` end")) + ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 20) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 24)) then `tbl_client`.`id` end)) AS count")) ->where('tbl_appointment.date_attended', '!=', 'tbl_appointment.appntmnt_date') - ->count(); + ->where('tbl_appointment.created_at', '>=', date($request->from))->where('tbl_appointment.created_at', '<=', date($request->to)) + ->pluck('count'); - // missed appointment by gender - $appointment_missed_female = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') - ->where('tbl_appointment.app_status', '=', 'Missed') - ->where('tbl_client.gender', '=', '1') - ->count(); - $appointment_missed_male = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + $appointment_total_missed_to_twentyfive_above = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 25)) then `tbl_client`.`id` end)) AS count")) ->where('tbl_appointment.app_status', '=', 'Missed') - ->where('tbl_client.gender', '=', '1') - ->count(); + ->orwhere('tbl_appointment.app_status', '=', 'LTFU') + ->orwhere('tbl_appointment.app_status', '=', 'Defaulted') + ->where('tbl_appointment.created_at', '>=', date($request->from))->where('tbl_appointment.created_at', '<=', date($request->to)) + ->pluck('count'); - // missed appointment by age - $appointment_missed_to_nine = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') - ->select(\DB::raw("case when (((year(curdate()) - year(`tbl_client`.`dob`)) > 0) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 9)) then `tbl_client`.`dob` end")) - ->where('tbl_appointment.app_status', '=', 'Missed') - ->count(); - $appointment_missed_to_fourteen = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') - ->select(\DB::raw("case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 10) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 14)) then `tbl_client`.`dob` end")) - ->where('tbl_appointment.app_status', '=', 'Missed') - ->count(); - $appointment_missed_to_nineteen = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') - ->select(\DB::raw("case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 15) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 19)) then `tbl_client`.`dob` end")) - ->where('tbl_appointment.app_status', '=', 'Missed') - ->count(); - $appointment_missed_to_twentyfour = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') - ->select(\DB::raw("case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 20) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 24)) then `tbl_client`.`dob` end")) - ->where('tbl_appointment.app_status', '=', 'Missed') - ->count(); - $appointment_missed_to_twentyfive_above = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') - ->select(\DB::raw("case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 25) then `tbl_client`.`dob` end")) + $appointment_total_missed_uknown_age = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->where('tbl_client.dob', '=', '') + ->orWhereNull('tbl_client.dob') ->where('tbl_appointment.app_status', '=', 'Missed') + ->orwhere('tbl_appointment.app_status', '=', 'LTFU') + ->orwhere('tbl_appointment.app_status', '=', 'Defaulted') + ->where('tbl_appointment.created_at', '>=', date($request->from))->where('tbl_appointment.created_at', '<=', date($request->to)) ->count(); - // defaulted appointment by gender - $appointment_defaulted_female = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') - ->where('tbl_appointment.app_status', '=', 'Defaulted') - ->where('tbl_client.gender', '=', '1') + // client charts + $client_consented = Client::select('smsenable') + ->where('status', '=', 'Active') + ->whereNull('hei_no') + ->where('smsenable', '=', 'Yes') + ->where('created_at', '>=', date($request->from))->where('created_at', '<=', date($request->to)) ->count(); - $appointment_defaulted_female = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') - ->where('tbl_appointment.app_status', '=', 'Defaulted') - ->where('tbl_client.gender', '=', '2') + $client_nonconsented = Client::select('smsenable') + ->where('status', '=', 'Active') + ->whereNull('hei_no') + ->where('smsenable', '!=', 'Yes') + ->where('created_at', '>=', date($request->from))->where('created_at', '<=', date($request->to)) ->count(); - // defaulted appointment by age - $appointment_defaulted_to_nine = join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') - ->select(\DB::raw("case when (((year(curdate()) - year(`tbl_client`.`dob`)) > 0) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 9)) then `tbl_client`.`dob` end")) - ->where('tbl_appointment.app_status', '=', 'Defaulted') - ->count(); - $appointment_defaulted_to_fourteen = join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') - ->select(\DB::raw("case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 10) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 14)) then `tbl_client`.`dob` end")) - ->where('tbl_appointment.app_status', '=', 'Defaulted') - ->count(); - $appointment_defaulted_to_nineteen = join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') - ->select(\DB::raw("case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 15) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 19)) then `tbl_client`.`dob` end")) - ->where('tbl_appointment.app_status', '=', 'Defaulted') - ->count(); - $appointment_defaulted_to_twentyfour = join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') - ->select(\DB::raw("case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 20) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 24)) then `tbl_client`.`dob` end")) - ->where('tbl_appointment.app_status', '=', 'Defaulted') - ->count(); - $appointment_defaulted_to_twentyfive_above = join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') - ->select(\DB::raw("case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 25) then `tbl_client`.`dob` end")) - ->where('tbl_appointment.app_status', '=', 'Defaulted') - ->count(); + // consented clients by gender - // ltfu appointment by gender - $appointment_ltfu_female = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') - ->where('tbl_appointment.app_status', '=', 'LTFU') - ->where('tbl_client.gender', '=', '1') + $client_consented_male = Client::where('smsenable', '=', 'Yes') + ->where('status', '=', 'Active') + ->whereNull('hei_no') + ->where('gender', '=', '2') + ->where('created_at', '>=', date($request->from))->where('created_at', '<=', date($request->to)) ->count(); - $appointment_ltfu_female = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') - ->where('tbl_appointment.app_status', '=', 'LTFU') - ->where('tbl_client.gender', '=', '2') + $client_consented_female = Client::where('smsenable', '=', 'Yes') + ->where('status', '=', 'Active') + ->whereNull('hei_no') + ->where('gender', '=', '1') + ->where('created_at', '>=', date($request->from))->where('created_at', '<=', date($request->to)) ->count(); - // ltfu appointment by age - $appointment_ltfu_to_nine = join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') - ->select(\DB::raw("case when (((year(curdate()) - year(`tbl_client`.`dob`)) > 0) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 9)) then `tbl_client`.`dob` end")) - ->where('tbl_appointment.app_status', '=', 'LTFU') - ->count(); - $appointment_ltfu_to_fourteen = join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') - ->select(\DB::raw("case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 10) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 14)) then `tbl_client`.`dob` end")) - ->where('tbl_appointment.app_status', '=', 'LTFU') - ->count(); - $appointment_ltfu_to_nineteen = join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') - ->select(\DB::raw("case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 15) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 19)) then `tbl_client`.`dob` end")) - ->where('tbl_appointment.app_status', '=', 'LTFU') - ->count(); - $appointment_ltfu_to_twentyfour = join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') - ->select(\DB::raw("case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 20) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 24)) then `tbl_client`.`dob` end")) - ->where('tbl_appointment.app_status', '=', 'LTFU') - ->count(); - $appointment_ltfu_to_twentyfive_above = join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') - ->select(\DB::raw("case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 25) then `tbl_client`.`dob` end")) - ->where('tbl_appointment.app_status', '=', 'LTFU') - ->count(); - } - if (Auth::user()->access_level == 'Facility') { - // main dashboard all - $appointment_total_missed = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') - ->where('tbl_appointment.date_attended', '!=', 'tbl_appointment.appntmnt_date') - ->where('tbl_client.mfl_code', Auth::user()->facility_id) - ->count(); - $appointment_missed = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') - ->where('tbl_appointment.app_status', '=', 'Missed') - ->where('tbl_client.mfl_code', Auth::user()->facility_id) + $client_consented_uknown_gender = Client::where('smsenable', '=', 'Yes') + ->where('status', '=', 'Active') + ->whereNull('hei_no') + ->where('gender', '!=', '1') + ->where('gender', '!=', '2') + ->where('created_at', '>=', date($request->from))->where('created_at', '<=', date($request->to)) ->count(); - $appointment_defaulted = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') - ->where('tbl_appointment.app_status', '=', 'Defaulted') - ->where('tbl_client.mfl_code', Auth::user()->facility_id) + // non consented clients by gender + $client_nonconsented_male = Client::where('smsenable', '!=', 'Yes') + ->where('status', '=', 'Active') + ->whereNull('hei_no') + ->where('gender', '=', '2') + ->where('created_at', '>=', date($request->from))->where('created_at', '<=', date($request->to)) ->count(); - $appointment_lftu = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') - ->where('tbl_appointment.app_status', '=', 'LTFU') - ->where('tbl_client.mfl_code', Auth::user()->facility_id) + $client_nonconsented_female = Client::where('smsenable', '!=', 'Yes') + ->where('status', '=', 'Active') + ->whereNull('hei_no') + ->where('gender', '=', '1') + ->where('created_at', '>=', date($request->from))->where('created_at', '<=', date($request->to)) ->count(); - // Total missed appointment by gender - $appointment_total_missed_female = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') - ->where('tbl_appointment.date_attended', '!=', 'tbl_appointment.appntmnt_date') - ->where('tbl_client.gender', '=', '1') - ->where('tbl_client.mfl_code', Auth::user()->facility_id) - ->count(); - $appointment_total_missed_male = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') - ->where('tbl_appointment.date_attended', '!=', 'tbl_appointment.appntmnt_date') - ->where('tbl_client.gender', '=', '2') - ->where('tbl_client.mfl_code', Auth::user()->facility_id) + $client_nonconsented_uknown_gender = Client::where('smsenable', '!=', 'Yes') + ->where('gender', '!=', '1') + ->where('gender', '!=', '2') + ->where('created_at', '>=', date($request->from))->where('created_at', '<=', date($request->to)) ->count(); - // Total missed appointment by age - $appointment_total_missed_to_nine = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') - ->select(\DB::raw("case when (((year(curdate()) - year(`tbl_client`.`dob`)) > 0) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 9)) then `tbl_client`.`dob` end")) - ->where('tbl_appointment.date_attended', '!=', 'tbl_appointment.appntmnt_date') - ->where('tbl_client.mfl_code', Auth::user()->facility_id) - ->count(); - $appointment_total_missed_to_fourteen = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') - ->select(\DB::raw("case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 10) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 14)) then `tbl_client`.`dob` end")) - ->where('tbl_appointment.date_attended', '!=', 'tbl_appointment.appntmnt_date') - ->where('tbl_client.mfl_code', Auth::user()->facility_id) - ->count(); - $appointment_total_missed_to_nineteen = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') - ->select(\DB::raw("case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 15) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 19)) then `tbl_client`.`dob` end")) - ->where('tbl_appointment.date_attended', '!=', 'tbl_appointment.appntmnt_date') - ->where('tbl_client.mfl_code', Auth::user()->facility_id) - ->count(); - $appointment_total_missed_to_twentyfour = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') - ->select(\DB::raw("case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 20) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 24)) then `tbl_client`.`dob` end")) - ->where('tbl_appointment.date_attended', '!=', 'tbl_appointment.appntmnt_date') - ->where('tbl_client.mfl_code', Auth::user()->facility_id) - ->count(); - $appointment_total_missed_to_twentyfive_above = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') - ->select(\DB::raw("case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 25) then `tbl_client`.`dob` end")) - ->where('tbl_appointment.date_attended', '!=', 'tbl_appointment.appntmnt_date') - ->where('tbl_client.mfl_code', Auth::user()->facility_id) - ->count(); + // consented clients by age distribution + $client_consented_to_nine = Client::select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) > 0) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 9)) then `tbl_client`.`id` end)) AS count")) + ->where('smsenable', '=', 'Yes') + ->where('status', '=', 'Active') + ->whereNull('hei_no') + ->pluck('count'); - // missed appointment by gender - $appointment_missed_female = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') - ->where('tbl_appointment.app_status', '=', 'Missed') - ->where('tbl_client.gender', '=', '1') - ->where('tbl_client.mfl_code', Auth::user()->facility_id) + $client_consented_to_fourteen = Client::select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 10) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 14)) then `tbl_client`.`id` end)) AS count")) + ->where('smsenable', '=', 'Yes') + ->where('status', '=', 'Active') + ->whereNull('hei_no') + ->where('created_at', '>=', date($request->from))->where('created_at', '<=', date($request->to)) + ->pluck('count'); + + $client_consented_to_nineteen = Client::select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 15) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 19)) then `tbl_client`.`id` end)) AS count")) + ->where('smsenable', '=', 'Yes') + ->where('status', '=', 'Active') + ->whereNull('hei_no') + ->where('created_at', '>=', date($request->from))->where('created_at', '<=', date($request->to)) + ->pluck('count'); + + $client_consented_to_twentyfour = Client::select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 20) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 24)) then `tbl_client`.`id` end)) AS count")) + ->where('smsenable', '=', 'Yes') + ->where('status', '=', 'Active') + ->whereNull('hei_no') + ->pluck('count'); + + $client_consented_to_twentyfive_above = Client::select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 25)) then `tbl_client`.`id` end)) AS count")) + ->where('smsenable', '=', 'Yes') + ->where('status', '=', 'Active') + ->whereNull('hei_no') + ->where('created_at', '>=', date($request->from))->where('created_at', '<=', date($request->to)) + ->pluck('count'); + + $client_consented_uknown_age = Client::select('smsenable') + ->where('dob', '=', '') + ->where('status', '=', 'Active') + ->whereNull('hei_no') + ->orWhereNull('dob') + ->where('smsenable', '=', 'Yes') + ->where('created_at', '>=', date($request->from))->where('created_at', '<=', date($request->to)) ->count(); - $appointment_missed_male = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') - ->where('tbl_appointment.app_status', '=', 'Missed') - ->where('tbl_client.gender', '=', '1') - ->where('tbl_client.mfl_code', Auth::user()->facility_id) + // non consented clients by age distribution + $client_nonconsented_to_nine = Client::select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) > 0) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 9)) then `tbl_client`.`id` end)) AS count")) + ->where('smsenable', '!=', 'Yes') + ->where('status', '=', 'Active') + ->whereNull('hei_no') + ->where('created_at', '>=', date($request->from))->where('created_at', '<=', date($request->to)) + ->pluck('count'); + $client_nonconsented_to_fourteen = Client::select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 10) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 14)) then `tbl_client`.`id` end)) AS count")) + ->where('smsenable', '!=', 'Yes') + ->where('status', '=', 'Active') + ->whereNull('hei_no') + ->where('created_at', '>=', date($request->from))->where('created_at', '<=', date($request->to)) + ->pluck('count'); + + $client_nonconsented_to_nineteen = Client::select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 15) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 19)) then `tbl_client`.`id` end)) AS count")) + ->where('smsenable', '!=', 'Yes') + ->where('status', '=', 'Active') + ->whereNull('hei_no') + ->where('created_at', '>=', date($request->from))->where('created_at', '<=', date($request->to)) + ->pluck('count'); + $client_nonconsented_to_twentyfour = Client::select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 20) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 24)) then `tbl_client`.`id` end)) AS count")) + ->where('smsenable', '!=', 'Yes') + ->where('status', '=', 'Active') + ->whereNull('hei_no') + ->where('created_at', '>=', date($request->from))->where('created_at', '<=', date($request->to)) + ->pluck('count'); + + $client_nonconsented_to_twentyfive_above = Client::select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 25)) then `tbl_client`.`id` end)) AS count")) + ->where('smsenable', '!=', 'Yes') + ->where('status', '=', 'Active') + ->whereNull('hei_no') + ->where('created_at', '>=', date($request->from))->where('created_at', '<=', date($request->to)) + ->pluck('count'); + $client_nonconsented_uknown_age = Client::select('smsenable') + ->where('status', '=', 'Active') + ->whereNull('hei_no') + ->where('dob', '=', '') + ->orWhereNull('dob') + ->where('smsenable', '!=', 'Yes') + ->where('created_at', '>=', date($request->from))->where('created_at', '<=', date($request->to)) ->count(); - // missed appointment by age - $appointment_missed_to_nine = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') - ->select(\DB::raw("case when (((year(curdate()) - year(`tbl_client`.`dob`)) > 0) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 9)) then `tbl_client`.`dob` end")) - ->where('tbl_appointment.app_status', '=', 'Missed') - ->where('tbl_client.mfl_code', Auth::user()->facility_id) - ->count(); - $appointment_missed_to_fourteen = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') - ->select(\DB::raw("case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 10) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 14)) then `tbl_client`.`dob` end")) - ->where('tbl_appointment.app_status', '=', 'Missed') - ->where('tbl_client.mfl_code', Auth::user()->facility_id) - ->count(); - $appointment_missed_to_nineteen = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') - ->select(\DB::raw("case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 15) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 19)) then `tbl_client`.`dob` end")) - ->where('tbl_appointment.app_status', '=', 'Missed') - ->where('tbl_client.mfl_code', Auth::user()->facility_id) - ->count(); - $appointment_missed_to_twentyfour = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') - ->select(\DB::raw("case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 20) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 24)) then `tbl_client`.`dob` end")) - ->where('tbl_appointment.app_status', '=', 'Missed') - ->where('tbl_client.mfl_code', Auth::user()->facility_id) - ->count(); - $appointment_missed_to_twentyfive_above = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') - ->select(\DB::raw("case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 25) then `tbl_client`.`dob` end")) - ->where('tbl_appointment.app_status', '=', 'Missed') - ->where('tbl_client.mfl_code', Auth::user()->facility_id) - ->count(); + // main appointments + $appointment_honoured = Appointments::select('id')->where('appntmnt_date', '=', 'date_attended') + ->where('created_at', '>=', date($request->from))->where('created_at', '<=', date($request->to)) + ->count(); - // defaulted appointment by gender - $appointment_defaulted_female = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') - ->where('tbl_appointment.app_status', '=', 'Defaulted') - ->where('tbl_client.gender', '=', '1') - ->where('tbl_client.mfl_code', Auth::user()->facility_id) + // dd($appointment_honoured); + $appointment_not_honoured = Appointments::select('id') + ->where('tbl_appointment.app_status', '=', 'Missed') + ->orwhere('tbl_appointment.app_status', '=', 'LTFU') + ->orwhere('tbl_appointment.app_status', '=', 'Defaulted') + ->where('created_at', '>=', date($request->from))->where('created_at', '<=', date($request->to)) ->count(); - $appointment_defaulted_female = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') - ->where('tbl_appointment.app_status', '=', 'Defaulted') + // appointment honored by gender + $appointment_honoured_male = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') ->where('tbl_client.gender', '=', '2') - ->where('tbl_client.mfl_code', Auth::user()->facility_id) - ->count(); - - // defaulted appointment by age - $appointment_defaulted_to_nine = join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') - ->select(\DB::raw("case when (((year(curdate()) - year(`tbl_client`.`dob`)) > 0) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 9)) then `tbl_client`.`dob` end")) - ->where('tbl_appointment.app_status', '=', 'Defaulted') - ->where('tbl_client.mfl_code', Auth::user()->facility_id) - ->count(); - $appointment_defaulted_to_fourteen = join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') - ->select(\DB::raw("case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 10) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 14)) then `tbl_client`.`dob` end")) - ->where('tbl_appointment.app_status', '=', 'Defaulted') - ->where('tbl_client.mfl_code', Auth::user()->facility_id) - ->count(); - $appointment_defaulted_to_nineteen = join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') - ->select(\DB::raw("case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 15) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 19)) then `tbl_client`.`dob` end")) - ->where('tbl_appointment.app_status', '=', 'Defaulted') - ->where('tbl_client.mfl_code', Auth::user()->facility_id) - ->count(); - $appointment_defaulted_to_twentyfour = join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') - ->select(\DB::raw("case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 20) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 24)) then `tbl_client`.`dob` end")) - ->where('tbl_appointment.app_status', '=', 'Defaulted') - ->where('tbl_client.mfl_code', Auth::user()->facility_id) - ->count(); - $appointment_defaulted_to_twentyfive_above = join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') - ->select(\DB::raw("case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 25) then `tbl_client`.`dob` end")) - ->where('tbl_appointment.app_status', '=', 'Defaulted') - ->where('tbl_client.mfl_code', Auth::user()->facility_id) + ->where('tbl_appointment.date_attended', '=', 'tbl_appointment.appntmnt_date') + ->where('tbl_appointment.created_at', '>=', date($request->from))->where('tbl_appointment.created_at', '<=', date($request->to)) ->count(); - - // ltfu appointment by gender - $appointment_ltfu_female = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') - ->where('tbl_appointment.app_status', '=', 'LTFU') + $appointment_honoured_female = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') ->where('tbl_client.gender', '=', '1') - ->where('tbl_client.mfl_code', Auth::user()->facility_id) + ->where('tbl_appointment.date_attended', '=', 'tbl_appointment.appntmnt_date') + ->where('tbl_appointment.created_at', '>=', date($request->from))->where('tbl_appointment.created_at', '<=', date($request->to)) ->count(); - $appointment_ltfu_female = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') - ->where('tbl_appointment.app_status', '=', 'LTFU') - ->where('tbl_client.gender', '=', '2') - ->where('tbl_client.mfl_code', Auth::user()->facility_id) + $appointment_honoured_uknown_gender = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->where('tbl_client.gender', '!=', '1') + ->where('tbl_client.gender', '!=', '2') + ->where('tbl_appointment.date_attended', '=', 'tbl_appointment.appntmnt_date') + ->where('tbl_appointment.created_at', '>=', date($request->from))->where('tbl_appointment.created_at', '<=', date($request->to)) ->count(); + // appointment honored by age + $appointment_honored_to_nine = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) > 0) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 9)) then `tbl_client`.`id` end)) AS count")) + ->where('tbl_appointment.date_attended', '=', 'tbl_appointment.appntmnt_date') + ->where('tbl_appointment.created_at', '>=', date($request->from))->where('tbl_appointment.created_at', '<=', date($request->to)) + ->pluck('count'); + $appointment_honored_to_fourteen = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 10) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 14)) then `tbl_client`.`id` end)) AS count")) + ->where('tbl_appointment.date_attended', '=', 'tbl_appointment.appntmnt_date') + ->where('tbl_appointment.created_at', '>=', date($request->from))->where('tbl_appointment.created_at', '<=', date($request->to)) + ->pluck('count'); + $appointment_honored_to_nineteen = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 15) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 19)) then `tbl_client`.`id` end)) AS count")) + ->where('tbl_appointment.date_attended', '=', 'tbl_appointment.appntmnt_date') + ->where('tbl_appointment.created_at', '>=', date($request->from))->where('tbl_appointment.created_at', '<=', date($request->to)) + ->pluck('count'); - // ltfu appointment by age - $appointment_ltfu_to_nine = join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') - ->select(\DB::raw("case when (((year(curdate()) - year(`tbl_client`.`dob`)) > 0) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 9)) then `tbl_client`.`dob` end")) - ->where('tbl_appointment.app_status', '=', 'LTFU') - ->where('tbl_client.mfl_code', Auth::user()->facility_id) - ->count(); - $appointment_ltfu_to_fourteen = join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') - ->select(\DB::raw("case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 10) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 14)) then `tbl_client`.`dob` end")) - ->where('tbl_appointment.app_status', '=', 'LTFU') - ->where('tbl_client.mfl_code', Auth::user()->facility_id) - ->count(); - $appointment_ltfu_to_nineteen = join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') - ->select(\DB::raw("case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 15) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 19)) then `tbl_client`.`dob` end")) - ->where('tbl_appointment.app_status', '=', 'LTFU') - ->where('tbl_client.mfl_code', Auth::user()->facility_id) + $appointment_honored_to_twentyfour = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 20) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 24)) then `tbl_client`.`id` end)) AS count")) + ->where('tbl_appointment.date_attended', '=', 'tbl_appointment.appntmnt_date') + ->where('tbl_appointment.created_at', '>=', date($request->from))->where('tbl_appointment.created_at', '<=', date($request->to)) + ->pluck('count'); + $appointment_honored_to_twentyfive_above = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 25)) then `tbl_client`.`id` end)) AS count")) + ->where('tbl_appointment.date_attended', '=', 'tbl_appointment.appntmnt_date') + ->where('tbl_appointment.created_at', '>=', date($request->from))->where('tbl_appointment.created_at', '<=', date($request->to)) + ->pluck('count'); + $appointment_honored_to_uknown_age = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->select('tbl_client.dob') + ->where('tbl_client.dob', '=', '') + ->orWhereNull('tbl_client.dob') + ->where('tbl_appointment.date_attended', '=', 'tbl_appointment.appntmnt_date') + ->where('tbl_appointment.created_at', '>=', date($request->from))->where('tbl_appointment.created_at', '<=', date($request->to)) ->count(); - $appointment_ltfu_to_twentyfour = join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') - ->select(\DB::raw("case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 20) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 24)) then `tbl_client`.`dob` end")) - ->where('tbl_appointment.app_status', '=', 'LTFU') - ->where('tbl_client.mfl_code', Auth::user()->facility_id) + + // appointment not honored by gender + $appointment_not_honoured_male = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->where('tbl_client.gender', '=', '2') + ->where('tbl_appointment.app_status', '=', 'Missed') + ->orwhere('tbl_appointment.app_status', '=', 'LTFU') + ->orwhere('tbl_appointment.app_status', '=', 'Defaulted') + ->where('tbl_appointment.created_at', '>=', date($request->from))->where('tbl_appointment.created_at', '<=', date($request->to)) ->count(); - $appointment_ltfu_to_twentyfive_above = join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') - ->select(\DB::raw("case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 25) then `tbl_client`.`dob` end")) - ->where('tbl_appointment.app_status', '=', 'LTFU') - ->where('tbl_client.mfl_code', Auth::user()->facility_id) + $appointment_not_honoured_female = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->where('tbl_client.gender', '=', '1') + ->where('tbl_appointment.app_status', '=', 'Missed') + ->orwhere('tbl_appointment.app_status', '=', 'LTFU') + ->orwhere('tbl_appointment.app_status', '=', 'Defaulted') + ->where('tbl_appointment.created_at', '>=', date($request->from))->where('tbl_appointment.created_at', '<=', date($request->to)) ->count(); - } - if (Auth::user()->access_level == 'Partner') { - // main dashboard all - $appointment_total_missed = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') - ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') - ->where('tbl_appointment.date_attended', '!=', 'tbl_appointment.appntmnt_date') - ->where('tbl_client.partner_id', Auth::user()->partner_id) + $appointment_not_honoured_uknown_gender = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->where('tbl_client.gender', '!=', '1') + ->where('tbl_client.gender', '!=', '2') + ->where('tbl_appointment.app_status', '=', 'Missed') + ->orwhere('tbl_appointment.app_status', '=', 'LTFU') + ->orwhere('tbl_appointment.app_status', '=', 'Defaulted') + ->where('tbl_appointment.created_at', '>=', date($request->from))->where('tbl_appointment.created_at', '<=', date($request->to)) ->count(); - $appointment_missed = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + // appointment not honored by age + $appointment_not_honored_to_nine = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) > 0) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 9)) then `tbl_client`.`id` end)) AS count")) ->where('tbl_appointment.app_status', '=', 'Missed') - ->where('tbl_client.partner_id', Auth::user()->partner_id) - ->count(); - $appointment_defaulted = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->orwhere('tbl_appointment.app_status', '=', 'LTFU') + ->orwhere('tbl_appointment.app_status', '=', 'Defaulted') + ->where('tbl_appointment.created_at', '>=', date($request->from))->where('tbl_appointment.created_at', '<=', date($request->to)) + ->pluck('count'); + $appointment_not_honored_to_fourteen = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') - ->where('tbl_appointment.app_status', '=', 'Defaulted') - ->where('tbl_client.partner_id', Auth::user()->partner_id) - ->count(); - $appointment_lftu = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 10) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 14)) then `tbl_client`.`id` end)) AS count")) + ->where('tbl_appointment.app_status', '=', 'Missed') + ->orwhere('tbl_appointment.app_status', '=', 'LTFU') + ->orwhere('tbl_appointment.app_status', '=', 'Defaulted') + ->where('tbl_appointment.created_at', '>=', date($request->from))->where('tbl_appointment.created_at', '<=', date($request->to)) + ->pluck('count'); + $appointment_not_honored_to_nineteen = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') - ->where('tbl_appointment.app_status', '=', 'LTFU') - ->where('tbl_client.partner_id', Auth::user()->partner_id) - ->count(); - - // Total missed appointment by gender - $appointment_total_missed_female = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 15) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 19)) then `tbl_client`.`id` end)) AS count")) + ->where('tbl_appointment.app_status', '=', 'Missed') + ->orwhere('tbl_appointment.app_status', '=', 'LTFU') + ->orwhere('tbl_appointment.app_status', '=', 'Defaulted') + ->where('tbl_appointment.created_at', '>=', date($request->from))->where('tbl_appointment.created_at', '<=', date($request->to)) + ->pluck('count'); + $appointment_not_honored_to_twentyfour = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') - ->where('tbl_appointment.date_attended', '!=', 'tbl_appointment.appntmnt_date') - ->where('tbl_client.gender', '=', '1') - ->where('tbl_client.partner_id', Auth::user()->partner_id) - ->count(); - $appointment_total_missed_male = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 20) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 24)) then `tbl_client`.`id` end)) AS count")) + ->where('tbl_appointment.app_status', '=', 'Missed') + ->orwhere('tbl_appointment.app_status', '=', 'LTFU') + ->orwhere('tbl_appointment.app_status', '=', 'Defaulted') + ->where('tbl_appointment.created_at', '>=', date($request->from))->where('tbl_appointment.created_at', '<=', date($request->to)) + ->pluck('count'); + $appointment_not_honored_to_twentyfive_above = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') - ->where('tbl_appointment.date_attended', '!=', 'tbl_appointment.appntmnt_date') - ->where('tbl_client.gender', '=', '2') - ->where('tbl_client.partner_id', Auth::user()->partner_id) + ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 25)) then `tbl_client`.`id` end)) AS count")) + ->where('tbl_appointment.app_status', '=', 'Missed') + ->orwhere('tbl_appointment.app_status', '=', 'LTFU') + ->orwhere('tbl_appointment.app_status', '=', 'Defaulted') + ->where('tbl_appointment.created_at', '>=', date($request->from))->where('tbl_appointment.created_at', '<=', date($request->to)) + ->pluck('count'); + $appointment_not_honored_to_uknown_age = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->select('tbl_client.dob') + ->where('tbl_client.dob', '=', '') + ->orWhereNull('tbl_client.dob') + ->where('tbl_appointment.app_status', '=', 'Missed') + ->orwhere('tbl_appointment.app_status', '=', 'LTFU') + ->orwhere('tbl_appointment.app_status', '=', 'Defaulted') + ->where('tbl_appointment.created_at', '>=', date($request->from))->where('tbl_appointment.created_at', '<=', date($request->to)) ->count(); + // missed appointments - // Total missed appointment by age - $appointment_total_missed_to_nine = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') - ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') - ->select(\DB::raw("case when (((year(curdate()) - year(`tbl_client`.`dob`)) > 0) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 9)) then `tbl_client`.`dob` end")) - ->where('tbl_appointment.date_attended', '!=', 'tbl_appointment.appntmnt_date') - ->where('tbl_client.partner_id', Auth::user()->partner_id) - ->count(); - $appointment_total_missed_to_fourteen = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') - ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') - ->select(\DB::raw("case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 10) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 14)) then `tbl_client`.`dob` end")) - ->where('tbl_appointment.date_attended', '!=', 'tbl_appointment.appntmnt_date') - ->where('tbl_client.partner_id', Auth::user()->partner_id) - ->count(); - $appointment_total_missed_to_nineteen = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') - ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') - ->select(\DB::raw("case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 15) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 19)) then `tbl_client`.`dob` end")) - ->where('tbl_appointment.date_attended', '!=', 'tbl_appointment.appntmnt_date') - ->where('tbl_client.partner_id', Auth::user()->partner_id) + $appointment_missed = Appointments::where('app_status', '=', 'Missed') + ->where('created_at', '>=', date($request->from))->where('created_at', '<=', date($request->to)) ->count(); - $appointment_total_missed_to_twentyfour = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') - ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') - ->select(\DB::raw("case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 20) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 24)) then `tbl_client`.`dob` end")) - ->where('tbl_appointment.date_attended', '!=', 'tbl_appointment.appntmnt_date') - ->where('tbl_client.partner_id', Auth::user()->partner_id) + $appointment_defaulted = Appointments::where('app_status', '=', 'Defaulted') + ->where('created_at', '>=', date($request->from))->where('created_at', '<=', date($request->to)) ->count(); - $appointment_total_missed_to_twentyfive_above = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') - ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') - ->select(\DB::raw("case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 25) then `tbl_client`.`dob` end")) - ->where('tbl_appointment.date_attended', '!=', 'tbl_appointment.appntmnt_date') - ->where('tbl_client.partner_id', Auth::user()->partner_id) + $appointment_lftu = Appointments::where('app_status', '=', 'LTFU') + ->where('created_at', '>=', date($request->from))->where('created_at', '<=', date($request->to)) ->count(); // missed appointment by gender $appointment_missed_female = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') - ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') ->where('tbl_appointment.app_status', '=', 'Missed') ->where('tbl_client.gender', '=', '1') - ->where('tbl_client.partner_id', Auth::user()->partner_id) + ->where('tbl_appointment.created_at', '>=', date($request->from))->where('tbl_appointment.created_at', '<=', date($request->to)) ->count(); $appointment_missed_male = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') - ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') ->where('tbl_appointment.app_status', '=', 'Missed') - ->where('tbl_client.gender', '=', '1') - ->where('tbl_client.partner_id', Auth::user()->partner_id) + ->where('tbl_client.gender', '=', '2') + ->where('tbl_appointment.created_at', '>=', date($request->from))->where('tbl_appointment.created_at', '<=', date($request->to)) + ->count(); + $appointment_missed_uknown_gender = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->where('tbl_appointment.app_status', '=', 'Missed') + ->where('tbl_client.gender', '!=', '1') + ->where('tbl_client.gender', '!=', '2') + ->where('tbl_appointment.created_at', '>=', date($request->from))->where('tbl_appointment.created_at', '<=', date($request->to)) ->count(); - // missed appointment by age $appointment_missed_to_nine = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') - ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') - ->select(\DB::raw("case when (((year(curdate()) - year(`tbl_client`.`dob`)) > 0) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 9)) then `tbl_client`.`dob` end")) + ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) > 0) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 9)) then `tbl_client`.`id` end)) AS count")) ->where('tbl_appointment.app_status', '=', 'Missed') - ->where('tbl_client.partner_id', Auth::user()->partner_id) - ->count(); + ->where('tbl_appointment.created_at', '>=', date($request->from))->where('tbl_appointment.created_at', '<=', date($request->to)) + ->pluck('count'); $appointment_missed_to_fourteen = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') - ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') - ->select(\DB::raw("case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 10) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 14)) then `tbl_client`.`dob` end")) + ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 10) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 14)) then `tbl_client`.`id` end)) AS count")) ->where('tbl_appointment.app_status', '=', 'Missed') - ->where('tbl_client.partner_id', Auth::user()->partner_id) - ->count(); + ->where('tbl_appointment.created_at', '>=', date($request->from))->where('tbl_appointment.created_at', '<=', date($request->to)) + ->pluck('count'); $appointment_missed_to_nineteen = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') - ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') - ->select(\DB::raw("case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 15) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 19)) then `tbl_client`.`dob` end")) + ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 15) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 19)) then `tbl_client`.`id` end)) AS count")) ->where('tbl_appointment.app_status', '=', 'Missed') - ->where('tbl_client.partner_id', Auth::user()->partner_id) - ->count(); + ->where('tbl_appointment.created_at', '>=', date($request->from))->where('tbl_appointment.created_at', '<=', date($request->to)) + ->pluck('count'); $appointment_missed_to_twentyfour = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') - ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') - ->select(\DB::raw("case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 20) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 24)) then `tbl_client`.`dob` end")) + ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 20) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 24)) then `tbl_client`.`id` end)) AS count")) ->where('tbl_appointment.app_status', '=', 'Missed') - ->where('tbl_client.partner_id', Auth::user()->partner_id) - ->count(); + ->where('tbl_appointment.created_at', '>=', date($request->from))->where('tbl_appointment.created_at', '<=', date($request->to)) + ->pluck('count'); $appointment_missed_to_twentyfive_above = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') - ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') - ->select(\DB::raw("case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 25) then `tbl_client`.`dob` end")) + ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 25)) then `tbl_client`.`id` end)) AS count")) + ->where('tbl_appointment.app_status', '=', 'Missed') + ->where('tbl_appointment.created_at', '>=', date($request->from))->where('tbl_appointment.created_at', '<=', date($request->to)) + ->pluck('count'); + $appointment_missed_to_uknown_age = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->select('tbl_client.dob') + ->where('tbl_client.dob', '=', '') + ->orWhereNull('tbl_client.dob') ->where('tbl_appointment.app_status', '=', 'Missed') - ->where('tbl_client.partner_id', Auth::user()->partner_id) + ->where('tbl_appointment.created_at', '>=', date($request->from))->where('tbl_appointment.created_at', '<=', date($request->to)) ->count(); - // defaulted appointment by gender $appointment_defaulted_female = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') - ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') ->where('tbl_appointment.app_status', '=', 'Defaulted') ->where('tbl_client.gender', '=', '1') - ->where('tbl_client.partner_id', Auth::user()->partner_id) + ->where('tbl_appointment.created_at', '>=', date($request->from))->where('tbl_appointment.created_at', '<=', date($request->to)) ->count(); - $appointment_defaulted_female = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') - ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + $appointment_defaulted_male = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') ->where('tbl_appointment.app_status', '=', 'Defaulted') ->where('tbl_client.gender', '=', '2') - ->where('tbl_client.partner_id', Auth::user()->partner_id) + ->where('tbl_appointment.created_at', '>=', date($request->from))->where('tbl_appointment.created_at', '<=', date($request->to)) + ->count(); + $appointment_defaulted_uknown_gender = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->where('tbl_appointment.app_status', '=', 'Defaulted') + ->where('tbl_client.gender', '!=', '1') + ->where('tbl_client.gender', '!=', '2') + ->where('tbl_appointment.created_at', '>=', date($request->from))->where('tbl_appointment.created_at', '<=', date($request->to)) ->count(); // defaulted appointment by age - $appointment_defaulted_to_nine = join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') - ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') - ->select(\DB::raw("case when (((year(curdate()) - year(`tbl_client`.`dob`)) > 0) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 9)) then `tbl_client`.`dob` end")) + $appointment_defaulted_to_nine = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) > 0) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 9)) then `tbl_client`.`id` end)) AS count")) ->where('tbl_appointment.app_status', '=', 'Defaulted') - ->where('tbl_client.partner_id', Auth::user()->partner_id) - ->count(); - $appointment_defaulted_to_fourteen = join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') - ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') - ->select(\DB::raw("case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 10) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 14)) then `tbl_client`.`dob` end")) + ->where('tbl_appointment.created_at', '>=', date($request->from))->where('tbl_appointment.created_at', '<=', date($request->to)) + ->pluck('count'); + $appointment_defaulted_to_fourteen = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 10) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 14)) then `tbl_client`.`id` end)) AS count")) ->where('tbl_appointment.app_status', '=', 'Defaulted') - ->where('tbl_client.partner_id', Auth::user()->partner_id) - ->count(); - $appointment_defaulted_to_nineteen = join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') - ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') - ->select(\DB::raw("case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 15) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 19)) then `tbl_client`.`dob` end")) + ->where('tbl_appointment.created_at', '>=', date($request->from))->where('tbl_appointment.created_at', '<=', date($request->to)) + ->pluck('count'); + $appointment_defaulted_to_nineteen = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 15) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 19)) then `tbl_client`.`id` end)) AS count")) ->where('tbl_appointment.app_status', '=', 'Defaulted') - ->where('tbl_client.partner_id', Auth::user()->partner_id) - ->count(); - $appointment_defaulted_to_twentyfour = join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') - ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') - ->select(\DB::raw("case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 20) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 24)) then `tbl_client`.`dob` end")) + ->where('tbl_appointment.created_at', '>=', date($request->from))->where('tbl_appointment.created_at', '<=', date($request->to)) + ->pluck('count'); + $appointment_defaulted_to_twentyfour = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 20) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 24)) then `tbl_client`.`id` end)) AS count")) ->where('tbl_appointment.app_status', '=', 'Defaulted') - ->where('tbl_client.partner_id', Auth::user()->partner_id) - ->count(); - $appointment_defaulted_to_twentyfive_above = join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') - ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') - ->select(\DB::raw("case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 25) then `tbl_client`.`dob` end")) + ->where('tbl_appointment.created_at', '>=', date($request->from))->where('tbl_appointment.created_at', '<=', date($request->to)) + ->pluck('count'); + $appointment_defaulted_to_twentyfive_above = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 25)) then `tbl_client`.`id` end)) AS count")) ->where('tbl_appointment.app_status', '=', 'Defaulted') - ->where('tbl_client.partner_id', Auth::user()->partner_id) + ->where('tbl_appointment.created_at', '>=', date($request->from))->where('tbl_appointment.created_at', '<=', date($request->to)) + ->pluck('count'); + $appointment_defaulted_to_uknown_age = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->select('tbl_client.dob') + ->where('tbl_client.dob', '=', '') + ->orWhereNull('tbl_client.dob') + ->where('tbl_appointment.app_status', '=', 'Defaulted') + ->where('tbl_appointment.created_at', '>=', date($request->from))->where('tbl_appointment.created_at', '<=', date($request->to)) ->count(); - // ltfu appointment by gender $appointment_ltfu_female = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') - ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') ->where('tbl_appointment.app_status', '=', 'LTFU') ->where('tbl_client.gender', '=', '1') - ->where('tbl_client.partner_id', Auth::user()->partner_id) + ->where('tbl_appointment.created_at', '>=', date($request->from))->where('tbl_appointment.created_at', '<=', date($request->to)) ->count(); - $appointment_ltfu_female = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') - ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + $appointment_ltfu_male = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') ->where('tbl_appointment.app_status', '=', 'LTFU') ->where('tbl_client.gender', '=', '2') - ->where('tbl_client.partner_id', Auth::user()->partner_id) + ->where('tbl_appointment.created_at', '>=', date($request->from))->where('tbl_appointment.created_at', '<=', date($request->to)) + ->count(); + $appointment_ltfu_uknown_gender = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->where('tbl_appointment.app_status', '=', 'LTFU') + ->where('tbl_client.gender', '!=', '1') + ->where('tbl_client.gender', '!=', '2') + ->where('tbl_appointment.created_at', '>=', date($request->from))->where('tbl_appointment.created_at', '<=', date($request->to)) ->count(); // ltfu appointment by age - $appointment_ltfu_to_nine = join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') - ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') - ->select(\DB::raw("case when (((year(curdate()) - year(`tbl_client`.`dob`)) > 0) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 9)) then `tbl_client`.`dob` end")) + $appointment_ltfu_to_nine = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) > 0) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 9)) then `tbl_client`.`id` end)) AS count")) ->where('tbl_appointment.app_status', '=', 'LTFU') - ->where('tbl_client.partner_id', Auth::user()->partner_id) - ->count(); - $appointment_ltfu_to_fourteen = join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') - ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') - ->select(\DB::raw("case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 10) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 14)) then `tbl_client`.`dob` end")) + ->where('tbl_appointment.created_at', '>=', date($request->from))->where('tbl_appointment.created_at', '<=', date($request->to)) + ->pluck('count'); + $appointment_ltfu_to_fourteen = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 10) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 14)) then `tbl_client`.`id` end)) AS count")) ->where('tbl_appointment.app_status', '=', 'LTFU') - ->where('tbl_client.partner_id', Auth::user()->partner_id) - ->count(); - $appointment_ltfu_to_nineteen = join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') - ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') - ->select(\DB::raw("case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 15) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 19)) then `tbl_client`.`dob` end")) + ->where('tbl_appointment.created_at', '>=', date($request->from))->where('tbl_appointment.created_at', '<=', date($request->to)) + ->pluck('count'); + $appointment_ltfu_to_nineteen = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 15) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 19)) then `tbl_client`.`id` end)) AS count")) ->where('tbl_appointment.app_status', '=', 'LTFU') - ->where('tbl_client.partner_id', Auth::user()->partner_id) - ->count(); - $appointment_ltfu_to_twentyfour = join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') - ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') - ->select(\DB::raw("case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 20) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 24)) then `tbl_client`.`dob` end")) + ->where('tbl_appointment.created_at', '>=', date($request->from))->where('tbl_appointment.created_at', '<=', date($request->to)) + ->pluck('count'); + $appointment_ltfu_to_twentyfour = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 20) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 24)) then `tbl_client`.`id` end)) AS count")) ->where('tbl_appointment.app_status', '=', 'LTFU') - ->where('tbl_client.partner_id', Auth::user()->partner_id) - ->count(); - $appointment_ltfu_to_twentyfive_above = join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') - ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') - ->select(\DB::raw("case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 25) then `tbl_client`.`dob` end")) + ->where('tbl_appointment.created_at', '>=', date($request->from))->where('tbl_appointment.created_at', '<=', date($request->to)) + ->pluck('count'); + $appointment_ltfu_to_twentyfive_above = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 25)) then `tbl_client`.`id` end)) AS count")) + ->where('tbl_appointment.app_status', '=', 'LTFU') + ->where('tbl_appointment.created_at', '>=', date($request->from))->where('tbl_appointment.created_at', '<=', date($request->to)) + ->pluck('count'); + $appointment_ltfu_to_uknown_age = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->select('tbl_client.dob') + ->where('tbl_client.dob', '=', '') + ->orWhereNull('tbl_client.dob') ->where('tbl_appointment.app_status', '=', 'LTFU') - ->where('tbl_client.partner_id', Auth::user()->partner_id) + ->where('tbl_appointment.created_at', '>=', date($request->from))->where('tbl_appointment.created_at', '<=', date($request->to)) ->count(); } + return view('new_dashboard.main_dashbaord', compact( + 'all_partners', + 'active_facilities', + 'indicator', + 'client', + 'appointment', + 'missed_appointment', + 'clients_male', + 'clients_female', + 'unknown_gender', + 'client_to_nine', + 'client_to_fourteen', + 'client_to_nineteen', + 'client_to_twentyfour', + 'client_to_twentyfive_above', + 'client_unknown_age', + 'appointment_male', + 'appointment_female', + 'appointment_uknown_gender', + 'appointment_to_nine', + 'appointment_to_fourteen', + 'appointment_to_nineteen', + 'appointment_to_twentyfour', + 'appointment_to_twentyfive_above', + 'appointment_uknown_age', + 'appointment_total_missed_female', + 'appointment_total_missed_male', + 'appointment_total_missed_uknown_gender', + 'appointment_total_missed_to_nine', + 'appointment_total_missed_to_fourteen', + 'appointment_total_missed_to_nineteen', + 'appointment_total_missed_to_twentyfour', + 'appointment_total_missed_to_twentyfive_above', + 'appointment_total_missed_uknown_age', + 'client_consented', + 'client_nonconsented', + 'client_consented_male', + 'client_consented_female', + 'client_consented_uknown_gender', + 'client_nonconsented_male', + 'client_nonconsented_female', + 'client_nonconsented_uknown_gender', + 'client_consented_to_nine', + 'client_consented_to_fourteen', + 'client_consented_to_nineteen', + 'client_consented_to_twentyfour', + 'client_consented_to_twentyfive_above', + 'client_consented_uknown_age', + 'client_nonconsented_to_nine', + 'client_nonconsented_to_fourteen', + 'client_nonconsented_to_nineteen', + 'client_nonconsented_to_twentyfour', + 'client_nonconsented_to_twentyfive_above', + 'client_nonconsented_uknown_age', + 'appointment_honoured', + 'appointment_not_honoured', + 'appointment_honoured_male', + 'appointment_honoured_female', + 'appointment_honoured_uknown_gender', + 'appointment_honored_to_nine', + 'appointment_honored_to_fourteen', + 'appointment_honored_to_nineteen', + 'appointment_honored_to_twentyfour', + 'appointment_honored_to_twentyfive_above', + 'appointment_honored_to_uknown_age', + 'appointment_not_honoured_male', + 'appointment_not_honoured_female', + 'appointment_not_honoured_uknown_gender', + 'appointment_not_honored_to_nine', + 'appointment_not_honored_to_fourteen', + 'appointment_not_honored_to_nineteen', + 'appointment_not_honored_to_twentyfour', + 'appointment_not_honored_to_twentyfive_above', + 'appointment_not_honored_to_uknown_age', + 'appointment_missed', + 'appointment_defaulted', + 'appointment_lftu', + 'appointment_missed_female', + 'appointment_missed_male', + 'appointment_missed_uknown_gender', + 'appointment_missed_to_nine', + 'appointment_missed_to_fourteen', + 'appointment_missed_to_nineteen', + 'appointment_missed_to_twentyfour', + 'appointment_missed_to_twentyfive_above', + 'appointment_missed_to_uknown_age', + 'appointment_defaulted_female', + 'appointment_defaulted_male', + 'appointment_defaulted_uknown_gender', + 'appointment_defaulted_to_nine', + 'appointment_defaulted_to_fourteen', + 'appointment_defaulted_to_nineteen', + 'appointment_defaulted_to_twentyfour', + 'appointment_defaulted_to_twentyfive_above', + 'appointment_defaulted_to_uknown_age', + 'appointment_ltfu_female', + 'appointment_ltfu_male', + 'appointment_ltfu_uknown_gender', + 'appointment_ltfu_to_nine', + 'appointment_ltfu_to_fourteen', + 'appointment_ltfu_to_nineteen', + 'appointment_ltfu_to_twentyfour', + 'appointment_ltfu_to_twentyfive_above', + 'appointment_ltfu_to_uknown_age' + + )); + } + } diff --git a/app/Models/AgeDashboard.php b/app/Models/AgeDashboard.php new file mode 100644 index 0000000..220825f --- /dev/null +++ b/app/Models/AgeDashboard.php @@ -0,0 +1,18 @@ +belongsTo('App\Models\Client','client_id','id'); + return $this->belongsTo('App\Models\Client','client_id'); } } diff --git a/app/Models/Client.php b/app/Models/Client.php index 60d083a..b72e7f2 100644 --- a/app/Models/Client.php +++ b/app/Models/Client.php @@ -16,9 +16,12 @@ class Client extends Model 'clinic_number', 'consent_date', 'smsenable', 'language_id', 'motivational_enable', 'txt_time', 'phone_no' ]; - public function age() { - return $this->dob->diffInYears(\Carbon::now()); - } +// protected $appends = ['age']; + +// public function getAgeAttribute() +// { +// return Carbon::parse($this->attributes['dob'])->age; +// } } diff --git a/app/Models/GenderDashboard.php b/app/Models/GenderDashboard.php new file mode 100644 index 0000000..2cafdad --- /dev/null +++ b/app/Models/GenderDashboard.php @@ -0,0 +1,11 @@ +dob->diffInYears(\Carbon\Carbon::now())->format('Y-m-d'); + return Carbon::parse($this->attributes['dob'])->age; +} /** * The attributes that should be hidden for arrays. diff --git a/composer.json b/composer.json index ec5c9c4..1a23796 100644 --- a/composer.json +++ b/composer.json @@ -18,9 +18,11 @@ "laravel/tinker": "^2.0", "laravel/ui": "^3.2", "maatwebsite/excel": "^3.1", - "nesbot/carbon": "^2.45" + "nesbot/carbon": "^2.45", + "predis/predis": "^1.1" }, "require-dev": { + "barryvdh/laravel-debugbar": "^3.6", "facade/ignition": "^2.3.6", "fzaninotto/faker": "^1.9.1", "mockery/mockery": "^1.3.1", diff --git a/composer.lock b/composer.lock index 06c0d71..6d87b3a 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "d34d3ad4c67480c131eb400b0f9e8263", + "content-hash": "3bb8458a55e3bbc780c4aa16f6040e7f", "packages": [ { "name": "acaronlex/laravel-calendar", @@ -2456,6 +2456,62 @@ ], "time": "2021-12-04T23:24:31+00:00" }, + { + "name": "predis/predis", + "version": "v1.1.10", + "source": { + "type": "git", + "url": "https://github.com/predis/predis.git", + "reference": "a2fb02d738bedadcffdbb07efa3a5e7bd57f8d6e" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/predis/predis/zipball/a2fb02d738bedadcffdbb07efa3a5e7bd57f8d6e", + "reference": "a2fb02d738bedadcffdbb07efa3a5e7bd57f8d6e", + "shasum": "" + }, + "require": { + "php": ">=5.3.9" + }, + "require-dev": { + "phpunit/phpunit": "~4.8" + }, + "suggest": { + "ext-curl": "Allows access to Webdis when paired with phpiredis", + "ext-phpiredis": "Allows faster serialization and deserialization of the Redis protocol" + }, + "type": "library", + "autoload": { + "psr-4": { + "Predis\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Daniele Alessandri", + "email": "suppakilla@gmail.com", + "homepage": "http://clorophilla.net", + "role": "Creator & Maintainer" + }, + { + "name": "Till Krüss", + "homepage": "https://till.im", + "role": "Maintainer" + } + ], + "description": "Flexible and feature-complete Redis client for PHP and HHVM", + "homepage": "http://github.com/predis/predis", + "keywords": [ + "nosql", + "predis", + "redis" + ], + "time": "2022-01-05T17:46:08+00:00" + }, { "name": "psr/container", "version": "1.1.2", @@ -5074,6 +5130,77 @@ } ], "packages-dev": [ + { + "name": "barryvdh/laravel-debugbar", + "version": "v3.6.7", + "source": { + "type": "git", + "url": "https://github.com/barryvdh/laravel-debugbar.git", + "reference": "b96f9820aaf1ff9afe945207883149e1c7afb298" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/barryvdh/laravel-debugbar/zipball/b96f9820aaf1ff9afe945207883149e1c7afb298", + "reference": "b96f9820aaf1ff9afe945207883149e1c7afb298", + "shasum": "" + }, + "require": { + "illuminate/routing": "^6|^7|^8|^9", + "illuminate/session": "^6|^7|^8|^9", + "illuminate/support": "^6|^7|^8|^9", + "maximebf/debugbar": "^1.17.2", + "php": ">=7.2", + "symfony/debug": "^4.3|^5|^6", + "symfony/finder": "^4.3|^5|^6" + }, + "require-dev": { + "mockery/mockery": "^1.3.3", + "orchestra/testbench-dusk": "^4|^5|^6|^7", + "phpunit/phpunit": "^8.5|^9.0", + "squizlabs/php_codesniffer": "^3.5" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "3.6-dev" + }, + "laravel": { + "providers": [ + "Barryvdh\\Debugbar\\ServiceProvider" + ], + "aliases": { + "Debugbar": "Barryvdh\\Debugbar\\Facades\\Debugbar" + } + } + }, + "autoload": { + "files": [ + "src/helpers.php" + ], + "psr-4": { + "Barryvdh\\Debugbar\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Barry vd. Heuvel", + "email": "barryvdh@gmail.com" + } + ], + "description": "PHP Debugbar integration for Laravel", + "keywords": [ + "debug", + "debugbar", + "laravel", + "profiler", + "webprofiler" + ], + "time": "2022-02-09T07:52:32+00:00" + }, { "name": "composer/package-versions-deprecated", "version": "1.11.99.5", @@ -5804,6 +5931,68 @@ ], "time": "2020-07-09T08:09:16+00:00" }, + { + "name": "maximebf/debugbar", + "version": "v1.18.0", + "source": { + "type": "git", + "url": "https://github.com/maximebf/php-debugbar.git", + "reference": "0d44b75f3b5d6d41ae83b79c7a4bceae7fbc78b6" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/maximebf/php-debugbar/zipball/0d44b75f3b5d6d41ae83b79c7a4bceae7fbc78b6", + "reference": "0d44b75f3b5d6d41ae83b79c7a4bceae7fbc78b6", + "shasum": "" + }, + "require": { + "php": "^7.1|^8", + "psr/log": "^1|^2|^3", + "symfony/var-dumper": "^2.6|^3|^4|^5|^6" + }, + "require-dev": { + "phpunit/phpunit": "^7.5.20 || ^9.4.2", + "twig/twig": "^1.38|^2.7|^3.0" + }, + "suggest": { + "kriswallsmith/assetic": "The best way to manage assets", + "monolog/monolog": "Log using Monolog", + "predis/predis": "Redis storage" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.17-dev" + } + }, + "autoload": { + "psr-4": { + "DebugBar\\": "src/DebugBar/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Maxime Bouroumeau-Fuseau", + "email": "maxime.bouroumeau@gmail.com", + "homepage": "http://maximebf.com" + }, + { + "name": "Barry vd. Heuvel", + "email": "barryvdh@gmail.com" + } + ], + "description": "Debug bar in the browser for php application", + "homepage": "https://github.com/maximebf/php-debugbar", + "keywords": [ + "debug", + "debugbar" + ], + "time": "2021-12-27T18:49:48+00:00" + }, { "name": "mockery/mockery", "version": "1.4.4", @@ -7569,6 +7758,57 @@ "homepage": "https://github.com/sebastianbergmann/version", "time": "2020-09-28T06:39:44+00:00" }, + { + "name": "symfony/debug", + "version": "v4.4.37", + "source": { + "type": "git", + "url": "https://github.com/symfony/debug.git", + "reference": "5de6c6e7f52b364840e53851c126be4d71e60470" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/symfony/debug/zipball/5de6c6e7f52b364840e53851c126be4d71e60470", + "reference": "5de6c6e7f52b364840e53851c126be4d71e60470", + "shasum": "" + }, + "require": { + "php": ">=7.1.3", + "psr/log": "^1|^2|^3" + }, + "conflict": { + "symfony/http-kernel": "<3.4" + }, + "require-dev": { + "symfony/http-kernel": "^3.4|^4.0|^5.0" + }, + "type": "library", + "autoload": { + "psr-4": { + "Symfony\\Component\\Debug\\": "" + }, + "exclude-from-classmap": [ + "/Tests/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Fabien Potencier", + "email": "fabien@symfony.com" + }, + { + "name": "Symfony Community", + "homepage": "https://symfony.com/contributors" + } + ], + "description": "Provides tools to ease debugging PHP code", + "homepage": "https://symfony.com", + "time": "2022-01-02T09:41:36+00:00" + }, { "name": "theseer/tokenizer", "version": "1.2.1", diff --git a/config/app.php b/config/app.php index 201f1ce..b797cff 100644 --- a/config/app.php +++ b/config/app.php @@ -175,6 +175,7 @@ App\Providers\EventServiceProvider::class, App\Providers\RouteServiceProvider::class, Maatwebsite\Excel\ExcelServiceProvider::class, + Barryvdh\Debugbar\ServiceProvider::class, // MaddHatter\LaravelFullcalendar\ServiceProvider::class, diff --git a/resources/views/new_dashboard/main_dashbaord.blade.php b/resources/views/new_dashboard/main_dashbaord.blade.php index 64cff8a..6d98c57 100644 --- a/resources/views/new_dashboard/main_dashbaord.blade.php +++ b/resources/views/new_dashboard/main_dashbaord.blade.php @@ -15,7 +15,7 @@
-
+ {{ csrf_field() }}
@@ -69,21 +69,39 @@
-
-
-
- - -
- -
- +
+
+
+ +
+ + +
+
+ +
+
+
+
+
+
+
+
+ +
+ + +
+
+ +
+
+
-
- -
-
-
@@ -99,16 +117,16 @@ @endif - - + + + + + + + +
@@ -263,6 +518,74 @@ var Appointment_total_missed_to_twentyfive_above = ; var Appointment_total_missed_uknown_age = ; + var Client_consented_male = ; + var Client_consented_female = ; + var Client_consented_uknown_gender = ; + var Client_nonconsented_male = ; + var Client_nonconsented_female = ; + var Client_nonconsented_uknown_gender = ; + var Client_consented_to_nine = ; + var Client_consented_to_fourteen = ; + var Client_consented_to_nineteen = ; + var Client_consented_to_twentyfour = ; + var Client_consented_to_twentyfive_above = ; + var Client_consented_uknown_age = ; + var Client_nonconsented_to_nine = ; + var Client_nonconsented_to_fourteen = ; + var Client_nonconsented_to_nineteen = ; + var Client_nonconsented_to_twentyfour = ; + var Client_nonconsented_to_twentyfive_above = ; + var Client_nonconsented_uknown_age = ; + + + var Appointment_honoured_male = ; + var Appointment_honoured_female = ; + var Appointment_honoured_uknown_gender = ; + var Appointment_honored_to_nine = ; + var Appointment_honored_to_fourteen = ; + var Appointment_honored_to_nineteen = ; + var Appointment_honored_to_twentyfour = ; + var Appointment_honored_to_twentyfive_above = ; + var Appointment_honored_to_uknown_age = ; + var Appointment_not_honoured_male = ; + var Appointment_not_honoured_female = ; + var Appointment_not_honoured_uknown_gender = ; + var Appointment_not_honored_to_nine = ; + var Appointment_not_honored_to_fourteen = ; + var Appointment_not_honored_to_nineteen = ; + var Appointment_not_honored_to_twentyfour = ; + var Appointment_not_honored_to_twentyfive_above = ; + var Appointment_not_honored_to_uknown_age = ; + + + var Appointment_missed_male = ; + var Appointment_missed_female = ; + var Appointment_missed_uknown_gender = ; + var Appointment_missed_to_nine = ; + var Appointment_missed_to_fourteen = ; + var Appointment_missed_to_nineteen = ; + var Appointment_missed_to_twentyfour = ; + var Appointment_missed_to_twentyfive_above = ; + var Appointment_missed_to_uknown_age = ; + var Appointment_defaulted_female = ; + var Appointment_defaulted_male = ; + var Appointment_defaulted_uknown_gender = ; + var Appointment_defaulted_to_nine = ; + var Appointment_defaulted_to_fourteen = ; + var Appointment_defaulted_to_nineteen = ; + var Appointment_defaulted_to_twentyfour = ; + var Appointment_defaulted_to_twentyfive_above = ; + var Appointment_defaulted_to_uknown_age = ; + var Appointment_ltfu_female = ; + var Appointment_ltfu_male = ; + var Appointment_ltfu_uknown_gender = ; + var Appointment_ltfu_to_nine = ; + var Appointment_ltfu_to_fourteen = ; + var Appointment_ltfu_to_nineteen = ; + var Appointment_ltfu_to_twentyfour = ; + var Appointment_ltfu_to_twentyfive_above = ; + var Appointment_ltfu_to_uknown_age = ; + $(document).ready(function() { $('select[name="partner"]').on('change', function() { @@ -638,6 +961,628 @@ }); + // CONSENTED CLIENTS GENDER + var appChart = Highcharts.chart('consented_gender', { + chart: { + type: 'column' + }, + title: { + text: 'Consented Clients By Gender' + }, + xAxis: { + categories: ['Male', 'Female', 'UKNOWN Gender'] + }, + yAxis: { + min: 0, + title: { + text: 'No of Consented Clients' + }, + stackLabels: { + enabled: true, + style: { + fontWeight: 'bold', + color: ( // theme + Highcharts.defaultOptions.title.style && + Highcharts.defaultOptions.title.style.color + ) || 'gray' + } + } + }, + tooltip: { + formatter: function() { + return '' + this.x + '
' + + this.series.name + ': ' + this.y; + } + }, + plotOptions: { + column: { + stacking: 'normal', + } + }, + series: [{ + name: 'Gender', + data: [Client_consented_male, Client_consented_female, Client_consented_uknown_gender] + }], + + }); + // CONSENTED CLIENTS AGE + var appChart = Highcharts.chart('consented_age', { + chart: { + type: 'column' + }, + title: { + text: 'Consented Clients By Age' + }, + xAxis: { + categories: ['0-9 YRS', '10-14 YRS', '15-19 YRS', '20-24 YRS', '25+ YRS', 'UKNOWN AGE'] + }, + yAxis: { + min: 0, + title: { + text: 'No of Consented Clients' + }, + stackLabels: { + enabled: true, + style: { + fontWeight: 'bold', + color: ( // theme + Highcharts.defaultOptions.title.style && + Highcharts.defaultOptions.title.style.color + ) || 'gray' + } + } + }, + tooltip: { + formatter: function() { + return '' + this.x + '
' + + this.series.name + ': ' + this.y; + } + }, + plotOptions: { + column: { + stacking: 'normal', + } + }, + series: [{ + name: 'Age', + data: [Client_consented_to_nine, Client_consented_to_fourteen, Client_consented_to_nineteen, Client_consented_to_twentyfour, Client_consented_to_twentyfive_above, Client_consented_uknown_age] + }], + + }); + + //NON CONSENTED CLIENTS GENDER + var appChart = Highcharts.chart('nonconsented_gender', { + chart: { + type: 'column' + }, + title: { + text: 'Non Consented Clients By Gender' + }, + xAxis: { + categories: ['Male', 'Female', 'UKNOWN Gender'] + }, + yAxis: { + min: 0, + title: { + text: 'No of Non Consented Clients' + }, + stackLabels: { + enabled: true, + style: { + fontWeight: 'bold', + color: ( // theme + Highcharts.defaultOptions.title.style && + Highcharts.defaultOptions.title.style.color + ) || 'gray' + } + } + }, + tooltip: { + formatter: function() { + return '' + this.x + '
' + + this.series.name + ': ' + this.y; + } + }, + plotOptions: { + column: { + stacking: 'normal', + } + }, + series: [{ + name: 'Gender', + data: [Client_nonconsented_male, Client_nonconsented_female, Client_nonconsented_uknown_gender] + }], + + }); +// NON CONSENTED AGE + var appChart = Highcharts.chart('nonconsented_age', { + chart: { + type: 'column' + }, + title: { + text: 'Non Consented Clients By Age' + }, + xAxis: { + categories: ['0-9 YRS', '10-14 YRS', '15-19 YRS', '20-24 YRS', '25+ YRS', 'UKNOWN AGE'] + }, + yAxis: { + min: 0, + title: { + text: 'No of Non Consented Clients' + }, + stackLabels: { + enabled: true, + style: { + fontWeight: 'bold', + color: ( // theme + Highcharts.defaultOptions.title.style && + Highcharts.defaultOptions.title.style.color + ) || 'gray' + } + } + }, + tooltip: { + formatter: function() { + return '' + this.x + '
' + + this.series.name + ': ' + this.y; + } + }, + plotOptions: { + column: { + stacking: 'normal', + } + }, + series: [{ + name: 'Age', + data: [Client_nonconsented_to_nine, Client_nonconsented_to_fourteen, Client_nonconsented_to_nineteen, Client_nonconsented_to_twentyfour, Client_nonconsented_to_twentyfive_above, Client_nonconsented_uknown_age] + }], + + }); + + //APPOINTMENT HONOURED GENDER + var appChart = Highcharts.chart('appointment_honoured_gender', { + chart: { + type: 'column' + }, + title: { + text: 'Appointment Honoured By Gender' + }, + xAxis: { + categories: ['Male', 'Female', 'UKNOWN Gender'] + }, + yAxis: { + min: 0, + title: { + text: 'No of Appointment Honoured' + }, + stackLabels: { + enabled: true, + style: { + fontWeight: 'bold', + color: ( // theme + Highcharts.defaultOptions.title.style && + Highcharts.defaultOptions.title.style.color + ) || 'gray' + } + } + }, + tooltip: { + formatter: function() { + return '' + this.x + '
' + + this.series.name + ': ' + this.y; + } + }, + plotOptions: { + column: { + stacking: 'normal', + } + }, + series: [{ + name: 'Gender', + data: [Appointment_honoured_male, Appointment_honoured_female, Appointment_honoured_uknown_gender] + }], + + }); +// APPOINTMENT HONOURED AGE + var appChart = Highcharts.chart('appointment_honoured_age', { + chart: { + type: 'column' + }, + title: { + text: 'Appointment Honoured By Age' + }, + xAxis: { + categories: ['0-9 YRS', '10-14 YRS', '15-19 YRS', '20-24 YRS', '25+ YRS', 'UKNOWN AGE'] + }, + yAxis: { + min: 0, + title: { + text: 'No of Appointment Honoured' + }, + stackLabels: { + enabled: true, + style: { + fontWeight: 'bold', + color: ( // theme + Highcharts.defaultOptions.title.style && + Highcharts.defaultOptions.title.style.color + ) || 'gray' + } + } + }, + tooltip: { + formatter: function() { + return '' + this.x + '
' + + this.series.name + ': ' + this.y; + } + }, + plotOptions: { + column: { + stacking: 'normal', + } + }, + series: [{ + name: 'Age', + data: [Appointment_honored_to_nine, Appointment_honored_to_fourteen, Appointment_honored_to_nineteen, Appointment_honored_to_twentyfour, Appointment_honored_to_twentyfive_above, Appointment_honored_to_uknown_age] + }], + + }); + + //APPOINTMENT NOT HONOURED GENDER + var appChart = Highcharts.chart('appointment_not_honoured_gender', { + chart: { + type: 'column' + }, + title: { + text: 'Appointment Not Honoured By Gender' + }, + xAxis: { + categories: ['Male', 'Female', 'UKNOWN Gender'] + }, + yAxis: { + min: 0, + title: { + text: 'No of Appointment Not Honoured' + }, + stackLabels: { + enabled: true, + style: { + fontWeight: 'bold', + color: ( // theme + Highcharts.defaultOptions.title.style && + Highcharts.defaultOptions.title.style.color + ) || 'gray' + } + } + }, + tooltip: { + formatter: function() { + return '' + this.x + '
' + + this.series.name + ': ' + this.y; + } + }, + plotOptions: { + column: { + stacking: 'normal', + } + }, + series: [{ + name: 'Gender', + data: [Appointment_not_honoured_male, Appointment_not_honoured_female, Appointment_not_honoured_uknown_gender] + }], + + }); +// APPOINTMENT NOT HONOURED AGE + var appChart = Highcharts.chart('appointment_not_honoured_age', { + chart: { + type: 'column' + }, + title: { + text: 'Appointment Not Honoured By Age' + }, + xAxis: { + categories: ['0-9 YRS', '10-14 YRS', '15-19 YRS', '20-24 YRS', '25+ YRS', 'UKNOWN AGE'] + }, + yAxis: { + min: 0, + title: { + text: 'No of Appointment Not Honoured' + }, + stackLabels: { + enabled: true, + style: { + fontWeight: 'bold', + color: ( // theme + Highcharts.defaultOptions.title.style && + Highcharts.defaultOptions.title.style.color + ) || 'gray' + } + } + }, + tooltip: { + formatter: function() { + return '' + this.x + '
' + + this.series.name + ': ' + this.y; + } + }, + plotOptions: { + column: { + stacking: 'normal', + } + }, + series: [{ + name: 'Age', + data: [Appointment_not_honored_to_nine, Appointment_not_honored_to_fourteen, Appointment_not_honored_to_nineteen, Appointment_not_honored_to_twentyfour, Appointment_not_honored_to_twentyfive_above, Appointment_not_honored_to_uknown_age] + }], + + }); + + //MISSED APPOINTMENT BY GENDER + var appChart = Highcharts.chart('appointment_missed_gender', { + chart: { + type: 'column' + }, + title: { + text: 'Appointment Missed By Gender' + }, + xAxis: { + categories: ['Male', 'Female', 'UKNOWN Gender'] + }, + yAxis: { + min: 0, + title: { + text: 'No of Appointment Missed' + }, + stackLabels: { + enabled: true, + style: { + fontWeight: 'bold', + color: ( // theme + Highcharts.defaultOptions.title.style && + Highcharts.defaultOptions.title.style.color + ) || 'gray' + } + } + }, + tooltip: { + formatter: function() { + return '' + this.x + '
' + + this.series.name + ': ' + this.y; + } + }, + plotOptions: { + column: { + stacking: 'normal', + } + }, + series: [{ + name: 'Gender', + data: [Appointment_missed_male, Appointment_missed_female, Appointment_missed_uknown_gender] + }], + + }); +// APPOINTMENT MISSED AGE + var appChart = Highcharts.chart('appointment_missed_age', { + chart: { + type: 'column' + }, + title: { + text: 'Appointment Missed By Age' + }, + xAxis: { + categories: ['0-9 YRS', '10-14 YRS', '15-19 YRS', '20-24 YRS', '25+ YRS', 'UKNOWN AGE'] + }, + yAxis: { + min: 0, + title: { + text: 'No of Appointment Missed' + }, + stackLabels: { + enabled: true, + style: { + fontWeight: 'bold', + color: ( // theme + Highcharts.defaultOptions.title.style && + Highcharts.defaultOptions.title.style.color + ) || 'gray' + } + } + }, + tooltip: { + formatter: function() { + return '' + this.x + '
' + + this.series.name + ': ' + this.y; + } + }, + plotOptions: { + column: { + stacking: 'normal', + } + }, + series: [{ + name: 'Age', + data: [Appointment_missed_to_nine, Appointment_missed_to_fourteen, Appointment_missed_to_nineteen, Appointment_missed_to_twentyfour, Appointment_missed_to_twentyfive_above, Appointment_missed_to_uknown_age] + }], + + }); + //DEFAULTED APPOINTMENT BY GENDER + var appChart = Highcharts.chart('appointment_defaulted_gender', { + chart: { + type: 'column' + }, + title: { + text: 'Appointment Defaulted By Gender' + }, + xAxis: { + categories: ['Male', 'Female', 'UKNOWN Gender'] + }, + yAxis: { + min: 0, + title: { + text: 'No of Appointment Defaulted' + }, + stackLabels: { + enabled: true, + style: { + fontWeight: 'bold', + color: ( // theme + Highcharts.defaultOptions.title.style && + Highcharts.defaultOptions.title.style.color + ) || 'gray' + } + } + }, + tooltip: { + formatter: function() { + return '' + this.x + '
' + + this.series.name + ': ' + this.y; + } + }, + plotOptions: { + column: { + stacking: 'normal', + } + }, + series: [{ + name: 'Gender', + data: [Appointment_defaulted_male, Appointment_defaulted_female, Appointment_defaulted_uknown_gender] + }], + + }); +// APPOINTMENT DEFAULTED AGE + var appChart = Highcharts.chart('appointment_defaulted_age', { + chart: { + type: 'column' + }, + title: { + text: 'Appointment Defaulted By Age' + }, + xAxis: { + categories: ['0-9 YRS', '10-14 YRS', '15-19 YRS', '20-24 YRS', '25+ YRS', 'UKNOWN AGE'] + }, + yAxis: { + min: 0, + title: { + text: 'No of Appointment Defaulted' + }, + stackLabels: { + enabled: true, + style: { + fontWeight: 'bold', + color: ( // theme + Highcharts.defaultOptions.title.style && + Highcharts.defaultOptions.title.style.color + ) || 'gray' + } + } + }, + tooltip: { + formatter: function() { + return '' + this.x + '
' + + this.series.name + ': ' + this.y; + } + }, + plotOptions: { + column: { + stacking: 'normal', + } + }, + series: [{ + name: 'Age', + data: [Appointment_defaulted_to_nine, Appointment_defaulted_to_fourteen, Appointment_defaulted_to_nineteen, Appointment_defaulted_to_twentyfour, Appointment_defaulted_to_twentyfive_above, Appointment_defaulted_to_uknown_age] + }], + + }); + + //LTFU APPOINTMENT BY GENDER + var appChart = Highcharts.chart('appointment_ltfu_gender', { + chart: { + type: 'column' + }, + title: { + text: 'Appointment LTFU By Gender' + }, + xAxis: { + categories: ['Male', 'Female', 'UKNOWN Gender'] + }, + yAxis: { + min: 0, + title: { + text: 'No of Appointment LTFU' + }, + stackLabels: { + enabled: true, + style: { + fontWeight: 'bold', + color: ( // theme + Highcharts.defaultOptions.title.style && + Highcharts.defaultOptions.title.style.color + ) || 'gray' + } + } + }, + tooltip: { + formatter: function() { + return '' + this.x + '
' + + this.series.name + ': ' + this.y; + } + }, + plotOptions: { + column: { + stacking: 'normal', + } + }, + series: [{ + name: 'Gender', + data: [Appointment_ltfu_male, Appointment_ltfu_female, Appointment_ltfu_uknown_gender] + }], + + }); +// APPOINTMENT LTFU AGE + var appChart = Highcharts.chart('appointment_lftu_age', { + chart: { + type: 'column' + }, + title: { + text: 'Appointment LTFU By Age' + }, + xAxis: { + categories: ['0-9 YRS', '10-14 YRS', '15-19 YRS', '20-24 YRS', '25+ YRS', 'UKNOWN AGE'] + }, + yAxis: { + min: 0, + title: { + text: 'No of Appointment LTFU' + }, + stackLabels: { + enabled: true, + style: { + fontWeight: 'bold', + color: ( // theme + Highcharts.defaultOptions.title.style && + Highcharts.defaultOptions.title.style.color + ) || 'gray' + } + } + }, + tooltip: { + formatter: function() { + return '' + this.x + '
' + + this.series.name + ': ' + this.y; + } + }, + plotOptions: { + column: { + stacking: 'normal', + } + }, + series: [{ + name: 'Age', + data: [Appointment_ltfu_to_nine, Appointment_ltfu_to_fourteen, Appointment_ltfu_to_nineteen, Appointment_ltfu_to_twentyfour, Appointment_ltfu_to_twentyfive_above, Appointment_ltfu_to_uknown_age] + }], + + }); + var colors = Highcharts.getOptions().colors; diff --git a/routes/web.php b/routes/web.php index b4fabc1..52fa307 100644 --- a/routes/web.php +++ b/routes/web.php @@ -200,4 +200,5 @@ // new dashbaord routes Route::get('/admin/dashboard', ['uses' => 'App\Http\Controllers\NewDashboardController@dashboard', 'as' => 'dashboard']); + Route::get('/filter_charts', ['uses' => 'App\Http\Controllers\NewDashboardController@filter_charts', 'as' => 'filter_charts']); }); diff --git a/storage/debugbar/.gitignore b/storage/debugbar/.gitignore new file mode 100644 index 0000000..d6b7ef3 --- /dev/null +++ b/storage/debugbar/.gitignore @@ -0,0 +1,2 @@ +* +!.gitignore From e9336b522f11786d44328f44b766c14e3ac309e4 Mon Sep 17 00:00:00 2001 From: Ronald-pro <36841157+Ronald-pro@users.noreply.github.com> Date: Thu, 28 Apr 2022 08:01:09 +0300 Subject: [PATCH 026/171] added date filters --- .../Controllers/NewDashboardController.php | 1320 +++++++++++------ app/Http/Controllers/SMSReportController.php | 9 +- .../appointment_dashboard.blade.php | 928 ++++++++++++ .../facility_dashboard.blade.php | 0 .../new_dashboard/main_dashbaord.blade.php | 653 -------- routes/web.php | 1 + 6 files changed, 1805 insertions(+), 1106 deletions(-) create mode 100644 resources/views/new_dashboard/appointment_dashboard.blade.php delete mode 100644 resources/views/new_dashboard/facility_dashboard.blade.php diff --git a/app/Http/Controllers/NewDashboardController.php b/app/Http/Controllers/NewDashboardController.php index 7f7c71b..e440dfa 100644 --- a/app/Http/Controllers/NewDashboardController.php +++ b/app/Http/Controllers/NewDashboardController.php @@ -29,30 +29,30 @@ public function dashboard() } if (Auth::user()->access_level == 'Partner') { - - } - if (Auth::user()->access_level == 'Admin' || Auth::user()->access_level == 'Donor') { - $all_partners = Partner::where('status', '=', 'Active')->pluck('name', 'id'); - $client = Client::select('id')->where('status', '=', 'Active') - ->whereNull('hei_no') - ->count(); - - $indicator = Indicator::all(); - $appointment = Appointments::select('id') - ->count(); - - - $missed_appointment = Appointments::select('id') - ->where('app_status', '=', 'Missed') - ->orwhere('app_status', '=', 'LTFU') - ->orwhere('app_status', '=', 'Defaulted') + $client = Client::join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->where('tbl_client.status', '=', 'Active') + ->whereNull('tbl_client.hei_no') + ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) + ->count('tbl_client.clinic_number'); + + $indicator = Indicator::select(['name', 'description'])->get(); + $appointment = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select('tbl_appointment.id') + ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) + ->count(); + $missed_appointment = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select('tbl_appointment.id') + ->whereIn('tbl_appointment.app_status', ['Defaulted', 'LTFU', 'Missed']) + ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) ->count(); - // dd($missed_appointment); $active_facilities = PartnerFacility::join('tbl_client', 'tbl_partner_facility.mfl_code', '=', 'tbl_client.mfl_code') ->join('tbl_appointment', 'tbl_client.id', '=', 'tbl_appointment.client_id') ->select(\DB::raw('COUNT(tbl_partner_facility.mfl_code) as facilities')) ->where('tbl_appointment.created_at', '>=', Carbon::now()->subMonths(6)) + ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) ->orderBy('tbl_appointment.created_at', 'DESC') ->groupBy('tbl_partner_facility.mfl_code') ->get(); @@ -60,81 +60,105 @@ public function dashboard() // dd($active_facilities); // active clients by gender - $clients_male = Client::select('id')->where([['gender', '=', '2'], ['status', '=', 'Active'],]) - ->whereNull('hei_no') + $clients_male = Client::join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select('id')->where([['tbl_client.gender', '=', '2'], ['tbl_client.status', '=', 'Active'],]) + ->whereNull('tbl_client.hei_no') + ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) ->count(); - $clients_female = Client::where('gender', '=', '1') - ->where('status', '=', 'Active') - ->whereNull('hei_no') + $clients_female = Client::join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->where('tbl_client.gender', '=', '1') + ->where('tbl_client.status', '=', 'Active') + ->whereNull('tbl_client.hei_no') + ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) ->count(); - $unknown_gender = Client::where('gender', '!=', '1') - ->where('gender', '!=', '2') - ->where('status', '=', 'Active') - ->whereNull('hei_no') + $unknown_gender = Client::join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->where('tbl_client.gender', '!=', '1') + ->where('tbl_client.gender', '!=', '2') + ->where('tbl_client.status', '=', 'Active') + ->whereNull('tbl_client.hei_no') + ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) ->count(); - $client_to_nine = Cache::remember('client-nine', 10, function () { - return Client::select(\DB::raw("count((case when (((year(curdate()) - year(`dob`)) > 0) and ((year(curdate()) - year(`dob`)) <= 9)) then `dob` end)) AS count")) - ->where('status', '=', 'Active') - ->whereNull('hei_no') + $client_to_nine = Cache::remember('client_to_nine', 10, function () { + return Client::join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) > 0) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 9)) then `tbl_client`.`dob` end)) AS count")) + ->where('tbl_client.status', '=', 'Active') + ->whereNull('tbl_client.hei_no') + ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) ->pluck('count'); }); $client_to_fourteen = Cache::remember('client-fourteen', 10, function () { - return Client::select(\DB::raw("count((case when (((year(curdate()) - year(`dob`)) >= 10) and ((year(curdate()) - year(`dob`)) <= 14)) then `dob` end)) AS count")) - ->where('status', '=', 'Active') - ->whereNull('hei_no') + return Client::join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 10) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 14)) then `tbl_client`.`dob` end)) AS count")) + ->where('tbl_client.status', '=', 'Active') + ->whereNull('tbl_client.hei_no') + ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) ->pluck('count'); }); $client_to_nineteen = Cache::remember('client-nineteen', 10, function () { - return Client::select(\DB::raw("count((case when (((year(curdate()) - year(`dob`)) >= 15) and ((year(curdate()) - year(`dob`)) <= 19)) then `dob` end)) AS count")) - ->where('status', '=', 'Active') - ->whereNull('hei_no') + return Client::join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 15) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 19)) then `tbl_client`.`dob` end)) AS count")) + ->where('tbl_client.status', '=', 'Active') + ->whereNull('tbl_client.hei_no') + ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) ->pluck('count'); }); $client_to_twentyfour = Cache::remember('client-twentyfour', 10, function () { - return Client::select(\DB::raw("count((case when (((year(curdate()) - year(`dob`)) >= 20) and ((year(curdate()) - year(`dob`)) <= 24)) then `id` end)) AS count")) - ->where('status', '=', 'Active') - ->whereNull('hei_no') + return Client::join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 20) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 24)) then `tbl_client`.`dob` end)) AS count")) + ->where('tbl_client.status', '=', 'Active') + ->whereNull('tbl_client.hei_no') + ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) ->pluck('count'); }); $client_to_twentyfive_above = Cache::remember('client-twentyfive-above', 10, function () { - return Client::select(\DB::raw("count((case when (((year(curdate()) - year(`dob`)) >= 25)) then `id` end)) AS count")) - ->where('status', '=', 'Active') - ->whereNull('hei_no') + return Client::join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 25)) then `tbl_client`.`dob` end)) AS count")) + ->where('tbl_client.status', '=', 'Active') + ->whereNull('tbl_client.hei_no') + ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) ->pluck('count'); }); $client_unknown_age = Cache::remember('client-unknown-age', 10, function () { - return Client::where('dob', '=', '') - ->orWhereNull('dob') - ->where('status', '=', 'Active') - ->whereNull('hei_no') + return Client::join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->where('tbl_client.dob', '=', '') + ->orWhereNull('tbl_client.dob') + ->where('tbl_client.status', '=', 'Active') + ->whereNull('tbl_client.hei_no') + ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) ->count(); }); // appointment by gender $appointment_male = Cache::remember('appointment-male', 10, function () { return Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') ->select('tbl_appointment.id') ->where('tbl_client.gender', '=', '2') + ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) ->count(); }); $appointment_female = Cache::remember('appointment-female', 10, function () { return Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') ->select('tbl_appointment.id') ->where('tbl_client.gender', '=', '1') + ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) ->count(); }); $appointment_uknown_gender = Cache::remember('appointment-uknown-gender', 10, function () { return Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') ->select('tbl_appointment.id') ->where('tbl_client.gender', '!=', '1') ->where('tbl_client.gender', '!=', '2') + ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) ->count(); }); // appointment by age @@ -142,30 +166,35 @@ public function dashboard() return Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) > 0) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 9)) then `tbl_client`.`id` end)) AS count")) + ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) ->pluck('count'); }); $appointment_to_fourteen = Cache::remember('appointment-to-fourteen', 10, function () { return Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 10) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 14)) then `tbl_client`.`id` end)) AS count")) + ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) ->pluck('count'); }); $appointment_to_nineteen = Cache::remember('appointment-to-nineteen', 10, function () { return Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 15) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 19)) then `tbl_client`.`id` end)) AS count")) + ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) ->pluck('count'); }); $appointment_to_twentyfour = Cache::remember('appointment-to-twentyfour', 10, function () { return Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 20) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 24)) then `tbl_client`.`id` end)) AS count")) + ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) ->pluck('count'); }); $appointment_to_twentyfive_above = Cache::remember('appointment-to-twentyfive-above', 10, function () { return Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 25)) then `tbl_client`.`id` end)) AS count")) + ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) ->pluck('count'); }); $appointment_uknown_age = Cache::remember('appointment-uknown-age', 10, function () { @@ -173,590 +202,630 @@ public function dashboard() ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') ->where('tbl_client.dob', '=', '') ->orWhereNull('tbl_client.dob') + ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) ->count(); }); // Total missed appointment by gender $appointment_total_missed_female = Cache::remember('appointment-total-missed-female', 10, function () { return Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') ->where('tbl_client.gender', '=', '1') - ->where('tbl_appointment.app_status', '=', 'Missed') - ->orwhere('tbl_appointment.app_status', '=', 'LTFU') - ->orwhere('tbl_appointment.app_status', '=', 'Defaulted') + ->whereIn('tbl_appointment.app_status', ['Defaulted', 'LTFU', 'Missed']) + ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) ->count(); }); $appointment_total_missed_male = Cache::remember('appointment-total-missed-male', 10, function () { return Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') ->where('tbl_client.gender', '=', '2') - ->where('tbl_appointment.app_status', '=', 'Missed') - ->orwhere('tbl_appointment.app_status', '=', 'LTFU') - ->orwhere('tbl_appointment.app_status', '=', 'Defaulted') + ->whereIn('tbl_appointment.app_status', ['Defaulted', 'LTFU', 'Missed']) + ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) ->count(); }); $appointment_total_missed_uknown_gender = Cache::remember('appointment-total-missed-uknown-gender', 10, function () { return Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') ->where('tbl_client.gender', '!=', '1') ->where('tbl_client.gender', '!=', '2') - ->where('tbl_appointment.app_status', '=', 'Missed') - ->orwhere('tbl_appointment.app_status', '=', 'LTFU') - ->orwhere('tbl_appointment.app_status', '=', 'Defaulted') + ->whereIn('tbl_appointment.app_status', ['Defaulted', 'LTFU', 'Missed']) + ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) ->count(); }); // Total missed appointment by age $appointment_total_missed_to_nine = Cache::remember('appointment-total-missed-to-nine', 10, function () { return Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) > 0) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 9)) then `tbl_client`.`id` end)) AS count")) - ->where('tbl_appointment.app_status', '=', 'Missed') - ->orwhere('tbl_appointment.app_status', '=', 'LTFU') - ->orwhere('tbl_appointment.app_status', '=', 'Defaulted') + ->whereIn('tbl_appointment.app_status', ['Defaulted', 'LTFU', 'Missed']) + ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) ->pluck('count'); }); $appointment_total_missed_to_fourteen = Cache::remember('appointment-total-missed-to-fourteen', 10, function () { return Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 10) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 14)) then `tbl_client`.`id` end)) AS count")) - ->where('tbl_appointment.app_status', '=', 'Missed') - ->orwhere('tbl_appointment.app_status', '=', 'LTFU') - ->orwhere('tbl_appointment.app_status', '=', 'Defaulted') + ->whereIn('tbl_appointment.app_status', ['Defaulted', 'LTFU', 'Missed']) + ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) ->pluck('count'); }); $appointment_total_missed_to_nineteen = Cache::remember('appointment-total-missed-to-nineteen', 10, function () { return Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 15) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 19)) then `tbl_client`.`id` end)) AS count")) - ->where('tbl_appointment.date_attended', '!=', 'tbl_appointment.appntmnt_date') + ->whereIn('tbl_appointment.app_status', ['Defaulted', 'LTFU', 'Missed']) + ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) ->pluck('count'); }); $appointment_total_missed_to_twentyfour = Cache::remember('appointment-total-missed-to-twentyfour', 10, function () { return Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 20) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 24)) then `tbl_client`.`id` end)) AS count")) - ->where('tbl_appointment.date_attended', '!=', 'tbl_appointment.appntmnt_date') + ->whereIn('tbl_appointment.app_status', ['Defaulted', 'LTFU', 'Missed']) + ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) ->pluck('count'); }); $appointment_total_missed_to_twentyfive_above = Cache::remember('appointment-total-missed-to-twentyfive_above', 10, function () { return Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 25)) then `tbl_client`.`id` end)) AS count")) - ->where('tbl_appointment.app_status', '=', 'Missed') - ->orwhere('tbl_appointment.app_status', '=', 'LTFU') - ->orwhere('tbl_appointment.app_status', '=', 'Defaulted') + ->whereIn('tbl_appointment.app_status', ['Defaulted', 'LTFU', 'Missed']) + ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) ->pluck('count'); }); $appointment_total_missed_uknown_age = Cache::remember('appointment-total-missed-uknown-age', 10, function () { return Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') ->where('tbl_client.dob', '=', '') - ->orWhereNull('tbl_client.dob') - ->where('tbl_appointment.app_status', '=', 'Missed') - ->orwhere('tbl_appointment.app_status', '=', 'LTFU') - ->orwhere('tbl_appointment.app_status', '=', 'Defaulted') + ->whereIn('tbl_appointment.app_status', ['Defaulted', 'LTFU', 'Missed']) + ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) ->count(); }); // client charts $client_consented = Cache::remember('client-consented', 10, function () { - return Client::select('smsenable') - ->where('status', '=', 'Active') - ->whereNull('hei_no') - ->where('smsenable', '=', 'Yes') + return Client::join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select('tbl_clientsmsenable') + ->where('tbl_client.status', '=', 'Active') + ->whereNull('tbl_client.hei_no') + ->where('tbl_client.smsenable', '=', 'Yes') + ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) ->count(); }); $client_nonconsented = Cache::remember('client-nonconsented', 10, function () { - return Client::select('smsenable') - ->where('status', '=', 'Active') - ->whereNull('hei_no') - ->where('smsenable', '!=', 'Yes') + return Client::join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select('smsenable') + ->where('tbl_client.status', '=', 'Active') + ->whereNull('tbl_client.hei_no') + ->where('tbl_client.smsenable', '!=', 'Yes') + ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) ->count(); }); // consented clients by gender $client_consented_male = Cache::remember('client-consented-male', 10, function () { - return Client::where('smsenable', '=', 'Yes') - ->where('status', '=', 'Active') - ->whereNull('hei_no') - ->where('gender', '=', '2') + return Client::join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->where('tbl_client.smsenable', '=', 'Yes') + ->where('tbl_client.status', '=', 'Active') + ->whereNull('tbl_client.hei_no') + ->where('tbl_client.gender', '=', '2') + ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) ->count(); }); $client_consented_female = Cache::remember('client-consented-female', 10, function () { - return Client::where('smsenable', '=', 'Yes') - ->where('status', '=', 'Active') - ->whereNull('hei_no') - ->where('gender', '=', '1') + return Client::join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->where('tbl_client.smsenable', '=', 'Yes') + ->where('tbl_client.status', '=', 'Active') + ->whereNull('tbl_client.hei_no') + ->where('tbl_client.gender', '=', '1') + ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) ->count(); }); $client_consented_uknown_gender = Cache::remember('client-consented-uknown-gender', 10, function () { - return Client::where('smsenable', '=', 'Yes') - ->where('status', '=', 'Active') - ->whereNull('hei_no') - ->where('gender', '!=', '1') - ->where('gender', '!=', '2') + return Client::join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->where('tbl_client.smsenable', '=', 'Yes') + ->where('tbl_client.status', '=', 'Active') + ->whereNull('tbl_client.hei_no') + ->where('tbl_client.gender', '!=', '1') + ->where('tbl_client.gender', '!=', '2') + ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) ->count(); }); // non consented clients by gender $client_nonconsented_male = Cache::remember('client-nonconsented-male', 10, function () { - return Client::where('smsenable', '!=', 'Yes') - ->where('status', '=', 'Active') - ->whereNull('hei_no') - ->where('gender', '=', '2') + return Client::join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->where('tbl_client.smsenable', '!=', 'Yes') + ->where('tbl_client.status', '=', 'Active') + ->whereNull('tbl_client.hei_no') + ->where('tbl_client.gender', '=', '2') + ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) ->count(); }); $client_nonconsented_female = Cache::remember('client-nonconsented-female', 10, function () { - return Client::where('smsenable', '!=', 'Yes') - ->where('status', '=', 'Active') - ->whereNull('hei_no') - ->where('gender', '=', '1') + return Client::join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->where('tbl_client.smsenable', '!=', 'Yes') + ->where('tbl_client.status', '=', 'Active') + ->whereNull('tbl_client.hei_no') + ->where('tbl_client.gender', '=', '1') + ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) ->count(); }); $client_nonconsented_uknown_gender = Cache::remember('client-nonconsented-uknown-gender', 10, function () { - return Client::where('smsenable', '!=', 'Yes') - ->where('gender', '!=', '1') - ->where('gender', '!=', '2') + return Client::join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->where('tbl_client.smsenable', '!=', 'Yes') + ->where('tbl_client.gender', '!=', '1') + ->where('tbl_client.gender', '!=', '2') + ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) ->count(); }); // consented clients by age distribution $client_consented_to_nine = Cache::remember('client-consented-to-nine', 10, function () { - return Client::select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) > 0) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 9)) then `tbl_client`.`id` end)) AS count")) - ->where('smsenable', '=', 'Yes') - ->where('status', '=', 'Active') - ->whereNull('hei_no') + return Client::join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) > 0) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 9)) then `tbl_client`.`id` end)) AS count")) + ->where('tbl_client.smsenable', '=', 'Yes') + ->where('tbl_client.status', '=', 'Active') + ->whereNull('tbl_client.hei_no') + ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) ->pluck('count'); }); $client_consented_to_fourteen = Cache::remember('tbl-client', 10, function () { - return Client::select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 10) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 14)) then `tbl_client`.`id` end)) AS count")) - ->where('smsenable', '=', 'Yes') - ->where('status', '=', 'Active') - ->whereNull('hei_no') + return Client::join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 10) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 14)) then `tbl_client`.`id` end)) AS count")) + ->where('tbl_client.smsenable', '=', 'Yes') + ->where('tbl_client.status', '=', 'Active') + ->whereNull('tbl_client.hei_no') + ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) ->pluck('count'); }); $client_consented_to_nineteen = Cache::remember('client-consented-to-nineteen', 10, function () { - return Client::select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 15) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 19)) then `tbl_client`.`id` end)) AS count")) - ->where('smsenable', '=', 'Yes') - ->where('status', '=', 'Active') - ->whereNull('hei_no') + return Client::join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 15) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 19)) then `tbl_client`.`id` end)) AS count")) + ->where('tbl_client.smsenable', '=', 'Yes') + ->where('tbl_client.status', '=', 'Active') + ->whereNull('tbl_client.hei_no') + ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) ->pluck('count'); }); $client_consented_to_twentyfour = Cache::remember('client-consented-to-twentyfour', 10, function () { - return Client::select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 20) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 24)) then `tbl_client`.`id` end)) AS count")) - ->where('smsenable', '=', 'Yes') - ->where('status', '=', 'Active') - ->whereNull('hei_no') + return Client::join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 20) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 24)) then `tbl_client`.`id` end)) AS count")) + ->where('tbl_client.smsenable', '=', 'Yes') + ->where('tbl_client.status', '=', 'Active') + ->whereNull('tbl_client.hei_no') + ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) ->pluck('count'); }); $client_consented_to_twentyfive_above = Cache::remember('client-consented-to-twentyfive-above', 10, function () { - return Client::select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 25)) then `tbl_client`.`id` end)) AS count")) - ->where('smsenable', '=', 'Yes') - ->where('status', '=', 'Active') - ->whereNull('hei_no') + return Client::join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 25)) then `tbl_client`.`id` end)) AS count")) + ->where('tbl_client.smsenable', '=', 'Yes') + ->where('tbl_client.status', '=', 'Active') + ->whereNull('tbl_client.hei_no') + ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) ->pluck('count'); }); $client_consented_uknown_age = Cache::remember('client-consented-uknown-age', 10, function () { - return Client::select('smsenable') - ->where('dob', '=', '') - ->where('status', '=', 'Active') - ->whereNull('hei_no') - ->orWhereNull('dob') - ->where('smsenable', '=', 'Yes') + return Client::join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select('tbl_client.smsenable') + ->where('tbl_client.dob', '=', '') + ->where('tbl_client.status', '=', 'Active') + ->whereNull('tbl_client.hei_no') + ->orWhereNull('tbl_client.dob') + ->where('tbl_client.smsenable', '=', 'Yes') + ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) ->count(); }); // non consented clients by age distribution $client_nonconsented_to_nine = Cache::remember('client-nonconsented-to-nine', 10, function () { - return Client::select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) > 0) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 9)) then `tbl_client`.`id` end)) AS count")) - ->where('smsenable', '!=', 'Yes') - ->where('status', '=', 'Active') - ->whereNull('hei_no') + return Client::join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) > 0) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 9)) then `tbl_client`.`id` end)) AS count")) + ->where('tbl_client.smsenable', '!=', 'Yes') + ->where('tbl_client.status', '=', 'Active') + ->whereNull('tbl_client.hei_no') + ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) ->pluck('count'); }); $client_nonconsented_to_fourteen = Cache::remember('client-nonconsented-to-fourteen', 10, function () { - return Client::select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 10) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 14)) then `tbl_client`.`id` end)) AS count")) - ->where('smsenable', '!=', 'Yes') - ->where('status', '=', 'Active') - ->whereNull('hei_no') + return Client::join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 10) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 14)) then `tbl_client`.`id` end)) AS count")) + ->where('tbl_client.smsenable', '!=', 'Yes') + ->where('tbl_client.status', '=', 'Active') + ->whereNull('tbl_client.hei_no') + ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) ->pluck('count'); }); $client_nonconsented_to_nineteen = Cache::remember('client-nonconsented-to-nineteen', 10, function () { - return Client::select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 15) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 19)) then `tbl_client`.`id` end)) AS count")) - ->where('smsenable', '!=', 'Yes') - ->where('status', '=', 'Active') - ->whereNull('hei_no') + return Client::join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 15) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 19)) then `tbl_client`.`id` end)) AS count")) + ->where('tbl_client.smsenable', '!=', 'Yes') + ->where('tbl_client.status', '=', 'Active') + ->whereNull('tbl_client.hei_no') + ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) ->pluck('count'); }); $client_nonconsented_to_twentyfour = Cache::remember('client-nonconsented-to-twentyfour', 10, function () { - return Client::select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 20) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 24)) then `tbl_client`.`id` end)) AS count")) - ->where('smsenable', '!=', 'Yes') - ->where('status', '=', 'Active') - ->whereNull('hei_no') + return Client::join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 20) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 24)) then `tbl_client`.`id` end)) AS count")) + ->where('tbl_client.smsenable', '!=', 'Yes') + ->where('tbl_client.status', '=', 'Active') + ->whereNull('tbl_client.hei_no') + ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) ->pluck('count'); }); $client_nonconsented_to_twentyfive_above = Cache::remember('client-nonconsented-to-twentyfive-above', 10, function () { - return Client::select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 25)) then `tbl_client`.`id` end)) AS count")) - ->where('smsenable', '!=', 'Yes') - ->where('status', '=', 'Active') - ->whereNull('hei_no') + return Client::join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 25)) then `tbl_client`.`id` end)) AS count")) + ->where('tbl_client.smsenable', '!=', 'Yes') + ->where('tbl_client.status', '=', 'Active') + ->whereNull('tbl_client.hei_no') + ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) ->pluck('count'); }); $client_nonconsented_uknown_age = Cache::remember('client-nonconsented-uknown-age', 10, function () { - return Client::select('smsenable') - ->where('status', '=', 'Active') - ->whereNull('hei_no') - ->where('dob', '=', '') - ->orWhereNull('dob') - ->where('smsenable', '!=', 'Yes') + return Client::join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select('tbl_client.smsenable') + ->where('tbl_client.status', '=', 'Active') + ->whereNull('tbl_client.hei_no') + ->where('tbl_client.dob', '=', '') + ->orWhereNull('tbl_client.dob') + ->where('tbl_client.smsenable', '!=', 'Yes') + ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) ->count(); }); - // main appointments - $appointment_honoured = Cache::remember('appointment-honoured', 10, function () { - return Appointments::select('id')->where('appntmnt_date', '=', 'date_attended') - ->count(); - }); - // dd($appointment_honoured); - $appointment_not_honoured = Cache::remember('appointment-not-honoured', 10, function () { - return Appointments::select('id') - ->where('tbl_appointment.app_status', '=', 'Missed') - ->orwhere('tbl_appointment.app_status', '=', 'LTFU') - ->orwhere('tbl_appointment.app_status', '=', 'Defaulted') + } + if (Auth::user()->access_level == 'Admin' || Auth::user()->access_level == 'Donor') { + + $all_partners = Partner::where('status', '=', 'Active')->pluck('name', 'id'); + $client = Client::where('status', '=', 'Active') + ->whereNull('hei_no') + ->count('clinic_number'); + + $indicator = Indicator::select(['name', 'description'])->get(); + $appointment = Appointments::select('id') ->count(); - }); + $missed_appointment = Appointments::select('id') + ->whereIn('app_status', ['Defaulted', 'LTFU', 'Missed']) + ->count(); + // dd($missed_appointment); + $active_facilities = PartnerFacility::join('tbl_client', 'tbl_partner_facility.mfl_code', '=', 'tbl_client.mfl_code') + ->join('tbl_appointment', 'tbl_client.id', '=', 'tbl_appointment.client_id') + ->select(\DB::raw('COUNT(tbl_partner_facility.mfl_code) as facilities')) + ->where('tbl_appointment.created_at', '>=', Carbon::now()->subMonths(6)) + ->orderBy('tbl_appointment.created_at', 'DESC') + ->groupBy('tbl_partner_facility.mfl_code') + ->get(); - // appointment honored by gender - $appointment_honoured_male = Cache::remember('appointment-honoured-male', 10, function () { - return Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') - ->where('tbl_client.gender', '=', '2') - ->where('tbl_appointment.date_attended', '=', 'tbl_appointment.appntmnt_date') + + // dd($active_facilities); + // active clients by gender + $clients_male = Client::select('id')->where([['gender', '=', '2'], ['status', '=', 'Active'],]) + ->whereNull('hei_no') ->count(); - }); - $appointment_honoured_female = Cache::remember('appointment-honoured-female', 10, function () { - return Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') - ->where('tbl_client.gender', '=', '1') - ->where('tbl_appointment.date_attended', '=', 'tbl_appointment.appntmnt_date') + + $clients_female = Client::where('gender', '=', '1') + ->where('status', '=', 'Active') + ->whereNull('hei_no') ->count(); - }); - $appointment_honoured_uknown_gender = Cache::remember('appointment-honoured-uknown-gender', 10, function () { - return Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') - ->where('tbl_client.gender', '!=', '1') - ->where('tbl_client.gender', '!=', '2') - ->where('tbl_appointment.date_attended', '=', 'tbl_appointment.appntmnt_date') + $unknown_gender = Client::where('gender', '!=', '1') + ->where('gender', '!=', '2') + ->where('status', '=', 'Active') + ->whereNull('hei_no') ->count(); - }); - // appointment honored by age - $appointment_honored_to_nine = Cache::remember('appointment-honored-to-nine', 10, function () { - return Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') - ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') - ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) > 0) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 9)) then `tbl_client`.`id` end)) AS count")) - ->where('tbl_appointment.date_attended', '=', 'tbl_appointment.appntmnt_date') + + $client_to_nine = Cache::remember('client_to_nine', 10, function () { + return Client::select(\DB::raw("count((case when (((year(curdate()) - year(`dob`)) > 0) and ((year(curdate()) - year(`dob`)) <= 9)) then `dob` end)) AS count")) + ->where('status', '=', 'Active') + ->whereNull('hei_no') ->pluck('count'); }); - $appointment_honored_to_fourteen = Cache::remember('appointment-honored-to-fourteen', 10, function () { - return Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') - ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') - ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 10) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 14)) then `tbl_client`.`id` end)) AS count")) - ->where('tbl_appointment.date_attended', '=', 'tbl_appointment.appntmnt_date') + + $client_to_fourteen = Cache::remember('client-fourteen', 10, function () { + return Client::select(\DB::raw("count((case when (((year(curdate()) - year(`dob`)) >= 10) and ((year(curdate()) - year(`dob`)) <= 14)) then `dob` end)) AS count")) + ->where('status', '=', 'Active') + ->whereNull('hei_no') ->pluck('count'); }); - $appointment_honored_to_nineteen = Cache::remember('appointment-honored-to-nineteen', 10, function () { - return Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') - ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') - ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 15) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 19)) then `tbl_client`.`id` end)) AS count")) - ->where('tbl_appointment.date_attended', '=', 'tbl_appointment.appntmnt_date') + + $client_to_nineteen = Cache::remember('client-nineteen', 10, function () { + return Client::select(\DB::raw("count((case when (((year(curdate()) - year(`dob`)) >= 15) and ((year(curdate()) - year(`dob`)) <= 19)) then `dob` end)) AS count")) + ->where('status', '=', 'Active') + ->whereNull('hei_no') ->pluck('count'); }); - $appointment_honored_to_twentyfour = Cache::remember('appointment-honored-to-twentyfour', 10, function () { - return Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') - ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') - ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 20) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 24)) then `tbl_client`.`id` end)) AS count")) - ->where('tbl_appointment.date_attended', '=', 'tbl_appointment.appntmnt_date') + + $client_to_twentyfour = Cache::remember('client-twentyfour', 10, function () { + return Client::select(\DB::raw("count((case when (((year(curdate()) - year(`dob`)) >= 20) and ((year(curdate()) - year(`dob`)) <= 24)) then `id` end)) AS count")) + ->where('status', '=', 'Active') + ->whereNull('hei_no') ->pluck('count'); }); - $appointment_honored_to_twentyfive_above = Cache::remember('appointment-honored-to-twentyfive_above', 10, function () { - return Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') - ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') - ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 25)) then `tbl_client`.`id` end)) AS count")) - ->where('tbl_appointment.date_attended', '=', 'tbl_appointment.appntmnt_date') + + $client_to_twentyfive_above = Cache::remember('client-twentyfive-above', 10, function () { + return Client::select(\DB::raw("count((case when (((year(curdate()) - year(`dob`)) >= 25)) then `id` end)) AS count")) + ->where('status', '=', 'Active') + ->whereNull('hei_no') ->pluck('count'); }); - $appointment_honored_to_uknown_age = Cache::remember('appointment_honored-to-uknown-age', 10, function () { - return Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') - ->select('tbl_client.dob') - ->where('tbl_client.dob', '=', '') - ->orWhereNull('tbl_client.dob') - ->where('tbl_appointment.date_attended', '=', 'tbl_appointment.appntmnt_date') + + $client_unknown_age = Cache::remember('client-unknown-age', 10, function () { + return Client::where('dob', '=', '') + ->orWhereNull('dob') + ->where('status', '=', 'Active') + ->whereNull('hei_no') ->count(); }); - // appointment not honored by gender - $appointment_not_honoured_male = Cache::remember('appointment-not-honoured-male', 10, function () { + // appointment by gender + $appointment_male = Cache::remember('appointment-male', 10, function () { return Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->select('tbl_appointment.id') ->where('tbl_client.gender', '=', '2') - ->where('tbl_appointment.app_status', '=', 'Missed') - ->orwhere('tbl_appointment.app_status', '=', 'LTFU') - ->orwhere('tbl_appointment.app_status', '=', 'Defaulted') ->count(); }); - $appointment_not_honoured_female = Cache::remember('appointment-not-honoured-female', 10, function () { + $appointment_female = Cache::remember('appointment-female', 10, function () { return Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->select('tbl_appointment.id') ->where('tbl_client.gender', '=', '1') - ->where('tbl_appointment.app_status', '=', 'Missed') - ->orwhere('tbl_appointment.app_status', '=', 'LTFU') - ->orwhere('tbl_appointment.app_status', '=', 'Defaulted') ->count(); }); - $appointment_not_honoured_uknown_gender = Cache::remember('appointment-not-honoured-uknown-gender', 10, function () { + $appointment_uknown_gender = Cache::remember('appointment-uknown-gender', 10, function () { return Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->select('tbl_appointment.id') ->where('tbl_client.gender', '!=', '1') ->where('tbl_client.gender', '!=', '2') - ->where('tbl_appointment.app_status', '=', 'Missed') - ->orwhere('tbl_appointment.app_status', '=', 'LTFU') - ->orwhere('tbl_appointment.app_status', '=', 'Defaulted') ->count(); }); - // appointment not honored by age - $appointment_not_honored_to_nine = Cache::remember('appointment-not-honored-to-nine', 10, function () { - return Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + // appointment by age + $appointment_to_nine = Cache::remember('appointment-to-nine', 10, function () { + return Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) > 0) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 9)) then `tbl_client`.`id` end)) AS count")) - ->where('tbl_appointment.app_status', '=', 'Missed') - ->orwhere('tbl_appointment.app_status', '=', 'LTFU') - ->orwhere('tbl_appointment.app_status', '=', 'Defaulted') ->pluck('count'); }); - $appointment_not_honored_to_fourteen = Cache::remember('appointment-not-honored-to-fourteen', 10, function () { - return Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + $appointment_to_fourteen = Cache::remember('appointment-to-fourteen', 10, function () { + return Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 10) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 14)) then `tbl_client`.`id` end)) AS count")) - ->where('tbl_appointment.app_status', '=', 'Missed') - ->orwhere('tbl_appointment.app_status', '=', 'LTFU') - ->orwhere('tbl_appointment.app_status', '=', 'Defaulted') ->pluck('count'); }); - $appointment_not_honored_to_nineteen = Cache::remember('appointment_not_honored_to_nineteen', 10, function () { - return Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + $appointment_to_nineteen = Cache::remember('appointment-to-nineteen', 10, function () { + return Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 15) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 19)) then `tbl_client`.`id` end)) AS count")) - ->where('tbl_appointment.app_status', '=', 'Missed') - ->orwhere('tbl_appointment.app_status', '=', 'LTFU') - ->orwhere('tbl_appointment.app_status', '=', 'Defaulted') ->pluck('count'); }); - $appointment_not_honored_to_twentyfour = Cache::remember('appointment_not_honored_to_twentyfour', 10, function () { - return Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + $appointment_to_twentyfour = Cache::remember('appointment-to-twentyfour', 10, function () { + return Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 20) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 24)) then `tbl_client`.`id` end)) AS count")) - ->where('tbl_appointment.app_status', '=', 'Missed') - ->orwhere('tbl_appointment.app_status', '=', 'LTFU') - ->orwhere('tbl_appointment.app_status', '=', 'Defaulted') ->pluck('count'); }); - $appointment_not_honored_to_twentyfive_above = Cache::remember('appointment_not_honored_to_twentyfive_above', 10, function () { - return Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + $appointment_to_twentyfive_above = Cache::remember('appointment-to-twentyfive-above', 10, function () { + return Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 25)) then `tbl_client`.`id` end)) AS count")) - ->where('tbl_appointment.app_status', '=', 'Missed') - ->orwhere('tbl_appointment.app_status', '=', 'LTFU') - ->orwhere('tbl_appointment.app_status', '=', 'Defaulted') ->pluck('count'); }); - $appointment_not_honored_to_uknown_age = Cache::remember('appointment_not_honored_to_uknown_age', 10, function () { - return Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') - ->select('tbl_client.dob') + $appointment_uknown_age = Cache::remember('appointment-uknown-age', 10, function () { + return Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') ->where('tbl_client.dob', '=', '') ->orWhereNull('tbl_client.dob') - ->where('tbl_appointment.app_status', '=', 'Missed') - ->orwhere('tbl_appointment.app_status', '=', 'LTFU') - ->orwhere('tbl_appointment.app_status', '=', 'Defaulted') - ->count(); - }); - - // missed appointments - - $appointment_missed = Cache::remember('appointment_missed', 10, function () { - return Appointments::where('app_status', '=', 'Missed') - ->count(); - }); - $appointment_defaulted = Cache::remember('appointment_defaulted', 10, function () { - return Appointments::where('app_status', '=', 'Defaulted') - ->count(); - }); - $appointment_lftu = Cache::remember('appointment_lftu', 10, function () { - return Appointments::where('app_status', '=', 'LTFU') ->count(); }); - // missed appointment by gender - $appointment_missed_female = Cache::remember('appointment_missed_female', 10, function () { - return Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') - ->where('tbl_appointment.app_status', '=', 'Missed') + // Total missed appointment by gender + $appointment_total_missed_female = Cache::remember('appointment-total-missed-female', 10, function () { + return Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->whereIn('tbl_appointment.app_status', ['Defaulted', 'LTFU', 'Missed']) ->where('tbl_client.gender', '=', '1') ->count(); }); - $appointment_missed_male = Cache::remember('appointment_missed_male', 10, function () { - return Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') - ->where('tbl_appointment.app_status', '=', 'Missed') + $appointment_total_missed_male = Cache::remember('appointment-total-missed-male', 10, function () { + return Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') ->where('tbl_client.gender', '=', '2') + ->whereIn('tbl_appointment.app_status', ['Defaulted', 'LTFU', 'Missed']) ->count(); }); - $appointment_missed_uknown_gender = Cache::remember('appointment_missed_uknown_gender', 10, function () { - return Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') - ->where('tbl_appointment.app_status', '=', 'Missed') + $appointment_total_missed_uknown_gender = Cache::remember('appointment-total-missed-uknown-gender', 10, function () { + return Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->whereIn('tbl_appointment.app_status', ['Defaulted', 'LTFU', 'Missed']) ->where('tbl_client.gender', '!=', '1') ->where('tbl_client.gender', '!=', '2') ->count(); }); - // missed appointment by age - $appointment_missed_to_nine = Cache::remember('appointment_missed_to_nine', 10, function () { + + // Total missed appointment by age + $appointment_total_missed_to_nine = Cache::remember('appointment-total-missed-to-nine', 10, function () { return Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') - ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) > 0) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 9)) then `tbl_client`.`id` end)) AS count")) - ->where('tbl_appointment.app_status', '=', 'Missed') + ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) > 0) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 9)) then `tbl_client`.`id` end)) AS count")) + ->whereIn('tbl_appointment.app_status', ['Defaulted', 'LTFU', 'Missed']) ->pluck('count'); }); - $appointment_missed_to_fourteen = Cache::remember('appointment_missed_to_fourteen', 10, function () { - return Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') - ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 10) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 14)) then `tbl_client`.`id` end)) AS count")) - ->where('tbl_appointment.app_status', '=', 'Missed') + $appointment_total_missed_to_fourteen = Cache::remember('appointment-total-missed-to-fourteen', 10, function () { + return Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 10) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 14)) then `tbl_client`.`id` end)) AS count")) + ->whereIn('tbl_appointment.app_status', ['Defaulted', 'LTFU', 'Missed']) ->pluck('count'); }); - $appointment_missed_to_nineteen = Cache::remember('appointment_missed_to_nineteen', 10, function () { - return Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') - ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 15) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 19)) then `tbl_client`.`id` end)) AS count")) - ->where('tbl_appointment.app_status', '=', 'Missed') + $appointment_total_missed_to_nineteen = Cache::remember('appointment-total-missed-to-nineteen', 10, function () { + return Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 15) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 19)) then `tbl_client`.`id` end)) AS count")) + ->whereIn('tbl_appointment.app_status', ['Defaulted', 'LTFU', 'Missed']) ->pluck('count'); }); - $appointment_missed_to_twentyfour = Cache::remember('appointment_missed_to_twentyfour', 10, function () { + $appointment_total_missed_to_twentyfour = Cache::remember('appointment-total-missed-to-twentyfour', 10, function () { return Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') - ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 20) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 24)) then `tbl_client`.`id` end)) AS count")) - ->where('tbl_appointment.app_status', '=', 'Missed') + ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 20) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 24)) then `tbl_client`.`id` end)) AS count")) + ->whereIn('tbl_appointment.app_status', ['Defaulted', 'LTFU', 'Missed']) ->pluck('count'); }); - $appointment_missed_to_twentyfive_above = Cache::remember('appointment_missed_to_twentyfive_above', 10, function () { - return Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') - ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 25)) then `tbl_client`.`id` end)) AS count")) - ->where('tbl_appointment.app_status', '=', 'Missed') + $appointment_total_missed_to_twentyfive_above = Cache::remember('appointment-total-missed-to-twentyfive_above', 10, function () { + return Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 25)) then `tbl_client`.`id` end)) AS count")) + ->whereIn('tbl_appointment.app_status', ['Defaulted', 'LTFU', 'Missed']) ->pluck('count'); }); - $appointment_missed_to_uknown_age = Cache::remember('appointment_missed_to_uknown_age', 10, function () { - return Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') - ->select('tbl_client.dob') + $appointment_total_missed_uknown_age = Cache::remember('appointment-total-missed-uknown-age', 10, function () { + return Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') ->where('tbl_client.dob', '=', '') ->orWhereNull('tbl_client.dob') - ->where('tbl_appointment.app_status', '=', 'Missed') + ->whereIn('tbl_appointment.app_status', ['Defaulted', 'LTFU', 'Missed']) + ->count(); + }); + // client charts + $client_consented = Cache::remember('client-consented', 10, function () { + return Client::select('smsenable') + ->where('status', '=', 'Active') + ->whereNull('hei_no') + ->where('smsenable', '=', 'Yes') ->count(); }); + $client_nonconsented = Cache::remember('client-nonconsented', 10, function () { + return Client::select('smsenable') + ->where('status', '=', 'Active') + ->whereNull('hei_no') + ->where('smsenable', '!=', 'Yes') + ->count(); + }); + // consented clients by gender - // defaulted appointment by gender - $appointment_defaulted_female = Cache::remember('appointment_defaulted_female', 10, function () { - return Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') - ->where('tbl_appointment.app_status', '=', 'Defaulted') - ->where('tbl_client.gender', '=', '1') + $client_consented_male = Cache::remember('client-consented-male', 10, function () { + return Client::where('smsenable', '=', 'Yes') + ->where('status', '=', 'Active') + ->whereNull('hei_no') + ->where('gender', '=', '2') ->count(); }); - $appointment_defaulted_male = Cache::remember('appointment_defaulted_male', 10, function () { - return Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') - ->where('tbl_appointment.app_status', '=', 'Defaulted') - ->where('tbl_client.gender', '=', '2') + $client_consented_female = Cache::remember('client-consented-female', 10, function () { + return Client::where('smsenable', '=', 'Yes') + ->where('status', '=', 'Active') + ->whereNull('hei_no') + ->where('gender', '=', '1') ->count(); }); - $appointment_defaulted_uknown_gender = Cache::remember('appointment_defaulted_uknown_gender', 10, function () { - return Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') - ->where('tbl_appointment.app_status', '=', 'Defaulted') - ->where('tbl_client.gender', '!=', '1') - ->where('tbl_client.gender', '!=', '2') + $client_consented_uknown_gender = Cache::remember('client-consented-uknown-gender', 10, function () { + return Client::where('smsenable', '=', 'Yes') + ->where('status', '=', 'Active') + ->whereNull('hei_no') + ->where('gender', '!=', '1') + ->where('gender', '!=', '2') ->count(); }); - - // defaulted appointment by age - $appointment_defaulted_to_nine = Cache::remember('appointment_defaulted_to_nine', 10, function () { - return Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') - ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) > 0) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 9)) then `tbl_client`.`id` end)) AS count")) - ->where('tbl_appointment.app_status', '=', 'Defaulted') - ->pluck('count'); + // non consented clients by gender + $client_nonconsented_male = Cache::remember('client-nonconsented-male', 10, function () { + return Client::where('smsenable', '!=', 'Yes') + ->where('status', '=', 'Active') + ->whereNull('hei_no') + ->where('gender', '=', '2') + ->count(); }); - $appointment_defaulted_to_fourteen = Cache::remember('appointment_defaulted_to_fourteen', 10, function () { - return Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') - ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 10) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 14)) then `tbl_client`.`id` end)) AS count")) - ->where('tbl_appointment.app_status', '=', 'Defaulted') - ->pluck('count'); + $client_nonconsented_female = Cache::remember('client-nonconsented-female', 10, function () { + return Client::where('smsenable', '!=', 'Yes') + ->where('status', '=', 'Active') + ->whereNull('hei_no') + ->where('gender', '=', '1') + ->count(); }); - $appointment_defaulted_to_nineteen = Cache::remember('appointment_defaulted_to_nineteen', 10, function () { - return Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') - ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 15) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 19)) then `tbl_client`.`id` end)) AS count")) - ->where('tbl_appointment.app_status', '=', 'Defaulted') - ->pluck('count'); + $client_nonconsented_uknown_gender = Cache::remember('client-nonconsented-uknown-gender', 10, function () { + return Client::where('smsenable', '!=', 'Yes') + ->where('gender', '!=', '1') + ->where('gender', '!=', '2') + ->count(); }); - $appointment_defaulted_to_twentyfour = Cache::remember('appointment_defaulted_to_twentyfour', 10, function () { - return Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') - ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 20) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 24)) then `tbl_client`.`id` end)) AS count")) - ->where('tbl_appointment.app_status', '=', 'Defaulted') + // consented clients by age distribution + $client_consented_to_nine = Cache::remember('client-consented-to-nine', 10, function () { + return Client::select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) > 0) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 9)) then `tbl_client`.`id` end)) AS count")) + ->where('smsenable', '=', 'Yes') + ->where('status', '=', 'Active') + ->whereNull('hei_no') ->pluck('count'); }); - $appointment_defaulted_to_twentyfive_above = Cache::remember('appointment_defaulted_to_twentyfive_above', 10, function () { - return Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') - ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 25)) then `tbl_client`.`id` end)) AS count")) - ->where('tbl_appointment.app_status', '=', 'Defaulted') + $client_consented_to_fourteen = Cache::remember('tbl-client', 10, function () { + return Client::select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 10) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 14)) then `tbl_client`.`id` end)) AS count")) + ->where('smsenable', '=', 'Yes') + ->where('status', '=', 'Active') + ->whereNull('hei_no') ->pluck('count'); }); - $appointment_defaulted_to_uknown_age = Cache::remember('appointment_defaulted_to_uknown_age', 10, function () { - return Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') - ->select('tbl_client.dob') - ->where('tbl_client.dob', '=', '') - ->orWhereNull('tbl_client.dob') - ->where('tbl_appointment.app_status', '=', 'Defaulted') - ->count(); + $client_consented_to_nineteen = Cache::remember('client-consented-to-nineteen', 10, function () { + return Client::select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 15) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 19)) then `tbl_client`.`id` end)) AS count")) + ->where('smsenable', '=', 'Yes') + ->where('status', '=', 'Active') + ->whereNull('hei_no') + ->pluck('count'); }); - // ltfu appointment by gender - $appointment_ltfu_female = Cache::remember('appointment_ltfu_female', 10, function () { - return Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') - ->where('tbl_appointment.app_status', '=', 'LTFU') - ->where('tbl_client.gender', '=', '1') - ->count(); + $client_consented_to_twentyfour = Cache::remember('client-consented-to-twentyfour', 10, function () { + return Client::select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 20) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 24)) then `tbl_client`.`id` end)) AS count")) + ->where('smsenable', '=', 'Yes') + ->where('status', '=', 'Active') + ->whereNull('hei_no') + ->pluck('count'); }); - $appointment_ltfu_male = Cache::remember('appointment_ltfu_male', 10, function () { - return Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') - ->where('tbl_appointment.app_status', '=', 'LTFU') - ->where('tbl_client.gender', '=', '2') - ->count(); + $client_consented_to_twentyfive_above = Cache::remember('client-consented-to-twentyfive-above', 10, function () { + return Client::select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 25)) then `tbl_client`.`id` end)) AS count")) + ->where('smsenable', '=', 'Yes') + ->where('status', '=', 'Active') + ->whereNull('hei_no') + ->pluck('count'); }); - $appointment_ltfu_uknown_gender = Cache::remember('appointment_ltfu_uknown_gender', 10, function () { - return Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') - ->where('tbl_appointment.app_status', '=', 'LTFU') - ->where('tbl_client.gender', '!=', '1') - ->where('tbl_client.gender', '!=', '2') + $client_consented_uknown_age = Cache::remember('client-consented-uknown-age', 10, function () { + return Client::select('smsenable') + ->where('dob', '=', '') + ->where('status', '=', 'Active') + ->whereNull('hei_no') + ->orWhereNull('dob') + ->where('smsenable', '=', 'Yes') ->count(); }); - - // ltfu appointment by age - $appointment_ltfu_to_nine = Cache::remember('appointment_ltfu_to_nine', 10, function () { - return Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') - ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) > 0) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 9)) then `tbl_client`.`id` end)) AS count")) - ->where('tbl_appointment.app_status', '=', 'LTFU') + // non consented clients by age distribution + $client_nonconsented_to_nine = Cache::remember('client-nonconsented-to-nine', 10, function () { + return Client::select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) > 0) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 9)) then `tbl_client`.`id` end)) AS count")) + ->where('smsenable', '!=', 'Yes') + ->where('status', '=', 'Active') + ->whereNull('hei_no') ->pluck('count'); }); - $appointment_ltfu_to_fourteen = Cache::remember('appointment_ltfu_to_fourteen', 10, function () { - return Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') - ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 10) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 14)) then `tbl_client`.`id` end)) AS count")) - ->where('tbl_appointment.app_status', '=', 'LTFU') + $client_nonconsented_to_fourteen = Cache::remember('client-nonconsented-to-fourteen', 10, function () { + return Client::select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 10) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 14)) then `tbl_client`.`id` end)) AS count")) + ->where('smsenable', '!=', 'Yes') + ->where('status', '=', 'Active') + ->whereNull('hei_no') ->pluck('count'); }); - $appointment_ltfu_to_nineteen = Cache::remember('appointment_ltfu_to_nineteen', 10, function () { - return Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') - ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 15) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 19)) then `tbl_client`.`id` end)) AS count")) - ->where('tbl_appointment.app_status', '=', 'LTFU') + $client_nonconsented_to_nineteen = Cache::remember('client-nonconsented-to-nineteen', 10, function () { + return Client::select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 15) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 19)) then `tbl_client`.`id` end)) AS count")) + ->where('smsenable', '!=', 'Yes') + ->where('status', '=', 'Active') + ->whereNull('hei_no') ->pluck('count'); }); - $appointment_ltfu_to_twentyfour = Cache::remember('appointment_ltfu_to_twentyfour', 10, function () { - return Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') - ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 20) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 24)) then `tbl_client`.`id` end)) AS count")) - ->where('tbl_appointment.app_status', '=', 'LTFU') + $client_nonconsented_to_twentyfour = Cache::remember('client-nonconsented-to-twentyfour', 10, function () { + return Client::select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 20) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 24)) then `tbl_client`.`id` end)) AS count")) + ->where('smsenable', '!=', 'Yes') + ->where('status', '=', 'Active') + ->whereNull('hei_no') ->pluck('count'); }); - $appointment_ltfu_to_twentyfive_above = Cache::remember('appointment_ltfu_to_twentyfive_above', 10, function () { - return Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') - ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 25)) then `tbl_client`.`id` end)) AS count")) - ->where('tbl_appointment.app_status', '=', 'LTFU') + $client_nonconsented_to_twentyfive_above = Cache::remember('client-nonconsented-to-twentyfive-above', 10, function () { + return Client::select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 25)) then `tbl_client`.`id` end)) AS count")) + ->where('smsenable', '!=', 'Yes') + ->where('status', '=', 'Active') + ->whereNull('hei_no') ->pluck('count'); }); - $appointment_ltfu_to_uknown_age = Cache::remember('appointment_ltfu_to_uknown_age', 10, function () { - return Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') - ->select('tbl_client.dob') - ->where('tbl_client.dob', '=', '') - ->orWhereNull('tbl_client.dob') - ->where('tbl_appointment.app_status', '=', 'LTFU') + $client_nonconsented_uknown_age = Cache::remember('client-nonconsented-uknown-age', 10, function () { + return Client::select('smsenable') + ->where('status', '=', 'Active') + ->whereNull('hei_no') + ->where('dob', '=', '') + ->orWhereNull('dob') + ->where('smsenable', '!=', 'Yes') ->count(); }); + + } @@ -815,61 +884,412 @@ public function dashboard() 'client_nonconsented_to_nineteen', 'client_nonconsented_to_twentyfour', 'client_nonconsented_to_twentyfive_above', - 'client_nonconsented_uknown_age', - 'appointment_honoured', - 'appointment_not_honoured', - 'appointment_honoured_male', - 'appointment_honoured_female', - 'appointment_honoured_uknown_gender', - 'appointment_honored_to_nine', - 'appointment_honored_to_fourteen', - 'appointment_honored_to_nineteen', - 'appointment_honored_to_twentyfour', - 'appointment_honored_to_twentyfive_above', - 'appointment_honored_to_uknown_age', - 'appointment_not_honoured_male', - 'appointment_not_honoured_female', - 'appointment_not_honoured_uknown_gender', - 'appointment_not_honored_to_nine', - 'appointment_not_honored_to_fourteen', - 'appointment_not_honored_to_nineteen', - 'appointment_not_honored_to_twentyfour', - 'appointment_not_honored_to_twentyfive_above', - 'appointment_not_honored_to_uknown_age', - 'appointment_missed', - 'appointment_defaulted', - 'appointment_lftu', - 'appointment_missed_female', - 'appointment_missed_male', - 'appointment_missed_uknown_gender', - 'appointment_missed_to_nine', - 'appointment_missed_to_fourteen', - 'appointment_missed_to_nineteen', - 'appointment_missed_to_twentyfour', - 'appointment_missed_to_twentyfive_above', - 'appointment_missed_to_uknown_age', - 'appointment_defaulted_female', - 'appointment_defaulted_male', - 'appointment_defaulted_uknown_gender', - 'appointment_defaulted_to_nine', - 'appointment_defaulted_to_fourteen', - 'appointment_defaulted_to_nineteen', - 'appointment_defaulted_to_twentyfour', - 'appointment_defaulted_to_twentyfive_above', - 'appointment_defaulted_to_uknown_age', - 'appointment_ltfu_female', - 'appointment_ltfu_male', - 'appointment_ltfu_uknown_gender', - 'appointment_ltfu_to_nine', - 'appointment_ltfu_to_fourteen', - 'appointment_ltfu_to_nineteen', - 'appointment_ltfu_to_twentyfour', - 'appointment_ltfu_to_twentyfive_above', - 'appointment_ltfu_to_uknown_age' + 'client_nonconsented_uknown_age' )); } + public function appointment_charts() + { + if (Auth::user()->access_level == 'Admin' || Auth::user()->access_level == 'Donor') { + $all_partners = Partner::where('status', '=', 'Active')->pluck('name', 'id'); + // main appointments + $appointment = Appointments::select('id') + ->count(); + $appointment_honoured = Cache::remember('appointment-honoured', 10, function () { + return Appointments::select(\DB::raw("COUNT(id) as count")) + ->where('date_attended', '=', DB::raw('appntmnt_date')) + ->pluck('count'); + }); + // dd($appointment_honoured); + $appointment_not_honoured = Cache::remember('appointment-not-honoured', 10, function () { + return Appointments::select(\DB::raw("COUNT(id) as count")) + ->whereIn('app_status', ['Defaulted', 'LTFU', 'Missed']) + ->pluck('count'); + }); + + // appointment honored by gender + $appointment_honoured_male = Cache::remember('appointment-honoured-male', 10, function () { + return Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->select(\DB::raw("COUNT(tbl_appointment.id) as count")) + ->where('tbl_appointment.date_attended', '=', DB::raw('tbl_appointment.appntmnt_date')) + ->where('tbl_client.gender', '=', '2') + ->pluck('count'); + }); + $appointment_honoured_female = Cache::remember('appointment-honoured-female', 10, function () { + return Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->where('tbl_appointment.date_attended', '=', DB::raw('tbl_appointment.appntmnt_date')) + ->where('tbl_client.gender', '=', '1') + ->count(); + }); + $appointment_honoured_uknown_gender = Cache::remember('appointment-honoured-uknown-gender', 10, function () { + return Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->where('tbl_appointment.date_attended', '=', DB::raw('tbl_appointment.appntmnt_date')) + ->where('tbl_client.gender', '!=', '1') + ->where('tbl_client.gender', '!=', '2') + ->count(); + }); + // appointment honored by age + $appointment_honored_to_nine = Cache::remember('appointment-honored-to-nine', 10, function () { + return Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) > 0) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 9)) then `tbl_client`.`id` end)) AS count")) + ->where('tbl_appointment.date_attended', '=', DB::raw('tbl_appointment.appntmnt_date')) + ->pluck('count'); + }); + $appointment_honored_to_fourteen = Cache::remember('appointment-honored-to-fourteen', 10, function () { + return Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 10) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 14)) then `tbl_client`.`id` end)) AS count")) + ->where('tbl_appointment.date_attended', '=', DB::raw('tbl_appointment.appntmnt_date')) + ->pluck('count'); + }); + $appointment_honored_to_nineteen = Cache::remember('appointment-honored-to-nineteen', 10, function () { + return Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 15) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 19)) then `tbl_client`.`id` end)) AS count")) + ->where('tbl_appointment.date_attended', '=', DB::raw('tbl_appointment.appntmnt_date')) + ->pluck('count'); + }); + $appointment_honored_to_twentyfour = Cache::remember('appointment-honored-to-twentyfour', 10, function () { + return Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 20) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 24)) then `tbl_client`.`id` end)) AS count")) + ->where('tbl_appointment.date_attended', '=', DB::raw('tbl_appointment.appntmnt_date')) + ->pluck('count'); + }); + $appointment_honored_to_twentyfive_above = Cache::remember('appointment-honored-to-twentyfive_above', 10, function () { + return Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 25)) then `tbl_client`.`id` end)) AS count")) + ->where('tbl_appointment.date_attended', '=', DB::raw('tbl_appointment.appntmnt_date')) + ->pluck('count'); + }); + $appointment_honored_to_uknown_age = Cache::remember('appointment_honored-to-uknown-age', 10, function () { + return Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->select('tbl_client.dob') + ->where('tbl_appointment.date_attended', '=', DB::raw('tbl_appointment.appntmnt_date')) + ->where('tbl_client.dob', '=', '') + ->orWhereNull('tbl_client.dob') + ->count(); + }); + + // appointment not honored by gender + $appointment_not_honoured_male = Cache::remember('appointment-not-honoured-male', 10, function () { + return Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->where('tbl_client.gender', '=', '2') + ->whereIn('app_status', ['Defaulted', 'LTFU', 'Missed']) + ->count(); + }); + $appointment_not_honoured_female = Cache::remember('appointment-not-honoured-female', 10, function () { + return Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->where('tbl_client.gender', '=', '1') + ->whereIn('app_status', ['Defaulted', 'LTFU', 'Missed']) + ->count(); + }); + $appointment_not_honoured_uknown_gender = Cache::remember('appointment-not-honoured-uknown-gender', 10, function () { + return Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->where('tbl_client.gender', '!=', '1') + ->where('tbl_client.gender', '!=', '2') + ->whereIn('app_status', ['Defaulted', 'LTFU', 'Missed']) + ->count(); + }); + // appointment not honored by age + $appointment_not_honored_to_nine = Cache::remember('appointment-not-honored-to-nine', 10, function () { + return Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) > 0) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 9)) then `tbl_client`.`id` end)) AS count")) + ->whereIn('app_status', ['Defaulted', 'LTFU', 'Missed']) + ->pluck('count'); + }); + $appointment_not_honored_to_fourteen = Cache::remember('appointment-not-honored-to-fourteen', 10, function () { + return Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 10) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 14)) then `tbl_client`.`id` end)) AS count")) + ->whereIn('app_status', ['Defaulted', 'LTFU', 'Missed']) + ->pluck('count'); + }); + $appointment_not_honored_to_nineteen = Cache::remember('appointment_not_honored_to_nineteen', 10, function () { + return Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 15) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 19)) then `tbl_client`.`id` end)) AS count")) + ->whereIn('app_status', ['Defaulted', 'LTFU', 'Missed']) + ->pluck('count'); + }); + $appointment_not_honored_to_twentyfour = Cache::remember('appointment_not_honored_to_twentyfour', 10, function () { + return Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 20) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 24)) then `tbl_client`.`id` end)) AS count")) + ->whereIn('app_status', ['Defaulted', 'LTFU', 'Missed']) + ->pluck('count'); + }); + $appointment_not_honored_to_twentyfive_above = Cache::remember('appointment_not_honored_to_twentyfive_above', 10, function () { + return Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 25)) then `tbl_client`.`id` end)) AS count")) + ->whereIn('app_status', ['Defaulted', 'LTFU', 'Missed']) + ->pluck('count'); + }); + $appointment_not_honored_to_uknown_age = Cache::remember('appointment_not_honored_to_uknown_age', 10, function () { + return Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->select('tbl_client.dob') + ->where('tbl_client.dob', '=', '') + ->orWhereNull('tbl_client.dob') + ->whereIn('app_status', ['Defaulted', 'LTFU', 'Missed']) + ->count(); + }); + + // missed appointments + + $appointment_missed = Cache::remember('appointment_missed', 10, function () { + return Appointments::where('app_status', '=', 'Missed') + ->count(); + }); + $appointment_defaulted = Cache::remember('appointment_defaulted', 10, function () { + return Appointments::where('app_status', '=', 'Defaulted') + ->count(); + }); + $appointment_lftu = Cache::remember('appointment_lftu', 10, function () { + return Appointments::where('app_status', '=', 'LTFU') + ->count(); + }); + + // missed appointment by gender + $appointment_missed_female = Cache::remember('appointment_missed_female', 10, function () { + return Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->where('tbl_appointment.app_status', '=', 'Missed') + ->where('tbl_client.gender', '=', '1') + ->count(); + }); + $appointment_missed_male = Cache::remember('appointment_missed_male', 10, function () { + return Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->where('tbl_appointment.app_status', '=', 'Missed') + ->where('tbl_client.gender', '=', '2') + ->count(); + }); + $appointment_missed_uknown_gender = Cache::remember('appointment_missed_uknown_gender', 10, function () { + return Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->where('tbl_appointment.app_status', '=', 'Missed') + ->where('tbl_client.gender', '!=', '1') + ->where('tbl_client.gender', '!=', '2') + ->count(); + }); + // missed appointment by age + $appointment_missed_to_nine = Cache::remember('appointment_missed_to_nine', 10, function () { + return Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) > 0) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 9)) then `tbl_client`.`id` end)) AS count")) + ->where('tbl_appointment.app_status', '=', 'Missed') + ->pluck('count'); + }); + $appointment_missed_to_fourteen = Cache::remember('appointment_missed_to_fourteen', 10, function () { + return Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 10) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 14)) then `tbl_client`.`id` end)) AS count")) + ->where('tbl_appointment.app_status', '=', 'Missed') + ->pluck('count'); + }); + $appointment_missed_to_nineteen = Cache::remember('appointment_missed_to_nineteen', 10, function () { + return Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 15) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 19)) then `tbl_client`.`id` end)) AS count")) + ->where('tbl_appointment.app_status', '=', 'Missed') + ->pluck('count'); + }); + $appointment_missed_to_twentyfour = Cache::remember('appointment_missed_to_twentyfour', 10, function () { + return Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 20) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 24)) then `tbl_client`.`id` end)) AS count")) + ->where('tbl_appointment.app_status', '=', 'Missed') + ->pluck('count'); + }); + $appointment_missed_to_twentyfive_above = Cache::remember('appointment_missed_to_twentyfive_above', 10, function () { + return Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 25)) then `tbl_client`.`id` end)) AS count")) + ->where('tbl_appointment.app_status', '=', 'Missed') + ->pluck('count'); + }); + $appointment_missed_to_uknown_age = Cache::remember('appointment_missed_to_uknown_age', 10, function () { + return Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->select('tbl_client.dob') + ->where('tbl_client.dob', '=', '') + ->orWhereNull('tbl_client.dob') + ->where('tbl_appointment.app_status', '=', 'Missed') + ->count(); + }); + + // defaulted appointment by gender + $appointment_defaulted_female = Cache::remember('appointment_defaulted_female', 10, function () { + return Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->where('tbl_appointment.app_status', '=', 'Defaulted') + ->where('tbl_client.gender', '=', '1') + ->count(); + }); + $appointment_defaulted_male = Cache::remember('appointment_defaulted_male', 10, function () { + return Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->where('tbl_appointment.app_status', '=', 'Defaulted') + ->where('tbl_client.gender', '=', '2') + ->count(); + }); + $appointment_defaulted_uknown_gender = Cache::remember('appointment_defaulted_uknown_gender', 10, function () { + return Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->where('tbl_appointment.app_status', '=', 'Defaulted') + ->where('tbl_client.gender', '!=', '1') + ->where('tbl_client.gender', '!=', '2') + ->count(); + }); + + // defaulted appointment by age + $appointment_defaulted_to_nine = Cache::remember('appointment_defaulted_to_nine', 10, function () { + return Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) > 0) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 9)) then `tbl_client`.`id` end)) AS count")) + ->where('tbl_appointment.app_status', '=', 'Defaulted') + ->pluck('count'); + }); + $appointment_defaulted_to_fourteen = Cache::remember('appointment_defaulted_to_fourteen', 10, function () { + return Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 10) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 14)) then `tbl_client`.`id` end)) AS count")) + ->where('tbl_appointment.app_status', '=', 'Defaulted') + ->pluck('count'); + }); + $appointment_defaulted_to_nineteen = Cache::remember('appointment_defaulted_to_nineteen', 10, function () { + return Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 15) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 19)) then `tbl_client`.`id` end)) AS count")) + ->where('tbl_appointment.app_status', '=', 'Defaulted') + ->pluck('count'); + }); + $appointment_defaulted_to_twentyfour = Cache::remember('appointment_defaulted_to_twentyfour', 10, function () { + return Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 20) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 24)) then `tbl_client`.`id` end)) AS count")) + ->where('tbl_appointment.app_status', '=', 'Defaulted') + ->pluck('count'); + }); + $appointment_defaulted_to_twentyfive_above = Cache::remember('appointment_defaulted_to_twentyfive_above', 10, function () { + return Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 25)) then `tbl_client`.`id` end)) AS count")) + ->where('tbl_appointment.app_status', '=', 'Defaulted') + ->pluck('count'); + }); + $appointment_defaulted_to_uknown_age = Cache::remember('appointment_defaulted_to_uknown_age', 10, function () { + return Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->select('tbl_client.dob') + ->where('tbl_client.dob', '=', '') + ->orWhereNull('tbl_client.dob') + ->where('tbl_appointment.app_status', '=', 'Defaulted') + ->count(); + }); + // ltfu appointment by gender + $appointment_ltfu_female = Cache::remember('appointment_ltfu_female', 10, function () { + return Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->where('tbl_appointment.app_status', '=', 'LTFU') + ->where('tbl_client.gender', '=', '1') + ->count(); + }); + $appointment_ltfu_male = Cache::remember('appointment_ltfu_male', 10, function () { + return Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->where('tbl_appointment.app_status', '=', 'LTFU') + ->where('tbl_client.gender', '=', '2') + ->count(); + }); + $appointment_ltfu_uknown_gender = Cache::remember('appointment_ltfu_uknown_gender', 10, function () { + return Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->where('tbl_appointment.app_status', '=', 'LTFU') + ->where('tbl_client.gender', '!=', '1') + ->where('tbl_client.gender', '!=', '2') + ->count(); + }); + + // ltfu appointment by age + $appointment_ltfu_to_nine = Cache::remember('appointment_ltfu_to_nine', 10, function () { + return Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) > 0) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 9)) then `tbl_client`.`id` end)) AS count")) + ->where('tbl_appointment.app_status', '=', 'LTFU') + ->pluck('count'); + }); + $appointment_ltfu_to_fourteen = Cache::remember('appointment_ltfu_to_fourteen', 10, function () { + return Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 10) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 14)) then `tbl_client`.`id` end)) AS count")) + ->where('tbl_appointment.app_status', '=', 'LTFU') + ->pluck('count'); + }); + $appointment_ltfu_to_nineteen = Cache::remember('appointment_ltfu_to_nineteen', 10, function () { + return Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 15) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 19)) then `tbl_client`.`id` end)) AS count")) + ->where('tbl_appointment.app_status', '=', 'LTFU') + ->pluck('count'); + }); + $appointment_ltfu_to_twentyfour = Cache::remember('appointment_ltfu_to_twentyfour', 10, function () { + return Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 20) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 24)) then `tbl_client`.`id` end)) AS count")) + ->where('tbl_appointment.app_status', '=', 'LTFU') + ->pluck('count'); + }); + $appointment_ltfu_to_twentyfive_above = Cache::remember('appointment_ltfu_to_twentyfive_above', 10, function () { + return Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 25)) then `tbl_client`.`id` end)) AS count")) + ->where('tbl_appointment.app_status', '=', 'LTFU') + ->pluck('count'); + }); + $appointment_ltfu_to_uknown_age = Cache::remember('appointment_ltfu_to_uknown_age', 10, function () { + return Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->select('tbl_client.dob') + ->where('tbl_client.dob', '=', '') + ->orWhereNull('tbl_client.dob') + ->where('tbl_appointment.app_status', '=', 'LTFU') + ->count(); + }); + } + + + return view('new_dashboard.appointment_dashboard', compact('all_partners', 'appointment', 'appointment_honoured', + 'appointment_not_honoured', + 'appointment_honoured_male', + 'appointment_honoured_female', + 'appointment_honoured_uknown_gender', + 'appointment_honored_to_nine', + 'appointment_honored_to_fourteen', + 'appointment_honored_to_nineteen', + 'appointment_honored_to_twentyfour', + 'appointment_honored_to_twentyfive_above', + 'appointment_honored_to_uknown_age', + 'appointment_not_honoured_male', + 'appointment_not_honoured_female', + 'appointment_not_honoured_uknown_gender', + 'appointment_not_honored_to_nine', + 'appointment_not_honored_to_fourteen', + 'appointment_not_honored_to_nineteen', + 'appointment_not_honored_to_twentyfour', + 'appointment_not_honored_to_twentyfive_above', + 'appointment_not_honored_to_uknown_age', + 'appointment_missed', + 'appointment_defaulted', + 'appointment_lftu', + 'appointment_missed_female', + 'appointment_missed_male', + 'appointment_missed_uknown_gender', + 'appointment_missed_to_nine', + 'appointment_missed_to_fourteen', + 'appointment_missed_to_nineteen', + 'appointment_missed_to_twentyfour', + 'appointment_missed_to_twentyfive_above', + 'appointment_missed_to_uknown_age', + 'appointment_defaulted_female', + 'appointment_defaulted_male', + 'appointment_defaulted_uknown_gender', + 'appointment_defaulted_to_nine', + 'appointment_defaulted_to_fourteen', + 'appointment_defaulted_to_nineteen', + 'appointment_defaulted_to_twentyfour', + 'appointment_defaulted_to_twentyfive_above', + 'appointment_defaulted_to_uknown_age', + 'appointment_ltfu_female', + 'appointment_ltfu_male', + 'appointment_ltfu_uknown_gender', + 'appointment_ltfu_to_nine', + 'appointment_ltfu_to_fourteen', + 'appointment_ltfu_to_nineteen', + 'appointment_ltfu_to_twentyfour', + 'appointment_ltfu_to_twentyfive_above', + 'appointment_ltfu_to_uknown_age' + )); + } + public function filter_charts(Request $request) { // $data = []; diff --git a/app/Http/Controllers/SMSReportController.php b/app/Http/Controllers/SMSReportController.php index d693dfd..51da299 100644 --- a/app/Http/Controllers/SMSReportController.php +++ b/app/Http/Controllers/SMSReportController.php @@ -21,7 +21,8 @@ public function success_sms() $all_partners = Partner::where('status', '=', 'Active')->pluck('name', 'id'); $delivered_partners = ClientOutgoing::join('tbl_client', 'tbl_clnt_outgoing.clnt_usr_id', '=', 'tbl_client.id') - ->join('tbl_partner', 'tbl_client.partner_id', '=', 'tbl_partner.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->join('tbl_partner', 'tbl_partner_facility.partner_id', '=', 'tbl_partner.id') ->select('tbl_partner.name', DB::raw('count(tbl_clnt_outgoing.callback_status) as total')) ->where('tbl_clnt_outgoing.callback_status', '=', 'Success') ->groupBy('tbl_partner.name') @@ -29,14 +30,16 @@ public function success_sms() ->get(); // dd($delivered_partners); $failed_partners = ClientOutgoing::join('tbl_client', 'tbl_clnt_outgoing.clnt_usr_id', '=', 'tbl_client.id') - ->join('tbl_partner', 'tbl_client.partner_id', '=', 'tbl_partner.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->join('tbl_partner', 'tbl_partner_facility.partner_id', '=', 'tbl_partner.id') ->select('tbl_partner.name', DB::raw('count(tbl_clnt_outgoing.callback_status) as total')) ->where('tbl_clnt_outgoing.callback_status', '=', 'Failed') ->groupBy('tbl_partner.name') ->get(); $cost_partners = ClientOutgoing::join('tbl_client', 'tbl_clnt_outgoing.clnt_usr_id', '=', 'tbl_client.id') - ->join('tbl_partner', 'tbl_client.partner_id', '=', 'tbl_partner.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->join('tbl_partner', 'tbl_partner_facility.partner_id', '=', 'tbl_partner.id') ->select('tbl_partner.name', DB::raw("ROUND(SUM(SUBSTRING(tbl_clnt_outgoing.cost, 5)), 0) as total_cost")) ->groupBy('tbl_partner.name') ->get(); diff --git a/resources/views/new_dashboard/appointment_dashboard.blade.php b/resources/views/new_dashboard/appointment_dashboard.blade.php new file mode 100644 index 0000000..5f89b79 --- /dev/null +++ b/resources/views/new_dashboard/appointment_dashboard.blade.php @@ -0,0 +1,928 @@ +@extends('layouts.master') +@section('page-css') + +@endsection + +@section('main-content') + +@if (Auth::user()->access_level == 'Admin' || Auth::user()->access_level == 'Partner' || Auth::user()->access_level == 'Donor') + + +
+ + + {{ csrf_field() }} +
+
+
+ + +
+
+
+
+ +
+
+
+
+ + +
+
+
+
+ + + +
+
+
+
+ + + +
+
+ +
+
+
+ +
+ + +
+
+ +
+
+
+
+
+
+
+
+ +
+ + +
+
+ +
+
+
+
+
+
+ + +
+
+
+ + + +
+@endif + + + + + + + + + + + + + + + + + + + + + + + + +@endsection \ No newline at end of file diff --git a/resources/views/new_dashboard/facility_dashboard.blade.php b/resources/views/new_dashboard/facility_dashboard.blade.php deleted file mode 100644 index e69de29..0000000 diff --git a/resources/views/new_dashboard/main_dashbaord.blade.php b/resources/views/new_dashboard/main_dashbaord.blade.php index 6d98c57..0a2a749 100644 --- a/resources/views/new_dashboard/main_dashbaord.blade.php +++ b/resources/views/new_dashboard/main_dashbaord.blade.php @@ -119,8 +119,6 @@ @@ -303,168 +301,7 @@
- - @@ -538,54 +375,6 @@ var Client_nonconsented_uknown_age = ; - var Appointment_honoured_male = ; - var Appointment_honoured_female = ; - var Appointment_honoured_uknown_gender = ; - var Appointment_honored_to_nine = ; - var Appointment_honored_to_fourteen = ; - var Appointment_honored_to_nineteen = ; - var Appointment_honored_to_twentyfour = ; - var Appointment_honored_to_twentyfive_above = ; - var Appointment_honored_to_uknown_age = ; - var Appointment_not_honoured_male = ; - var Appointment_not_honoured_female = ; - var Appointment_not_honoured_uknown_gender = ; - var Appointment_not_honored_to_nine = ; - var Appointment_not_honored_to_fourteen = ; - var Appointment_not_honored_to_nineteen = ; - var Appointment_not_honored_to_twentyfour = ; - var Appointment_not_honored_to_twentyfive_above = ; - var Appointment_not_honored_to_uknown_age = ; - - - var Appointment_missed_male = ; - var Appointment_missed_female = ; - var Appointment_missed_uknown_gender = ; - var Appointment_missed_to_nine = ; - var Appointment_missed_to_fourteen = ; - var Appointment_missed_to_nineteen = ; - var Appointment_missed_to_twentyfour = ; - var Appointment_missed_to_twentyfive_above = ; - var Appointment_missed_to_uknown_age = ; - var Appointment_defaulted_female = ; - var Appointment_defaulted_male = ; - var Appointment_defaulted_uknown_gender = ; - var Appointment_defaulted_to_nine = ; - var Appointment_defaulted_to_fourteen = ; - var Appointment_defaulted_to_nineteen = ; - var Appointment_defaulted_to_twentyfour = ; - var Appointment_defaulted_to_twentyfive_above = ; - var Appointment_defaulted_to_uknown_age = ; - var Appointment_ltfu_female = ; - var Appointment_ltfu_male = ; - var Appointment_ltfu_uknown_gender = ; - var Appointment_ltfu_to_nine = ; - var Appointment_ltfu_to_fourteen = ; - var Appointment_ltfu_to_nineteen = ; - var Appointment_ltfu_to_twentyfour = ; - var Appointment_ltfu_to_twentyfive_above = ; - var Appointment_ltfu_to_uknown_age = ; - $(document).ready(function() { $('select[name="partner"]').on('change', function() { @@ -1139,449 +928,7 @@ }); - //APPOINTMENT HONOURED GENDER - var appChart = Highcharts.chart('appointment_honoured_gender', { - chart: { - type: 'column' - }, - title: { - text: 'Appointment Honoured By Gender' - }, - xAxis: { - categories: ['Male', 'Female', 'UKNOWN Gender'] - }, - yAxis: { - min: 0, - title: { - text: 'No of Appointment Honoured' - }, - stackLabels: { - enabled: true, - style: { - fontWeight: 'bold', - color: ( // theme - Highcharts.defaultOptions.title.style && - Highcharts.defaultOptions.title.style.color - ) || 'gray' - } - } - }, - tooltip: { - formatter: function() { - return '' + this.x + '
' + - this.series.name + ': ' + this.y; - } - }, - plotOptions: { - column: { - stacking: 'normal', - } - }, - series: [{ - name: 'Gender', - data: [Appointment_honoured_male, Appointment_honoured_female, Appointment_honoured_uknown_gender] - }], - - }); -// APPOINTMENT HONOURED AGE - var appChart = Highcharts.chart('appointment_honoured_age', { - chart: { - type: 'column' - }, - title: { - text: 'Appointment Honoured By Age' - }, - xAxis: { - categories: ['0-9 YRS', '10-14 YRS', '15-19 YRS', '20-24 YRS', '25+ YRS', 'UKNOWN AGE'] - }, - yAxis: { - min: 0, - title: { - text: 'No of Appointment Honoured' - }, - stackLabels: { - enabled: true, - style: { - fontWeight: 'bold', - color: ( // theme - Highcharts.defaultOptions.title.style && - Highcharts.defaultOptions.title.style.color - ) || 'gray' - } - } - }, - tooltip: { - formatter: function() { - return '' + this.x + '
' + - this.series.name + ': ' + this.y; - } - }, - plotOptions: { - column: { - stacking: 'normal', - } - }, - series: [{ - name: 'Age', - data: [Appointment_honored_to_nine, Appointment_honored_to_fourteen, Appointment_honored_to_nineteen, Appointment_honored_to_twentyfour, Appointment_honored_to_twentyfive_above, Appointment_honored_to_uknown_age] - }], - - }); - - //APPOINTMENT NOT HONOURED GENDER - var appChart = Highcharts.chart('appointment_not_honoured_gender', { - chart: { - type: 'column' - }, - title: { - text: 'Appointment Not Honoured By Gender' - }, - xAxis: { - categories: ['Male', 'Female', 'UKNOWN Gender'] - }, - yAxis: { - min: 0, - title: { - text: 'No of Appointment Not Honoured' - }, - stackLabels: { - enabled: true, - style: { - fontWeight: 'bold', - color: ( // theme - Highcharts.defaultOptions.title.style && - Highcharts.defaultOptions.title.style.color - ) || 'gray' - } - } - }, - tooltip: { - formatter: function() { - return '' + this.x + '
' + - this.series.name + ': ' + this.y; - } - }, - plotOptions: { - column: { - stacking: 'normal', - } - }, - series: [{ - name: 'Gender', - data: [Appointment_not_honoured_male, Appointment_not_honoured_female, Appointment_not_honoured_uknown_gender] - }], - }); -// APPOINTMENT NOT HONOURED AGE - var appChart = Highcharts.chart('appointment_not_honoured_age', { - chart: { - type: 'column' - }, - title: { - text: 'Appointment Not Honoured By Age' - }, - xAxis: { - categories: ['0-9 YRS', '10-14 YRS', '15-19 YRS', '20-24 YRS', '25+ YRS', 'UKNOWN AGE'] - }, - yAxis: { - min: 0, - title: { - text: 'No of Appointment Not Honoured' - }, - stackLabels: { - enabled: true, - style: { - fontWeight: 'bold', - color: ( // theme - Highcharts.defaultOptions.title.style && - Highcharts.defaultOptions.title.style.color - ) || 'gray' - } - } - }, - tooltip: { - formatter: function() { - return '' + this.x + '
' + - this.series.name + ': ' + this.y; - } - }, - plotOptions: { - column: { - stacking: 'normal', - } - }, - series: [{ - name: 'Age', - data: [Appointment_not_honored_to_nine, Appointment_not_honored_to_fourteen, Appointment_not_honored_to_nineteen, Appointment_not_honored_to_twentyfour, Appointment_not_honored_to_twentyfive_above, Appointment_not_honored_to_uknown_age] - }], - - }); - - //MISSED APPOINTMENT BY GENDER - var appChart = Highcharts.chart('appointment_missed_gender', { - chart: { - type: 'column' - }, - title: { - text: 'Appointment Missed By Gender' - }, - xAxis: { - categories: ['Male', 'Female', 'UKNOWN Gender'] - }, - yAxis: { - min: 0, - title: { - text: 'No of Appointment Missed' - }, - stackLabels: { - enabled: true, - style: { - fontWeight: 'bold', - color: ( // theme - Highcharts.defaultOptions.title.style && - Highcharts.defaultOptions.title.style.color - ) || 'gray' - } - } - }, - tooltip: { - formatter: function() { - return '' + this.x + '
' + - this.series.name + ': ' + this.y; - } - }, - plotOptions: { - column: { - stacking: 'normal', - } - }, - series: [{ - name: 'Gender', - data: [Appointment_missed_male, Appointment_missed_female, Appointment_missed_uknown_gender] - }], - - }); -// APPOINTMENT MISSED AGE - var appChart = Highcharts.chart('appointment_missed_age', { - chart: { - type: 'column' - }, - title: { - text: 'Appointment Missed By Age' - }, - xAxis: { - categories: ['0-9 YRS', '10-14 YRS', '15-19 YRS', '20-24 YRS', '25+ YRS', 'UKNOWN AGE'] - }, - yAxis: { - min: 0, - title: { - text: 'No of Appointment Missed' - }, - stackLabels: { - enabled: true, - style: { - fontWeight: 'bold', - color: ( // theme - Highcharts.defaultOptions.title.style && - Highcharts.defaultOptions.title.style.color - ) || 'gray' - } - } - }, - tooltip: { - formatter: function() { - return '' + this.x + '
' + - this.series.name + ': ' + this.y; - } - }, - plotOptions: { - column: { - stacking: 'normal', - } - }, - series: [{ - name: 'Age', - data: [Appointment_missed_to_nine, Appointment_missed_to_fourteen, Appointment_missed_to_nineteen, Appointment_missed_to_twentyfour, Appointment_missed_to_twentyfive_above, Appointment_missed_to_uknown_age] - }], - - }); - //DEFAULTED APPOINTMENT BY GENDER - var appChart = Highcharts.chart('appointment_defaulted_gender', { - chart: { - type: 'column' - }, - title: { - text: 'Appointment Defaulted By Gender' - }, - xAxis: { - categories: ['Male', 'Female', 'UKNOWN Gender'] - }, - yAxis: { - min: 0, - title: { - text: 'No of Appointment Defaulted' - }, - stackLabels: { - enabled: true, - style: { - fontWeight: 'bold', - color: ( // theme - Highcharts.defaultOptions.title.style && - Highcharts.defaultOptions.title.style.color - ) || 'gray' - } - } - }, - tooltip: { - formatter: function() { - return '' + this.x + '
' + - this.series.name + ': ' + this.y; - } - }, - plotOptions: { - column: { - stacking: 'normal', - } - }, - series: [{ - name: 'Gender', - data: [Appointment_defaulted_male, Appointment_defaulted_female, Appointment_defaulted_uknown_gender] - }], - - }); -// APPOINTMENT DEFAULTED AGE - var appChart = Highcharts.chart('appointment_defaulted_age', { - chart: { - type: 'column' - }, - title: { - text: 'Appointment Defaulted By Age' - }, - xAxis: { - categories: ['0-9 YRS', '10-14 YRS', '15-19 YRS', '20-24 YRS', '25+ YRS', 'UKNOWN AGE'] - }, - yAxis: { - min: 0, - title: { - text: 'No of Appointment Defaulted' - }, - stackLabels: { - enabled: true, - style: { - fontWeight: 'bold', - color: ( // theme - Highcharts.defaultOptions.title.style && - Highcharts.defaultOptions.title.style.color - ) || 'gray' - } - } - }, - tooltip: { - formatter: function() { - return '' + this.x + '
' + - this.series.name + ': ' + this.y; - } - }, - plotOptions: { - column: { - stacking: 'normal', - } - }, - series: [{ - name: 'Age', - data: [Appointment_defaulted_to_nine, Appointment_defaulted_to_fourteen, Appointment_defaulted_to_nineteen, Appointment_defaulted_to_twentyfour, Appointment_defaulted_to_twentyfive_above, Appointment_defaulted_to_uknown_age] - }], - - }); - - //LTFU APPOINTMENT BY GENDER - var appChart = Highcharts.chart('appointment_ltfu_gender', { - chart: { - type: 'column' - }, - title: { - text: 'Appointment LTFU By Gender' - }, - xAxis: { - categories: ['Male', 'Female', 'UKNOWN Gender'] - }, - yAxis: { - min: 0, - title: { - text: 'No of Appointment LTFU' - }, - stackLabels: { - enabled: true, - style: { - fontWeight: 'bold', - color: ( // theme - Highcharts.defaultOptions.title.style && - Highcharts.defaultOptions.title.style.color - ) || 'gray' - } - } - }, - tooltip: { - formatter: function() { - return '' + this.x + '
' + - this.series.name + ': ' + this.y; - } - }, - plotOptions: { - column: { - stacking: 'normal', - } - }, - series: [{ - name: 'Gender', - data: [Appointment_ltfu_male, Appointment_ltfu_female, Appointment_ltfu_uknown_gender] - }], - - }); -// APPOINTMENT LTFU AGE - var appChart = Highcharts.chart('appointment_lftu_age', { - chart: { - type: 'column' - }, - title: { - text: 'Appointment LTFU By Age' - }, - xAxis: { - categories: ['0-9 YRS', '10-14 YRS', '15-19 YRS', '20-24 YRS', '25+ YRS', 'UKNOWN AGE'] - }, - yAxis: { - min: 0, - title: { - text: 'No of Appointment LTFU' - }, - stackLabels: { - enabled: true, - style: { - fontWeight: 'bold', - color: ( // theme - Highcharts.defaultOptions.title.style && - Highcharts.defaultOptions.title.style.color - ) || 'gray' - } - } - }, - tooltip: { - formatter: function() { - return '' + this.x + '
' + - this.series.name + ': ' + this.y; - } - }, - plotOptions: { - column: { - stacking: 'normal', - } - }, - series: [{ - name: 'Age', - data: [Appointment_ltfu_to_nine, Appointment_ltfu_to_fourteen, Appointment_ltfu_to_nineteen, Appointment_ltfu_to_twentyfour, Appointment_ltfu_to_twentyfive_above, Appointment_ltfu_to_uknown_age] - }], - - }); var colors = Highcharts.getOptions().colors; diff --git a/routes/web.php b/routes/web.php index 52fa307..8c669f7 100644 --- a/routes/web.php +++ b/routes/web.php @@ -200,5 +200,6 @@ // new dashbaord routes Route::get('/admin/dashboard', ['uses' => 'App\Http\Controllers\NewDashboardController@dashboard', 'as' => 'dashboard']); + Route::get('/admin/appointment/dashboard', ['uses' => 'App\Http\Controllers\NewDashboardController@appointment_charts', 'as' => 'appointment_charts']); Route::get('/filter_charts', ['uses' => 'App\Http\Controllers\NewDashboardController@filter_charts', 'as' => 'filter_charts']); }); From ace53f3262e76e61b6fc06d1820da6b744fd5047 Mon Sep 17 00:00:00 2001 From: Ronald-pro <36841157+Ronald-pro@users.noreply.github.com> Date: Thu, 28 Apr 2022 08:24:11 +0300 Subject: [PATCH 027/171] added filters --- config/app.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config/app.php b/config/app.php index b797cff..608bad4 100644 --- a/config/app.php +++ b/config/app.php @@ -175,7 +175,7 @@ App\Providers\EventServiceProvider::class, App\Providers\RouteServiceProvider::class, Maatwebsite\Excel\ExcelServiceProvider::class, - Barryvdh\Debugbar\ServiceProvider::class, + // Barryvdh\Debugbar\ServiceProvider::class, // MaddHatter\LaravelFullcalendar\ServiceProvider::class, From 299c4a4d37b480701754f4f8e4efb4eb4573b22e Mon Sep 17 00:00:00 2001 From: Ronald-pro <36841157+Ronald-pro@users.noreply.github.com> Date: Sat, 30 Apr 2022 17:12:52 +0300 Subject: [PATCH 028/171] adjustment on main dashboard and client dashboard filters --- .../Controllers/NewDashboardController.php | 3287 ++++++++++++----- app/Models/Appointments.php | 2 +- app/Models/Client.php | 4 + config/app.php | 2 +- .../appointment_dashboard.blade.php | 16 +- .../new_dashboard/main_dashbaord.blade.php | 137 +- 6 files changed, 2553 insertions(+), 895 deletions(-) diff --git a/app/Http/Controllers/NewDashboardController.php b/app/Http/Controllers/NewDashboardController.php index e440dfa..3e940e3 100644 --- a/app/Http/Controllers/NewDashboardController.php +++ b/app/Http/Controllers/NewDashboardController.php @@ -26,33 +26,28 @@ public function dashboard() // showing all the active clients, all appointments, missed appointments if (Auth::user()->access_level == 'Facility') { - - } - if (Auth::user()->access_level == 'Partner') { $all_partners = Partner::where('status', '=', 'Active')->pluck('name', 'id'); - $client = Client::join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') - ->where('tbl_client.status', '=', 'Active') - ->whereNull('tbl_client.hei_no') - ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) - ->count('tbl_client.clinic_number'); + $client = Client::where('status', '=', 'Active') + ->whereNull('hei_no') + ->where('mfl_code', Auth::user()->facility_id) + ->count('clinic_number'); $indicator = Indicator::select(['name', 'description'])->get(); $appointment = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') ->select('tbl_appointment.id') - ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) - ->count(); - $missed_appointment = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') - ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') - ->select('tbl_appointment.id') - ->whereIn('tbl_appointment.app_status', ['Defaulted', 'LTFU', 'Missed']) - ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) + ->where('tbl_partner_facility.mfl_code', Auth::user()->facility_id) ->count(); + $missed_appointment = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select('tbl_appointment.id') + ->whereIn('tbl_appointment.app_status', ['Defaulted', 'LTFU', 'Missed']) + ->where('tbl_partner_facility.mfl_code', Auth::user()->facility_id) + ->count(); $active_facilities = PartnerFacility::join('tbl_client', 'tbl_partner_facility.mfl_code', '=', 'tbl_client.mfl_code') ->join('tbl_appointment', 'tbl_client.id', '=', 'tbl_appointment.client_id') - ->select(\DB::raw('COUNT(tbl_partner_facility.mfl_code) as facilities')) + ->select('tbl_partner_facility.mfl_code') ->where('tbl_appointment.created_at', '>=', Carbon::now()->subMonths(6)) - ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) ->orderBy('tbl_appointment.created_at', 'DESC') ->groupBy('tbl_partner_facility.mfl_code') ->get(); @@ -60,78 +55,69 @@ public function dashboard() // dd($active_facilities); // active clients by gender - $clients_male = Client::join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') - ->select('id')->where([['tbl_client.gender', '=', '2'], ['tbl_client.status', '=', 'Active'],]) - ->whereNull('tbl_client.hei_no') - ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) + $clients_male = Client::select('id')->where([['gender', '=', '2'], ['status', '=', 'Active'],]) + ->whereNull('hei_no') + ->where('mfl_code', Auth::user()->facility_id) ->count(); - $clients_female = Client::join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') - ->where('tbl_client.gender', '=', '1') - ->where('tbl_client.status', '=', 'Active') - ->whereNull('tbl_client.hei_no') - ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) + $clients_female = Client::where('gender', '=', '1') + ->where('status', '=', 'Active') + ->whereNull('hei_no') + ->where('mfl_code', Auth::user()->facility_id) ->count(); - $unknown_gender = Client::join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') - ->where('tbl_client.gender', '!=', '1') - ->where('tbl_client.gender', '!=', '2') - ->where('tbl_client.status', '=', 'Active') - ->whereNull('tbl_client.hei_no') - ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) + $unknown_gender = Client::where('gender', '!=', '1') + ->where('gender', '!=', '2') + ->where('status', '=', 'Active') + ->whereNull('hei_no') + ->where('mfl_code', Auth::user()->facility_id) ->count(); $client_to_nine = Cache::remember('client_to_nine', 10, function () { - return Client::join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') - ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) > 0) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 9)) then `tbl_client`.`dob` end)) AS count")) - ->where('tbl_client.status', '=', 'Active') - ->whereNull('tbl_client.hei_no') - ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) + return Client::select(\DB::raw("count((case when (((year(curdate()) - year(`dob`)) > 0) and ((year(curdate()) - year(`dob`)) <= 9)) then `dob` end)) AS count")) + ->where('status', '=', 'Active') + ->whereNull('hei_no') + ->where('mfl_code', Auth::user()->facility_id) ->pluck('count'); }); $client_to_fourteen = Cache::remember('client-fourteen', 10, function () { - return Client::join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') - ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 10) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 14)) then `tbl_client`.`dob` end)) AS count")) - ->where('tbl_client.status', '=', 'Active') - ->whereNull('tbl_client.hei_no') - ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) + return Client::select(\DB::raw("count((case when (((year(curdate()) - year(`dob`)) >= 10) and ((year(curdate()) - year(`dob`)) <= 14)) then `dob` end)) AS count")) + ->where('status', '=', 'Active') + ->whereNull('hei_no') + ->where('mfl_code', Auth::user()->facility_id) ->pluck('count'); }); $client_to_nineteen = Cache::remember('client-nineteen', 10, function () { - return Client::join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') - ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 15) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 19)) then `tbl_client`.`dob` end)) AS count")) - ->where('tbl_client.status', '=', 'Active') - ->whereNull('tbl_client.hei_no') - ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) + return Client::select(\DB::raw("count((case when (((year(curdate()) - year(`dob`)) >= 15) and ((year(curdate()) - year(`dob`)) <= 19)) then `dob` end)) AS count")) + ->where('status', '=', 'Active') + ->whereNull('hei_no') + ->where('mfl_code', Auth::user()->facility_id) ->pluck('count'); }); $client_to_twentyfour = Cache::remember('client-twentyfour', 10, function () { - return Client::join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') - ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 20) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 24)) then `tbl_client`.`dob` end)) AS count")) - ->where('tbl_client.status', '=', 'Active') - ->whereNull('tbl_client.hei_no') - ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) + return Client::select(\DB::raw("count((case when (((year(curdate()) - year(`dob`)) >= 20) and ((year(curdate()) - year(`dob`)) <= 24)) then `id` end)) AS count")) + ->where('status', '=', 'Active') + ->whereNull('hei_no') + ->where('mfl_code', Auth::user()->facility_id) ->pluck('count'); }); $client_to_twentyfive_above = Cache::remember('client-twentyfive-above', 10, function () { - return Client::join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') - ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 25)) then `tbl_client`.`dob` end)) AS count")) - ->where('tbl_client.status', '=', 'Active') - ->whereNull('tbl_client.hei_no') - ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) + return Client::select(\DB::raw("count((case when (((year(curdate()) - year(`dob`)) >= 25)) then `id` end)) AS count")) + ->where('status', '=', 'Active') + ->whereNull('hei_no') + ->where('mfl_code', Auth::user()->facility_id) ->pluck('count'); }); $client_unknown_age = Cache::remember('client-unknown-age', 10, function () { - return Client::join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') - ->where('tbl_client.dob', '=', '') - ->orWhereNull('tbl_client.dob') - ->where('tbl_client.status', '=', 'Active') - ->whereNull('tbl_client.hei_no') - ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) + return Client::where('dob', '=', '') + ->orWhereNull('dob') + ->where('status', '=', 'Active') + ->whereNull('hei_no') + ->where('mfl_code', Auth::user()->facility_id) ->count(); }); @@ -141,7 +127,7 @@ public function dashboard() ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') ->select('tbl_appointment.id') ->where('tbl_client.gender', '=', '2') - ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) + ->where('tbl_partner_facility.mfl_code', Auth::user()->facility_id) ->count(); }); $appointment_female = Cache::remember('appointment-female', 10, function () { @@ -149,7 +135,7 @@ public function dashboard() ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') ->select('tbl_appointment.id') ->where('tbl_client.gender', '=', '1') - ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) + ->where('tbl_partner_facility.mfl_code', Auth::user()->facility_id) ->count(); }); $appointment_uknown_gender = Cache::remember('appointment-uknown-gender', 10, function () { @@ -158,422 +144,434 @@ public function dashboard() ->select('tbl_appointment.id') ->where('tbl_client.gender', '!=', '1') ->where('tbl_client.gender', '!=', '2') - ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) + ->where('tbl_partner_facility.mfl_code', Auth::user()->facility_id) ->count(); }); // appointment by age $appointment_to_nine = Cache::remember('appointment-to-nine', 10, function () { - return Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + return Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) > 0) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 9)) then `tbl_client`.`id` end)) AS count")) + ->where('tbl_partner_facility.mfl_code', Auth::user()->facility_id) + ->pluck('count'); + }); + $appointment_to_fourteen = Cache::remember('appointment-to-fourteen', 10, function () { + return Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 10) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 14)) then `tbl_client`.`id` end)) AS count")) + ->where('tbl_partner_facility.mfl_code', Auth::user()->facility_id) + ->pluck('count'); + }); + $appointment_to_nineteen = Cache::remember('appointment-to-nineteen', 10, function () { + return Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 15) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 19)) then `tbl_client`.`id` end)) AS count")) + ->where('tbl_partner_facility.mfl_code', Auth::user()->facility_id) + ->pluck('count'); + }); + $appointment_to_twentyfour = Cache::remember('appointment-to-twentyfour', 10, function () { + return Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 20) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 24)) then `tbl_client`.`id` end)) AS count")) + ->where('tbl_partner_facility.mfl_code', Auth::user()->facility_id) + ->pluck('count'); + }); + $appointment_to_twentyfive_above = Cache::remember('appointment-to-twentyfive-above', 10, function () { + return Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 25)) then `tbl_client`.`id` end)) AS count")) + ->where('tbl_partner_facility.mfl_code', Auth::user()->facility_id) + ->pluck('count'); + }); + + $appointment_uknown_age = Cache::remember('appointment-uknown-age', 10, function () { + return Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->where('tbl_client.dob', '=', '') + ->orWhereNull('tbl_client.dob') + ->where('tbl_partner_facility.mfl_code', Auth::user()->facility_id) + ->count(); + }); + + // Total missed appointment by gender + $appointment_total_missed_female = Cache::remember('appointment-total-missed-female', 10, function () { + return Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') - ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) > 0) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 9)) then `tbl_client`.`id` end)) AS count")) - ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) - ->pluck('count'); - }); - $appointment_to_fourteen = Cache::remember('appointment-to-fourteen', 10, function () { - return Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->where('tbl_client.gender', '=', '1') + ->whereIn('tbl_appointment.app_status', ['Defaulted', 'LTFU', 'Missed']) + ->where('tbl_partner_facility.mfl_code', Auth::user()->facility_id) + ->count(); + }); + $appointment_total_missed_male = Cache::remember('appointment-total-missed-male', 10, function () { + return Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->where('tbl_client.gender', '=', '2') + ->whereIn('tbl_appointment.app_status', ['Defaulted', 'LTFU', 'Missed']) + ->where('tbl_partner_facility.mfl_code', Auth::user()->facility_id) + ->count(); + }); + $appointment_total_missed_uknown_gender = Cache::remember('appointment-total-missed-uknown-gender', 10, function () { + return Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->where('tbl_client.gender', '!=', '1') + ->where('tbl_client.gender', '!=', '2') + ->whereIn('tbl_appointment.app_status', ['Defaulted', 'LTFU', 'Missed']) + ->where('tbl_partner_facility.mfl_code', Auth::user()->facility_id) + ->count(); + }); + + // Total missed appointment by age + $appointment_total_missed_to_nine = Cache::remember('appointment-total-missed-to-nine', 10, function () { + return Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') - ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 10) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 14)) then `tbl_client`.`id` end)) AS count")) - ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) - ->pluck('count'); + ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) > 0) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 9)) then `tbl_client`.`id` end)) AS count")) + ->whereIn('tbl_appointment.app_status', ['Defaulted', 'LTFU', 'Missed']) + ->where('tbl_partner_facility.mfl_code', Auth::user()->facility_id) + ->pluck('count'); + }); + $appointment_total_missed_to_fourteen = Cache::remember('appointment-total-missed-to-fourteen', 10, function () { + return Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 10) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 14)) then `tbl_client`.`id` end)) AS count")) + ->whereIn('tbl_appointment.app_status', ['Defaulted', 'LTFU', 'Missed']) + ->where('tbl_partner_facility.mfl_code', Auth::user()->facility_id) + ->pluck('count'); + }); + $appointment_total_missed_to_nineteen = Cache::remember('appointment-total-missed-to-nineteen', 10, function () { + return Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 15) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 19)) then `tbl_client`.`id` end)) AS count")) + ->whereIn('tbl_appointment.app_status', ['Defaulted', 'LTFU', 'Missed']) + ->where('tbl_partner_facility.mfl_code', Auth::user()->facility_id) + ->pluck('count'); + }); + $appointment_total_missed_to_twentyfour = Cache::remember('appointment-total-missed-to-twentyfour', 10, function () { + return Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 20) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 24)) then `tbl_client`.`id` end)) AS count")) + ->whereIn('tbl_appointment.app_status', ['Defaulted', 'LTFU', 'Missed']) + ->where('tbl_partner_facility.mfl_code', Auth::user()->facility_id) + ->pluck('count'); + }); + $appointment_total_missed_to_twentyfive_above = Cache::remember('appointment-total-missed-to-twentyfive_above', 10, function () { + return Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 25)) then `tbl_client`.`id` end)) AS count")) + ->whereIn('tbl_appointment.app_status', ['Defaulted', 'LTFU', 'Missed']) + ->where('tbl_partner_facility.mfl_code', Auth::user()->facility_id) + ->pluck('count'); + }); + $appointment_total_missed_uknown_age = Cache::remember('appointment-total-missed-uknown-age', 10, function () { + return Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->where('tbl_client.dob', '=', '') + ->whereIn('tbl_appointment.app_status', ['Defaulted', 'LTFU', 'Missed']) + ->where('tbl_partner_facility.mfl_code', Auth::user()->facility_id) + ->count(); + }); + // client charts + $client_consented = Cache::remember('client-consented', 10, function () { + return Client::select('smsenable') + ->where('status', '=', 'Active') + ->whereNull('hei_no') + ->where('smsenable', '=', 'Yes') + ->where('mfl_code', Auth::user()->facility_id) + ->count(); }); - $appointment_to_nineteen = Cache::remember('appointment-to-nineteen', 10, function () { - return Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') - ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') - ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 15) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 19)) then `tbl_client`.`id` end)) AS count")) - ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) - ->pluck('count'); + $client_nonconsented = Cache::remember('client-nonconsented', 10, function () { + return Client::select('smsenable') + ->where('status', '=', 'Active') + ->whereNull('hei_no') + ->where('smsenable', '!=', 'Yes') + ->where('mfl_code', Auth::user()->facility_id) + ->count(); }); - $appointment_to_twentyfour = Cache::remember('appointment-to-twentyfour', 10, function () { - return Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') - ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') - ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 20) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 24)) then `tbl_client`.`id` end)) AS count")) - ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) - ->pluck('count'); + // consented clients by gender + + $client_consented_male = Cache::remember('client-consented-male', 10, function () { + return Client::where('smsenable', '=', 'Yes') + ->where('status', '=', 'Active') + ->whereNull('hei_no') + ->where('gender', '=', '2') + ->where('mfl_code', Auth::user()->facility_id) + ->count(); }); - $appointment_to_twentyfive_above = Cache::remember('appointment-to-twentyfive-above', 10, function () { - return Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') - ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') - ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 25)) then `tbl_client`.`id` end)) AS count")) - ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) - ->pluck('count'); + $client_consented_female = Cache::remember('client-consented-female', 10, function () { + return Client::where('smsenable', '=', 'Yes') + ->where('status', '=', 'Active') + ->whereNull('hei_no') + ->where('gender', '=', '1') + ->where('mfl_code', Auth::user()->facility_id) + ->count(); }); - $appointment_uknown_age = Cache::remember('appointment-uknown-age', 10, function () { - return Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') - ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') - ->where('tbl_client.dob', '=', '') - ->orWhereNull('tbl_client.dob') - ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) + $client_consented_uknown_gender = Cache::remember('client-consented-uknown-gender', 10, function () { + return Client::where('smsenable', '=', 'Yes') + ->where('status', '=', 'Active') + ->whereNull('hei_no') + ->where('gender', '!=', '1') + ->where('gender', '!=', '2') + ->where('mfl_code', Auth::user()->facility_id) ->count(); }); - - // Total missed appointment by gender - $appointment_total_missed_female = Cache::remember('appointment-total-missed-female', 10, function () { - return Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') - ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') - ->where('tbl_client.gender', '=', '1') - ->whereIn('tbl_appointment.app_status', ['Defaulted', 'LTFU', 'Missed']) - ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) + // non consented clients by gender + $client_nonconsented_male = Cache::remember('client-nonconsented-male', 10, function () { + return Client::where('smsenable', '!=', 'Yes') + ->where('status', '=', 'Active') + ->whereNull('hei_no') + ->where('gender', '=', '2') + ->where('mfl_code', Auth::user()->facility_id) ->count(); }); - $appointment_total_missed_male = Cache::remember('appointment-total-missed-male', 10, function () { - return Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') - ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') - ->where('tbl_client.gender', '=', '2') - ->whereIn('tbl_appointment.app_status', ['Defaulted', 'LTFU', 'Missed']) - ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) + $client_nonconsented_female = Cache::remember('client-nonconsented-female', 10, function () { + return Client::where('smsenable', '!=', 'Yes') + ->where('status', '=', 'Active') + ->whereNull('hei_no') + ->where('gender', '=', '1') + ->where('mfl_code', Auth::user()->facility_id) ->count(); }); - $appointment_total_missed_uknown_gender = Cache::remember('appointment-total-missed-uknown-gender', 10, function () { - return Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') - ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') - ->where('tbl_client.gender', '!=', '1') - ->where('tbl_client.gender', '!=', '2') - ->whereIn('tbl_appointment.app_status', ['Defaulted', 'LTFU', 'Missed']) - ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) + $client_nonconsented_uknown_gender = Cache::remember('client-nonconsented-uknown-gender', 10, function () { + return Client::where('smsenable', '!=', 'Yes') + ->where('gender', '!=', '1') + ->where('gender', '!=', '2') + ->where('mfl_code', Auth::user()->facility_id) ->count(); }); - - // Total missed appointment by age - $appointment_total_missed_to_nine = Cache::remember('appointment-total-missed-to-nine', 10, function () { - return Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') - ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') - ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) > 0) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 9)) then `tbl_client`.`id` end)) AS count")) - ->whereIn('tbl_appointment.app_status', ['Defaulted', 'LTFU', 'Missed']) - ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) + // consented clients by age distribution + $client_consented_to_nine = Cache::remember('client-consented-to-nine', 10, function () { + return Client::select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) > 0) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 9)) then `tbl_client`.`id` end)) AS count")) + ->where('smsenable', '=', 'Yes') + ->where('status', '=', 'Active') + ->whereNull('hei_no') + ->where('mfl_code', Auth::user()->facility_id) ->pluck('count'); }); - $appointment_total_missed_to_fourteen = Cache::remember('appointment-total-missed-to-fourteen', 10, function () { - return Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') - ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') - ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 10) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 14)) then `tbl_client`.`id` end)) AS count")) - ->whereIn('tbl_appointment.app_status', ['Defaulted', 'LTFU', 'Missed']) - ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) + $client_consented_to_fourteen = Cache::remember('tbl-client', 10, function () { + return Client::select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 10) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 14)) then `tbl_client`.`id` end)) AS count")) + ->where('smsenable', '=', 'Yes') + ->where('status', '=', 'Active') + ->whereNull('hei_no') + ->where('mfl_code', Auth::user()->facility_id) ->pluck('count'); }); - $appointment_total_missed_to_nineteen = Cache::remember('appointment-total-missed-to-nineteen', 10, function () { - return Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') - ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') - ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 15) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 19)) then `tbl_client`.`id` end)) AS count")) - ->whereIn('tbl_appointment.app_status', ['Defaulted', 'LTFU', 'Missed']) - ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) + $client_consented_to_nineteen = Cache::remember('client-consented-to-nineteen', 10, function () { + return Client::select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 15) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 19)) then `tbl_client`.`id` end)) AS count")) + ->where('smsenable', '=', 'Yes') + ->where('status', '=', 'Active') + ->whereNull('hei_no') + ->where('mfl_code', Auth::user()->facility_id) ->pluck('count'); }); - $appointment_total_missed_to_twentyfour = Cache::remember('appointment-total-missed-to-twentyfour', 10, function () { - return Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') - ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') - ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 20) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 24)) then `tbl_client`.`id` end)) AS count")) - ->whereIn('tbl_appointment.app_status', ['Defaulted', 'LTFU', 'Missed']) - ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) + $client_consented_to_twentyfour = Cache::remember('client-consented-to-twentyfour', 10, function () { + return Client::select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 20) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 24)) then `tbl_client`.`id` end)) AS count")) + ->where('smsenable', '=', 'Yes') + ->where('status', '=', 'Active') + ->whereNull('hei_no') + ->where('mfl_code', Auth::user()->facility_id) ->pluck('count'); }); - $appointment_total_missed_to_twentyfive_above = Cache::remember('appointment-total-missed-to-twentyfive_above', 10, function () { - return Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') - ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') - ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 25)) then `tbl_client`.`id` end)) AS count")) - ->whereIn('tbl_appointment.app_status', ['Defaulted', 'LTFU', 'Missed']) - ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) + $client_consented_to_twentyfive_above = Cache::remember('client-consented-to-twentyfive-above', 10, function () { + return Client::select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 25)) then `tbl_client`.`id` end)) AS count")) + ->where('smsenable', '=', 'Yes') + ->where('status', '=', 'Active') + ->whereNull('hei_no') + ->where('mfl_code', Auth::user()->facility_id) ->pluck('count'); }); - $appointment_total_missed_uknown_age = Cache::remember('appointment-total-missed-uknown-age', 10, function () { - return Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') - ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') - ->where('tbl_client.dob', '=', '') - ->whereIn('tbl_appointment.app_status', ['Defaulted', 'LTFU', 'Missed']) - ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) + $client_consented_uknown_age = Cache::remember('client-consented-uknown-age', 10, function () { + return Client::select('smsenable') + ->where('dob', '=', '') + ->where('status', '=', 'Active') + ->whereNull('hei_no') + ->orWhereNull('dob') + ->where('smsenable', '=', 'Yes') + ->where('mfl_code', Auth::user()->facility_id) ->count(); }); - // client charts - $client_consented = Cache::remember('client-consented', 10, function () { - return Client::join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') - ->select('tbl_clientsmsenable') - ->where('tbl_client.status', '=', 'Active') - ->whereNull('tbl_client.hei_no') - ->where('tbl_client.smsenable', '=', 'Yes') - ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) - ->count(); + // non consented clients by age distribution + $client_nonconsented_to_nine = Cache::remember('client-nonconsented-to-nine', 10, function () { + return Client::select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) > 0) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 9)) then `tbl_client`.`id` end)) AS count")) + ->where('smsenable', '!=', 'Yes') + ->where('status', '=', 'Active') + ->whereNull('hei_no') + ->where('mfl_code', Auth::user()->facility_id) + ->pluck('count'); }); - $client_nonconsented = Cache::remember('client-nonconsented', 10, function () { - return Client::join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') - ->select('smsenable') - ->where('tbl_client.status', '=', 'Active') - ->whereNull('tbl_client.hei_no') - ->where('tbl_client.smsenable', '!=', 'Yes') - ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) + $client_nonconsented_to_fourteen = Cache::remember('client-nonconsented-to-fourteen', 10, function () { + return Client::select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 10) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 14)) then `tbl_client`.`id` end)) AS count")) + ->where('smsenable', '!=', 'Yes') + ->where('status', '=', 'Active') + ->whereNull('hei_no') + ->where('mfl_code', Auth::user()->facility_id) + ->pluck('count'); + }); + $client_nonconsented_to_nineteen = Cache::remember('client-nonconsented-to-nineteen', 10, function () { + return Client::select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 15) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 19)) then `tbl_client`.`id` end)) AS count")) + ->where('smsenable', '!=', 'Yes') + ->where('status', '=', 'Active') + ->whereNull('hei_no') + ->where('mfl_code', Auth::user()->facility_id) + ->pluck('count'); + }); + $client_nonconsented_to_twentyfour = Cache::remember('client-nonconsented-to-twentyfour', 10, function () { + return Client::select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 20) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 24)) then `tbl_client`.`id` end)) AS count")) + ->where('smsenable', '!=', 'Yes') + ->where('status', '=', 'Active') + ->whereNull('hei_no') + ->where('mfl_code', Auth::user()->facility_id) + ->pluck('count'); + }); + $client_nonconsented_to_twentyfive_above = Cache::remember('client-nonconsented-to-twentyfive-above', 10, function () { + return Client::select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 25)) then `tbl_client`.`id` end)) AS count")) + ->where('smsenable', '!=', 'Yes') + ->where('status', '=', 'Active') + ->whereNull('hei_no') + ->where('mfl_code', Auth::user()->facility_id) + ->pluck('count'); + }); + $client_nonconsented_uknown_age = Cache::remember('client-nonconsented-uknown-age', 10, function () { + return Client::select('smsenable') + ->where('status', '=', 'Active') + ->whereNull('hei_no') + ->where('dob', '=', '') + ->orWhereNull('dob') + ->where('smsenable', '!=', 'Yes') + ->where('mfl_code', Auth::user()->facility_id) ->count(); }); - // consented clients by gender - $client_consented_male = Cache::remember('client-consented-male', 10, function () { - return Client::join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') - ->where('tbl_client.smsenable', '=', 'Yes') - ->where('tbl_client.status', '=', 'Active') + } + if (Auth::user()->access_level == 'Partner') { + $all_partners = Partner::where('status', '=', 'Active')->pluck('name', 'id'); + $client = Client::join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->where('tbl_client.status', '=', 'Active') ->whereNull('tbl_client.hei_no') - ->where('tbl_client.gender', '=', '2') ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) + ->count('tbl_client.clinic_number'); + + $indicator = Indicator::select(['name', 'description'])->get(); + $appointment = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select('tbl_appointment.id') + ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) ->count(); - }); - $client_consented_female = Cache::remember('client-consented-female', 10, function () { - return Client::join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') - ->where('tbl_client.smsenable', '=', 'Yes') - ->where('tbl_client.status', '=', 'Active') - ->whereNull('tbl_client.hei_no') - ->where('tbl_client.gender', '=', '1') + $missed_appointment = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select('tbl_appointment.id') + ->whereIn('tbl_appointment.app_status', ['Defaulted', 'LTFU', 'Missed']) ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) ->count(); - }); - $client_consented_uknown_gender = Cache::remember('client-consented-uknown-gender', 10, function () { - return Client::join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') - ->where('tbl_client.smsenable', '=', 'Yes') - ->where('tbl_client.status', '=', 'Active') - ->whereNull('tbl_client.hei_no') - ->where('tbl_client.gender', '!=', '1') - ->where('tbl_client.gender', '!=', '2') + $active_facilities = PartnerFacility::join('tbl_client', 'tbl_partner_facility.mfl_code', '=', 'tbl_client.mfl_code') + ->join('tbl_appointment', 'tbl_client.id', '=', 'tbl_appointment.client_id') + ->select(\DB::raw('COUNT(tbl_partner_facility.mfl_code) as facilities')) + ->where('tbl_appointment.created_at', '>=', Carbon::now()->subMonths(6)) ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) - ->count(); - }); - // non consented clients by gender - $client_nonconsented_male = Cache::remember('client-nonconsented-male', 10, function () { - return Client::join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') - ->where('tbl_client.smsenable', '!=', 'Yes') - ->where('tbl_client.status', '=', 'Active') + ->orderBy('tbl_appointment.created_at', 'DESC') + ->groupBy('tbl_partner_facility.mfl_code') + ->get(); + + + // dd($active_facilities); + // active clients by gender + $clients_male = Client::join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select('id')->where([['tbl_client.gender', '=', '2'], ['tbl_client.status', '=', 'Active'],]) ->whereNull('tbl_client.hei_no') - ->where('tbl_client.gender', '=', '2') ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) ->count(); - }); - $client_nonconsented_female = Cache::remember('client-nonconsented-female', 10, function () { - return Client::join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') - ->where('tbl_client.smsenable', '!=', 'Yes') + + $clients_female = Client::join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->where('tbl_client.gender', '=', '1') ->where('tbl_client.status', '=', 'Active') ->whereNull('tbl_client.hei_no') - ->where('tbl_client.gender', '=', '1') ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) ->count(); - }); - $client_nonconsented_uknown_gender = Cache::remember('client-nonconsented-uknown-gender', 10, function () { - return Client::join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') - ->where('tbl_client.smsenable', '!=', 'Yes') - ->where('tbl_client.gender', '!=', '1') + $unknown_gender = Client::join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->where('tbl_client.gender', '!=', '1') ->where('tbl_client.gender', '!=', '2') - ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) - ->count(); - }); - // consented clients by age distribution - $client_consented_to_nine = Cache::remember('client-consented-to-nine', 10, function () { - return Client::join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') - ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) > 0) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 9)) then `tbl_client`.`id` end)) AS count")) - ->where('tbl_client.smsenable', '=', 'Yes') ->where('tbl_client.status', '=', 'Active') ->whereNull('tbl_client.hei_no') ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) - ->pluck('count'); - }); - $client_consented_to_fourteen = Cache::remember('tbl-client', 10, function () { + ->count(); + + $client_to_nine = Cache::remember('client_to_nine', 10, function () { return Client::join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') - ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 10) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 14)) then `tbl_client`.`id` end)) AS count")) - ->where('tbl_client.smsenable', '=', 'Yes') + ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) > 0) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 9)) then `tbl_client`.`dob` end)) AS count")) ->where('tbl_client.status', '=', 'Active') ->whereNull('tbl_client.hei_no') ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) ->pluck('count'); }); - $client_consented_to_nineteen = Cache::remember('client-consented-to-nineteen', 10, function () { + + $client_to_fourteen = Cache::remember('client-fourteen', 10, function () { return Client::join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') - ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 15) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 19)) then `tbl_client`.`id` end)) AS count")) - ->where('tbl_client.smsenable', '=', 'Yes') + ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 10) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 14)) then `tbl_client`.`dob` end)) AS count")) ->where('tbl_client.status', '=', 'Active') ->whereNull('tbl_client.hei_no') ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) ->pluck('count'); }); - $client_consented_to_twentyfour = Cache::remember('client-consented-to-twentyfour', 10, function () { + + $client_to_nineteen = Cache::remember('client-nineteen', 10, function () { return Client::join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') - ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 20) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 24)) then `tbl_client`.`id` end)) AS count")) - ->where('tbl_client.smsenable', '=', 'Yes') + ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 15) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 19)) then `tbl_client`.`dob` end)) AS count")) ->where('tbl_client.status', '=', 'Active') ->whereNull('tbl_client.hei_no') ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) ->pluck('count'); }); - $client_consented_to_twentyfive_above = Cache::remember('client-consented-to-twentyfive-above', 10, function () { + + $client_to_twentyfour = Cache::remember('client-twentyfour', 10, function () { return Client::join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') - ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 25)) then `tbl_client`.`id` end)) AS count")) - ->where('tbl_client.smsenable', '=', 'Yes') + ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 20) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 24)) then `tbl_client`.`dob` end)) AS count")) ->where('tbl_client.status', '=', 'Active') ->whereNull('tbl_client.hei_no') ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) ->pluck('count'); }); - $client_consented_uknown_age = Cache::remember('client-consented-uknown-age', 10, function () { - return Client::join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') - ->select('tbl_client.smsenable') - ->where('tbl_client.dob', '=', '') + + $client_to_twentyfive_above = Cache::remember('client-twentyfive-above', 10, function () { + return Client::join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 25)) then `tbl_client`.`dob` end)) AS count")) ->where('tbl_client.status', '=', 'Active') ->whereNull('tbl_client.hei_no') - ->orWhereNull('tbl_client.dob') - ->where('tbl_client.smsenable', '=', 'Yes') ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) - ->count(); + ->pluck('count'); }); - // non consented clients by age distribution - $client_nonconsented_to_nine = Cache::remember('client-nonconsented-to-nine', 10, function () { + + $client_unknown_age = Cache::remember('client-unknown-age', 10, function () { return Client::join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') - ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) > 0) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 9)) then `tbl_client`.`id` end)) AS count")) - ->where('tbl_client.smsenable', '!=', 'Yes') + ->where('tbl_client.dob', '=', '') + ->orWhereNull('tbl_client.dob') ->where('tbl_client.status', '=', 'Active') ->whereNull('tbl_client.hei_no') ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) - ->pluck('count'); + ->count(); }); - $client_nonconsented_to_fourteen = Cache::remember('client-nonconsented-to-fourteen', 10, function () { - return Client::join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') - ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 10) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 14)) then `tbl_client`.`id` end)) AS count")) - ->where('tbl_client.smsenable', '!=', 'Yes') - ->where('tbl_client.status', '=', 'Active') - ->whereNull('tbl_client.hei_no') + + // appointment by gender + $appointment_male = Cache::remember('appointment-male', 10, function () { + return Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select('tbl_appointment.id') + ->where('tbl_client.gender', '=', '2') ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) - ->pluck('count'); - }); - $client_nonconsented_to_nineteen = Cache::remember('client-nonconsented-to-nineteen', 10, function () { - return Client::join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') - ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 15) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 19)) then `tbl_client`.`id` end)) AS count")) - ->where('tbl_client.smsenable', '!=', 'Yes') - ->where('tbl_client.status', '=', 'Active') - ->whereNull('tbl_client.hei_no') - ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) - ->pluck('count'); - }); - $client_nonconsented_to_twentyfour = Cache::remember('client-nonconsented-to-twentyfour', 10, function () { - return Client::join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') - ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 20) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 24)) then `tbl_client`.`id` end)) AS count")) - ->where('tbl_client.smsenable', '!=', 'Yes') - ->where('tbl_client.status', '=', 'Active') - ->whereNull('tbl_client.hei_no') - ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) - ->pluck('count'); - }); - $client_nonconsented_to_twentyfive_above = Cache::remember('client-nonconsented-to-twentyfive-above', 10, function () { - return Client::join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') - ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 25)) then `tbl_client`.`id` end)) AS count")) - ->where('tbl_client.smsenable', '!=', 'Yes') - ->where('tbl_client.status', '=', 'Active') - ->whereNull('tbl_client.hei_no') - ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) - ->pluck('count'); - }); - $client_nonconsented_uknown_age = Cache::remember('client-nonconsented-uknown-age', 10, function () { - return Client::join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') - ->select('tbl_client.smsenable') - ->where('tbl_client.status', '=', 'Active') - ->whereNull('tbl_client.hei_no') - ->where('tbl_client.dob', '=', '') - ->orWhereNull('tbl_client.dob') - ->where('tbl_client.smsenable', '!=', 'Yes') - ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) - ->count(); - }); - - } - if (Auth::user()->access_level == 'Admin' || Auth::user()->access_level == 'Donor') { - - $all_partners = Partner::where('status', '=', 'Active')->pluck('name', 'id'); - $client = Client::where('status', '=', 'Active') - ->whereNull('hei_no') - ->count('clinic_number'); - - $indicator = Indicator::select(['name', 'description'])->get(); - $appointment = Appointments::select('id') - ->count(); - $missed_appointment = Appointments::select('id') - ->whereIn('app_status', ['Defaulted', 'LTFU', 'Missed']) - ->count(); - // dd($missed_appointment); - $active_facilities = PartnerFacility::join('tbl_client', 'tbl_partner_facility.mfl_code', '=', 'tbl_client.mfl_code') - ->join('tbl_appointment', 'tbl_client.id', '=', 'tbl_appointment.client_id') - ->select(\DB::raw('COUNT(tbl_partner_facility.mfl_code) as facilities')) - ->where('tbl_appointment.created_at', '>=', Carbon::now()->subMonths(6)) - ->orderBy('tbl_appointment.created_at', 'DESC') - ->groupBy('tbl_partner_facility.mfl_code') - ->get(); - - - // dd($active_facilities); - // active clients by gender - $clients_male = Client::select('id')->where([['gender', '=', '2'], ['status', '=', 'Active'],]) - ->whereNull('hei_no') - ->count(); - - $clients_female = Client::where('gender', '=', '1') - ->where('status', '=', 'Active') - ->whereNull('hei_no') - ->count(); - $unknown_gender = Client::where('gender', '!=', '1') - ->where('gender', '!=', '2') - ->where('status', '=', 'Active') - ->whereNull('hei_no') - ->count(); - - $client_to_nine = Cache::remember('client_to_nine', 10, function () { - return Client::select(\DB::raw("count((case when (((year(curdate()) - year(`dob`)) > 0) and ((year(curdate()) - year(`dob`)) <= 9)) then `dob` end)) AS count")) - ->where('status', '=', 'Active') - ->whereNull('hei_no') - ->pluck('count'); - }); - - $client_to_fourteen = Cache::remember('client-fourteen', 10, function () { - return Client::select(\DB::raw("count((case when (((year(curdate()) - year(`dob`)) >= 10) and ((year(curdate()) - year(`dob`)) <= 14)) then `dob` end)) AS count")) - ->where('status', '=', 'Active') - ->whereNull('hei_no') - ->pluck('count'); - }); - - $client_to_nineteen = Cache::remember('client-nineteen', 10, function () { - return Client::select(\DB::raw("count((case when (((year(curdate()) - year(`dob`)) >= 15) and ((year(curdate()) - year(`dob`)) <= 19)) then `dob` end)) AS count")) - ->where('status', '=', 'Active') - ->whereNull('hei_no') - ->pluck('count'); - }); - - $client_to_twentyfour = Cache::remember('client-twentyfour', 10, function () { - return Client::select(\DB::raw("count((case when (((year(curdate()) - year(`dob`)) >= 20) and ((year(curdate()) - year(`dob`)) <= 24)) then `id` end)) AS count")) - ->where('status', '=', 'Active') - ->whereNull('hei_no') - ->pluck('count'); - }); - - $client_to_twentyfive_above = Cache::remember('client-twentyfive-above', 10, function () { - return Client::select(\DB::raw("count((case when (((year(curdate()) - year(`dob`)) >= 25)) then `id` end)) AS count")) - ->where('status', '=', 'Active') - ->whereNull('hei_no') - ->pluck('count'); - }); - - $client_unknown_age = Cache::remember('client-unknown-age', 10, function () { - return Client::where('dob', '=', '') - ->orWhereNull('dob') - ->where('status', '=', 'Active') - ->whereNull('hei_no') - ->count(); - }); - - // appointment by gender - $appointment_male = Cache::remember('appointment-male', 10, function () { - return Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') - ->select('tbl_appointment.id') - ->where('tbl_client.gender', '=', '2') - ->count(); + ->count(); }); $appointment_female = Cache::remember('appointment-female', 10, function () { return Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') ->select('tbl_appointment.id') ->where('tbl_client.gender', '=', '1') + ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) ->count(); }); $appointment_uknown_gender = Cache::remember('appointment-uknown-gender', 10, function () { return Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') ->select('tbl_appointment.id') ->where('tbl_client.gender', '!=', '1') ->where('tbl_client.gender', '!=', '2') + ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) ->count(); }); // appointment by age @@ -581,30 +579,35 @@ public function dashboard() return Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) > 0) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 9)) then `tbl_client`.`id` end)) AS count")) + ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) ->pluck('count'); }); $appointment_to_fourteen = Cache::remember('appointment-to-fourteen', 10, function () { return Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 10) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 14)) then `tbl_client`.`id` end)) AS count")) + ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) ->pluck('count'); }); $appointment_to_nineteen = Cache::remember('appointment-to-nineteen', 10, function () { return Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 15) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 19)) then `tbl_client`.`id` end)) AS count")) + ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) ->pluck('count'); }); $appointment_to_twentyfour = Cache::remember('appointment-to-twentyfour', 10, function () { return Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 20) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 24)) then `tbl_client`.`id` end)) AS count")) + ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) ->pluck('count'); }); $appointment_to_twentyfive_above = Cache::remember('appointment-to-twentyfive-above', 10, function () { return Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 25)) then `tbl_client`.`id` end)) AS count")) + ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) ->pluck('count'); }); $appointment_uknown_age = Cache::remember('appointment-uknown-age', 10, function () { @@ -612,333 +615,1420 @@ public function dashboard() ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') ->where('tbl_client.dob', '=', '') ->orWhereNull('tbl_client.dob') + ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) ->count(); }); // Total missed appointment by gender $appointment_total_missed_female = Cache::remember('appointment-total-missed-female', 10, function () { return Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') - ->whereIn('tbl_appointment.app_status', ['Defaulted', 'LTFU', 'Missed']) + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') ->where('tbl_client.gender', '=', '1') + ->whereIn('tbl_appointment.app_status', ['Defaulted', 'LTFU', 'Missed']) + ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) ->count(); }); $appointment_total_missed_male = Cache::remember('appointment-total-missed-male', 10, function () { return Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') ->where('tbl_client.gender', '=', '2') ->whereIn('tbl_appointment.app_status', ['Defaulted', 'LTFU', 'Missed']) + ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) ->count(); }); $appointment_total_missed_uknown_gender = Cache::remember('appointment-total-missed-uknown-gender', 10, function () { return Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') - ->whereIn('tbl_appointment.app_status', ['Defaulted', 'LTFU', 'Missed']) + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') ->where('tbl_client.gender', '!=', '1') ->where('tbl_client.gender', '!=', '2') + ->whereIn('tbl_appointment.app_status', ['Defaulted', 'LTFU', 'Missed']) + ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) ->count(); }); // Total missed appointment by age $appointment_total_missed_to_nine = Cache::remember('appointment-total-missed-to-nine', 10, function () { return Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) > 0) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 9)) then `tbl_client`.`id` end)) AS count")) ->whereIn('tbl_appointment.app_status', ['Defaulted', 'LTFU', 'Missed']) + ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) ->pluck('count'); }); $appointment_total_missed_to_fourteen = Cache::remember('appointment-total-missed-to-fourteen', 10, function () { return Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 10) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 14)) then `tbl_client`.`id` end)) AS count")) ->whereIn('tbl_appointment.app_status', ['Defaulted', 'LTFU', 'Missed']) + ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) ->pluck('count'); }); $appointment_total_missed_to_nineteen = Cache::remember('appointment-total-missed-to-nineteen', 10, function () { return Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 15) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 19)) then `tbl_client`.`id` end)) AS count")) ->whereIn('tbl_appointment.app_status', ['Defaulted', 'LTFU', 'Missed']) + ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) ->pluck('count'); }); $appointment_total_missed_to_twentyfour = Cache::remember('appointment-total-missed-to-twentyfour', 10, function () { return Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 20) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 24)) then `tbl_client`.`id` end)) AS count")) ->whereIn('tbl_appointment.app_status', ['Defaulted', 'LTFU', 'Missed']) + ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) ->pluck('count'); }); $appointment_total_missed_to_twentyfive_above = Cache::remember('appointment-total-missed-to-twentyfive_above', 10, function () { return Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 25)) then `tbl_client`.`id` end)) AS count")) ->whereIn('tbl_appointment.app_status', ['Defaulted', 'LTFU', 'Missed']) + ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) ->pluck('count'); }); $appointment_total_missed_uknown_age = Cache::remember('appointment-total-missed-uknown-age', 10, function () { return Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') ->where('tbl_client.dob', '=', '') - ->orWhereNull('tbl_client.dob') ->whereIn('tbl_appointment.app_status', ['Defaulted', 'LTFU', 'Missed']) + ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) ->count(); }); // client charts $client_consented = Cache::remember('client-consented', 10, function () { - return Client::select('smsenable') - ->where('status', '=', 'Active') - ->whereNull('hei_no') - ->where('smsenable', '=', 'Yes') + return Client::join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select('tbl_clientsmsenable') + ->where('tbl_client.status', '=', 'Active') + ->whereNull('tbl_client.hei_no') + ->where('tbl_client.smsenable', '=', 'Yes') + ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) ->count(); }); $client_nonconsented = Cache::remember('client-nonconsented', 10, function () { - return Client::select('smsenable') - ->where('status', '=', 'Active') - ->whereNull('hei_no') - ->where('smsenable', '!=', 'Yes') + return Client::join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select('smsenable') + ->where('tbl_client.status', '=', 'Active') + ->whereNull('tbl_client.hei_no') + ->where('tbl_client.smsenable', '!=', 'Yes') + ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) ->count(); }); // consented clients by gender $client_consented_male = Cache::remember('client-consented-male', 10, function () { - return Client::where('smsenable', '=', 'Yes') - ->where('status', '=', 'Active') - ->whereNull('hei_no') - ->where('gender', '=', '2') + return Client::join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->where('tbl_client.smsenable', '=', 'Yes') + ->where('tbl_client.status', '=', 'Active') + ->whereNull('tbl_client.hei_no') + ->where('tbl_client.gender', '=', '2') + ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) ->count(); }); $client_consented_female = Cache::remember('client-consented-female', 10, function () { - return Client::where('smsenable', '=', 'Yes') - ->where('status', '=', 'Active') - ->whereNull('hei_no') - ->where('gender', '=', '1') + return Client::join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->where('tbl_client.smsenable', '=', 'Yes') + ->where('tbl_client.status', '=', 'Active') + ->whereNull('tbl_client.hei_no') + ->where('tbl_client.gender', '=', '1') + ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) ->count(); }); $client_consented_uknown_gender = Cache::remember('client-consented-uknown-gender', 10, function () { - return Client::where('smsenable', '=', 'Yes') - ->where('status', '=', 'Active') - ->whereNull('hei_no') - ->where('gender', '!=', '1') - ->where('gender', '!=', '2') + return Client::join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->where('tbl_client.smsenable', '=', 'Yes') + ->where('tbl_client.status', '=', 'Active') + ->whereNull('tbl_client.hei_no') + ->where('tbl_client.gender', '!=', '1') + ->where('tbl_client.gender', '!=', '2') + ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) ->count(); }); // non consented clients by gender $client_nonconsented_male = Cache::remember('client-nonconsented-male', 10, function () { - return Client::where('smsenable', '!=', 'Yes') - ->where('status', '=', 'Active') - ->whereNull('hei_no') - ->where('gender', '=', '2') + return Client::join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->where('tbl_client.smsenable', '!=', 'Yes') + ->where('tbl_client.status', '=', 'Active') + ->whereNull('tbl_client.hei_no') + ->where('tbl_client.gender', '=', '2') + ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) ->count(); }); $client_nonconsented_female = Cache::remember('client-nonconsented-female', 10, function () { - return Client::where('smsenable', '!=', 'Yes') - ->where('status', '=', 'Active') - ->whereNull('hei_no') - ->where('gender', '=', '1') + return Client::join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->where('tbl_client.smsenable', '!=', 'Yes') + ->where('tbl_client.status', '=', 'Active') + ->whereNull('tbl_client.hei_no') + ->where('tbl_client.gender', '=', '1') + ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) ->count(); }); $client_nonconsented_uknown_gender = Cache::remember('client-nonconsented-uknown-gender', 10, function () { - return Client::where('smsenable', '!=', 'Yes') - ->where('gender', '!=', '1') - ->where('gender', '!=', '2') + return Client::join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->where('tbl_client.smsenable', '!=', 'Yes') + ->where('tbl_client.gender', '!=', '1') + ->where('tbl_client.gender', '!=', '2') + ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) ->count(); }); // consented clients by age distribution $client_consented_to_nine = Cache::remember('client-consented-to-nine', 10, function () { - return Client::select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) > 0) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 9)) then `tbl_client`.`id` end)) AS count")) - ->where('smsenable', '=', 'Yes') - ->where('status', '=', 'Active') - ->whereNull('hei_no') + return Client::join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) > 0) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 9)) then `tbl_client`.`id` end)) AS count")) + ->where('tbl_client.smsenable', '=', 'Yes') + ->where('tbl_client.status', '=', 'Active') + ->whereNull('tbl_client.hei_no') + ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) ->pluck('count'); }); $client_consented_to_fourteen = Cache::remember('tbl-client', 10, function () { - return Client::select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 10) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 14)) then `tbl_client`.`id` end)) AS count")) - ->where('smsenable', '=', 'Yes') - ->where('status', '=', 'Active') - ->whereNull('hei_no') - ->pluck('count'); - }); + return Client::join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 10) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 14)) then `tbl_client`.`id` end)) AS count")) + ->where('tbl_client.smsenable', '=', 'Yes') + ->where('tbl_client.status', '=', 'Active') + ->whereNull('tbl_client.hei_no') + ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) + ->pluck('count'); + }); $client_consented_to_nineteen = Cache::remember('client-consented-to-nineteen', 10, function () { - return Client::select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 15) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 19)) then `tbl_client`.`id` end)) AS count")) - ->where('smsenable', '=', 'Yes') - ->where('status', '=', 'Active') - ->whereNull('hei_no') + return Client::join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 15) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 19)) then `tbl_client`.`id` end)) AS count")) + ->where('tbl_client.smsenable', '=', 'Yes') + ->where('tbl_client.status', '=', 'Active') + ->whereNull('tbl_client.hei_no') + ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) ->pluck('count'); }); $client_consented_to_twentyfour = Cache::remember('client-consented-to-twentyfour', 10, function () { - return Client::select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 20) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 24)) then `tbl_client`.`id` end)) AS count")) - ->where('smsenable', '=', 'Yes') - ->where('status', '=', 'Active') - ->whereNull('hei_no') + return Client::join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 20) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 24)) then `tbl_client`.`id` end)) AS count")) + ->where('tbl_client.smsenable', '=', 'Yes') + ->where('tbl_client.status', '=', 'Active') + ->whereNull('tbl_client.hei_no') + ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) ->pluck('count'); }); $client_consented_to_twentyfive_above = Cache::remember('client-consented-to-twentyfive-above', 10, function () { - return Client::select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 25)) then `tbl_client`.`id` end)) AS count")) - ->where('smsenable', '=', 'Yes') - ->where('status', '=', 'Active') - ->whereNull('hei_no') + return Client::join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 25)) then `tbl_client`.`id` end)) AS count")) + ->where('tbl_client.smsenable', '=', 'Yes') + ->where('tbl_client.status', '=', 'Active') + ->whereNull('tbl_client.hei_no') + ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) ->pluck('count'); }); $client_consented_uknown_age = Cache::remember('client-consented-uknown-age', 10, function () { - return Client::select('smsenable') - ->where('dob', '=', '') - ->where('status', '=', 'Active') - ->whereNull('hei_no') - ->orWhereNull('dob') - ->where('smsenable', '=', 'Yes') + return Client::join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select('tbl_client.smsenable') + ->where('tbl_client.dob', '=', '') + ->where('tbl_client.status', '=', 'Active') + ->whereNull('tbl_client.hei_no') + ->orWhereNull('tbl_client.dob') + ->where('tbl_client.smsenable', '=', 'Yes') + ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) ->count(); }); // non consented clients by age distribution $client_nonconsented_to_nine = Cache::remember('client-nonconsented-to-nine', 10, function () { - return Client::select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) > 0) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 9)) then `tbl_client`.`id` end)) AS count")) - ->where('smsenable', '!=', 'Yes') - ->where('status', '=', 'Active') - ->whereNull('hei_no') + return Client::join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) > 0) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 9)) then `tbl_client`.`id` end)) AS count")) + ->where('tbl_client.smsenable', '!=', 'Yes') + ->where('tbl_client.status', '=', 'Active') + ->whereNull('tbl_client.hei_no') + ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) ->pluck('count'); }); $client_nonconsented_to_fourteen = Cache::remember('client-nonconsented-to-fourteen', 10, function () { - return Client::select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 10) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 14)) then `tbl_client`.`id` end)) AS count")) - ->where('smsenable', '!=', 'Yes') - ->where('status', '=', 'Active') - ->whereNull('hei_no') + return Client::join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 10) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 14)) then `tbl_client`.`id` end)) AS count")) + ->where('tbl_client.smsenable', '!=', 'Yes') + ->where('tbl_client.status', '=', 'Active') + ->whereNull('tbl_client.hei_no') + ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) ->pluck('count'); }); $client_nonconsented_to_nineteen = Cache::remember('client-nonconsented-to-nineteen', 10, function () { - return Client::select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 15) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 19)) then `tbl_client`.`id` end)) AS count")) - ->where('smsenable', '!=', 'Yes') - ->where('status', '=', 'Active') - ->whereNull('hei_no') + return Client::join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 15) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 19)) then `tbl_client`.`id` end)) AS count")) + ->where('tbl_client.smsenable', '!=', 'Yes') + ->where('tbl_client.status', '=', 'Active') + ->whereNull('tbl_client.hei_no') + ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) ->pluck('count'); }); $client_nonconsented_to_twentyfour = Cache::remember('client-nonconsented-to-twentyfour', 10, function () { - return Client::select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 20) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 24)) then `tbl_client`.`id` end)) AS count")) - ->where('smsenable', '!=', 'Yes') - ->where('status', '=', 'Active') - ->whereNull('hei_no') + return Client::join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 20) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 24)) then `tbl_client`.`id` end)) AS count")) + ->where('tbl_client.smsenable', '!=', 'Yes') + ->where('tbl_client.status', '=', 'Active') + ->whereNull('tbl_client.hei_no') + ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) ->pluck('count'); }); $client_nonconsented_to_twentyfive_above = Cache::remember('client-nonconsented-to-twentyfive-above', 10, function () { - return Client::select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 25)) then `tbl_client`.`id` end)) AS count")) - ->where('smsenable', '!=', 'Yes') - ->where('status', '=', 'Active') - ->whereNull('hei_no') + return Client::join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 25)) then `tbl_client`.`id` end)) AS count")) + ->where('tbl_client.smsenable', '!=', 'Yes') + ->where('tbl_client.status', '=', 'Active') + ->whereNull('tbl_client.hei_no') + ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) ->pluck('count'); }); $client_nonconsented_uknown_age = Cache::remember('client-nonconsented-uknown-age', 10, function () { - return Client::select('smsenable') - ->where('status', '=', 'Active') - ->whereNull('hei_no') - ->where('dob', '=', '') - ->orWhereNull('dob') - ->where('smsenable', '!=', 'Yes') + return Client::join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select('tbl_client.smsenable') + ->where('tbl_client.status', '=', 'Active') + ->whereNull('tbl_client.hei_no') + ->where('tbl_client.dob', '=', '') + ->orWhereNull('tbl_client.dob') + ->where('tbl_client.smsenable', '!=', 'Yes') + ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) ->count(); }); - } + if (Auth::user()->access_level == 'Admin' || Auth::user()->access_level == 'Donor') { + $all_partners = Partner::where('status', '=', 'Active')->pluck('name', 'id'); + $client = Client::where('status', '=', 'Active')->whereNull('hei_no')->count('clinic_number'); - // dd($active_facilities); - return view('new_dashboard.main_dashbaord', compact( - 'all_partners', - 'active_facilities', - 'indicator', - 'client', - 'appointment', - 'missed_appointment', - 'clients_male', - 'clients_female', - 'unknown_gender', - 'client_to_nine', - 'client_to_fourteen', - 'client_to_nineteen', - 'client_to_twentyfour', - 'client_to_twentyfive_above', - 'client_unknown_age', - 'appointment_male', - 'appointment_female', - 'appointment_uknown_gender', - 'appointment_to_nine', - 'appointment_to_fourteen', - 'appointment_to_nineteen', - 'appointment_to_twentyfour', - 'appointment_to_twentyfive_above', - 'appointment_uknown_age', - 'appointment_total_missed_female', - 'appointment_total_missed_male', - 'appointment_total_missed_uknown_gender', - 'appointment_total_missed_to_nine', - 'appointment_total_missed_to_fourteen', - 'appointment_total_missed_to_nineteen', - 'appointment_total_missed_to_twentyfour', - 'appointment_total_missed_to_twentyfive_above', - 'appointment_total_missed_uknown_age', - 'client_consented', - 'client_nonconsented', - 'client_consented_male', - 'client_consented_female', - 'client_consented_uknown_gender', - 'client_nonconsented_male', - 'client_nonconsented_female', - 'client_nonconsented_uknown_gender', - 'client_consented_to_nine', - 'client_consented_to_fourteen', - 'client_consented_to_nineteen', - 'client_consented_to_twentyfour', - 'client_consented_to_twentyfive_above', - 'client_consented_uknown_age', - 'client_nonconsented_to_nine', - 'client_nonconsented_to_fourteen', - 'client_nonconsented_to_nineteen', - 'client_nonconsented_to_twentyfour', - 'client_nonconsented_to_twentyfive_above', - 'client_nonconsented_uknown_age' + $indicator = Indicator::select(['name', 'description'])->get(); + $appointment = Appointments::select('id') + ->count(); + $missed_appointment = Appointments::select('id') + ->whereIn('app_status', ['Defaulted', 'LTFU', 'Missed']) + ->count(); + // dd($missed_appointment); + $active_facilities = PartnerFacility::join('tbl_client', 'tbl_partner_facility.mfl_code', '=', 'tbl_client.mfl_code') + ->join('tbl_appointment', 'tbl_client.id', '=', 'tbl_appointment.client_id') + ->select('tbl_partner_facility.mfl_code') + ->where('tbl_appointment.created_at', '>=', Carbon::now()->subMonths(6)) + ->orderBy('tbl_appointment.created_at', 'DESC') + ->groupBy('tbl_partner_facility.mfl_code') + ->get(); - )); - } - public function appointment_charts() - { - if (Auth::user()->access_level == 'Admin' || Auth::user()->access_level == 'Donor') { - $all_partners = Partner::where('status', '=', 'Active')->pluck('name', 'id'); - // main appointments - $appointment = Appointments::select('id') + // dd($active_facilities); + // active clients by gender + $clients_male = Client::select('id')->where([['gender', '=', '2'], ['status', '=', 'Active'],]) + ->whereNull('hei_no') ->count(); - $appointment_honoured = Cache::remember('appointment-honoured', 10, function () { - return Appointments::select(\DB::raw("COUNT(id) as count")) - ->where('date_attended', '=', DB::raw('appntmnt_date')) + + $clients_female = Client::where('gender', '=', '1') + ->where('status', '=', 'Active') + ->whereNull('hei_no') + ->count(); + $unknown_gender = Client::where('gender', '!=', '1') + ->where('gender', '!=', '2') + ->where('status', '=', 'Active') + ->whereNull('hei_no') + ->count(); + + $client_to_nine = Cache::remember('client_to_nine', 10, function () { + return Client::select(\DB::raw("count((case when (((year(curdate()) - year(`dob`)) > 0) and ((year(curdate()) - year(`dob`)) <= 9)) then `dob` end)) AS count")) + ->where('status', '=', 'Active') + ->whereNull('hei_no') ->pluck('count'); - }); - // dd($appointment_honoured); - $appointment_not_honoured = Cache::remember('appointment-not-honoured', 10, function () { - return Appointments::select(\DB::raw("COUNT(id) as count")) - ->whereIn('app_status', ['Defaulted', 'LTFU', 'Missed']) - ->pluck('count'); - }); + }); - // appointment honored by gender - $appointment_honoured_male = Cache::remember('appointment-honoured-male', 10, function () { - return Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') - ->select(\DB::raw("COUNT(tbl_appointment.id) as count")) - ->where('tbl_appointment.date_attended', '=', DB::raw('tbl_appointment.appntmnt_date')) - ->where('tbl_client.gender', '=', '2') - ->pluck('count'); - }); - $appointment_honoured_female = Cache::remember('appointment-honoured-female', 10, function () { - return Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') - ->where('tbl_appointment.date_attended', '=', DB::raw('tbl_appointment.appntmnt_date')) - ->where('tbl_client.gender', '=', '1') - ->count(); - }); - $appointment_honoured_uknown_gender = Cache::remember('appointment-honoured-uknown-gender', 10, function () { - return Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') - ->where('tbl_appointment.date_attended', '=', DB::raw('tbl_appointment.appntmnt_date')) - ->where('tbl_client.gender', '!=', '1') - ->where('tbl_client.gender', '!=', '2') - ->count(); - }); - // appointment honored by age - $appointment_honored_to_nine = Cache::remember('appointment-honored-to-nine', 10, function () { - return Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') - ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') - ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) > 0) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 9)) then `tbl_client`.`id` end)) AS count")) - ->where('tbl_appointment.date_attended', '=', DB::raw('tbl_appointment.appntmnt_date')) - ->pluck('count'); - }); - $appointment_honored_to_fourteen = Cache::remember('appointment-honored-to-fourteen', 10, function () { - return Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + $client_to_fourteen = Cache::remember('client-fourteen', 10, function () { + return Client::select(\DB::raw("count((case when (((year(curdate()) - year(`dob`)) >= 10) and ((year(curdate()) - year(`dob`)) <= 14)) then `dob` end)) AS count")) + ->where('status', '=', 'Active') + ->whereNull('hei_no') + ->pluck('count'); + }); + + $client_to_nineteen = Cache::remember('client-nineteen', 10, function () { + return Client::select(\DB::raw("count((case when (((year(curdate()) - year(`dob`)) >= 15) and ((year(curdate()) - year(`dob`)) <= 19)) then `dob` end)) AS count")) + ->where('status', '=', 'Active') + ->whereNull('hei_no') + ->pluck('count'); + }); + + $client_to_twentyfour = Cache::remember('client-twentyfour', 10, function () { + return Client::select(\DB::raw("count((case when (((year(curdate()) - year(`dob`)) >= 20) and ((year(curdate()) - year(`dob`)) <= 24)) then `id` end)) AS count")) + ->where('status', '=', 'Active') + ->whereNull('hei_no') + ->pluck('count'); + }); + + $client_to_twentyfive_above = Cache::remember('client-twentyfive-above', 10, function () { + return Client::select(\DB::raw("count((case when (((year(curdate()) - year(`dob`)) >= 25)) then `id` end)) AS count")) + ->where('status', '=', 'Active') + ->whereNull('hei_no') + ->pluck('count'); + }); + + $client_unknown_age = Cache::remember('client-unknown-age', 10, function () { + return Client::where('dob', '=', '') + ->orWhereNull('dob') + ->where('status', '=', 'Active') + ->whereNull('hei_no') + ->count(); + }); + + // appointment by gender + $appointment_male = Cache::remember('appointment-male', 10, function () { + return Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->select('tbl_appointment.id') + ->where('tbl_client.gender', '=', '2') + ->count(); + }); + $appointment_female = Cache::remember('appointment-female', 10, function () { + return Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->select('tbl_appointment.id') + ->where('tbl_client.gender', '=', '1') + ->count(); + }); + $appointment_uknown_gender = Cache::remember('appointment-uknown-gender', 10, function () { + return Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->select('tbl_appointment.id') + ->where('tbl_client.gender', '!=', '1') + ->where('tbl_client.gender', '!=', '2') + ->count(); + }); + // appointment by age + $appointment_to_nine = Cache::remember('appointment-to-nine', 10, function () { + return Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) > 0) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 9)) then `tbl_client`.`id` end)) AS count")) + ->pluck('count'); + }); + $appointment_to_fourteen = Cache::remember('appointment-to-fourteen', 10, function () { + return Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 10) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 14)) then `tbl_client`.`id` end)) AS count")) + ->pluck('count'); + }); + $appointment_to_nineteen = Cache::remember('appointment-to-nineteen', 10, function () { + return Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 15) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 19)) then `tbl_client`.`id` end)) AS count")) + ->pluck('count'); + }); + $appointment_to_twentyfour = Cache::remember('appointment-to-twentyfour', 10, function () { + return Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 20) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 24)) then `tbl_client`.`id` end)) AS count")) + ->pluck('count'); + }); + $appointment_to_twentyfive_above = Cache::remember('appointment-to-twentyfive-above', 10, function () { + return Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 25)) then `tbl_client`.`id` end)) AS count")) + ->pluck('count'); + }); + $appointment_uknown_age = Cache::remember('appointment-uknown-age', 10, function () { + return Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->where('tbl_client.dob', '=', '') + ->orWhereNull('tbl_client.dob') + ->count(); + }); + + // Total missed appointment by gender + $appointment_total_missed_female = Cache::remember('appointment-total-missed-female', 10, function () { + return Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->whereIn('tbl_appointment.app_status', ['Defaulted', 'LTFU', 'Missed']) + ->where('tbl_client.gender', '=', '1') + ->count(); + }); + $appointment_total_missed_male = Cache::remember('appointment-total-missed-male', 10, function () { + return Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->where('tbl_client.gender', '=', '2') + ->whereIn('tbl_appointment.app_status', ['Defaulted', 'LTFU', 'Missed']) + ->count(); + }); + $appointment_total_missed_uknown_gender = Cache::remember('appointment-total-missed-uknown-gender', 10, function () { + return Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->whereIn('tbl_appointment.app_status', ['Defaulted', 'LTFU', 'Missed']) + ->where('tbl_client.gender', '!=', '1') + ->where('tbl_client.gender', '!=', '2') + ->count(); + }); + + // Total missed appointment by age + $appointment_total_missed_to_nine = Cache::remember('appointment-total-missed-to-nine', 10, function () { + return Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) > 0) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 9)) then `tbl_client`.`id` end)) AS count")) + ->whereIn('tbl_appointment.app_status', ['Defaulted', 'LTFU', 'Missed']) + ->pluck('count'); + }); + $appointment_total_missed_to_fourteen = Cache::remember('appointment-total-missed-to-fourteen', 10, function () { + return Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 10) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 14)) then `tbl_client`.`id` end)) AS count")) + ->whereIn('tbl_appointment.app_status', ['Defaulted', 'LTFU', 'Missed']) + ->pluck('count'); + }); + $appointment_total_missed_to_nineteen = Cache::remember('appointment-total-missed-to-nineteen', 10, function () { + return Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 15) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 19)) then `tbl_client`.`id` end)) AS count")) + ->whereIn('tbl_appointment.app_status', ['Defaulted', 'LTFU', 'Missed']) + ->pluck('count'); + }); + $appointment_total_missed_to_twentyfour = Cache::remember('appointment-total-missed-to-twentyfour', 10, function () { + return Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 20) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 24)) then `tbl_client`.`id` end)) AS count")) + ->whereIn('tbl_appointment.app_status', ['Defaulted', 'LTFU', 'Missed']) + ->pluck('count'); + }); + $appointment_total_missed_to_twentyfive_above = Cache::remember('appointment-total-missed-to-twentyfive_above', 10, function () { + return Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 25)) then `tbl_client`.`id` end)) AS count")) + ->whereIn('tbl_appointment.app_status', ['Defaulted', 'LTFU', 'Missed']) + ->pluck('count'); + }); + $appointment_total_missed_uknown_age = Cache::remember('appointment-total-missed-uknown-age', 10, function () { + return Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->where('tbl_client.dob', '=', '') + ->orWhereNull('tbl_client.dob') + ->whereIn('tbl_appointment.app_status', ['Defaulted', 'LTFU', 'Missed']) + ->count(); + }); + // client charts + $client_consented = Cache::remember('client-consented', 10, function () { + return Client::select('smsenable') + ->where('status', '=', 'Active') + ->whereNull('hei_no') + ->where('smsenable', '=', 'Yes') + ->count(); + }); + $client_nonconsented = Cache::remember('client-nonconsented', 10, function () { + return Client::select('smsenable') + ->where('status', '=', 'Active') + ->whereNull('hei_no') + ->where('smsenable', '!=', 'Yes') + ->count(); + }); + // consented clients by gender + + $client_consented_male = Cache::remember('client-consented-male', 10, function () { + return Client::where('smsenable', '=', 'Yes') + ->where('status', '=', 'Active') + ->whereNull('hei_no') + ->where('gender', '=', '2') + ->count(); + }); + $client_consented_female = Cache::remember('client-consented-female', 10, function () { + return Client::where('smsenable', '=', 'Yes') + ->where('status', '=', 'Active') + ->whereNull('hei_no') + ->where('gender', '=', '1') + ->count(); + }); + $client_consented_uknown_gender = Cache::remember('client-consented-uknown-gender', 10, function () { + return Client::where('smsenable', '=', 'Yes') + ->where('status', '=', 'Active') + ->whereNull('hei_no') + ->where('gender', '!=', '1') + ->where('gender', '!=', '2') + ->count(); + }); + // non consented clients by gender + $client_nonconsented_male = Cache::remember('client-nonconsented-male', 10, function () { + return Client::where('smsenable', '!=', 'Yes') + ->where('status', '=', 'Active') + ->whereNull('hei_no') + ->where('gender', '=', '2') + ->count(); + }); + $client_nonconsented_female = Cache::remember('client-nonconsented-female', 10, function () { + return Client::where('smsenable', '!=', 'Yes') + ->where('status', '=', 'Active') + ->whereNull('hei_no') + ->where('gender', '=', '1') + ->count(); + }); + $client_nonconsented_uknown_gender = Cache::remember('client-nonconsented-uknown-gender', 10, function () { + return Client::where('smsenable', '!=', 'Yes') + ->where('gender', '!=', '1') + ->where('gender', '!=', '2') + ->count(); + }); + // consented clients by age distribution + $client_consented_to_nine = Cache::remember('client-consented-to-nine', 10, function () { + return Client::select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) > 0) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 9)) then `tbl_client`.`id` end)) AS count")) + ->where('smsenable', '=', 'Yes') + ->where('status', '=', 'Active') + ->whereNull('hei_no') + ->pluck('count'); + }); + $client_consented_to_fourteen = Cache::remember('tbl-client', 10, function () { + return Client::select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 10) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 14)) then `tbl_client`.`id` end)) AS count")) + ->where('smsenable', '=', 'Yes') + ->where('status', '=', 'Active') + ->whereNull('hei_no') + ->pluck('count'); + }); + $client_consented_to_nineteen = Cache::remember('client-consented-to-nineteen', 10, function () { + return Client::select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 15) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 19)) then `tbl_client`.`id` end)) AS count")) + ->where('smsenable', '=', 'Yes') + ->where('status', '=', 'Active') + ->whereNull('hei_no') + ->pluck('count'); + }); + $client_consented_to_twentyfour = Cache::remember('client-consented-to-twentyfour', 10, function () { + return Client::select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 20) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 24)) then `tbl_client`.`id` end)) AS count")) + ->where('smsenable', '=', 'Yes') + ->where('status', '=', 'Active') + ->whereNull('hei_no') + ->pluck('count'); + }); + $client_consented_to_twentyfive_above = Cache::remember('client-consented-to-twentyfive-above', 10, function () { + return Client::select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 25)) then `tbl_client`.`id` end)) AS count")) + ->where('smsenable', '=', 'Yes') + ->where('status', '=', 'Active') + ->whereNull('hei_no') + ->pluck('count'); + }); + $client_consented_uknown_age = Cache::remember('client-consented-uknown-age', 10, function () { + return Client::select('smsenable') + ->where('dob', '=', '') + ->where('status', '=', 'Active') + ->whereNull('hei_no') + ->orWhereNull('dob') + ->where('smsenable', '=', 'Yes') + ->count(); + }); + // non consented clients by age distribution + $client_nonconsented_to_nine = Cache::remember('client-nonconsented-to-nine', 10, function () { + return Client::select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) > 0) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 9)) then `tbl_client`.`id` end)) AS count")) + ->where('smsenable', '!=', 'Yes') + ->where('status', '=', 'Active') + ->whereNull('hei_no') + ->pluck('count'); + }); + $client_nonconsented_to_fourteen = Cache::remember('client-nonconsented-to-fourteen', 10, function () { + return Client::select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 10) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 14)) then `tbl_client`.`id` end)) AS count")) + ->where('smsenable', '!=', 'Yes') + ->where('status', '=', 'Active') + ->whereNull('hei_no') + ->pluck('count'); + }); + $client_nonconsented_to_nineteen = Cache::remember('client-nonconsented-to-nineteen', 10, function () { + return Client::select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 15) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 19)) then `tbl_client`.`id` end)) AS count")) + ->where('smsenable', '!=', 'Yes') + ->where('status', '=', 'Active') + ->whereNull('hei_no') + ->pluck('count'); + }); + $client_nonconsented_to_twentyfour = Cache::remember('client-nonconsented-to-twentyfour', 10, function () { + return Client::select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 20) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 24)) then `tbl_client`.`id` end)) AS count")) + ->where('smsenable', '!=', 'Yes') + ->where('status', '=', 'Active') + ->whereNull('hei_no') + ->pluck('count'); + }); + $client_nonconsented_to_twentyfive_above = Cache::remember('client-nonconsented-to-twentyfive-above', 10, function () { + return Client::select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 25)) then `tbl_client`.`id` end)) AS count")) + ->where('smsenable', '!=', 'Yes') + ->where('status', '=', 'Active') + ->whereNull('hei_no') + ->pluck('count'); + }); + $client_nonconsented_uknown_age = Cache::remember('client-nonconsented-uknown-age', 10, function () { + return Client::select('smsenable') + ->where('status', '=', 'Active') + ->whereNull('hei_no') + ->where('dob', '=', '') + ->orWhereNull('dob') + ->where('smsenable', '!=', 'Yes') + ->count(); + }); + + + } + + + // dd($active_facilities); + + return view('new_dashboard.main_dashbaord', compact( + 'all_partners', + 'active_facilities', + 'indicator', + 'client', + 'appointment', + 'missed_appointment', + 'clients_male', + 'clients_female', + 'unknown_gender', + 'client_to_nine', + 'client_to_fourteen', + 'client_to_nineteen', + 'client_to_twentyfour', + 'client_to_twentyfive_above', + 'client_unknown_age', + 'appointment_male', + 'appointment_female', + 'appointment_uknown_gender', + 'appointment_to_nine', + 'appointment_to_fourteen', + 'appointment_to_nineteen', + 'appointment_to_twentyfour', + 'appointment_to_twentyfive_above', + 'appointment_uknown_age', + 'appointment_total_missed_female', + 'appointment_total_missed_male', + 'appointment_total_missed_uknown_gender', + 'appointment_total_missed_to_nine', + 'appointment_total_missed_to_fourteen', + 'appointment_total_missed_to_nineteen', + 'appointment_total_missed_to_twentyfour', + 'appointment_total_missed_to_twentyfive_above', + 'appointment_total_missed_uknown_age', + 'client_consented', + 'client_nonconsented', + 'client_consented_male', + 'client_consented_female', + 'client_consented_uknown_gender', + 'client_nonconsented_male', + 'client_nonconsented_female', + 'client_nonconsented_uknown_gender', + 'client_consented_to_nine', + 'client_consented_to_fourteen', + 'client_consented_to_nineteen', + 'client_consented_to_twentyfour', + 'client_consented_to_twentyfive_above', + 'client_consented_uknown_age', + 'client_nonconsented_to_nine', + 'client_nonconsented_to_fourteen', + 'client_nonconsented_to_nineteen', + 'client_nonconsented_to_twentyfour', + 'client_nonconsented_to_twentyfive_above', + 'client_nonconsented_uknown_age' + + )); + } + + public function appointment_charts() + { + if (Auth::user()->access_level == 'Facility') { + $all_partners = Partner::where('status', '=', 'Active')->pluck('name', 'id'); + // main appointments + $appointment = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->select('tbl_appointment.id') + ->where('tbl_client.mfl_code', Auth::user()->facility_id) + ->count(); + $appointment_honoured = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->select('tbl_appointment.id') + ->where('tbl_appointment.date_attended', '=', DB::raw('tbl_appointment.appntmnt_date')) + ->where('tbl_client.mfl_code', Auth::user()->facility_id) + ->count(); + + // dd($appointment_honoured); + $appointment_not_honoured = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->select('tbl_appointment.id') + ->whereIn('tbl_appointment.app_status', ['Defaulted', 'LTFU', 'Missed']) + ->where('tbl_client.mfl_code', Auth::user()->facility_id) + ->count(); + + // appointment honored by gender + $appointment_honoured_male = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->select(\DB::raw("COUNT(tbl_appointment.id) as count")) + ->where('tbl_appointment.date_attended', '=', DB::raw('tbl_appointment.appntmnt_date')) + ->where('tbl_client.gender', '=', '2') + ->where('tbl_client.mfl_code', Auth::user()->facility_id) + ->pluck('count'); + $appointment_honoured_female = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->where('tbl_appointment.date_attended', '=', DB::raw('tbl_appointment.appntmnt_date')) + ->where('tbl_client.gender', '=', '1') + ->where('tbl_client.mfl_code', Auth::user()->facility_id) + ->count(); + $appointment_honoured_uknown_gender = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->where('tbl_appointment.date_attended', '=', DB::raw('tbl_appointment.appntmnt_date')) + ->where('tbl_client.gender', '!=', '1') + ->where('tbl_client.gender', '!=', '2') + ->where('tbl_client.mfl_code', Auth::user()->facility_id) + ->count(); + // appointment honored by age + $appointment_honored_to_nine = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) > 0) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 9)) then `tbl_client`.`id` end)) AS count")) + ->where('tbl_appointment.date_attended', '=', DB::raw('tbl_appointment.appntmnt_date')) + ->where('tbl_client.mfl_code', Auth::user()->facility_id) + ->pluck('count'); + $appointment_honored_to_fourteen = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 10) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 14)) then `tbl_client`.`id` end)) AS count")) + ->where('tbl_appointment.date_attended', '=', DB::raw('tbl_appointment.appntmnt_date')) + ->where('tbl_client.mfl_code', Auth::user()->facility_id) + ->pluck('count'); + $appointment_honored_to_nineteen = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 15) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 19)) then `tbl_client`.`id` end)) AS count")) + ->where('tbl_appointment.date_attended', '=', DB::raw('tbl_appointment.appntmnt_date')) + ->where('tbl_client.mfl_code', Auth::user()->facility_id) + ->pluck('count'); + + $appointment_honored_to_twentyfour = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 20) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 24)) then `tbl_client`.`id` end)) AS count")) + ->where('tbl_appointment.date_attended', '=', DB::raw('tbl_appointment.appntmnt_date')) + ->where('tbl_client.mfl_code', Auth::user()->facility_id) + ->pluck('count'); + + $appointment_honored_to_twentyfive_above = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 25)) then `tbl_client`.`id` end)) AS count")) + ->where('tbl_appointment.date_attended', '=', DB::raw('tbl_appointment.appntmnt_date')) + ->where('tbl_client.mfl_code', Auth::user()->facility_id) + ->pluck('count'); + + $appointment_honored_to_uknown_age = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->select('tbl_client.dob') + ->where('tbl_appointment.date_attended', '=', DB::raw('tbl_appointment.appntmnt_date')) + ->where('tbl_client.dob', '=', '') + ->orWhereNull('tbl_client.dob') + ->where('tbl_client.mfl_code', Auth::user()->facility_id) + ->count(); + // appointment not honored by gender + $appointment_not_honoured_male = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->where('tbl_client.gender', '=', '2') + ->whereIn('tbl_appointment.app_status', ['Defaulted', 'LTFU', 'Missed']) + ->where('tbl_client.mfl_code', Auth::user()->facility_id) + ->count(); + + $appointment_not_honoured_female = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->where('tbl_client.gender', '=', '1') + ->whereIn('tbl_appointment.app_status', ['Defaulted', 'LTFU', 'Missed']) + ->where('tbl_client.mfl_code', Auth::user()->facility_id) + ->count(); + $appointment_not_honoured_uknown_gender = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->where('tbl_client.gender', '!=', '1') + ->where('tbl_client.gender', '!=', '2') + ->whereIn('tbl_appointment.app_status', ['Defaulted', 'LTFU', 'Missed']) + ->where('tbl_client.mfl_code', Auth::user()->facility_id) + ->count(); + // appointment not honored by age + $appointment_not_honored_to_nine = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) > 0) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 9)) then `tbl_client`.`id` end)) AS count")) + ->whereIn('tbl_appointment.app_status', ['Defaulted', 'LTFU', 'Missed']) + ->where('tbl_client.mfl_code', Auth::user()->facility_id) + ->pluck('count'); + + $appointment_not_honored_to_fourteen = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 10) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 14)) then `tbl_client`.`id` end)) AS count")) + ->whereIn('tbl_appointment.app_status', ['Defaulted', 'LTFU', 'Missed']) + ->where('tbl_client.mfl_code', Auth::user()->facility_id) + ->pluck('count'); + + $appointment_not_honored_to_nineteen = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 15) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 19)) then `tbl_client`.`id` end)) AS count")) + ->whereIn('tbl_appointment.app_status', ['Defaulted', 'LTFU', 'Missed']) + ->where('tbl_client.mfl_code', Auth::user()->facility_id) + ->pluck('count'); + $appointment_not_honored_to_twentyfour = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 20) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 24)) then `tbl_client`.`id` end)) AS count")) + ->whereIn('tbl_appointment.app_status', ['Defaulted', 'LTFU', 'Missed']) + ->where('tbl_client.mfl_code', Auth::user()->facility_id) + ->pluck('count'); + $appointment_not_honored_to_twentyfive_above = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 25)) then `tbl_client`.`id` end)) AS count")) + ->whereIn('tbl_appointment.app_status', ['Defaulted', 'LTFU', 'Missed']) + ->where('tbl_client.mfl_code', Auth::user()->facility_id) + ->pluck('count'); + + $appointment_not_honored_to_uknown_age = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->select('tbl_client.dob') + ->where('tbl_client.dob', '=', '') + ->orWhereNull('tbl_client.dob') + ->whereIn('tbl_appointment.app_status', ['Defaulted', 'LTFU', 'Missed']) + ->where('tbl_client.mfl_code', Auth::user()->facility_id) + ->count(); + + // missed appointments + + $appointment_missed = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->where('tbl_appointment.app_status', '=', 'Missed') + ->where('tbl_client.mfl_code', Auth::user()->facility_id) + ->count(); + $appointment_defaulted = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->where('tbl_appointment.app_status', '=', 'Defaulted') + ->where('tbl_client.mfl_code', Auth::user()->facility_id) + ->count(); + $appointment_lftu = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->where('tbl_appointment.app_status', '=', 'LTFU') + ->where('tbl_client.mfl_code', Auth::user()->facility_id) + ->count(); + + // missed appointment by gender + $appointment_missed_female = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->where('tbl_appointment.app_status', '=', 'Missed') + ->where('tbl_client.gender', '=', '1') + ->where('tbl_client.mfl_code', Auth::user()->facility_id) + ->count(); + $appointment_missed_male = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->where('tbl_appointment.app_status', '=', 'Missed') + ->where('tbl_client.gender', '=', '2') + ->where('tbl_client.mfl_code', Auth::user()->facility_id) + ->count(); + + $appointment_missed_uknown_gender = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->where('tbl_appointment.app_status', '=', 'Missed') + ->where('tbl_client.gender', '!=', '1') + ->where('tbl_client.gender', '!=', '2') + ->where('tbl_client.mfl_code', Auth::user()->facility_id) + ->count(); + + // missed appointment by age + $appointment_missed_to_nine = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) > 0) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 9)) then `tbl_client`.`id` end)) AS count")) + ->where('tbl_appointment.app_status', '=', 'Missed') + ->where('tbl_client.mfl_code', Auth::user()->facility_id) + ->pluck('count'); + $appointment_missed_to_fourteen = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 10) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 14)) then `tbl_client`.`id` end)) AS count")) + ->where('tbl_appointment.app_status', '=', 'Missed') + ->where('tbl_client.mfl_code', Auth::user()->facility_id) + ->pluck('count'); + + $appointment_missed_to_nineteen = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 15) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 19)) then `tbl_client`.`id` end)) AS count")) + ->where('tbl_appointment.app_status', '=', 'Missed') + ->where('tbl_client.mfl_code', Auth::user()->facility_id) + ->pluck('count'); + $appointment_missed_to_twentyfour = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 20) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 24)) then `tbl_client`.`id` end)) AS count")) + ->where('tbl_appointment.app_status', '=', 'Missed') + ->where('tbl_client.mfl_code', Auth::user()->facility_id) + ->pluck('count'); + $appointment_missed_to_twentyfive_above = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 25)) then `tbl_client`.`id` end)) AS count")) + ->where('tbl_appointment.app_status', '=', 'Missed') + ->where('tbl_client.mfl_code', Auth::user()->facility_id) + ->pluck('count'); + $appointment_missed_to_uknown_age = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->select('tbl_client.dob') + ->where('tbl_client.dob', '=', '') + ->orWhereNull('tbl_client.dob') + ->where('tbl_appointment.app_status', '=', 'Missed') + ->where('tbl_client.mfl_code', Auth::user()->facility_id) + ->count(); + + // defaulted appointment by gender + $appointment_defaulted_female = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->where('tbl_appointment.app_status', '=', 'Defaulted') + ->where('tbl_client.gender', '=', '1') + ->where('tbl_client.mfl_code', Auth::user()->facility_id) + ->count(); + $appointment_defaulted_male = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->where('tbl_appointment.app_status', '=', 'Defaulted') + ->where('tbl_client.gender', '=', '2') + ->where('tbl_client.mfl_code', Auth::user()->facility_id) + ->count(); + + $appointment_defaulted_uknown_gender = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->where('tbl_appointment.app_status', '=', 'Defaulted') + ->where('tbl_client.gender', '!=', '1') + ->where('tbl_client.gender', '!=', '2') + ->where('tbl_client.mfl_code', Auth::user()->facility_id) + ->count(); + // defaulted appointment by age + $appointment_defaulted_to_nine = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) > 0) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 9)) then `tbl_client`.`id` end)) AS count")) + ->where('tbl_appointment.app_status', '=', 'Defaulted') + ->where('tbl_client.mfl_code', Auth::user()->facility_id) + ->pluck('count'); + $appointment_defaulted_to_fourteen = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 10) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 14)) then `tbl_client`.`id` end)) AS count")) + ->where('tbl_appointment.app_status', '=', 'Defaulted') + ->where('tbl_client.mfl_code', Auth::user()->facility_id) + ->pluck('count'); + $appointment_defaulted_to_nineteen = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 15) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 19)) then `tbl_client`.`id` end)) AS count")) + ->where('tbl_appointment.app_status', '=', 'Defaulted') + ->where('tbl_client.mfl_code', Auth::user()->facility_id) + ->pluck('count'); + $appointment_defaulted_to_twentyfour = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 20) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 24)) then `tbl_client`.`id` end)) AS count")) + ->where('tbl_appointment.app_status', '=', 'Defaulted') + ->where('tbl_client.mfl_code', Auth::user()->facility_id) + ->pluck('count'); + + $appointment_defaulted_to_twentyfive_above = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 25)) then `tbl_client`.`id` end)) AS count")) + ->where('tbl_appointment.app_status', '=', 'Defaulted') + ->where('tbl_client.mfl_code', Auth::user()->facility_id) + ->pluck('count'); + + $appointment_defaulted_to_uknown_age = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->select('tbl_client.dob') + ->where('tbl_client.dob', '=', '') + ->orWhereNull('tbl_client.dob') + ->where('tbl_appointment.app_status', '=', 'Defaulted') + ->where('tbl_client.mfl_code', Auth::user()->facility_id) + ->count(); + // ltfu appointment by gender + $appointment_ltfu_female = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->where('tbl_appointment.app_status', '=', 'LTFU') + ->where('tbl_client.gender', '=', '1') + ->where('tbl_client.mfl_code', Auth::user()->facility_id) + ->count(); + + $appointment_ltfu_male = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->where('tbl_appointment.app_status', '=', 'LTFU') + ->where('tbl_client.gender', '=', '2') + ->where('tbl_client.mfl_code', Auth::user()->facility_id) + ->count(); + $appointment_ltfu_uknown_gender = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->where('tbl_appointment.app_status', '=', 'LTFU') + ->where('tbl_client.gender', '!=', '1') + ->where('tbl_client.gender', '!=', '2') + ->where('tbl_client.mfl_code', Auth::user()->facility_id) + ->count(); + + // ltfu appointment by age + $appointment_ltfu_to_nine = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) > 0) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 9)) then `tbl_client`.`id` end)) AS count")) + ->where('tbl_appointment.app_status', '=', 'LTFU') + ->where('tbl_client.mfl_code', Auth::user()->facility_id) + ->pluck('count'); + + $appointment_ltfu_to_fourteen = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 10) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 14)) then `tbl_client`.`id` end)) AS count")) + ->where('tbl_appointment.app_status', '=', 'LTFU') + ->where('tbl_client.mfl_code', Auth::user()->facility_id) + ->pluck('count'); + + $appointment_ltfu_to_nineteen = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 15) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 19)) then `tbl_client`.`id` end)) AS count")) + ->where('tbl_appointment.app_status', '=', 'LTFU') + ->where('tbl_client.mfl_code', Auth::user()->facility_id) + ->pluck('count'); + + $appointment_ltfu_to_twentyfour = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 20) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 24)) then `tbl_client`.`id` end)) AS count")) + ->where('tbl_appointment.app_status', '=', 'LTFU') + ->where('tbl_client.mfl_code', Auth::user()->facility_id) + ->pluck('count'); + $appointment_ltfu_to_twentyfive_above = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 25)) then `tbl_client`.`id` end)) AS count")) + ->where('tbl_appointment.app_status', '=', 'LTFU') + ->where('tbl_client.mfl_code', Auth::user()->facility_id) + ->pluck('count'); + + $appointment_ltfu_to_uknown_age = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->select('tbl_client.dob') + ->where('tbl_client.dob', '=', '') + ->orWhereNull('tbl_client.dob') + ->where('tbl_appointment.app_status', '=', 'LTFU') + ->where('tbl_client.mfl_code', Auth::user()->facility_id) + ->count(); + } + if (Auth::user()->access_level == 'Partner') { + $all_partners = Partner::where('status', '=', 'Active')->pluck('name', 'id'); + // main appointments + $appointment = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select('tbl_appointment.id') + ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) + ->count(); + $appointment_honoured = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select('tbl_appointment.id') + ->where('tbl_appointment.date_attended', '=', DB::raw('tbl_appointment.appntmnt_date')) + ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) + ->count(); + + // dd($appointment_honoured); + $appointment_not_honoured = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select('tbl_appointment.id') + ->whereIn('tbl_appointment.app_status', ['Defaulted', 'LTFU', 'Missed']) + ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) + ->count(); + + // appointment honored by gender + $appointment_honoured_male = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select(\DB::raw("COUNT(tbl_appointment.id) as count")) + ->where('tbl_appointment.date_attended', '=', DB::raw('tbl_appointment.appntmnt_date')) + ->where('tbl_client.gender', '=', '2') + ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) + ->pluck('count'); + $appointment_honoured_female = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->where('tbl_appointment.date_attended', '=', DB::raw('tbl_appointment.appntmnt_date')) + ->where('tbl_client.gender', '=', '1') + ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) + ->count(); + $appointment_honoured_uknown_gender = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->where('tbl_appointment.date_attended', '=', DB::raw('tbl_appointment.appntmnt_date')) + ->where('tbl_client.gender', '!=', '1') + ->where('tbl_client.gender', '!=', '2') + ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) + ->count(); + // appointment honored by age + $appointment_honored_to_nine = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) > 0) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 9)) then `tbl_client`.`id` end)) AS count")) + ->where('tbl_appointment.date_attended', '=', DB::raw('tbl_appointment.appntmnt_date')) + ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) + ->pluck('count'); + $appointment_honored_to_fourteen = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 10) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 14)) then `tbl_client`.`id` end)) AS count")) + ->where('tbl_appointment.date_attended', '=', DB::raw('tbl_appointment.appntmnt_date')) + ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) + ->pluck('count'); + $appointment_honored_to_nineteen = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 15) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 19)) then `tbl_client`.`id` end)) AS count")) + ->where('tbl_appointment.date_attended', '=', DB::raw('tbl_appointment.appntmnt_date')) + ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) + ->pluck('count'); + + $appointment_honored_to_twentyfour = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 20) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 24)) then `tbl_client`.`id` end)) AS count")) + ->where('tbl_appointment.date_attended', '=', DB::raw('tbl_appointment.appntmnt_date')) + ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) + ->pluck('count'); + + $appointment_honored_to_twentyfive_above = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 25)) then `tbl_client`.`id` end)) AS count")) + ->where('tbl_appointment.date_attended', '=', DB::raw('tbl_appointment.appntmnt_date')) + ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) + ->pluck('count'); + + $appointment_honored_to_uknown_age = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select('tbl_client.dob') + ->where('tbl_appointment.date_attended', '=', DB::raw('tbl_appointment.appntmnt_date')) + ->where('tbl_client.dob', '=', '') + ->orWhereNull('tbl_client.dob') + ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) + ->count(); + // appointment not honored by gender + $appointment_not_honoured_male = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->where('tbl_client.gender', '=', '2') + ->whereIn('tbl_appointment.app_status', ['Defaulted', 'LTFU', 'Missed']) + ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) + ->count(); + + $appointment_not_honoured_female = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->where('tbl_client.gender', '=', '1') + ->whereIn('tbl_appointment.app_status', ['Defaulted', 'LTFU', 'Missed']) + ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) + ->count(); + $appointment_not_honoured_uknown_gender = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->where('tbl_client.gender', '!=', '1') + ->where('tbl_client.gender', '!=', '2') + ->whereIn('tbl_appointment.app_status', ['Defaulted', 'LTFU', 'Missed']) + ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) + ->count(); + // appointment not honored by age + $appointment_not_honored_to_nine = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) > 0) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 9)) then `tbl_client`.`id` end)) AS count")) + ->whereIn('tbl_appointment.app_status', ['Defaulted', 'LTFU', 'Missed']) + ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) + ->pluck('count'); + + $appointment_not_honored_to_fourteen = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 10) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 14)) then `tbl_client`.`id` end)) AS count")) + ->whereIn('tbl_appointment.app_status', ['Defaulted', 'LTFU', 'Missed']) + ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) + ->pluck('count'); + + $appointment_not_honored_to_nineteen = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 15) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 19)) then `tbl_client`.`id` end)) AS count")) + ->whereIn('tbl_appointment.app_status', ['Defaulted', 'LTFU', 'Missed']) + ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) + ->pluck('count'); + $appointment_not_honored_to_twentyfour = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 20) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 24)) then `tbl_client`.`id` end)) AS count")) + ->whereIn('tbl_appointment.app_status', ['Defaulted', 'LTFU', 'Missed']) + ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) + ->pluck('count'); + $appointment_not_honored_to_twentyfive_above = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 25)) then `tbl_client`.`id` end)) AS count")) + ->whereIn('tbl_appointment.app_status', ['Defaulted', 'LTFU', 'Missed']) + ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) + ->pluck('count'); + + $appointment_not_honored_to_uknown_age = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select('tbl_client.dob') + ->where('tbl_client.dob', '=', '') + ->orWhereNull('tbl_client.dob') + ->whereIn('tbl_appointment.app_status', ['Defaulted', 'LTFU', 'Missed']) + ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) + ->count(); + + // missed appointments + + $appointment_missed = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->where('tbl_appointment.app_status', '=', 'Missed') + ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) + ->count(); + $appointment_defaulted = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->where('tbl_appointment.app_status', '=', 'Defaulted') + ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) + ->count(); + $appointment_lftu = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->where('tbl_appointment.app_status', '=', 'LTFU') + ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) + ->count(); + + // missed appointment by gender + $appointment_missed_female = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->where('tbl_appointment.app_status', '=', 'Missed') + ->where('tbl_client.gender', '=', '1') + ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) + ->count(); + $appointment_missed_male = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->where('tbl_appointment.app_status', '=', 'Missed') + ->where('tbl_client.gender', '=', '2') + ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) + ->count(); + + $appointment_missed_uknown_gender = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->where('tbl_appointment.app_status', '=', 'Missed') + ->where('tbl_client.gender', '!=', '1') + ->where('tbl_client.gender', '!=', '2') + ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) + ->count(); + + // missed appointment by age + $appointment_missed_to_nine = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) > 0) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 9)) then `tbl_client`.`id` end)) AS count")) + ->where('tbl_appointment.app_status', '=', 'Missed') + ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) + ->pluck('count'); + $appointment_missed_to_fourteen = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 10) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 14)) then `tbl_client`.`id` end)) AS count")) + ->where('tbl_appointment.app_status', '=', 'Missed') + ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) + ->pluck('count'); + + $appointment_missed_to_nineteen = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 15) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 19)) then `tbl_client`.`id` end)) AS count")) + ->where('tbl_appointment.app_status', '=', 'Missed') + ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) + ->pluck('count'); + $appointment_missed_to_twentyfour = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 20) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 24)) then `tbl_client`.`id` end)) AS count")) + ->where('tbl_appointment.app_status', '=', 'Missed') + ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) + ->pluck('count'); + $appointment_missed_to_twentyfive_above = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 25)) then `tbl_client`.`id` end)) AS count")) + ->where('tbl_appointment.app_status', '=', 'Missed') + ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) + ->pluck('count'); + $appointment_missed_to_uknown_age = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select('tbl_client.dob') + ->where('tbl_client.dob', '=', '') + ->orWhereNull('tbl_client.dob') + ->where('tbl_appointment.app_status', '=', 'Missed') + ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) + ->count(); + + // defaulted appointment by gender + $appointment_defaulted_female = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->where('tbl_appointment.app_status', '=', 'Defaulted') + ->where('tbl_client.gender', '=', '1') + ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) + ->count(); + $appointment_defaulted_male = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->where('tbl_appointment.app_status', '=', 'Defaulted') + ->where('tbl_client.gender', '=', '2') + ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) + ->count(); + + $appointment_defaulted_uknown_gender = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->where('tbl_appointment.app_status', '=', 'Defaulted') + ->where('tbl_client.gender', '!=', '1') + ->where('tbl_client.gender', '!=', '2') + ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) + ->count(); + // defaulted appointment by age + $appointment_defaulted_to_nine = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) > 0) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 9)) then `tbl_client`.`id` end)) AS count")) + ->where('tbl_appointment.app_status', '=', 'Defaulted') + ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) + ->pluck('count'); + $appointment_defaulted_to_fourteen = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 10) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 14)) then `tbl_client`.`id` end)) AS count")) + ->where('tbl_appointment.app_status', '=', 'Defaulted') + ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) + ->pluck('count'); + $appointment_defaulted_to_nineteen = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 15) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 19)) then `tbl_client`.`id` end)) AS count")) + ->where('tbl_appointment.app_status', '=', 'Defaulted') + ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) + ->pluck('count'); + $appointment_defaulted_to_twentyfour = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 20) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 24)) then `tbl_client`.`id` end)) AS count")) + ->where('tbl_appointment.app_status', '=', 'Defaulted') + ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) + ->pluck('count'); + + $appointment_defaulted_to_twentyfive_above = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 25)) then `tbl_client`.`id` end)) AS count")) + ->where('tbl_appointment.app_status', '=', 'Defaulted') + ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) + ->pluck('count'); + + $appointment_defaulted_to_uknown_age = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select('tbl_client.dob') + ->where('tbl_client.dob', '=', '') + ->orWhereNull('tbl_client.dob') + ->where('tbl_appointment.app_status', '=', 'Defaulted') + ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) + ->count(); + // ltfu appointment by gender + $appointment_ltfu_female = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->where('tbl_appointment.app_status', '=', 'LTFU') + ->where('tbl_client.gender', '=', '1') + ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) + ->count(); + + $appointment_ltfu_male = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->where('tbl_appointment.app_status', '=', 'LTFU') + ->where('tbl_client.gender', '=', '2') + ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) + ->count(); + $appointment_ltfu_uknown_gender = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->where('tbl_appointment.app_status', '=', 'LTFU') + ->where('tbl_client.gender', '!=', '1') + ->where('tbl_client.gender', '!=', '2') + ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) + ->count(); + + // ltfu appointment by age + $appointment_ltfu_to_nine = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) > 0) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 9)) then `tbl_client`.`id` end)) AS count")) + ->where('tbl_appointment.app_status', '=', 'LTFU') + ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) + ->pluck('count'); + + $appointment_ltfu_to_fourteen = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 10) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 14)) then `tbl_client`.`id` end)) AS count")) + ->where('tbl_appointment.app_status', '=', 'LTFU') + ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) + ->pluck('count'); + + $appointment_ltfu_to_nineteen = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 15) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 19)) then `tbl_client`.`id` end)) AS count")) + ->where('tbl_appointment.app_status', '=', 'LTFU') + ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) + ->pluck('count'); + + $appointment_ltfu_to_twentyfour = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 20) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 24)) then `tbl_client`.`id` end)) AS count")) + ->where('tbl_appointment.app_status', '=', 'LTFU') + ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) + ->pluck('count'); + $appointment_ltfu_to_twentyfive_above = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 25)) then `tbl_client`.`id` end)) AS count")) + ->where('tbl_appointment.app_status', '=', 'LTFU') + ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) + ->pluck('count'); + + $appointment_ltfu_to_uknown_age = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select('tbl_client.dob') + ->where('tbl_client.dob', '=', '') + ->orWhereNull('tbl_client.dob') + ->where('tbl_appointment.app_status', '=', 'LTFU') + ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) + ->count(); + } + + if (Auth::user()->access_level == 'Admin' || Auth::user()->access_level == 'Donor') { + $all_partners = Partner::where('status', '=', 'Active')->pluck('name', 'id'); + // main appointments + $appointment = Appointments::select('id') + ->count(); + $appointment_honoured = Cache::remember('appointment-honoured', 10, function () { + return Appointments::select(\DB::raw("COUNT(id) as count")) + ->where('date_attended', '=', DB::raw('appntmnt_date')) + ->pluck('count'); + }); + // dd($appointment_honoured); + $appointment_not_honoured = Cache::remember('appointment-not-honoured', 10, function () { + return Appointments::select(\DB::raw("COUNT(id) as count")) + ->whereIn('app_status', ['Defaulted', 'LTFU', 'Missed']) + ->pluck('count'); + }); + + // appointment honored by gender + $appointment_honoured_male = Cache::remember('appointment-honoured-male', 10, function () { + return Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->select(\DB::raw("COUNT(tbl_appointment.id) as count")) + ->where('tbl_appointment.date_attended', '=', DB::raw('tbl_appointment.appntmnt_date')) + ->where('tbl_client.gender', '=', '2') + ->pluck('count'); + }); + $appointment_honoured_female = Cache::remember('appointment-honoured-female', 10, function () { + return Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->where('tbl_appointment.date_attended', '=', DB::raw('tbl_appointment.appntmnt_date')) + ->where('tbl_client.gender', '=', '1') + ->count(); + }); + $appointment_honoured_uknown_gender = Cache::remember('appointment-honoured-uknown-gender', 10, function () { + return Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->where('tbl_appointment.date_attended', '=', DB::raw('tbl_appointment.appntmnt_date')) + ->where('tbl_client.gender', '!=', '1') + ->where('tbl_client.gender', '!=', '2') + ->count(); + }); + // appointment honored by age + $appointment_honored_to_nine = Cache::remember('appointment-honored-to-nine', 10, function () { + return Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) > 0) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 9)) then `tbl_client`.`id` end)) AS count")) + ->where('tbl_appointment.date_attended', '=', DB::raw('tbl_appointment.appntmnt_date')) + ->pluck('count'); + }); + $appointment_honored_to_fourteen = Cache::remember('appointment-honored-to-fourteen', 10, function () { + return Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 10) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 14)) then `tbl_client`.`id` end)) AS count")) ->where('tbl_appointment.date_attended', '=', DB::raw('tbl_appointment.appntmnt_date')) @@ -1102,202 +2192,774 @@ public function appointment_charts() $appointment_missed_to_twentyfive_above = Cache::remember('appointment_missed_to_twentyfive_above', 10, function () { return Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 25)) then `tbl_client`.`id` end)) AS count")) - ->where('tbl_appointment.app_status', '=', 'Missed') + ->where('tbl_appointment.app_status', '=', 'Missed') + ->pluck('count'); + }); + $appointment_missed_to_uknown_age = Cache::remember('appointment_missed_to_uknown_age', 10, function () { + return Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->select('tbl_client.dob') + ->where('tbl_client.dob', '=', '') + ->orWhereNull('tbl_client.dob') + ->where('tbl_appointment.app_status', '=', 'Missed') + ->count(); + }); + + // defaulted appointment by gender + $appointment_defaulted_female = Cache::remember('appointment_defaulted_female', 10, function () { + return Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->where('tbl_appointment.app_status', '=', 'Defaulted') + ->where('tbl_client.gender', '=', '1') + ->count(); + }); + $appointment_defaulted_male = Cache::remember('appointment_defaulted_male', 10, function () { + return Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->where('tbl_appointment.app_status', '=', 'Defaulted') + ->where('tbl_client.gender', '=', '2') + ->count(); + }); + $appointment_defaulted_uknown_gender = Cache::remember('appointment_defaulted_uknown_gender', 10, function () { + return Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->where('tbl_appointment.app_status', '=', 'Defaulted') + ->where('tbl_client.gender', '!=', '1') + ->where('tbl_client.gender', '!=', '2') + ->count(); + }); + + // defaulted appointment by age + $appointment_defaulted_to_nine = Cache::remember('appointment_defaulted_to_nine', 10, function () { + return Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) > 0) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 9)) then `tbl_client`.`id` end)) AS count")) + ->where('tbl_appointment.app_status', '=', 'Defaulted') + ->pluck('count'); + }); + $appointment_defaulted_to_fourteen = Cache::remember('appointment_defaulted_to_fourteen', 10, function () { + return Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 10) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 14)) then `tbl_client`.`id` end)) AS count")) + ->where('tbl_appointment.app_status', '=', 'Defaulted') + ->pluck('count'); + }); + $appointment_defaulted_to_nineteen = Cache::remember('appointment_defaulted_to_nineteen', 10, function () { + return Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 15) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 19)) then `tbl_client`.`id` end)) AS count")) + ->where('tbl_appointment.app_status', '=', 'Defaulted') + ->pluck('count'); + }); + $appointment_defaulted_to_twentyfour = Cache::remember('appointment_defaulted_to_twentyfour', 10, function () { + return Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 20) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 24)) then `tbl_client`.`id` end)) AS count")) + ->where('tbl_appointment.app_status', '=', 'Defaulted') + ->pluck('count'); + }); + $appointment_defaulted_to_twentyfive_above = Cache::remember('appointment_defaulted_to_twentyfive_above', 10, function () { + return Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 25)) then `tbl_client`.`id` end)) AS count")) + ->where('tbl_appointment.app_status', '=', 'Defaulted') + ->pluck('count'); + }); + $appointment_defaulted_to_uknown_age = Cache::remember('appointment_defaulted_to_uknown_age', 10, function () { + return Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->select('tbl_client.dob') + ->where('tbl_client.dob', '=', '') + ->orWhereNull('tbl_client.dob') + ->where('tbl_appointment.app_status', '=', 'Defaulted') + ->count(); + }); + // ltfu appointment by gender + $appointment_ltfu_female = Cache::remember('appointment_ltfu_female', 10, function () { + return Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->where('tbl_appointment.app_status', '=', 'LTFU') + ->where('tbl_client.gender', '=', '1') + ->count(); + }); + $appointment_ltfu_male = Cache::remember('appointment_ltfu_male', 10, function () { + return Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->where('tbl_appointment.app_status', '=', 'LTFU') + ->where('tbl_client.gender', '=', '2') + ->count(); + }); + $appointment_ltfu_uknown_gender = Cache::remember('appointment_ltfu_uknown_gender', 10, function () { + return Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->where('tbl_appointment.app_status', '=', 'LTFU') + ->where('tbl_client.gender', '!=', '1') + ->where('tbl_client.gender', '!=', '2') + ->count(); + }); + + // ltfu appointment by age + $appointment_ltfu_to_nine = Cache::remember('appointment_ltfu_to_nine', 10, function () { + return Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) > 0) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 9)) then `tbl_client`.`id` end)) AS count")) + ->where('tbl_appointment.app_status', '=', 'LTFU') + ->pluck('count'); + }); + $appointment_ltfu_to_fourteen = Cache::remember('appointment_ltfu_to_fourteen', 10, function () { + return Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 10) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 14)) then `tbl_client`.`id` end)) AS count")) + ->where('tbl_appointment.app_status', '=', 'LTFU') + ->pluck('count'); + }); + $appointment_ltfu_to_nineteen = Cache::remember('appointment_ltfu_to_nineteen', 10, function () { + return Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 15) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 19)) then `tbl_client`.`id` end)) AS count")) + ->where('tbl_appointment.app_status', '=', 'LTFU') + ->pluck('count'); + }); + $appointment_ltfu_to_twentyfour = Cache::remember('appointment_ltfu_to_twentyfour', 10, function () { + return Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 20) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 24)) then `tbl_client`.`id` end)) AS count")) + ->where('tbl_appointment.app_status', '=', 'LTFU') + ->pluck('count'); + }); + $appointment_ltfu_to_twentyfive_above = Cache::remember('appointment_ltfu_to_twentyfive_above', 10, function () { + return Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 25)) then `tbl_client`.`id` end)) AS count")) + ->where('tbl_appointment.app_status', '=', 'LTFU') ->pluck('count'); }); - $appointment_missed_to_uknown_age = Cache::remember('appointment_missed_to_uknown_age', 10, function () { + $appointment_ltfu_to_uknown_age = Cache::remember('appointment_ltfu_to_uknown_age', 10, function () { return Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') ->select('tbl_client.dob') ->where('tbl_client.dob', '=', '') ->orWhereNull('tbl_client.dob') - ->where('tbl_appointment.app_status', '=', 'Missed') + ->where('tbl_appointment.app_status', '=', 'LTFU') ->count(); }); + } - // defaulted appointment by gender - $appointment_defaulted_female = Cache::remember('appointment_defaulted_female', 10, function () { - return Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') - ->where('tbl_appointment.app_status', '=', 'Defaulted') - ->where('tbl_client.gender', '=', '1') - ->count(); - }); - $appointment_defaulted_male = Cache::remember('appointment_defaulted_male', 10, function () { - return Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') - ->where('tbl_appointment.app_status', '=', 'Defaulted') - ->where('tbl_client.gender', '=', '2') - ->count(); - }); - $appointment_defaulted_uknown_gender = Cache::remember('appointment_defaulted_uknown_gender', 10, function () { - return Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') - ->where('tbl_appointment.app_status', '=', 'Defaulted') - ->where('tbl_client.gender', '!=', '1') - ->where('tbl_client.gender', '!=', '2') - ->count(); - }); - // defaulted appointment by age - $appointment_defaulted_to_nine = Cache::remember('appointment_defaulted_to_nine', 10, function () { - return Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') - ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) > 0) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 9)) then `tbl_client`.`id` end)) AS count")) - ->where('tbl_appointment.app_status', '=', 'Defaulted') - ->pluck('count'); - }); - $appointment_defaulted_to_fourteen = Cache::remember('appointment_defaulted_to_fourteen', 10, function () { - return Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') - ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 10) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 14)) then `tbl_client`.`id` end)) AS count")) - ->where('tbl_appointment.app_status', '=', 'Defaulted') - ->pluck('count'); - }); - $appointment_defaulted_to_nineteen = Cache::remember('appointment_defaulted_to_nineteen', 10, function () { - return Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') - ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 15) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 19)) then `tbl_client`.`id` end)) AS count")) - ->where('tbl_appointment.app_status', '=', 'Defaulted') - ->pluck('count'); - }); - $appointment_defaulted_to_twentyfour = Cache::remember('appointment_defaulted_to_twentyfour', 10, function () { - return Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') - ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 20) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 24)) then `tbl_client`.`id` end)) AS count")) - ->where('tbl_appointment.app_status', '=', 'Defaulted') - ->pluck('count'); - }); - $appointment_defaulted_to_twentyfive_above = Cache::remember('appointment_defaulted_to_twentyfive_above', 10, function () { - return Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') - ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 25)) then `tbl_client`.`id` end)) AS count")) - ->where('tbl_appointment.app_status', '=', 'Defaulted') - ->pluck('count'); - }); - $appointment_defaulted_to_uknown_age = Cache::remember('appointment_defaulted_to_uknown_age', 10, function () { - return Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') - ->select('tbl_client.dob') - ->where('tbl_client.dob', '=', '') - ->orWhereNull('tbl_client.dob') - ->where('tbl_appointment.app_status', '=', 'Defaulted') - ->count(); - }); - // ltfu appointment by gender - $appointment_ltfu_female = Cache::remember('appointment_ltfu_female', 10, function () { - return Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') - ->where('tbl_appointment.app_status', '=', 'LTFU') - ->where('tbl_client.gender', '=', '1') - ->count(); - }); - $appointment_ltfu_male = Cache::remember('appointment_ltfu_male', 10, function () { - return Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') - ->where('tbl_appointment.app_status', '=', 'LTFU') - ->where('tbl_client.gender', '=', '2') - ->count(); - }); - $appointment_ltfu_uknown_gender = Cache::remember('appointment_ltfu_uknown_gender', 10, function () { - return Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') - ->where('tbl_appointment.app_status', '=', 'LTFU') - ->where('tbl_client.gender', '!=', '1') - ->where('tbl_client.gender', '!=', '2') - ->count(); - }); + return view('new_dashboard.appointment_dashboard', compact('all_partners', 'appointment', 'appointment_honoured', + 'appointment_not_honoured', + 'appointment_honoured_male', + 'appointment_honoured_female', + 'appointment_honoured_uknown_gender', + 'appointment_honored_to_nine', + 'appointment_honored_to_fourteen', + 'appointment_honored_to_nineteen', + 'appointment_honored_to_twentyfour', + 'appointment_honored_to_twentyfive_above', + 'appointment_honored_to_uknown_age', + 'appointment_not_honoured_male', + 'appointment_not_honoured_female', + 'appointment_not_honoured_uknown_gender', + 'appointment_not_honored_to_nine', + 'appointment_not_honored_to_fourteen', + 'appointment_not_honored_to_nineteen', + 'appointment_not_honored_to_twentyfour', + 'appointment_not_honored_to_twentyfive_above', + 'appointment_not_honored_to_uknown_age', + 'appointment_missed', + 'appointment_defaulted', + 'appointment_lftu', + 'appointment_missed_female', + 'appointment_missed_male', + 'appointment_missed_uknown_gender', + 'appointment_missed_to_nine', + 'appointment_missed_to_fourteen', + 'appointment_missed_to_nineteen', + 'appointment_missed_to_twentyfour', + 'appointment_missed_to_twentyfive_above', + 'appointment_missed_to_uknown_age', + 'appointment_defaulted_female', + 'appointment_defaulted_male', + 'appointment_defaulted_uknown_gender', + 'appointment_defaulted_to_nine', + 'appointment_defaulted_to_fourteen', + 'appointment_defaulted_to_nineteen', + 'appointment_defaulted_to_twentyfour', + 'appointment_defaulted_to_twentyfive_above', + 'appointment_defaulted_to_uknown_age', + 'appointment_ltfu_female', + 'appointment_ltfu_male', + 'appointment_ltfu_uknown_gender', + 'appointment_ltfu_to_nine', + 'appointment_ltfu_to_fourteen', + 'appointment_ltfu_to_nineteen', + 'appointment_ltfu_to_twentyfour', + 'appointment_ltfu_to_twentyfive_above', + 'appointment_ltfu_to_uknown_age' + )); + } + + public function filter_charts(Request $request) + { + // $data = []; + + $selected_partners = $request->partners; + $selected_counties = $request->counties; + $selected_subcounties = $request->subcounties; + $selected_facilites = $request->facilities; + + if (Auth::user()->access_level == 'Facility'){} + if (Auth::user()->access_level == 'Partner'){} + + $client = Client::where('status', '=', 'Active') + ->whereNull('hei_no') + ->where('created_at', '>=', date($request->from))->where('created_at', '<=', date($request->to)); + $appointment = Appointments::select('id') + ->where('created_at', '>=', date($request->from))->where('created_at', '<=', date($request->to)); + $missed_appointment = Appointments::select('id') + ->whereIn('app_status', ['Defaulted', 'LTFU', 'Missed']) + ->where('created_at', '>=', date($request->from))->where('created_at', '<=', date($request->to)); + $active_facilities = PartnerFacility::join('tbl_client', 'tbl_partner_facility.mfl_code', '=', 'tbl_client.mfl_code') + ->join('tbl_appointment', 'tbl_client.id', '=', 'tbl_appointment.client_id') + ->select('tbl_partner_facility.mfl_code') + ->where('tbl_appointment.created_at', '>=', Carbon::now()->subMonths(6)) + ->where('tbl_appointment.created_at', '>=', date($request->from))->where('tbl_appointment.created_at', '<=', date($request->to)); + ->orderBy('tbl_appointment.created_at', 'DESC') + ->groupBy('tbl_partner_facility.mfl_code') + ->get(); + // active clients by gender + $clients_male = Client::select('id') + ->where([['gender', '=', '2'], ['status', '=', 'Active'],]) + ->whereNull('hei_no') + ->where('created_at', '>=', date($request->from))->where('created_at', '<=', date($request->to)); + + $clients_female = Client::where('gender', '=', '1') + ->where('status', '=', 'Active') + ->whereNull('hei_no') + ->where('created_at', '>=', date($request->from))->where('created_at', '<=', date($request->to)); + $unknown_gender = Client::where('gender', '!=', '1') + ->where('gender', '!=', '2') + ->where('status', '=', 'Active') + ->whereNull('hei_no') + ->where('created_at', '>=', date($request->from))->where('created_at', '<=', date($request->to)); + + $client_to_nine = Client::select(\DB::raw("count((case when (((year(curdate()) - year(`dob`)) > 0) and ((year(curdate()) - year(`dob`)) <= 9)) then `dob` end")) + ->where('status', '=', 'Active') + ->whereNull('hei_no') + ->where('created_at', '>=', date($request->from))->where('created_at', '<=', date($request->to)); + + $client_to_fourteen = Client::select(\DB::raw("case when (((year(curdate()) - year(`dob`)) >= 10) and ((year(curdate()) - year(`dob`)) <= 14)) then `dob` end")) + ->where('status', '=', 'Active') + ->whereNull('hei_no') + ->where('created_at', '>=', date($request->from))->where('created_at', '<=', date($request->to)); + + + $client_to_nineteen = Client::select(\DB::raw("case when (((year(curdate()) - year(`dob`)) >= 15) and ((year(curdate()) - year(`dob`)) <= 19)) then `dob` end")) + ->where('status', '=', 'Active') + ->whereNull('hei_no') + ->where('created_at', '>=', date($request->from))->where('created_at', '<=', date($request->to)); + + + $client_to_twentyfour = Client::select(\DB::raw("case when (((year(curdate()) - year(`dob`)) >= 20) and ((year(curdate()) - year(`dob`)) <= 24)) then `id` end")) + ->where('status', '=', 'Active') + ->whereNull('hei_no') + ->where('created_at', '>=', date($request->from))->where('created_at', '<=', date($request->to)); + + + $client_to_twentyfive_above = Client::select(\DB::raw("case when (((year(curdate()) - year(`dob`)) >= 25)) then `id` end")) + ->where('status', '=', 'Active') + ->whereNull('hei_no') + ->where('created_at', '>=', date($request->from))->where('created_at', '<=', date($request->to)); + + + $client_unknown_age = Client::where('dob', '=', '') + ->orWhereNull('dob') + ->where('status', '=', 'Active') + ->whereNull('hei_no') + ->where('created_at', '>=', date($request->from))->where('created_at', '<=', date($request->to)); + + + // appointment by gender + $appointment_male = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->select('tbl_appointment.id') + ->where('tbl_client.gender', '=', '2') + ->where('tbl_appointment.created_at', '>=', date($request->from))->where('tbl_appointment.created_at', '<=', date($request->to)); + + $appointment_female = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->select('tbl_appointment.id') + ->where('tbl_client.gender', '=', '1') + ->where('tbl_appointment.created_at', '>=', date($request->from))->where('tbl_appointment.created_at', '<=', date($request->to)); + + $appointment_uknown_gender = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->select('tbl_appointment.id') + ->where('tbl_client.gender', '!=', '1') + ->where('tbl_client.gender', '!=', '2') + ->where('tbl_appointment.created_at', '>=', date($request->from))->where('tbl_appointment.created_at', '<=', date($request->to)); + + // appointment by age + $appointment_to_nine = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select(\DB::raw("case when (((year(curdate()) - year(`tbl_client`.`dob`)) > 0) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 9)) then `tbl_client`.`id` end")) + ->where('tbl_appointment.created_at', '>=', date($request->from))->where('tbl_appointment.created_at', '<=', date($request->to)); + + $appointment_to_fourteen = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select(\DB::raw("case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 10) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 14)) then `tbl_client`.`id` end")) + + $appointment_to_nineteen = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select(\DB::raw("case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 15) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 19)) then `tbl_client`.`id` end")) + ->where('tbl_appointment.created_at', '>=', date($request->from))->where('tbl_appointment.created_at', '<=', date($request->to)); + + + $appointment_to_twentyfour = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select(\DB::raw("case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 20) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 24)) then `tbl_client`.`id` end")) + ->where('tbl_appointment.created_at', '>=', date($request->from))->where('tbl_appointment.created_at', '<=', date($request->to)); + + + $appointment_to_twentyfive_above = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select(\DB::raw("case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 25)) then `tbl_client`.`id` end")) + ->where('tbl_appointment.created_at', '>=', date($request->from))->where('tbl_appointment.created_at', '<=', date($request->to)); + + + $appointment_uknown_age = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->where('tbl_client.dob', '=', '') + ->orWhereNull('tbl_client.dob') + ->where('tbl_appointment.created_at', '>=', date($request->from))->where('tbl_appointment.created_at', '<=', date($request->to)); + + + // Total missed appointment by gender + $appointment_total_missed_female = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->whereIn('tbl_appointment.app_status', ['Defaulted', 'LTFU', 'Missed']) + ->where('tbl_client.gender', '=', '1') + ->where('tbl_appointment.created_at', '>=', date($request->from))->where('tbl_appointment.created_at', '<=', date($request->to)); + + $appointment_total_missed_male = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->where('tbl_client.gender', '=', '2') + ->whereIn('tbl_appointment.app_status', ['Defaulted', 'LTFU', 'Missed']) + ->where('tbl_appointment.created_at', '>=', date($request->from))->where('tbl_appointment.created_at', '<=', date($request->to)); + + + $appointment_total_missed_uknown_gender = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->whereIn('tbl_appointment.app_status', ['Defaulted', 'LTFU', 'Missed']) + ->where('tbl_client.gender', '!=', '1') + ->where('tbl_client.gender', '!=', '2') + + + // Total missed appointment by age + $appointment_total_missed_to_nine = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->select(\DB::raw("case when (((year(curdate()) - year(`tbl_client`.`dob`)) > 0) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 9)) then `tbl_client`.`id` end")) + ->whereIn('tbl_appointment.app_status', ['Defaulted', 'LTFU', 'Missed']) + ->where('tbl_appointment.created_at', '>=', date($request->from))->where('tbl_appointment.created_at', '<=', date($request->to)); + + $appointment_total_missed_to_fourteen = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->select(\DB::raw("case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 10) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 14)) then `tbl_client`.`id` end")) + ->whereIn('tbl_appointment.app_status', ['Defaulted', 'LTFU', 'Missed']) + ->where('tbl_appointment.created_at', '>=', date($request->from))->where('tbl_appointment.created_at', '<=', date($request->to)); + + $appointment_total_missed_to_nineteen = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->select(\DB::raw("case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 15) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 19)) then `tbl_client`.`id` end")) + ->whereIn('tbl_appointment.app_status', ['Defaulted', 'LTFU', 'Missed']) + ->where('tbl_appointment.created_at', '>=', date($request->from))->where('tbl_appointment.created_at', '<=', date($request->to)); + + $appointment_total_missed_to_twentyfour = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->select(\DB::raw("case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 20) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 24)) then `tbl_client`.`id` end")) + ->whereIn('tbl_appointment.app_status', ['Defaulted', 'LTFU', 'Missed']) + ->where('tbl_appointment.created_at', '>=', date($request->from))->where('tbl_appointment.created_at', '<=', date($request->to)); + + $appointment_total_missed_to_twentyfive_above = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->select(\DB::raw("case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 25)) then `tbl_client`.`id` end")) + ->whereIn('tbl_appointment.app_status', ['Defaulted', 'LTFU', 'Missed']) + ->where('tbl_appointment.created_at', '>=', date($request->from))->where('tbl_appointment.created_at', '<=', date($request->to)); + + $appointment_total_missed_uknown_age = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->where('tbl_client.dob', '=', '') + ->orWhereNull('tbl_client.dob') + ->whereIn('tbl_appointment.app_status', ['Defaulted', 'LTFU', 'Missed']) + ->where('tbl_appointment.created_at', '>=', date($request->from))->where('tbl_appointment.created_at', '<=', date($request->to)); + + // client charts + $client_consented = Client::select('smsenable') + ->where('status', '=', 'Active') + ->whereNull('hei_no') + ->where('smsenable', '=', 'Yes') + ->where('created_at', '>=', date($request->from))->where('created_at', '<=', date($request->to)); + + $client_nonconsented = Client::select('smsenable') + ->where('status', '=', 'Active') + ->whereNull('hei_no') + ->where('smsenable', '!=', 'Yes') + ->where('created_at', '>=', date($request->from))->where('created_at', '<=', date($request->to)); + + // consented clients by gender + + $client_consented_male = Client::where('smsenable', '=', 'Yes') + ->where('status', '=', 'Active') + ->whereNull('hei_no') + ->where('gender', '=', '2') + ->where('created_at', '>=', date($request->from))->where('created_at', '<=', date($request->to)); + + $client_consented_female = Client::where('smsenable', '=', 'Yes') + ->where('status', '=', 'Active') + ->whereNull('hei_no') + ->where('gender', '=', '1') + ->where('created_at', '>=', date($request->from))->where('created_at', '<=', date($request->to)); + + $client_consented_uknown_gender = Client::where('smsenable', '=', 'Yes') + ->where('status', '=', 'Active') + ->whereNull('hei_no') + ->where('gender', '!=', '1') + ->where('gender', '!=', '2') + ->where('created_at', '>=', date($request->from))->where('created_at', '<=', date($request->to)); + + // non consented clients by gender + $client_nonconsented_male = Client::where('smsenable', '!=', 'Yes') + ->where('status', '=', 'Active') + ->whereNull('hei_no') + ->where('gender', '=', '2') + ->where('created_at', '>=', date($request->from))->where('created_at', '<=', date($request->to)); + + + $client_nonconsented_female = Client::where('smsenable', '!=', 'Yes') + ->where('status', '=', 'Active') + ->whereNull('hei_no') + ->where('gender', '=', '1') + ->where('created_at', '>=', date($request->from))->where('created_at', '<=', date($request->to)); + + $client_nonconsented_uknown_gender = Client::where('smsenable', '!=', 'Yes') + ->where('gender', '!=', '1') + ->where('gender', '!=', '2') + ->where('created_at', '>=', date($request->from))->where('created_at', '<=', date($request->to)); + + // consented clients by age distribution + $client_consented_to_nine = Client::select(\DB::raw("case when (((year(curdate()) - year(`tbl_client`.`dob`)) > 0) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 9)) then `tbl_client`.`id` end")) + ->where('smsenable', '=', 'Yes') + ->where('status', '=', 'Active') + ->whereNull('hei_no') + ->where('created_at', '>=', date($request->from))->where('created_at', '<=', date($request->to)); + + $client_consented_to_fourteen = Client::select(\DB::raw("case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 10) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 14)) then `tbl_client`.`id` end")) + ->where('smsenable', '=', 'Yes') + ->where('status', '=', 'Active') + ->whereNull('hei_no') + ->where('created_at', '>=', date($request->from))->where('created_at', '<=', date($request->to)); - // ltfu appointment by age - $appointment_ltfu_to_nine = Cache::remember('appointment_ltfu_to_nine', 10, function () { - return Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') - ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) > 0) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 9)) then `tbl_client`.`id` end)) AS count")) - ->where('tbl_appointment.app_status', '=', 'LTFU') - ->pluck('count'); - }); - $appointment_ltfu_to_fourteen = Cache::remember('appointment_ltfu_to_fourteen', 10, function () { - return Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') - ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 10) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 14)) then `tbl_client`.`id` end)) AS count")) - ->where('tbl_appointment.app_status', '=', 'LTFU') - ->pluck('count'); - }); - $appointment_ltfu_to_nineteen = Cache::remember('appointment_ltfu_to_nineteen', 10, function () { - return Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') - ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 15) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 19)) then `tbl_client`.`id` end)) AS count")) - ->where('tbl_appointment.app_status', '=', 'LTFU') - ->pluck('count'); - }); - $appointment_ltfu_to_twentyfour = Cache::remember('appointment_ltfu_to_twentyfour', 10, function () { - return Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') - ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 20) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 24)) then `tbl_client`.`id` end)) AS count")) - ->where('tbl_appointment.app_status', '=', 'LTFU') - ->pluck('count'); - }); - $appointment_ltfu_to_twentyfive_above = Cache::remember('appointment_ltfu_to_twentyfive_above', 10, function () { - return Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') - ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 25)) then `tbl_client`.`id` end)) AS count")) - ->where('tbl_appointment.app_status', '=', 'LTFU') - ->pluck('count'); - }); - $appointment_ltfu_to_uknown_age = Cache::remember('appointment_ltfu_to_uknown_age', 10, function () { - return Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') - ->select('tbl_client.dob') - ->where('tbl_client.dob', '=', '') - ->orWhereNull('tbl_client.dob') - ->where('tbl_appointment.app_status', '=', 'LTFU') - ->count(); - }); - } + $client_consented_to_nineteen = Client::select(\DB::raw("case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 15) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 19)) then `tbl_client`.`id` end")) + ->where('smsenable', '=', 'Yes') + ->where('status', '=', 'Active') + ->whereNull('hei_no') + ->where('created_at', '>=', date($request->from))->where('created_at', '<=', date($request->to)); + $client_consented_to_twentyfour = Client::select(\DB::raw("case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 20) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 24)) then `tbl_client`.`id` end")) + ->where('smsenable', '=', 'Yes') + ->where('status', '=', 'Active') + ->whereNull('hei_no') + ->where('created_at', '>=', date($request->from))->where('created_at', '<=', date($request->to)); - return view('new_dashboard.appointment_dashboard', compact('all_partners', 'appointment', 'appointment_honoured', - 'appointment_not_honoured', - 'appointment_honoured_male', - 'appointment_honoured_female', - 'appointment_honoured_uknown_gender', - 'appointment_honored_to_nine', - 'appointment_honored_to_fourteen', - 'appointment_honored_to_nineteen', - 'appointment_honored_to_twentyfour', - 'appointment_honored_to_twentyfive_above', - 'appointment_honored_to_uknown_age', - 'appointment_not_honoured_male', - 'appointment_not_honoured_female', - 'appointment_not_honoured_uknown_gender', - 'appointment_not_honored_to_nine', - 'appointment_not_honored_to_fourteen', - 'appointment_not_honored_to_nineteen', - 'appointment_not_honored_to_twentyfour', - 'appointment_not_honored_to_twentyfive_above', - 'appointment_not_honored_to_uknown_age', - 'appointment_missed', - 'appointment_defaulted', - 'appointment_lftu', - 'appointment_missed_female', - 'appointment_missed_male', - 'appointment_missed_uknown_gender', - 'appointment_missed_to_nine', - 'appointment_missed_to_fourteen', - 'appointment_missed_to_nineteen', - 'appointment_missed_to_twentyfour', - 'appointment_missed_to_twentyfive_above', - 'appointment_missed_to_uknown_age', - 'appointment_defaulted_female', - 'appointment_defaulted_male', - 'appointment_defaulted_uknown_gender', - 'appointment_defaulted_to_nine', - 'appointment_defaulted_to_fourteen', - 'appointment_defaulted_to_nineteen', - 'appointment_defaulted_to_twentyfour', - 'appointment_defaulted_to_twentyfive_above', - 'appointment_defaulted_to_uknown_age', - 'appointment_ltfu_female', - 'appointment_ltfu_male', - 'appointment_ltfu_uknown_gender', - 'appointment_ltfu_to_nine', - 'appointment_ltfu_to_fourteen', - 'appointment_ltfu_to_nineteen', - 'appointment_ltfu_to_twentyfour', - 'appointment_ltfu_to_twentyfive_above', - 'appointment_ltfu_to_uknown_age' - )); - } + $client_consented_to_twentyfive_above = Client::select(\DB::raw("case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 25)) then `tbl_client`.`id` end")) + ->where('smsenable', '=', 'Yes') + ->where('status', '=', 'Active') + ->whereNull('hei_no') + ->where('created_at', '>=', date($request->from))->where('created_at', '<=', date($request->to)); - public function filter_charts(Request $request) - { - // $data = []; + $client_consented_uknown_age = Client::select('smsenable') + ->where('dob', '=', '') + ->where('status', '=', 'Active') + ->whereNull('hei_no') + ->orWhereNull('dob') + ->where('smsenable', '=', 'Yes') + ->where('created_at', '>=', date($request->from))->where('created_at', '<=', date($request->to)); + + // non consented clients by age distribution + $client_nonconsented_to_nine = Client::select(\DB::raw("case when (((year(curdate()) - year(`tbl_client`.`dob`)) > 0) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 9)) then `tbl_client`.`id` end")) + ->where('smsenable', '!=', 'Yes') + ->where('status', '=', 'Active') + ->whereNull('hei_no') + ->where('created_at', '>=', date($request->from))->where('created_at', '<=', date($request->to)); + + $client_nonconsented_to_fourteen = Client::select(\DB::raw("case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 10) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 14)) then `tbl_client`.`id` end")) + ->where('smsenable', '!=', 'Yes') + ->where('status', '=', 'Active') + ->whereNull('hei_no') + ->where('created_at', '>=', date($request->from))->where('created_at', '<=', date($request->to)); + + $client_nonconsented_to_nineteen = Client::select(\DB::raw("case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 15) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 19)) then `tbl_client`.`id` end")) + ->where('smsenable', '!=', 'Yes') + ->where('status', '=', 'Active') + ->whereNull('hei_no') + ->where('created_at', '>=', date($request->from))->where('created_at', '<=', date($request->to)); + + $client_nonconsented_to_twentyfour = Client::select(\DB::raw("case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 20) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 24)) then `tbl_client`.`id` end")) + ->where('smsenable', '!=', 'Yes') + ->where('status', '=', 'Active') + ->whereNull('hei_no') + ->where('created_at', '>=', date($request->from))->where('created_at', '<=', date($request->to)); + + $client_nonconsented_to_twentyfive_above = Client::select(\DB::raw("case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 25)) then `tbl_client`.`id` end")) + ->where('smsenable', '!=', 'Yes') + ->where('status', '=', 'Active') + ->whereNull('hei_no') + ->where('created_at', '>=', date($request->from))->where('created_at', '<=', date($request->to)); - // $selected_counties = $request->partners; - // $selected_counties = $request->counties; - // $selected_subcounties = $request->subcounties; - // $selected_facilites = $request->facilities; + $client_nonconsented_uknown_age = Client::select('smsenable') + ->where('status', '=', 'Active') + ->whereNull('hei_no') + ->where('dob', '=', '') + ->orWhereNull('dob') + ->where('smsenable', '!=', 'Yes') + ->where('created_at', '>=', date($request->from))->where('created_at', '<=', date($request->to)); + + if (!empty($selected_partners)) { + $client = $client->where('tbl_partner_facility.partner_id', $selected_partners); + $appointment = $appointment->where('tbl_partner_facility.partner_id', $selected_partners); + $missed_appointment = $missed_appointment->where('tbl_partner_facility.partner_id', $selected_partners); + $active_facilities = $active_facilities->where('tbl_partner_facility.partner_id', $selected_partners); + $clients_male = $clients_male->where('tbl_partner_facility.partner_id', $selected_partners); + $clients_female = $clients_female->where('tbl_partner_facility.partner_id', $selected_partners); + $unknown_gender = $unknown_gender->where('tbl_partner_facility.partner_id', $selected_partners); + $client_to_nine = $client_to_nine->where('tbl_partner_facility.partner_id', $selected_partners); + $client_to_fourteen = $client_to_fourteen->where('tbl_partner_facility.partner_id', $selected_partners); + $client_to_nineteen = $client_to_nineteen->where('tbl_partner_facility.partner_id', $selected_partners); + $client_to_twentyfour = $client_to_twentyfour->where('tbl_partner_facility.partner_id', $selected_partners); + $client_to_twentyfive_above = $client_to_twentyfive_above->where('tbl_partner_facility.partner_id', $selected_partners); + $client_unknown_age = $client_unknown_age->where('tbl_partner_facility.partner_id', $selected_partners); + $appointment_male = $appointment_male->where('tbl_partner_facility.partner_id', $selected_partners); + $appointment_female = $appointment_female->where('tbl_partner_facility.partner_id', $selected_partners); + $appointment_uknown_gender = $appointment_uknown_gender->where('tbl_partner_facility.partner_id', $selected_partners); + $appointment_to_nine = $appointment_to_nine->where('tbl_partner_facility.partner_id', $selected_partners); + $appointment_to_fourteen = $appointment_to_fourteen->where('tbl_partner_facility.partner_id', $selected_partners); + $appointment_to_nineteen = $appointment_to_nineteen->where('tbl_partner_facility.partner_id', $selected_partners); + $appointment_to_twentyfour = $appointment_to_twentyfour->where('tbl_partner_facility.partner_id', $selected_partners); + $appointment_to_twentyfive_above = $appointment_to_twentyfive_above->where('tbl_partner_facility.partner_id', $selected_partners); + $appointment_uknown_age = $appointment_uknown_age->where('tbl_partner_facility.partner_id', $selected_partners); + $appointment_total_missed_female = $appointment_total_missed_female->where('tbl_partner_facility.partner_id', $selected_partners); + $appointment_total_missed_male = $appointment_total_missed_male->where('tbl_partner_facility.partner_id', $selected_partners); + $appointment_total_missed_uknown_gender = $appointment_total_missed_uknown_gender->where('tbl_partner_facility.partner_id', $selected_partners); + $appointment_total_missed_to_nine = $appointment_total_missed_to_nine->where('tbl_partner_facility.partner_id', $selected_partners); + $appointment_total_missed_to_fourteen = $appointment_total_missed_to_fourteen->where('tbl_partner_facility.partner_id', $selected_partners); + $appointment_total_missed_to_nineteen = $appointment_total_missed_to_nineteen->where('tbl_partner_facility.partner_id', $selected_partners); + $appointment_total_missed_to_twentyfour = $appointment_total_missed_to_twentyfour->where('tbl_partner_facility.partner_id', $selected_partners); + $appointment_total_missed_to_twentyfive_above = $appointment_total_missed_to_twentyfive_above->where('tbl_partner_facility.partner_id', $selected_partners); + $appointment_total_missed_uknown_age = $appointment_total_missed_uknown_age->where('tbl_partner_facility.partner_id', $selected_partners); + + $client_consented = $client_consented->where('tbl_partner_facility.partner_id', $selected_partners); + $client_nonconsented = $client_nonconsented->where('tbl_partner_facility.partner_id', $selected_partners); + $client_consented_male = $client_consented_male->where('tbl_partner_facility.partner_id', $selected_partners); + $client_consented_female = $client_consented_female->where('tbl_partner_facility.partner_id', $selected_partners); + $client_consented_uknown_gender = $client_consented_uknown_gender->where('tbl_partner_facility.partner_id', $selected_partners); + $client_nonconsented_male = $client_nonconsented_male->where('tbl_partner_facility.partner_id', $selected_partners); + $client_nonconsented_female = $client_nonconsented_female->where('tbl_partner_facility.partner_id', $selected_partners); + $client_nonconsented_uknown_gender = $client_nonconsented_uknown_gender->where('tbl_partner_facility.partner_id', $selected_partners); + $client_consented_to_nine = $client_consented_to_nine->where('tbl_partner_facility.partner_id', $selected_partners); + $client_consented_to_fourteen = $client_consented_to_fourteen->where('tbl_partner_facility.partner_id', $selected_partners); + $client_consented_to_nineteen = $client_consented_to_nineteen->where('tbl_partner_facility.partner_id', $selected_partners); + $client_consented_to_twentyfour = $client_consented_to_twentyfour->where('tbl_partner_facility.partner_id', $selected_partners); + $client_consented_to_twentyfive_above = $client_consented_to_twentyfive_above->where('tbl_partner_facility.partner_id', $selected_partners); + $client_consented_uknown_age = $client_consented_uknown_age->where('tbl_partner_facility.partner_id', $selected_partners); + $client_nonconsented_to_nine = $client_nonconsented_to_nine->where('tbl_partner_facility.partner_id', $selected_partners); + $client_nonconsented_to_fourteen = $client_nonconsented_to_fourteen->where('tbl_partner_facility.partner_id', $selected_partners); + $client_nonconsented_to_nineteen = $client_nonconsented_to_nineteen->where('tbl_partner_facility.partner_id', $selected_partners); + $client_nonconsented_to_twentyfour = $client_nonconsented_to_twentyfour->where('tbl_partner_facility.partner_id', $selected_partners); + $client_nonconsented_to_twentyfive_above = $client_nonconsented_to_twentyfive_above->where('tbl_partner_facility.partner_id', $selected_partners); + $client_nonconsented_uknown_age = $client_nonconsented_to_twentyfive_aboclient_nonconsented_uknown_ageve->where('tbl_partner_facility.partner_id', $selected_partners); + } + if (!empty($selected_counties)) { + $client = $client->where('tbl_partner_facility.county_id', $selected_counties); + $appointment = $appointment->where('tbl_partner_facility.county_id', $selected_counties); + $missed_appointment = $missed_appointment->where('tbl_partner_facility.county_id', $selected_counties); + $active_facilities = $active_facilities->where('tbl_partner_facility.county_id', $selected_counties); + $clients_male = $clients_male->where('tbl_partner_facility.county_id', $selected_counties); + $clients_female = $clients_female->where('tbl_partner_facility.county_id', $selected_counties); + $unknown_gender = $unknown_gender->where('tbl_partner_facility.county_id', $selected_counties); + $client_to_nine = $client_to_nine->where('tbl_partner_facility.county_id', $selected_counties); + $client_to_fourteen = $client_to_fourteen->where('tbl_partner_facility.county_id', $selected_counties); + $client_to_nineteen = $client_to_nineteen->where('tbl_partner_facility.county_id', $selected_counties); + $client_to_twentyfour = $client_to_twentyfour->where('tbl_partner_facility.county_id', $selected_counties); + $client_to_twentyfive_above = $client_to_twentyfive_above->where('tbl_partner_facility.county_id', $selected_counties); + $client_unknown_age = $client_unknown_age->where('tbl_partner_facility.county_id', $selected_counties); + $appointment_male = $appointment_male->where('tbl_partner_facility.county_id', $selected_counties); + $appointment_female = $appointment_female->where('tbl_partner_facility.county_id', $selected_counties); + $appointment_uknown_gender = $appointment_uknown_gender->where('tbl_partner_facility.county_id', $selected_counties); + $appointment_to_nine = $appointment_to_nine->where('tbl_partner_facility.county_id', $selected_counties); + $appointment_to_fourteen = $appointment_to_fourteen->where('tbl_partner_facility.county_id', $selected_counties); + $appointment_to_nineteen = $appointment_to_nineteen->where('tbl_partner_facility.county_id', $selected_counties); + $appointment_to_twentyfour = $appointment_to_twentyfour->where('tbl_partner_facility.county_id', $selected_counties); + $appointment_to_twentyfive_above = $appointment_to_twentyfive_above->where('tbl_partner_facility.county_id', $selected_counties); + $appointment_uknown_age = $appointment_uknown_age->where('tbl_partner_facility.county_id', $selected_counties); + $appointment_total_missed_female = $appointment_total_missed_female->where('tbl_partner_facility.county_id', $selected_counties); + $appointment_total_missed_male = $appointment_total_missed_male->where('tbl_partner_facility.county_id', $selected_counties); + $appointment_total_missed_uknown_gender = $appointment_total_missed_uknown_gender->where('tbl_partner_facility.county_id', $selected_counties); + $appointment_total_missed_to_nine = $appointment_total_missed_to_nine->where('tbl_partner_facility.county_id', $selected_counties); + $appointment_total_missed_to_fourteen = $appointment_total_missed_to_fourteen->where('tbl_partner_facility.county_id', $selected_counties); + $appointment_total_missed_to_nineteen = $appointment_total_missed_to_nineteen->where('tbl_partner_facility.county_id', $selected_counties); + $appointment_total_missed_to_twentyfour = $appointment_total_missed_to_twentyfour->where('tbl_partner_facility.county_id', $selected_counties); + $appointment_total_missed_to_twentyfive_above = $appointment_total_missed_to_twentyfive_above->where('tbl_partner_facility.county_id', $selected_counties); + $appointment_total_missed_uknown_age = $appointment_total_missed_uknown_age->where('tbl_partner_facility.county_id', $selected_counties); + + $client_consented = $client_consented->where('tbl_partner_facility.county_id', $selected_counties); + $client_nonconsented = $client_nonconsented->where('tbl_partner_facility.county_id', $selected_counties); + $client_consented_male = $client_consented_male->where('tbl_partner_facility.county_id', $selected_counties); + $client_consented_female = $client_consented_female->where('tbl_partner_facility.county_id', $selected_counties); + $client_consented_uknown_gender = $client_consented_uknown_gender->where('tbl_partner_facility.county_id', $selected_counties); + $client_nonconsented_male = $client_nonconsented_male->where('tbl_partner_facility.county_id', $selected_counties); + $client_nonconsented_female = $client_nonconsented_female->where('tbl_partner_facility.county_id', $selected_counties); + $client_nonconsented_uknown_gender = $client_nonconsented_uknown_gender->where('tbl_partner_facility.county_id', $selected_counties); + $client_consented_to_nine = $client_consented_to_nine->where('tbl_partner_facility.county_id', $selected_counties); + $client_consented_to_fourteen = $client_consented_to_fourteen->where('tbl_partner_facility.county_id', $selected_counties); + $client_consented_to_nineteen = $client_consented_to_nineteen->where('tbl_partner_facility.county_id', $selected_counties); + $client_consented_to_twentyfour = $client_consented_to_twentyfour->where('tbl_partner_facility.county_id', $selected_counties); + $client_consented_to_twentyfive_above = $client_consented_to_twentyfive_above->where('tbl_partner_facility.county_id', $selected_counties); + $client_consented_uknown_age = $client_consented_uknown_age->where('tbl_partner_facility.county_id', $selected_counties); + $client_nonconsented_to_nine = $client_nonconsented_to_nine->where('tbl_partner_facility.county_id', $selected_counties); + $client_nonconsented_to_fourteen = $client_nonconsented_to_fourteen->where('tbl_partner_facility.county_id', $selected_counties); + $client_nonconsented_to_nineteen = $client_nonconsented_to_nineteen->where('tbl_partner_facility.county_id', $selected_counties); + $client_nonconsented_to_twentyfour = $client_nonconsented_to_twentyfour->where('tbl_partner_facility.county_id', $selected_counties); + $client_nonconsented_to_twentyfive_above = $client_nonconsented_to_twentyfive_above->where('tbl_partner_facility.county_id', $selected_counties); + $client_nonconsented_uknown_age = $client_nonconsented_to_twentyfive_aboclient_nonconsented_uknown_ageve->where('tbl_partner_facility.county_id', $selected_counties); + } + if (!empty($selected_subcounties)) { + $client = $client->where('tbl_partner_facility.sub_county_id', $selected_subcounties); + $appointment = $appointment->where('tbl_partner_facility.sub_county_id', $selected_subcounties); + $missed_appointment = $missed_appointment->where('tbl_partner_facility.sub_county_id', $selected_subcounties); + $active_facilities = $active_facilities->where('tbl_partner_facility.sub_county_id', $selected_subcounties); + $clients_male = $clients_male->where('tbl_partner_facility.sub_county_id', $selected_subcounties); + $clients_female = $clients_female->where('tbl_partner_facility.sub_county_id', $selected_subcounties); + $unknown_gender = $unknown_gender->where('tbl_partner_facility.sub_county_id', $selected_subcounties); + $client_to_nine = $client_to_nine->where('tbl_partner_facility.sub_county_id', $selected_subcounties); + $client_to_fourteen = $client_to_fourteen->where('tbl_partner_facility.sub_county_id', $selected_subcounties); + $client_to_nineteen = $client_to_nineteen->where('tbl_partner_facility.sub_county_id', $selected_subcounties); + $client_to_twentyfour = $client_to_twentyfour->where('tbl_partner_facility.sub_county_id', $selected_subcounties); + $client_to_twentyfive_above = $client_to_twentyfive_above->where('tbl_partner_facility.sub_county_id', $selected_subcounties); + $client_unknown_age = $client_unknown_age->where('tbl_partner_facility.sub_county_id', $selected_subcounties); + $appointment_male = $appointment_male->where('tbl_partner_facility.sub_county_id', $selected_subcounties); + $appointment_female = $appointment_female->where('tbl_partner_facility.sub_county_id', $selected_subcounties); + $appointment_uknown_gender = $appointment_uknown_gender->where('tbl_partner_facility.sub_county_id', $selected_subcounties); + $appointment_to_nine = $appointment_to_nine->where('tbl_partner_facility.sub_county_id', $selected_subcounties); + $appointment_to_fourteen = $appointment_to_fourteen->where('tbl_partner_facility.sub_county_id', $selected_subcounties); + $appointment_to_nineteen = $appointment_to_nineteen->where('tbl_partner_facility.sub_county_id', $selected_subcounties); + $appointment_to_twentyfour = $appointment_to_twentyfour->where('tbl_partner_facility.sub_county_id', $selected_subcounties); + $appointment_to_twentyfive_above = $appointment_to_twentyfive_above->where('tbl_partner_facility.sub_county_id', $selected_subcounties); + $appointment_uknown_age = $appointment_uknown_age->where('tbl_partner_facility.sub_county_id', $selected_subcounties); + $appointment_total_missed_female = $appointment_total_missed_female->where('tbl_partner_facility.sub_county_id', $selected_subcounties); + $appointment_total_missed_male = $appointment_total_missed_male->where('tbl_partner_facility.sub_county_id', $selected_subcounties); + $appointment_total_missed_uknown_gender = $appointment_total_missed_uknown_gender->where('tbl_partner_facility.sub_county_id', $selected_subcounties); + $appointment_total_missed_to_nine = $appointment_total_missed_to_nine->where('tbl_partner_facility.sub_county_id', $selected_subcounties); + $appointment_total_missed_to_fourteen = $appointment_total_missed_to_fourteen->where('tbl_partner_facility.sub_county_id', $selected_subcounties); + $appointment_total_missed_to_nineteen = $appointment_total_missed_to_nineteen->where('tbl_partner_facility.sub_county_id', $selected_subcounties); + $appointment_total_missed_to_twentyfour = $appointment_total_missed_to_twentyfour->where('tbl_partner_facility.sub_county_id', $selected_subcounties); + $appointment_total_missed_to_twentyfive_above = $appointment_total_missed_to_twentyfive_above->where('tbl_partner_facility.sub_county_id', $selected_subcounties); + $appointment_total_missed_uknown_age = $appointment_total_missed_uknown_age->where('tbl_partner_facility.sub_county_id', $selected_subcounties); + + $client_consented = $client_consented->where('tbl_partner_facility.sub_county_id', $selected_subcounties); + $client_nonconsented = $client_nonconsented->where('tbl_partner_facility.sub_county_id', $selected_subcounties); + $client_consented_male = $client_consented_male->where('tbl_partner_facility.sub_county_id', $selected_subcounties); + $client_consented_female = $client_consented_female->where('tbl_partner_facility.sub_county_id', $selected_subcounties); + $client_consented_uknown_gender = $client_consented_uknown_gender->where('tbl_partner_facility.sub_county_id', $selected_subcounties); + $client_nonconsented_male = $client_nonconsented_male->where('tbl_partner_facility.sub_county_id', $selected_subcounties); + $client_nonconsented_female = $client_nonconsented_female->where('tbl_partner_facility.sub_county_id', $selected_subcounties); + $client_nonconsented_uknown_gender = $client_nonconsented_uknown_gender->where('tbl_partner_facility.sub_county_id', $selected_subcounties); + $client_consented_to_nine = $client_consented_to_nine->where('tbl_partner_facility.sub_county_id', $selected_subcounties); + $client_consented_to_fourteen = $client_consented_to_fourteen->where('tbl_partner_facility.sub_county_id', $selected_subcounties); + $client_consented_to_nineteen = $client_consented_to_nineteen->where('tbl_partner_facility.sub_county_id', $selected_subcounties); + $client_consented_to_twentyfour = $client_consented_to_twentyfour->where('tbl_partner_facility.sub_county_id', $selected_subcounties); + $client_consented_to_twentyfive_above = $client_consented_to_twentyfive_above->where('tbl_partner_facility.sub_county_id', $selected_subcounties); + $client_consented_uknown_age = $client_consented_uknown_age->where('tbl_partner_facility.sub_county_id', $selected_subcounties); + $client_nonconsented_to_nine = $client_nonconsented_to_nine->where('tbl_partner_facility.sub_county_id', $selected_subcounties); + $client_nonconsented_to_fourteen = $client_nonconsented_to_fourteen->where('tbl_partner_facility.sub_county_id', $selected_subcounties); + $client_nonconsented_to_nineteen = $client_nonconsented_to_nineteen->where('tbl_partner_facility.sub_county_id', $selected_subcounties); + $client_nonconsented_to_twentyfour = $client_nonconsented_to_twentyfour->where('tbl_partner_facility.sub_county_id', $selected_subcounties); + $client_nonconsented_to_twentyfive_above = $client_nonconsented_to_twentyfive_above->where('tbl_partner_facility.sub_county_id', $selected_subcounties); + $client_nonconsented_uknown_age = $client_nonconsented_to_twentyfive_aboclient_nonconsented_uknown_ageve->where('tbl_partner_facility.sub_county_id', $selected_subcounties); + } + if (!empty($selected_facilites)) { + $client = $client->where('tbl_partner_facility.mfl_code', $selected_facilites); + $appointment = $appointment->where('tbl_partner_facility.mfl_code', $selected_facilites); + $missed_appointment = $missed_appointment->where('tbl_partner_facility.mfl_code', $selected_facilites); + $active_facilities = $active_facilities->where('tbl_partner_facility.mfl_code', $selected_facilites); + $clients_male = $clients_male->where('tbl_partner_facility.mfl_code', $selected_facilites); + $clients_female = $clients_female->where('tbl_partner_facility.mfl_code', $selected_facilites); + $unknown_gender = $unknown_gender->where('tbl_partner_facility.mfl_code', $selected_facilites); + $client_to_nine = $client_to_nine->where('tbl_partner_facility.mfl_code', $selected_facilites); + $client_to_fourteen = $client_to_fourteen->where('tbl_partner_facility.mfl_code', $selected_facilites); + $client_to_nineteen = $client_to_nineteen->where('tbl_partner_facility.mfl_code', $selected_facilites); + $client_to_twentyfour = $client_to_twentyfour->where('tbl_partner_facility.mfl_code', $selected_facilites); + $client_to_twentyfive_above = $client_to_twentyfive_above->where('tbl_partner_facility.mfl_code', $selected_facilites); + $client_unknown_age = $client_unknown_age->where('tbl_partner_facility.mfl_code', $selected_facilites); + $appointment_male = $appointment_male->where('tbl_partner_facility.mfl_code', $selected_facilites); + $appointment_female = $appointment_female->where('tbl_partner_facility.mfl_code', $selected_facilites); + $appointment_uknown_gender = $appointment_uknown_gender->where('tbl_partner_facility.mfl_code', $selected_facilites); + $appointment_to_nine = $appointment_to_nine->where('tbl_partner_facility.mfl_code', $selected_facilites); + $appointment_to_fourteen = $appointment_to_fourteen->where('tbl_partner_facility.mfl_code', $selected_facilites); + $appointment_to_nineteen = $appointment_to_nineteen->where('tbl_partner_facility.mfl_code', $selected_facilites); + $appointment_to_twentyfour = $appointment_to_twentyfour->where('tbl_partner_facility.mfl_code', $selected_facilites); + $appointment_to_twentyfive_above = $appointment_to_twentyfive_above->where('tbl_partner_facility.mfl_code', $selected_facilites); + $appointment_uknown_age = $appointment_uknown_age->where('tbl_partner_facility.mfl_code', $selected_facilites); + $appointment_total_missed_female = $appointment_total_missed_female->where('tbl_partner_facility.mfl_code', $selected_facilites); + $appointment_total_missed_male = $appointment_total_missed_male->where('tbl_partner_facility.mfl_code', $selected_facilites); + $appointment_total_missed_uknown_gender = $appointment_total_missed_uknown_gender->where('tbl_partner_facility.mfl_code', $selected_facilites); + $appointment_total_missed_to_nine = $appointment_total_missed_to_nine->where('tbl_partner_facility.mfl_code', $selected_facilites); + $appointment_total_missed_to_fourteen = $appointment_total_missed_to_fourteen->where('tbl_partner_facility.mfl_code', $selected_facilites); + $appointment_total_missed_to_nineteen = $appointment_total_missed_to_nineteen->where('tbl_partner_facility.mfl_code', $selected_facilites); + $appointment_total_missed_to_twentyfour = $appointment_total_missed_to_twentyfour->where('tbl_partner_facility.mfl_code', $selected_facilites); + $appointment_total_missed_to_twentyfive_above = $appointment_total_missed_to_twentyfive_above->where('tbl_partner_facility.mfl_code', $selected_facilites); + $appointment_total_missed_uknown_age = $appointment_total_missed_uknown_age->where('tbl_partner_facility.mfl_code', $selected_facilites); + + $client_consented = $client_consented->where('tbl_partner_facility.mfl_code', $selected_facilites); + $client_nonconsented = $client_nonconsented->where('tbl_partner_facility.mfl_code', $selected_facilites); + $client_consented_male = $client_consented_male->where('tbl_partner_facility.mfl_code', $selected_facilites); + $client_consented_female = $client_consented_female->where('tbl_partner_facility.mfl_code', $selected_facilites); + $client_consented_uknown_gender = $client_consented_uknown_gender->where('tbl_partner_facility.mfl_code', $selected_facilites); + $client_nonconsented_male = $client_nonconsented_male->where('tbl_partner_facility.mfl_code', $selected_facilites); + $client_nonconsented_female = $client_nonconsented_female->where('tbl_partner_facility.mfl_code', $selected_facilites); + $client_nonconsented_uknown_gender = $client_nonconsented_uknown_gender->where('tbl_partner_facility.mfl_code', $selected_facilites); + $client_consented_to_nine = $client_consented_to_nine->where('tbl_partner_facility.mfl_code', $selected_facilites); + $client_consented_to_fourteen = $client_consented_to_fourteen->where('tbl_partner_facility.mfl_code', $selected_facilites); + $client_consented_to_nineteen = $client_consented_to_nineteen->where('tbl_partner_facility.mfl_code', $selected_facilites); + $client_consented_to_twentyfour = $client_consented_to_twentyfour->where('tbl_partner_facility.mfl_code', $selected_facilites); + $client_consented_to_twentyfive_above = $client_consented_to_twentyfive_above->where('tbl_partner_facility.mfl_code', $selected_facilites); + $client_consented_uknown_age = $client_consented_uknown_age->where('tbl_partner_facility.mfl_code', $selected_facilites); + $client_nonconsented_to_nine = $client_nonconsented_to_nine->where('tbl_partner_facility.mfl_code', $selected_facilites); + $client_nonconsented_to_fourteen = $client_nonconsented_to_fourteen->where('tbl_partner_facility.mfl_code', $selected_facilites); + $client_nonconsented_to_nineteen = $client_nonconsented_to_nineteen->where('tbl_partner_facility.mfl_code', $selected_facilites); + $client_nonconsented_to_twentyfour = $client_nonconsented_to_twentyfour->where('tbl_partner_facility.mfl_code', $selected_facilites); + $client_nonconsented_to_twentyfive_above = $client_nonconsented_to_twentyfive_above->where('tbl_partner_facility.mfl_code', $selected_facilites); + $client_nonconsented_uknown_age = $client_nonconsented_to_twentyfive_aboclient_nonconsented_uknown_ageve->where('tbl_partner_facility.mfl_code', $selected_facilites); + } + $data["client"] = $client->count(); + $data["appointment"] = $appointment->count(); + $data["missed_appointment"] = $missed_appointment->count(); + $data["clients_male"] = $clients_male->count(); + $data["clients_female"] = $clients_female->count(); + $data["unknown_gender"] = $unknown_gender->count(); + $data["client_to_nine"] = $client_to_nine->count(); + $data["client_to_fourteen"] = $client_to_fourteen->count(); + $data["client_to_nineteen"] = $client_to_nineteen->count(); + $data["client_to_twentyfour"] = $client_to_twentyfour->count(); + $data["client_to_twentyfive_above"] = $client_to_twentyfive_above->count(); + $data["client_unknown_age"] = $client_unknown_age->count(); + $data["appointment_male"] = $appointment_male->count(); + $data["appointment_female"] = $appointment_female->count(); + $data["appointment_uknown_gender"] = $appointment_uknown_gender->count(); + $data["appointment_to_nine"] = $appointment_to_nine->count(); + $data["appointment_to_fourteen"] = $appointment_to_fourteen->count(); + $data["appointment_to_nineteen"] = $appointment_to_nineteen->count(); + $data["appointment_to_twentyfour"] = $appointment_to_twentyfour->count(); + $data["appointment_to_twentyfive_above"] = $appointment_to_twentyfive_above->count(); + $data["appointment_uknown_age"] = $appointment_uknown_age->count(); + $data["appointment_total_missed_female"] = $appointment_total_missed_female->count(); + $data["appointment_total_missed_male"] = $appointment_total_missed_male->count(); + $data["appointment_total_missed_uknown_gender"] = $appointment_total_missed_uknown_gender->count(); + $data["appointment_total_missed_to_nine"] = $appointment_total_missed_to_nine->count(); + $data["appointment_total_missed_to_fourteen"] = $appointment_total_missed_to_fourteen->count(); + $data["appointment_total_missed_to_nineteen"] = $appointment_total_missed_to_nineteen->count(); + $data["appointment_total_missed_to_twentyfour"] = $appointment_total_missed_to_twentyfour->count(); + $data["appointment_total_missed_to_twentyfive_above"] = $appointment_total_missed_to_twentyfive_above->count(); + $data["appointment_total_missed_uknown_age"] = $appointment_total_missed_uknown_age->count(); + + $data["client_consented"] = $client_consented->count(); + $data["client_nonconsented"] = $client_nonconsented->count(); + $data["client_consented_male"] = $client_consented_male->count(); + $data["client_consented_female"] = $client_consented_female->count(); + $data["client_consented_uknown_gender"] = $client_consented_uknown_gender->count(); + $data["client_nonconsented_male"] = $client_nonconsented_male->count(); + $data["client_nonconsented_female"] = $client_nonconsented_female->count(); + $data["client_nonconsented_uknown_gender"] = $client_nonconsented_uknown_gender->count(); + $data["client_consented_to_nine"] = $client_consented_to_nine->count(); + $data["client_consented_to_fourteen"] = $client_consented_to_fourteen->count(); + $data["client_consented_to_nineteen"] = $client_consented_to_nineteen->count(); + $data["client_consented_to_twentyfour"] = $client_consented_to_twentyfour->count(); + $data["client_consented_to_twentyfive_above"] = $client_consented_to_twentyfive_above->count(); + $data["client_consented_uknown_age"] = $client_consented_uknown_age->count(); + $data["client_nonconsented_to_nine"] = $client_nonconsented_to_nine->count(); + $data["client_nonconsented_to_fourteen"] = $client_nonconsented_to_fourteen->count(); + $data["client_nonconsented_to_nineteen"] = $client_nonconsented_to_nineteen->count(); + $data["client_nonconsented_to_twentyfour"] = $client_nonconsented_to_twentyfour->count(); + $data["client_nonconsented_to_twentyfive_above"] = $client_nonconsented_to_twentyfive_above->count(); + $data["client_nonconsented_uknown_age"] = $client_nonconsented_uknown_age->count(); if (Auth::user()->access_level == 'Admin' || Auth::user()->access_level == 'Donor') { @@ -1961,112 +3623,7 @@ public function filter_charts(Request $request) ->where('tbl_appointment.created_at', '>=', date($request->from))->where('tbl_appointment.created_at', '<=', date($request->to)) ->count(); } - return view('new_dashboard.main_dashbaord', compact( - 'all_partners', - 'active_facilities', - 'indicator', - 'client', - 'appointment', - 'missed_appointment', - 'clients_male', - 'clients_female', - 'unknown_gender', - 'client_to_nine', - 'client_to_fourteen', - 'client_to_nineteen', - 'client_to_twentyfour', - 'client_to_twentyfive_above', - 'client_unknown_age', - 'appointment_male', - 'appointment_female', - 'appointment_uknown_gender', - 'appointment_to_nine', - 'appointment_to_fourteen', - 'appointment_to_nineteen', - 'appointment_to_twentyfour', - 'appointment_to_twentyfive_above', - 'appointment_uknown_age', - 'appointment_total_missed_female', - 'appointment_total_missed_male', - 'appointment_total_missed_uknown_gender', - 'appointment_total_missed_to_nine', - 'appointment_total_missed_to_fourteen', - 'appointment_total_missed_to_nineteen', - 'appointment_total_missed_to_twentyfour', - 'appointment_total_missed_to_twentyfive_above', - 'appointment_total_missed_uknown_age', - 'client_consented', - 'client_nonconsented', - 'client_consented_male', - 'client_consented_female', - 'client_consented_uknown_gender', - 'client_nonconsented_male', - 'client_nonconsented_female', - 'client_nonconsented_uknown_gender', - 'client_consented_to_nine', - 'client_consented_to_fourteen', - 'client_consented_to_nineteen', - 'client_consented_to_twentyfour', - 'client_consented_to_twentyfive_above', - 'client_consented_uknown_age', - 'client_nonconsented_to_nine', - 'client_nonconsented_to_fourteen', - 'client_nonconsented_to_nineteen', - 'client_nonconsented_to_twentyfour', - 'client_nonconsented_to_twentyfive_above', - 'client_nonconsented_uknown_age', - 'appointment_honoured', - 'appointment_not_honoured', - 'appointment_honoured_male', - 'appointment_honoured_female', - 'appointment_honoured_uknown_gender', - 'appointment_honored_to_nine', - 'appointment_honored_to_fourteen', - 'appointment_honored_to_nineteen', - 'appointment_honored_to_twentyfour', - 'appointment_honored_to_twentyfive_above', - 'appointment_honored_to_uknown_age', - 'appointment_not_honoured_male', - 'appointment_not_honoured_female', - 'appointment_not_honoured_uknown_gender', - 'appointment_not_honored_to_nine', - 'appointment_not_honored_to_fourteen', - 'appointment_not_honored_to_nineteen', - 'appointment_not_honored_to_twentyfour', - 'appointment_not_honored_to_twentyfive_above', - 'appointment_not_honored_to_uknown_age', - 'appointment_missed', - 'appointment_defaulted', - 'appointment_lftu', - 'appointment_missed_female', - 'appointment_missed_male', - 'appointment_missed_uknown_gender', - 'appointment_missed_to_nine', - 'appointment_missed_to_fourteen', - 'appointment_missed_to_nineteen', - 'appointment_missed_to_twentyfour', - 'appointment_missed_to_twentyfive_above', - 'appointment_missed_to_uknown_age', - 'appointment_defaulted_female', - 'appointment_defaulted_male', - 'appointment_defaulted_uknown_gender', - 'appointment_defaulted_to_nine', - 'appointment_defaulted_to_fourteen', - 'appointment_defaulted_to_nineteen', - 'appointment_defaulted_to_twentyfour', - 'appointment_defaulted_to_twentyfive_above', - 'appointment_defaulted_to_uknown_age', - 'appointment_ltfu_female', - 'appointment_ltfu_male', - 'appointment_ltfu_uknown_gender', - 'appointment_ltfu_to_nine', - 'appointment_ltfu_to_fourteen', - 'appointment_ltfu_to_nineteen', - 'appointment_ltfu_to_twentyfour', - 'appointment_ltfu_to_twentyfive_above', - 'appointment_ltfu_to_uknown_age' - - )); + return view('new_dashboard.main_dashbaord', compact('data')); } diff --git a/app/Models/Appointments.php b/app/Models/Appointments.php index 2607c10..d688f06 100644 --- a/app/Models/Appointments.php +++ b/app/Models/Appointments.php @@ -13,7 +13,7 @@ class Appointments extends Model public $incrementing = false; protected $fillable = [ - 'app_type_1', 'reason', 'appntmnt_date', 'date_attended' + 'client_id', 'app_type_1', 'reason', 'appntmnt_date', 'date_attended' ]; diff --git a/app/Models/Client.php b/app/Models/Client.php index b72e7f2..5e3a1d2 100644 --- a/app/Models/Client.php +++ b/app/Models/Client.php @@ -22,6 +22,10 @@ class Client extends Model // { // return Carbon::parse($this->attributes['dob'])->age; // } + public function appointments() + { + return $this->hasMany(Appointments::class); + } } diff --git a/config/app.php b/config/app.php index 608bad4..b797cff 100644 --- a/config/app.php +++ b/config/app.php @@ -175,7 +175,7 @@ App\Providers\EventServiceProvider::class, App\Providers\RouteServiceProvider::class, Maatwebsite\Excel\ExcelServiceProvider::class, - // Barryvdh\Debugbar\ServiceProvider::class, + Barryvdh\Debugbar\ServiceProvider::class, // MaddHatter\LaravelFullcalendar\ServiceProvider::class, diff --git a/resources/views/new_dashboard/appointment_dashboard.blade.php b/resources/views/new_dashboard/appointment_dashboard.blade.php index 5f89b79..b28af7f 100644 --- a/resources/views/new_dashboard/appointment_dashboard.blade.php +++ b/resources/views/new_dashboard/appointment_dashboard.blade.php @@ -477,7 +477,7 @@ type: 'column' }, title: { - text: 'Appointment Honoured By Gender' + text: 'Appointment Honored By Gender' }, xAxis: { categories: ['Male', 'Female', 'UKNOWN Gender'] @@ -485,7 +485,7 @@ yAxis: { min: 0, title: { - text: 'No of Appointment Honoured' + text: 'No of Appointment Honored' }, stackLabels: { enabled: true, @@ -521,7 +521,7 @@ type: 'column' }, title: { - text: 'Appointment Honoured By Age' + text: 'Appointment Honored By Age' }, xAxis: { categories: ['0-9 YRS', '10-14 YRS', '15-19 YRS', '20-24 YRS', '25+ YRS', 'UKNOWN AGE'] @@ -529,7 +529,7 @@ yAxis: { min: 0, title: { - text: 'No of Appointment Honoured' + text: 'No of Appointment Honored' }, stackLabels: { enabled: true, @@ -566,7 +566,7 @@ type: 'column' }, title: { - text: 'Appointment Not Honoured By Gender' + text: 'Appointment Not Honored By Gender' }, xAxis: { categories: ['Male', 'Female', 'UKNOWN Gender'] @@ -574,7 +574,7 @@ yAxis: { min: 0, title: { - text: 'No of Appointment Not Honoured' + text: 'No of Appointment Not Honored' }, stackLabels: { enabled: true, @@ -610,7 +610,7 @@ type: 'column' }, title: { - text: 'Appointment Not Honoured By Age' + text: 'Appointment Not Honored By Age' }, xAxis: { categories: ['0-9 YRS', '10-14 YRS', '15-19 YRS', '20-24 YRS', '25+ YRS', 'UKNOWN AGE'] @@ -618,7 +618,7 @@ yAxis: { min: 0, title: { - text: 'No of Appointment Not Honoured' + text: 'No of Appointment Not Honored' }, stackLabels: { enabled: true, diff --git a/resources/views/new_dashboard/main_dashbaord.blade.php b/resources/views/new_dashboard/main_dashbaord.blade.php index 0a2a749..785414a 100644 --- a/resources/views/new_dashboard/main_dashbaord.blade.php +++ b/resources/views/new_dashboard/main_dashbaord.blade.php @@ -129,26 +129,25 @@
- + @if (Auth::user()->access_level == 'Admin' || Auth::user()->access_level == 'Partner' || Auth::user()->access_level == 'Donor')

Facilities

-

{{count($active_facilities)}}

+

{{count($active_facilities)}}

-

Clients

-

{{$client}}

+

{{$client}}

@@ -160,7 +159,7 @@

Appointments

-

{{$appointment}}

+

{{$appointment}}

@@ -172,13 +171,49 @@

Missed Appointments

-

{{$missed_appointment}}

+

{{$missed_appointment}}

+
+
+
+
+ @endif + @if (Auth::user()->access_level == 'Facility') +
+
+
+
+

Clients

+ +

{{$client}}

+
+
+
+
+ +
+
+
+
+

Appointments

+ +

{{$appointment}}

+
+
+
+
+

Missed Appointments

+

{{$missed_appointment}}

+
+
+
+
+ @endif
@@ -237,7 +272,7 @@

Clients

-

{{$client}}

+

{{$client}}

@@ -249,7 +284,7 @@

Consented

-

{{$client_consented}}

+

{{$client_consented}}

@@ -261,7 +296,7 @@

Non Consented

-

{{$client_nonconsented}}

+

{{$client_nonconsented}}

@@ -477,7 +512,69 @@ }, url: "{{ route('filter_appointment_dashboard') }}", success: function(data) { - + $("#client").html(data.client); + $("#appointment").html(data.appointment); + $("#missed_appointment").html(data.missed_appointment); + Clients_male = parseInt(data.clients_male) + Clients_female = parseInt(data.clients_female) + Unknown_gender = parseInt(data.unknown_gender) + Client_to_nine = parseInt(data.client_to_nine) + Client_to_fourteen = parseInt(data.client_to_fourteen) + Client_to_nineteen = parseInt(data.client_to_nineteen) + Client_to_twentyfour = parseInt(data.client_to_twentyfour) + Client_to_twentyfive_above = parseInt(data.client_to_twentyfive_above) + Client_unknown_age = parseInt(data.client_unknown_age) + Appointment_male = parseInt(data.appointment_male) + Appointment_female = parseInt(data.appointment_female) + Appointment_uknown_gender = parseInt(data.appointment_uknown_gender) + Appointment_to_nine = parseInt(data.appointment_to_nine) + Appointment_to_fourteen = parseInt(data.appointment_to_fourteen) + Appointment_to_nineteen = parseInt(data.appointment_to_nineteen) + Appointment_to_twentyfour = parseInt(data.appointment_to_twentyfour) + Appointment_to_twentyfive_above = parseInt(data.appointment_to_twentyfive_above) + Appointment_uknown_age = parseInt(data.appointment_uknown_age) + Appointment_total_missed_female = parseInt(data.appointment_total_missed_female) + Appointment_total_missed_male = parseInt(data.appointment_total_missed_male) + Appointment_total_missed_uknown_gender = parseInt(data.appointment_total_missed_uknown_gender) + Appointment_total_missed_to_nine = parseInt(data.appointment_total_missed_to_nine) + Appointment_total_missed_to_fourteen = parseInt(data.appointment_total_missed_to_fourteen) + Appointment_total_missed_to_nineteen = parseInt(data.appointment_total_missed_to_nineteen) + Appointment_total_missed_to_twentyfour = parseInt(data.appointment_total_missed_to_twentyfour) + Appointment_total_missed_to_twentyfive_above = parseInt(data.appointment_total_missed_to_twentyfive_above) + Appointment_total_missed_uknown_age = parseInt(data.appointment_total_missed_uknown_age) + + + $("#client_consented").html(data.client_consented); + $("#client_nonconsented").html(data.client_nonconsented); + Client_consented_male = parseInt(data.client_consented_male) + Client_consented_female = parseInt(data.client_consented_female) + Client_consented_uknown_gender = parseInt(data.client_consented_uknown_gender) + Client_nonconsented_male = parseInt(data.client_nonconsented_male) + Client_nonconsented_female = parseInt(data.client_nonconsented_female) + Client_nonconsented_uknown_gender = parseInt(data.client_nonconsented_uknown_gender) + Client_consented_to_nine = parseInt(data.client_consented_to_nine) + Client_consented_to_fourteen = parseInt(data.client_consented_to_fourteen) + Client_consented_to_nineteen = parseInt(data.client_consented_to_nineteen) + Client_consented_to_twentyfour = parseInt(data.client_consented_to_twentyfour) + Client_consented_to_twentyfive_above = parseInt(data.client_consented_to_twentyfive_above) + Client_consented_uknown_age = parseInt(data.client_consented_uknown_age) + Client_nonconsented_to_nine = parseInt(data.client_nonconsented_to_nine) + Client_nonconsented_to_fourteen = parseInt(data.client_nonconsented_to_fourteen) + Client_nonconsented_to_nineteen = parseInt(data.client_nonconsented_to_nineteen) + Client_nonconsented_to_twentyfour = parseInt(data.client_nonconsented_to_twentyfour) + Client_nonconsented_to_twentyfive_above = parseInt(data.client_nonconsented_to_twentyfive_above) + Client_nonconsented_uknown_age = parseInt(data.client_nonconsented_uknown_age) + + clientGender.series[0].setData([Clients_male, Clients_female, Unknown_gender]); + clientAge.series[0].setData([Client_to_nine, Client_to_fourteen, Client_to_nineteen, Client_to_twentyfour, Client_to_twentyfive_above, Client_unknown_age]); + appointmentGender.series[0].setData([Appointment_male, Appointment_female, Appointment_uknown_gender]); + appointmentAge.series[0].setData([Appointment_to_nine, Appointment_to_fourteen, Appointment_to_nineteen, Appointment_to_twentyfour, Appointment_to_twentyfive_above, Appointment_uknown_age]); + totalmissedappointmentGender.series[0].setData([Appointment_total_missed_male, Appointment_total_missed_female, Appointment_total_missed_uknown_gender]); + totalmissedappointmentAge.series[0].setData([Appointment_total_missed_to_nine, Appointment_total_missed_to_fourteen, Appointment_total_missed_to_nineteen, Appointment_total_missed_to_twentyfour, Appointment_total_missed_to_twentyfive_above, Appointment_total_missed_uknown_age]); + consentedGender.series[0].setData([Client_consented_male, Client_consented_female, Client_consented_uknown_gender]); + consentedAge.series[0].setData([Client_consented_to_nine, Client_consented_to_fourteen, Client_consented_to_nineteen, Client_consented_to_twentyfour, Client_consented_to_twentyfive_above, Client_consented_uknown_age]); + nonconsentedGender.series[0].setData([Client_nonconsented_male, Client_nonconsented_female, Client_nonconsented_uknown_gender]); + nonconsentedAge.series[0].setData([Client_nonconsented_to_nine, Client_nonconsented_to_fourteen, Client_nonconsented_to_nineteen, Client_nonconsented_to_twentyfour, Client_nonconsented_to_twentyfive_above, Client_nonconsented_uknown_age]); } }); @@ -485,7 +582,7 @@ - var appChart = Highcharts.chart('client_gender', { + var clientGender = Highcharts.chart('client_gender', { chart: { type: 'column' }, @@ -529,7 +626,7 @@ }); - var appChart = Highcharts.chart('client_age', { + var clientAge = Highcharts.chart('client_age', { chart: { type: 'column' }, @@ -573,7 +670,7 @@ }); - var appChart = Highcharts.chart('appointment_gender', { + var appointmentGender = Highcharts.chart('appointment_gender', { chart: { type: 'column' }, @@ -617,7 +714,7 @@ }); - var appChart = Highcharts.chart('appointment_age', { + var appointmentAge = Highcharts.chart('appointment_age', { chart: { type: 'column' }, @@ -662,7 +759,7 @@ }); // missed appointment charts - var appChart = Highcharts.chart('total_missed_appointment_gender', { + var totalmissedappointmentGender = Highcharts.chart('total_missed_appointment_gender', { chart: { type: 'column' }, @@ -706,7 +803,7 @@ }); - var appChart = Highcharts.chart('total_missed_appointment_age', { + var totalmissedappointmentAge = Highcharts.chart('total_missed_appointment_age', { chart: { type: 'column' }, @@ -751,7 +848,7 @@ }); // CONSENTED CLIENTS GENDER - var appChart = Highcharts.chart('consented_gender', { + var consentedGender = Highcharts.chart('consented_gender', { chart: { type: 'column' }, @@ -795,7 +892,7 @@ }); // CONSENTED CLIENTS AGE - var appChart = Highcharts.chart('consented_age', { + var consentedAge = Highcharts.chart('consented_age', { chart: { type: 'column' }, @@ -840,7 +937,7 @@ }); //NON CONSENTED CLIENTS GENDER - var appChart = Highcharts.chart('nonconsented_gender', { + var nonconsentedGender = Highcharts.chart('nonconsented_gender', { chart: { type: 'column' }, @@ -884,7 +981,7 @@ }); // NON CONSENTED AGE - var appChart = Highcharts.chart('nonconsented_age', { + var nonconsentedAge = Highcharts.chart('nonconsented_age', { chart: { type: 'column' }, From b96ddf1a49e54403238ed53f86f231ffe5c8ea7a Mon Sep 17 00:00:00 2001 From: Ronald-pro <36841157+Ronald-pro@users.noreply.github.com> Date: Tue, 3 May 2022 08:34:25 +0300 Subject: [PATCH 029/171] update readme --- README.md | 65 +++++++------------------------------------------------ 1 file changed, 8 insertions(+), 57 deletions(-) diff --git a/README.md b/README.md index f3decb1..f7cc723 100644 --- a/README.md +++ b/README.md @@ -1,61 +1,12 @@ -

+Clone the repository -

-Build Status -Total Downloads -Latest Stable Version -License -

+git clone https://github.com/palladiumkenya/ushauri_dashboard +Switch to the repo folder -## About Laravel +cd ushauri_dashboard +Install all the dependencies using composer -Laravel is a web application framework with expressive, elegant syntax. We believe development must be an enjoyable and creative experience to be truly fulfilling. Laravel takes the pain out of development by easing common tasks used in many web projects, such as: +composer install +Copy the example env file and make the required configuration changes in the .env file -- [Simple, fast routing engine](https://laravel.com/docs/routing). -- [Powerful dependency injection container](https://laravel.com/docs/container). -- Multiple back-ends for [session](https://laravel.com/docs/session) and [cache](https://laravel.com/docs/cache) storage. -- Expressive, intuitive [database ORM](https://laravel.com/docs/eloquent). -- Database agnostic [schema migrations](https://laravel.com/docs/migrations). -- [Robust background job processing](https://laravel.com/docs/queues). -- [Real-time event broadcasting](https://laravel.com/docs/broadcasting). - -Laravel is accessible, powerful, and provides tools required for large, robust applications. - -## Learning Laravel - -Laravel has the most extensive and thorough [documentation](https://laravel.com/docs) and video tutorial library of all modern web application frameworks, making it a breeze to get started with the framework. - -If you don't feel like reading, [Laracasts](https://laracasts.com) can help. Laracasts contains over 1500 video tutorials on a range of topics including Laravel, modern PHP, unit testing, and JavaScript. Boost your skills by digging into our comprehensive video library. - -## Laravel Sponsors - -We would like to extend our thanks to the following sponsors for funding Laravel development. If you are interested in becoming a sponsor, please visit the Laravel [Patreon page](https://patreon.com/taylorotwell). - -### Premium Partners - -- **[Vehikl](https://vehikl.com/)** -- **[Tighten Co.](https://tighten.co)** -- **[Kirschbaum Development Group](https://kirschbaumdevelopment.com)** -- **[64 Robots](https://64robots.com)** -- **[Cubet Techno Labs](https://cubettech.com)** -- **[Cyber-Duck](https://cyber-duck.co.uk)** -- **[Many](https://www.many.co.uk)** -- **[Webdock, Fast VPS Hosting](https://www.webdock.io/en)** -- **[DevSquad](https://devsquad.com)** -- **[OP.GG](https://op.gg)** - -## Contributing - -Thank you for considering contributing to the Laravel framework! The contribution guide can be found in the [Laravel documentation](https://laravel.com/docs/contributions). - -## Code of Conduct - -In order to ensure that the Laravel community is welcoming to all, please review and abide by the [Code of Conduct](https://laravel.com/docs/contributions#code-of-conduct). - -## Security Vulnerabilities - -If you discover a security vulnerability within Laravel, please send an e-mail to Taylor Otwell via [taylor@laravel.com](mailto:taylor@laravel.com). All security vulnerabilities will be promptly addressed. - -## License - -The Laravel framework is open-sourced software licensed under the [MIT license](https://opensource.org/licenses/MIT). +cp .env.example .env From 2a29e6c9de96e2c02c18b6867c2c7e6cea7f1725 Mon Sep 17 00:00:00 2001 From: andrinem Date: Tue, 3 May 2022 16:30:24 +0300 Subject: [PATCH 030/171] setup cicd github workflow --- .github/workflows/cicd_process.yml | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 .github/workflows/cicd_process.yml diff --git a/.github/workflows/cicd_process.yml b/.github/workflows/cicd_process.yml new file mode 100644 index 0000000..1106a7f --- /dev/null +++ b/.github/workflows/cicd_process.yml @@ -0,0 +1,24 @@ +name: deploy to test instance +on: + push: + branches: [ cicd ] +jobs: + + build: + name: Deploy + runs-on: ubuntu-latest + steps: + - name: executing remote connection + uses: appleboy/ssh-action@master + with: + host: ${{ secrets.HOST }} + username: ${{ secrets.USERNAME }} + key: ${{ secrets.CICD_SECRET }} + port: ${{ secrets.PORT }} + script: | + git config --global --add safe.directory /apps/github-workflows/mhealth-apps/ushauri_dashboard/ + cd /apps/github-workflows/mhealth-apps/ushauri_dashboard/ + git pull origin main + git status + cp /apps/configs/ushauri-dashboard/.env /apps/github-workflows/mhealth-apps/ushauri_dashboard/ + composer install From 6d61d84db5d3940d66c17780d02df385f7a60751 Mon Sep 17 00:00:00 2001 From: andrinem Date: Tue, 3 May 2022 16:33:19 +0300 Subject: [PATCH 031/171] setup cicd github workflow --- .github/workflows/cicd_process.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/cicd_process.yml b/.github/workflows/cicd_process.yml index 1106a7f..41f51d8 100644 --- a/.github/workflows/cicd_process.yml +++ b/.github/workflows/cicd_process.yml @@ -21,4 +21,4 @@ jobs: git pull origin main git status cp /apps/configs/ushauri-dashboard/.env /apps/github-workflows/mhealth-apps/ushauri_dashboard/ - composer install + composer update From 5987e67543a63fc6a490db765f82a452c2295e74 Mon Sep 17 00:00:00 2001 From: andrinem Date: Tue, 3 May 2022 16:42:48 +0300 Subject: [PATCH 032/171] setup cicd github workflow --- .github/workflows/cicd_process.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/cicd_process.yml b/.github/workflows/cicd_process.yml index 41f51d8..1106a7f 100644 --- a/.github/workflows/cicd_process.yml +++ b/.github/workflows/cicd_process.yml @@ -21,4 +21,4 @@ jobs: git pull origin main git status cp /apps/configs/ushauri-dashboard/.env /apps/github-workflows/mhealth-apps/ushauri_dashboard/ - composer update + composer install From a8961c769158292b858f8e713228a5fd1dea5c78 Mon Sep 17 00:00:00 2001 From: andrinem Date: Wed, 4 May 2022 07:23:25 +0300 Subject: [PATCH 033/171] setup cicd github workflow --- .github/workflows/cicd_process.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/cicd_process.yml b/.github/workflows/cicd_process.yml index 1106a7f..66af4f1 100644 --- a/.github/workflows/cicd_process.yml +++ b/.github/workflows/cicd_process.yml @@ -21,4 +21,4 @@ jobs: git pull origin main git status cp /apps/configs/ushauri-dashboard/.env /apps/github-workflows/mhealth-apps/ushauri_dashboard/ - composer install + composer install --ignore-platform-reqs From 4c03987c38bd5f4942f8f2cab5b79c2f3efab7b5 Mon Sep 17 00:00:00 2001 From: andrinem Date: Wed, 4 May 2022 10:39:50 +0300 Subject: [PATCH 034/171] setup cicd github workflow --- .github/workflows/cicd_process.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/cicd_process.yml b/.github/workflows/cicd_process.yml index 66af4f1..4d62460 100644 --- a/.github/workflows/cicd_process.yml +++ b/.github/workflows/cicd_process.yml @@ -22,3 +22,4 @@ jobs: git status cp /apps/configs/ushauri-dashboard/.env /apps/github-workflows/mhealth-apps/ushauri_dashboard/ composer install --ignore-platform-reqs + php artisan serve From a8cd03862122d4786b6bd5626ea79c8cf7383d5d Mon Sep 17 00:00:00 2001 From: andrinem Date: Wed, 4 May 2022 11:36:35 +0300 Subject: [PATCH 035/171] Include option to server instance with nginx --- .github/workflows/cicd_process.yml | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/.github/workflows/cicd_process.yml b/.github/workflows/cicd_process.yml index 4d62460..76161fd 100644 --- a/.github/workflows/cicd_process.yml +++ b/.github/workflows/cicd_process.yml @@ -21,5 +21,8 @@ jobs: git pull origin main git status cp /apps/configs/ushauri-dashboard/.env /apps/github-workflows/mhealth-apps/ushauri_dashboard/ - composer install --ignore-platform-reqs - php artisan serve + cp /apps/configs/ushauri-dashboard/docker-compose.yml /apps/github-workflows/mhealth-apps/ushauri_dashboard/ + cp /apps/configs/ushauri-dashboard/nginx.dockerfile /apps/github-workflows/mhealth-apps/ushauri_dashboard/ + cp /apps/configs/ushauri-dashboard/php.dockerfile /apps/github-workflows/mhealth-apps/ushauri_dashboard/ + cp -r /apps/configs/ushauri-dashboard/docker /apps/github-workflows/mhealth-apps/ushauri_dashboard/ + docker-compose up -d From e4a8bf64bc07da040ed4c5878d44898115ee3cce Mon Sep 17 00:00:00 2001 From: andrinem Date: Wed, 4 May 2022 12:03:01 +0300 Subject: [PATCH 036/171] Include option to server instance with nginx --- .github/workflows/cicd_process.yml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.github/workflows/cicd_process.yml b/.github/workflows/cicd_process.yml index 76161fd..f55a971 100644 --- a/.github/workflows/cicd_process.yml +++ b/.github/workflows/cicd_process.yml @@ -25,4 +25,6 @@ jobs: cp /apps/configs/ushauri-dashboard/nginx.dockerfile /apps/github-workflows/mhealth-apps/ushauri_dashboard/ cp /apps/configs/ushauri-dashboard/php.dockerfile /apps/github-workflows/mhealth-apps/ushauri_dashboard/ cp -r /apps/configs/ushauri-dashboard/docker /apps/github-workflows/mhealth-apps/ushauri_dashboard/ - docker-compose up -d + docker-compose down + docker-compose rm -f + docker-compose up --build -d From 761466d9d8a797ca0a570f77db8d121b3ac47e2c Mon Sep 17 00:00:00 2001 From: andrinem Date: Wed, 4 May 2022 13:24:53 +0300 Subject: [PATCH 037/171] Include option to server instance with nginx --- .github/workflows/cicd_process.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/cicd_process.yml b/.github/workflows/cicd_process.yml index f55a971..d99cbc3 100644 --- a/.github/workflows/cicd_process.yml +++ b/.github/workflows/cicd_process.yml @@ -24,7 +24,7 @@ jobs: cp /apps/configs/ushauri-dashboard/docker-compose.yml /apps/github-workflows/mhealth-apps/ushauri_dashboard/ cp /apps/configs/ushauri-dashboard/nginx.dockerfile /apps/github-workflows/mhealth-apps/ushauri_dashboard/ cp /apps/configs/ushauri-dashboard/php.dockerfile /apps/github-workflows/mhealth-apps/ushauri_dashboard/ - cp -r /apps/configs/ushauri-dashboard/docker /apps/github-workflows/mhealth-apps/ushauri_dashboard/ + cp -r /apps/configs/ushauri-dashboard/nginx /apps/github-workflows/mhealth-apps/ushauri_dashboard/ docker-compose down docker-compose rm -f - docker-compose up --build -d + docker-compose --env-file .env up -d --build site From 42f110e9f66e19761016f53e293784c02513d003 Mon Sep 17 00:00:00 2001 From: kevlanyo Date: Wed, 4 May 2022 14:58:42 +0300 Subject: [PATCH 038/171] Update README.md --- README.md | 63 +++++++++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 59 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index f7cc723..8d6f97d 100644 --- a/README.md +++ b/README.md @@ -1,12 +1,67 @@ +# Getting started + +## Installation + +Please check the official laravel installation guide for server requirements before you start. [Official Documentation](https://laravel.com/docs/8.x/installation) + Clone the repository -git clone https://github.com/palladiumkenya/ushauri_dashboard + git clone https://github.com/palladiumkenya/ushauri_dashboard + Switch to the repo folder + cd ushauri_dashboard -cd ushauri_dashboard Install all the dependencies using composer -composer install + composer install + Copy the example env file and make the required configuration changes in the .env file -cp .env.example .env + cp .env.example .env + +Start the local development server + + php artisan serve + +You can now access the server at http://localhost:8000 + +**TL;DR command list** + + git clone https://github.com/palladiumkenya/ushauri_dashboard + cd ushauri_dashboard + composer install + cp .env.example .env + php artisan serve + + ---------- + +# Code overview + +## Folders + +- `app` - Contains all the Eloquent models +- `app/Http/Controllers/Api` - Contains all the api controllers +- `app/Http/Middleware` - Contains the JWT auth middleware +- `app/Http/Requests/Api` - Contains all the api form requests +- `app/RealWorld/Favorite` - Contains the files implementing the favorite feature +- `app/RealWorld/Filters` - Contains the query filters used for filtering api requests +- `app/RealWorld/Follow` - Contains the files implementing the follow feature +- `app/RealWorld/Paginate` - Contains the pagination class used to paginate the result +- `app/RealWorld/Slug` - Contains the files implementing slugs to articles +- `app/RealWorld/Transformers` - Contains all the data transformers +- `config` - Contains all the application configuration files +- `database/factories` - Contains the model factory for all the models +- `database/migrations` - Contains all the database migrations +- `database/seeds` - Contains the database seeder +- `routes` - Contains all the api routes defined in api.php file +- `tests` - Contains all the application tests +- `tests/Feature/Api` - Contains all the api tests + +## Environment variables + +- `.env` - Environment variables can be set in this file + +***Note*** : You can quickly set the database information and other variables in this file and have the application fully working. + +---------- + From d4dc9ca92bfc1ed5bfee638ceb7e9da1f6f27c51 Mon Sep 17 00:00:00 2001 From: Ronald-pro <36841157+Ronald-pro@users.noreply.github.com> Date: Wed, 4 May 2022 15:06:04 +0300 Subject: [PATCH 039/171] Update Readme --- README.md | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-) diff --git a/README.md b/README.md index 8d6f97d..66a0c3b 100644 --- a/README.md +++ b/README.md @@ -39,23 +39,17 @@ You can now access the server at http://localhost:8000 ## Folders -- `app` - Contains all the Eloquent models -- `app/Http/Controllers/Api` - Contains all the api controllers +- `app/Models` - Contains all the Eloquent models +- `app/Http/Controllers` - Contain all the data controllers +- `app/Http/Controllers/Auth` - Contains all the auth controllers - `app/Http/Middleware` - Contains the JWT auth middleware -- `app/Http/Requests/Api` - Contains all the api form requests -- `app/RealWorld/Favorite` - Contains the files implementing the favorite feature -- `app/RealWorld/Filters` - Contains the query filters used for filtering api requests -- `app/RealWorld/Follow` - Contains the files implementing the follow feature -- `app/RealWorld/Paginate` - Contains the pagination class used to paginate the result -- `app/RealWorld/Slug` - Contains the files implementing slugs to articles -- `app/RealWorld/Transformers` - Contains all the data transformers +- `app/Http/Jobs` - Contains all the jobs handlers - `config` - Contains all the application configuration files - `database/factories` - Contains the model factory for all the models -- `database/migrations` - Contains all the database migrations - `database/seeds` - Contains the database seeder -- `routes` - Contains all the api routes defined in api.php file +- `resources` - Contains all the application views and styling files +- `routes` - Contains all the web routes defined in web.php file - `tests` - Contains all the application tests -- `tests/Feature/Api` - Contains all the api tests ## Environment variables From e1d01dc18f8d15385c11269d0128160faa113061 Mon Sep 17 00:00:00 2001 From: andrinem Date: Wed, 4 May 2022 16:20:14 +0300 Subject: [PATCH 040/171] Include option to server instance with nginx --- .github/workflows/cicd_process.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/cicd_process.yml b/.github/workflows/cicd_process.yml index d99cbc3..1bdad72 100644 --- a/.github/workflows/cicd_process.yml +++ b/.github/workflows/cicd_process.yml @@ -20,6 +20,7 @@ jobs: cd /apps/github-workflows/mhealth-apps/ushauri_dashboard/ git pull origin main git status + composer install --ignore-platform-reqs cp /apps/configs/ushauri-dashboard/.env /apps/github-workflows/mhealth-apps/ushauri_dashboard/ cp /apps/configs/ushauri-dashboard/docker-compose.yml /apps/github-workflows/mhealth-apps/ushauri_dashboard/ cp /apps/configs/ushauri-dashboard/nginx.dockerfile /apps/github-workflows/mhealth-apps/ushauri_dashboard/ From df332d2d7b89c498d02c29a0cfdae5ac83cc0921 Mon Sep 17 00:00:00 2001 From: andrinem Date: Wed, 4 May 2022 21:45:33 +0300 Subject: [PATCH 041/171] Include option to serve instance with nginx on https://prod.kenyahmis.org:8001/ --- .github/workflows/cicd_process.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/cicd_process.yml b/.github/workflows/cicd_process.yml index 1bdad72..c7a2898 100644 --- a/.github/workflows/cicd_process.yml +++ b/.github/workflows/cicd_process.yml @@ -1,7 +1,7 @@ name: deploy to test instance on: push: - branches: [ cicd ] + branches: [ main ] jobs: build: From 8f709fe2a58a50335ebd2e7321da84e4b6c544ce Mon Sep 17 00:00:00 2001 From: andrinem Date: Wed, 4 May 2022 22:03:34 +0300 Subject: [PATCH 042/171] Include option to serve instance with nginx on https://prod.kenyahmis.org:8001/ --- .github/workflows/cicd_process.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/cicd_process.yml b/.github/workflows/cicd_process.yml index c7a2898..fc92431 100644 --- a/.github/workflows/cicd_process.yml +++ b/.github/workflows/cicd_process.yml @@ -29,3 +29,4 @@ jobs: docker-compose down docker-compose rm -f docker-compose --env-file .env up -d --build site + docker-compose exec php php artisan key:generate From 06e97cfdb0dd798bb3b8983a0ed93801fb7125bc Mon Sep 17 00:00:00 2001 From: andrineM <53934661+andrineM@users.noreply.github.com> Date: Wed, 4 May 2022 22:09:45 +0300 Subject: [PATCH 043/171] =?UTF-8?q?Revert=20"Include=20option=20to=20serve?= =?UTF-8?q?=20instance=20with=20nginx=20on=20https://prod.kenyahmis?= =?UTF-8?q?=E2=80=A6"?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/cicd_process.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/workflows/cicd_process.yml b/.github/workflows/cicd_process.yml index fc92431..c7a2898 100644 --- a/.github/workflows/cicd_process.yml +++ b/.github/workflows/cicd_process.yml @@ -29,4 +29,3 @@ jobs: docker-compose down docker-compose rm -f docker-compose --env-file .env up -d --build site - docker-compose exec php php artisan key:generate From 0cefaced04239b572915ccfa148a4f6900f01bfc Mon Sep 17 00:00:00 2001 From: andrinem Date: Wed, 4 May 2022 22:18:58 +0300 Subject: [PATCH 044/171] Disable pseudo-tty allocation and include php artisan key:generate command --- .github/workflows/cicd_process.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/cicd_process.yml b/.github/workflows/cicd_process.yml index fc92431..157c7a8 100644 --- a/.github/workflows/cicd_process.yml +++ b/.github/workflows/cicd_process.yml @@ -1,7 +1,7 @@ name: deploy to test instance on: push: - branches: [ main ] + branches: [ cicd ] jobs: build: @@ -29,4 +29,4 @@ jobs: docker-compose down docker-compose rm -f docker-compose --env-file .env up -d --build site - docker-compose exec php php artisan key:generate + docker-compose exec -T php php artisan key:generate From cc971b727bce0d53a445a866cc40f42bb18bc1f0 Mon Sep 17 00:00:00 2001 From: andrinem Date: Wed, 4 May 2022 22:21:33 +0300 Subject: [PATCH 045/171] Disable pseudo-tty allocation and include php artisan key:generate command --- .github/workflows/cicd_process.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/cicd_process.yml b/.github/workflows/cicd_process.yml index 157c7a8..c8b462e 100644 --- a/.github/workflows/cicd_process.yml +++ b/.github/workflows/cicd_process.yml @@ -1,7 +1,7 @@ name: deploy to test instance on: push: - branches: [ cicd ] + branches: [ main ] jobs: build: From 1bbba876a75afa06fe2cc81adf4da0ac711f0c77 Mon Sep 17 00:00:00 2001 From: Ronald-pro <36841157+Ronald-pro@users.noreply.github.com> Date: Fri, 6 May 2022 12:10:30 +0300 Subject: [PATCH 046/171] update client upload --- app/Http/Controllers/BulkUploadController.php | 10 +- .../Controllers/NewDashboardController.php | 3803 ++++++++--------- public/template/UshauriTemplate.xlsx | Bin 0 -> 15313 bytes .../clients/upload-clients-form.blade.php | 50 +- .../appointment_dashboard.blade.php | 400 +- .../new_dashboard/client_dashboard.blade.php | 640 +++ .../new_dashboard/main_dashbaord.blade.php | 860 ++-- .../new_dashboard/missed_dashboard.blade.php | 660 +++ resources/views/sms/sms_report.blade.php | 111 +- routes/web.php | 4 + 10 files changed, 3443 insertions(+), 3095 deletions(-) create mode 100644 public/template/UshauriTemplate.xlsx create mode 100644 resources/views/new_dashboard/client_dashboard.blade.php create mode 100644 resources/views/new_dashboard/missed_dashboard.blade.php diff --git a/app/Http/Controllers/BulkUploadController.php b/app/Http/Controllers/BulkUploadController.php index 043a4f4..d93acbf 100644 --- a/app/Http/Controllers/BulkUploadController.php +++ b/app/Http/Controllers/BulkUploadController.php @@ -19,8 +19,6 @@ public function uploadClientForm() { return view('clients.upload-clients-form'); } - - public function importClients(Request $request) { @@ -247,8 +245,6 @@ public function importSecondClients(Request $request) echo "Done"; } - - function csvToArray($filename = '', $delimiter = ',') { if (!file_exists($filename) || !is_readable($filename)) @@ -272,4 +268,10 @@ function csvToArray($filename = '', $delimiter = ',') return $data; } + + public function downloadClientTemplate() + { + $path = public_path('template/UshauriTemplate.xlsx'); + return response()->download($path); + } } diff --git a/app/Http/Controllers/NewDashboardController.php b/app/Http/Controllers/NewDashboardController.php index 3e940e3..b7f595f 100644 --- a/app/Http/Controllers/NewDashboardController.php +++ b/app/Http/Controllers/NewDashboardController.php @@ -31,26 +31,21 @@ public function dashboard() ->whereNull('hei_no') ->where('mfl_code', Auth::user()->facility_id) ->count('clinic_number'); + $client_ever_enrolled = Client::whereNull('hei_no') + ->where('mfl_code', Auth::user()->facility_id) + ->count('clinic_number'); $indicator = Indicator::select(['name', 'description'])->get(); - $appointment = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') - ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') - ->select('tbl_appointment.id') - ->where('tbl_partner_facility.mfl_code', Auth::user()->facility_id) - ->count(); - $missed_appointment = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') - ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') - ->select('tbl_appointment.id') - ->whereIn('tbl_appointment.app_status', ['Defaulted', 'LTFU', 'Missed']) - ->where('tbl_partner_facility.mfl_code', Auth::user()->facility_id) - ->count(); + $active_facilities = PartnerFacility::join('tbl_client', 'tbl_partner_facility.mfl_code', '=', 'tbl_client.mfl_code') ->join('tbl_appointment', 'tbl_client.id', '=', 'tbl_appointment.client_id') ->select('tbl_partner_facility.mfl_code') ->where('tbl_appointment.created_at', '>=', Carbon::now()->subMonths(6)) + ->where('tbl_partner_facility.mfl_code', Auth::user()->facility_id) ->orderBy('tbl_appointment.created_at', 'DESC') ->groupBy('tbl_partner_facility.mfl_code') ->get(); + $facilities_ever_enrolled = PartnerFacility::count('mfl_code'); // dd($active_facilities); @@ -120,258 +115,446 @@ public function dashboard() ->where('mfl_code', Auth::user()->facility_id) ->count(); }); + } + if (Auth::user()->access_level == 'Partner') { + $all_partners = Partner::where('status', '=', 'Active')->pluck('name', 'id'); + $client = Client::join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->where('tbl_client.status', '=', 'Active') + ->whereNull('tbl_client.hei_no') + ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) + ->count('tbl_client.clinic_number'); + $client_ever_enrolled = Client::join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->whereNull('tbl_client.hei_no') + ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) + ->count('tbl_client.clinic_number'); - // appointment by gender - $appointment_male = Cache::remember('appointment-male', 10, function () { - return Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') - ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') - ->select('tbl_appointment.id') - ->where('tbl_client.gender', '=', '2') - ->where('tbl_partner_facility.mfl_code', Auth::user()->facility_id) + $indicator = Indicator::select(['name', 'description'])->get(); + $active_facilities = PartnerFacility::join('tbl_client', 'tbl_partner_facility.mfl_code', '=', 'tbl_client.mfl_code') + ->join('tbl_appointment', 'tbl_client.id', '=', 'tbl_appointment.client_id') + ->select(\DB::raw('COUNT(tbl_partner_facility.mfl_code) as facilities')) + ->where('tbl_appointment.created_at', '>=', Carbon::now()->subMonths(6)) + ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) + ->orderBy('tbl_appointment.created_at', 'DESC') + ->groupBy('tbl_partner_facility.mfl_code') + ->get(); + $facilities_ever_enrolled = PartnerFacility::where('partner_id', Auth::user()->partner_id) + ->count('mfl_code'); + + // dd($active_facilities); + // active clients by gender + $clients_male = Client::join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select('id')->where([['tbl_client.gender', '=', '2'], ['tbl_client.status', '=', 'Active'],]) + ->whereNull('tbl_client.hei_no') + ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) ->count(); - }); - $appointment_female = Cache::remember('appointment-female', 10, function () { - return Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') - ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') - ->select('tbl_appointment.id') - ->where('tbl_client.gender', '=', '1') - ->where('tbl_partner_facility.mfl_code', Auth::user()->facility_id) + + $clients_female = Client::join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->where('tbl_client.gender', '=', '1') + ->where('tbl_client.status', '=', 'Active') + ->whereNull('tbl_client.hei_no') + ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) ->count(); - }); - $appointment_uknown_gender = Cache::remember('appointment-uknown-gender', 10, function () { - return Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') - ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') - ->select('tbl_appointment.id') - ->where('tbl_client.gender', '!=', '1') + $unknown_gender = Client::join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->where('tbl_client.gender', '!=', '1') ->where('tbl_client.gender', '!=', '2') - ->where('tbl_partner_facility.mfl_code', Auth::user()->facility_id) + ->where('tbl_client.status', '=', 'Active') + ->whereNull('tbl_client.hei_no') + ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) ->count(); + + $client_to_nine = Cache::remember('client_to_nine', 10, function () { + return Client::join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) > 0) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 9)) then `tbl_client`.`dob` end)) AS count")) + ->where('tbl_client.status', '=', 'Active') + ->whereNull('tbl_client.hei_no') + ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) + ->pluck('count'); }); - // appointment by age - $appointment_to_nine = Cache::remember('appointment-to-nine', 10, function () { - return Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') - ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') - ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) > 0) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 9)) then `tbl_client`.`id` end)) AS count")) - ->where('tbl_partner_facility.mfl_code', Auth::user()->facility_id) - ->pluck('count'); - }); - $appointment_to_fourteen = Cache::remember('appointment-to-fourteen', 10, function () { - return Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') - ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') - ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 10) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 14)) then `tbl_client`.`id` end)) AS count")) - ->where('tbl_partner_facility.mfl_code', Auth::user()->facility_id) - ->pluck('count'); - }); - $appointment_to_nineteen = Cache::remember('appointment-to-nineteen', 10, function () { - return Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') - ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') - ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 15) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 19)) then `tbl_client`.`id` end)) AS count")) - ->where('tbl_partner_facility.mfl_code', Auth::user()->facility_id) - ->pluck('count'); - }); - $appointment_to_twentyfour = Cache::remember('appointment-to-twentyfour', 10, function () { - return Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') - ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') - ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 20) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 24)) then `tbl_client`.`id` end)) AS count")) - ->where('tbl_partner_facility.mfl_code', Auth::user()->facility_id) - ->pluck('count'); - }); - $appointment_to_twentyfive_above = Cache::remember('appointment-to-twentyfive-above', 10, function () { - return Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') - ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') - ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 25)) then `tbl_client`.`id` end)) AS count")) - ->where('tbl_partner_facility.mfl_code', Auth::user()->facility_id) - ->pluck('count'); - }); - - $appointment_uknown_age = Cache::remember('appointment-uknown-age', 10, function () { - return Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') - ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') - ->where('tbl_client.dob', '=', '') - ->orWhereNull('tbl_client.dob') - ->where('tbl_partner_facility.mfl_code', Auth::user()->facility_id) - ->count(); - }); - // Total missed appointment by gender - $appointment_total_missed_female = Cache::remember('appointment-total-missed-female', 10, function () { - return Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') - ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') - ->where('tbl_client.gender', '=', '1') - ->whereIn('tbl_appointment.app_status', ['Defaulted', 'LTFU', 'Missed']) - ->where('tbl_partner_facility.mfl_code', Auth::user()->facility_id) - ->count(); - }); - $appointment_total_missed_male = Cache::remember('appointment-total-missed-male', 10, function () { - return Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') - ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') - ->where('tbl_client.gender', '=', '2') - ->whereIn('tbl_appointment.app_status', ['Defaulted', 'LTFU', 'Missed']) - ->where('tbl_partner_facility.mfl_code', Auth::user()->facility_id) - ->count(); - }); - $appointment_total_missed_uknown_gender = Cache::remember('appointment-total-missed-uknown-gender', 10, function () { - return Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') - ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') - ->where('tbl_client.gender', '!=', '1') - ->where('tbl_client.gender', '!=', '2') - ->whereIn('tbl_appointment.app_status', ['Defaulted', 'LTFU', 'Missed']) - ->where('tbl_partner_facility.mfl_code', Auth::user()->facility_id) - ->count(); - }); + $client_to_fourteen = Cache::remember('client-fourteen', 10, function () { + return Client::join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 10) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 14)) then `tbl_client`.`dob` end)) AS count")) + ->where('tbl_client.status', '=', 'Active') + ->whereNull('tbl_client.hei_no') + ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) + ->pluck('count'); + }); - // Total missed appointment by age - $appointment_total_missed_to_nine = Cache::remember('appointment-total-missed-to-nine', 10, function () { - return Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') - ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') - ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) > 0) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 9)) then `tbl_client`.`id` end)) AS count")) - ->whereIn('tbl_appointment.app_status', ['Defaulted', 'LTFU', 'Missed']) - ->where('tbl_partner_facility.mfl_code', Auth::user()->facility_id) - ->pluck('count'); - }); - $appointment_total_missed_to_fourteen = Cache::remember('appointment-total-missed-to-fourteen', 10, function () { - return Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') - ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') - ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 10) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 14)) then `tbl_client`.`id` end)) AS count")) - ->whereIn('tbl_appointment.app_status', ['Defaulted', 'LTFU', 'Missed']) - ->where('tbl_partner_facility.mfl_code', Auth::user()->facility_id) - ->pluck('count'); - }); - $appointment_total_missed_to_nineteen = Cache::remember('appointment-total-missed-to-nineteen', 10, function () { - return Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') - ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') - ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 15) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 19)) then `tbl_client`.`id` end)) AS count")) - ->whereIn('tbl_appointment.app_status', ['Defaulted', 'LTFU', 'Missed']) - ->where('tbl_partner_facility.mfl_code', Auth::user()->facility_id) - ->pluck('count'); - }); - $appointment_total_missed_to_twentyfour = Cache::remember('appointment-total-missed-to-twentyfour', 10, function () { - return Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') - ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') - ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 20) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 24)) then `tbl_client`.`id` end)) AS count")) - ->whereIn('tbl_appointment.app_status', ['Defaulted', 'LTFU', 'Missed']) - ->where('tbl_partner_facility.mfl_code', Auth::user()->facility_id) - ->pluck('count'); - }); - $appointment_total_missed_to_twentyfive_above = Cache::remember('appointment-total-missed-to-twentyfive_above', 10, function () { - return Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') - ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') - ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 25)) then `tbl_client`.`id` end)) AS count")) - ->whereIn('tbl_appointment.app_status', ['Defaulted', 'LTFU', 'Missed']) - ->where('tbl_partner_facility.mfl_code', Auth::user()->facility_id) - ->pluck('count'); - }); - $appointment_total_missed_uknown_age = Cache::remember('appointment-total-missed-uknown-age', 10, function () { - return Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') - ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') - ->where('tbl_client.dob', '=', '') - ->whereIn('tbl_appointment.app_status', ['Defaulted', 'LTFU', 'Missed']) - ->where('tbl_partner_facility.mfl_code', Auth::user()->facility_id) - ->count(); - }); - // client charts - $client_consented = Cache::remember('client-consented', 10, function () { - return Client::select('smsenable') - ->where('status', '=', 'Active') - ->whereNull('hei_no') - ->where('smsenable', '=', 'Yes') - ->where('mfl_code', Auth::user()->facility_id) - ->count(); + $client_to_nineteen = Cache::remember('client-nineteen', 10, function () { + return Client::join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 15) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 19)) then `tbl_client`.`dob` end)) AS count")) + ->where('tbl_client.status', '=', 'Active') + ->whereNull('tbl_client.hei_no') + ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) + ->pluck('count'); }); - $client_nonconsented = Cache::remember('client-nonconsented', 10, function () { - return Client::select('smsenable') - ->where('status', '=', 'Active') - ->whereNull('hei_no') - ->where('smsenable', '!=', 'Yes') - ->where('mfl_code', Auth::user()->facility_id) - ->count(); + + $client_to_twentyfour = Cache::remember('client-twentyfour', 10, function () { + return Client::join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 20) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 24)) then `tbl_client`.`dob` end)) AS count")) + ->where('tbl_client.status', '=', 'Active') + ->whereNull('tbl_client.hei_no') + ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) + ->pluck('count'); }); - // consented clients by gender - $client_consented_male = Cache::remember('client-consented-male', 10, function () { - return Client::where('smsenable', '=', 'Yes') - ->where('status', '=', 'Active') - ->whereNull('hei_no') - ->where('gender', '=', '2') - ->where('mfl_code', Auth::user()->facility_id) - ->count(); + $client_to_twentyfive_above = Cache::remember('client-twentyfive-above', 10, function () { + return Client::join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 25)) then `tbl_client`.`dob` end)) AS count")) + ->where('tbl_client.status', '=', 'Active') + ->whereNull('tbl_client.hei_no') + ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) + ->pluck('count'); }); - $client_consented_female = Cache::remember('client-consented-female', 10, function () { - return Client::where('smsenable', '=', 'Yes') - ->where('status', '=', 'Active') - ->whereNull('hei_no') - ->where('gender', '=', '1') - ->where('mfl_code', Auth::user()->facility_id) + + $client_unknown_age = Cache::remember('client-unknown-age', 10, function () { + return Client::join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->where('tbl_client.dob', '=', '') + ->orWhereNull('tbl_client.dob') + ->where('tbl_client.status', '=', 'Active') + ->whereNull('tbl_client.hei_no') + ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) ->count(); }); - $client_consented_uknown_gender = Cache::remember('client-consented-uknown-gender', 10, function () { - return Client::where('smsenable', '=', 'Yes') - ->where('status', '=', 'Active') + + } + if (Auth::user()->access_level == 'Admin' || Auth::user()->access_level == 'Donor') { + + $all_partners = Partner::where('status', '=', 'Active')->pluck('name', 'id'); + $client = Client::where('status', '=', 'Active')->whereNull('hei_no')->count('clinic_number'); + $client_ever_enrolled = Client::whereNull('hei_no')->count('clinic_number'); + + + $indicator = Indicator::select(['name', 'description'])->get(); + // $missed_appointment = Appointments::select('id')->whereIn('app_status', ['Defaulted', 'LTFU', 'Missed'])->count(); + $active_facilities = PartnerFacility::join('tbl_client', 'tbl_partner_facility.mfl_code', '=', 'tbl_client.mfl_code') + ->join('tbl_appointment', 'tbl_client.id', '=', 'tbl_appointment.client_id') + ->select('tbl_partner_facility.mfl_code') + ->where('tbl_appointment.created_at', '>=', Carbon::now()->subMonths(6)) + ->orderBy('tbl_appointment.created_at', 'DESC') + ->groupBy('tbl_partner_facility.mfl_code') + ->get(); + $facilities_ever_enrolled = PartnerFacility::count('mfl_code'); + + // dd($active_facilities); + // active clients by gender + $clients_male = Client::select('id')->where([['gender', '=', '2'], ['status', '=', 'Active'],]) ->whereNull('hei_no') - ->where('gender', '!=', '1') - ->where('gender', '!=', '2') - ->where('mfl_code', Auth::user()->facility_id) ->count(); - }); - // non consented clients by gender - $client_nonconsented_male = Cache::remember('client-nonconsented-male', 10, function () { - return Client::where('smsenable', '!=', 'Yes') + + $clients_female = Client::where('gender', '=', '1') ->where('status', '=', 'Active') ->whereNull('hei_no') - ->where('gender', '=', '2') - ->where('mfl_code', Auth::user()->facility_id) ->count(); - }); - $client_nonconsented_female = Cache::remember('client-nonconsented-female', 10, function () { - return Client::where('smsenable', '!=', 'Yes') + $unknown_gender = Client::where('gender', '!=', '1') + ->where('gender', '!=', '2') ->where('status', '=', 'Active') ->whereNull('hei_no') - ->where('gender', '=', '1') - ->where('mfl_code', Auth::user()->facility_id) - ->count(); - }); - $client_nonconsented_uknown_gender = Cache::remember('client-nonconsented-uknown-gender', 10, function () { - return Client::where('smsenable', '!=', 'Yes') - ->where('gender', '!=', '1') - ->where('gender', '!=', '2') - ->where('mfl_code', Auth::user()->facility_id) ->count(); - }); - // consented clients by age distribution - $client_consented_to_nine = Cache::remember('client-consented-to-nine', 10, function () { - return Client::select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) > 0) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 9)) then `tbl_client`.`id` end)) AS count")) - ->where('smsenable', '=', 'Yes') + + $client_to_nine = Cache::remember('client_to_nine', 10, function () { + return Client::select(\DB::raw("count((case when (((year(curdate()) - year(`dob`)) > 0) and ((year(curdate()) - year(`dob`)) <= 9)) then `dob` end)) AS count")) ->where('status', '=', 'Active') ->whereNull('hei_no') - ->where('mfl_code', Auth::user()->facility_id) ->pluck('count'); }); - $client_consented_to_fourteen = Cache::remember('tbl-client', 10, function () { - return Client::select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 10) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 14)) then `tbl_client`.`id` end)) AS count")) - ->where('smsenable', '=', 'Yes') + + $client_to_fourteen = Cache::remember('client-fourteen', 10, function () { + return Client::select(\DB::raw("count((case when (((year(curdate()) - year(`dob`)) >= 10) and ((year(curdate()) - year(`dob`)) <= 14)) then `dob` end)) AS count")) ->where('status', '=', 'Active') ->whereNull('hei_no') - ->where('mfl_code', Auth::user()->facility_id) ->pluck('count'); }); - $client_consented_to_nineteen = Cache::remember('client-consented-to-nineteen', 10, function () { - return Client::select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 15) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 19)) then `tbl_client`.`id` end)) AS count")) - ->where('smsenable', '=', 'Yes') + + $client_to_nineteen = Cache::remember('client-nineteen', 10, function () { + return Client::select(\DB::raw("count((case when (((year(curdate()) - year(`dob`)) >= 15) and ((year(curdate()) - year(`dob`)) <= 19)) then `dob` end)) AS count")) ->where('status', '=', 'Active') ->whereNull('hei_no') - ->where('mfl_code', Auth::user()->facility_id) ->pluck('count'); }); - $client_consented_to_twentyfour = Cache::remember('client-consented-to-twentyfour', 10, function () { - return Client::select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 20) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 24)) then `tbl_client`.`id` end)) AS count")) - ->where('smsenable', '=', 'Yes') + + $client_to_twentyfour = Cache::remember('client-twentyfour', 10, function () { + return Client::select(\DB::raw("count((case when (((year(curdate()) - year(`dob`)) >= 20) and ((year(curdate()) - year(`dob`)) <= 24)) then `id` end)) AS count")) ->where('status', '=', 'Active') ->whereNull('hei_no') - ->where('mfl_code', Auth::user()->facility_id) ->pluck('count'); }); - $client_consented_to_twentyfive_above = Cache::remember('client-consented-to-twentyfive-above', 10, function () { - return Client::select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 25)) then `tbl_client`.`id` end)) AS count")) + + $client_to_twentyfive_above = Cache::remember('client-twentyfive-above', 10, function () { + return Client::select(\DB::raw("count((case when (((year(curdate()) - year(`dob`)) >= 25)) then `id` end)) AS count")) + ->where('status', '=', 'Active') + ->whereNull('hei_no') + ->pluck('count'); + }); + + $client_unknown_age = Cache::remember('client-unknown-age', 10, function () { + return Client::where('dob', '=', '') + ->orWhereNull('dob') + ->where('status', '=', 'Active') + ->whereNull('hei_no') + ->count(); + }); + + // // appointment by gender + // $appointment_male = Cache::remember('appointment-male', 10, function () { + // return Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + // ->select('tbl_appointment.id') + // ->where('tbl_client.gender', '=', '2') + // ->count(); + // }); + // $appointment_female = Cache::remember('appointment-female', 10, function () { + // return Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + // ->select('tbl_appointment.id') + // ->where('tbl_client.gender', '=', '1') + // ->count(); + // }); + // $appointment_uknown_gender = Cache::remember('appointment-uknown-gender', 10, function () { + // return Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + // ->select('tbl_appointment.id') + // ->where('tbl_client.gender', '!=', '1') + // ->where('tbl_client.gender', '!=', '2') + // ->count(); + // }); + // // appointment by age + // $appointment_to_nine = Cache::remember('appointment-to-nine', 10, function () { + // return Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + // ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + // ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) > 0) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 9)) then `tbl_client`.`id` end)) AS count")) + // ->pluck('count'); + // }); + // $appointment_to_fourteen = Cache::remember('appointment-to-fourteen', 10, function () { + // return Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + // ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + // ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 10) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 14)) then `tbl_client`.`id` end)) AS count")) + // ->pluck('count'); + // }); + // $appointment_to_nineteen = Cache::remember('appointment-to-nineteen', 10, function () { + // return Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + // ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + // ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 15) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 19)) then `tbl_client`.`id` end)) AS count")) + // ->pluck('count'); + // }); + // $appointment_to_twentyfour = Cache::remember('appointment-to-twentyfour', 10, function () { + // return Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + // ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + // ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 20) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 24)) then `tbl_client`.`id` end)) AS count")) + // ->pluck('count'); + // }); + // $appointment_to_twentyfive_above = Cache::remember('appointment-to-twentyfive-above', 10, function () { + // return Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + // ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + // ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 25)) then `tbl_client`.`id` end)) AS count")) + // ->pluck('count'); + // }); + // $appointment_uknown_age = Cache::remember('appointment-uknown-age', 10, function () { + // return Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + // ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + // ->where('tbl_client.dob', '=', '') + // ->orWhereNull('tbl_client.dob') + // ->count(); + // }); + + // // Total missed appointment by gender + // $appointment_total_missed_female = Cache::remember('appointment-total-missed-female', 10, function () { + // return Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + // ->whereIn('tbl_appointment.app_status', ['Defaulted', 'LTFU', 'Missed']) + // ->where('tbl_client.gender', '=', '1') + // ->count(); + // }); + // $appointment_total_missed_male = Cache::remember('appointment-total-missed-male', 10, function () { + // return Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + // ->where('tbl_client.gender', '=', '2') + // ->whereIn('tbl_appointment.app_status', ['Defaulted', 'LTFU', 'Missed']) + // ->count(); + // }); + // $appointment_total_missed_uknown_gender = Cache::remember('appointment-total-missed-uknown-gender', 10, function () { + // return Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + // ->whereIn('tbl_appointment.app_status', ['Defaulted', 'LTFU', 'Missed']) + // ->where('tbl_client.gender', '!=', '1') + // ->where('tbl_client.gender', '!=', '2') + // ->count(); + // }); + + // // Total missed appointment by age + // $appointment_total_missed_to_nine = Cache::remember('appointment-total-missed-to-nine', 10, function () { + // return Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + // ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) > 0) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 9)) then `tbl_client`.`id` end)) AS count")) + // ->whereIn('tbl_appointment.app_status', ['Defaulted', 'LTFU', 'Missed']) + // ->pluck('count'); + // }); + // $appointment_total_missed_to_fourteen = Cache::remember('appointment-total-missed-to-fourteen', 10, function () { + // return Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + // ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 10) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 14)) then `tbl_client`.`id` end)) AS count")) + // ->whereIn('tbl_appointment.app_status', ['Defaulted', 'LTFU', 'Missed']) + // ->pluck('count'); + // }); + // $appointment_total_missed_to_nineteen = Cache::remember('appointment-total-missed-to-nineteen', 10, function () { + // return Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + // ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 15) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 19)) then `tbl_client`.`id` end)) AS count")) + // ->whereIn('tbl_appointment.app_status', ['Defaulted', 'LTFU', 'Missed']) + // ->pluck('count'); + // }); + // $appointment_total_missed_to_twentyfour = Cache::remember('appointment-total-missed-to-twentyfour', 10, function () { + // return Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + // ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 20) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 24)) then `tbl_client`.`id` end)) AS count")) + // ->whereIn('tbl_appointment.app_status', ['Defaulted', 'LTFU', 'Missed']) + // ->pluck('count'); + // }); + // $appointment_total_missed_to_twentyfive_above = Cache::remember('appointment-total-missed-to-twentyfive_above', 10, function () { + // return Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + // ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 25)) then `tbl_client`.`id` end)) AS count")) + // ->whereIn('tbl_appointment.app_status', ['Defaulted', 'LTFU', 'Missed']) + // ->pluck('count'); + // }); + // $appointment_total_missed_uknown_age = Cache::remember('appointment-total-missed-uknown-age', 10, function () { + // return Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + // ->where('tbl_client.dob', '=', '') + // ->orWhereNull('tbl_client.dob') + // ->whereIn('tbl_appointment.app_status', ['Defaulted', 'LTFU', 'Missed']) + // ->count(); + // }); + + } + + + // dd($active_facilities); + + return view('new_dashboard.main_dashbaord', compact( + 'all_partners', + 'active_facilities', + 'facilities_ever_enrolled', + 'indicator', + 'client', + 'client_ever_enrolled', + 'clients_male', + 'clients_female', + 'unknown_gender', + 'client_to_nine', + 'client_to_fourteen', + 'client_to_nineteen', + 'client_to_twentyfour', + 'client_to_twentyfive_above', + 'client_unknown_age' + + )); + } + + public function client_dashboard() + { + + // showing all the active clients, all appointments, missed appointments + if (Auth::user()->access_level == 'Facility') { + $all_partners = Partner::where('status', '=', 'Active')->pluck('name', 'id'); + $client = Client::where('status', '=', 'Active') + ->whereNull('hei_no') + ->where('mfl_code', Auth::user()->facility_id) + ->count('clinic_number'); + + $indicator = Indicator::select(['name', 'description'])->get(); + + // client charts + $client_consented = Cache::remember('client-consented', 10, function () { + return Client::select('smsenable') + ->where('status', '=', 'Active') + ->whereNull('hei_no') + ->where('smsenable', '=', 'Yes') + ->where('mfl_code', Auth::user()->facility_id) + ->count(); + }); + $client_nonconsented = Cache::remember('client-nonconsented', 10, function () { + return Client::select('smsenable') + ->where('status', '=', 'Active') + ->whereNull('hei_no') + ->where('smsenable', '!=', 'Yes') + ->where('mfl_code', Auth::user()->facility_id) + ->count(); + }); + // consented clients by gender + + $client_consented_male = Cache::remember('client-consented-male', 10, function () { + return Client::where('smsenable', '=', 'Yes') + ->where('status', '=', 'Active') + ->whereNull('hei_no') + ->where('gender', '=', '2') + ->where('mfl_code', Auth::user()->facility_id) + ->count(); + }); + $client_consented_female = Cache::remember('client-consented-female', 10, function () { + return Client::where('smsenable', '=', 'Yes') + ->where('status', '=', 'Active') + ->whereNull('hei_no') + ->where('gender', '=', '1') + ->where('mfl_code', Auth::user()->facility_id) + ->count(); + }); + $client_consented_uknown_gender = Cache::remember('client-consented-uknown-gender', 10, function () { + return Client::where('smsenable', '=', 'Yes') + ->where('status', '=', 'Active') + ->whereNull('hei_no') + ->where('gender', '!=', '1') + ->where('gender', '!=', '2') + ->where('mfl_code', Auth::user()->facility_id) + ->count(); + }); + // non consented clients by gender + $client_nonconsented_male = Cache::remember('client-nonconsented-male', 10, function () { + return Client::where('smsenable', '!=', 'Yes') + ->where('status', '=', 'Active') + ->whereNull('hei_no') + ->where('gender', '=', '2') + ->where('mfl_code', Auth::user()->facility_id) + ->count(); + }); + $client_nonconsented_female = Cache::remember('client-nonconsented-female', 10, function () { + return Client::where('smsenable', '!=', 'Yes') + ->where('status', '=', 'Active') + ->whereNull('hei_no') + ->where('gender', '=', '1') + ->where('mfl_code', Auth::user()->facility_id) + ->count(); + }); + $client_nonconsented_uknown_gender = Cache::remember('client-nonconsented-uknown-gender', 10, function () { + return Client::where('smsenable', '!=', 'Yes') + ->where('gender', '!=', '1') + ->where('gender', '!=', '2') + ->where('mfl_code', Auth::user()->facility_id) + ->count(); + }); + // consented clients by age distribution + $client_consented_to_nine = Cache::remember('client-consented-to-nine', 10, function () { + return Client::select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) > 0) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 9)) then `tbl_client`.`id` end)) AS count")) + ->where('smsenable', '=', 'Yes') + ->where('status', '=', 'Active') + ->whereNull('hei_no') + ->where('mfl_code', Auth::user()->facility_id) + ->pluck('count'); + }); + $client_consented_to_fourteen = Cache::remember('tbl-client', 10, function () { + return Client::select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 10) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 14)) then `tbl_client`.`id` end)) AS count")) + ->where('smsenable', '=', 'Yes') + ->where('status', '=', 'Active') + ->whereNull('hei_no') + ->where('mfl_code', Auth::user()->facility_id) + ->pluck('count'); + }); + $client_consented_to_nineteen = Cache::remember('client-consented-to-nineteen', 10, function () { + return Client::select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 15) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 19)) then `tbl_client`.`id` end)) AS count")) + ->where('smsenable', '=', 'Yes') + ->where('status', '=', 'Active') + ->whereNull('hei_no') + ->where('mfl_code', Auth::user()->facility_id) + ->pluck('count'); + }); + $client_consented_to_twentyfour = Cache::remember('client-consented-to-twentyfour', 10, function () { + return Client::select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 20) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 24)) then `tbl_client`.`id` end)) AS count")) + ->where('smsenable', '=', 'Yes') + ->where('status', '=', 'Active') + ->whereNull('hei_no') + ->where('mfl_code', Auth::user()->facility_id) + ->pluck('count'); + }); + $client_consented_to_twentyfive_above = Cache::remember('client-consented-to-twentyfive-above', 10, function () { + return Client::select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 25)) then `tbl_client`.`id` end)) AS count")) ->where('smsenable', '=', 'Yes') ->where('status', '=', 'Active') ->whereNull('hei_no') @@ -450,332 +633,87 @@ public function dashboard() ->count('tbl_client.clinic_number'); $indicator = Indicator::select(['name', 'description'])->get(); - $appointment = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') - ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') - ->select('tbl_appointment.id') - ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) - ->count(); - $missed_appointment = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') - ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') - ->select('tbl_appointment.id') - ->whereIn('tbl_appointment.app_status', ['Defaulted', 'LTFU', 'Missed']) + // client charts + $client_consented = Cache::remember('client-consented', 10, function () { + return Client::join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select('tbl_clientsmsenable') + ->where('tbl_client.status', '=', 'Active') + ->whereNull('tbl_client.hei_no') + ->where('tbl_client.smsenable', '=', 'Yes') ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) ->count(); - $active_facilities = PartnerFacility::join('tbl_client', 'tbl_partner_facility.mfl_code', '=', 'tbl_client.mfl_code') - ->join('tbl_appointment', 'tbl_client.id', '=', 'tbl_appointment.client_id') - ->select(\DB::raw('COUNT(tbl_partner_facility.mfl_code) as facilities')) - ->where('tbl_appointment.created_at', '>=', Carbon::now()->subMonths(6)) - ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) - ->orderBy('tbl_appointment.created_at', 'DESC') - ->groupBy('tbl_partner_facility.mfl_code') - ->get(); - - - // dd($active_facilities); - // active clients by gender - $clients_male = Client::join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') - ->select('id')->where([['tbl_client.gender', '=', '2'], ['tbl_client.status', '=', 'Active'],]) + }); + $client_nonconsented = Cache::remember('client-nonconsented', 10, function () { + return Client::join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select('smsenable') + ->where('tbl_client.status', '=', 'Active') ->whereNull('tbl_client.hei_no') + ->where('tbl_client.smsenable', '!=', 'Yes') ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) ->count(); + }); + // consented clients by gender - $clients_female = Client::join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') - ->where('tbl_client.gender', '=', '1') + $client_consented_male = Cache::remember('client-consented-male', 10, function () { + return Client::join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->where('tbl_client.smsenable', '=', 'Yes') ->where('tbl_client.status', '=', 'Active') ->whereNull('tbl_client.hei_no') + ->where('tbl_client.gender', '=', '2') ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) ->count(); - $unknown_gender = Client::join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') - ->where('tbl_client.gender', '!=', '1') - ->where('tbl_client.gender', '!=', '2') + }); + $client_consented_female = Cache::remember('client-consented-female', 10, function () { + return Client::join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->where('tbl_client.smsenable', '=', 'Yes') ->where('tbl_client.status', '=', 'Active') ->whereNull('tbl_client.hei_no') + ->where('tbl_client.gender', '=', '1') ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) ->count(); - - $client_to_nine = Cache::remember('client_to_nine', 10, function () { + }); + $client_consented_uknown_gender = Cache::remember('client-consented-uknown-gender', 10, function () { return Client::join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') - ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) > 0) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 9)) then `tbl_client`.`dob` end)) AS count")) + ->where('tbl_client.smsenable', '=', 'Yes') ->where('tbl_client.status', '=', 'Active') ->whereNull('tbl_client.hei_no') + ->where('tbl_client.gender', '!=', '1') + ->where('tbl_client.gender', '!=', '2') ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) - ->pluck('count'); + ->count(); }); - - $client_to_fourteen = Cache::remember('client-fourteen', 10, function () { - return Client::join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') - ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 10) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 14)) then `tbl_client`.`dob` end)) AS count")) + // non consented clients by gender + $client_nonconsented_male = Cache::remember('client-nonconsented-male', 10, function () { + return Client::join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->where('tbl_client.smsenable', '!=', 'Yes') ->where('tbl_client.status', '=', 'Active') ->whereNull('tbl_client.hei_no') + ->where('tbl_client.gender', '=', '2') ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) - ->pluck('count'); + ->count(); }); - - $client_to_nineteen = Cache::remember('client-nineteen', 10, function () { + $client_nonconsented_female = Cache::remember('client-nonconsented-female', 10, function () { return Client::join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') - ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 15) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 19)) then `tbl_client`.`dob` end)) AS count")) + ->where('tbl_client.smsenable', '!=', 'Yes') ->where('tbl_client.status', '=', 'Active') ->whereNull('tbl_client.hei_no') + ->where('tbl_client.gender', '=', '1') ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) - ->pluck('count'); + ->count(); }); - - $client_to_twentyfour = Cache::remember('client-twentyfour', 10, function () { + $client_nonconsented_uknown_gender = Cache::remember('client-nonconsented-uknown-gender', 10, function () { return Client::join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') - ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 20) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 24)) then `tbl_client`.`dob` end)) AS count")) - ->where('tbl_client.status', '=', 'Active') - ->whereNull('tbl_client.hei_no') + ->where('tbl_client.smsenable', '!=', 'Yes') + ->where('tbl_client.gender', '!=', '1') + ->where('tbl_client.gender', '!=', '2') ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) - ->pluck('count'); + ->count(); }); - - $client_to_twentyfive_above = Cache::remember('client-twentyfive-above', 10, function () { - return Client::join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') - ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 25)) then `tbl_client`.`dob` end)) AS count")) - ->where('tbl_client.status', '=', 'Active') - ->whereNull('tbl_client.hei_no') - ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) - ->pluck('count'); - }); - - $client_unknown_age = Cache::remember('client-unknown-age', 10, function () { - return Client::join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') - ->where('tbl_client.dob', '=', '') - ->orWhereNull('tbl_client.dob') - ->where('tbl_client.status', '=', 'Active') - ->whereNull('tbl_client.hei_no') - ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) - ->count(); - }); - - // appointment by gender - $appointment_male = Cache::remember('appointment-male', 10, function () { - return Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') - ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') - ->select('tbl_appointment.id') - ->where('tbl_client.gender', '=', '2') - ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) - ->count(); - }); - $appointment_female = Cache::remember('appointment-female', 10, function () { - return Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') - ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') - ->select('tbl_appointment.id') - ->where('tbl_client.gender', '=', '1') - ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) - ->count(); - }); - $appointment_uknown_gender = Cache::remember('appointment-uknown-gender', 10, function () { - return Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') - ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') - ->select('tbl_appointment.id') - ->where('tbl_client.gender', '!=', '1') - ->where('tbl_client.gender', '!=', '2') - ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) - ->count(); - }); - // appointment by age - $appointment_to_nine = Cache::remember('appointment-to-nine', 10, function () { - return Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') - ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') - ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) > 0) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 9)) then `tbl_client`.`id` end)) AS count")) - ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) - ->pluck('count'); - }); - $appointment_to_fourteen = Cache::remember('appointment-to-fourteen', 10, function () { - return Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') - ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') - ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 10) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 14)) then `tbl_client`.`id` end)) AS count")) - ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) - ->pluck('count'); - }); - $appointment_to_nineteen = Cache::remember('appointment-to-nineteen', 10, function () { - return Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') - ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') - ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 15) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 19)) then `tbl_client`.`id` end)) AS count")) - ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) - ->pluck('count'); - }); - $appointment_to_twentyfour = Cache::remember('appointment-to-twentyfour', 10, function () { - return Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') - ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') - ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 20) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 24)) then `tbl_client`.`id` end)) AS count")) - ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) - ->pluck('count'); - }); - $appointment_to_twentyfive_above = Cache::remember('appointment-to-twentyfive-above', 10, function () { - return Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') - ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') - ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 25)) then `tbl_client`.`id` end)) AS count")) - ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) - ->pluck('count'); - }); - $appointment_uknown_age = Cache::remember('appointment-uknown-age', 10, function () { - return Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') - ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') - ->where('tbl_client.dob', '=', '') - ->orWhereNull('tbl_client.dob') - ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) - ->count(); - }); - - // Total missed appointment by gender - $appointment_total_missed_female = Cache::remember('appointment-total-missed-female', 10, function () { - return Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') - ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') - ->where('tbl_client.gender', '=', '1') - ->whereIn('tbl_appointment.app_status', ['Defaulted', 'LTFU', 'Missed']) - ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) - ->count(); - }); - $appointment_total_missed_male = Cache::remember('appointment-total-missed-male', 10, function () { - return Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') - ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') - ->where('tbl_client.gender', '=', '2') - ->whereIn('tbl_appointment.app_status', ['Defaulted', 'LTFU', 'Missed']) - ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) - ->count(); - }); - $appointment_total_missed_uknown_gender = Cache::remember('appointment-total-missed-uknown-gender', 10, function () { - return Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') - ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') - ->where('tbl_client.gender', '!=', '1') - ->where('tbl_client.gender', '!=', '2') - ->whereIn('tbl_appointment.app_status', ['Defaulted', 'LTFU', 'Missed']) - ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) - ->count(); - }); - - // Total missed appointment by age - $appointment_total_missed_to_nine = Cache::remember('appointment-total-missed-to-nine', 10, function () { - return Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') - ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') - ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) > 0) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 9)) then `tbl_client`.`id` end)) AS count")) - ->whereIn('tbl_appointment.app_status', ['Defaulted', 'LTFU', 'Missed']) - ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) - ->pluck('count'); - }); - $appointment_total_missed_to_fourteen = Cache::remember('appointment-total-missed-to-fourteen', 10, function () { - return Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') - ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') - ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 10) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 14)) then `tbl_client`.`id` end)) AS count")) - ->whereIn('tbl_appointment.app_status', ['Defaulted', 'LTFU', 'Missed']) - ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) - ->pluck('count'); - }); - $appointment_total_missed_to_nineteen = Cache::remember('appointment-total-missed-to-nineteen', 10, function () { - return Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') - ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') - ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 15) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 19)) then `tbl_client`.`id` end)) AS count")) - ->whereIn('tbl_appointment.app_status', ['Defaulted', 'LTFU', 'Missed']) - ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) - ->pluck('count'); - }); - $appointment_total_missed_to_twentyfour = Cache::remember('appointment-total-missed-to-twentyfour', 10, function () { - return Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') - ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') - ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 20) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 24)) then `tbl_client`.`id` end)) AS count")) - ->whereIn('tbl_appointment.app_status', ['Defaulted', 'LTFU', 'Missed']) - ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) - ->pluck('count'); - }); - $appointment_total_missed_to_twentyfive_above = Cache::remember('appointment-total-missed-to-twentyfive_above', 10, function () { - return Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') - ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') - ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 25)) then `tbl_client`.`id` end)) AS count")) - ->whereIn('tbl_appointment.app_status', ['Defaulted', 'LTFU', 'Missed']) - ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) - ->pluck('count'); - }); - $appointment_total_missed_uknown_age = Cache::remember('appointment-total-missed-uknown-age', 10, function () { - return Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') - ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') - ->where('tbl_client.dob', '=', '') - ->whereIn('tbl_appointment.app_status', ['Defaulted', 'LTFU', 'Missed']) - ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) - ->count(); - }); - // client charts - $client_consented = Cache::remember('client-consented', 10, function () { - return Client::join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') - ->select('tbl_clientsmsenable') - ->where('tbl_client.status', '=', 'Active') - ->whereNull('tbl_client.hei_no') - ->where('tbl_client.smsenable', '=', 'Yes') - ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) - ->count(); - }); - $client_nonconsented = Cache::remember('client-nonconsented', 10, function () { - return Client::join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') - ->select('smsenable') - ->where('tbl_client.status', '=', 'Active') - ->whereNull('tbl_client.hei_no') - ->where('tbl_client.smsenable', '!=', 'Yes') - ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) - ->count(); - }); - // consented clients by gender - - $client_consented_male = Cache::remember('client-consented-male', 10, function () { - return Client::join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') - ->where('tbl_client.smsenable', '=', 'Yes') - ->where('tbl_client.status', '=', 'Active') - ->whereNull('tbl_client.hei_no') - ->where('tbl_client.gender', '=', '2') - ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) - ->count(); - }); - $client_consented_female = Cache::remember('client-consented-female', 10, function () { - return Client::join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') - ->where('tbl_client.smsenable', '=', 'Yes') - ->where('tbl_client.status', '=', 'Active') - ->whereNull('tbl_client.hei_no') - ->where('tbl_client.gender', '=', '1') - ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) - ->count(); - }); - $client_consented_uknown_gender = Cache::remember('client-consented-uknown-gender', 10, function () { - return Client::join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') - ->where('tbl_client.smsenable', '=', 'Yes') - ->where('tbl_client.status', '=', 'Active') - ->whereNull('tbl_client.hei_no') - ->where('tbl_client.gender', '!=', '1') - ->where('tbl_client.gender', '!=', '2') - ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) - ->count(); - }); - // non consented clients by gender - $client_nonconsented_male = Cache::remember('client-nonconsented-male', 10, function () { - return Client::join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') - ->where('tbl_client.smsenable', '!=', 'Yes') - ->where('tbl_client.status', '=', 'Active') - ->whereNull('tbl_client.hei_no') - ->where('tbl_client.gender', '=', '2') - ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) - ->count(); - }); - $client_nonconsented_female = Cache::remember('client-nonconsented-female', 10, function () { - return Client::join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') - ->where('tbl_client.smsenable', '!=', 'Yes') - ->where('tbl_client.status', '=', 'Active') - ->whereNull('tbl_client.hei_no') - ->where('tbl_client.gender', '=', '1') - ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) - ->count(); - }); - $client_nonconsented_uknown_gender = Cache::remember('client-nonconsented-uknown-gender', 10, function () { - return Client::join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') - ->where('tbl_client.smsenable', '!=', 'Yes') - ->where('tbl_client.gender', '!=', '1') - ->where('tbl_client.gender', '!=', '2') - ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) - ->count(); - }); - // consented clients by age distribution - $client_consented_to_nine = Cache::remember('client-consented-to-nine', 10, function () { - return Client::join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') - ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) > 0) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 9)) then `tbl_client`.`id` end)) AS count")) - ->where('tbl_client.smsenable', '=', 'Yes') + // consented clients by age distribution + $client_consented_to_nine = Cache::remember('client-consented-to-nine', 10, function () { + return Client::join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) > 0) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 9)) then `tbl_client`.`id` end)) AS count")) + ->where('tbl_client.smsenable', '=', 'Yes') ->where('tbl_client.status', '=', 'Active') ->whereNull('tbl_client.hei_no') ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) @@ -891,227 +829,34 @@ public function dashboard() $all_partners = Partner::where('status', '=', 'Active')->pluck('name', 'id'); $client = Client::where('status', '=', 'Active')->whereNull('hei_no')->count('clinic_number'); - - $indicator = Indicator::select(['name', 'description'])->get(); - $appointment = Appointments::select('id') - ->count(); - $missed_appointment = Appointments::select('id') - ->whereIn('app_status', ['Defaulted', 'LTFU', 'Missed']) - ->count(); - // dd($missed_appointment); - $active_facilities = PartnerFacility::join('tbl_client', 'tbl_partner_facility.mfl_code', '=', 'tbl_client.mfl_code') - ->join('tbl_appointment', 'tbl_client.id', '=', 'tbl_appointment.client_id') - ->select('tbl_partner_facility.mfl_code') - ->where('tbl_appointment.created_at', '>=', Carbon::now()->subMonths(6)) - ->orderBy('tbl_appointment.created_at', 'DESC') - ->groupBy('tbl_partner_facility.mfl_code') - ->get(); - - // dd($active_facilities); - // active clients by gender - $clients_male = Client::select('id')->where([['gender', '=', '2'], ['status', '=', 'Active'],]) - ->whereNull('hei_no') - ->count(); - - $clients_female = Client::where('gender', '=', '1') + // client charts + $client_consented = Cache::remember('client-consented', 10, function () { + return Client::select('smsenable') ->where('status', '=', 'Active') ->whereNull('hei_no') + ->where('smsenable', '=', 'Yes') ->count(); - $unknown_gender = Client::where('gender', '!=', '1') - ->where('gender', '!=', '2') + }); + $client_nonconsented = Cache::remember('client-nonconsented', 10, function () { + return Client::select('smsenable') ->where('status', '=', 'Active') ->whereNull('hei_no') + ->where('smsenable', '!=', 'Yes') ->count(); + }); + // consented clients by gender - $client_to_nine = Cache::remember('client_to_nine', 10, function () { - return Client::select(\DB::raw("count((case when (((year(curdate()) - year(`dob`)) > 0) and ((year(curdate()) - year(`dob`)) <= 9)) then `dob` end)) AS count")) + $client_consented_male = Cache::remember('client-consented-male', 10, function () { + return Client::where('smsenable', '=', 'Yes') ->where('status', '=', 'Active') ->whereNull('hei_no') - ->pluck('count'); + ->where('gender', '=', '2') + ->count(); }); - - $client_to_fourteen = Cache::remember('client-fourteen', 10, function () { - return Client::select(\DB::raw("count((case when (((year(curdate()) - year(`dob`)) >= 10) and ((year(curdate()) - year(`dob`)) <= 14)) then `dob` end)) AS count")) - ->where('status', '=', 'Active') - ->whereNull('hei_no') - ->pluck('count'); - }); - - $client_to_nineteen = Cache::remember('client-nineteen', 10, function () { - return Client::select(\DB::raw("count((case when (((year(curdate()) - year(`dob`)) >= 15) and ((year(curdate()) - year(`dob`)) <= 19)) then `dob` end)) AS count")) - ->where('status', '=', 'Active') - ->whereNull('hei_no') - ->pluck('count'); - }); - - $client_to_twentyfour = Cache::remember('client-twentyfour', 10, function () { - return Client::select(\DB::raw("count((case when (((year(curdate()) - year(`dob`)) >= 20) and ((year(curdate()) - year(`dob`)) <= 24)) then `id` end)) AS count")) - ->where('status', '=', 'Active') - ->whereNull('hei_no') - ->pluck('count'); - }); - - $client_to_twentyfive_above = Cache::remember('client-twentyfive-above', 10, function () { - return Client::select(\DB::raw("count((case when (((year(curdate()) - year(`dob`)) >= 25)) then `id` end)) AS count")) - ->where('status', '=', 'Active') - ->whereNull('hei_no') - ->pluck('count'); - }); - - $client_unknown_age = Cache::remember('client-unknown-age', 10, function () { - return Client::where('dob', '=', '') - ->orWhereNull('dob') - ->where('status', '=', 'Active') - ->whereNull('hei_no') - ->count(); - }); - - // appointment by gender - $appointment_male = Cache::remember('appointment-male', 10, function () { - return Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') - ->select('tbl_appointment.id') - ->where('tbl_client.gender', '=', '2') - ->count(); - }); - $appointment_female = Cache::remember('appointment-female', 10, function () { - return Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') - ->select('tbl_appointment.id') - ->where('tbl_client.gender', '=', '1') - ->count(); - }); - $appointment_uknown_gender = Cache::remember('appointment-uknown-gender', 10, function () { - return Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') - ->select('tbl_appointment.id') - ->where('tbl_client.gender', '!=', '1') - ->where('tbl_client.gender', '!=', '2') - ->count(); - }); - // appointment by age - $appointment_to_nine = Cache::remember('appointment-to-nine', 10, function () { - return Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') - ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') - ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) > 0) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 9)) then `tbl_client`.`id` end)) AS count")) - ->pluck('count'); - }); - $appointment_to_fourteen = Cache::remember('appointment-to-fourteen', 10, function () { - return Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') - ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') - ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 10) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 14)) then `tbl_client`.`id` end)) AS count")) - ->pluck('count'); - }); - $appointment_to_nineteen = Cache::remember('appointment-to-nineteen', 10, function () { - return Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') - ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') - ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 15) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 19)) then `tbl_client`.`id` end)) AS count")) - ->pluck('count'); - }); - $appointment_to_twentyfour = Cache::remember('appointment-to-twentyfour', 10, function () { - return Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') - ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') - ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 20) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 24)) then `tbl_client`.`id` end)) AS count")) - ->pluck('count'); - }); - $appointment_to_twentyfive_above = Cache::remember('appointment-to-twentyfive-above', 10, function () { - return Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') - ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') - ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 25)) then `tbl_client`.`id` end)) AS count")) - ->pluck('count'); - }); - $appointment_uknown_age = Cache::remember('appointment-uknown-age', 10, function () { - return Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') - ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') - ->where('tbl_client.dob', '=', '') - ->orWhereNull('tbl_client.dob') - ->count(); - }); - - // Total missed appointment by gender - $appointment_total_missed_female = Cache::remember('appointment-total-missed-female', 10, function () { - return Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') - ->whereIn('tbl_appointment.app_status', ['Defaulted', 'LTFU', 'Missed']) - ->where('tbl_client.gender', '=', '1') - ->count(); - }); - $appointment_total_missed_male = Cache::remember('appointment-total-missed-male', 10, function () { - return Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') - ->where('tbl_client.gender', '=', '2') - ->whereIn('tbl_appointment.app_status', ['Defaulted', 'LTFU', 'Missed']) - ->count(); - }); - $appointment_total_missed_uknown_gender = Cache::remember('appointment-total-missed-uknown-gender', 10, function () { - return Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') - ->whereIn('tbl_appointment.app_status', ['Defaulted', 'LTFU', 'Missed']) - ->where('tbl_client.gender', '!=', '1') - ->where('tbl_client.gender', '!=', '2') - ->count(); - }); - - // Total missed appointment by age - $appointment_total_missed_to_nine = Cache::remember('appointment-total-missed-to-nine', 10, function () { - return Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') - ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) > 0) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 9)) then `tbl_client`.`id` end)) AS count")) - ->whereIn('tbl_appointment.app_status', ['Defaulted', 'LTFU', 'Missed']) - ->pluck('count'); - }); - $appointment_total_missed_to_fourteen = Cache::remember('appointment-total-missed-to-fourteen', 10, function () { - return Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') - ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 10) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 14)) then `tbl_client`.`id` end)) AS count")) - ->whereIn('tbl_appointment.app_status', ['Defaulted', 'LTFU', 'Missed']) - ->pluck('count'); - }); - $appointment_total_missed_to_nineteen = Cache::remember('appointment-total-missed-to-nineteen', 10, function () { - return Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') - ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 15) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 19)) then `tbl_client`.`id` end)) AS count")) - ->whereIn('tbl_appointment.app_status', ['Defaulted', 'LTFU', 'Missed']) - ->pluck('count'); - }); - $appointment_total_missed_to_twentyfour = Cache::remember('appointment-total-missed-to-twentyfour', 10, function () { - return Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') - ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 20) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 24)) then `tbl_client`.`id` end)) AS count")) - ->whereIn('tbl_appointment.app_status', ['Defaulted', 'LTFU', 'Missed']) - ->pluck('count'); - }); - $appointment_total_missed_to_twentyfive_above = Cache::remember('appointment-total-missed-to-twentyfive_above', 10, function () { - return Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') - ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 25)) then `tbl_client`.`id` end)) AS count")) - ->whereIn('tbl_appointment.app_status', ['Defaulted', 'LTFU', 'Missed']) - ->pluck('count'); - }); - $appointment_total_missed_uknown_age = Cache::remember('appointment-total-missed-uknown-age', 10, function () { - return Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') - ->where('tbl_client.dob', '=', '') - ->orWhereNull('tbl_client.dob') - ->whereIn('tbl_appointment.app_status', ['Defaulted', 'LTFU', 'Missed']) - ->count(); - }); - // client charts - $client_consented = Cache::remember('client-consented', 10, function () { - return Client::select('smsenable') - ->where('status', '=', 'Active') - ->whereNull('hei_no') - ->where('smsenable', '=', 'Yes') - ->count(); - }); - $client_nonconsented = Cache::remember('client-nonconsented', 10, function () { - return Client::select('smsenable') - ->where('status', '=', 'Active') - ->whereNull('hei_no') - ->where('smsenable', '!=', 'Yes') - ->count(); - }); - // consented clients by gender - - $client_consented_male = Cache::remember('client-consented-male', 10, function () { - return Client::where('smsenable', '=', 'Yes') - ->where('status', '=', 'Active') - ->whereNull('hei_no') - ->where('gender', '=', '2') - ->count(); - }); - $client_consented_female = Cache::remember('client-consented-female', 10, function () { - return Client::where('smsenable', '=', 'Yes') + $client_consented_female = Cache::remember('client-consented-female', 10, function () { + return Client::where('smsenable', '=', 'Yes') ->where('status', '=', 'Active') ->whereNull('hei_no') ->where('gender', '=', '1') @@ -1243,40 +988,10 @@ public function dashboard() // dd($active_facilities); - return view('new_dashboard.main_dashbaord', compact( + return view('new_dashboard.client_dashboard', compact( 'all_partners', - 'active_facilities', 'indicator', 'client', - 'appointment', - 'missed_appointment', - 'clients_male', - 'clients_female', - 'unknown_gender', - 'client_to_nine', - 'client_to_fourteen', - 'client_to_nineteen', - 'client_to_twentyfour', - 'client_to_twentyfive_above', - 'client_unknown_age', - 'appointment_male', - 'appointment_female', - 'appointment_uknown_gender', - 'appointment_to_nine', - 'appointment_to_fourteen', - 'appointment_to_nineteen', - 'appointment_to_twentyfour', - 'appointment_to_twentyfive_above', - 'appointment_uknown_age', - 'appointment_total_missed_female', - 'appointment_total_missed_male', - 'appointment_total_missed_uknown_gender', - 'appointment_total_missed_to_nine', - 'appointment_total_missed_to_fourteen', - 'appointment_total_missed_to_nineteen', - 'appointment_total_missed_to_twentyfour', - 'appointment_total_missed_to_twentyfive_above', - 'appointment_total_missed_uknown_age', 'client_consented', 'client_nonconsented', 'client_consented_male', @@ -1305,6 +1020,7 @@ public function appointment_charts() { if (Auth::user()->access_level == 'Facility') { $all_partners = Partner::where('status', '=', 'Active')->pluck('name', 'id'); + $indicator = Indicator::select(['name', 'description'])->get(); // main appointments $appointment = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') ->select('tbl_appointment.id') @@ -1442,235 +1158,58 @@ public function appointment_charts() ->where('tbl_client.mfl_code', Auth::user()->facility_id) ->count(); - // missed appointments - - $appointment_missed = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') - ->where('tbl_appointment.app_status', '=', 'Missed') - ->where('tbl_client.mfl_code', Auth::user()->facility_id) - ->count(); - $appointment_defaulted = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') - ->where('tbl_appointment.app_status', '=', 'Defaulted') - ->where('tbl_client.mfl_code', Auth::user()->facility_id) - ->count(); - $appointment_lftu = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') - ->where('tbl_appointment.app_status', '=', 'LTFU') - ->where('tbl_client.mfl_code', Auth::user()->facility_id) + } + if (Auth::user()->access_level == 'Partner') { + $all_partners = Partner::where('status', '=', 'Active')->pluck('name', 'id'); + $indicator = Indicator::select(['name', 'description'])->get(); + // main appointments + $appointment = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select('tbl_appointment.id') + ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) + ->count(); + $appointment_honoured = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select('tbl_appointment.id') + ->where('tbl_appointment.date_attended', '=', DB::raw('tbl_appointment.appntmnt_date')) + ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) ->count(); - // missed appointment by gender - $appointment_missed_female = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') - ->where('tbl_appointment.app_status', '=', 'Missed') - ->where('tbl_client.gender', '=', '1') - ->where('tbl_client.mfl_code', Auth::user()->facility_id) + // dd($appointment_honoured); + $appointment_not_honoured = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select('tbl_appointment.id') + ->whereIn('tbl_appointment.app_status', ['Defaulted', 'LTFU', 'Missed']) + ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) ->count(); - $appointment_missed_male = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') - ->where('tbl_appointment.app_status', '=', 'Missed') + + // appointment honored by gender + $appointment_honoured_male = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select(\DB::raw("COUNT(tbl_appointment.id) as count")) + ->where('tbl_appointment.date_attended', '=', DB::raw('tbl_appointment.appntmnt_date')) ->where('tbl_client.gender', '=', '2') - ->where('tbl_client.mfl_code', Auth::user()->facility_id) + ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) + ->pluck('count'); + $appointment_honoured_female = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->where('tbl_appointment.date_attended', '=', DB::raw('tbl_appointment.appntmnt_date')) + ->where('tbl_client.gender', '=', '1') + ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) ->count(); - - $appointment_missed_uknown_gender = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') - ->where('tbl_appointment.app_status', '=', 'Missed') + $appointment_honoured_uknown_gender = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->where('tbl_appointment.date_attended', '=', DB::raw('tbl_appointment.appntmnt_date')) ->where('tbl_client.gender', '!=', '1') ->where('tbl_client.gender', '!=', '2') - ->where('tbl_client.mfl_code', Auth::user()->facility_id) + ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) ->count(); - - // missed appointment by age - $appointment_missed_to_nine = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') - ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) > 0) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 9)) then `tbl_client`.`id` end)) AS count")) - ->where('tbl_appointment.app_status', '=', 'Missed') - ->where('tbl_client.mfl_code', Auth::user()->facility_id) - ->pluck('count'); - $appointment_missed_to_fourteen = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') - ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 10) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 14)) then `tbl_client`.`id` end)) AS count")) - ->where('tbl_appointment.app_status', '=', 'Missed') - ->where('tbl_client.mfl_code', Auth::user()->facility_id) - ->pluck('count'); - - $appointment_missed_to_nineteen = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') - ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 15) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 19)) then `tbl_client`.`id` end)) AS count")) - ->where('tbl_appointment.app_status', '=', 'Missed') - ->where('tbl_client.mfl_code', Auth::user()->facility_id) - ->pluck('count'); - $appointment_missed_to_twentyfour = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') - ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 20) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 24)) then `tbl_client`.`id` end)) AS count")) - ->where('tbl_appointment.app_status', '=', 'Missed') - ->where('tbl_client.mfl_code', Auth::user()->facility_id) - ->pluck('count'); - $appointment_missed_to_twentyfive_above = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') - ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 25)) then `tbl_client`.`id` end)) AS count")) - ->where('tbl_appointment.app_status', '=', 'Missed') - ->where('tbl_client.mfl_code', Auth::user()->facility_id) - ->pluck('count'); - $appointment_missed_to_uknown_age = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') - ->select('tbl_client.dob') - ->where('tbl_client.dob', '=', '') - ->orWhereNull('tbl_client.dob') - ->where('tbl_appointment.app_status', '=', 'Missed') - ->where('tbl_client.mfl_code', Auth::user()->facility_id) - ->count(); - - // defaulted appointment by gender - $appointment_defaulted_female = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') - ->where('tbl_appointment.app_status', '=', 'Defaulted') - ->where('tbl_client.gender', '=', '1') - ->where('tbl_client.mfl_code', Auth::user()->facility_id) - ->count(); - $appointment_defaulted_male = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') - ->where('tbl_appointment.app_status', '=', 'Defaulted') - ->where('tbl_client.gender', '=', '2') - ->where('tbl_client.mfl_code', Auth::user()->facility_id) - ->count(); - - $appointment_defaulted_uknown_gender = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') - ->where('tbl_appointment.app_status', '=', 'Defaulted') - ->where('tbl_client.gender', '!=', '1') - ->where('tbl_client.gender', '!=', '2') - ->where('tbl_client.mfl_code', Auth::user()->facility_id) - ->count(); - // defaulted appointment by age - $appointment_defaulted_to_nine = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') - ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) > 0) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 9)) then `tbl_client`.`id` end)) AS count")) - ->where('tbl_appointment.app_status', '=', 'Defaulted') - ->where('tbl_client.mfl_code', Auth::user()->facility_id) - ->pluck('count'); - $appointment_defaulted_to_fourteen = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') - ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 10) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 14)) then `tbl_client`.`id` end)) AS count")) - ->where('tbl_appointment.app_status', '=', 'Defaulted') - ->where('tbl_client.mfl_code', Auth::user()->facility_id) - ->pluck('count'); - $appointment_defaulted_to_nineteen = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') - ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 15) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 19)) then `tbl_client`.`id` end)) AS count")) - ->where('tbl_appointment.app_status', '=', 'Defaulted') - ->where('tbl_client.mfl_code', Auth::user()->facility_id) - ->pluck('count'); - $appointment_defaulted_to_twentyfour = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') - ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 20) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 24)) then `tbl_client`.`id` end)) AS count")) - ->where('tbl_appointment.app_status', '=', 'Defaulted') - ->where('tbl_client.mfl_code', Auth::user()->facility_id) - ->pluck('count'); - - $appointment_defaulted_to_twentyfive_above = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') - ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 25)) then `tbl_client`.`id` end)) AS count")) - ->where('tbl_appointment.app_status', '=', 'Defaulted') - ->where('tbl_client.mfl_code', Auth::user()->facility_id) - ->pluck('count'); - - $appointment_defaulted_to_uknown_age = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') - ->select('tbl_client.dob') - ->where('tbl_client.dob', '=', '') - ->orWhereNull('tbl_client.dob') - ->where('tbl_appointment.app_status', '=', 'Defaulted') - ->where('tbl_client.mfl_code', Auth::user()->facility_id) - ->count(); - // ltfu appointment by gender - $appointment_ltfu_female = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') - ->where('tbl_appointment.app_status', '=', 'LTFU') - ->where('tbl_client.gender', '=', '1') - ->where('tbl_client.mfl_code', Auth::user()->facility_id) - ->count(); - - $appointment_ltfu_male = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') - ->where('tbl_appointment.app_status', '=', 'LTFU') - ->where('tbl_client.gender', '=', '2') - ->where('tbl_client.mfl_code', Auth::user()->facility_id) - ->count(); - $appointment_ltfu_uknown_gender = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') - ->where('tbl_appointment.app_status', '=', 'LTFU') - ->where('tbl_client.gender', '!=', '1') - ->where('tbl_client.gender', '!=', '2') - ->where('tbl_client.mfl_code', Auth::user()->facility_id) - ->count(); - - // ltfu appointment by age - $appointment_ltfu_to_nine = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') - ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) > 0) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 9)) then `tbl_client`.`id` end)) AS count")) - ->where('tbl_appointment.app_status', '=', 'LTFU') - ->where('tbl_client.mfl_code', Auth::user()->facility_id) - ->pluck('count'); - - $appointment_ltfu_to_fourteen = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') - ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 10) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 14)) then `tbl_client`.`id` end)) AS count")) - ->where('tbl_appointment.app_status', '=', 'LTFU') - ->where('tbl_client.mfl_code', Auth::user()->facility_id) - ->pluck('count'); - - $appointment_ltfu_to_nineteen = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') - ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 15) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 19)) then `tbl_client`.`id` end)) AS count")) - ->where('tbl_appointment.app_status', '=', 'LTFU') - ->where('tbl_client.mfl_code', Auth::user()->facility_id) - ->pluck('count'); - - $appointment_ltfu_to_twentyfour = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') - ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 20) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 24)) then `tbl_client`.`id` end)) AS count")) - ->where('tbl_appointment.app_status', '=', 'LTFU') - ->where('tbl_client.mfl_code', Auth::user()->facility_id) - ->pluck('count'); - $appointment_ltfu_to_twentyfive_above = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') - ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 25)) then `tbl_client`.`id` end)) AS count")) - ->where('tbl_appointment.app_status', '=', 'LTFU') - ->where('tbl_client.mfl_code', Auth::user()->facility_id) - ->pluck('count'); - - $appointment_ltfu_to_uknown_age = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') - ->select('tbl_client.dob') - ->where('tbl_client.dob', '=', '') - ->orWhereNull('tbl_client.dob') - ->where('tbl_appointment.app_status', '=', 'LTFU') - ->where('tbl_client.mfl_code', Auth::user()->facility_id) - ->count(); - } - if (Auth::user()->access_level == 'Partner') { - $all_partners = Partner::where('status', '=', 'Active')->pluck('name', 'id'); - // main appointments - $appointment = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') - ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') - ->select('tbl_appointment.id') - ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) - ->count(); - $appointment_honoured = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') - ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') - ->select('tbl_appointment.id') - ->where('tbl_appointment.date_attended', '=', DB::raw('tbl_appointment.appntmnt_date')) - ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) - ->count(); - - // dd($appointment_honoured); - $appointment_not_honoured = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') - ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') - ->select('tbl_appointment.id') - ->whereIn('tbl_appointment.app_status', ['Defaulted', 'LTFU', 'Missed']) - ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) - ->count(); - - // appointment honored by gender - $appointment_honoured_male = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') - ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') - ->select(\DB::raw("COUNT(tbl_appointment.id) as count")) - ->where('tbl_appointment.date_attended', '=', DB::raw('tbl_appointment.appntmnt_date')) - ->where('tbl_client.gender', '=', '2') - ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) - ->pluck('count'); - $appointment_honoured_female = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') - ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') - ->where('tbl_appointment.date_attended', '=', DB::raw('tbl_appointment.appntmnt_date')) - ->where('tbl_client.gender', '=', '1') - ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) - ->count(); - $appointment_honoured_uknown_gender = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') - ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') - ->where('tbl_appointment.date_attended', '=', DB::raw('tbl_appointment.appntmnt_date')) - ->where('tbl_client.gender', '!=', '1') - ->where('tbl_client.gender', '!=', '2') - ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) - ->count(); - // appointment honored by age - $appointment_honored_to_nine = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') - ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') - ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) > 0) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 9)) then `tbl_client`.`id` end)) AS count")) - ->where('tbl_appointment.date_attended', '=', DB::raw('tbl_appointment.appntmnt_date')) - ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) + // appointment honored by age + $appointment_honored_to_nine = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) > 0) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 9)) then `tbl_client`.`id` end)) AS count")) + ->where('tbl_appointment.date_attended', '=', DB::raw('tbl_appointment.appntmnt_date')) + ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) ->pluck('count'); $appointment_honored_to_fourteen = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') @@ -1771,470 +1310,705 @@ public function appointment_charts() ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) ->count(); - // missed appointments - $appointment_missed = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') - ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') - ->where('tbl_appointment.app_status', '=', 'Missed') - ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) - ->count(); - $appointment_defaulted = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') - ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') - ->where('tbl_appointment.app_status', '=', 'Defaulted') - ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) + } + + if (Auth::user()->access_level == 'Admin' || Auth::user()->access_level == 'Donor') { + $all_partners = Partner::where('status', '=', 'Active')->pluck('name', 'id'); + $indicator = Indicator::select(['name', 'description'])->get(); + // main appointments + $appointment = Appointments::select('id') ->count(); - $appointment_lftu = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') - ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') - ->where('tbl_appointment.app_status', '=', 'LTFU') - ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) + $appointment_honoured = Appointments::select('id') + ->where('date_attended', '=', DB::raw('appntmnt_date')) ->count(); - - // missed appointment by gender - $appointment_missed_female = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') - ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') - ->where('tbl_appointment.app_status', '=', 'Missed') - ->where('tbl_client.gender', '=', '1') - ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) + // dd($appointment_honoured); + $appointment_not_honoured = Appointments::select('id') + ->whereIn('app_status', ['Defaulted', 'LTFU', 'Missed']) ->count(); - $appointment_missed_male = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') - ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') - ->where('tbl_appointment.app_status', '=', 'Missed') + + // appointment honored by gender + $appointment_honoured_male = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->select('tbl_appointment.id') + ->where('tbl_appointment.date_attended', '=', DB::raw('tbl_appointment.appntmnt_date')) ->where('tbl_client.gender', '=', '2') - ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) ->count(); - - $appointment_missed_uknown_gender = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') - ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') - ->where('tbl_appointment.app_status', '=', 'Missed') + $appointment_honoured_female = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->where('tbl_appointment.date_attended', '=', DB::raw('tbl_appointment.appntmnt_date')) + ->where('tbl_client.gender', '=', '1') + ->count(); + $appointment_honoured_uknown_gender = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->where('tbl_appointment.date_attended', '=', DB::raw('tbl_appointment.appntmnt_date')) ->where('tbl_client.gender', '!=', '1') ->where('tbl_client.gender', '!=', '2') - ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) ->count(); - - // missed appointment by age - $appointment_missed_to_nine = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') - ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') - ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) > 0) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 9)) then `tbl_client`.`id` end)) AS count")) - ->where('tbl_appointment.app_status', '=', 'Missed') - ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) - ->pluck('count'); - $appointment_missed_to_fourteen = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') - ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') - ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 10) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 14)) then `tbl_client`.`id` end)) AS count")) - ->where('tbl_appointment.app_status', '=', 'Missed') - ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) + // appointment honored by age + $appointment_honored_to_nine = Cache::remember('appointment-honored-to-nine', 10, function () { + return Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) > 0) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 9)) then `tbl_client`.`id` end)) AS count")) + ->where('tbl_appointment.date_attended', '=', DB::raw('tbl_appointment.appntmnt_date')) + ->pluck('count'); + }); + $appointment_honored_to_fourteen = Cache::remember('appointment-honored-to-fourteen', 10, function () { + return Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 10) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 14)) then `tbl_client`.`id` end)) AS count")) + ->where('tbl_appointment.date_attended', '=', DB::raw('tbl_appointment.appntmnt_date')) + ->pluck('count'); + }); + $appointment_honored_to_nineteen = Cache::remember('appointment-honored-to-nineteen', 10, function () { + return Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 15) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 19)) then `tbl_client`.`id` end)) AS count")) + ->where('tbl_appointment.date_attended', '=', DB::raw('tbl_appointment.appntmnt_date')) + ->pluck('count'); + }); + $appointment_honored_to_twentyfour = Cache::remember('appointment-honored-to-twentyfour', 10, function () { + return Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 20) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 24)) then `tbl_client`.`id` end)) AS count")) + ->where('tbl_appointment.date_attended', '=', DB::raw('tbl_appointment.appntmnt_date')) + ->pluck('count'); + }); + $appointment_honored_to_twentyfive_above = Cache::remember('appointment-honored-to-twentyfive_above', 10, function () { + return Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 25)) then `tbl_client`.`id` end)) AS count")) + ->where('tbl_appointment.date_attended', '=', DB::raw('tbl_appointment.appntmnt_date')) + ->pluck('count'); + }); + $appointment_honored_to_uknown_age = Cache::remember('appointment_honored-to-uknown-age', 10, function () { + return Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->select('tbl_client.dob') + ->where('tbl_appointment.date_attended', '=', DB::raw('tbl_appointment.appntmnt_date')) + ->where('tbl_client.dob', '=', '') + ->orWhereNull('tbl_client.dob') + ->count(); + }); + + // appointment not honored by gender + $appointment_not_honoured_male = Cache::remember('appointment-not-honoured-male', 10, function () { + return Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->where('tbl_client.gender', '=', '2') + ->whereIn('app_status', ['Defaulted', 'LTFU', 'Missed']) + ->count(); + }); + $appointment_not_honoured_female = Cache::remember('appointment-not-honoured-female', 10, function () { + return Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->where('tbl_client.gender', '=', '1') + ->whereIn('app_status', ['Defaulted', 'LTFU', 'Missed']) + ->count(); + }); + $appointment_not_honoured_uknown_gender = Cache::remember('appointment-not-honoured-uknown-gender', 10, function () { + return Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->where('tbl_client.gender', '!=', '1') + ->where('tbl_client.gender', '!=', '2') + ->whereIn('app_status', ['Defaulted', 'LTFU', 'Missed']) + ->count(); + }); + // appointment not honored by age + $appointment_not_honored_to_nine = Cache::remember('appointment-not-honored-to-nine', 10, function () { + return Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) > 0) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 9)) then `tbl_client`.`id` end)) AS count")) + ->whereIn('app_status', ['Defaulted', 'LTFU', 'Missed']) + ->pluck('count'); + }); + $appointment_not_honored_to_fourteen = Cache::remember('appointment-not-honored-to-fourteen', 10, function () { + return Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 10) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 14)) then `tbl_client`.`id` end)) AS count")) + ->whereIn('app_status', ['Defaulted', 'LTFU', 'Missed']) + ->pluck('count'); + }); + $appointment_not_honored_to_nineteen = Cache::remember('appointment_not_honored_to_nineteen', 10, function () { + return Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 15) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 19)) then `tbl_client`.`id` end)) AS count")) + ->whereIn('app_status', ['Defaulted', 'LTFU', 'Missed']) + ->pluck('count'); + }); + $appointment_not_honored_to_twentyfour = Cache::remember('appointment_not_honored_to_twentyfour', 10, function () { + return Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 20) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 24)) then `tbl_client`.`id` end)) AS count")) + ->whereIn('app_status', ['Defaulted', 'LTFU', 'Missed']) + ->pluck('count'); + }); + $appointment_not_honored_to_twentyfive_above = Cache::remember('appointment_not_honored_to_twentyfive_above', 10, function () { + return Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 25)) then `tbl_client`.`id` end)) AS count")) + ->whereIn('app_status', ['Defaulted', 'LTFU', 'Missed']) + ->pluck('count'); + }); + $appointment_not_honored_to_uknown_age = Cache::remember('appointment_not_honored_to_uknown_age', 10, function () { + return Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->select('tbl_client.dob') + ->where('tbl_client.dob', '=', '') + ->orWhereNull('tbl_client.dob') + ->whereIn('app_status', ['Defaulted', 'LTFU', 'Missed']) + ->count(); + }); + + } + + + return view('new_dashboard.appointment_dashboard', compact('all_partners', 'indicator', 'appointment', 'appointment_honoured', + 'appointment_not_honoured', + 'appointment_honoured_male', + 'appointment_honoured_female', + 'appointment_honoured_uknown_gender', + 'appointment_honored_to_nine', + 'appointment_honored_to_fourteen', + 'appointment_honored_to_nineteen', + 'appointment_honored_to_twentyfour', + 'appointment_honored_to_twentyfive_above', + 'appointment_honored_to_uknown_age', + 'appointment_not_honoured_male', + 'appointment_not_honoured_female', + 'appointment_not_honoured_uknown_gender', + 'appointment_not_honored_to_nine', + 'appointment_not_honored_to_fourteen', + 'appointment_not_honored_to_nineteen', + 'appointment_not_honored_to_twentyfour', + 'appointment_not_honored_to_twentyfive_above', + 'appointment_not_honored_to_uknown_age', + )); + } + public function missed_appointment_charts() + { + if (Auth::user()->access_level == 'Facility') { + $all_partners = Partner::where('status', '=', 'Active')->pluck('name', 'id'); + $indicator = Indicator::select(['name', 'description'])->get(); + + // dd($appointment_honoured); + $appointment_not_honoured = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->select('tbl_appointment.id') + ->whereIn('tbl_appointment.app_status', ['Defaulted', 'LTFU', 'Missed']) + ->where('tbl_client.mfl_code', Auth::user()->facility_id) + ->count(); + + // missed appointments + + $appointment_missed = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->where('tbl_appointment.app_status', '=', 'Missed') + ->where('tbl_client.mfl_code', Auth::user()->facility_id) + ->count(); + $appointment_defaulted = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->where('tbl_appointment.app_status', '=', 'Defaulted') + ->where('tbl_client.mfl_code', Auth::user()->facility_id) + ->count(); + $appointment_lftu = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->where('tbl_appointment.app_status', '=', 'LTFU') + ->where('tbl_client.mfl_code', Auth::user()->facility_id) + ->count(); + + // missed appointment by gender + $appointment_missed_female = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->where('tbl_appointment.app_status', '=', 'Missed') + ->where('tbl_client.gender', '=', '1') + ->where('tbl_client.mfl_code', Auth::user()->facility_id) + ->count(); + $appointment_missed_male = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->where('tbl_appointment.app_status', '=', 'Missed') + ->where('tbl_client.gender', '=', '2') + ->where('tbl_client.mfl_code', Auth::user()->facility_id) + ->count(); + + $appointment_missed_uknown_gender = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->where('tbl_appointment.app_status', '=', 'Missed') + ->where('tbl_client.gender', '!=', '1') + ->where('tbl_client.gender', '!=', '2') + ->where('tbl_client.mfl_code', Auth::user()->facility_id) + ->count(); + + // missed appointment by age + $appointment_missed_to_nine = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) > 0) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 9)) then `tbl_client`.`id` end)) AS count")) + ->where('tbl_appointment.app_status', '=', 'Missed') + ->where('tbl_client.mfl_code', Auth::user()->facility_id) + ->pluck('count'); + $appointment_missed_to_fourteen = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 10) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 14)) then `tbl_client`.`id` end)) AS count")) + ->where('tbl_appointment.app_status', '=', 'Missed') + ->where('tbl_client.mfl_code', Auth::user()->facility_id) ->pluck('count'); $appointment_missed_to_nineteen = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') - ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 15) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 19)) then `tbl_client`.`id` end)) AS count")) ->where('tbl_appointment.app_status', '=', 'Missed') - ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) + ->where('tbl_client.mfl_code', Auth::user()->facility_id) ->pluck('count'); $appointment_missed_to_twentyfour = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') - ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 20) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 24)) then `tbl_client`.`id` end)) AS count")) ->where('tbl_appointment.app_status', '=', 'Missed') - ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) + ->where('tbl_client.mfl_code', Auth::user()->facility_id) ->pluck('count'); $appointment_missed_to_twentyfive_above = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') - ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 25)) then `tbl_client`.`id` end)) AS count")) ->where('tbl_appointment.app_status', '=', 'Missed') - ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) + ->where('tbl_client.mfl_code', Auth::user()->facility_id) ->pluck('count'); $appointment_missed_to_uknown_age = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') - ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') ->select('tbl_client.dob') ->where('tbl_client.dob', '=', '') ->orWhereNull('tbl_client.dob') ->where('tbl_appointment.app_status', '=', 'Missed') - ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) + ->where('tbl_client.mfl_code', Auth::user()->facility_id) ->count(); // defaulted appointment by gender $appointment_defaulted_female = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') - ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') ->where('tbl_appointment.app_status', '=', 'Defaulted') ->where('tbl_client.gender', '=', '1') - ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) + ->where('tbl_client.mfl_code', Auth::user()->facility_id) ->count(); $appointment_defaulted_male = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') - ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') ->where('tbl_appointment.app_status', '=', 'Defaulted') ->where('tbl_client.gender', '=', '2') - ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) + ->where('tbl_client.mfl_code', Auth::user()->facility_id) ->count(); $appointment_defaulted_uknown_gender = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') - ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') ->where('tbl_appointment.app_status', '=', 'Defaulted') ->where('tbl_client.gender', '!=', '1') ->where('tbl_client.gender', '!=', '2') - ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) + ->where('tbl_client.mfl_code', Auth::user()->facility_id) ->count(); // defaulted appointment by age $appointment_defaulted_to_nine = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') - ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) > 0) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 9)) then `tbl_client`.`id` end)) AS count")) ->where('tbl_appointment.app_status', '=', 'Defaulted') - ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) + ->where('tbl_client.mfl_code', Auth::user()->facility_id) ->pluck('count'); $appointment_defaulted_to_fourteen = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') - ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 10) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 14)) then `tbl_client`.`id` end)) AS count")) ->where('tbl_appointment.app_status', '=', 'Defaulted') - ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) + ->where('tbl_client.mfl_code', Auth::user()->facility_id) ->pluck('count'); $appointment_defaulted_to_nineteen = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') - ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 15) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 19)) then `tbl_client`.`id` end)) AS count")) ->where('tbl_appointment.app_status', '=', 'Defaulted') - ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) + ->where('tbl_client.mfl_code', Auth::user()->facility_id) ->pluck('count'); $appointment_defaulted_to_twentyfour = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') - ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 20) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 24)) then `tbl_client`.`id` end)) AS count")) ->where('tbl_appointment.app_status', '=', 'Defaulted') - ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) + ->where('tbl_client.mfl_code', Auth::user()->facility_id) ->pluck('count'); $appointment_defaulted_to_twentyfive_above = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') - ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 25)) then `tbl_client`.`id` end)) AS count")) ->where('tbl_appointment.app_status', '=', 'Defaulted') - ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) + ->where('tbl_client.mfl_code', Auth::user()->facility_id) ->pluck('count'); $appointment_defaulted_to_uknown_age = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') - ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') ->select('tbl_client.dob') ->where('tbl_client.dob', '=', '') ->orWhereNull('tbl_client.dob') ->where('tbl_appointment.app_status', '=', 'Defaulted') - ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) + ->where('tbl_client.mfl_code', Auth::user()->facility_id) ->count(); // ltfu appointment by gender $appointment_ltfu_female = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') - ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') ->where('tbl_appointment.app_status', '=', 'LTFU') ->where('tbl_client.gender', '=', '1') - ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) + ->where('tbl_client.mfl_code', Auth::user()->facility_id) ->count(); $appointment_ltfu_male = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') - ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') ->where('tbl_appointment.app_status', '=', 'LTFU') ->where('tbl_client.gender', '=', '2') - ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) + ->where('tbl_client.mfl_code', Auth::user()->facility_id) ->count(); $appointment_ltfu_uknown_gender = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') - ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') ->where('tbl_appointment.app_status', '=', 'LTFU') ->where('tbl_client.gender', '!=', '1') ->where('tbl_client.gender', '!=', '2') - ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) + ->where('tbl_client.mfl_code', Auth::user()->facility_id) ->count(); // ltfu appointment by age $appointment_ltfu_to_nine = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') - ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) > 0) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 9)) then `tbl_client`.`id` end)) AS count")) ->where('tbl_appointment.app_status', '=', 'LTFU') - ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) + ->where('tbl_client.mfl_code', Auth::user()->facility_id) ->pluck('count'); $appointment_ltfu_to_fourteen = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') - ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 10) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 14)) then `tbl_client`.`id` end)) AS count")) ->where('tbl_appointment.app_status', '=', 'LTFU') - ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) + ->where('tbl_client.mfl_code', Auth::user()->facility_id) ->pluck('count'); $appointment_ltfu_to_nineteen = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') - ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 15) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 19)) then `tbl_client`.`id` end)) AS count")) ->where('tbl_appointment.app_status', '=', 'LTFU') - ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) + ->where('tbl_client.mfl_code', Auth::user()->facility_id) ->pluck('count'); $appointment_ltfu_to_twentyfour = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') - ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 20) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 24)) then `tbl_client`.`id` end)) AS count")) ->where('tbl_appointment.app_status', '=', 'LTFU') - ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) + ->where('tbl_client.mfl_code', Auth::user()->facility_id) ->pluck('count'); $appointment_ltfu_to_twentyfive_above = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') - ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 25)) then `tbl_client`.`id` end)) AS count")) ->where('tbl_appointment.app_status', '=', 'LTFU') - ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) + ->where('tbl_client.mfl_code', Auth::user()->facility_id) ->pluck('count'); $appointment_ltfu_to_uknown_age = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') - ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') ->select('tbl_client.dob') ->where('tbl_client.dob', '=', '') ->orWhereNull('tbl_client.dob') ->where('tbl_appointment.app_status', '=', 'LTFU') - ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) + ->where('tbl_client.mfl_code', Auth::user()->facility_id) ->count(); } - - if (Auth::user()->access_level == 'Admin' || Auth::user()->access_level == 'Donor') { + if (Auth::user()->access_level == 'Partner') { $all_partners = Partner::where('status', '=', 'Active')->pluck('name', 'id'); - // main appointments - $appointment = Appointments::select('id') - ->count(); - $appointment_honoured = Cache::remember('appointment-honoured', 10, function () { - return Appointments::select(\DB::raw("COUNT(id) as count")) - ->where('date_attended', '=', DB::raw('appntmnt_date')) - ->pluck('count'); - }); - // dd($appointment_honoured); - $appointment_not_honoured = Cache::remember('appointment-not-honoured', 10, function () { - return Appointments::select(\DB::raw("COUNT(id) as count")) - ->whereIn('app_status', ['Defaulted', 'LTFU', 'Missed']) - ->pluck('count'); - }); - - // appointment honored by gender - $appointment_honoured_male = Cache::remember('appointment-honoured-male', 10, function () { - return Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') - ->select(\DB::raw("COUNT(tbl_appointment.id) as count")) - ->where('tbl_appointment.date_attended', '=', DB::raw('tbl_appointment.appntmnt_date')) - ->where('tbl_client.gender', '=', '2') - ->pluck('count'); - }); - $appointment_honoured_female = Cache::remember('appointment-honoured-female', 10, function () { - return Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') - ->where('tbl_appointment.date_attended', '=', DB::raw('tbl_appointment.appntmnt_date')) - ->where('tbl_client.gender', '=', '1') - ->count(); - }); - $appointment_honoured_uknown_gender = Cache::remember('appointment-honoured-uknown-gender', 10, function () { - return Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') - ->where('tbl_appointment.date_attended', '=', DB::raw('tbl_appointment.appntmnt_date')) - ->where('tbl_client.gender', '!=', '1') - ->where('tbl_client.gender', '!=', '2') - ->count(); - }); - // appointment honored by age - $appointment_honored_to_nine = Cache::remember('appointment-honored-to-nine', 10, function () { - return Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') - ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') - ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) > 0) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 9)) then `tbl_client`.`id` end)) AS count")) - ->where('tbl_appointment.date_attended', '=', DB::raw('tbl_appointment.appntmnt_date')) - ->pluck('count'); - }); - $appointment_honored_to_fourteen = Cache::remember('appointment-honored-to-fourteen', 10, function () { - return Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') - ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') - ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 10) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 14)) then `tbl_client`.`id` end)) AS count")) - ->where('tbl_appointment.date_attended', '=', DB::raw('tbl_appointment.appntmnt_date')) - ->pluck('count'); - }); - $appointment_honored_to_nineteen = Cache::remember('appointment-honored-to-nineteen', 10, function () { - return Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') - ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') - ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 15) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 19)) then `tbl_client`.`id` end)) AS count")) - ->where('tbl_appointment.date_attended', '=', DB::raw('tbl_appointment.appntmnt_date')) - ->pluck('count'); - }); - $appointment_honored_to_twentyfour = Cache::remember('appointment-honored-to-twentyfour', 10, function () { - return Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') - ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') - ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 20) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 24)) then `tbl_client`.`id` end)) AS count")) - ->where('tbl_appointment.date_attended', '=', DB::raw('tbl_appointment.appntmnt_date')) - ->pluck('count'); - }); - $appointment_honored_to_twentyfive_above = Cache::remember('appointment-honored-to-twentyfive_above', 10, function () { - return Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') - ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') - ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 25)) then `tbl_client`.`id` end)) AS count")) - ->where('tbl_appointment.date_attended', '=', DB::raw('tbl_appointment.appntmnt_date')) - ->pluck('count'); - }); - $appointment_honored_to_uknown_age = Cache::remember('appointment_honored-to-uknown-age', 10, function () { - return Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') - ->select('tbl_client.dob') - ->where('tbl_appointment.date_attended', '=', DB::raw('tbl_appointment.appntmnt_date')) - ->where('tbl_client.dob', '=', '') - ->orWhereNull('tbl_client.dob') - ->count(); - }); + $indicator = Indicator::select(['name', 'description'])->get(); - // appointment not honored by gender - $appointment_not_honoured_male = Cache::remember('appointment-not-honoured-male', 10, function () { - return Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') - ->where('tbl_client.gender', '=', '2') - ->whereIn('app_status', ['Defaulted', 'LTFU', 'Missed']) - ->count(); - }); - $appointment_not_honoured_female = Cache::remember('appointment-not-honoured-female', 10, function () { - return Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') - ->where('tbl_client.gender', '=', '1') - ->whereIn('app_status', ['Defaulted', 'LTFU', 'Missed']) - ->count(); - }); - $appointment_not_honoured_uknown_gender = Cache::remember('appointment-not-honoured-uknown-gender', 10, function () { - return Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') - ->where('tbl_client.gender', '!=', '1') - ->where('tbl_client.gender', '!=', '2') - ->whereIn('app_status', ['Defaulted', 'LTFU', 'Missed']) - ->count(); - }); - // appointment not honored by age - $appointment_not_honored_to_nine = Cache::remember('appointment-not-honored-to-nine', 10, function () { - return Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') - ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') - ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) > 0) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 9)) then `tbl_client`.`id` end)) AS count")) - ->whereIn('app_status', ['Defaulted', 'LTFU', 'Missed']) - ->pluck('count'); - }); - $appointment_not_honored_to_fourteen = Cache::remember('appointment-not-honored-to-fourteen', 10, function () { - return Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') - ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') - ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 10) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 14)) then `tbl_client`.`id` end)) AS count")) - ->whereIn('app_status', ['Defaulted', 'LTFU', 'Missed']) - ->pluck('count'); - }); - $appointment_not_honored_to_nineteen = Cache::remember('appointment_not_honored_to_nineteen', 10, function () { - return Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') - ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') - ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 15) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 19)) then `tbl_client`.`id` end)) AS count")) - ->whereIn('app_status', ['Defaulted', 'LTFU', 'Missed']) - ->pluck('count'); - }); - $appointment_not_honored_to_twentyfour = Cache::remember('appointment_not_honored_to_twentyfour', 10, function () { - return Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') - ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') - ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 20) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 24)) then `tbl_client`.`id` end)) AS count")) - ->whereIn('app_status', ['Defaulted', 'LTFU', 'Missed']) - ->pluck('count'); - }); - $appointment_not_honored_to_twentyfive_above = Cache::remember('appointment_not_honored_to_twentyfive_above', 10, function () { - return Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') - ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') - ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 25)) then `tbl_client`.`id` end)) AS count")) - ->whereIn('app_status', ['Defaulted', 'LTFU', 'Missed']) - ->pluck('count'); - }); - $appointment_not_honored_to_uknown_age = Cache::remember('appointment_not_honored_to_uknown_age', 10, function () { - return Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') - ->select('tbl_client.dob') - ->where('tbl_client.dob', '=', '') - ->orWhereNull('tbl_client.dob') - ->whereIn('app_status', ['Defaulted', 'LTFU', 'Missed']) + // dd($appointment_honoured); + $appointment_not_honoured = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select('tbl_appointment.id') + ->whereIn('tbl_appointment.app_status', ['Defaulted', 'LTFU', 'Missed']) + ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) ->count(); - }); // missed appointments - $appointment_missed = Cache::remember('appointment_missed', 10, function () { - return Appointments::where('app_status', '=', 'Missed') - ->count(); - }); - $appointment_defaulted = Cache::remember('appointment_defaulted', 10, function () { - return Appointments::where('app_status', '=', 'Defaulted') - ->count(); - }); - $appointment_lftu = Cache::remember('appointment_lftu', 10, function () { - return Appointments::where('app_status', '=', 'LTFU') - ->count(); - }); + $appointment_missed = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->where('tbl_appointment.app_status', '=', 'Missed') + ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) + ->count(); + $appointment_defaulted = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->where('tbl_appointment.app_status', '=', 'Defaulted') + ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) + ->count(); + $appointment_lftu = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->where('tbl_appointment.app_status', '=', 'LTFU') + ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) + ->count(); // missed appointment by gender - $appointment_missed_female = Cache::remember('appointment_missed_female', 10, function () { - return Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + $appointment_missed_female = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') ->where('tbl_appointment.app_status', '=', 'Missed') ->where('tbl_client.gender', '=', '1') + ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) ->count(); - }); - $appointment_missed_male = Cache::remember('appointment_missed_male', 10, function () { - return Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + $appointment_missed_male = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') ->where('tbl_appointment.app_status', '=', 'Missed') ->where('tbl_client.gender', '=', '2') + ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) ->count(); - }); - $appointment_missed_uknown_gender = Cache::remember('appointment_missed_uknown_gender', 10, function () { - return Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + + $appointment_missed_uknown_gender = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') ->where('tbl_appointment.app_status', '=', 'Missed') ->where('tbl_client.gender', '!=', '1') ->where('tbl_client.gender', '!=', '2') + ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) ->count(); - }); + // missed appointment by age - $appointment_missed_to_nine = Cache::remember('appointment_missed_to_nine', 10, function () { - return Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + $appointment_missed_to_nine = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) > 0) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 9)) then `tbl_client`.`id` end)) AS count")) ->where('tbl_appointment.app_status', '=', 'Missed') + ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) ->pluck('count'); - }); - $appointment_missed_to_fourteen = Cache::remember('appointment_missed_to_fourteen', 10, function () { - return Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + $appointment_missed_to_fourteen = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 10) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 14)) then `tbl_client`.`id` end)) AS count")) ->where('tbl_appointment.app_status', '=', 'Missed') + ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) ->pluck('count'); - }); - $appointment_missed_to_nineteen = Cache::remember('appointment_missed_to_nineteen', 10, function () { - return Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + + $appointment_missed_to_nineteen = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 15) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 19)) then `tbl_client`.`id` end)) AS count")) ->where('tbl_appointment.app_status', '=', 'Missed') + ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) ->pluck('count'); - }); - $appointment_missed_to_twentyfour = Cache::remember('appointment_missed_to_twentyfour', 10, function () { - return Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + $appointment_missed_to_twentyfour = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 20) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 24)) then `tbl_client`.`id` end)) AS count")) ->where('tbl_appointment.app_status', '=', 'Missed') + ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) ->pluck('count'); - }); - $appointment_missed_to_twentyfive_above = Cache::remember('appointment_missed_to_twentyfive_above', 10, function () { - return Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + $appointment_missed_to_twentyfive_above = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 25)) then `tbl_client`.`id` end)) AS count")) ->where('tbl_appointment.app_status', '=', 'Missed') + ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) ->pluck('count'); - }); - $appointment_missed_to_uknown_age = Cache::remember('appointment_missed_to_uknown_age', 10, function () { - return Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + $appointment_missed_to_uknown_age = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') ->select('tbl_client.dob') ->where('tbl_client.dob', '=', '') ->orWhereNull('tbl_client.dob') ->where('tbl_appointment.app_status', '=', 'Missed') + ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) ->count(); - }); // defaulted appointment by gender - $appointment_defaulted_female = Cache::remember('appointment_defaulted_female', 10, function () { - return Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + $appointment_defaulted_female = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') ->where('tbl_appointment.app_status', '=', 'Defaulted') ->where('tbl_client.gender', '=', '1') + ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) ->count(); - }); - $appointment_defaulted_male = Cache::remember('appointment_defaulted_male', 10, function () { - return Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + $appointment_defaulted_male = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') ->where('tbl_appointment.app_status', '=', 'Defaulted') ->where('tbl_client.gender', '=', '2') + ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) ->count(); - }); - $appointment_defaulted_uknown_gender = Cache::remember('appointment_defaulted_uknown_gender', 10, function () { - return Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + + $appointment_defaulted_uknown_gender = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') ->where('tbl_appointment.app_status', '=', 'Defaulted') ->where('tbl_client.gender', '!=', '1') ->where('tbl_client.gender', '!=', '2') + ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) ->count(); - }); - // defaulted appointment by age - $appointment_defaulted_to_nine = Cache::remember('appointment_defaulted_to_nine', 10, function () { - return Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + $appointment_defaulted_to_nine = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) > 0) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 9)) then `tbl_client`.`id` end)) AS count")) ->where('tbl_appointment.app_status', '=', 'Defaulted') + ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) ->pluck('count'); - }); - $appointment_defaulted_to_fourteen = Cache::remember('appointment_defaulted_to_fourteen', 10, function () { - return Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') - ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 10) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 14)) then `tbl_client`.`id` end)) AS count")) + $appointment_defaulted_to_fourteen = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 10) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 14)) then `tbl_client`.`id` end)) AS count")) + ->where('tbl_appointment.app_status', '=', 'Defaulted') + ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) + ->pluck('count'); + $appointment_defaulted_to_nineteen = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 15) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 19)) then `tbl_client`.`id` end)) AS count")) + ->where('tbl_appointment.app_status', '=', 'Defaulted') + ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) + ->pluck('count'); + $appointment_defaulted_to_twentyfour = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 20) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 24)) then `tbl_client`.`id` end)) AS count")) + ->where('tbl_appointment.app_status', '=', 'Defaulted') + ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) + ->pluck('count'); + + $appointment_defaulted_to_twentyfive_above = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 25)) then `tbl_client`.`id` end)) AS count")) + ->where('tbl_appointment.app_status', '=', 'Defaulted') + ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) + ->pluck('count'); + + $appointment_defaulted_to_uknown_age = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select('tbl_client.dob') + ->where('tbl_client.dob', '=', '') + ->orWhereNull('tbl_client.dob') + ->where('tbl_appointment.app_status', '=', 'Defaulted') + ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) + ->count(); + // ltfu appointment by gender + $appointment_ltfu_female = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->where('tbl_appointment.app_status', '=', 'LTFU') + ->where('tbl_client.gender', '=', '1') + ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) + ->count(); + + $appointment_ltfu_male = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->where('tbl_appointment.app_status', '=', 'LTFU') + ->where('tbl_client.gender', '=', '2') + ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) + ->count(); + $appointment_ltfu_uknown_gender = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->where('tbl_appointment.app_status', '=', 'LTFU') + ->where('tbl_client.gender', '!=', '1') + ->where('tbl_client.gender', '!=', '2') + ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) + ->count(); + + // ltfu appointment by age + $appointment_ltfu_to_nine = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) > 0) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 9)) then `tbl_client`.`id` end)) AS count")) + ->where('tbl_appointment.app_status', '=', 'LTFU') + ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) + ->pluck('count'); + + $appointment_ltfu_to_fourteen = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 10) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 14)) then `tbl_client`.`id` end)) AS count")) + ->where('tbl_appointment.app_status', '=', 'LTFU') + ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) + ->pluck('count'); + + $appointment_ltfu_to_nineteen = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 15) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 19)) then `tbl_client`.`id` end)) AS count")) + ->where('tbl_appointment.app_status', '=', 'LTFU') + ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) + ->pluck('count'); + + $appointment_ltfu_to_twentyfour = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 20) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 24)) then `tbl_client`.`id` end)) AS count")) + ->where('tbl_appointment.app_status', '=', 'LTFU') + ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) + ->pluck('count'); + $appointment_ltfu_to_twentyfive_above = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 25)) then `tbl_client`.`id` end)) AS count")) + ->where('tbl_appointment.app_status', '=', 'LTFU') + ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) + ->pluck('count'); + + $appointment_ltfu_to_uknown_age = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select('tbl_client.dob') + ->where('tbl_client.dob', '=', '') + ->orWhereNull('tbl_client.dob') + ->where('tbl_appointment.app_status', '=', 'LTFU') + ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) + ->count(); + } + + if (Auth::user()->access_level == 'Admin' || Auth::user()->access_level == 'Donor') { + $all_partners = Partner::where('status', '=', 'Active')->pluck('name', 'id'); + $indicator = Indicator::select(['name', 'description'])->get(); + // main appointments + // dd($appointment_honoured); + $appointment_not_honoured = Cache::remember('appointment-not-honoured', 10, function () { + return Appointments::select(\DB::raw("COUNT(id) as count")) + ->whereIn('app_status', ['Defaulted', 'LTFU', 'Missed']) + ->pluck('count'); + }); + + + // missed appointments + + $appointment_missed = Cache::remember('appointment_missed', 10, function () { + return Appointments::where('app_status', '=', 'Missed') + ->count(); + }); + $appointment_defaulted = Cache::remember('appointment_defaulted', 10, function () { + return Appointments::where('app_status', '=', 'Defaulted') + ->count(); + }); + $appointment_lftu = Cache::remember('appointment_lftu', 10, function () { + return Appointments::where('app_status', '=', 'LTFU') + ->count(); + }); + + // missed appointment by gender + $appointment_missed_female = Cache::remember('appointment_missed_female', 10, function () { + return Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->where('tbl_appointment.app_status', '=', 'Missed') + ->where('tbl_client.gender', '=', '1') + ->count(); + }); + $appointment_missed_male = Cache::remember('appointment_missed_male', 10, function () { + return Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->where('tbl_appointment.app_status', '=', 'Missed') + ->where('tbl_client.gender', '=', '2') + ->count(); + }); + $appointment_missed_uknown_gender = Cache::remember('appointment_missed_uknown_gender', 10, function () { + return Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->where('tbl_appointment.app_status', '=', 'Missed') + ->where('tbl_client.gender', '!=', '1') + ->where('tbl_client.gender', '!=', '2') + ->count(); + }); + // missed appointment by age + $appointment_missed_to_nine = Cache::remember('appointment_missed_to_nine', 10, function () { + return Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) > 0) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 9)) then `tbl_client`.`id` end)) AS count")) + ->where('tbl_appointment.app_status', '=', 'Missed') + ->pluck('count'); + }); + $appointment_missed_to_fourteen = Cache::remember('appointment_missed_to_fourteen', 10, function () { + return Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 10) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 14)) then `tbl_client`.`id` end)) AS count")) + ->where('tbl_appointment.app_status', '=', 'Missed') + ->pluck('count'); + }); + $appointment_missed_to_nineteen = Cache::remember('appointment_missed_to_nineteen', 10, function () { + return Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 15) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 19)) then `tbl_client`.`id` end)) AS count")) + ->where('tbl_appointment.app_status', '=', 'Missed') + ->pluck('count'); + }); + $appointment_missed_to_twentyfour = Cache::remember('appointment_missed_to_twentyfour', 10, function () { + return Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 20) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 24)) then `tbl_client`.`id` end)) AS count")) + ->where('tbl_appointment.app_status', '=', 'Missed') + ->pluck('count'); + }); + $appointment_missed_to_twentyfive_above = Cache::remember('appointment_missed_to_twentyfive_above', 10, function () { + return Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 25)) then `tbl_client`.`id` end)) AS count")) + ->where('tbl_appointment.app_status', '=', 'Missed') + ->pluck('count'); + }); + $appointment_missed_to_uknown_age = Cache::remember('appointment_missed_to_uknown_age', 10, function () { + return Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->select('tbl_client.dob') + ->where('tbl_client.dob', '=', '') + ->orWhereNull('tbl_client.dob') + ->where('tbl_appointment.app_status', '=', 'Missed') + ->count(); + }); + + // defaulted appointment by gender + $appointment_defaulted_female = Cache::remember('appointment_defaulted_female', 10, function () { + return Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->where('tbl_appointment.app_status', '=', 'Defaulted') + ->where('tbl_client.gender', '=', '1') + ->count(); + }); + $appointment_defaulted_male = Cache::remember('appointment_defaulted_male', 10, function () { + return Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->where('tbl_appointment.app_status', '=', 'Defaulted') + ->where('tbl_client.gender', '=', '2') + ->count(); + }); + $appointment_defaulted_uknown_gender = Cache::remember('appointment_defaulted_uknown_gender', 10, function () { + return Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->where('tbl_appointment.app_status', '=', 'Defaulted') + ->where('tbl_client.gender', '!=', '1') + ->where('tbl_client.gender', '!=', '2') + ->count(); + }); + + // defaulted appointment by age + $appointment_defaulted_to_nine = Cache::remember('appointment_defaulted_to_nine', 10, function () { + return Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) > 0) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 9)) then `tbl_client`.`id` end)) AS count")) + ->where('tbl_appointment.app_status', '=', 'Defaulted') + ->pluck('count'); + }); + $appointment_defaulted_to_fourteen = Cache::remember('appointment_defaulted_to_fourteen', 10, function () { + return Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 10) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 14)) then `tbl_client`.`id` end)) AS count")) ->where('tbl_appointment.app_status', '=', 'Defaulted') ->pluck('count'); }); @@ -2327,26 +2101,8 @@ public function appointment_charts() } - return view('new_dashboard.appointment_dashboard', compact('all_partners', 'appointment', 'appointment_honoured', + return view('new_dashboard.missed_dashboard', compact('all_partners', 'indicator', 'appointment_not_honoured', - 'appointment_honoured_male', - 'appointment_honoured_female', - 'appointment_honoured_uknown_gender', - 'appointment_honored_to_nine', - 'appointment_honored_to_fourteen', - 'appointment_honored_to_nineteen', - 'appointment_honored_to_twentyfour', - 'appointment_honored_to_twentyfive_above', - 'appointment_honored_to_uknown_age', - 'appointment_not_honoured_male', - 'appointment_not_honoured_female', - 'appointment_not_honoured_uknown_gender', - 'appointment_not_honored_to_nine', - 'appointment_not_honored_to_fourteen', - 'appointment_not_honored_to_nineteen', - 'appointment_not_honored_to_twentyfour', - 'appointment_not_honored_to_twentyfive_above', - 'appointment_not_honored_to_uknown_age', 'appointment_missed', 'appointment_defaulted', 'appointment_lftu', @@ -2391,87 +2147,103 @@ public function filter_charts(Request $request) if (Auth::user()->access_level == 'Facility'){} if (Auth::user()->access_level == 'Partner'){} + $all_partners = Partner::where('status', '=', 'Active')->pluck('name', 'id'); + $indicator = Indicator::select(['name', 'description'])->get(); - $client = Client::where('status', '=', 'Active') - ->whereNull('hei_no') - ->where('created_at', '>=', date($request->from))->where('created_at', '<=', date($request->to)); - $appointment = Appointments::select('id') - ->where('created_at', '>=', date($request->from))->where('created_at', '<=', date($request->to)); - $missed_appointment = Appointments::select('id') - ->whereIn('app_status', ['Defaulted', 'LTFU', 'Missed']) - ->where('created_at', '>=', date($request->from))->where('created_at', '<=', date($request->to)); + $client = Client::join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->where('tbl_client.status', '=', 'Active') + ->whereNull('tbl_client.hei_no') + ->where('tbl_client.created_at', '>=', date($request->from))->where('tbl_client.created_at', '<=', date($request->to)); + $appointment = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select('tbl_appointment.id') + ->where('tbl_appointment.created_at', '>=', date($request->from))->where('tbl_appointment.created_at', '<=', date($request->to)); + $missed_appointment = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select('tbl_appointment.id') + ->whereIn('tbl_appointment.app_status', ['Defaulted', 'LTFU', 'Missed']) + ->where('tbl_appointment.created_at', '>=', date($request->from))->where('tbl_appointment.created_at', '<=', date($request->to)); $active_facilities = PartnerFacility::join('tbl_client', 'tbl_partner_facility.mfl_code', '=', 'tbl_client.mfl_code') ->join('tbl_appointment', 'tbl_client.id', '=', 'tbl_appointment.client_id') ->select('tbl_partner_facility.mfl_code') ->where('tbl_appointment.created_at', '>=', Carbon::now()->subMonths(6)) - ->where('tbl_appointment.created_at', '>=', date($request->from))->where('tbl_appointment.created_at', '<=', date($request->to)); + ->where('tbl_appointment.created_at', '>=', date($request->from))->where('tbl_appointment.created_at', '<=', date($request->to)) ->orderBy('tbl_appointment.created_at', 'DESC') ->groupBy('tbl_partner_facility.mfl_code') ->get(); // active clients by gender - $clients_male = Client::select('id') - ->where([['gender', '=', '2'], ['status', '=', 'Active'],]) - ->whereNull('hei_no') - ->where('created_at', '>=', date($request->from))->where('created_at', '<=', date($request->to)); + $clients_male = Client::join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select('tbl_client.id') + ->where([['tbl_client.gender', '=', '2'], ['tbl_client.status', '=', 'Active'],]) + ->whereNull('tbl_client.hei_no') + ->where('tbl_client.created_at', '>=', date($request->from))->where('tbl_client.created_at', '<=', date($request->to)); - $clients_female = Client::where('gender', '=', '1') - ->where('status', '=', 'Active') - ->whereNull('hei_no') - ->where('created_at', '>=', date($request->from))->where('created_at', '<=', date($request->to)); - $unknown_gender = Client::where('gender', '!=', '1') - ->where('gender', '!=', '2') - ->where('status', '=', 'Active') - ->whereNull('hei_no') - ->where('created_at', '>=', date($request->from))->where('created_at', '<=', date($request->to)); + $clients_female = Client::join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->where([['tbl_client.gender', '=', '2'], ['tbl_client.status', '=', 'Active'],]) + ->whereNull('tbl_client.hei_no') + ->where('tbl_client.created_at', '>=', date($request->from))->where('tbl_client.created_at', '<=', date($request->to)); + $unknown_gender = Client::join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->where([['tbl_client.gender', '!=', '1'], ['tbl_client.gender', '!=', '2'], ['tbl_client.status', '=', 'Active'],]) + ->whereNull('tbl_client.hei_no') + ->where('tbl_client.created_at', '>=', date($request->from))->where('tbl_client.created_at', '<=', date($request->to)); - $client_to_nine = Client::select(\DB::raw("count((case when (((year(curdate()) - year(`dob`)) > 0) and ((year(curdate()) - year(`dob`)) <= 9)) then `dob` end")) - ->where('status', '=', 'Active') - ->whereNull('hei_no') - ->where('created_at', '>=', date($request->from))->where('created_at', '<=', date($request->to)); + $client_to_nine = Client::join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select(\DB::raw("case when (((year(curdate()) - year(`tbl_client`.`dob`)) > 0) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 9)) then `tbl_client`.`dob` end")) + ->where('tbl_client.status', '=', 'Active') + ->whereNull('tbl_client.hei_no') + ->where('tbl_client.created_at', '>=', date($request->from))->where('tbl_client.created_at', '<=', date($request->to)); - $client_to_fourteen = Client::select(\DB::raw("case when (((year(curdate()) - year(`dob`)) >= 10) and ((year(curdate()) - year(`dob`)) <= 14)) then `dob` end")) - ->where('status', '=', 'Active') - ->whereNull('hei_no') - ->where('created_at', '>=', date($request->from))->where('created_at', '<=', date($request->to)); + $client_to_fourteen = Client::join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select(\DB::raw("case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 10) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 14)) then `tbl_client`.`dob` end")) + ->where('tbl_client.status', '=', 'Active') + ->whereNull('tbl_client.hei_no') + ->where('tbl_client.created_at', '>=', date($request->from))->where('tbl_client.created_at', '<=', date($request->to)); - $client_to_nineteen = Client::select(\DB::raw("case when (((year(curdate()) - year(`dob`)) >= 15) and ((year(curdate()) - year(`dob`)) <= 19)) then `dob` end")) - ->where('status', '=', 'Active') - ->whereNull('hei_no') - ->where('created_at', '>=', date($request->from))->where('created_at', '<=', date($request->to)); + $client_to_nineteen = Client::join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select(\DB::raw("case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 15) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 19)) then `tbl_client`.`dob` end")) + ->where('tbl_client.status', '=', 'Active') + ->whereNull('tbl_client.hei_no') + ->where('tbl_client.created_at', '>=', date($request->from))->where('tbl_client.created_at', '<=', date($request->to)); - $client_to_twentyfour = Client::select(\DB::raw("case when (((year(curdate()) - year(`dob`)) >= 20) and ((year(curdate()) - year(`dob`)) <= 24)) then `id` end")) - ->where('status', '=', 'Active') - ->whereNull('hei_no') - ->where('created_at', '>=', date($request->from))->where('created_at', '<=', date($request->to)); + $client_to_twentyfour = Client::join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select(\DB::raw("case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 20) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 24)) then `id` end")) + ->where('tbl_client.status', '=', 'Active') + ->whereNull('tbl_client.hei_no') + ->where('tbl_client.created_at', '>=', date($request->from))->where('tbl_client.created_at', '<=', date($request->to)); - $client_to_twentyfive_above = Client::select(\DB::raw("case when (((year(curdate()) - year(`dob`)) >= 25)) then `id` end")) - ->where('status', '=', 'Active') - ->whereNull('hei_no') - ->where('created_at', '>=', date($request->from))->where('created_at', '<=', date($request->to)); + $client_to_twentyfive_above = Client::join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select(\DB::raw("case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 25)) then `id` end")) + ->where('tbl_client.status', '=', 'Active') + ->whereNull('tbl_client.hei_no') + ->where('tbl_client.created_at', '>=', date($request->from))->where('tbl_client.created_at', '<=', date($request->to)); - $client_unknown_age = Client::where('dob', '=', '') - ->orWhereNull('dob') - ->where('status', '=', 'Active') - ->whereNull('hei_no') - ->where('created_at', '>=', date($request->from))->where('created_at', '<=', date($request->to)); + $client_unknown_age = Client::join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->where('tbl_client.dob', '=', '') + ->orWhereNull('tbl_client.dob') + ->where('tbl_client.status', '=', 'Active') + ->whereNull('tbl_client.hei_no') + ->where('tbl_client.created_at', '>=', date($request->from))->where('tbl_client.created_at', '<=', date($request->to)); // appointment by gender $appointment_male = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') ->select('tbl_appointment.id') ->where('tbl_client.gender', '=', '2') ->where('tbl_appointment.created_at', '>=', date($request->from))->where('tbl_appointment.created_at', '<=', date($request->to)); $appointment_female = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') ->select('tbl_appointment.id') ->where('tbl_client.gender', '=', '1') ->where('tbl_appointment.created_at', '>=', date($request->from))->where('tbl_appointment.created_at', '<=', date($request->to)); $appointment_uknown_gender = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') ->select('tbl_appointment.id') ->where('tbl_client.gender', '!=', '1') ->where('tbl_client.gender', '!=', '2') @@ -2480,33 +2252,34 @@ public function filter_charts(Request $request) // appointment by age $appointment_to_nine = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') - ->select(\DB::raw("case when (((year(curdate()) - year(`tbl_client`.`dob`)) > 0) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 9)) then `tbl_client`.`id` end")) + ->select(\DB::raw("case when (((year(curdate()) - year(`tbl_client`.`tbl_client`.`dob`)) > 0) and ((year(curdate()) - year(`tbl_client`.`tbl_client`.`dob`)) <= 9)) then `tbl_client`.`id` end")) ->where('tbl_appointment.created_at', '>=', date($request->from))->where('tbl_appointment.created_at', '<=', date($request->to)); $appointment_to_fourteen = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') - ->select(\DB::raw("case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 10) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 14)) then `tbl_client`.`id` end")) + ->select(\DB::raw("case when (((year(curdate()) - year(`tbl_client`.`tbl_client`.`dob`)) >= 10) and ((year(curdate()) - year(`tbl_client`.`tbl_client`.`dob`)) <= 14)) then `tbl_client`.`id` end")) + ->where('tbl_appointment.created_at', '>=', date($request->from))->where('tbl_appointment.created_at', '<=', date($request->to)); $appointment_to_nineteen = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') - ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') - ->select(\DB::raw("case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 15) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 19)) then `tbl_client`.`id` end")) + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select(\DB::raw("case when (((year(curdate()) - year(`tbl_client`.`tbl_client`.`dob`)) >= 15) and ((year(curdate()) - year(`tbl_client`.`tbl_client`.`dob`)) <= 19)) then `tbl_client`.`id` end")) ->where('tbl_appointment.created_at', '>=', date($request->from))->where('tbl_appointment.created_at', '<=', date($request->to)); $appointment_to_twentyfour = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') - ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') - ->select(\DB::raw("case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 20) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 24)) then `tbl_client`.`id` end")) + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select(\DB::raw("case when (((year(curdate()) - year(`tbl_client`.`tbl_client`.`dob`)) >= 20) and ((year(curdate()) - year(`tbl_client`.`tbl_client`.`dob`)) <= 24)) then `tbl_client`.`id` end")) ->where('tbl_appointment.created_at', '>=', date($request->from))->where('tbl_appointment.created_at', '<=', date($request->to)); $appointment_to_twentyfive_above = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') - ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') - ->select(\DB::raw("case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 25)) then `tbl_client`.`id` end")) + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select(\DB::raw("case when (((year(curdate()) - year(`tbl_client`.`tbl_client`.`dob`)) >= 25)) then `tbl_client`.`id` end")) ->where('tbl_appointment.created_at', '>=', date($request->from))->where('tbl_appointment.created_at', '<=', date($request->to)); $appointment_uknown_age = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') - ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') ->where('tbl_client.dob', '=', '') ->orWhereNull('tbl_client.dob') ->where('tbl_appointment.created_at', '>=', date($request->from))->where('tbl_appointment.created_at', '<=', date($request->to)); @@ -2514,190 +2287,219 @@ public function filter_charts(Request $request) // Total missed appointment by gender $appointment_total_missed_female = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') ->whereIn('tbl_appointment.app_status', ['Defaulted', 'LTFU', 'Missed']) ->where('tbl_client.gender', '=', '1') ->where('tbl_appointment.created_at', '>=', date($request->from))->where('tbl_appointment.created_at', '<=', date($request->to)); $appointment_total_missed_male = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') ->where('tbl_client.gender', '=', '2') ->whereIn('tbl_appointment.app_status', ['Defaulted', 'LTFU', 'Missed']) ->where('tbl_appointment.created_at', '>=', date($request->from))->where('tbl_appointment.created_at', '<=', date($request->to)); $appointment_total_missed_uknown_gender = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') ->whereIn('tbl_appointment.app_status', ['Defaulted', 'LTFU', 'Missed']) ->where('tbl_client.gender', '!=', '1') ->where('tbl_client.gender', '!=', '2') + ->where('tbl_appointment.created_at', '>=', date($request->from))->where('tbl_appointment.created_at', '<=', date($request->to)); // Total missed appointment by age $appointment_total_missed_to_nine = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') - ->select(\DB::raw("case when (((year(curdate()) - year(`tbl_client`.`dob`)) > 0) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 9)) then `tbl_client`.`id` end")) + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select(\DB::raw("case when (((year(curdate()) - year(`tbl_client`.`tbl_client`.`dob`)) > 0) and ((year(curdate()) - year(`tbl_client`.`tbl_client`.`dob`)) <= 9)) then `tbl_client`.`id` end")) ->whereIn('tbl_appointment.app_status', ['Defaulted', 'LTFU', 'Missed']) ->where('tbl_appointment.created_at', '>=', date($request->from))->where('tbl_appointment.created_at', '<=', date($request->to)); $appointment_total_missed_to_fourteen = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') - ->select(\DB::raw("case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 10) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 14)) then `tbl_client`.`id` end")) + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select(\DB::raw("case when (((year(curdate()) - year(`tbl_client`.`tbl_client`.`dob`)) >= 10) and ((year(curdate()) - year(`tbl_client`.`tbl_client`.`dob`)) <= 14)) then `tbl_client`.`id` end")) ->whereIn('tbl_appointment.app_status', ['Defaulted', 'LTFU', 'Missed']) ->where('tbl_appointment.created_at', '>=', date($request->from))->where('tbl_appointment.created_at', '<=', date($request->to)); $appointment_total_missed_to_nineteen = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') - ->select(\DB::raw("case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 15) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 19)) then `tbl_client`.`id` end")) + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select(\DB::raw("case when (((year(curdate()) - year(`tbl_client`.`tbl_client`.`dob`)) >= 15) and ((year(curdate()) - year(`tbl_client`.`tbl_client`.`dob`)) <= 19)) then `tbl_client`.`id` end")) ->whereIn('tbl_appointment.app_status', ['Defaulted', 'LTFU', 'Missed']) ->where('tbl_appointment.created_at', '>=', date($request->from))->where('tbl_appointment.created_at', '<=', date($request->to)); $appointment_total_missed_to_twentyfour = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') - ->select(\DB::raw("case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 20) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 24)) then `tbl_client`.`id` end")) + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select(\DB::raw("case when (((year(curdate()) - year(`tbl_client`.`tbl_client`.`dob`)) >= 20) and ((year(curdate()) - year(`tbl_client`.`tbl_client`.`dob`)) <= 24)) then `tbl_client`.`id` end")) ->whereIn('tbl_appointment.app_status', ['Defaulted', 'LTFU', 'Missed']) ->where('tbl_appointment.created_at', '>=', date($request->from))->where('tbl_appointment.created_at', '<=', date($request->to)); $appointment_total_missed_to_twentyfive_above = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') - ->select(\DB::raw("case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 25)) then `tbl_client`.`id` end")) + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select(\DB::raw("case when (((year(curdate()) - year(`tbl_client`.`tbl_client`.`dob`)) >= 25)) then `tbl_client`.`id` end")) ->whereIn('tbl_appointment.app_status', ['Defaulted', 'LTFU', 'Missed']) ->where('tbl_appointment.created_at', '>=', date($request->from))->where('tbl_appointment.created_at', '<=', date($request->to)); $appointment_total_missed_uknown_age = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') - ->where('tbl_client.dob', '=', '') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') ->orWhereNull('tbl_client.dob') ->whereIn('tbl_appointment.app_status', ['Defaulted', 'LTFU', 'Missed']) ->where('tbl_appointment.created_at', '>=', date($request->from))->where('tbl_appointment.created_at', '<=', date($request->to)); // client charts - $client_consented = Client::select('smsenable') - ->where('status', '=', 'Active') - ->whereNull('hei_no') - ->where('smsenable', '=', 'Yes') - ->where('created_at', '>=', date($request->from))->where('created_at', '<=', date($request->to)); + $client_consented = Client::join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select('tbl_client.id') + ->where('tbl_client.status', '=', 'Active') + ->whereNull('tbl_client.hei_no') + ->where('tbl_client.smsenable', '=', 'Yes') + ->where('tbl_client.created_at', '>=', date($request->from))->where('tbl_client.created_at', '<=', date($request->to)); - $client_nonconsented = Client::select('smsenable') - ->where('status', '=', 'Active') - ->whereNull('hei_no') - ->where('smsenable', '!=', 'Yes') - ->where('created_at', '>=', date($request->from))->where('created_at', '<=', date($request->to)); + $client_nonconsented = Client::join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select('tbl_client.id') + ->where('tbl_client.status', '=', 'Active') + ->whereNull('tbl_client.hei_no') + ->where('tbl_client.smsenable', '!=', 'Yes') + ->where('tbl_client.created_at', '>=', date($request->from))->where('tbl_client.created_at', '<=', date($request->to)); // consented clients by gender - $client_consented_male = Client::where('smsenable', '=', 'Yes') - ->where('status', '=', 'Active') - ->whereNull('hei_no') - ->where('gender', '=', '2') - ->where('created_at', '>=', date($request->from))->where('created_at', '<=', date($request->to)); + $client_consented_male = Client::join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->where('tbl_client.smsenable', '=', 'Yes') + ->where('tbl_client.status', '=', 'Active') + ->whereNull('tbl_client.hei_no') + ->where('tbl_client.gender', '=', '2') + ->where('tbl_client.created_at', '>=', date($request->from))->where('tbl_client.created_at', '<=', date($request->to)); - $client_consented_female = Client::where('smsenable', '=', 'Yes') - ->where('status', '=', 'Active') - ->whereNull('hei_no') - ->where('gender', '=', '1') - ->where('created_at', '>=', date($request->from))->where('created_at', '<=', date($request->to)); + $client_consented_female = Client::join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->where('tbl_client.smsenable', '=', 'Yes') + ->where('tbl_client.status', '=', 'Active') + ->whereNull('tbl_client.hei_no') + ->where('tbl_client.gender', '=', '1') + ->where('tbl_client.created_at', '>=', date($request->from))->where('tbl_client.created_at', '<=', date($request->to)); - $client_consented_uknown_gender = Client::where('smsenable', '=', 'Yes') - ->where('status', '=', 'Active') - ->whereNull('hei_no') - ->where('gender', '!=', '1') - ->where('gender', '!=', '2') - ->where('created_at', '>=', date($request->from))->where('created_at', '<=', date($request->to)); + $client_consented_uknown_gender = Client::join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->where('tbl_client.smsenable', '=', 'Yes') + ->where('tbl_client.status', '=', 'Active') + ->whereNull('tbl_client.hei_no') + ->where('tbl_client.gender', '!=', '1') + ->where('tbl_client.gender', '!=', '2') + ->where('tbl_client.created_at', '>=', date($request->from))->where('tbl_client.created_at', '<=', date($request->to)); // non consented clients by gender - $client_nonconsented_male = Client::where('smsenable', '!=', 'Yes') - ->where('status', '=', 'Active') - ->whereNull('hei_no') - ->where('gender', '=', '2') - ->where('created_at', '>=', date($request->from))->where('created_at', '<=', date($request->to)); + $client_nonconsented_male = Client::join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->where('tbl_client.smsenable', '!=', 'Yes') + ->where('tbl_client.status', '=', 'Active') + ->whereNull('tbl_client.hei_no') + ->where('tbl_client.gender', '=', '2') + ->where('tbl_client.created_at', '>=', date($request->from))->where('tbl_client.created_at', '<=', date($request->to)); - $client_nonconsented_female = Client::where('smsenable', '!=', 'Yes') - ->where('status', '=', 'Active') - ->whereNull('hei_no') - ->where('gender', '=', '1') - ->where('created_at', '>=', date($request->from))->where('created_at', '<=', date($request->to)); + $client_nonconsented_female = Client::join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->where('tbl_client.smsenable', '!=', 'Yes') + ->where('tbl_client.status', '=', 'Active') + ->whereNull('tbl_client.hei_no') + ->where('tbl_client.gender', '=', '1') + ->where('tbl_client.created_at', '>=', date($request->from))->where('tbl_client.created_at', '<=', date($request->to)); - $client_nonconsented_uknown_gender = Client::where('smsenable', '!=', 'Yes') - ->where('gender', '!=', '1') - ->where('gender', '!=', '2') - ->where('created_at', '>=', date($request->from))->where('created_at', '<=', date($request->to)); + $client_nonconsented_uknown_gender = Client::join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->where('tbl_client.smsenable', '!=', 'Yes') + ->where('tbl_client.gender', '!=', '1') + ->where('tbl_client.gender', '!=', '2') + ->where('tbl_client.created_at', '>=', date($request->from))->where('tbl_client.created_at', '<=', date($request->to)); // consented clients by age distribution - $client_consented_to_nine = Client::select(\DB::raw("case when (((year(curdate()) - year(`tbl_client`.`dob`)) > 0) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 9)) then `tbl_client`.`id` end")) - ->where('smsenable', '=', 'Yes') - ->where('status', '=', 'Active') - ->whereNull('hei_no') - ->where('created_at', '>=', date($request->from))->where('created_at', '<=', date($request->to)); + $client_consented_to_nine = Client::join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select(\DB::raw("case when (((year(curdate()) - year(`tbl_client`.`tbl_client`.`dob`)) > 0) and ((year(curdate()) - year(`tbl_client`.`tbl_client`.`dob`)) <= 9)) then `tbl_client`.`id` end")) + ->where('tbl_client.smsenable', '=', 'Yes') + ->where('tbl_client.status', '=', 'Active') + ->whereNull('tbl_client.hei_no') + ->where('tbl_client.created_at', '>=', date($request->from))->where('tbl_client.created_at', '<=', date($request->to)); - $client_consented_to_fourteen = Client::select(\DB::raw("case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 10) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 14)) then `tbl_client`.`id` end")) - ->where('smsenable', '=', 'Yes') - ->where('status', '=', 'Active') - ->whereNull('hei_no') - ->where('created_at', '>=', date($request->from))->where('created_at', '<=', date($request->to)); + $client_consented_to_fourteen = Client::join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select(\DB::raw("case when (((year(curdate()) - year(`tbl_client`.`tbl_client`.`dob`)) >= 10) and ((year(curdate()) - year(`tbl_client`.`tbl_client`.`dob`)) <= 14)) then `tbl_client`.`id` end")) + ->where('tbl_client.smsenable', '=', 'Yes') + ->where('tbl_client.status', '=', 'Active') + ->whereNull('tbl_client.hei_no') + ->where('tbl_client.created_at', '>=', date($request->from))->where('tbl_client.created_at', '<=', date($request->to)); - $client_consented_to_nineteen = Client::select(\DB::raw("case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 15) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 19)) then `tbl_client`.`id` end")) - ->where('smsenable', '=', 'Yes') - ->where('status', '=', 'Active') - ->whereNull('hei_no') - ->where('created_at', '>=', date($request->from))->where('created_at', '<=', date($request->to)); + $client_consented_to_nineteen = Client::join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select(\DB::raw("case when (((year(curdate()) - year(`tbl_client`.`tbl_client`.`dob`)) >= 15) and ((year(curdate()) - year(`tbl_client`.`tbl_client`.`dob`)) <= 19)) then `tbl_client`.`id` end")) + ->where('tbl_client.smsenable', '=', 'Yes') + ->where('tbl_client.status', '=', 'Active') + ->whereNull('tbl_client.hei_no') + ->where('tbl_client.created_at', '>=', date($request->from))->where('tbl_client.created_at', '<=', date($request->to)); - $client_consented_to_twentyfour = Client::select(\DB::raw("case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 20) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 24)) then `tbl_client`.`id` end")) - ->where('smsenable', '=', 'Yes') - ->where('status', '=', 'Active') - ->whereNull('hei_no') - ->where('created_at', '>=', date($request->from))->where('created_at', '<=', date($request->to)); + $client_consented_to_twentyfour = Client::join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select(\DB::raw("case when (((year(curdate()) - year(`tbl_client`.`tbl_client`.`dob`)) >= 20) and ((year(curdate()) - year(`tbl_client`.`tbl_client`.`dob`)) <= 24)) then `tbl_client`.`id` end")) + ->where('tbl_client.smsenable', '=', 'Yes') + ->where('tbl_client.status', '=', 'Active') + ->whereNull('tbl_client.hei_no') + ->where('tbl_client.created_at', '>=', date($request->from))->where('tbl_client.created_at', '<=', date($request->to)); - $client_consented_to_twentyfive_above = Client::select(\DB::raw("case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 25)) then `tbl_client`.`id` end")) - ->where('smsenable', '=', 'Yes') - ->where('status', '=', 'Active') - ->whereNull('hei_no') - ->where('created_at', '>=', date($request->from))->where('created_at', '<=', date($request->to)); + $client_consented_to_twentyfive_above = Client::join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select(\DB::raw("case when (((year(curdate()) - year(`tbl_client`.`tbl_client`.`dob`)) >= 25)) then `tbl_client`.`id` end")) + ->where('tbl_client.smsenable', '=', 'Yes') + ->where('tbl_client.status', '=', 'Active') + ->whereNull('tbl_client.hei_no') + ->where('tbl_client.created_at', '>=', date($request->from))->where('tbl_client.created_at', '<=', date($request->to)); - $client_consented_uknown_age = Client::select('smsenable') - ->where('dob', '=', '') - ->where('status', '=', 'Active') - ->whereNull('hei_no') - ->orWhereNull('dob') - ->where('smsenable', '=', 'Yes') - ->where('created_at', '>=', date($request->from))->where('created_at', '<=', date($request->to)); + $client_consented_uknown_age = Client::join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select('tbl_client.smsenable') + ->where('tbl_client.dob', '=', '') + ->where('tbl_client.status', '=', 'Active') + ->whereNull('tbl_client.hei_no') + ->orWhereNull('tbl_client.dob') + ->where('tbl_client.smsenable', '=', 'Yes') + ->where('tbl_client.created_at', '>=', date($request->from))->where('tbl_client.created_at', '<=', date($request->to)); // non consented clients by age distribution - $client_nonconsented_to_nine = Client::select(\DB::raw("case when (((year(curdate()) - year(`tbl_client`.`dob`)) > 0) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 9)) then `tbl_client`.`id` end")) - ->where('smsenable', '!=', 'Yes') - ->where('status', '=', 'Active') - ->whereNull('hei_no') - ->where('created_at', '>=', date($request->from))->where('created_at', '<=', date($request->to)); + $client_nonconsented_to_nine = Client::join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select(\DB::raw("case when (((year(curdate()) - year(`tbl_client`.`tbl_client`.`dob`)) > 0) and ((year(curdate()) - year(`tbl_client`.`tbl_client`.`dob`)) <= 9)) then `tbl_client`.`id` end")) + ->where('tbl_client.smsenable', '!=', 'Yes') + ->where('tbl_client.status', '=', 'Active') + ->whereNull('tbl_client.hei_no') + ->where('tbl_client.created_at', '>=', date($request->from))->where('tbl_client.created_at', '<=', date($request->to)); - $client_nonconsented_to_fourteen = Client::select(\DB::raw("case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 10) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 14)) then `tbl_client`.`id` end")) - ->where('smsenable', '!=', 'Yes') - ->where('status', '=', 'Active') - ->whereNull('hei_no') - ->where('created_at', '>=', date($request->from))->where('created_at', '<=', date($request->to)); + $client_nonconsented_to_fourteen = Client::join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select(\DB::raw("case when (((year(curdate()) - year(`tbl_client`.`tbl_client`.`dob`)) >= 10) and ((year(curdate()) - year(`tbl_client`.`tbl_client`.`dob`)) <= 14)) then `tbl_client`.`id` end")) + ->where('tbl_client.smsenable', '!=', 'Yes') + ->where('tbl_client.status', '=', 'Active') + ->whereNull('tbl_client.hei_no') + ->where('tbl_client.created_at', '>=', date($request->from))->where('tbl_client.created_at', '<=', date($request->to)); - $client_nonconsented_to_nineteen = Client::select(\DB::raw("case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 15) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 19)) then `tbl_client`.`id` end")) - ->where('smsenable', '!=', 'Yes') - ->where('status', '=', 'Active') - ->whereNull('hei_no') - ->where('created_at', '>=', date($request->from))->where('created_at', '<=', date($request->to)); + $client_nonconsented_to_nineteen = Client::join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select(\DB::raw("case when (((year(curdate()) - year(`tbl_client`.`tbl_client`.`dob`)) >= 15) and ((year(curdate()) - year(`tbl_client`.`tbl_client`.`dob`)) <= 19)) then `tbl_client`.`id` end")) + ->where('tbl_client.smsenable', '!=', 'Yes') + ->where('tbl_client.status', '=', 'Active') + ->whereNull('tbl_client.hei_no') + ->where('tbl_client.created_at', '>=', date($request->from))->where('tbl_client.created_at', '<=', date($request->to)); - $client_nonconsented_to_twentyfour = Client::select(\DB::raw("case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 20) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 24)) then `tbl_client`.`id` end")) - ->where('smsenable', '!=', 'Yes') - ->where('status', '=', 'Active') - ->whereNull('hei_no') - ->where('created_at', '>=', date($request->from))->where('created_at', '<=', date($request->to)); + $client_nonconsented_to_twentyfour = Client::join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select(\DB::raw("case when (((year(curdate()) - year(`tbl_client`.`tbl_client`.`dob`)) >= 20) and ((year(curdate()) - year(`tbl_client`.`tbl_client`.`dob`)) <= 24)) then `tbl_client`.`id` end")) + ->where('tbl_client.smsenable', '!=', 'Yes') + ->where('tbl_client.status', '=', 'Active') + ->whereNull('tbl_client.hei_no') + ->where('tbl_client.created_at', '>=', date($request->from))->where('tbl_client.created_at', '<=', date($request->to)); - $client_nonconsented_to_twentyfive_above = Client::select(\DB::raw("case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 25)) then `tbl_client`.`id` end")) - ->where('smsenable', '!=', 'Yes') - ->where('status', '=', 'Active') - ->whereNull('hei_no') - ->where('created_at', '>=', date($request->from))->where('created_at', '<=', date($request->to)); + $client_nonconsented_to_twentyfive_above = Client::join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select(\DB::raw("case when (((year(curdate()) - year(`tbl_client`.`tbl_client`.`dob`)) >= 25)) then `tbl_client`.`id` end")) + ->where('tbl_client.smsenable', '!=', 'Yes') + ->where('tbl_client.status', '=', 'Active') + ->whereNull('tbl_client.hei_no') + ->where('tbl_client.created_at', '>=', date($request->from))->where('tbl_client.created_at', '<=', date($request->to)); - $client_nonconsented_uknown_age = Client::select('smsenable') - ->where('status', '=', 'Active') - ->whereNull('hei_no') - ->where('dob', '=', '') - ->orWhereNull('dob') - ->where('smsenable', '!=', 'Yes') - ->where('created_at', '>=', date($request->from))->where('created_at', '<=', date($request->to)); + $client_nonconsented_uknown_age = Client::join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select('tbl_client.smsenable') + ->where('tbl_client.status', '=', 'Active') + ->whereNull('tbl_client.hei_no') + ->where('tbl_client.dob', '=', '') + ->orWhereNull('tbl_client.dob') + ->where('tbl_client.smsenable', '!=', 'Yes') + ->where('tbl_client.created_at', '>=', date($request->from))->where('tbl_client.created_at', '<=', date($request->to)); if (!empty($selected_partners)) { $client = $client->where('tbl_partner_facility.partner_id', $selected_partners); $appointment = $appointment->where('tbl_partner_facility.partner_id', $selected_partners); $missed_appointment = $missed_appointment->where('tbl_partner_facility.partner_id', $selected_partners); - $active_facilities = $active_facilities->where('tbl_partner_facility.partner_id', $selected_partners); + // $active_facilities = $active_facilities->where('tbl_partner_facility.partner_id', $selected_partners); $clients_male = $clients_male->where('tbl_partner_facility.partner_id', $selected_partners); $clients_female = $clients_female->where('tbl_partner_facility.partner_id', $selected_partners); $unknown_gender = $unknown_gender->where('tbl_partner_facility.partner_id', $selected_partners); @@ -2745,13 +2547,13 @@ public function filter_charts(Request $request) $client_nonconsented_to_nineteen = $client_nonconsented_to_nineteen->where('tbl_partner_facility.partner_id', $selected_partners); $client_nonconsented_to_twentyfour = $client_nonconsented_to_twentyfour->where('tbl_partner_facility.partner_id', $selected_partners); $client_nonconsented_to_twentyfive_above = $client_nonconsented_to_twentyfive_above->where('tbl_partner_facility.partner_id', $selected_partners); - $client_nonconsented_uknown_age = $client_nonconsented_to_twentyfive_aboclient_nonconsented_uknown_ageve->where('tbl_partner_facility.partner_id', $selected_partners); + $client_nonconsented_uknown_age = $client_nonconsented_uknown_age->where('tbl_partner_facility.partner_id', $selected_partners); } if (!empty($selected_counties)) { $client = $client->where('tbl_partner_facility.county_id', $selected_counties); $appointment = $appointment->where('tbl_partner_facility.county_id', $selected_counties); $missed_appointment = $missed_appointment->where('tbl_partner_facility.county_id', $selected_counties); - $active_facilities = $active_facilities->where('tbl_partner_facility.county_id', $selected_counties); + // $active_facilities = $active_facilities->where('tbl_partner_facility.county_id', $selected_counties); $clients_male = $clients_male->where('tbl_partner_facility.county_id', $selected_counties); $clients_female = $clients_female->where('tbl_partner_facility.county_id', $selected_counties); $unknown_gender = $unknown_gender->where('tbl_partner_facility.county_id', $selected_counties); @@ -2799,13 +2601,13 @@ public function filter_charts(Request $request) $client_nonconsented_to_nineteen = $client_nonconsented_to_nineteen->where('tbl_partner_facility.county_id', $selected_counties); $client_nonconsented_to_twentyfour = $client_nonconsented_to_twentyfour->where('tbl_partner_facility.county_id', $selected_counties); $client_nonconsented_to_twentyfive_above = $client_nonconsented_to_twentyfive_above->where('tbl_partner_facility.county_id', $selected_counties); - $client_nonconsented_uknown_age = $client_nonconsented_to_twentyfive_aboclient_nonconsented_uknown_ageve->where('tbl_partner_facility.county_id', $selected_counties); + $client_nonconsented_uknown_age = $client_nonconsented_uknown_age->where('tbl_partner_facility.county_id', $selected_counties); } if (!empty($selected_subcounties)) { $client = $client->where('tbl_partner_facility.sub_county_id', $selected_subcounties); $appointment = $appointment->where('tbl_partner_facility.sub_county_id', $selected_subcounties); $missed_appointment = $missed_appointment->where('tbl_partner_facility.sub_county_id', $selected_subcounties); - $active_facilities = $active_facilities->where('tbl_partner_facility.sub_county_id', $selected_subcounties); + // $active_facilities = $active_facilities->where('tbl_partner_facility.sub_county_id', $selected_subcounties); $clients_male = $clients_male->where('tbl_partner_facility.sub_county_id', $selected_subcounties); $clients_female = $clients_female->where('tbl_partner_facility.sub_county_id', $selected_subcounties); $unknown_gender = $unknown_gender->where('tbl_partner_facility.sub_county_id', $selected_subcounties); @@ -2853,12 +2655,12 @@ public function filter_charts(Request $request) $client_nonconsented_to_nineteen = $client_nonconsented_to_nineteen->where('tbl_partner_facility.sub_county_id', $selected_subcounties); $client_nonconsented_to_twentyfour = $client_nonconsented_to_twentyfour->where('tbl_partner_facility.sub_county_id', $selected_subcounties); $client_nonconsented_to_twentyfive_above = $client_nonconsented_to_twentyfive_above->where('tbl_partner_facility.sub_county_id', $selected_subcounties); - $client_nonconsented_uknown_age = $client_nonconsented_to_twentyfive_aboclient_nonconsented_uknown_ageve->where('tbl_partner_facility.sub_county_id', $selected_subcounties); + $client_nonconsented_uknown_age = $client_nonconsented_uknown_age->where('tbl_partner_facility.sub_county_id', $selected_subcounties); } if (!empty($selected_facilites)) { $client = $client->where('tbl_partner_facility.mfl_code', $selected_facilites); $appointment = $appointment->where('tbl_partner_facility.mfl_code', $selected_facilites); - $missed_appointment = $missed_appointment->where('tbl_partner_facility.mfl_code', $selected_facilites); + // $missed_appointment = $missed_appointment->where('tbl_partner_facility.mfl_code', $selected_facilites); $active_facilities = $active_facilities->where('tbl_partner_facility.mfl_code', $selected_facilites); $clients_male = $clients_male->where('tbl_partner_facility.mfl_code', $selected_facilites); $clients_female = $clients_female->where('tbl_partner_facility.mfl_code', $selected_facilites); @@ -2907,7 +2709,7 @@ public function filter_charts(Request $request) $client_nonconsented_to_nineteen = $client_nonconsented_to_nineteen->where('tbl_partner_facility.mfl_code', $selected_facilites); $client_nonconsented_to_twentyfour = $client_nonconsented_to_twentyfour->where('tbl_partner_facility.mfl_code', $selected_facilites); $client_nonconsented_to_twentyfive_above = $client_nonconsented_to_twentyfive_above->where('tbl_partner_facility.mfl_code', $selected_facilites); - $client_nonconsented_uknown_age = $client_nonconsented_to_twentyfive_aboclient_nonconsented_uknown_ageve->where('tbl_partner_facility.mfl_code', $selected_facilites); + $client_nonconsented_uknown_age = $client_nonconsented_uknown_age->where('tbl_partner_facility.mfl_code', $selected_facilites); } $data["client"] = $client->count(); $data["appointment"] = $appointment->count(); @@ -2961,670 +2763,513 @@ public function filter_charts(Request $request) $data["client_nonconsented_to_twentyfive_above"] = $client_nonconsented_to_twentyfive_above->count(); $data["client_nonconsented_uknown_age"] = $client_nonconsented_uknown_age->count(); - if (Auth::user()->access_level == 'Admin' || Auth::user()->access_level == 'Donor') { - $all_partners = Partner::where('status', '=', 'Active')->pluck('name', 'id'); - $client = Client::select('id')->where('status', '=', 'Active') - ->whereNull('hei_no') - ->where('created_at', '>=', date($request->from))->where('created_at', '<=', date($request->to)) - ->count(); - $indicator = Indicator::all(); - $appointment = Appointments::select('id') - ->where('created_at', '>=', date($request->from))->where('created_at', '<=', date($request->to)) - ->count(); + //return view('new_dashboard.main_dashbaord', compact('data')); + return view('new_dashboard.main_dashbaord', compact( + 'all_partners', + 'active_facilities', + 'indicator', + 'client', + 'appointment', + 'missed_appointment', + 'clients_male', + 'clients_female', + 'unknown_gender', + 'client_to_nine', + 'client_to_fourteen', + 'client_to_nineteen', + 'client_to_twentyfour', + 'client_to_twentyfive_above', + 'client_unknown_age', + 'appointment_male', + 'appointment_female', + 'appointment_uknown_gender', + 'appointment_to_nine', + 'appointment_to_fourteen', + 'appointment_to_nineteen', + 'appointment_to_twentyfour', + 'appointment_to_twentyfive_above', + 'appointment_uknown_age', + 'appointment_total_missed_female', + 'appointment_total_missed_male', + 'appointment_total_missed_uknown_gender', + 'appointment_total_missed_to_nine', + 'appointment_total_missed_to_fourteen', + 'appointment_total_missed_to_nineteen', + 'appointment_total_missed_to_twentyfour', + 'appointment_total_missed_to_twentyfive_above', + 'appointment_total_missed_uknown_age', + 'client_consented', + 'client_nonconsented', + 'client_consented_male', + 'client_consented_female', + 'client_consented_uknown_gender', + 'client_nonconsented_male', + 'client_nonconsented_female', + 'client_nonconsented_uknown_gender', + 'client_consented_to_nine', + 'client_consented_to_fourteen', + 'client_consented_to_nineteen', + 'client_consented_to_twentyfour', + 'client_consented_to_twentyfive_above', + 'client_consented_uknown_age', + 'client_nonconsented_to_nine', + 'client_nonconsented_to_fourteen', + 'client_nonconsented_to_nineteen', + 'client_nonconsented_to_twentyfour', + 'client_nonconsented_to_twentyfive_above', + 'client_nonconsented_uknown_age' - $missed_appointment = Appointments::select('id') - ->where('app_status', '=', 'Missed') - ->orwhere('app_status', '=', 'LTFU') - ->orwhere('app_status', '=', 'Defaulted') - ->where('created_at', '>=', date($request->from))->where('created_at', '<=', date($request->to)) - ->count(); - $active_facilities = PartnerFacility::join('tbl_client', 'tbl_partner_facility.mfl_code', '=', 'tbl_client.mfl_code') - ->join('tbl_appointment', 'tbl_client.id', '=', 'tbl_appointment.client_id') - ->select(\DB::raw('COUNT(tbl_partner_facility.mfl_code) as facilities')) - ->where('tbl_appointment.created_at', '>=', Carbon::now()->subMonths(6)) - ->where('tbl_appointment.created_at', '>=', date($request->from))->where('tbl_appointment.created_at', '<=', date($request->to)) - ->orderBy('tbl_appointment.created_at', 'DESC') - ->groupBy('tbl_partner_facility.mfl_code') - ->get(); - // dd($active_facilities); + )); - // dd($active_facilities); + } + public function filter_dashboard_charts(Request $request) + { + // $data = []; + + $selected_partners = $request->partners; + $selected_counties = $request->counties; + $selected_subcounties = $request->subcounties; + $selected_facilites = $request->facilities; + + if (Auth::user()->access_level == 'Facility'){} + if (Auth::user()->access_level == 'Partner'){} + $all_partners = Partner::where('status', '=', 'Active')->pluck('name', 'id'); + $indicator = Indicator::select(['name', 'description'])->get(); + + $client = Client::join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->where('tbl_client.status', '=', 'Active') + ->whereNull('tbl_client.hei_no') + ->whereDate('tbl_client.created_at', '>=', date($request->from))->whereDate('tbl_client.created_at', '<=', date($request->to)); + $client_ever_enrolled = Client::join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->whereNull('tbl_client.hei_no') + ->where('tbl_client.created_at', '>=', date($request->from))->where('tbl_client.created_at', '<=', date($request->to)); + $active_facilities = PartnerFacility::join('tbl_client', 'tbl_partner_facility.mfl_code', '=', 'tbl_client.mfl_code') + ->join('tbl_appointment', 'tbl_client.id', '=', 'tbl_appointment.client_id') + ->select('tbl_partner_facility.mfl_code') + ->where('tbl_appointment.created_at', '>=', Carbon::now()->subMonths(6)) + ->where('tbl_appointment.created_at', '>=', date($request->from))->where('tbl_appointment.created_at', '<=', date($request->to)) + ->orderBy('tbl_appointment.created_at', 'DESC') + ->groupBy('tbl_partner_facility.mfl_code') + ->get(); + $facilities_ever_enrolled = PartnerFacility::where('created_at', '>=', date($request->from))->where('created_at', '<=', date($request->to)); // active clients by gender - $clients_male = Client::select('id')->where([['gender', '=', '2'], ['status', '=', 'Active'],]) - ->whereNull('hei_no') - ->where('created_at', '>=', date($request->from))->where('created_at', '<=', date($request->to)) - ->count(); + $clients_male = Client::join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select('tbl_client.id') + ->where([['tbl_client.gender', '=', '2'], ['tbl_client.status', '=', 'Active'],]) + ->whereNull('tbl_client.hei_no') + ->whereDate('tbl_client.created_at', '>=', date($request->from))->whereDate('tbl_client.created_at', '<=', date($request->to)); - $clients_female = Client::where('gender', '=', '1') - ->where('status', '=', 'Active') - ->whereNull('hei_no') - ->where('created_at', '>=', date($request->from))->where('created_at', '<=', date($request->to)) - ->count(); - $unknown_gender = Client::where('gender', '!=', '1') - ->where('gender', '!=', '2') - ->where('status', '=', 'Active') - ->whereNull('hei_no') - ->where('created_at', '>=', date($request->from))->where('created_at', '<=', date($request->to)) - ->count(); - $client_to_nine = Client::select(\DB::raw("count((case when (((year(curdate()) - year(`dob`)) > 0) and ((year(curdate()) - year(`dob`)) <= 9)) then `dob` end)) AS count")) - ->where('status', '=', 'Active') - ->whereNull('hei_no') - ->where('created_at', '>=', date($request->from))->where('created_at', '<=', date($request->to)) - ->pluck('count'); + $clients_female = Client::join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->where([['tbl_client.gender', '=', '1'], ['tbl_client.status', '=', 'Active'],]) + ->whereNull('tbl_client.hei_no') + ->whereDate('tbl_client.created_at', '>=', date($request->from))->whereDate('tbl_client.created_at', '<=', date($request->to)); + $unknown_gender = Client::join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->where([['tbl_client.gender', '!=', '1'], ['tbl_client.gender', '!=', '2'], ['tbl_client.status', '=', 'Active'],]) + ->whereNull('tbl_client.hei_no') + ->whereDate('tbl_client.created_at', '>=', date($request->from))->whereDate('tbl_client.created_at', '<=', date($request->to)); - $client_to_fourteen = Client::select(\DB::raw("count((case when (((year(curdate()) - year(`dob`)) >= 10) and ((year(curdate()) - year(`dob`)) <= 14)) then `dob` end)) AS count")) - ->where('status', '=', 'Active') - ->whereNull('hei_no') - ->where('created_at', '>=', date($request->from))->where('created_at', '<=', date($request->to)) - ->pluck('count'); + $client_to_nine = Client::join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) > 0) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 9)) then `tbl_client`.`dob` end)) AS count")) + ->where('tbl_client.status', '=', 'Active') + ->whereNull('tbl_client.hei_no') + ->whereDate('tbl_client.created_at', '>=', date($request->from))->whereDate('tbl_client.created_at', '<=', date($request->to)); - $client_to_nineteen = Client::select(\DB::raw("count((case when (((year(curdate()) - year(`dob`)) >= 15) and ((year(curdate()) - year(`dob`)) <= 19)) then `dob` end)) AS count")) - ->where('status', '=', 'Active') - ->whereNull('hei_no') - ->where('created_at', '>=', date($request->from))->where('created_at', '<=', date($request->to)) - ->pluck('count'); - $client_to_twentyfour = Client::select(\DB::raw("count((case when (((year(curdate()) - year(`dob`)) >= 20) and ((year(curdate()) - year(`dob`)) <= 24)) then `id` end)) AS count")) - ->where('status', '=', 'Active') - ->whereNull('hei_no') - ->where('created_at', '>=', date($request->from))->where('created_at', '<=', date($request->to)) - ->pluck('count'); + $client_to_fourteen = Client::join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 10) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 14)) then `tbl_client`.`dob` end)) AS count")) + ->where('tbl_client.status', '=', 'Active') + ->whereNull('tbl_client.hei_no') + ->whereDate('tbl_client.created_at', '>=', date($request->from))->whereDate('tbl_client.created_at', '<=', date($request->to)); - $client_to_twentyfive_above = Client::select(\DB::raw("count((case when (((year(curdate()) - year(`dob`)) >= 25)) then `id` end)) AS count")) - ->where('status', '=', 'Active') - ->whereNull('hei_no') - ->where('created_at', '>=', date($request->from))->where('created_at', '<=', date($request->to)) - ->pluck('count'); - $client_unknown_age = Client::where('dob', '=', '') - ->orWhereNull('dob') - ->where('status', '=', 'Active') - ->whereNull('hei_no') - ->where('created_at', '>=', date($request->from))->where('created_at', '<=', date($request->to)) - ->count(); + $client_to_nineteen = Client::join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 15) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 19)) then `tbl_client`.`dob` end)) AS count")) + ->where('tbl_client.status', '=', 'Active') + ->whereNull('tbl_client.hei_no') + ->whereDate('tbl_client.created_at', '>=', date($request->from))->whereDate('tbl_client.created_at', '<=', date($request->to)); - // appointment by gender - $appointment_male = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') - ->select('tbl_appointment.id') - ->where('tbl_client.gender', '=', '2') - ->where('tbl_appointment.created_at', '>=', date($request->from))->where('tbl_appointment.created_at', '<=', date($request->to)) - ->count(); + $client_to_twentyfour = Client::join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 20) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 24)) then `tbl_client`.`dob` end)) AS count")) + ->where('tbl_client.status', '=', 'Active') + ->whereNull('tbl_client.hei_no') + ->whereDate('tbl_client.created_at', '>=', date($request->from))->whereDate('tbl_client.created_at', '<=', date($request->to)); - $appointment_female = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') - ->select('tbl_appointment.id') - ->where('tbl_client.gender', '=', '1') - ->where('tbl_appointment.created_at', '>=', date($request->from))->where('tbl_appointment.created_at', '<=', date($request->to)) - ->count(); + $client_to_twentyfive_above = Client::join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 25)) then `tbl_client`.`dob` end)) AS count")) + ->where('tbl_client.status', '=', 'Active') + ->whereNull('tbl_client.hei_no') + ->whereDate('tbl_client.created_at', '>=', date($request->from))->whereDate('tbl_client.created_at', '<=', date($request->to)); - $appointment_uknown_gender = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') - ->select('tbl_appointment.id') - ->where('tbl_client.gender', '!=', '1') - ->where('tbl_client.gender', '!=', '2') - ->where('tbl_appointment.created_at', '>=', date($request->from))->where('tbl_appointment.created_at', '<=', date($request->to)) - ->count(); - // appointment by age - $appointment_to_nine = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') - ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') - ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) > 0) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 9)) then `tbl_client`.`id` end)) AS count")) - ->where('tbl_appointment.created_at', '>=', date($request->from))->where('tbl_appointment.created_at', '<=', date($request->to)) - ->pluck('count'); - $appointment_to_fourteen = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') - ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') - ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 10) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 14)) then `tbl_client`.`id` end)) AS count")) - ->where('tbl_appointment.created_at', '>=', date($request->from))->where('tbl_appointment.created_at', '<=', date($request->to)) - ->pluck('count'); + $client_unknown_age = Client::join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->where('tbl_client.dob', '=', '') + ->WhereNull('tbl_client.dob') + ->where('tbl_client.status', '=', 'Active') + ->whereNull('tbl_client.hei_no') + ->whereDate('tbl_client.created_at', '>=', date($request->from))->whereDate('tbl_client.created_at', '<=', date($request->to)); - $appointment_to_nineteen = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') - ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') - ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 15) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 19)) then `tbl_client`.`id` end)) AS count")) - ->where('tbl_appointment.created_at', '>=', date($request->from))->where('tbl_appointment.created_at', '<=', date($request->to)) - ->pluck('count'); - $appointment_to_twentyfour = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') - ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') - ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 20) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 24)) then `tbl_client`.`id` end)) AS count")) - ->where('tbl_appointment.created_at', '>=', date($request->from))->where('tbl_appointment.created_at', '<=', date($request->to)) - ->pluck('count'); + if (!empty($selected_partners)) { + $client = $client->where('tbl_partner_facility.partner_id', $selected_partners); + $client_ever_enrolled = $client_ever_enrolled->where('tbl_partner_facility.partner_id', $selected_partners); + $facilities_ever_enrolled = $facilities_ever_enrolled->where('tbl_partner_facility.partner_id', $selected_partners); + $clients_male = $clients_male->where('tbl_partner_facility.partner_id', $selected_partners); + $clients_female = $clients_female->where('tbl_partner_facility.partner_id', $selected_partners); + $unknown_gender = $unknown_gender->where('tbl_partner_facility.partner_id', $selected_partners); + $client_to_nine = $client_to_nine->where('tbl_partner_facility.partner_id', $selected_partners); + $client_to_fourteen = $client_to_fourteen->where('tbl_partner_facility.partner_id', $selected_partners); + $client_to_nineteen = $client_to_nineteen->where('tbl_partner_facility.partner_id', $selected_partners); + $client_to_twentyfour = $client_to_twentyfour->where('tbl_partner_facility.partner_id', $selected_partners); + $client_to_twentyfive_above = $client_to_twentyfive_above->where('tbl_partner_facility.partner_id', $selected_partners); + $client_unknown_age = $client_unknown_age->where('tbl_partner_facility.partner_id', $selected_partners); - $appointment_to_twentyfive_above = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') - ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') - ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 25)) then `tbl_client`.`id` end)) AS count")) - ->where('tbl_appointment.created_at', '>=', date($request->from))->where('tbl_appointment.created_at', '<=', date($request->to)) - ->pluck('count'); + } + if (!empty($selected_counties)) { + $client = $client->where('tbl_partner_facility.county_id', $selected_counties); + $client_ever_enrolled = $client_ever_enrolled->where('tbl_partner_facility.county_id', $selected_counties); + $facilities_ever_enrolled = $facilities_ever_enrolled->where('tbl_partner_facility.county_id', $selected_counties); + $clients_male = $clients_male->where('tbl_partner_facility.county_id', $selected_counties); + $clients_female = $clients_female->where('tbl_partner_facility.county_id', $selected_counties); + $unknown_gender = $unknown_gender->where('tbl_partner_facility.county_id', $selected_counties); + $client_to_nine = $client_to_nine->where('tbl_partner_facility.county_id', $selected_counties); + $client_to_fourteen = $client_to_fourteen->where('tbl_partner_facility.county_id', $selected_counties); + $client_to_nineteen = $client_to_nineteen->where('tbl_partner_facility.county_id', $selected_counties); + $client_to_twentyfour = $client_to_twentyfour->where('tbl_partner_facility.county_id', $selected_counties); + $client_to_twentyfive_above = $client_to_twentyfive_above->where('tbl_partner_facility.county_id', $selected_counties); + $client_unknown_age = $client_unknown_age->where('tbl_partner_facility.county_id', $selected_counties); + } + if (!empty($selected_subcounties)) { + $client = $client->where('tbl_partner_facility.sub_county_id', $selected_subcounties); + $client_ever_enrolled = $client_ever_enrolled->where('tbl_partner_facility.sub_county_id', $selected_subcounties); + $facilities_ever_enrolled = $facilities_ever_enrolled->where('tbl_partner_facility.sub_county_id', $selected_subcounties); + $clients_male = $clients_male->where('tbl_partner_facility.sub_county_id', $selected_subcounties); + $clients_female = $clients_female->where('tbl_partner_facility.sub_county_id', $selected_subcounties); + $unknown_gender = $unknown_gender->where('tbl_partner_facility.sub_county_id', $selected_subcounties); + $client_to_nine = $client_to_nine->where('tbl_partner_facility.sub_county_id', $selected_subcounties); + $client_to_fourteen = $client_to_fourteen->where('tbl_partner_facility.sub_county_id', $selected_subcounties); + $client_to_nineteen = $client_to_nineteen->where('tbl_partner_facility.sub_county_id', $selected_subcounties); + $client_to_twentyfour = $client_to_twentyfour->where('tbl_partner_facility.sub_county_id', $selected_subcounties); + $client_to_twentyfive_above = $client_to_twentyfive_above->where('tbl_partner_facility.sub_county_id', $selected_subcounties); + $client_unknown_age = $client_unknown_age->where('tbl_partner_facility.sub_county_id', $selected_subcounties); - $appointment_uknown_age = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') - ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') - ->where('tbl_client.dob', '=', '') - ->orWhereNull('tbl_client.dob') - ->where('tbl_appointment.created_at', '>=', date($request->from))->where('tbl_appointment.created_at', '<=', date($request->to)) - ->count(); + } + if (!empty($selected_facilites)) { + $client = $client->where('tbl_partner_facility.mfl_code', $selected_facilites); + $client_ever_enrolled = $client_ever_enrolled->where('tbl_partner_facility.mfl_code', $selected_facilites); + $active_facilities = $active_facilities->where('tbl_partner_facility.mfl_code', $selected_facilites); + $facilities_ever_enrolled = $facilities_ever_enrolled->where('tbl_partner_facility.mfl_code', $selected_facilites); + $clients_male = $clients_male->where('tbl_partner_facility.mfl_code', $selected_facilites); + $clients_female = $clients_female->where('tbl_partner_facility.mfl_code', $selected_facilites); + $unknown_gender = $unknown_gender->where('tbl_partner_facility.mfl_code', $selected_facilites); + $client_to_nine = $client_to_nine->where('tbl_partner_facility.mfl_code', $selected_facilites); + $client_to_fourteen = $client_to_fourteen->where('tbl_partner_facility.mfl_code', $selected_facilites); + $client_to_nineteen = $client_to_nineteen->where('tbl_partner_facility.mfl_code', $selected_facilites); + $client_to_twentyfour = $client_to_twentyfour->where('tbl_partner_facility.mfl_code', $selected_facilites); + $client_to_twentyfive_above = $client_to_twentyfive_above->where('tbl_partner_facility.mfl_code', $selected_facilites); + $client_unknown_age = $client_unknown_age->where('tbl_partner_facility.mfl_code', $selected_facilites); + } + $data["client"] = $client->count(); + $data["facilities_ever_enrolled"] = $facilities_ever_enrolled->count(); + $data["client_ever_enrolled"] = $client_ever_enrolled->count(); + $data["clients_male"] = $clients_male->count(); + $data["clients_female"] = $clients_female->count(); + $data["unknown_gender"] = $unknown_gender->count(); + $data["client_to_nine"] = $client_to_nine->pluck('count'); + $data["client_to_fourteen"] = $client_to_fourteen->pluck('count'); + $data["client_to_nineteen"] = $client_to_nineteen->pluck('count'); + $data["client_to_twentyfour"] = $client_to_twentyfour->pluck('count'); + $data["client_to_twentyfive_above"] = $client_to_twentyfive_above->pluck('count'); + $data["client_unknown_age"] = $client_unknown_age->count(); - // Total missed appointment by gender - $appointment_total_missed_female = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') - ->where('tbl_client.gender', '=', '1') - ->where('tbl_appointment.app_status', '=', 'Missed') - ->orwhere('tbl_appointment.app_status', '=', 'LTFU') - ->orwhere('tbl_appointment.app_status', '=', 'Defaulted') - ->where('tbl_appointment.created_at', '>=', date($request->from))->where('tbl_appointment.created_at', '<=', date($request->to)) - ->count(); - $appointment_total_missed_male = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') - ->where('tbl_client.gender', '=', '2') - ->where('tbl_appointment.app_status', '=', 'Missed') - ->orwhere('tbl_appointment.app_status', '=', 'LTFU') - ->orwhere('tbl_appointment.app_status', '=', 'Defaulted') - ->where('tbl_appointment.created_at', '>=', date($request->from))->where('tbl_appointment.created_at', '<=', date($request->to)) - ->count(); + return $data; - $appointment_total_missed_uknown_gender = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') - ->where('tbl_client.gender', '!=', '1') - ->where('tbl_client.gender', '!=', '2') - ->where('tbl_appointment.app_status', '=', 'Missed') - ->orwhere('tbl_appointment.app_status', '=', 'LTFU') - ->orwhere('tbl_appointment.app_status', '=', 'Defaulted') - ->where('tbl_appointment.created_at', '>=', date($request->from))->where('tbl_appointment.created_at', '<=', date($request->to)) - ->count(); + } + public function filter_client_charts(Request $request) + { + $data = []; + // client charts + $selected_partners = $request->partners; + $selected_counties = $request->counties; + $selected_subcounties = $request->subcounties; + $selected_facilites = $request->facilities; - // Total missed appointment by age - $appointment_total_missed_to_nine = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') - ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) > 0) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 9)) then `tbl_client`.`id` end)) AS count")) - ->where('tbl_appointment.app_status', '=', 'Missed') - ->orwhere('tbl_appointment.app_status', '=', 'LTFU') - ->orwhere('tbl_appointment.app_status', '=', 'Defaulted') - ->where('tbl_appointment.created_at', '>=', date($request->from))->where('tbl_appointment.created_at', '<=', date($request->to)) - ->pluck('count'); + if (Auth::user()->access_level == 'Facility'){} + if (Auth::user()->access_level == 'Partner'){} - $appointment_total_missed_to_fourteen = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') - ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 10) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 14)) then `tbl_client`.`id` end)) AS count")) - ->where('tbl_appointment.app_status', '=', 'Missed') - ->orwhere('tbl_appointment.app_status', '=', 'LTFU') - ->orwhere('tbl_appointment.app_status', '=', 'Defaulted') - ->where('tbl_appointment.created_at', '>=', date($request->from))->where('tbl_appointment.created_at', '<=', date($request->to)) - ->pluck('count'); + $client = Client::join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->where('tbl_client.status', '=', 'Active') + ->whereNull('tbl_client.hei_no') + ->where('tbl_client.created_at', '>=', date($request->from))->where('tbl_client.created_at', '<=', date($request->to)); + $client_consented = Client::join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select('tbl_client.id') + ->where('tbl_client.status', '=', 'Active') + ->whereNull('tbl_client.hei_no') + ->where('tbl_client.smsenable', '=', 'Yes') + ->where('tbl_client.created_at', '>=', date($request->from))->where('tbl_client.created_at', '<=', date($request->to)); - $appointment_total_missed_to_nineteen = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') - ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 15) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 19)) then `tbl_client`.`id` end)) AS count")) - ->where('tbl_appointment.date_attended', '!=', 'tbl_appointment.appntmnt_date') - ->where('tbl_appointment.created_at', '>=', date($request->from))->where('tbl_appointment.created_at', '<=', date($request->to)) - ->pluck('count'); + $client_nonconsented = Client::join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select('tbl_client.id') + ->where('tbl_client.status', '=', 'Active') + ->whereNull('tbl_client.hei_no') + ->where('tbl_client.smsenable', '!=', 'Yes') + ->where('tbl_client.created_at', '>=', date($request->from))->where('tbl_client.created_at', '<=', date($request->to)); - $appointment_total_missed_to_twentyfour = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') - ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 20) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 24)) then `tbl_client`.`id` end)) AS count")) - ->where('tbl_appointment.date_attended', '!=', 'tbl_appointment.appntmnt_date') - ->where('tbl_appointment.created_at', '>=', date($request->from))->where('tbl_appointment.created_at', '<=', date($request->to)) - ->pluck('count'); + // consented clients by gender - $appointment_total_missed_to_twentyfive_above = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') - ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 25)) then `tbl_client`.`id` end)) AS count")) - ->where('tbl_appointment.app_status', '=', 'Missed') - ->orwhere('tbl_appointment.app_status', '=', 'LTFU') - ->orwhere('tbl_appointment.app_status', '=', 'Defaulted') - ->where('tbl_appointment.created_at', '>=', date($request->from))->where('tbl_appointment.created_at', '<=', date($request->to)) - ->pluck('count'); + $client_consented_male = Client::join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->where('tbl_client.smsenable', '=', 'Yes') + ->where('tbl_client.status', '=', 'Active') + ->whereNull('tbl_client.hei_no') + ->where('tbl_client.gender', '=', '2') + ->where('tbl_client.created_at', '>=', date($request->from))->where('tbl_client.created_at', '<=', date($request->to)); - $appointment_total_missed_uknown_age = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') - ->where('tbl_client.dob', '=', '') - ->orWhereNull('tbl_client.dob') - ->where('tbl_appointment.app_status', '=', 'Missed') - ->orwhere('tbl_appointment.app_status', '=', 'LTFU') - ->orwhere('tbl_appointment.app_status', '=', 'Defaulted') - ->where('tbl_appointment.created_at', '>=', date($request->from))->where('tbl_appointment.created_at', '<=', date($request->to)) - ->count(); + $client_consented_female = Client::join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->where('tbl_client.smsenable', '=', 'Yes') + ->where('tbl_client.status', '=', 'Active') + ->whereNull('tbl_client.hei_no') + ->where('tbl_client.gender', '=', '1') + ->where('tbl_client.created_at', '>=', date($request->from))->where('tbl_client.created_at', '<=', date($request->to)); - // client charts - $client_consented = Client::select('smsenable') - ->where('status', '=', 'Active') - ->whereNull('hei_no') - ->where('smsenable', '=', 'Yes') - ->where('created_at', '>=', date($request->from))->where('created_at', '<=', date($request->to)) - ->count(); - $client_nonconsented = Client::select('smsenable') - ->where('status', '=', 'Active') - ->whereNull('hei_no') - ->where('smsenable', '!=', 'Yes') - ->where('created_at', '>=', date($request->from))->where('created_at', '<=', date($request->to)) - ->count(); + $client_consented_uknown_gender = Client::join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->where('tbl_client.smsenable', '=', 'Yes') + ->where('tbl_client.status', '=', 'Active') + ->whereNull('tbl_client.hei_no') + ->where('tbl_client.gender', '!=', '1') + ->where('tbl_client.gender', '!=', '2') + ->where('tbl_client.created_at', '>=', date($request->from))->where('tbl_client.created_at', '<=', date($request->to)); - // consented clients by gender + // non consented clients by gender + $client_nonconsented_male = Client::join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->where('tbl_client.smsenable', '!=', 'Yes') + ->where('tbl_client.status', '=', 'Active') + ->whereNull('tbl_client.hei_no') + ->where('tbl_client.gender', '=', '2') + ->where('tbl_client.created_at', '>=', date($request->from))->where('tbl_client.created_at', '<=', date($request->to)); - $client_consented_male = Client::where('smsenable', '=', 'Yes') - ->where('status', '=', 'Active') - ->whereNull('hei_no') - ->where('gender', '=', '2') - ->where('created_at', '>=', date($request->from))->where('created_at', '<=', date($request->to)) - ->count(); - $client_consented_female = Client::where('smsenable', '=', 'Yes') - ->where('status', '=', 'Active') - ->whereNull('hei_no') - ->where('gender', '=', '1') - ->where('created_at', '>=', date($request->from))->where('created_at', '<=', date($request->to)) - ->count(); - $client_consented_uknown_gender = Client::where('smsenable', '=', 'Yes') - ->where('status', '=', 'Active') - ->whereNull('hei_no') - ->where('gender', '!=', '1') - ->where('gender', '!=', '2') - ->where('created_at', '>=', date($request->from))->where('created_at', '<=', date($request->to)) - ->count(); - // non consented clients by gender - $client_nonconsented_male = Client::where('smsenable', '!=', 'Yes') - ->where('status', '=', 'Active') - ->whereNull('hei_no') - ->where('gender', '=', '2') - ->where('created_at', '>=', date($request->from))->where('created_at', '<=', date($request->to)) - ->count(); - $client_nonconsented_female = Client::where('smsenable', '!=', 'Yes') - ->where('status', '=', 'Active') - ->whereNull('hei_no') - ->where('gender', '=', '1') - ->where('created_at', '>=', date($request->from))->where('created_at', '<=', date($request->to)) - ->count(); - - $client_nonconsented_uknown_gender = Client::where('smsenable', '!=', 'Yes') - ->where('gender', '!=', '1') - ->where('gender', '!=', '2') - ->where('created_at', '>=', date($request->from))->where('created_at', '<=', date($request->to)) - ->count(); - - // consented clients by age distribution - $client_consented_to_nine = Client::select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) > 0) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 9)) then `tbl_client`.`id` end)) AS count")) - ->where('smsenable', '=', 'Yes') - ->where('status', '=', 'Active') - ->whereNull('hei_no') - ->pluck('count'); - - $client_consented_to_fourteen = Client::select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 10) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 14)) then `tbl_client`.`id` end)) AS count")) - ->where('smsenable', '=', 'Yes') - ->where('status', '=', 'Active') - ->whereNull('hei_no') - ->where('created_at', '>=', date($request->from))->where('created_at', '<=', date($request->to)) - ->pluck('count'); - - $client_consented_to_nineteen = Client::select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 15) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 19)) then `tbl_client`.`id` end)) AS count")) - ->where('smsenable', '=', 'Yes') - ->where('status', '=', 'Active') - ->whereNull('hei_no') - ->where('created_at', '>=', date($request->from))->where('created_at', '<=', date($request->to)) - ->pluck('count'); - - $client_consented_to_twentyfour = Client::select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 20) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 24)) then `tbl_client`.`id` end)) AS count")) - ->where('smsenable', '=', 'Yes') - ->where('status', '=', 'Active') - ->whereNull('hei_no') - ->pluck('count'); + $client_nonconsented_female = Client::join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->where('tbl_client.smsenable', '!=', 'Yes') + ->where('tbl_client.status', '=', 'Active') + ->whereNull('tbl_client.hei_no') + ->where('tbl_client.gender', '=', '1') + ->where('tbl_client.created_at', '>=', date($request->from))->where('tbl_client.created_at', '<=', date($request->to)); - $client_consented_to_twentyfive_above = Client::select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 25)) then `tbl_client`.`id` end)) AS count")) - ->where('smsenable', '=', 'Yes') - ->where('status', '=', 'Active') - ->whereNull('hei_no') - ->where('created_at', '>=', date($request->from))->where('created_at', '<=', date($request->to)) - ->pluck('count'); + $client_nonconsented_uknown_gender = Client::join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->where('tbl_client.smsenable', '!=', 'Yes') + ->where('tbl_client.gender', '!=', '1') + ->where('tbl_client.gender', '!=', '2') + ->where('tbl_client.created_at', '>=', date($request->from))->where('tbl_client.created_at', '<=', date($request->to)); - $client_consented_uknown_age = Client::select('smsenable') - ->where('dob', '=', '') - ->where('status', '=', 'Active') - ->whereNull('hei_no') - ->orWhereNull('dob') - ->where('smsenable', '=', 'Yes') - ->where('created_at', '>=', date($request->from))->where('created_at', '<=', date($request->to)) - ->count(); - // non consented clients by age distribution - $client_nonconsented_to_nine = Client::select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) > 0) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 9)) then `tbl_client`.`id` end)) AS count")) - ->where('smsenable', '!=', 'Yes') - ->where('status', '=', 'Active') - ->whereNull('hei_no') - ->where('created_at', '>=', date($request->from))->where('created_at', '<=', date($request->to)) - ->pluck('count'); - $client_nonconsented_to_fourteen = Client::select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 10) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 14)) then `tbl_client`.`id` end)) AS count")) - ->where('smsenable', '!=', 'Yes') - ->where('status', '=', 'Active') - ->whereNull('hei_no') - ->where('created_at', '>=', date($request->from))->where('created_at', '<=', date($request->to)) - ->pluck('count'); + // consented clients by age distribution + $client_consented_to_nine = Client::join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select(\DB::raw("case when (((year(curdate()) - year(`tbl_client`.`tbl_client`.`dob`)) > 0) and ((year(curdate()) - year(`tbl_client`.`tbl_client`.`dob`)) <= 9)) then `tbl_client`.`id` end")) + ->where('tbl_client.smsenable', '=', 'Yes') + ->where('tbl_client.status', '=', 'Active') + ->whereNull('tbl_client.hei_no') + ->where('tbl_client.created_at', '>=', date($request->from))->where('tbl_client.created_at', '<=', date($request->to)); - $client_nonconsented_to_nineteen = Client::select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 15) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 19)) then `tbl_client`.`id` end)) AS count")) - ->where('smsenable', '!=', 'Yes') - ->where('status', '=', 'Active') - ->whereNull('hei_no') - ->where('created_at', '>=', date($request->from))->where('created_at', '<=', date($request->to)) - ->pluck('count'); - $client_nonconsented_to_twentyfour = Client::select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 20) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 24)) then `tbl_client`.`id` end)) AS count")) - ->where('smsenable', '!=', 'Yes') - ->where('status', '=', 'Active') - ->whereNull('hei_no') - ->where('created_at', '>=', date($request->from))->where('created_at', '<=', date($request->to)) - ->pluck('count'); + $client_consented_to_fourteen = Client::join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select(\DB::raw("case when (((year(curdate()) - year(`tbl_client`.`tbl_client`.`dob`)) >= 10) and ((year(curdate()) - year(`tbl_client`.`tbl_client`.`dob`)) <= 14)) then `tbl_client`.`id` end")) + ->where('tbl_client.smsenable', '=', 'Yes') + ->where('tbl_client.status', '=', 'Active') + ->whereNull('tbl_client.hei_no') + ->where('tbl_client.created_at', '>=', date($request->from))->where('tbl_client.created_at', '<=', date($request->to)); - $client_nonconsented_to_twentyfive_above = Client::select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 25)) then `tbl_client`.`id` end)) AS count")) - ->where('smsenable', '!=', 'Yes') - ->where('status', '=', 'Active') - ->whereNull('hei_no') - ->where('created_at', '>=', date($request->from))->where('created_at', '<=', date($request->to)) - ->pluck('count'); - $client_nonconsented_uknown_age = Client::select('smsenable') - ->where('status', '=', 'Active') - ->whereNull('hei_no') - ->where('dob', '=', '') - ->orWhereNull('dob') - ->where('smsenable', '!=', 'Yes') - ->where('created_at', '>=', date($request->from))->where('created_at', '<=', date($request->to)) - ->count(); + $client_consented_to_nineteen = Client::join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select(\DB::raw("case when (((year(curdate()) - year(`tbl_client`.`tbl_client`.`dob`)) >= 15) and ((year(curdate()) - year(`tbl_client`.`tbl_client`.`dob`)) <= 19)) then `tbl_client`.`id` end")) + ->where('tbl_client.smsenable', '=', 'Yes') + ->where('tbl_client.status', '=', 'Active') + ->whereNull('tbl_client.hei_no') + ->where('tbl_client.created_at', '>=', date($request->from))->where('tbl_client.created_at', '<=', date($request->to)); - // main appointments - $appointment_honoured = Appointments::select('id')->where('appntmnt_date', '=', 'date_attended') - ->where('created_at', '>=', date($request->from))->where('created_at', '<=', date($request->to)) - ->count(); - - // dd($appointment_honoured); - $appointment_not_honoured = Appointments::select('id') - ->where('tbl_appointment.app_status', '=', 'Missed') - ->orwhere('tbl_appointment.app_status', '=', 'LTFU') - ->orwhere('tbl_appointment.app_status', '=', 'Defaulted') - ->where('created_at', '>=', date($request->from))->where('created_at', '<=', date($request->to)) - ->count(); - // appointment honored by gender - $appointment_honoured_male = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') - ->where('tbl_client.gender', '=', '2') - ->where('tbl_appointment.date_attended', '=', 'tbl_appointment.appntmnt_date') - ->where('tbl_appointment.created_at', '>=', date($request->from))->where('tbl_appointment.created_at', '<=', date($request->to)) - ->count(); - $appointment_honoured_female = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') - ->where('tbl_client.gender', '=', '1') - ->where('tbl_appointment.date_attended', '=', 'tbl_appointment.appntmnt_date') - ->where('tbl_appointment.created_at', '>=', date($request->from))->where('tbl_appointment.created_at', '<=', date($request->to)) - ->count(); - $appointment_honoured_uknown_gender = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') - ->where('tbl_client.gender', '!=', '1') - ->where('tbl_client.gender', '!=', '2') - ->where('tbl_appointment.date_attended', '=', 'tbl_appointment.appntmnt_date') - ->where('tbl_appointment.created_at', '>=', date($request->from))->where('tbl_appointment.created_at', '<=', date($request->to)) - ->count(); - // appointment honored by age - $appointment_honored_to_nine = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') - ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') - ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) > 0) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 9)) then `tbl_client`.`id` end)) AS count")) - ->where('tbl_appointment.date_attended', '=', 'tbl_appointment.appntmnt_date') - ->where('tbl_appointment.created_at', '>=', date($request->from))->where('tbl_appointment.created_at', '<=', date($request->to)) - ->pluck('count'); - $appointment_honored_to_fourteen = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') - ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') - ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 10) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 14)) then `tbl_client`.`id` end)) AS count")) - ->where('tbl_appointment.date_attended', '=', 'tbl_appointment.appntmnt_date') - ->where('tbl_appointment.created_at', '>=', date($request->from))->where('tbl_appointment.created_at', '<=', date($request->to)) - ->pluck('count'); - $appointment_honored_to_nineteen = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') - ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') - ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 15) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 19)) then `tbl_client`.`id` end)) AS count")) - ->where('tbl_appointment.date_attended', '=', 'tbl_appointment.appntmnt_date') - ->where('tbl_appointment.created_at', '>=', date($request->from))->where('tbl_appointment.created_at', '<=', date($request->to)) - ->pluck('count'); + $client_consented_to_twentyfour = Client::join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select(\DB::raw("case when (((year(curdate()) - year(`tbl_client`.`tbl_client`.`dob`)) >= 20) and ((year(curdate()) - year(`tbl_client`.`tbl_client`.`dob`)) <= 24)) then `tbl_client`.`id` end")) + ->where('tbl_client.smsenable', '=', 'Yes') + ->where('tbl_client.status', '=', 'Active') + ->whereNull('tbl_client.hei_no') + ->where('tbl_client.created_at', '>=', date($request->from))->where('tbl_client.created_at', '<=', date($request->to)); - $appointment_honored_to_twentyfour = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') - ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') - ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 20) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 24)) then `tbl_client`.`id` end)) AS count")) - ->where('tbl_appointment.date_attended', '=', 'tbl_appointment.appntmnt_date') - ->where('tbl_appointment.created_at', '>=', date($request->from))->where('tbl_appointment.created_at', '<=', date($request->to)) - ->pluck('count'); - $appointment_honored_to_twentyfive_above = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') - ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') - ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 25)) then `tbl_client`.`id` end)) AS count")) - ->where('tbl_appointment.date_attended', '=', 'tbl_appointment.appntmnt_date') - ->where('tbl_appointment.created_at', '>=', date($request->from))->where('tbl_appointment.created_at', '<=', date($request->to)) - ->pluck('count'); - $appointment_honored_to_uknown_age = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') - ->select('tbl_client.dob') - ->where('tbl_client.dob', '=', '') - ->orWhereNull('tbl_client.dob') - ->where('tbl_appointment.date_attended', '=', 'tbl_appointment.appntmnt_date') - ->where('tbl_appointment.created_at', '>=', date($request->from))->where('tbl_appointment.created_at', '<=', date($request->to)) - ->count(); + $client_consented_to_twentyfive_above = Client::join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select(\DB::raw("case when (((year(curdate()) - year(`tbl_client`.`tbl_client`.`dob`)) >= 25)) then `tbl_client`.`id` end")) + ->where('tbl_client.smsenable', '=', 'Yes') + ->where('tbl_client.status', '=', 'Active') + ->whereNull('tbl_client.hei_no') + ->where('tbl_client.created_at', '>=', date($request->from))->where('tbl_client.created_at', '<=', date($request->to)); - // appointment not honored by gender - $appointment_not_honoured_male = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') - ->where('tbl_client.gender', '=', '2') - ->where('tbl_appointment.app_status', '=', 'Missed') - ->orwhere('tbl_appointment.app_status', '=', 'LTFU') - ->orwhere('tbl_appointment.app_status', '=', 'Defaulted') - ->where('tbl_appointment.created_at', '>=', date($request->from))->where('tbl_appointment.created_at', '<=', date($request->to)) - ->count(); - $appointment_not_honoured_female = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') - ->where('tbl_client.gender', '=', '1') - ->where('tbl_appointment.app_status', '=', 'Missed') - ->orwhere('tbl_appointment.app_status', '=', 'LTFU') - ->orwhere('tbl_appointment.app_status', '=', 'Defaulted') - ->where('tbl_appointment.created_at', '>=', date($request->from))->where('tbl_appointment.created_at', '<=', date($request->to)) - ->count(); - $appointment_not_honoured_uknown_gender = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') - ->where('tbl_client.gender', '!=', '1') - ->where('tbl_client.gender', '!=', '2') - ->where('tbl_appointment.app_status', '=', 'Missed') - ->orwhere('tbl_appointment.app_status', '=', 'LTFU') - ->orwhere('tbl_appointment.app_status', '=', 'Defaulted') - ->where('tbl_appointment.created_at', '>=', date($request->from))->where('tbl_appointment.created_at', '<=', date($request->to)) - ->count(); - // appointment not honored by age - $appointment_not_honored_to_nine = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') - ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') - ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) > 0) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 9)) then `tbl_client`.`id` end)) AS count")) - ->where('tbl_appointment.app_status', '=', 'Missed') - ->orwhere('tbl_appointment.app_status', '=', 'LTFU') - ->orwhere('tbl_appointment.app_status', '=', 'Defaulted') - ->where('tbl_appointment.created_at', '>=', date($request->from))->where('tbl_appointment.created_at', '<=', date($request->to)) - ->pluck('count'); - $appointment_not_honored_to_fourteen = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') - ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') - ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 10) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 14)) then `tbl_client`.`id` end)) AS count")) - ->where('tbl_appointment.app_status', '=', 'Missed') - ->orwhere('tbl_appointment.app_status', '=', 'LTFU') - ->orwhere('tbl_appointment.app_status', '=', 'Defaulted') - ->where('tbl_appointment.created_at', '>=', date($request->from))->where('tbl_appointment.created_at', '<=', date($request->to)) - ->pluck('count'); - $appointment_not_honored_to_nineteen = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') - ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') - ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 15) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 19)) then `tbl_client`.`id` end)) AS count")) - ->where('tbl_appointment.app_status', '=', 'Missed') - ->orwhere('tbl_appointment.app_status', '=', 'LTFU') - ->orwhere('tbl_appointment.app_status', '=', 'Defaulted') - ->where('tbl_appointment.created_at', '>=', date($request->from))->where('tbl_appointment.created_at', '<=', date($request->to)) - ->pluck('count'); - $appointment_not_honored_to_twentyfour = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') - ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') - ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 20) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 24)) then `tbl_client`.`id` end)) AS count")) - ->where('tbl_appointment.app_status', '=', 'Missed') - ->orwhere('tbl_appointment.app_status', '=', 'LTFU') - ->orwhere('tbl_appointment.app_status', '=', 'Defaulted') - ->where('tbl_appointment.created_at', '>=', date($request->from))->where('tbl_appointment.created_at', '<=', date($request->to)) - ->pluck('count'); - $appointment_not_honored_to_twentyfive_above = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') - ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') - ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 25)) then `tbl_client`.`id` end)) AS count")) - ->where('tbl_appointment.app_status', '=', 'Missed') - ->orwhere('tbl_appointment.app_status', '=', 'LTFU') - ->orwhere('tbl_appointment.app_status', '=', 'Defaulted') - ->where('tbl_appointment.created_at', '>=', date($request->from))->where('tbl_appointment.created_at', '<=', date($request->to)) - ->pluck('count'); - $appointment_not_honored_to_uknown_age = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') - ->select('tbl_client.dob') - ->where('tbl_client.dob', '=', '') - ->orWhereNull('tbl_client.dob') - ->where('tbl_appointment.app_status', '=', 'Missed') - ->orwhere('tbl_appointment.app_status', '=', 'LTFU') - ->orwhere('tbl_appointment.app_status', '=', 'Defaulted') - ->where('tbl_appointment.created_at', '>=', date($request->from))->where('tbl_appointment.created_at', '<=', date($request->to)) - ->count(); - // missed appointments + $client_consented_uknown_age = Client::join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select('tbl_client.smsenable') + ->where('tbl_client.dob', '=', '') + ->where('tbl_client.status', '=', 'Active') + ->whereNull('tbl_client.hei_no') + ->orWhereNull('tbl_client.dob') + ->where('tbl_client.smsenable', '=', 'Yes') + ->where('tbl_client.created_at', '>=', date($request->from))->where('tbl_client.created_at', '<=', date($request->to)); + + // non consented clients by age distribution + $client_nonconsented_to_nine = Client::join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select(\DB::raw("case when (((year(curdate()) - year(`tbl_client`.`tbl_client`.`dob`)) > 0) and ((year(curdate()) - year(`tbl_client`.`tbl_client`.`dob`)) <= 9)) then `tbl_client`.`id` end")) + ->where('tbl_client.smsenable', '!=', 'Yes') + ->where('tbl_client.status', '=', 'Active') + ->whereNull('tbl_client.hei_no') + ->where('tbl_client.created_at', '>=', date($request->from))->where('tbl_client.created_at', '<=', date($request->to)); - $appointment_missed = Appointments::where('app_status', '=', 'Missed') - ->where('created_at', '>=', date($request->from))->where('created_at', '<=', date($request->to)) - ->count(); - $appointment_defaulted = Appointments::where('app_status', '=', 'Defaulted') - ->where('created_at', '>=', date($request->from))->where('created_at', '<=', date($request->to)) - ->count(); - $appointment_lftu = Appointments::where('app_status', '=', 'LTFU') - ->where('created_at', '>=', date($request->from))->where('created_at', '<=', date($request->to)) - ->count(); + $client_nonconsented_to_fourteen = Client::join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select(\DB::raw("case when (((year(curdate()) - year(`tbl_client`.`tbl_client`.`dob`)) >= 10) and ((year(curdate()) - year(`tbl_client`.`tbl_client`.`dob`)) <= 14)) then `tbl_client`.`id` end")) + ->where('tbl_client.smsenable', '!=', 'Yes') + ->where('tbl_client.status', '=', 'Active') + ->whereNull('tbl_client.hei_no') + ->where('tbl_client.created_at', '>=', date($request->from))->where('tbl_client.created_at', '<=', date($request->to)); - // missed appointment by gender - $appointment_missed_female = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') - ->where('tbl_appointment.app_status', '=', 'Missed') - ->where('tbl_client.gender', '=', '1') - ->where('tbl_appointment.created_at', '>=', date($request->from))->where('tbl_appointment.created_at', '<=', date($request->to)) - ->count(); - $appointment_missed_male = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') - ->where('tbl_appointment.app_status', '=', 'Missed') - ->where('tbl_client.gender', '=', '2') - ->where('tbl_appointment.created_at', '>=', date($request->from))->where('tbl_appointment.created_at', '<=', date($request->to)) - ->count(); - $appointment_missed_uknown_gender = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') - ->where('tbl_appointment.app_status', '=', 'Missed') - ->where('tbl_client.gender', '!=', '1') - ->where('tbl_client.gender', '!=', '2') - ->where('tbl_appointment.created_at', '>=', date($request->from))->where('tbl_appointment.created_at', '<=', date($request->to)) - ->count(); - // missed appointment by age - $appointment_missed_to_nine = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') - ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) > 0) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 9)) then `tbl_client`.`id` end)) AS count")) - ->where('tbl_appointment.app_status', '=', 'Missed') - ->where('tbl_appointment.created_at', '>=', date($request->from))->where('tbl_appointment.created_at', '<=', date($request->to)) - ->pluck('count'); - $appointment_missed_to_fourteen = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') - ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 10) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 14)) then `tbl_client`.`id` end)) AS count")) - ->where('tbl_appointment.app_status', '=', 'Missed') - ->where('tbl_appointment.created_at', '>=', date($request->from))->where('tbl_appointment.created_at', '<=', date($request->to)) - ->pluck('count'); - $appointment_missed_to_nineteen = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') - ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 15) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 19)) then `tbl_client`.`id` end)) AS count")) - ->where('tbl_appointment.app_status', '=', 'Missed') - ->where('tbl_appointment.created_at', '>=', date($request->from))->where('tbl_appointment.created_at', '<=', date($request->to)) - ->pluck('count'); - $appointment_missed_to_twentyfour = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') - ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 20) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 24)) then `tbl_client`.`id` end)) AS count")) - ->where('tbl_appointment.app_status', '=', 'Missed') - ->where('tbl_appointment.created_at', '>=', date($request->from))->where('tbl_appointment.created_at', '<=', date($request->to)) - ->pluck('count'); - $appointment_missed_to_twentyfive_above = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') - ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 25)) then `tbl_client`.`id` end)) AS count")) - ->where('tbl_appointment.app_status', '=', 'Missed') - ->where('tbl_appointment.created_at', '>=', date($request->from))->where('tbl_appointment.created_at', '<=', date($request->to)) - ->pluck('count'); - $appointment_missed_to_uknown_age = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') - ->select('tbl_client.dob') - ->where('tbl_client.dob', '=', '') - ->orWhereNull('tbl_client.dob') - ->where('tbl_appointment.app_status', '=', 'Missed') - ->where('tbl_appointment.created_at', '>=', date($request->from))->where('tbl_appointment.created_at', '<=', date($request->to)) - ->count(); - // defaulted appointment by gender - $appointment_defaulted_female = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') - ->where('tbl_appointment.app_status', '=', 'Defaulted') - ->where('tbl_client.gender', '=', '1') - ->where('tbl_appointment.created_at', '>=', date($request->from))->where('tbl_appointment.created_at', '<=', date($request->to)) - ->count(); - $appointment_defaulted_male = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') - ->where('tbl_appointment.app_status', '=', 'Defaulted') - ->where('tbl_client.gender', '=', '2') - ->where('tbl_appointment.created_at', '>=', date($request->from))->where('tbl_appointment.created_at', '<=', date($request->to)) - ->count(); - $appointment_defaulted_uknown_gender = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') - ->where('tbl_appointment.app_status', '=', 'Defaulted') - ->where('tbl_client.gender', '!=', '1') - ->where('tbl_client.gender', '!=', '2') - ->where('tbl_appointment.created_at', '>=', date($request->from))->where('tbl_appointment.created_at', '<=', date($request->to)) - ->count(); + $client_nonconsented_to_nineteen = Client::join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select(\DB::raw("case when (((year(curdate()) - year(`tbl_client`.`tbl_client`.`dob`)) >= 15) and ((year(curdate()) - year(`tbl_client`.`tbl_client`.`dob`)) <= 19)) then `tbl_client`.`id` end")) + ->where('tbl_client.smsenable', '!=', 'Yes') + ->where('tbl_client.status', '=', 'Active') + ->whereNull('tbl_client.hei_no') + ->where('tbl_client.created_at', '>=', date($request->from))->where('tbl_client.created_at', '<=', date($request->to)); - // defaulted appointment by age - $appointment_defaulted_to_nine = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') - ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) > 0) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 9)) then `tbl_client`.`id` end)) AS count")) - ->where('tbl_appointment.app_status', '=', 'Defaulted') - ->where('tbl_appointment.created_at', '>=', date($request->from))->where('tbl_appointment.created_at', '<=', date($request->to)) - ->pluck('count'); - $appointment_defaulted_to_fourteen = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') - ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 10) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 14)) then `tbl_client`.`id` end)) AS count")) - ->where('tbl_appointment.app_status', '=', 'Defaulted') - ->where('tbl_appointment.created_at', '>=', date($request->from))->where('tbl_appointment.created_at', '<=', date($request->to)) - ->pluck('count'); - $appointment_defaulted_to_nineteen = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') - ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 15) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 19)) then `tbl_client`.`id` end)) AS count")) - ->where('tbl_appointment.app_status', '=', 'Defaulted') - ->where('tbl_appointment.created_at', '>=', date($request->from))->where('tbl_appointment.created_at', '<=', date($request->to)) - ->pluck('count'); - $appointment_defaulted_to_twentyfour = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') - ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 20) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 24)) then `tbl_client`.`id` end)) AS count")) - ->where('tbl_appointment.app_status', '=', 'Defaulted') - ->where('tbl_appointment.created_at', '>=', date($request->from))->where('tbl_appointment.created_at', '<=', date($request->to)) - ->pluck('count'); - $appointment_defaulted_to_twentyfive_above = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') - ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 25)) then `tbl_client`.`id` end)) AS count")) - ->where('tbl_appointment.app_status', '=', 'Defaulted') - ->where('tbl_appointment.created_at', '>=', date($request->from))->where('tbl_appointment.created_at', '<=', date($request->to)) - ->pluck('count'); - $appointment_defaulted_to_uknown_age = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') - ->select('tbl_client.dob') - ->where('tbl_client.dob', '=', '') - ->orWhereNull('tbl_client.dob') - ->where('tbl_appointment.app_status', '=', 'Defaulted') - ->where('tbl_appointment.created_at', '>=', date($request->from))->where('tbl_appointment.created_at', '<=', date($request->to)) - ->count(); - // ltfu appointment by gender - $appointment_ltfu_female = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') - ->where('tbl_appointment.app_status', '=', 'LTFU') - ->where('tbl_client.gender', '=', '1') - ->where('tbl_appointment.created_at', '>=', date($request->from))->where('tbl_appointment.created_at', '<=', date($request->to)) - ->count(); - $appointment_ltfu_male = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') - ->where('tbl_appointment.app_status', '=', 'LTFU') - ->where('tbl_client.gender', '=', '2') - ->where('tbl_appointment.created_at', '>=', date($request->from))->where('tbl_appointment.created_at', '<=', date($request->to)) - ->count(); - $appointment_ltfu_uknown_gender = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') - ->where('tbl_appointment.app_status', '=', 'LTFU') - ->where('tbl_client.gender', '!=', '1') - ->where('tbl_client.gender', '!=', '2') - ->where('tbl_appointment.created_at', '>=', date($request->from))->where('tbl_appointment.created_at', '<=', date($request->to)) - ->count(); + $client_nonconsented_to_twentyfour = Client::join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select(\DB::raw("case when (((year(curdate()) - year(`tbl_client`.`tbl_client`.`dob`)) >= 20) and ((year(curdate()) - year(`tbl_client`.`tbl_client`.`dob`)) <= 24)) then `tbl_client`.`id` end")) + ->where('tbl_client.smsenable', '!=', 'Yes') + ->where('tbl_client.status', '=', 'Active') + ->whereNull('tbl_client.hei_no') + ->where('tbl_client.created_at', '>=', date($request->from))->where('tbl_client.created_at', '<=', date($request->to)); - // ltfu appointment by age - $appointment_ltfu_to_nine = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') - ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) > 0) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 9)) then `tbl_client`.`id` end)) AS count")) - ->where('tbl_appointment.app_status', '=', 'LTFU') - ->where('tbl_appointment.created_at', '>=', date($request->from))->where('tbl_appointment.created_at', '<=', date($request->to)) - ->pluck('count'); - $appointment_ltfu_to_fourteen = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') - ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 10) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 14)) then `tbl_client`.`id` end)) AS count")) - ->where('tbl_appointment.app_status', '=', 'LTFU') - ->where('tbl_appointment.created_at', '>=', date($request->from))->where('tbl_appointment.created_at', '<=', date($request->to)) - ->pluck('count'); - $appointment_ltfu_to_nineteen = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') - ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 15) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 19)) then `tbl_client`.`id` end)) AS count")) - ->where('tbl_appointment.app_status', '=', 'LTFU') - ->where('tbl_appointment.created_at', '>=', date($request->from))->where('tbl_appointment.created_at', '<=', date($request->to)) - ->pluck('count'); - $appointment_ltfu_to_twentyfour = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') - ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 20) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 24)) then `tbl_client`.`id` end)) AS count")) - ->where('tbl_appointment.app_status', '=', 'LTFU') - ->where('tbl_appointment.created_at', '>=', date($request->from))->where('tbl_appointment.created_at', '<=', date($request->to)) - ->pluck('count'); - $appointment_ltfu_to_twentyfive_above = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') - ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 25)) then `tbl_client`.`id` end)) AS count")) - ->where('tbl_appointment.app_status', '=', 'LTFU') - ->where('tbl_appointment.created_at', '>=', date($request->from))->where('tbl_appointment.created_at', '<=', date($request->to)) - ->pluck('count'); - $appointment_ltfu_to_uknown_age = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') - ->select('tbl_client.dob') - ->where('tbl_client.dob', '=', '') - ->orWhereNull('tbl_client.dob') - ->where('tbl_appointment.app_status', '=', 'LTFU') - ->where('tbl_appointment.created_at', '>=', date($request->from))->where('tbl_appointment.created_at', '<=', date($request->to)) - ->count(); - } - return view('new_dashboard.main_dashbaord', compact('data')); + $client_nonconsented_to_twentyfive_above = Client::join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select(\DB::raw("case when (((year(curdate()) - year(`tbl_client`.`tbl_client`.`dob`)) >= 25)) then `tbl_client`.`id` end")) + ->where('tbl_client.smsenable', '!=', 'Yes') + ->where('tbl_client.status', '=', 'Active') + ->whereNull('tbl_client.hei_no') + ->where('tbl_client.created_at', '>=', date($request->from))->where('tbl_client.created_at', '<=', date($request->to)); + $client_nonconsented_uknown_age = Client::join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select('tbl_client.smsenable') + ->where('tbl_client.status', '=', 'Active') + ->whereNull('tbl_client.hei_no') + ->where('tbl_client.dob', '=', '') + ->orWhereNull('tbl_client.dob') + ->where('tbl_client.smsenable', '!=', 'Yes') + ->where('tbl_client.created_at', '>=', date($request->from))->where('tbl_client.created_at', '<=', date($request->to)); + + if (!empty($selected_partners)) { + $client = $client->where('tbl_partner_facility.partner_id', $selected_partners); + $client_consented = $client_consented->where('tbl_partner_facility.partner_id', $selected_partners); + $client_nonconsented = $client_nonconsented->where('tbl_partner_facility.partner_id', $selected_partners); + $client_consented_male = $client_consented_male->where('tbl_partner_facility.partner_id', $selected_partners); + $client_consented_female = $client_consented_female->where('tbl_partner_facility.partner_id', $selected_partners); + $client_consented_uknown_gender = $client_consented_uknown_gender->where('tbl_partner_facility.partner_id', $selected_partners); + $client_nonconsented_male = $client_nonconsented_male->where('tbl_partner_facility.partner_id', $selected_partners); + $client_nonconsented_female = $client_nonconsented_female->where('tbl_partner_facility.partner_id', $selected_partners); + $client_nonconsented_uknown_gender = $client_nonconsented_uknown_gender->where('tbl_partner_facility.partner_id', $selected_partners); + $client_consented_to_nine = $client_consented_to_nine->where('tbl_partner_facility.partner_id', $selected_partners); + $client_consented_to_fourteen = $client_consented_to_fourteen->where('tbl_partner_facility.partner_id', $selected_partners); + $client_consented_to_nineteen = $client_consented_to_nineteen->where('tbl_partner_facility.partner_id', $selected_partners); + $client_consented_to_twentyfour = $client_consented_to_twentyfour->where('tbl_partner_facility.partner_id', $selected_partners); + $client_consented_to_twentyfive_above = $client_consented_to_twentyfive_above->where('tbl_partner_facility.partner_id', $selected_partners); + $client_consented_uknown_age = $client_consented_uknown_age->where('tbl_partner_facility.partner_id', $selected_partners); + $client_nonconsented_to_nine = $client_nonconsented_to_nine->where('tbl_partner_facility.partner_id', $selected_partners); + $client_nonconsented_to_fourteen = $client_nonconsented_to_fourteen->where('tbl_partner_facility.partner_id', $selected_partners); + $client_nonconsented_to_nineteen = $client_nonconsented_to_nineteen->where('tbl_partner_facility.partner_id', $selected_partners); + $client_nonconsented_to_twentyfour = $client_nonconsented_to_twentyfour->where('tbl_partner_facility.partner_id', $selected_partners); + $client_nonconsented_to_twentyfive_above = $client_nonconsented_to_twentyfive_above->where('tbl_partner_facility.partner_id', $selected_partners); + $client_nonconsented_uknown_age = $client_nonconsented_uknown_age->where('tbl_partner_facility.partner_id', $selected_partners); + } + if (!empty($selected_counties)) { + $client = $client->where('tbl_partner_facility.county_id', $selected_counties); + $client_consented = $client_consented->where('tbl_partner_facility.county_id', $selected_counties); + $client_nonconsented = $client_nonconsented->where('tbl_partner_facility.county_id', $selected_counties); + $client_consented_male = $client_consented_male->where('tbl_partner_facility.county_id', $selected_counties); + $client_consented_female = $client_consented_female->where('tbl_partner_facility.county_id', $selected_counties); + $client_consented_uknown_gender = $client_consented_uknown_gender->where('tbl_partner_facility.county_id', $selected_counties); + $client_nonconsented_male = $client_nonconsented_male->where('tbl_partner_facility.county_id', $selected_counties); + $client_nonconsented_female = $client_nonconsented_female->where('tbl_partner_facility.county_id', $selected_counties); + $client_nonconsented_uknown_gender = $client_nonconsented_uknown_gender->where('tbl_partner_facility.county_id', $selected_counties); + $client_consented_to_nine = $client_consented_to_nine->where('tbl_partner_facility.county_id', $selected_counties); + $client_consented_to_fourteen = $client_consented_to_fourteen->where('tbl_partner_facility.county_id', $selected_counties); + $client_consented_to_nineteen = $client_consented_to_nineteen->where('tbl_partner_facility.county_id', $selected_counties); + $client_consented_to_twentyfour = $client_consented_to_twentyfour->where('tbl_partner_facility.county_id', $selected_counties); + $client_consented_to_twentyfive_above = $client_consented_to_twentyfive_above->where('tbl_partner_facility.county_id', $selected_counties); + $client_consented_uknown_age = $client_consented_uknown_age->where('tbl_partner_facility.county_id', $selected_counties); + $client_nonconsented_to_nine = $client_nonconsented_to_nine->where('tbl_partner_facility.county_id', $selected_counties); + $client_nonconsented_to_fourteen = $client_nonconsented_to_fourteen->where('tbl_partner_facility.county_id', $selected_counties); + $client_nonconsented_to_nineteen = $client_nonconsented_to_nineteen->where('tbl_partner_facility.county_id', $selected_counties); + $client_nonconsented_to_twentyfour = $client_nonconsented_to_twentyfour->where('tbl_partner_facility.county_id', $selected_counties); + $client_nonconsented_to_twentyfive_above = $client_nonconsented_to_twentyfive_above->where('tbl_partner_facility.county_id', $selected_counties); + $client_nonconsented_uknown_age = $client_nonconsented_uknown_age->where('tbl_partner_facility.county_id', $selected_counties); + } + if (!empty($selected_subcounties)) { + $client = $client->where('tbl_partner_facility.sub_county_id', $selected_subcounties); + $client_consented = $client_consented->where('tbl_partner_facility.sub_county_id', $selected_subcounties); + $client_nonconsented = $client_nonconsented->where('tbl_partner_facility.sub_county_id', $selected_subcounties); + $client_consented_male = $client_consented_male->where('tbl_partner_facility.sub_county_id', $selected_subcounties); + $client_consented_female = $client_consented_female->where('tbl_partner_facility.sub_county_id', $selected_subcounties); + $client_consented_uknown_gender = $client_consented_uknown_gender->where('tbl_partner_facility.sub_county_id', $selected_subcounties); + $client_nonconsented_male = $client_nonconsented_male->where('tbl_partner_facility.sub_county_id', $selected_subcounties); + $client_nonconsented_female = $client_nonconsented_female->where('tbl_partner_facility.sub_county_id', $selected_subcounties); + $client_nonconsented_uknown_gender = $client_nonconsented_uknown_gender->where('tbl_partner_facility.sub_county_id', $selected_subcounties); + $client_consented_to_nine = $client_consented_to_nine->where('tbl_partner_facility.sub_county_id', $selected_subcounties); + $client_consented_to_fourteen = $client_consented_to_fourteen->where('tbl_partner_facility.sub_county_id', $selected_subcounties); + $client_consented_to_nineteen = $client_consented_to_nineteen->where('tbl_partner_facility.sub_county_id', $selected_subcounties); + $client_consented_to_twentyfour = $client_consented_to_twentyfour->where('tbl_partner_facility.sub_county_id', $selected_subcounties); + $client_consented_to_twentyfive_above = $client_consented_to_twentyfive_above->where('tbl_partner_facility.sub_county_id', $selected_subcounties); + $client_consented_uknown_age = $client_consented_uknown_age->where('tbl_partner_facility.sub_county_id', $selected_subcounties); + $client_nonconsented_to_nine = $client_nonconsented_to_nine->where('tbl_partner_facility.sub_county_id', $selected_subcounties); + $client_nonconsented_to_fourteen = $client_nonconsented_to_fourteen->where('tbl_partner_facility.sub_county_id', $selected_subcounties); + $client_nonconsented_to_nineteen = $client_nonconsented_to_nineteen->where('tbl_partner_facility.sub_county_id', $selected_subcounties); + $client_nonconsented_to_twentyfour = $client_nonconsented_to_twentyfour->where('tbl_partner_facility.sub_county_id', $selected_subcounties); + $client_nonconsented_to_twentyfive_above = $client_nonconsented_to_twentyfive_above->where('tbl_partner_facility.sub_county_id', $selected_subcounties); + $client_nonconsented_uknown_age = $client_nonconsented_uknown_age->where('tbl_partner_facility.sub_county_id', $selected_subcounties); + } + if (!empty($selected_facilites)) { + $client = $client->where('tbl_partner_facility.mfl_code', $selected_facilites); + $client_consented = $client_consented->where('tbl_partner_facility.mfl_code', $selected_facilites); + $client_nonconsented = $client_nonconsented->where('tbl_partner_facility.mfl_code', $selected_facilites); + $client_consented_male = $client_consented_male->where('tbl_partner_facility.mfl_code', $selected_facilites); + $client_consented_female = $client_consented_female->where('tbl_partner_facility.mfl_code', $selected_facilites); + $client_consented_uknown_gender = $client_consented_uknown_gender->where('tbl_partner_facility.mfl_code', $selected_facilites); + $client_nonconsented_male = $client_nonconsented_male->where('tbl_partner_facility.mfl_code', $selected_facilites); + $client_nonconsented_female = $client_nonconsented_female->where('tbl_partner_facility.mfl_code', $selected_facilites); + $client_nonconsented_uknown_gender = $client_nonconsented_uknown_gender->where('tbl_partner_facility.mfl_code', $selected_facilites); + $client_consented_to_nine = $client_consented_to_nine->where('tbl_partner_facility.mfl_code', $selected_facilites); + $client_consented_to_fourteen = $client_consented_to_fourteen->where('tbl_partner_facility.mfl_code', $selected_facilites); + $client_consented_to_nineteen = $client_consented_to_nineteen->where('tbl_partner_facility.mfl_code', $selected_facilites); + $client_consented_to_twentyfour = $client_consented_to_twentyfour->where('tbl_partner_facility.mfl_code', $selected_facilites); + $client_consented_to_twentyfive_above = $client_consented_to_twentyfive_above->where('tbl_partner_facility.mfl_code', $selected_facilites); + $client_consented_uknown_age = $client_consented_uknown_age->where('tbl_partner_facility.mfl_code', $selected_facilites); + $client_nonconsented_to_nine = $client_nonconsented_to_nine->where('tbl_partner_facility.mfl_code', $selected_facilites); + $client_nonconsented_to_fourteen = $client_nonconsented_to_fourteen->where('tbl_partner_facility.mfl_code', $selected_facilites); + $client_nonconsented_to_nineteen = $client_nonconsented_to_nineteen->where('tbl_partner_facility.mfl_code', $selected_facilites); + $client_nonconsented_to_twentyfour = $client_nonconsented_to_twentyfour->where('tbl_partner_facility.mfl_code', $selected_facilites); + $client_nonconsented_to_twentyfive_above = $client_nonconsented_to_twentyfive_above->where('tbl_partner_facility.mfl_code', $selected_facilites); + $client_nonconsented_uknown_age = $client_nonconsented_uknown_age->where('tbl_partner_facility.mfl_code', $selected_facilites); + } + $data["client"] = $client->count(); + $data["client_consented"] = $client_consented->count(); + $data["client_nonconsented"] = $client_nonconsented->count(); + $data["client_consented_male"] = $client_consented_male->count(); + $data["client_consented_female"] = $client_consented_female->count(); + $data["client_consented_uknown_gender"] = $client_consented_uknown_gender->count(); + $data["client_nonconsented_male"] = $client_nonconsented_male->count(); + $data["client_nonconsented_female"] = $client_nonconsented_female->count(); + $data["client_nonconsented_uknown_gender"] = $client_nonconsented_uknown_gender->count(); + $data["client_consented_to_nine"] = $client_consented_to_nine->count(); + $data["client_consented_to_fourteen"] = $client_consented_to_fourteen->count(); + $data["client_consented_to_nineteen"] = $client_consented_to_nineteen->count(); + $data["client_consented_to_twentyfour"] = $client_consented_to_twentyfour->count(); + $data["client_consented_to_twentyfive_above"] = $client_consented_to_twentyfive_above->count(); + $data["client_consented_uknown_age"] = $client_consented_uknown_age->count(); + $data["client_nonconsented_to_nine"] = $client_nonconsented_to_nine->count(); + $data["client_nonconsented_to_fourteen"] = $client_nonconsented_to_fourteen->count(); + $data["client_nonconsented_to_nineteen"] = $client_nonconsented_to_nineteen->count(); + $data["client_nonconsented_to_twentyfour"] = $client_nonconsented_to_twentyfour->count(); + $data["client_nonconsented_to_twentyfive_above"] = $client_nonconsented_to_twentyfive_above->count(); + $data["client_nonconsented_uknown_age"] = $client_nonconsented_uknown_age->count(); + + return $data; } } diff --git a/public/template/UshauriTemplate.xlsx b/public/template/UshauriTemplate.xlsx new file mode 100644 index 0000000000000000000000000000000000000000..25ef495015cbfac89ecacbcf7fff02900410914c GIT binary patch literal 15313 zcmeHub980Rwr@JNZQDu5wr$(CZL5=X+_7yt9d&H0W7{wNopWEG)8~6{-2d-gdyLv+ z?^^S>s^*%rCTf~Lv?n-`1p}(#Z%K$`p|nFRaW_E7 zmR6CA36oOOyXTxPs1n};%yZDNB-5IrKHIYCEGX9p_zf;8-6Up(b(_dwY36TR-r@3w zgNv(IP?{2;VDT~Fu5G}WV!@%?Hw-8x3B9RHj7b!ukp2kV%UliCK=2I_@c2Tb^vPlJ zn0sVQ9Z-_tGr9q@SFjchRmA#yd%H3ttBMfaiX)6NWzzkZVdNUQmfEKxE$tW043FMxDbp!+KfzMkmD&qo_-VmnnJXT^pWvK(RO z9N+IA?^WvQRilWkDZ8=S)&g`4X_W!ENwRXce**d#>Q49MaYOtdDiZZO(_W0VP{i>B z4d4TX?ejRA#zSZKXhp&WL1bPkwrwoZ=m`H-~tcOU?{e^b{6WqP99j~=NHZG`$z zS6v5VD@QuoU+w>@>HlEe{FkXmB}~Zl(L)cOi?s{xJ|EeLfqyG#lM-tqP{QpdKErE> z&Lif#zY78ikT6`Cy4#=N)m%UOX|9BaZ9pf}*GkS`!(`yOVBuDgtpb;0Kxk@?JcJp8 zt*^SaZl&v%pOkK}@LXIQ8Hw4N^g?97j3bK-b$Q}Y5Kk{ZqHi{ph*503nzY9q(uFHW z!!_4q0S@K~R?73l^;p})EN$yX_tV=TMJ9?b3yE{oWlzuqs$^oNI89(wJP_qNV+LXP zna~g@i*#8__U65j&7M#)d{S)lnrkD%k?;7}pEld9e$N1$lJ4JX zi9|`E{?kW~C=dVuCII*+H!He-D2l7CgQbD3t>rJX_Fqc#>BF{t7{LG8S9`*^ML#`s z(0OoY;8cfw!kgR(hbKjFN8<_@eGOu$w3T5AulsXa(iuy2e#&GXG4nOUn8`Ey%{C5^ z^Ew52EjDoLa{7-3NS%9G)qDJ~2By|~Sd=KS>IzyqmWf468Cjz?KEe_<1--9*fk{f5 z*v!T}Ig%-ZL;Q}IhE#!-aIM1XKOZxrx<2QmnMY*G!@K^(?Dv5lezdjTVAhU~?exK# zyu^SS4u?w2iJ_?tFn`fORR;ud&-$j7xYaiVq%Oo`kF82vB-sM2_`)=1z}RHj8#jkA z4mG62!%@JbNk`&XM+qJ4ee_gA#XQb?=b-X_1oe08>ww`tr@)6a;C-yGa33P^Avyml zGg0!=vLCwDL3D{nxS_rrBTZkC83e#UKtQa=89Jz)x0ffu*!t?Zs$$6PQ2T1tac@PZ zDw?+h_mq<{PLN65J((;+**3a$eEs+nRxPYo;#=kbwhX$SvX(B5=KlT0k5deU#W+D6 z!@5nbq|cZLq?P=VnIrB*gkOAy1b5`W%Mpp>xhE4l+62|o(^J3rvS}%oAmVAe)0^$^ zZOccB-3eBt0SweCV6yg!NHLG6)9*eP`p2#<5ZXMJ=jh=kv~I=K5+Z1>)-ueWLlVw#DSHh z74s#uKbK_Ihjy~*A(nOG?>G$?zTV>)3W%-LA9CP!H(h6*Ye{=G{v2~BE-h3bCTF{h z7Zjp}qC|yw@=0kS+MUIW1Z1KR3t-6?F+JRuwXa}}TBU`Ug5?Y2;Fqi@3*Vo6Ot90+ z{vH9oNKvq@)~7_%-l_nM)_|}*2IcL0U@rwy3yze92h>~Rp{8s@>mK|$Q&Hr$utxxP zf=m^P040klrxg~IZNq>y(extYr^I~iEE&N5aBV)j`wxecXl_0U!nTLA3y2TKjPyjANL73;HnvTWPVCE3&DWPy^QW?(96(xA|PY~A9=07^@J-%I#g6C!V zEs#s?v?zffPqI)+L7ymKGAUT-RUR0acWS6yWJy*KtV}oOxDkMu(BCv7o&t;wLl`y{ ze)mc8Ts*E#;gqW!^hk6w0S~Dcj5H+!?TR(2d9LQM^Wm+mqvZq%%?}JL=P(CTMOiV@ z3lZ1DZwo~U8A^QsJ~0{C7c!PUc893nX90SzUCGkJC0y*|zz!f&v%R!T4}&?Gg3iwE zJX_?(d5?CVz$(JKwW7De+|fLImD#vM$30!LKB*9$z|aPlvFa>ja3be)PF9%GjTtys9K)P{39#By|3LO>;3b3XTNG>^m@AF&y0Crbr2I%eB<4c!I1x$XsZ zinN@Klo`66C1cc9B3}*%up(lIp(&@IB7u>IR>{$?lU)xpZSlNzc&zU*lav8H`6hOj zW%G;4FQ+y%{2k#18$uvv_bst~-+XaFI@2?s{5jFL<2f<2L~Kw&wyfAvbwt!>cW_^^ z?z`^;y5DZlucm|)WzbPp)U1hSb%XJHZcvEYt%=)PpD85YKNhk7bRm)YsgZg=bnVwN zNA!D%b2KwHc5?iuo&4(u`l!RUgLbL*x8;f=rAAW5w+e<|rS7&?WX)Wp>sa@yfL1dVaX_K= z=<9Q27PL~b+h*7X{mv;~%EhiGf`&;F^w@L7xW6l(js_X-TCapxSSGOX)U&OC!MlcNX4My-%QRj5HEc(#$PhGKar!f~ooPTaG7{lK zacU?~HNo=4ujqX~{Yy155G8RuKbOSA-RXxPBe5pSOD(LgbiwNBWE#$?cfC~uIk*+n z-%et@@wjaAx_D|V8R1o!}hWWT8mWjx{g-9NizT@L%*IMH}4b_NrXEx~8lKbT7U71(MQkPU<*L&-; z9m35B~E3Pi#3fkIw7c%HDnZgGQ%``W#V^H#>|@*%AHW{pg%!qvUAaOWf)3 zbp~2neQxZ4WEU5*daFvH%ZiVa56{W@^f=EXcw#P;$lFW1x-skHk#))`6^w$>N`3BQ zN>#d``J_u3tzBFF!;{NH^@uB2z(ehlO(`BE^TDY~;?gJ&-87x%$a5FHxGJcow^`3Q zOBo^E_5M-R=95S6X~xj2eRfyn3EwoA^9Ycheyc0!hSRRVim5Vg97t-e?%yJ_|XqV9G6Lyc)gkkW#5Cxft+99+j-;D|avVag#BBqvQYl^tx?zDNIT<_OVBhnEnDZsG5%VCm<=L9sU_q_)8R zEPpN?hH(wSZ(`;~FGy|Sur8FD4j=dwh7ZNeg%KDC>8PCsA4oZQL59hb$8XWc*8oVP z)S+=nQ8v&s9DQWD9{p^QxsVl^-H1C;p!FxR$zHoK4vox zTa0Yw?y(aYtah<`n0$LAa}!X^d@w`3Oh5KCb3J1}uw*UwmH zAeIRm@Ie*x)ralIFCq=~{Hjnvo9n_6`m$qV-K`pfIZ6%UoVNHR()$8%PNl&i1v1FV ze9bu!)c&*Rr+{#>L5^`J_PQN-7m@ zyAr7r_O?bkxN@I0B%DhDdIFA?3JO;P4zoL_z&GyW)}AjXw`2qR#`pQFd8`2rydh7` zA&ok5OX6S&+D~BNKk?a^NIYK;FM5h*!hIicG`yFppuDG+YoAtw-{4<@a&VaeqEn6@ z{hK@=CLK%*aSdiW(v7ZsH z`~lZPwRB8ox^%pHICVLyZaJ*YjoYh|#C(L~Kvkj5xUe10%81Z%#2%zgzH~hCf=r+# zqH!cQ1+tVGB3NNqm5tqSRs@J-9v-OyBTC-5qAyPz?GgGy>>OF&DqQ^)cnQa0F)X2D zeQYOjH#&Fj5iVVvULx}m{8rljfti#?e1lvgzRv_P%3xSuK7acnA)DB)2DKUdNj+|j zAXGU14d0M@6`HVZw%_5~*#z89Ys*zj82IPo3EF^+aWd zqsB76FI11vMc5{Ya7c%@4W&iqWQdBe{!5tl7c72NvAd_GiVxf!Y&ut`~9*h9%ivB;G1 z&J*i8(_9YTJV>-BFu> z>gZS2)oWtw<_#(A=`Cm1VgwSqC96~wi(j%ekT z(`x8L^s?`2tK(o=fE`8&sIkQGNmE`JK+}nzMNi6(R9wF()tZ9V8Kq$KOlm)MsCIdr z&w0u!v)b}Tmbiwr;8Pzy%weHy^bIGCi`5=H#FFJHjNS(c4MWQ(Z^m>D_I7z6Cw8q0 zfid7&8Rx6Wdgi$ZWQ;?=U1>jG*mdi0jOp_0V5qGBK zpwIH8P7EV^A{9(`HOTYiU!;kB11(I7{bFGyZgz4~UkYzP^OWRi8s_4aYC8CX?BVMT zcSKMS9fyzb`{SM_>*xVKQm#X6IRWdm?^i8Sdd`YN_Q!4FY-aG@oT>3!OMowJ&H9du z=qwK2n0|$dYUU#Y^GoHofzXzI)1skg{El)}8g7EV-l2}HN_bFJ{3UOCV7!>OJrSrn zfeK#DfpDIu>)rEJ{1lxvfwn5GfjQ=f3prs4yG~%*5LmZwCJpRHKMuYjt-}V&*CkWX z$-%?8JC#uUq>g_!pb?S9!287ai6Vjca@Qk#-waZIRWvEXZW||F7}&o_2m*;-t3+Ak z3&)FUHXpBfY%Wj~wD|y3YFH-0zz~w6Omgkc21rHcC->*4+w>IP4)@3Fbk(Z$_7_!_ zCKcmhoLnRQk=M($jrZ4awDogdpXZ^Jcd?@NK`5m6vut1Q`_Za%MK~&2smr@Ey!F?c zzLl!?yOn!gj(S&i4u&lxM8mDMq5X9t)ILC*mrIDQjDBK){scaR1D9glk?(-(xfVfN|o>81IcCzEfYHqa>sAt2EBmLY02Vo*Ns#|V&$aLTkio{8G z`yulM4&wSZQyL=io0n_HFOjN-iY@1WyiADnHSv$|d3$CVcW~+x$X!Y@a#GVkc?B39 z;<2k9XZvA-fo19Fjo0l$g6)R6Hmh~|4)5{%n%8`!7HXn*6Ea$za0v#bcKtH%h>+>D z7a7C}k)BJ~g5ibN1xd9p3{B4AZ()7-hIL$d2^JmhLy>w6#VSb)2>E7Nsm?C;aK_3X zaH_gp{=B45*4$SJ&%_l))W88ls^rRYU`QxfZ^%Up*5P08-P8h%aGZ44Y+ zI@SY>YSR;+e94xWjerqNR3DW0t+XnMTBy*2pq&KC&LBTDvlS()a@&waQkJ7k*}3$q zii*DxgAT;CJzGHnMe7u`%(=sD+NnTxtqnN&(r6q#X`T2i4slvKzcI0QA(V(?+$7aA zIrTCuDougUPALv5AI&}F%kJG~sK*c-5d0?swy3~6ufmt4R*xO+)3MmYL+`&jrlp>XskYx}q>v;O!anf%zd01QsJ#bsp9CHW4W?J(Lr@aNJ+{TdHctI-s zc}pI6k!4SqyN!-O(qmHmNayW4tVaYvW5_g|Z`d+XTMRk^C*ZebP*WgUZBit%tS`!p zqX|&#e1sA(m5DNGFb0GS_vGQ6ofJs?O=j*66tykeB=O!dgpQn5BC3)BlhLnJZ;(J?EFMbk<00{FfYy<5Qu zoWqJdl;E|rZV63A)!4YEwaXQ9!Vo~~D#{muHpCw;>;WNW<(>)5*4?P?q;(aaWY;4S zW8T{lT>^b*PEsf`{bt_K0dhWrEviGBxi?wavmS{bF2GZILX^G>=+gB89>LL`YgrR;-q#cjyGv_FS&qzAjXWLOIhjJoSCrZ0u27_xW3+Y(b0uCT*smhrm2X2m?#9vZ$8CL*Fi)GwO4vPe>Cn$3b}g#nhS9 zYi{hGosTC1>*rz&6^ks7@eIBW)EiLkf@&a+pE1o?Oe+fKx)r+GT=9XlT!x$AxF2y3 z+d?Q8p0pKmHgKM4^ePJ`z19~it%L7y2gQ@^UbDH+IY}`A=6a0yz!&q)gMXB9*K0SC z!C}z{@rEHa1A{g619{?jrpF;@K2ERmq^h!NdD<$jxU+|BHp*L<$pLFYdA~E%0zrX( z@=^`g9(C*i_mUt3>z@t6OgrCw9$yL-o$i{Fk6#WDDlp{)CxdOIl$`$z-Z6uR05z1V z_KCCxaHHmnNkjCJ22!X)o*~r{_=dfx(rIz&^wDM($(m(6%0o;AAA&@)D1D;X<^$o` zvUpqaO>7RwEHv(QF`u1!BWD!%DJ+`(y^6AV@hNO?o?V_FIWC_U!o6~tSjqd>OF;?j zPg+7M^`*;|tl{sq?%j++*J5C~{-q^p0T)2Bis&aRsFq6kMxaq+lP9j;=h6WMU>2BK zQtfdB9sa)XThmvQ6#Q&0%U~@ANcZBba?SwPmkqk-^E&zo>IjB$#^f|vjAIJ$6X<*N z%Us481!VzwlWv2AqkO%STtDT4 zdg&a=1=Lm9k-t^Sel*pV68?u@!66{NtnJDLP21GPAb)FY!HBT)lroav(C4ZeZ8guOk&5~mOzIM4eIt^k7pdq2# z5^}w*W5pTy2(?~@p56>OU8)Ins){K27QV$c6Xwrc!w5nx8Z9$^StM))f4vBb8H0#V zNka56{E2l|zQnsPd=yQ_eUI>AQ;5zd4np+ZWst=LSTK4671|P?2)z*4 z%U-1=*lUDl_X8KAa7ra;+*xt5bG)H7@4z&`-xOGe{$aRrs=QEEaCqm8EVlLXlm`au z%wgHt{x&@AVFcQ7ia|J0T2jr3jBOQ=0p*`FNCg(3_?SWJ#|#WcK=IFRBn#oawmzQZ zIU>9;i(qYOkw$q^fz_zZpV>(7v_cNa6M!Skn~2Pn)9+cmiODYaS<9Q+1c5?tImcYesw!&(A-P8d4I4=w=(PAJqZp#Eps zM}R|{FPOMQ2wz3SG!%&f$Cx@$se8e~RO_xjO*h2C$O#pO{dyi_EL%w?NaV$*#zX*4 z4w;>K&p?V^D;0YY(66H4#~F8o;OE$QI+I69_AyK4*X+6A#}WK)s%}fv$48&0gd4w> zOUF|8V%X%5+StRw1x2&sy+Gp71ztm6rSd0J_j1bK%4Q}i`pJqQY&auiOL|d(e6iXg zFXr~x<vU(53mIhAP)4qKC{Oz#1N#9o-j4iSm zdux)?iJEPk&22v}D^YA~2t)@ZyW^W{j7+E95O+Jw+nN*3!=S0Sz1723pl!mY*(j?Z zTHcST@VU(2kVYkO9+(T7+Q5KD>1-O=lLVG+vQd@#VQAZkFIqTZc44tx2zY7 zR#mL4cY9|qPq^2^5*TclwY=78`IQQ*oR+E7%Hs|gt?L)=@H{QM_#udCvTV=%+rZq# ztM~pkegiw6z-|tf!BQ!m9RT-duGyZ5ZfK2?vOC~mr@rqY{7|=^H0^+7 zy4-Zve*toev9>w6@Q9}+1$Ww}1u4|{+|WV`cZgA=%-(e^GPd-r6+ZaPzL@Gfcq>*L&O$y-~C1+8d{ zXPHgwdw%A3WPXHmY<@x#E!*X5*$CDa*>8xKGE?gr4sUpaZ9s&raE!G(bsaT{ExRrk zwTw6hmaFZeB(q>szJC_yy}>()-8}zdEIhXbl%)&~t{aCxM9kF0%lCw@fcH%yY5LLQ zg|`-63Aux@xEty0lsZHV&u5J~1jWn6i8Bym+EkY#Fj>c+3-b0R>}IGceTcQZ$QFg| zzLgu3D!;1J29+sepggEJEAH*ac_vj=PrS6-bj!{vzVo%!omw1s6w(LHT~megAtkfc zJq{#Y*I(basz*nhcQ{5}@~x!w{qO5Gbni<0d_EExFCTjr$p1)JIGX7@7#k@%Ihfm+ z{J{PN zi2o&TeW%Gb&G${z?&ga{Uy>KLG_SNs*ocC%)O>87VGSg%$aghDs@^a8v3XFR^Clwk zd{eOu5xz@Yvssi|`(njPFUj$bk(b$5ecikWK;A`pm+u3t=CwFXF;WVb1<_kHv zQ~O$;ZRg!i?H-|rf(Wo`0VMN)ErW`@U5XK{HTJQCIGYNL3c2$9(r`H+S)Q6IiImy& zQZ$tkRyOW>nHl$#v9e8|VC#4Oq ziqoWXyeVOCAz@~8?=4}r$6eKMv>dw--eszR4kCW*C)T_{x-wap_AI9rw2u6;&kDJr z`nBl5Vlg<+IYN~-YzG+)3oTeC5QoAt3APN9m0bX&q9kV{jA}Iz!oTFAu)y>xq^H2n z_-?`{V+G#x3pCbvl(A4QOfbk2zEu<@MvYy197i6`7c|*N2A$SBNVCk?fE8i;Mi>>g zCgwpapbR z^M0eQj0j3qXrPVQp}y)kX?W>b53AZ+>y80ebFkCavfd(~d5Kx`Qs*y~^K%(<$`zzL zSD!1L7iz|I(Qg*w%y1_OKFUE31))sU^I?6pB$~*QPs5qVh|yl70=$p=#v=&tmy)wb zz|%_T-S=((tcpjC`8r0lc}++X88?CW3hP=zL_A(t{9ydYm$ly8n_Bcb4gc&d(z_52 zQ{dHej2lG-CVu!A>~HNeH>L}>hA~aDW+lw0-gr@Lmv5wcdwzZ7bawVP%N((e$Rutp z?;G}*eH$y=oPQstGy^MZerzKpo5k;{R>j*pH;W?+pp1dEozsL}NZ z`{!ft74m7G!wf85(lC#a@P8Aqudwd(Vq1n`iSn(6*^G+Au<2&%;p*e2XAvb_CIaCl z951Q>^V>wXFynI%ogp6J)qrcX_ho_pf@DnOZ7NXMv8LF#X?R(@&hC!fXq{f4*dub0 zz1=j|cMbnJxpV^sOzCHUqK&`1wPa_*wEM79zVgtl$Od&iRAl&BLnwAO`E$km*rT$W zUjwlH$`{#Xkn!_pdcE&VGM^AYLY>AOi`!*TUFQ(LU<`{%723OK$5U~9ol0uIH=KC# z9NH1C!+YapI1V?`D4@th8zSId5!j{oCqk5 zrF4@4j|GjYFQByTplHN0?Vq+0p1`r)0CjSs1OaWJxRr`6;uo%dcrkHuGHs0T@&FT> zNlghsC4wLZrK9)exkJSsE)$Onf&p3W929@HJH^6unAddOIB2d1GA1uU>Al(mfQ; z>Z)L)u|d%tj-23o#D+WQ4%B}rFMeX_oSnGJxKU19X_PaI7DV%5wF3o;`a;h|RgW*L zXkDI{S99S`souX8GdWUmX7(Au6GVd+QY}H^4C9;C(n#KFM)jE)Mz)%H!cz|$#Or5r+jWk7rd7WV`FZZ>DQ{g+#(zk15u-@Db=sW3Rmd3 zk}VMZSTX#p&}}>+T&UC;MP5AsfE3euBkZ>;$FCw?Y%nnCyaDMeBtwxgE%pyVd((u~ z)L#S;LXl7RDAOwaEP)#a%O@eTjzfLQ@Op>C*S(`w<dq5c_!+|&=^+I z)9op%FW9w=dw)zt*H4GXv~YfXx#61lO3lTe+d$)hmNmKCeo$Q`-AmnDy?^jEA#I?d zoW`nG!KprJ4ADI4COgVGXW{61pw05YjhODeIk+vQEBrktFzyW%@u|?%%s|LNWV*;V z6d3v_UB0MCloTlpp=1X+Et0%!?rOfX~6?e)UsB`ThV0d=S#=_7qIX;I(^9u|avPeRRi z(?}2e4(1Y2ovix;;5!yb9sxZj;2%vN1+We{6TMpqs9PA2<`s(L`ufd%vP+WQa~v)6 zRzR4_Kq#1KCY@*#2Shnc>(`=r&K&`Arj_J7kfi`kOeW-5U-{19*IMgaPG5WDKNEyU(#-<9G0t*kKazQk-)*d_#y1(tpcmSn(CBVm=JhsHJYKB{ z-k;hIXFwY*xM|smu2Hye*TXesWj(ha7>Gz2J&)9~>Ne>>*d}Vfb|@G*EW}8!6u5S_ zVVLC}uc;Qi`+iLxAWl~(NLSx}8nOtKc=+6It5Pfl{q%fuTZPp`>ly-)RLWIzwVRkl zfc~&M$YqR%RK_i;J3FyBtm>tbZ*J&Oypp>k&=uYPv$6HDvy`1x_hK7ng9zsG#dc%9 z>_GbI&ibwP8pb&LnD$)VTln+K<2B;MX;sx#YkL)Y$L9Xc4&26@#FFM}5i8wSZkyhz z=b~wnH8Pwvu0zr;i>CJb)9LTNnhRdGl@V1IOFVQ8w4?pUGwLNHOywo*ZR>AhitPi+ z{jER0nW#?PY4eXV;u=eZLDq5mu#l0>QLj(mJ`Gjhm_IB0(DisbzHo6r+gw;*YM5vI z+;!x`z4T@)lB~1V{<%T-UaHAy;=Oum7zA1(W{C0hPI}{WM#4q0u85!>Gw^?-@%vDu zze}uQ44T9TeRwQrzm)A?Jr;dCyZ?1qe(~%dS4INA><&GA@Hy45O6QW90F|;428|v< zVpRDOkRLjx(`wBwyBN92x)a3mE6A{7p6OrjZ?25Fjx5?P)uAA?p@UOp9OC(_Yn=48 z!;0okAL-%=zRF?Z0U;ZJkyqXMYrNWEo|hB6Nxp7c zMW9oSyjjt>kqqS;w2~|~?V1%ik_=U7XzXmI1v(pZ1tbjlw*t-3SnF#ERA{6%=}{Cy zuW^3tg4Ozhe(R$UvP@v|M=z^`k=A_%r8rDU)u{o+S4x2CtEL-Tw?C!5EoZf}w>SX= zg-4Y^P>tc*G;E*`?<6|I0A2rNx^yW$`-u4esI~u-_|IDL-^4zUe-Zz#9RHK_&yv^Qq*otR=l^`}|E~b{ zPryG5NPh#~!v22%f0vW~3HWC{=5N6J50ByBNBFxs^G}pN%RPRhtfT#f@@MhKp8$XE zJN*Vo#{1i0{57LLQT|Nh{6>i;{|n_mk~)7Pko;R<`I{a9fSVcs;6K95Kgs`$0)7Kb z(Ec@mKVpEtjS2n){nJPL4I0Am-vRy0WBU{I-|f+FNC1Fy=6{*!KdqCTB*=%p{W_Tf P2Y?6+08sKP2m<&&j-?x_ literal 0 HcmV?d00001 diff --git a/resources/views/clients/upload-clients-form.blade.php b/resources/views/clients/upload-clients-form.blade.php index 7b4ce61..5b2be07 100644 --- a/resources/views/clients/upload-clients-form.blade.php +++ b/resources/views/clients/upload-clients-form.blade.php @@ -7,13 +7,18 @@
- -
-

- Bulk Upload Clients to Ushauri From KEMR -

+
+
-
+
+
+
+ Bulk Upload Clients to Ushauri From KenyaEMR +
@csrf
@@ -25,7 +30,7 @@
- +
@@ -35,13 +40,12 @@
-
-

- Bulk Upload Clients to Ushauri From Template -

-
-
+
+
+ Bulk Upload Clients to Ushauri From Template +
+
@csrf
@@ -53,25 +57,37 @@
- +
- -
+
+ @endsection @section('page-js') - + + + + diff --git a/resources/views/new_dashboard/appointment_dashboard.blade.php b/resources/views/new_dashboard/appointment_dashboard.blade.php index b28af7f..80295d5 100644 --- a/resources/views/new_dashboard/appointment_dashboard.blade.php +++ b/resources/views/new_dashboard/appointment_dashboard.blade.php @@ -118,8 +118,7 @@
@@ -145,7 +144,7 @@

Honored

-

{{$appointment_honoured}}

+

{{number_format($appointment_honoured)}}

@@ -157,7 +156,7 @@

Not Honored

-

{{$appointment_not_honoured}}

+

{{number_format($appointment_not_honoured)}}

@@ -197,100 +196,12 @@
-
@@ -334,34 +245,6 @@ var Appointment_not_honored_to_uknown_age = ; - var Appointment_missed_male = ; - var Appointment_missed_female = ; - var Appointment_missed_uknown_gender = ; - var Appointment_missed_to_nine = ; - var Appointment_missed_to_fourteen = ; - var Appointment_missed_to_nineteen = ; - var Appointment_missed_to_twentyfour = ; - var Appointment_missed_to_twentyfive_above = ; - var Appointment_missed_to_uknown_age = ; - var Appointment_defaulted_female = ; - var Appointment_defaulted_male = ; - var Appointment_defaulted_uknown_gender = ; - var Appointment_defaulted_to_nine = ; - var Appointment_defaulted_to_fourteen = ; - var Appointment_defaulted_to_nineteen = ; - var Appointment_defaulted_to_twentyfour = ; - var Appointment_defaulted_to_twentyfive_above = ; - var Appointment_defaulted_to_uknown_age = ; - var Appointment_ltfu_female = ; - var Appointment_ltfu_male = ; - var Appointment_ltfu_uknown_gender = ; - var Appointment_ltfu_to_nine = ; - var Appointment_ltfu_to_fourteen = ; - var Appointment_ltfu_to_nineteen = ; - var Appointment_ltfu_to_twentyfour = ; - var Appointment_ltfu_to_twentyfive_above = ; - var Appointment_ltfu_to_uknown_age = ; - $(document).ready(function() { $('select[name="partner"]').on('change', function() { @@ -649,271 +532,6 @@ }); - //MISSED APPOINTMENT BY GENDER - var appChart = Highcharts.chart('appointment_missed_gender', { - chart: { - type: 'column' - }, - title: { - text: 'Appointment Missed By Gender' - }, - xAxis: { - categories: ['Male', 'Female', 'UKNOWN Gender'] - }, - yAxis: { - min: 0, - title: { - text: 'No of Appointment Missed' - }, - stackLabels: { - enabled: true, - style: { - fontWeight: 'bold', - color: ( // theme - Highcharts.defaultOptions.title.style && - Highcharts.defaultOptions.title.style.color - ) || 'gray' - } - } - }, - tooltip: { - formatter: function() { - return '' + this.x + '
' + - this.series.name + ': ' + this.y; - } - }, - plotOptions: { - column: { - stacking: 'normal', - } - }, - series: [{ - name: 'Gender', - data: [Appointment_missed_male, Appointment_missed_female, Appointment_missed_uknown_gender] - }], - - }); -// APPOINTMENT MISSED AGE - var appChart = Highcharts.chart('appointment_missed_age', { - chart: { - type: 'column' - }, - title: { - text: 'Appointment Missed By Age' - }, - xAxis: { - categories: ['0-9 YRS', '10-14 YRS', '15-19 YRS', '20-24 YRS', '25+ YRS', 'UKNOWN AGE'] - }, - yAxis: { - min: 0, - title: { - text: 'No of Appointment Missed' - }, - stackLabels: { - enabled: true, - style: { - fontWeight: 'bold', - color: ( // theme - Highcharts.defaultOptions.title.style && - Highcharts.defaultOptions.title.style.color - ) || 'gray' - } - } - }, - tooltip: { - formatter: function() { - return '' + this.x + '
' + - this.series.name + ': ' + this.y; - } - }, - plotOptions: { - column: { - stacking: 'normal', - } - }, - series: [{ - name: 'Age', - data: [Appointment_missed_to_nine, Appointment_missed_to_fourteen, Appointment_missed_to_nineteen, Appointment_missed_to_twentyfour, Appointment_missed_to_twentyfive_above, Appointment_missed_to_uknown_age] - }], - - }); - //DEFAULTED APPOINTMENT BY GENDER - var appChart = Highcharts.chart('appointment_defaulted_gender', { - chart: { - type: 'column' - }, - title: { - text: 'Appointment Defaulted By Gender' - }, - xAxis: { - categories: ['Male', 'Female', 'UKNOWN Gender'] - }, - yAxis: { - min: 0, - title: { - text: 'No of Appointment Defaulted' - }, - stackLabels: { - enabled: true, - style: { - fontWeight: 'bold', - color: ( // theme - Highcharts.defaultOptions.title.style && - Highcharts.defaultOptions.title.style.color - ) || 'gray' - } - } - }, - tooltip: { - formatter: function() { - return '' + this.x + '
' + - this.series.name + ': ' + this.y; - } - }, - plotOptions: { - column: { - stacking: 'normal', - } - }, - series: [{ - name: 'Gender', - data: [Appointment_defaulted_male, Appointment_defaulted_female, Appointment_defaulted_uknown_gender] - }], - - }); -// APPOINTMENT DEFAULTED AGE - var appChart = Highcharts.chart('appointment_defaulted_age', { - chart: { - type: 'column' - }, - title: { - text: 'Appointment Defaulted By Age' - }, - xAxis: { - categories: ['0-9 YRS', '10-14 YRS', '15-19 YRS', '20-24 YRS', '25+ YRS', 'UKNOWN AGE'] - }, - yAxis: { - min: 0, - title: { - text: 'No of Appointment Defaulted' - }, - stackLabels: { - enabled: true, - style: { - fontWeight: 'bold', - color: ( // theme - Highcharts.defaultOptions.title.style && - Highcharts.defaultOptions.title.style.color - ) || 'gray' - } - } - }, - tooltip: { - formatter: function() { - return '' + this.x + '
' + - this.series.name + ': ' + this.y; - } - }, - plotOptions: { - column: { - stacking: 'normal', - } - }, - series: [{ - name: 'Age', - data: [Appointment_defaulted_to_nine, Appointment_defaulted_to_fourteen, Appointment_defaulted_to_nineteen, Appointment_defaulted_to_twentyfour, Appointment_defaulted_to_twentyfive_above, Appointment_defaulted_to_uknown_age] - }], - - }); - - //LTFU APPOINTMENT BY GENDER - var appChart = Highcharts.chart('appointment_ltfu_gender', { - chart: { - type: 'column' - }, - title: { - text: 'Appointment LTFU By Gender' - }, - xAxis: { - categories: ['Male', 'Female', 'UKNOWN Gender'] - }, - yAxis: { - min: 0, - title: { - text: 'No of Appointment LTFU' - }, - stackLabels: { - enabled: true, - style: { - fontWeight: 'bold', - color: ( // theme - Highcharts.defaultOptions.title.style && - Highcharts.defaultOptions.title.style.color - ) || 'gray' - } - } - }, - tooltip: { - formatter: function() { - return '' + this.x + '
' + - this.series.name + ': ' + this.y; - } - }, - plotOptions: { - column: { - stacking: 'normal', - } - }, - series: [{ - name: 'Gender', - data: [Appointment_ltfu_male, Appointment_ltfu_female, Appointment_ltfu_uknown_gender] - }], - - }); -// APPOINTMENT LTFU AGE - var appChart = Highcharts.chart('appointment_lftu_age', { - chart: { - type: 'column' - }, - title: { - text: 'Appointment LTFU By Age' - }, - xAxis: { - categories: ['0-9 YRS', '10-14 YRS', '15-19 YRS', '20-24 YRS', '25+ YRS', 'UKNOWN AGE'] - }, - yAxis: { - min: 0, - title: { - text: 'No of Appointment LTFU' - }, - stackLabels: { - enabled: true, - style: { - fontWeight: 'bold', - color: ( // theme - Highcharts.defaultOptions.title.style && - Highcharts.defaultOptions.title.style.color - ) || 'gray' - } - } - }, - tooltip: { - formatter: function() { - return '' + this.x + '
' + - this.series.name + ': ' + this.y; - } - }, - plotOptions: { - column: { - stacking: 'normal', - } - }, - series: [{ - name: 'Age', - data: [Appointment_ltfu_to_nine, Appointment_ltfu_to_fourteen, Appointment_ltfu_to_nineteen, Appointment_ltfu_to_twentyfour, Appointment_ltfu_to_twentyfive_above, Appointment_ltfu_to_uknown_age] - }], - - }); var colors = Highcharts.getOptions().colors; diff --git a/resources/views/new_dashboard/client_dashboard.blade.php b/resources/views/new_dashboard/client_dashboard.blade.php new file mode 100644 index 0000000..4b309d1 --- /dev/null +++ b/resources/views/new_dashboard/client_dashboard.blade.php @@ -0,0 +1,640 @@ +@extends('layouts.master') +@section('page-css') + +@endsection + +@section('main-content') + +@if (Auth::user()->access_level == 'Admin' || Auth::user()->access_level == 'Partner' || Auth::user()->access_level == 'Donor') +
+
+ {{ csrf_field() }} +
+
+
+ + +
+
+
+
+ +
+
+
+
+ + +
+
+
+
+ + + +
+
+
+
+ + + +
+
+ +
+
+
+ +
+ + +
+
+ +
+
+
+
+
+
+
+
+ +
+ + +
+
+ +
+
+
+
+
+
+ + +
+
+
+ + + +
+@endif +@if (Auth::user()->access_level == 'Facility') +
+
+ {{ csrf_field() }} +
+ +
+
+ + + +
+
+ +
+
+
+ +
+ + +
+
+ +
+
+
+
+
+
+
+
+ +
+ + +
+
+ +
+
+
+
+
+
+ + +
+
+
+ + + +
+@endif + + + + + + + + + + + + + + + + + + + + + + + + +@endsection \ No newline at end of file diff --git a/resources/views/new_dashboard/main_dashbaord.blade.php b/resources/views/new_dashboard/main_dashbaord.blade.php index 785414a..d5adbeb 100644 --- a/resources/views/new_dashboard/main_dashbaord.blade.php +++ b/resources/views/new_dashboard/main_dashbaord.blade.php @@ -15,7 +15,7 @@
-
+ {{ csrf_field() }}
@@ -69,6 +69,72 @@
+
+
+
+ +
+ + +
+
+ +
+
+
+
+
+
+
+ +
+ + +
+
+ +
+
+
+
+
+
+ + +
+
+
+ + + +
+@endif +@if (Auth::user()->access_level == 'Facility') + + +
+ +
+ {{ csrf_field() }} +
+ +
+
+ + + +
+
+
@@ -118,8 +184,7 @@ -
-
- -
-

-
-
-
- -
-

-
-
-
-
-
- -
-

-
-
-
- -
-

-
-
-
- @@ -370,46 +327,6 @@ var Client_to_twentyfive_above = ; var Client_unknown_age = ; - var Appointment_male = ; - var Appointment_female = ; - var Appointment_uknown_gender = ; - var Appointment_to_nine = ; - var Appointment_to_fourteen = ; - var Appointment_to_nineteen = ; - var Appointment_to_twentyfour = ; - var Appointment_to_twentyfive_above = ; - var Appointment_uknown_age = ; - - var Appointment_total_missed_female = ; - var Appointment_total_missed_male = ; - var Appointment_total_missed_uknown_gender = ; - var Appointment_total_missed_to_nine = ; - var Appointment_total_missed_to_fourteen = ; - var Appointment_total_missed_to_nineteen = ; - var Appointment_total_missed_to_twentyfour = ; - var Appointment_total_missed_to_twentyfive_above = ; - var Appointment_total_missed_uknown_age = ; - - var Client_consented_male = ; - var Client_consented_female = ; - var Client_consented_uknown_gender = ; - var Client_nonconsented_male = ; - var Client_nonconsented_female = ; - var Client_nonconsented_uknown_gender = ; - var Client_consented_to_nine = ; - var Client_consented_to_fourteen = ; - var Client_consented_to_nineteen = ; - var Client_consented_to_twentyfour = ; - var Client_consented_to_twentyfive_above = ; - var Client_consented_uknown_age = ; - var Client_nonconsented_to_nine = ; - var Client_nonconsented_to_fourteen = ; - var Client_nonconsented_to_nineteen = ; - var Client_nonconsented_to_twentyfour = ; - var Client_nonconsented_to_twentyfive_above = ; - var Client_nonconsented_uknown_age = ; - - $(document).ready(function() { $('select[name="partner"]').on('change', function() { @@ -496,6 +413,8 @@ let counties = $('#counties').val(); let subcounties = $('#subcounties').val(); let facilities = $('#facilities').val(); + let from = $('#from').val(); + let to = $('#to').val(); $.ajaxSetup({ headers: { 'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content') @@ -508,13 +427,15 @@ "partners": partners, "counties": counties, "subcounties": subcounties, - "facilities": facilities + "facilities": facilities, + "from": from, + "to": to }, - url: "{{ route('filter_appointment_dashboard') }}", + url: "{{ route('filter_dashboard_charts') }}", success: function(data) { $("#client").html(data.client); - $("#appointment").html(data.appointment); - $("#missed_appointment").html(data.missed_appointment); + $("#client_ever_enrolled").html(data.client_ever_enrolled); + $("#facilities_ever_enrolled").html(data.facilities_ever_enrolled); Clients_male = parseInt(data.clients_male) Clients_female = parseInt(data.clients_female) Unknown_gender = parseInt(data.unknown_gender) @@ -524,57 +445,11 @@ Client_to_twentyfour = parseInt(data.client_to_twentyfour) Client_to_twentyfive_above = parseInt(data.client_to_twentyfive_above) Client_unknown_age = parseInt(data.client_unknown_age) - Appointment_male = parseInt(data.appointment_male) - Appointment_female = parseInt(data.appointment_female) - Appointment_uknown_gender = parseInt(data.appointment_uknown_gender) - Appointment_to_nine = parseInt(data.appointment_to_nine) - Appointment_to_fourteen = parseInt(data.appointment_to_fourteen) - Appointment_to_nineteen = parseInt(data.appointment_to_nineteen) - Appointment_to_twentyfour = parseInt(data.appointment_to_twentyfour) - Appointment_to_twentyfive_above = parseInt(data.appointment_to_twentyfive_above) - Appointment_uknown_age = parseInt(data.appointment_uknown_age) - Appointment_total_missed_female = parseInt(data.appointment_total_missed_female) - Appointment_total_missed_male = parseInt(data.appointment_total_missed_male) - Appointment_total_missed_uknown_gender = parseInt(data.appointment_total_missed_uknown_gender) - Appointment_total_missed_to_nine = parseInt(data.appointment_total_missed_to_nine) - Appointment_total_missed_to_fourteen = parseInt(data.appointment_total_missed_to_fourteen) - Appointment_total_missed_to_nineteen = parseInt(data.appointment_total_missed_to_nineteen) - Appointment_total_missed_to_twentyfour = parseInt(data.appointment_total_missed_to_twentyfour) - Appointment_total_missed_to_twentyfive_above = parseInt(data.appointment_total_missed_to_twentyfive_above) - Appointment_total_missed_uknown_age = parseInt(data.appointment_total_missed_uknown_age) - - - $("#client_consented").html(data.client_consented); - $("#client_nonconsented").html(data.client_nonconsented); - Client_consented_male = parseInt(data.client_consented_male) - Client_consented_female = parseInt(data.client_consented_female) - Client_consented_uknown_gender = parseInt(data.client_consented_uknown_gender) - Client_nonconsented_male = parseInt(data.client_nonconsented_male) - Client_nonconsented_female = parseInt(data.client_nonconsented_female) - Client_nonconsented_uknown_gender = parseInt(data.client_nonconsented_uknown_gender) - Client_consented_to_nine = parseInt(data.client_consented_to_nine) - Client_consented_to_fourteen = parseInt(data.client_consented_to_fourteen) - Client_consented_to_nineteen = parseInt(data.client_consented_to_nineteen) - Client_consented_to_twentyfour = parseInt(data.client_consented_to_twentyfour) - Client_consented_to_twentyfive_above = parseInt(data.client_consented_to_twentyfive_above) - Client_consented_uknown_age = parseInt(data.client_consented_uknown_age) - Client_nonconsented_to_nine = parseInt(data.client_nonconsented_to_nine) - Client_nonconsented_to_fourteen = parseInt(data.client_nonconsented_to_fourteen) - Client_nonconsented_to_nineteen = parseInt(data.client_nonconsented_to_nineteen) - Client_nonconsented_to_twentyfour = parseInt(data.client_nonconsented_to_twentyfour) - Client_nonconsented_to_twentyfive_above = parseInt(data.client_nonconsented_to_twentyfive_above) - Client_nonconsented_uknown_age = parseInt(data.client_nonconsented_uknown_age) + clientGender.series[0].setData([Clients_male, Clients_female, Unknown_gender]); clientAge.series[0].setData([Client_to_nine, Client_to_fourteen, Client_to_nineteen, Client_to_twentyfour, Client_to_twentyfive_above, Client_unknown_age]); - appointmentGender.series[0].setData([Appointment_male, Appointment_female, Appointment_uknown_gender]); - appointmentAge.series[0].setData([Appointment_to_nine, Appointment_to_fourteen, Appointment_to_nineteen, Appointment_to_twentyfour, Appointment_to_twentyfive_above, Appointment_uknown_age]); - totalmissedappointmentGender.series[0].setData([Appointment_total_missed_male, Appointment_total_missed_female, Appointment_total_missed_uknown_gender]); - totalmissedappointmentAge.series[0].setData([Appointment_total_missed_to_nine, Appointment_total_missed_to_fourteen, Appointment_total_missed_to_nineteen, Appointment_total_missed_to_twentyfour, Appointment_total_missed_to_twentyfive_above, Appointment_total_missed_uknown_age]); - consentedGender.series[0].setData([Client_consented_male, Client_consented_female, Client_consented_uknown_gender]); - consentedAge.series[0].setData([Client_consented_to_nine, Client_consented_to_fourteen, Client_consented_to_nineteen, Client_consented_to_twentyfour, Client_consented_to_twentyfive_above, Client_consented_uknown_age]); - nonconsentedGender.series[0].setData([Client_nonconsented_male, Client_nonconsented_female, Client_nonconsented_uknown_gender]); - nonconsentedAge.series[0].setData([Client_nonconsented_to_nine, Client_nonconsented_to_fourteen, Client_nonconsented_to_nineteen, Client_nonconsented_to_twentyfour, Client_nonconsented_to_twentyfive_above, Client_nonconsented_uknown_age]); + } }); @@ -587,7 +462,7 @@ type: 'column' }, title: { - text: 'Client Registration By Gender' + text: 'Active Client By Gender' }, xAxis: { categories: ['Male', 'Female', 'Uknown Gender'] @@ -631,7 +506,7 @@ type: 'column' }, title: { - text: 'Client Registration By Age' + text: 'Active Client By Age' }, xAxis: { categories: ['0-9 YRS', '10-14 YRS', '15-19 YRS', '20-24 YRS', '25+ YRS', 'UKNOWN AGE'] @@ -670,360 +545,183 @@ }); - var appointmentGender = Highcharts.chart('appointment_gender', { - chart: { - type: 'column' - }, - title: { - text: 'Appointment By Gender' - }, - xAxis: { - categories: ['Male', 'Female', 'UKNOWN Gender'] - }, - yAxis: { - min: 0, - title: { - text: 'Number of Appointments' - }, - stackLabels: { - enabled: true, - style: { - fontWeight: 'bold', - color: ( // theme - Highcharts.defaultOptions.title.style && - Highcharts.defaultOptions.title.style.color - ) || 'gray' - } - } - }, - tooltip: { - formatter: function() { - return '' + this.x + '
' + - this.series.name + ': ' + this.y; - } - }, - plotOptions: { - column: { - stacking: 'normal', - } - }, - series: [{ - name: 'Gender', - data: [Appointment_male, Appointment_female, Appointment_uknown_gender] - }], - - }); - - var appointmentAge = Highcharts.chart('appointment_age', { - chart: { - type: 'column' - }, - title: { - text: 'Appointment By Age' - }, - xAxis: { - categories: ['0-9 YRS', '10-14 YRS', '15-19 YRS', '20-24 YRS', '25+ YRS', 'UKNOWN AGE'] - }, - yAxis: { - min: 0, - title: { - text: 'Number of Appointments' - }, - stackLabels: { - enabled: true, - style: { - fontWeight: 'bold', - color: ( // theme - Highcharts.defaultOptions.title.style && - Highcharts.defaultOptions.title.style.color - ) || 'gray' - } - } - }, - tooltip: { - formatter: function() { - return '' + this.x + '
' + - this.series.name + ': ' + this.y; - } - }, - plotOptions: { - column: { - stacking: 'normal', - } - }, - series: [{ - name: 'Age', - data: [Appointment_to_nine, Appointment_to_fourteen, Appointment_to_nineteen, Appointment_to_twentyfour, Appointment_to_twentyfive_above, Appointment_uknown_age] - }], - - }); - - // missed appointment charts - var totalmissedappointmentGender = Highcharts.chart('total_missed_appointment_gender', { - chart: { - type: 'column' - }, - title: { - text: 'Total Missed Appointment By Gender' - }, - xAxis: { - categories: ['Male', 'Female', 'UKNOWN Gender'] - }, - yAxis: { - min: 0, - title: { - text: 'No of Missed Appointments' - }, - stackLabels: { - enabled: true, - style: { - fontWeight: 'bold', - color: ( // theme - Highcharts.defaultOptions.title.style && - Highcharts.defaultOptions.title.style.color - ) || 'gray' - } - } - }, - tooltip: { - formatter: function() { - return '' + this.x + '
' + - this.series.name + ': ' + this.y; - } - }, - plotOptions: { - column: { - stacking: 'normal', - } - }, - series: [{ - name: 'Gender', - data: [Appointment_total_missed_male, Appointment_total_missed_female, Appointment_total_missed_uknown_gender] - }], - - }); + // var appointmentGender = Highcharts.chart('appointment_gender', { + // chart: { + // type: 'column' + // }, + // title: { + // text: 'Appointment By Gender' + // }, + // xAxis: { + // categories: ['Male', 'Female', 'UKNOWN Gender'] + // }, + // yAxis: { + // min: 0, + // title: { + // text: 'Number of Appointments' + // }, + // stackLabels: { + // enabled: true, + // style: { + // fontWeight: 'bold', + // color: ( // theme + // Highcharts.defaultOptions.title.style && + // Highcharts.defaultOptions.title.style.color + // ) || 'gray' + // } + // } + // }, + // tooltip: { + // formatter: function() { + // return '' + this.x + '
' + + // this.series.name + ': ' + this.y; + // } + // }, + // plotOptions: { + // column: { + // stacking: 'normal', + // } + // }, + // series: [{ + // name: 'Gender', + // data: [Appointment_male, Appointment_female, Appointment_uknown_gender] + // }], + + // }); + + // var appointmentAge = Highcharts.chart('appointment_age', { + // chart: { + // type: 'column' + // }, + // title: { + // text: 'Appointment By Age' + // }, + // xAxis: { + // categories: ['0-9 YRS', '10-14 YRS', '15-19 YRS', '20-24 YRS', '25+ YRS', 'UKNOWN AGE'] + // }, + // yAxis: { + // min: 0, + // title: { + // text: 'Number of Appointments' + // }, + // stackLabels: { + // enabled: true, + // style: { + // fontWeight: 'bold', + // color: ( // theme + // Highcharts.defaultOptions.title.style && + // Highcharts.defaultOptions.title.style.color + // ) || 'gray' + // } + // } + // }, + // tooltip: { + // formatter: function() { + // return '' + this.x + '
' + + // this.series.name + ': ' + this.y; + // } + // }, + // plotOptions: { + // column: { + // stacking: 'normal', + // } + // }, + // series: [{ + // name: 'Age', + // data: [Appointment_to_nine, Appointment_to_fourteen, Appointment_to_nineteen, Appointment_to_twentyfour, Appointment_to_twentyfive_above, Appointment_uknown_age] + // }], + + // }); + + // // missed appointment charts + // var totalmissedappointmentGender = Highcharts.chart('total_missed_appointment_gender', { + // chart: { + // type: 'column' + // }, + // title: { + // text: 'Total Missed Appointment By Gender' + // }, + // xAxis: { + // categories: ['Male', 'Female', 'UKNOWN Gender'] + // }, + // yAxis: { + // min: 0, + // title: { + // text: 'No of Missed Appointments' + // }, + // stackLabels: { + // enabled: true, + // style: { + // fontWeight: 'bold', + // color: ( // theme + // Highcharts.defaultOptions.title.style && + // Highcharts.defaultOptions.title.style.color + // ) || 'gray' + // } + // } + // }, + // tooltip: { + // formatter: function() { + // return '' + this.x + '
' + + // this.series.name + ': ' + this.y; + // } + // }, + // plotOptions: { + // column: { + // stacking: 'normal', + // } + // }, + // series: [{ + // name: 'Gender', + // data: [Appointment_total_missed_male, Appointment_total_missed_female, Appointment_total_missed_uknown_gender] + // }], + + // }); + + // var totalmissedappointmentAge = Highcharts.chart('total_missed_appointment_age', { + // chart: { + // type: 'column' + // }, + // title: { + // text: 'Total Missed Appointment By Age' + // }, + // xAxis: { + // categories: ['0-9 YRS', '10-14 YRS', '15-19 YRS', '20-24 YRS', '25+ YRS', 'UKNOWN AGE'] + // }, + // yAxis: { + // min: 0, + // title: { + // text: 'No of Missed Appointments' + // }, + // stackLabels: { + // enabled: true, + // style: { + // fontWeight: 'bold', + // color: ( // theme + // Highcharts.defaultOptions.title.style && + // Highcharts.defaultOptions.title.style.color + // ) || 'gray' + // } + // } + // }, + // tooltip: { + // formatter: function() { + // return '' + this.x + '
' + + // this.series.name + ': ' + this.y; + // } + // }, + // plotOptions: { + // column: { + // stacking: 'normal', + // } + // }, + // series: [{ + // name: 'Age', + // data: [Appointment_total_missed_to_nine, Appointment_total_missed_to_fourteen, Appointment_total_missed_to_nineteen, Appointment_total_missed_to_twentyfour, Appointment_total_missed_to_twentyfive_above, Appointment_total_missed_uknown_age] + // }], + + // }); - var totalmissedappointmentAge = Highcharts.chart('total_missed_appointment_age', { - chart: { - type: 'column' - }, - title: { - text: 'Total Missed Appointment By Age' - }, - xAxis: { - categories: ['0-9 YRS', '10-14 YRS', '15-19 YRS', '20-24 YRS', '25+ YRS', 'UKNOWN AGE'] - }, - yAxis: { - min: 0, - title: { - text: 'No of Missed Appointments' - }, - stackLabels: { - enabled: true, - style: { - fontWeight: 'bold', - color: ( // theme - Highcharts.defaultOptions.title.style && - Highcharts.defaultOptions.title.style.color - ) || 'gray' - } - } - }, - tooltip: { - formatter: function() { - return '' + this.x + '
' + - this.series.name + ': ' + this.y; - } - }, - plotOptions: { - column: { - stacking: 'normal', - } - }, - series: [{ - name: 'Age', - data: [Appointment_total_missed_to_nine, Appointment_total_missed_to_fourteen, Appointment_total_missed_to_nineteen, Appointment_total_missed_to_twentyfour, Appointment_total_missed_to_twentyfive_above, Appointment_total_missed_uknown_age] - }], - - }); - - // CONSENTED CLIENTS GENDER - var consentedGender = Highcharts.chart('consented_gender', { - chart: { - type: 'column' - }, - title: { - text: 'Consented Clients By Gender' - }, - xAxis: { - categories: ['Male', 'Female', 'UKNOWN Gender'] - }, - yAxis: { - min: 0, - title: { - text: 'No of Consented Clients' - }, - stackLabels: { - enabled: true, - style: { - fontWeight: 'bold', - color: ( // theme - Highcharts.defaultOptions.title.style && - Highcharts.defaultOptions.title.style.color - ) || 'gray' - } - } - }, - tooltip: { - formatter: function() { - return '' + this.x + '
' + - this.series.name + ': ' + this.y; - } - }, - plotOptions: { - column: { - stacking: 'normal', - } - }, - series: [{ - name: 'Gender', - data: [Client_consented_male, Client_consented_female, Client_consented_uknown_gender] - }], - - }); - // CONSENTED CLIENTS AGE - var consentedAge = Highcharts.chart('consented_age', { - chart: { - type: 'column' - }, - title: { - text: 'Consented Clients By Age' - }, - xAxis: { - categories: ['0-9 YRS', '10-14 YRS', '15-19 YRS', '20-24 YRS', '25+ YRS', 'UKNOWN AGE'] - }, - yAxis: { - min: 0, - title: { - text: 'No of Consented Clients' - }, - stackLabels: { - enabled: true, - style: { - fontWeight: 'bold', - color: ( // theme - Highcharts.defaultOptions.title.style && - Highcharts.defaultOptions.title.style.color - ) || 'gray' - } - } - }, - tooltip: { - formatter: function() { - return '' + this.x + '
' + - this.series.name + ': ' + this.y; - } - }, - plotOptions: { - column: { - stacking: 'normal', - } - }, - series: [{ - name: 'Age', - data: [Client_consented_to_nine, Client_consented_to_fourteen, Client_consented_to_nineteen, Client_consented_to_twentyfour, Client_consented_to_twentyfive_above, Client_consented_uknown_age] - }], - - }); - - //NON CONSENTED CLIENTS GENDER - var nonconsentedGender = Highcharts.chart('nonconsented_gender', { - chart: { - type: 'column' - }, - title: { - text: 'Non Consented Clients By Gender' - }, - xAxis: { - categories: ['Male', 'Female', 'UKNOWN Gender'] - }, - yAxis: { - min: 0, - title: { - text: 'No of Non Consented Clients' - }, - stackLabels: { - enabled: true, - style: { - fontWeight: 'bold', - color: ( // theme - Highcharts.defaultOptions.title.style && - Highcharts.defaultOptions.title.style.color - ) || 'gray' - } - } - }, - tooltip: { - formatter: function() { - return '' + this.x + '
' + - this.series.name + ': ' + this.y; - } - }, - plotOptions: { - column: { - stacking: 'normal', - } - }, - series: [{ - name: 'Gender', - data: [Client_nonconsented_male, Client_nonconsented_female, Client_nonconsented_uknown_gender] - }], - - }); -// NON CONSENTED AGE - var nonconsentedAge = Highcharts.chart('nonconsented_age', { - chart: { - type: 'column' - }, - title: { - text: 'Non Consented Clients By Age' - }, - xAxis: { - categories: ['0-9 YRS', '10-14 YRS', '15-19 YRS', '20-24 YRS', '25+ YRS', 'UKNOWN AGE'] - }, - yAxis: { - min: 0, - title: { - text: 'No of Non Consented Clients' - }, - stackLabels: { - enabled: true, - style: { - fontWeight: 'bold', - color: ( // theme - Highcharts.defaultOptions.title.style && - Highcharts.defaultOptions.title.style.color - ) || 'gray' - } - } - }, - tooltip: { - formatter: function() { - return '' + this.x + '
' + - this.series.name + ': ' + this.y; - } - }, - plotOptions: { - column: { - stacking: 'normal', - } - }, - series: [{ - name: 'Age', - data: [Client_nonconsented_to_nine, Client_nonconsented_to_fourteen, Client_nonconsented_to_nineteen, Client_nonconsented_to_twentyfour, Client_nonconsented_to_twentyfive_above, Client_nonconsented_uknown_age] - }], - - }); diff --git a/resources/views/new_dashboard/missed_dashboard.blade.php b/resources/views/new_dashboard/missed_dashboard.blade.php new file mode 100644 index 0000000..c4032d4 --- /dev/null +++ b/resources/views/new_dashboard/missed_dashboard.blade.php @@ -0,0 +1,660 @@ +@extends('layouts.master') +@section('page-css') + +@endsection + +@section('main-content') + +@if (Auth::user()->access_level == 'Admin' || Auth::user()->access_level == 'Partner' || Auth::user()->access_level == 'Donor') + + +
+ + + {{ csrf_field() }} +
+
+
+ + +
+
+
+
+ +
+
+
+
+ + +
+
+
+
+ + + +
+
+
+
+ + + +
+
+ +
+
+
+ +
+ + +
+
+ +
+
+
+
+
+
+
+
+ +
+ + +
+
+ +
+
+
+
+
+
+ + +
+
+
+ + + +
+@endif + + + + + + + + + + + + + + + + + + + + + + + + +@endsection \ No newline at end of file diff --git a/resources/views/sms/sms_report.blade.php b/resources/views/sms/sms_report.blade.php index e9edadf..95fe23f 100644 --- a/resources/views/sms/sms_report.blade.php +++ b/resources/views/sms/sms_report.blade.php @@ -355,20 +355,7 @@ name: 'SMS Count', data: [Success, Failed_blacklist, Failed_absent, Failed_deliveryfailure, Failed_inactive, Rejected_inactive, Rejected_blacklist, Rejected_deliveryfailure] } - // { - // type: 'spline', - // name: 'Cost(Ksh)', - // data: [Success_cost, Failed_backlist_cost, Failed_absent_cost, Failed_delivery_cost, Failed_inactive_cost, Rejected_inactive_cost, Rejected_blacklist_cost, Rejected_delivery_cost], - // marker: { - // lineWidth: 2, - // lineColor: Highcharts.getOptions().colors[3], - // fillColor: 'white' - // } - // } - ], - - }); var costAnalytics = Highcharts.chart('cost_analytics', { @@ -474,6 +461,22 @@ xAxis: { type: 'category' }, + yAxis: { + min: 0, + title: { + text: 'Count' + }, + stackLabels: { + enabled: true, + style: { + fontWeight: 'bold', + color: ( // theme + Highcharts.defaultOptions.title.style && + Highcharts.defaultOptions.title.style.color + ) || 'gray' + } + } + }, legend: { enabled: false @@ -490,8 +493,12 @@ series: [{ name: 'Delivered Sms Count', - colorByPoint: true, - data: partner_delivered_array + colorByPoint: false, + data: partner_delivered_array, + dataSorting: { + enabled: true, + sortKey: 'y' + } }], @@ -511,6 +518,22 @@ xAxis: { type: 'category' }, + yAxis: { + min: 0, + title: { + text: 'Count' + }, + stackLabels: { + enabled: true, + style: { + fontWeight: 'bold', + color: ( // theme + Highcharts.defaultOptions.title.style && + Highcharts.defaultOptions.title.style.color + ) || 'gray' + } + } + }, legend: { enabled: false @@ -527,8 +550,12 @@ series: [{ name: 'Failed Sms Count', - colorByPoint: true, - data: partner_failed_array + colorByPoint: false, + data: partner_failed_array, + dataSorting: { + enabled: true, + sortKey: 'y' + } }], @@ -548,6 +575,22 @@ xAxis: { type: 'category' }, + yAxis: { + min: 0, + title: { + text: 'Count' + }, + stackLabels: { + enabled: true, + style: { + fontWeight: 'bold', + color: ( // theme + Highcharts.defaultOptions.title.style && + Highcharts.defaultOptions.title.style.color + ) || 'gray' + } + } + }, legend: { enabled: false @@ -564,8 +607,12 @@ series: [{ name: 'SMS Cost(Ksh)', - colorByPoint: true, - data: partner_cost_array + colorByPoint: false, + data: partner_cost_array, + dataSorting: { + enabled: true, + sortKey: 'y' + } }], @@ -585,6 +632,22 @@ xAxis: { type: 'category' }, + yAxis: { + min: 0, + title: { + text: 'Count' + }, + stackLabels: { + enabled: false, + style: { + fontWeight: 'bold', + color: ( // theme + Highcharts.defaultOptions.title.style && + Highcharts.defaultOptions.title.style.color + ) || 'gray' + } + } + }, legend: { enabled: false @@ -601,8 +664,12 @@ series: [{ name: 'SMS Cost(Ksh)', - colorByPoint: true, - data: county_cost_array + colorByPoint: false, + data: county_cost_array, + dataSorting: { + enabled: true, + sortKey: 'y' + } }], @@ -612,8 +679,6 @@ }) }); - - var colors = Highcharts.getOptions().colors; @endsection diff --git a/routes/web.php b/routes/web.php index 8c669f7..089471a 100644 --- a/routes/web.php +++ b/routes/web.php @@ -200,6 +200,10 @@ // new dashbaord routes Route::get('/admin/dashboard', ['uses' => 'App\Http\Controllers\NewDashboardController@dashboard', 'as' => 'dashboard']); + Route::get('/admin/client/dashboard', ['uses' => 'App\Http\Controllers\NewDashboardController@client_dashboard', 'as' => 'client_dashboard']); Route::get('/admin/appointment/dashboard', ['uses' => 'App\Http\Controllers\NewDashboardController@appointment_charts', 'as' => 'appointment_charts']); + Route::get('/admin/appointment/missed/dashboard', ['uses' => 'App\Http\Controllers\NewDashboardController@missed_appointment_charts', 'as' => 'missed_appointment_charts']); Route::get('/filter_charts', ['uses' => 'App\Http\Controllers\NewDashboardController@filter_charts', 'as' => 'filter_charts']); + Route::get('/filter_dashboard_charts', ['uses' => 'App\Http\Controllers\NewDashboardController@filter_dashboard_charts', 'as' => 'filter_dashboard_charts']); + Route::get('/filter_client_charts', ['uses' => 'App\Http\Controllers\NewDashboardController@filter_client_charts', 'as' => 'filter_client_charts']); }); From c63d7063237402e15b2c723b99386b9d26762743 Mon Sep 17 00:00:00 2001 From: Ronald-pro <36841157+Ronald-pro@users.noreply.github.com> Date: Tue, 10 May 2022 23:04:44 +0300 Subject: [PATCH 047/171] refactor the filters --- .../Controllers/NewDashboardController.php | 6356 +++++++++++------ .../clients/upload-clients-form.blade.php | 7 +- .../large-vertical-sidebar/sidebar.blade.php | 7 +- .../appointment_dashboard.blade.php | 117 +- .../new_dashboard/client_dashboard.blade.php | 152 +- .../new_dashboard/main_dashbaord.blade.php | 185 +- .../new_dashboard/missed_dashboard.blade.php | 136 +- routes/web.php | 1 + 8 files changed, 4514 insertions(+), 2447 deletions(-) diff --git a/app/Http/Controllers/NewDashboardController.php b/app/Http/Controllers/NewDashboardController.php index b7f595f..e708693 100644 --- a/app/Http/Controllers/NewDashboardController.php +++ b/app/Http/Controllers/NewDashboardController.php @@ -1,6 +1,7 @@ access_level == 'Facility') { $all_partners = Partner::where('status', '=', 'Active')->pluck('name', 'id'); $client = Client::where('status', '=', 'Active') - ->whereNull('hei_no') - ->where('mfl_code', Auth::user()->facility_id) - ->count('clinic_number'); + ->whereNull('hei_no') + ->where('mfl_code', Auth::user()->facility_id) + ->count('clinic_number'); $client_ever_enrolled = Client::whereNull('hei_no') - ->where('mfl_code', Auth::user()->facility_id) - ->count('clinic_number'); + ->where('mfl_code', Auth::user()->facility_id) + ->count('clinic_number'); $indicator = Indicator::select(['name', 'description'])->get(); @@ -45,10 +46,10 @@ public function dashboard() ->orderBy('tbl_appointment.created_at', 'DESC') ->groupBy('tbl_partner_facility.mfl_code') ->get(); - $facilities_ever_enrolled = PartnerFacility::count('mfl_code'); + $facilities_ever_enrolled = PartnerFacility::count('mfl_code'); - // dd($active_facilities); + // dd($active_facilities); // active clients by gender $clients_male = Client::select('id')->where([['gender', '=', '2'], ['status', '=', 'Active'],]) ->whereNull('hei_no') @@ -69,64 +70,64 @@ public function dashboard() $client_to_nine = Cache::remember('client_to_nine', 10, function () { return Client::select(\DB::raw("count((case when (((year(curdate()) - year(`dob`)) > 0) and ((year(curdate()) - year(`dob`)) <= 9)) then `dob` end)) AS count")) - ->where('status', '=', 'Active') - ->whereNull('hei_no') - ->where('mfl_code', Auth::user()->facility_id) - ->pluck('count'); + ->where('status', '=', 'Active') + ->whereNull('hei_no') + ->where('mfl_code', Auth::user()->facility_id) + ->pluck('count'); }); $client_to_fourteen = Cache::remember('client-fourteen', 10, function () { return Client::select(\DB::raw("count((case when (((year(curdate()) - year(`dob`)) >= 10) and ((year(curdate()) - year(`dob`)) <= 14)) then `dob` end)) AS count")) - ->where('status', '=', 'Active') - ->whereNull('hei_no') - ->where('mfl_code', Auth::user()->facility_id) - ->pluck('count'); + ->where('status', '=', 'Active') + ->whereNull('hei_no') + ->where('mfl_code', Auth::user()->facility_id) + ->pluck('count'); }); $client_to_nineteen = Cache::remember('client-nineteen', 10, function () { return Client::select(\DB::raw("count((case when (((year(curdate()) - year(`dob`)) >= 15) and ((year(curdate()) - year(`dob`)) <= 19)) then `dob` end)) AS count")) - ->where('status', '=', 'Active') - ->whereNull('hei_no') - ->where('mfl_code', Auth::user()->facility_id) - ->pluck('count'); + ->where('status', '=', 'Active') + ->whereNull('hei_no') + ->where('mfl_code', Auth::user()->facility_id) + ->pluck('count'); }); $client_to_twentyfour = Cache::remember('client-twentyfour', 10, function () { return Client::select(\DB::raw("count((case when (((year(curdate()) - year(`dob`)) >= 20) and ((year(curdate()) - year(`dob`)) <= 24)) then `id` end)) AS count")) - ->where('status', '=', 'Active') - ->whereNull('hei_no') - ->where('mfl_code', Auth::user()->facility_id) - ->pluck('count'); + ->where('status', '=', 'Active') + ->whereNull('hei_no') + ->where('mfl_code', Auth::user()->facility_id) + ->pluck('count'); }); $client_to_twentyfive_above = Cache::remember('client-twentyfive-above', 10, function () { - return Client::select(\DB::raw("count((case when (((year(curdate()) - year(`dob`)) >= 25)) then `id` end)) AS count")) - ->where('status', '=', 'Active') - ->whereNull('hei_no') - ->where('mfl_code', Auth::user()->facility_id) - ->pluck('count'); + return Client::select(\DB::raw("count((case when (((year(curdate()) - year(`dob`)) >= 25)) then `id` end)) AS count")) + ->where('status', '=', 'Active') + ->whereNull('hei_no') + ->where('mfl_code', Auth::user()->facility_id) + ->pluck('count'); }); $client_unknown_age = Cache::remember('client-unknown-age', 10, function () { - return Client::where('dob', '=', '') - ->orWhereNull('dob') - ->where('status', '=', 'Active') - ->whereNull('hei_no') - ->where('mfl_code', Auth::user()->facility_id) - ->count(); + return Client::where('dob', '=', '') + ->orWhereNull('dob') + ->where('status', '=', 'Active') + ->whereNull('hei_no') + ->where('mfl_code', Auth::user()->facility_id) + ->count(); }); } if (Auth::user()->access_level == 'Partner') { $all_partners = Partner::where('status', '=', 'Active')->pluck('name', 'id'); $client = Client::join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') - ->where('tbl_client.status', '=', 'Active') + ->where('tbl_client.status', '=', 'Active') ->whereNull('tbl_client.hei_no') ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) ->count('tbl_client.clinic_number'); $client_ever_enrolled = Client::join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') - ->whereNull('tbl_client.hei_no') - ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) - ->count('tbl_client.clinic_number'); + ->whereNull('tbl_client.hei_no') + ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) + ->count('tbl_client.clinic_number'); $indicator = Indicator::select(['name', 'description'])->get(); $active_facilities = PartnerFacility::join('tbl_client', 'tbl_partner_facility.mfl_code', '=', 'tbl_client.mfl_code') @@ -138,24 +139,24 @@ public function dashboard() ->groupBy('tbl_partner_facility.mfl_code') ->get(); $facilities_ever_enrolled = PartnerFacility::where('partner_id', Auth::user()->partner_id) - ->count('mfl_code'); + ->count('mfl_code'); - // dd($active_facilities); + // dd($active_facilities); // active clients by gender $clients_male = Client::join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') - ->select('id')->where([['tbl_client.gender', '=', '2'], ['tbl_client.status', '=', 'Active'],]) + ->select('id')->where([['tbl_client.gender', '=', '2'], ['tbl_client.status', '=', 'Active'],]) ->whereNull('tbl_client.hei_no') ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) ->count(); $clients_female = Client::join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') - ->where('tbl_client.gender', '=', '1') + ->where('tbl_client.gender', '=', '1') ->where('tbl_client.status', '=', 'Active') ->whereNull('tbl_client.hei_no') ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) ->count(); $unknown_gender = Client::join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') - ->where('tbl_client.gender', '!=', '1') + ->where('tbl_client.gender', '!=', '1') ->where('tbl_client.gender', '!=', '2') ->where('tbl_client.status', '=', 'Active') ->whereNull('tbl_client.hei_no') @@ -164,59 +165,58 @@ public function dashboard() $client_to_nine = Cache::remember('client_to_nine', 10, function () { return Client::join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') - ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) > 0) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 9)) then `tbl_client`.`dob` end)) AS count")) - ->where('tbl_client.status', '=', 'Active') - ->whereNull('tbl_client.hei_no') - ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) - ->pluck('count'); + ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) > 0) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 9)) then `tbl_client`.`dob` end)) AS count")) + ->where('tbl_client.status', '=', 'Active') + ->whereNull('tbl_client.hei_no') + ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) + ->pluck('count'); }); $client_to_fourteen = Cache::remember('client-fourteen', 10, function () { return Client::join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') - ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 10) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 14)) then `tbl_client`.`dob` end)) AS count")) - ->where('tbl_client.status', '=', 'Active') - ->whereNull('tbl_client.hei_no') - ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) - ->pluck('count'); + ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 10) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 14)) then `tbl_client`.`dob` end)) AS count")) + ->where('tbl_client.status', '=', 'Active') + ->whereNull('tbl_client.hei_no') + ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) + ->pluck('count'); }); $client_to_nineteen = Cache::remember('client-nineteen', 10, function () { return Client::join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') - ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 15) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 19)) then `tbl_client`.`dob` end)) AS count")) - ->where('tbl_client.status', '=', 'Active') - ->whereNull('tbl_client.hei_no') - ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) - ->pluck('count'); + ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 15) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 19)) then `tbl_client`.`dob` end)) AS count")) + ->where('tbl_client.status', '=', 'Active') + ->whereNull('tbl_client.hei_no') + ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) + ->pluck('count'); }); $client_to_twentyfour = Cache::remember('client-twentyfour', 10, function () { return Client::join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') - ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 20) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 24)) then `tbl_client`.`dob` end)) AS count")) - ->where('tbl_client.status', '=', 'Active') - ->whereNull('tbl_client.hei_no') - ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) - ->pluck('count'); + ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 20) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 24)) then `tbl_client`.`dob` end)) AS count")) + ->where('tbl_client.status', '=', 'Active') + ->whereNull('tbl_client.hei_no') + ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) + ->pluck('count'); }); $client_to_twentyfive_above = Cache::remember('client-twentyfive-above', 10, function () { - return Client::join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') - ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 25)) then `tbl_client`.`dob` end)) AS count")) - ->where('tbl_client.status', '=', 'Active') - ->whereNull('tbl_client.hei_no') - ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) - ->pluck('count'); + return Client::join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 25)) then `tbl_client`.`dob` end)) AS count")) + ->where('tbl_client.status', '=', 'Active') + ->whereNull('tbl_client.hei_no') + ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) + ->pluck('count'); }); $client_unknown_age = Cache::remember('client-unknown-age', 10, function () { - return Client::join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') - ->where('tbl_client.dob', '=', '') - ->orWhereNull('tbl_client.dob') - ->where('tbl_client.status', '=', 'Active') - ->whereNull('tbl_client.hei_no') - ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) - ->count(); + return Client::join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->where('tbl_client.dob', '=', '') + ->orWhereNull('tbl_client.dob') + ->where('tbl_client.status', '=', 'Active') + ->whereNull('tbl_client.hei_no') + ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) + ->count(); }); - } if (Auth::user()->access_level == 'Admin' || Auth::user()->access_level == 'Donor') { @@ -236,7 +236,7 @@ public function dashboard() ->get(); $facilities_ever_enrolled = PartnerFacility::count('mfl_code'); - // dd($active_facilities); + // dd($active_facilities); // active clients by gender $clients_male = Client::select('id')->where([['gender', '=', '2'], ['status', '=', 'Active'],]) ->whereNull('hei_no') @@ -254,165 +254,165 @@ public function dashboard() $client_to_nine = Cache::remember('client_to_nine', 10, function () { return Client::select(\DB::raw("count((case when (((year(curdate()) - year(`dob`)) > 0) and ((year(curdate()) - year(`dob`)) <= 9)) then `dob` end)) AS count")) - ->where('status', '=', 'Active') - ->whereNull('hei_no') - ->pluck('count'); + ->where('status', '=', 'Active') + ->whereNull('hei_no') + ->pluck('count'); }); $client_to_fourteen = Cache::remember('client-fourteen', 10, function () { return Client::select(\DB::raw("count((case when (((year(curdate()) - year(`dob`)) >= 10) and ((year(curdate()) - year(`dob`)) <= 14)) then `dob` end)) AS count")) - ->where('status', '=', 'Active') - ->whereNull('hei_no') - ->pluck('count'); + ->where('status', '=', 'Active') + ->whereNull('hei_no') + ->pluck('count'); }); $client_to_nineteen = Cache::remember('client-nineteen', 10, function () { return Client::select(\DB::raw("count((case when (((year(curdate()) - year(`dob`)) >= 15) and ((year(curdate()) - year(`dob`)) <= 19)) then `dob` end)) AS count")) - ->where('status', '=', 'Active') - ->whereNull('hei_no') - ->pluck('count'); + ->where('status', '=', 'Active') + ->whereNull('hei_no') + ->pluck('count'); }); $client_to_twentyfour = Cache::remember('client-twentyfour', 10, function () { return Client::select(\DB::raw("count((case when (((year(curdate()) - year(`dob`)) >= 20) and ((year(curdate()) - year(`dob`)) <= 24)) then `id` end)) AS count")) - ->where('status', '=', 'Active') - ->whereNull('hei_no') - ->pluck('count'); + ->where('status', '=', 'Active') + ->whereNull('hei_no') + ->pluck('count'); }); $client_to_twentyfive_above = Cache::remember('client-twentyfive-above', 10, function () { - return Client::select(\DB::raw("count((case when (((year(curdate()) - year(`dob`)) >= 25)) then `id` end)) AS count")) - ->where('status', '=', 'Active') - ->whereNull('hei_no') - ->pluck('count'); + return Client::select(\DB::raw("count((case when (((year(curdate()) - year(`dob`)) >= 25)) then `id` end)) AS count")) + ->where('status', '=', 'Active') + ->whereNull('hei_no') + ->pluck('count'); }); $client_unknown_age = Cache::remember('client-unknown-age', 10, function () { - return Client::where('dob', '=', '') - ->orWhereNull('dob') - ->where('status', '=', 'Active') - ->whereNull('hei_no') - ->count(); + return Client::where('dob', '=', '') + ->orWhereNull('dob') + ->where('status', '=', 'Active') + ->whereNull('hei_no') + ->count(); }); - // // appointment by gender - // $appointment_male = Cache::remember('appointment-male', 10, function () { - // return Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') - // ->select('tbl_appointment.id') - // ->where('tbl_client.gender', '=', '2') - // ->count(); - // }); - // $appointment_female = Cache::remember('appointment-female', 10, function () { - // return Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') - // ->select('tbl_appointment.id') - // ->where('tbl_client.gender', '=', '1') - // ->count(); - // }); - // $appointment_uknown_gender = Cache::remember('appointment-uknown-gender', 10, function () { - // return Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') - // ->select('tbl_appointment.id') - // ->where('tbl_client.gender', '!=', '1') - // ->where('tbl_client.gender', '!=', '2') - // ->count(); - // }); - // // appointment by age - // $appointment_to_nine = Cache::remember('appointment-to-nine', 10, function () { - // return Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') - // ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') - // ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) > 0) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 9)) then `tbl_client`.`id` end)) AS count")) - // ->pluck('count'); - // }); - // $appointment_to_fourteen = Cache::remember('appointment-to-fourteen', 10, function () { - // return Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') - // ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') - // ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 10) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 14)) then `tbl_client`.`id` end)) AS count")) - // ->pluck('count'); - // }); - // $appointment_to_nineteen = Cache::remember('appointment-to-nineteen', 10, function () { - // return Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') - // ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') - // ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 15) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 19)) then `tbl_client`.`id` end)) AS count")) - // ->pluck('count'); - // }); - // $appointment_to_twentyfour = Cache::remember('appointment-to-twentyfour', 10, function () { - // return Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') - // ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') - // ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 20) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 24)) then `tbl_client`.`id` end)) AS count")) - // ->pluck('count'); - // }); - // $appointment_to_twentyfive_above = Cache::remember('appointment-to-twentyfive-above', 10, function () { - // return Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') - // ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') - // ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 25)) then `tbl_client`.`id` end)) AS count")) - // ->pluck('count'); - // }); - // $appointment_uknown_age = Cache::remember('appointment-uknown-age', 10, function () { - // return Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') - // ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') - // ->where('tbl_client.dob', '=', '') - // ->orWhereNull('tbl_client.dob') - // ->count(); - // }); - - // // Total missed appointment by gender - // $appointment_total_missed_female = Cache::remember('appointment-total-missed-female', 10, function () { - // return Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') - // ->whereIn('tbl_appointment.app_status', ['Defaulted', 'LTFU', 'Missed']) - // ->where('tbl_client.gender', '=', '1') - // ->count(); - // }); - // $appointment_total_missed_male = Cache::remember('appointment-total-missed-male', 10, function () { - // return Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') - // ->where('tbl_client.gender', '=', '2') - // ->whereIn('tbl_appointment.app_status', ['Defaulted', 'LTFU', 'Missed']) - // ->count(); - // }); - // $appointment_total_missed_uknown_gender = Cache::remember('appointment-total-missed-uknown-gender', 10, function () { - // return Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') - // ->whereIn('tbl_appointment.app_status', ['Defaulted', 'LTFU', 'Missed']) - // ->where('tbl_client.gender', '!=', '1') - // ->where('tbl_client.gender', '!=', '2') - // ->count(); - // }); - - // // Total missed appointment by age - // $appointment_total_missed_to_nine = Cache::remember('appointment-total-missed-to-nine', 10, function () { - // return Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') - // ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) > 0) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 9)) then `tbl_client`.`id` end)) AS count")) - // ->whereIn('tbl_appointment.app_status', ['Defaulted', 'LTFU', 'Missed']) - // ->pluck('count'); - // }); - // $appointment_total_missed_to_fourteen = Cache::remember('appointment-total-missed-to-fourteen', 10, function () { - // return Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') - // ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 10) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 14)) then `tbl_client`.`id` end)) AS count")) - // ->whereIn('tbl_appointment.app_status', ['Defaulted', 'LTFU', 'Missed']) - // ->pluck('count'); - // }); - // $appointment_total_missed_to_nineteen = Cache::remember('appointment-total-missed-to-nineteen', 10, function () { - // return Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') - // ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 15) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 19)) then `tbl_client`.`id` end)) AS count")) - // ->whereIn('tbl_appointment.app_status', ['Defaulted', 'LTFU', 'Missed']) - // ->pluck('count'); - // }); - // $appointment_total_missed_to_twentyfour = Cache::remember('appointment-total-missed-to-twentyfour', 10, function () { - // return Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') - // ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 20) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 24)) then `tbl_client`.`id` end)) AS count")) - // ->whereIn('tbl_appointment.app_status', ['Defaulted', 'LTFU', 'Missed']) - // ->pluck('count'); - // }); - // $appointment_total_missed_to_twentyfive_above = Cache::remember('appointment-total-missed-to-twentyfive_above', 10, function () { - // return Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') - // ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 25)) then `tbl_client`.`id` end)) AS count")) - // ->whereIn('tbl_appointment.app_status', ['Defaulted', 'LTFU', 'Missed']) - // ->pluck('count'); - // }); - // $appointment_total_missed_uknown_age = Cache::remember('appointment-total-missed-uknown-age', 10, function () { - // return Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') - // ->where('tbl_client.dob', '=', '') - // ->orWhereNull('tbl_client.dob') - // ->whereIn('tbl_appointment.app_status', ['Defaulted', 'LTFU', 'Missed']) - // ->count(); - // }); + // // appointment by gender + // $appointment_male = Cache::remember('appointment-male', 10, function () { + // return Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + // ->select('tbl_appointment.id') + // ->where('tbl_client.gender', '=', '2') + // ->count(); + // }); + // $appointment_female = Cache::remember('appointment-female', 10, function () { + // return Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + // ->select('tbl_appointment.id') + // ->where('tbl_client.gender', '=', '1') + // ->count(); + // }); + // $appointment_uknown_gender = Cache::remember('appointment-uknown-gender', 10, function () { + // return Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + // ->select('tbl_appointment.id') + // ->where('tbl_client.gender', '!=', '1') + // ->where('tbl_client.gender', '!=', '2') + // ->count(); + // }); + // // appointment by age + // $appointment_to_nine = Cache::remember('appointment-to-nine', 10, function () { + // return Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + // ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + // ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) > 0) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 9)) then `tbl_client`.`id` end)) AS count")) + // ->pluck('count'); + // }); + // $appointment_to_fourteen = Cache::remember('appointment-to-fourteen', 10, function () { + // return Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + // ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + // ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 10) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 14)) then `tbl_client`.`id` end)) AS count")) + // ->pluck('count'); + // }); + // $appointment_to_nineteen = Cache::remember('appointment-to-nineteen', 10, function () { + // return Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + // ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + // ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 15) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 19)) then `tbl_client`.`id` end)) AS count")) + // ->pluck('count'); + // }); + // $appointment_to_twentyfour = Cache::remember('appointment-to-twentyfour', 10, function () { + // return Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + // ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + // ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 20) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 24)) then `tbl_client`.`id` end)) AS count")) + // ->pluck('count'); + // }); + // $appointment_to_twentyfive_above = Cache::remember('appointment-to-twentyfive-above', 10, function () { + // return Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + // ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + // ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 25)) then `tbl_client`.`id` end)) AS count")) + // ->pluck('count'); + // }); + // $appointment_uknown_age = Cache::remember('appointment-uknown-age', 10, function () { + // return Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + // ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + // ->where('tbl_client.dob', '=', '') + // ->orWhereNull('tbl_client.dob') + // ->count(); + // }); + + // // Total missed appointment by gender + // $appointment_total_missed_female = Cache::remember('appointment-total-missed-female', 10, function () { + // return Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + // ->whereIn('tbl_appointment.app_status', ['Defaulted', 'LTFU', 'Missed']) + // ->where('tbl_client.gender', '=', '1') + // ->count(); + // }); + // $appointment_total_missed_male = Cache::remember('appointment-total-missed-male', 10, function () { + // return Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + // ->where('tbl_client.gender', '=', '2') + // ->whereIn('tbl_appointment.app_status', ['Defaulted', 'LTFU', 'Missed']) + // ->count(); + // }); + // $appointment_total_missed_uknown_gender = Cache::remember('appointment-total-missed-uknown-gender', 10, function () { + // return Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + // ->whereIn('tbl_appointment.app_status', ['Defaulted', 'LTFU', 'Missed']) + // ->where('tbl_client.gender', '!=', '1') + // ->where('tbl_client.gender', '!=', '2') + // ->count(); + // }); + + // // Total missed appointment by age + // $appointment_total_missed_to_nine = Cache::remember('appointment-total-missed-to-nine', 10, function () { + // return Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + // ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) > 0) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 9)) then `tbl_client`.`id` end)) AS count")) + // ->whereIn('tbl_appointment.app_status', ['Defaulted', 'LTFU', 'Missed']) + // ->pluck('count'); + // }); + // $appointment_total_missed_to_fourteen = Cache::remember('appointment-total-missed-to-fourteen', 10, function () { + // return Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + // ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 10) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 14)) then `tbl_client`.`id` end)) AS count")) + // ->whereIn('tbl_appointment.app_status', ['Defaulted', 'LTFU', 'Missed']) + // ->pluck('count'); + // }); + // $appointment_total_missed_to_nineteen = Cache::remember('appointment-total-missed-to-nineteen', 10, function () { + // return Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + // ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 15) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 19)) then `tbl_client`.`id` end)) AS count")) + // ->whereIn('tbl_appointment.app_status', ['Defaulted', 'LTFU', 'Missed']) + // ->pluck('count'); + // }); + // $appointment_total_missed_to_twentyfour = Cache::remember('appointment-total-missed-to-twentyfour', 10, function () { + // return Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + // ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 20) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 24)) then `tbl_client`.`id` end)) AS count")) + // ->whereIn('tbl_appointment.app_status', ['Defaulted', 'LTFU', 'Missed']) + // ->pluck('count'); + // }); + // $appointment_total_missed_to_twentyfive_above = Cache::remember('appointment-total-missed-to-twentyfive_above', 10, function () { + // return Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + // ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 25)) then `tbl_client`.`id` end)) AS count")) + // ->whereIn('tbl_appointment.app_status', ['Defaulted', 'LTFU', 'Missed']) + // ->pluck('count'); + // }); + // $appointment_total_missed_uknown_age = Cache::remember('appointment-total-missed-uknown-age', 10, function () { + // return Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + // ->where('tbl_client.dob', '=', '') + // ->orWhereNull('tbl_client.dob') + // ->whereIn('tbl_appointment.app_status', ['Defaulted', 'LTFU', 'Missed']) + // ->count(); + // }); } @@ -446,188 +446,187 @@ public function client_dashboard() if (Auth::user()->access_level == 'Facility') { $all_partners = Partner::where('status', '=', 'Active')->pluck('name', 'id'); $client = Client::where('status', '=', 'Active') - ->whereNull('hei_no') - ->where('mfl_code', Auth::user()->facility_id) - ->count('clinic_number'); + ->whereNull('hei_no') + ->where('mfl_code', Auth::user()->facility_id) + ->count('clinic_number'); $indicator = Indicator::select(['name', 'description'])->get(); // client charts $client_consented = Cache::remember('client-consented', 10, function () { return Client::select('smsenable') - ->where('status', '=', 'Active') - ->whereNull('hei_no') - ->where('smsenable', '=', 'Yes') - ->where('mfl_code', Auth::user()->facility_id) - ->count(); + ->where('status', '=', 'Active') + ->whereNull('hei_no') + ->where('smsenable', '=', 'Yes') + ->where('mfl_code', Auth::user()->facility_id) + ->count(); }); $client_nonconsented = Cache::remember('client-nonconsented', 10, function () { return Client::select('smsenable') - ->where('status', '=', 'Active') - ->whereNull('hei_no') - ->where('smsenable', '!=', 'Yes') - ->where('mfl_code', Auth::user()->facility_id) - ->count(); + ->where('status', '=', 'Active') + ->whereNull('hei_no') + ->where('smsenable', '!=', 'Yes') + ->where('mfl_code', Auth::user()->facility_id) + ->count(); }); // consented clients by gender $client_consented_male = Cache::remember('client-consented-male', 10, function () { return Client::where('smsenable', '=', 'Yes') - ->where('status', '=', 'Active') - ->whereNull('hei_no') - ->where('gender', '=', '2') - ->where('mfl_code', Auth::user()->facility_id) - ->count(); + ->where('status', '=', 'Active') + ->whereNull('hei_no') + ->where('gender', '=', '2') + ->where('mfl_code', Auth::user()->facility_id) + ->count(); }); $client_consented_female = Cache::remember('client-consented-female', 10, function () { return Client::where('smsenable', '=', 'Yes') - ->where('status', '=', 'Active') - ->whereNull('hei_no') - ->where('gender', '=', '1') - ->where('mfl_code', Auth::user()->facility_id) - ->count(); + ->where('status', '=', 'Active') + ->whereNull('hei_no') + ->where('gender', '=', '1') + ->where('mfl_code', Auth::user()->facility_id) + ->count(); }); $client_consented_uknown_gender = Cache::remember('client-consented-uknown-gender', 10, function () { return Client::where('smsenable', '=', 'Yes') - ->where('status', '=', 'Active') - ->whereNull('hei_no') - ->where('gender', '!=', '1') - ->where('gender', '!=', '2') - ->where('mfl_code', Auth::user()->facility_id) - ->count(); + ->where('status', '=', 'Active') + ->whereNull('hei_no') + ->where('gender', '!=', '1') + ->where('gender', '!=', '2') + ->where('mfl_code', Auth::user()->facility_id) + ->count(); }); // non consented clients by gender $client_nonconsented_male = Cache::remember('client-nonconsented-male', 10, function () { - return Client::where('smsenable', '!=', 'Yes') - ->where('status', '=', 'Active') - ->whereNull('hei_no') - ->where('gender', '=', '2') - ->where('mfl_code', Auth::user()->facility_id) - ->count(); + return Client::where('smsenable', '!=', 'Yes') + ->where('status', '=', 'Active') + ->whereNull('hei_no') + ->where('gender', '=', '2') + ->where('mfl_code', Auth::user()->facility_id) + ->count(); }); $client_nonconsented_female = Cache::remember('client-nonconsented-female', 10, function () { return Client::where('smsenable', '!=', 'Yes') - ->where('status', '=', 'Active') - ->whereNull('hei_no') - ->where('gender', '=', '1') - ->where('mfl_code', Auth::user()->facility_id) - ->count(); + ->where('status', '=', 'Active') + ->whereNull('hei_no') + ->where('gender', '=', '1') + ->where('mfl_code', Auth::user()->facility_id) + ->count(); }); $client_nonconsented_uknown_gender = Cache::remember('client-nonconsented-uknown-gender', 10, function () { return Client::where('smsenable', '!=', 'Yes') - ->where('gender', '!=', '1') - ->where('gender', '!=', '2') - ->where('mfl_code', Auth::user()->facility_id) - ->count(); + ->where('gender', '!=', '1') + ->where('gender', '!=', '2') + ->where('mfl_code', Auth::user()->facility_id) + ->count(); }); // consented clients by age distribution $client_consented_to_nine = Cache::remember('client-consented-to-nine', 10, function () { return Client::select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) > 0) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 9)) then `tbl_client`.`id` end)) AS count")) - ->where('smsenable', '=', 'Yes') - ->where('status', '=', 'Active') - ->whereNull('hei_no') - ->where('mfl_code', Auth::user()->facility_id) - ->pluck('count'); + ->where('smsenable', '=', 'Yes') + ->where('status', '=', 'Active') + ->whereNull('hei_no') + ->where('mfl_code', Auth::user()->facility_id) + ->pluck('count'); }); $client_consented_to_fourteen = Cache::remember('tbl-client', 10, function () { return Client::select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 10) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 14)) then `tbl_client`.`id` end)) AS count")) - ->where('smsenable', '=', 'Yes') - ->where('status', '=', 'Active') - ->whereNull('hei_no') - ->where('mfl_code', Auth::user()->facility_id) - ->pluck('count'); + ->where('smsenable', '=', 'Yes') + ->where('status', '=', 'Active') + ->whereNull('hei_no') + ->where('mfl_code', Auth::user()->facility_id) + ->pluck('count'); }); $client_consented_to_nineteen = Cache::remember('client-consented-to-nineteen', 10, function () { return Client::select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 15) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 19)) then `tbl_client`.`id` end)) AS count")) - ->where('smsenable', '=', 'Yes') - ->where('status', '=', 'Active') - ->whereNull('hei_no') - ->where('mfl_code', Auth::user()->facility_id) - ->pluck('count'); + ->where('smsenable', '=', 'Yes') + ->where('status', '=', 'Active') + ->whereNull('hei_no') + ->where('mfl_code', Auth::user()->facility_id) + ->pluck('count'); }); $client_consented_to_twentyfour = Cache::remember('client-consented-to-twentyfour', 10, function () { return Client::select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 20) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 24)) then `tbl_client`.`id` end)) AS count")) - ->where('smsenable', '=', 'Yes') - ->where('status', '=', 'Active') - ->whereNull('hei_no') - ->where('mfl_code', Auth::user()->facility_id) - ->pluck('count'); + ->where('smsenable', '=', 'Yes') + ->where('status', '=', 'Active') + ->whereNull('hei_no') + ->where('mfl_code', Auth::user()->facility_id) + ->pluck('count'); }); $client_consented_to_twentyfive_above = Cache::remember('client-consented-to-twentyfive-above', 10, function () { return Client::select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 25)) then `tbl_client`.`id` end)) AS count")) - ->where('smsenable', '=', 'Yes') - ->where('status', '=', 'Active') - ->whereNull('hei_no') - ->where('mfl_code', Auth::user()->facility_id) - ->pluck('count'); + ->where('smsenable', '=', 'Yes') + ->where('status', '=', 'Active') + ->whereNull('hei_no') + ->where('mfl_code', Auth::user()->facility_id) + ->pluck('count'); }); $client_consented_uknown_age = Cache::remember('client-consented-uknown-age', 10, function () { return Client::select('smsenable') - ->where('dob', '=', '') - ->where('status', '=', 'Active') - ->whereNull('hei_no') - ->orWhereNull('dob') - ->where('smsenable', '=', 'Yes') - ->where('mfl_code', Auth::user()->facility_id) - ->count(); + ->where('dob', '=', '') + ->where('status', '=', 'Active') + ->whereNull('hei_no') + ->orWhereNull('dob') + ->where('smsenable', '=', 'Yes') + ->where('mfl_code', Auth::user()->facility_id) + ->count(); }); // non consented clients by age distribution $client_nonconsented_to_nine = Cache::remember('client-nonconsented-to-nine', 10, function () { - return Client::select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) > 0) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 9)) then `tbl_client`.`id` end)) AS count")) - ->where('smsenable', '!=', 'Yes') - ->where('status', '=', 'Active') - ->whereNull('hei_no') - ->where('mfl_code', Auth::user()->facility_id) - ->pluck('count'); + return Client::select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) > 0) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 9)) then `tbl_client`.`id` end)) AS count")) + ->where('smsenable', '!=', 'Yes') + ->where('status', '=', 'Active') + ->whereNull('hei_no') + ->where('mfl_code', Auth::user()->facility_id) + ->pluck('count'); }); $client_nonconsented_to_fourteen = Cache::remember('client-nonconsented-to-fourteen', 10, function () { return Client::select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 10) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 14)) then `tbl_client`.`id` end)) AS count")) - ->where('smsenable', '!=', 'Yes') - ->where('status', '=', 'Active') - ->whereNull('hei_no') - ->where('mfl_code', Auth::user()->facility_id) - ->pluck('count'); + ->where('smsenable', '!=', 'Yes') + ->where('status', '=', 'Active') + ->whereNull('hei_no') + ->where('mfl_code', Auth::user()->facility_id) + ->pluck('count'); }); $client_nonconsented_to_nineteen = Cache::remember('client-nonconsented-to-nineteen', 10, function () { return Client::select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 15) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 19)) then `tbl_client`.`id` end)) AS count")) - ->where('smsenable', '!=', 'Yes') - ->where('status', '=', 'Active') - ->whereNull('hei_no') - ->where('mfl_code', Auth::user()->facility_id) - ->pluck('count'); + ->where('smsenable', '!=', 'Yes') + ->where('status', '=', 'Active') + ->whereNull('hei_no') + ->where('mfl_code', Auth::user()->facility_id) + ->pluck('count'); }); $client_nonconsented_to_twentyfour = Cache::remember('client-nonconsented-to-twentyfour', 10, function () { return Client::select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 20) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 24)) then `tbl_client`.`id` end)) AS count")) - ->where('smsenable', '!=', 'Yes') - ->where('status', '=', 'Active') - ->whereNull('hei_no') - ->where('mfl_code', Auth::user()->facility_id) - ->pluck('count'); + ->where('smsenable', '!=', 'Yes') + ->where('status', '=', 'Active') + ->whereNull('hei_no') + ->where('mfl_code', Auth::user()->facility_id) + ->pluck('count'); }); $client_nonconsented_to_twentyfive_above = Cache::remember('client-nonconsented-to-twentyfive-above', 10, function () { return Client::select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 25)) then `tbl_client`.`id` end)) AS count")) - ->where('smsenable', '!=', 'Yes') - ->where('status', '=', 'Active') - ->whereNull('hei_no') - ->where('mfl_code', Auth::user()->facility_id) - ->pluck('count'); + ->where('smsenable', '!=', 'Yes') + ->where('status', '=', 'Active') + ->whereNull('hei_no') + ->where('mfl_code', Auth::user()->facility_id) + ->pluck('count'); }); $client_nonconsented_uknown_age = Cache::remember('client-nonconsented-uknown-age', 10, function () { return Client::select('smsenable') - ->where('status', '=', 'Active') - ->whereNull('hei_no') - ->where('dob', '=', '') - ->orWhereNull('dob') - ->where('smsenable', '!=', 'Yes') - ->where('mfl_code', Auth::user()->facility_id) - ->count(); + ->where('status', '=', 'Active') + ->whereNull('hei_no') + ->where('dob', '=', '') + ->orWhereNull('dob') + ->where('smsenable', '!=', 'Yes') + ->where('mfl_code', Auth::user()->facility_id) + ->count(); }); - } if (Auth::user()->access_level == 'Partner') { $all_partners = Partner::where('status', '=', 'Active')->pluck('name', 'id'); $client = Client::join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') - ->where('tbl_client.status', '=', 'Active') + ->where('tbl_client.status', '=', 'Active') ->whereNull('tbl_client.hei_no') ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) ->count('tbl_client.clinic_number'); @@ -636,194 +635,193 @@ public function client_dashboard() // client charts $client_consented = Cache::remember('client-consented', 10, function () { return Client::join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') - ->select('tbl_clientsmsenable') - ->where('tbl_client.status', '=', 'Active') - ->whereNull('tbl_client.hei_no') - ->where('tbl_client.smsenable', '=', 'Yes') - ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) - ->count(); + ->select('tbl_clientsmsenable') + ->where('tbl_client.status', '=', 'Active') + ->whereNull('tbl_client.hei_no') + ->where('tbl_client.smsenable', '=', 'Yes') + ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) + ->count(); }); $client_nonconsented = Cache::remember('client-nonconsented', 10, function () { return Client::join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') - ->select('smsenable') - ->where('tbl_client.status', '=', 'Active') - ->whereNull('tbl_client.hei_no') - ->where('tbl_client.smsenable', '!=', 'Yes') - ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) - ->count(); + ->select('smsenable') + ->where('tbl_client.status', '=', 'Active') + ->whereNull('tbl_client.hei_no') + ->where('tbl_client.smsenable', '!=', 'Yes') + ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) + ->count(); }); // consented clients by gender $client_consented_male = Cache::remember('client-consented-male', 10, function () { return Client::join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') - ->where('tbl_client.smsenable', '=', 'Yes') - ->where('tbl_client.status', '=', 'Active') - ->whereNull('tbl_client.hei_no') - ->where('tbl_client.gender', '=', '2') - ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) - ->count(); + ->where('tbl_client.smsenable', '=', 'Yes') + ->where('tbl_client.status', '=', 'Active') + ->whereNull('tbl_client.hei_no') + ->where('tbl_client.gender', '=', '2') + ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) + ->count(); }); $client_consented_female = Cache::remember('client-consented-female', 10, function () { return Client::join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') - ->where('tbl_client.smsenable', '=', 'Yes') - ->where('tbl_client.status', '=', 'Active') - ->whereNull('tbl_client.hei_no') - ->where('tbl_client.gender', '=', '1') - ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) - ->count(); + ->where('tbl_client.smsenable', '=', 'Yes') + ->where('tbl_client.status', '=', 'Active') + ->whereNull('tbl_client.hei_no') + ->where('tbl_client.gender', '=', '1') + ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) + ->count(); }); $client_consented_uknown_gender = Cache::remember('client-consented-uknown-gender', 10, function () { return Client::join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') - ->where('tbl_client.smsenable', '=', 'Yes') - ->where('tbl_client.status', '=', 'Active') - ->whereNull('tbl_client.hei_no') - ->where('tbl_client.gender', '!=', '1') - ->where('tbl_client.gender', '!=', '2') - ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) - ->count(); + ->where('tbl_client.smsenable', '=', 'Yes') + ->where('tbl_client.status', '=', 'Active') + ->whereNull('tbl_client.hei_no') + ->where('tbl_client.gender', '!=', '1') + ->where('tbl_client.gender', '!=', '2') + ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) + ->count(); }); // non consented clients by gender $client_nonconsented_male = Cache::remember('client-nonconsented-male', 10, function () { - return Client::join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') - ->where('tbl_client.smsenable', '!=', 'Yes') - ->where('tbl_client.status', '=', 'Active') - ->whereNull('tbl_client.hei_no') - ->where('tbl_client.gender', '=', '2') - ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) - ->count(); + return Client::join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->where('tbl_client.smsenable', '!=', 'Yes') + ->where('tbl_client.status', '=', 'Active') + ->whereNull('tbl_client.hei_no') + ->where('tbl_client.gender', '=', '2') + ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) + ->count(); }); $client_nonconsented_female = Cache::remember('client-nonconsented-female', 10, function () { return Client::join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') - ->where('tbl_client.smsenable', '!=', 'Yes') - ->where('tbl_client.status', '=', 'Active') - ->whereNull('tbl_client.hei_no') - ->where('tbl_client.gender', '=', '1') - ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) - ->count(); + ->where('tbl_client.smsenable', '!=', 'Yes') + ->where('tbl_client.status', '=', 'Active') + ->whereNull('tbl_client.hei_no') + ->where('tbl_client.gender', '=', '1') + ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) + ->count(); }); $client_nonconsented_uknown_gender = Cache::remember('client-nonconsented-uknown-gender', 10, function () { return Client::join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') - ->where('tbl_client.smsenable', '!=', 'Yes') - ->where('tbl_client.gender', '!=', '1') - ->where('tbl_client.gender', '!=', '2') - ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) - ->count(); + ->where('tbl_client.smsenable', '!=', 'Yes') + ->where('tbl_client.gender', '!=', '1') + ->where('tbl_client.gender', '!=', '2') + ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) + ->count(); }); // consented clients by age distribution $client_consented_to_nine = Cache::remember('client-consented-to-nine', 10, function () { return Client::join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') - ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) > 0) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 9)) then `tbl_client`.`id` end)) AS count")) - ->where('tbl_client.smsenable', '=', 'Yes') - ->where('tbl_client.status', '=', 'Active') - ->whereNull('tbl_client.hei_no') - ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) - ->pluck('count'); + ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) > 0) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 9)) then `tbl_client`.`id` end)) AS count")) + ->where('tbl_client.smsenable', '=', 'Yes') + ->where('tbl_client.status', '=', 'Active') + ->whereNull('tbl_client.hei_no') + ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) + ->pluck('count'); }); $client_consented_to_fourteen = Cache::remember('tbl-client', 10, function () { return Client::join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') - ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 10) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 14)) then `tbl_client`.`id` end)) AS count")) - ->where('tbl_client.smsenable', '=', 'Yes') - ->where('tbl_client.status', '=', 'Active') - ->whereNull('tbl_client.hei_no') - ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) - ->pluck('count'); + ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 10) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 14)) then `tbl_client`.`id` end)) AS count")) + ->where('tbl_client.smsenable', '=', 'Yes') + ->where('tbl_client.status', '=', 'Active') + ->whereNull('tbl_client.hei_no') + ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) + ->pluck('count'); }); $client_consented_to_nineteen = Cache::remember('client-consented-to-nineteen', 10, function () { return Client::join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') - ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 15) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 19)) then `tbl_client`.`id` end)) AS count")) - ->where('tbl_client.smsenable', '=', 'Yes') - ->where('tbl_client.status', '=', 'Active') - ->whereNull('tbl_client.hei_no') - ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) - ->pluck('count'); + ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 15) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 19)) then `tbl_client`.`id` end)) AS count")) + ->where('tbl_client.smsenable', '=', 'Yes') + ->where('tbl_client.status', '=', 'Active') + ->whereNull('tbl_client.hei_no') + ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) + ->pluck('count'); }); $client_consented_to_twentyfour = Cache::remember('client-consented-to-twentyfour', 10, function () { return Client::join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') - ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 20) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 24)) then `tbl_client`.`id` end)) AS count")) - ->where('tbl_client.smsenable', '=', 'Yes') - ->where('tbl_client.status', '=', 'Active') - ->whereNull('tbl_client.hei_no') - ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) - ->pluck('count'); + ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 20) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 24)) then `tbl_client`.`id` end)) AS count")) + ->where('tbl_client.smsenable', '=', 'Yes') + ->where('tbl_client.status', '=', 'Active') + ->whereNull('tbl_client.hei_no') + ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) + ->pluck('count'); }); $client_consented_to_twentyfive_above = Cache::remember('client-consented-to-twentyfive-above', 10, function () { return Client::join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') - ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 25)) then `tbl_client`.`id` end)) AS count")) - ->where('tbl_client.smsenable', '=', 'Yes') - ->where('tbl_client.status', '=', 'Active') - ->whereNull('tbl_client.hei_no') - ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) - ->pluck('count'); + ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 25)) then `tbl_client`.`id` end)) AS count")) + ->where('tbl_client.smsenable', '=', 'Yes') + ->where('tbl_client.status', '=', 'Active') + ->whereNull('tbl_client.hei_no') + ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) + ->pluck('count'); }); $client_consented_uknown_age = Cache::remember('client-consented-uknown-age', 10, function () { return Client::join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') - ->select('tbl_client.smsenable') - ->where('tbl_client.dob', '=', '') - ->where('tbl_client.status', '=', 'Active') - ->whereNull('tbl_client.hei_no') - ->orWhereNull('tbl_client.dob') - ->where('tbl_client.smsenable', '=', 'Yes') - ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) - ->count(); + ->select('tbl_client.smsenable') + ->where('tbl_client.dob', '=', '') + ->where('tbl_client.status', '=', 'Active') + ->whereNull('tbl_client.hei_no') + ->orWhereNull('tbl_client.dob') + ->where('tbl_client.smsenable', '=', 'Yes') + ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) + ->count(); }); // non consented clients by age distribution $client_nonconsented_to_nine = Cache::remember('client-nonconsented-to-nine', 10, function () { - return Client::join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') - ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) > 0) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 9)) then `tbl_client`.`id` end)) AS count")) - ->where('tbl_client.smsenable', '!=', 'Yes') - ->where('tbl_client.status', '=', 'Active') - ->whereNull('tbl_client.hei_no') - ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) - ->pluck('count'); + return Client::join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) > 0) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 9)) then `tbl_client`.`id` end)) AS count")) + ->where('tbl_client.smsenable', '!=', 'Yes') + ->where('tbl_client.status', '=', 'Active') + ->whereNull('tbl_client.hei_no') + ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) + ->pluck('count'); }); $client_nonconsented_to_fourteen = Cache::remember('client-nonconsented-to-fourteen', 10, function () { return Client::join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') - ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 10) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 14)) then `tbl_client`.`id` end)) AS count")) - ->where('tbl_client.smsenable', '!=', 'Yes') - ->where('tbl_client.status', '=', 'Active') - ->whereNull('tbl_client.hei_no') - ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) - ->pluck('count'); + ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 10) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 14)) then `tbl_client`.`id` end)) AS count")) + ->where('tbl_client.smsenable', '!=', 'Yes') + ->where('tbl_client.status', '=', 'Active') + ->whereNull('tbl_client.hei_no') + ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) + ->pluck('count'); }); $client_nonconsented_to_nineteen = Cache::remember('client-nonconsented-to-nineteen', 10, function () { return Client::join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') - ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 15) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 19)) then `tbl_client`.`id` end)) AS count")) - ->where('tbl_client.smsenable', '!=', 'Yes') - ->where('tbl_client.status', '=', 'Active') - ->whereNull('tbl_client.hei_no') - ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) - ->pluck('count'); + ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 15) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 19)) then `tbl_client`.`id` end)) AS count")) + ->where('tbl_client.smsenable', '!=', 'Yes') + ->where('tbl_client.status', '=', 'Active') + ->whereNull('tbl_client.hei_no') + ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) + ->pluck('count'); }); $client_nonconsented_to_twentyfour = Cache::remember('client-nonconsented-to-twentyfour', 10, function () { return Client::join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') - ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 20) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 24)) then `tbl_client`.`id` end)) AS count")) - ->where('tbl_client.smsenable', '!=', 'Yes') - ->where('tbl_client.status', '=', 'Active') - ->whereNull('tbl_client.hei_no') - ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) - ->pluck('count'); + ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 20) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 24)) then `tbl_client`.`id` end)) AS count")) + ->where('tbl_client.smsenable', '!=', 'Yes') + ->where('tbl_client.status', '=', 'Active') + ->whereNull('tbl_client.hei_no') + ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) + ->pluck('count'); }); $client_nonconsented_to_twentyfive_above = Cache::remember('client-nonconsented-to-twentyfive-above', 10, function () { return Client::join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') - ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 25)) then `tbl_client`.`id` end)) AS count")) - ->where('tbl_client.smsenable', '!=', 'Yes') - ->where('tbl_client.status', '=', 'Active') - ->whereNull('tbl_client.hei_no') - ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) - ->pluck('count'); + ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 25)) then `tbl_client`.`id` end)) AS count")) + ->where('tbl_client.smsenable', '!=', 'Yes') + ->where('tbl_client.status', '=', 'Active') + ->whereNull('tbl_client.hei_no') + ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) + ->pluck('count'); }); $client_nonconsented_uknown_age = Cache::remember('client-nonconsented-uknown-age', 10, function () { return Client::join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') - ->select('tbl_client.smsenable') - ->where('tbl_client.status', '=', 'Active') - ->whereNull('tbl_client.hei_no') - ->where('tbl_client.dob', '=', '') - ->orWhereNull('tbl_client.dob') - ->where('tbl_client.smsenable', '!=', 'Yes') - ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) - ->count(); + ->select('tbl_client.smsenable') + ->where('tbl_client.status', '=', 'Active') + ->whereNull('tbl_client.hei_no') + ->where('tbl_client.dob', '=', '') + ->orWhereNull('tbl_client.dob') + ->where('tbl_client.smsenable', '!=', 'Yes') + ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) + ->count(); }); - } if (Auth::user()->access_level == 'Admin' || Auth::user()->access_level == 'Donor') { @@ -834,155 +832,153 @@ public function client_dashboard() // client charts $client_consented = Cache::remember('client-consented', 10, function () { return Client::select('smsenable') - ->where('status', '=', 'Active') - ->whereNull('hei_no') - ->where('smsenable', '=', 'Yes') - ->count(); + ->where('status', '=', 'Active') + ->whereNull('hei_no') + ->where('smsenable', '=', 'Yes') + ->count(); }); $client_nonconsented = Cache::remember('client-nonconsented', 10, function () { return Client::select('smsenable') - ->where('status', '=', 'Active') - ->whereNull('hei_no') - ->where('smsenable', '!=', 'Yes') - ->count(); + ->where('status', '=', 'Active') + ->whereNull('hei_no') + ->where('smsenable', '!=', 'Yes') + ->count(); }); // consented clients by gender $client_consented_male = Cache::remember('client-consented-male', 10, function () { return Client::where('smsenable', '=', 'Yes') - ->where('status', '=', 'Active') - ->whereNull('hei_no') - ->where('gender', '=', '2') - ->count(); + ->where('status', '=', 'Active') + ->whereNull('hei_no') + ->where('gender', '=', '2') + ->count(); }); $client_consented_female = Cache::remember('client-consented-female', 10, function () { return Client::where('smsenable', '=', 'Yes') - ->where('status', '=', 'Active') - ->whereNull('hei_no') - ->where('gender', '=', '1') - ->count(); + ->where('status', '=', 'Active') + ->whereNull('hei_no') + ->where('gender', '=', '1') + ->count(); }); $client_consented_uknown_gender = Cache::remember('client-consented-uknown-gender', 10, function () { return Client::where('smsenable', '=', 'Yes') - ->where('status', '=', 'Active') - ->whereNull('hei_no') - ->where('gender', '!=', '1') - ->where('gender', '!=', '2') - ->count(); + ->where('status', '=', 'Active') + ->whereNull('hei_no') + ->where('gender', '!=', '1') + ->where('gender', '!=', '2') + ->count(); }); // non consented clients by gender $client_nonconsented_male = Cache::remember('client-nonconsented-male', 10, function () { - return Client::where('smsenable', '!=', 'Yes') - ->where('status', '=', 'Active') - ->whereNull('hei_no') - ->where('gender', '=', '2') - ->count(); + return Client::where('smsenable', '!=', 'Yes') + ->where('status', '=', 'Active') + ->whereNull('hei_no') + ->where('gender', '=', '2') + ->count(); }); $client_nonconsented_female = Cache::remember('client-nonconsented-female', 10, function () { return Client::where('smsenable', '!=', 'Yes') - ->where('status', '=', 'Active') - ->whereNull('hei_no') - ->where('gender', '=', '1') - ->count(); + ->where('status', '=', 'Active') + ->whereNull('hei_no') + ->where('gender', '=', '1') + ->count(); }); $client_nonconsented_uknown_gender = Cache::remember('client-nonconsented-uknown-gender', 10, function () { return Client::where('smsenable', '!=', 'Yes') - ->where('gender', '!=', '1') - ->where('gender', '!=', '2') - ->count(); + ->where('gender', '!=', '1') + ->where('gender', '!=', '2') + ->count(); }); // consented clients by age distribution $client_consented_to_nine = Cache::remember('client-consented-to-nine', 10, function () { return Client::select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) > 0) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 9)) then `tbl_client`.`id` end)) AS count")) - ->where('smsenable', '=', 'Yes') - ->where('status', '=', 'Active') - ->whereNull('hei_no') - ->pluck('count'); + ->where('smsenable', '=', 'Yes') + ->where('status', '=', 'Active') + ->whereNull('hei_no') + ->pluck('count'); }); $client_consented_to_fourteen = Cache::remember('tbl-client', 10, function () { return Client::select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 10) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 14)) then `tbl_client`.`id` end)) AS count")) - ->where('smsenable', '=', 'Yes') - ->where('status', '=', 'Active') - ->whereNull('hei_no') - ->pluck('count'); + ->where('smsenable', '=', 'Yes') + ->where('status', '=', 'Active') + ->whereNull('hei_no') + ->pluck('count'); }); $client_consented_to_nineteen = Cache::remember('client-consented-to-nineteen', 10, function () { return Client::select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 15) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 19)) then `tbl_client`.`id` end)) AS count")) - ->where('smsenable', '=', 'Yes') - ->where('status', '=', 'Active') - ->whereNull('hei_no') - ->pluck('count'); + ->where('smsenable', '=', 'Yes') + ->where('status', '=', 'Active') + ->whereNull('hei_no') + ->pluck('count'); }); $client_consented_to_twentyfour = Cache::remember('client-consented-to-twentyfour', 10, function () { return Client::select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 20) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 24)) then `tbl_client`.`id` end)) AS count")) - ->where('smsenable', '=', 'Yes') - ->where('status', '=', 'Active') - ->whereNull('hei_no') - ->pluck('count'); + ->where('smsenable', '=', 'Yes') + ->where('status', '=', 'Active') + ->whereNull('hei_no') + ->pluck('count'); }); $client_consented_to_twentyfive_above = Cache::remember('client-consented-to-twentyfive-above', 10, function () { return Client::select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 25)) then `tbl_client`.`id` end)) AS count")) - ->where('smsenable', '=', 'Yes') - ->where('status', '=', 'Active') - ->whereNull('hei_no') - ->pluck('count'); + ->where('smsenable', '=', 'Yes') + ->where('status', '=', 'Active') + ->whereNull('hei_no') + ->pluck('count'); }); $client_consented_uknown_age = Cache::remember('client-consented-uknown-age', 10, function () { return Client::select('smsenable') - ->where('dob', '=', '') - ->where('status', '=', 'Active') - ->whereNull('hei_no') - ->orWhereNull('dob') - ->where('smsenable', '=', 'Yes') - ->count(); + ->where('dob', '=', '') + ->where('status', '=', 'Active') + ->whereNull('hei_no') + ->orWhereNull('dob') + ->where('smsenable', '=', 'Yes') + ->count(); }); // non consented clients by age distribution $client_nonconsented_to_nine = Cache::remember('client-nonconsented-to-nine', 10, function () { - return Client::select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) > 0) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 9)) then `tbl_client`.`id` end)) AS count")) - ->where('smsenable', '!=', 'Yes') - ->where('status', '=', 'Active') - ->whereNull('hei_no') - ->pluck('count'); + return Client::select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) > 0) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 9)) then `tbl_client`.`id` end)) AS count")) + ->where('smsenable', '!=', 'Yes') + ->where('status', '=', 'Active') + ->whereNull('hei_no') + ->pluck('count'); }); $client_nonconsented_to_fourteen = Cache::remember('client-nonconsented-to-fourteen', 10, function () { return Client::select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 10) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 14)) then `tbl_client`.`id` end)) AS count")) - ->where('smsenable', '!=', 'Yes') - ->where('status', '=', 'Active') - ->whereNull('hei_no') - ->pluck('count'); + ->where('smsenable', '!=', 'Yes') + ->where('status', '=', 'Active') + ->whereNull('hei_no') + ->pluck('count'); }); $client_nonconsented_to_nineteen = Cache::remember('client-nonconsented-to-nineteen', 10, function () { return Client::select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 15) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 19)) then `tbl_client`.`id` end)) AS count")) - ->where('smsenable', '!=', 'Yes') - ->where('status', '=', 'Active') - ->whereNull('hei_no') - ->pluck('count'); + ->where('smsenable', '!=', 'Yes') + ->where('status', '=', 'Active') + ->whereNull('hei_no') + ->pluck('count'); }); $client_nonconsented_to_twentyfour = Cache::remember('client-nonconsented-to-twentyfour', 10, function () { return Client::select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 20) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 24)) then `tbl_client`.`id` end)) AS count")) - ->where('smsenable', '!=', 'Yes') - ->where('status', '=', 'Active') - ->whereNull('hei_no') - ->pluck('count'); + ->where('smsenable', '!=', 'Yes') + ->where('status', '=', 'Active') + ->whereNull('hei_no') + ->pluck('count'); }); $client_nonconsented_to_twentyfive_above = Cache::remember('client-nonconsented-to-twentyfive-above', 10, function () { return Client::select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 25)) then `tbl_client`.`id` end)) AS count")) - ->where('smsenable', '!=', 'Yes') - ->where('status', '=', 'Active') - ->whereNull('hei_no') - ->pluck('count'); + ->where('smsenable', '!=', 'Yes') + ->where('status', '=', 'Active') + ->whereNull('hei_no') + ->pluck('count'); }); $client_nonconsented_uknown_age = Cache::remember('client-nonconsented-uknown-age', 10, function () { return Client::select('smsenable') - ->where('status', '=', 'Active') - ->whereNull('hei_no') - ->where('dob', '=', '') - ->orWhereNull('dob') - ->where('smsenable', '!=', 'Yes') - ->count(); + ->where('status', '=', 'Active') + ->whereNull('hei_no') + ->where('dob', '=', '') + ->orWhereNull('dob') + ->where('smsenable', '!=', 'Yes') + ->count(); }); - - } @@ -1021,461 +1017,461 @@ public function appointment_charts() if (Auth::user()->access_level == 'Facility') { $all_partners = Partner::where('status', '=', 'Active')->pluck('name', 'id'); $indicator = Indicator::select(['name', 'description'])->get(); - // main appointments - $appointment = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') - ->select('tbl_appointment.id') - ->where('tbl_client.mfl_code', Auth::user()->facility_id) - ->count(); - $appointment_honoured = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') - ->select('tbl_appointment.id') - ->where('tbl_appointment.date_attended', '=', DB::raw('tbl_appointment.appntmnt_date')) - ->where('tbl_client.mfl_code', Auth::user()->facility_id) - ->count(); - - // dd($appointment_honoured); - $appointment_not_honoured = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + // main appointments + $appointment = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') ->select('tbl_appointment.id') - ->whereIn('tbl_appointment.app_status', ['Defaulted', 'LTFU', 'Missed']) - ->where('tbl_client.mfl_code', Auth::user()->facility_id) - ->count(); + ->where('tbl_client.mfl_code', Auth::user()->facility_id) + ->count(); + $appointment_honoured = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->select('tbl_appointment.id') + ->where('tbl_appointment.date_attended', '=', DB::raw('tbl_appointment.appntmnt_date')) + ->where('tbl_client.mfl_code', Auth::user()->facility_id) + ->count(); - // appointment honored by gender - $appointment_honoured_male = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') - ->select(\DB::raw("COUNT(tbl_appointment.id) as count")) - ->where('tbl_appointment.date_attended', '=', DB::raw('tbl_appointment.appntmnt_date')) - ->where('tbl_client.gender', '=', '2') - ->where('tbl_client.mfl_code', Auth::user()->facility_id) - ->pluck('count'); - $appointment_honoured_female = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') - ->where('tbl_appointment.date_attended', '=', DB::raw('tbl_appointment.appntmnt_date')) - ->where('tbl_client.gender', '=', '1') - ->where('tbl_client.mfl_code', Auth::user()->facility_id) - ->count(); - $appointment_honoured_uknown_gender = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') - ->where('tbl_appointment.date_attended', '=', DB::raw('tbl_appointment.appntmnt_date')) - ->where('tbl_client.gender', '!=', '1') - ->where('tbl_client.gender', '!=', '2') - ->where('tbl_client.mfl_code', Auth::user()->facility_id) - ->count(); - // appointment honored by age - $appointment_honored_to_nine = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') - ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') - ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) > 0) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 9)) then `tbl_client`.`id` end)) AS count")) + // dd($appointment_honoured); + $appointment_not_honoured = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->select('tbl_appointment.id') + ->whereIn('tbl_appointment.app_status', ['Defaulted', 'LTFU', 'Missed']) + ->where('tbl_client.mfl_code', Auth::user()->facility_id) + ->count(); + + // appointment honored by gender + $appointment_honoured_male = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->select(\DB::raw("COUNT(tbl_appointment.id) as count")) + ->where('tbl_appointment.date_attended', '=', DB::raw('tbl_appointment.appntmnt_date')) + ->where('tbl_client.gender', '=', '2') + ->where('tbl_client.mfl_code', Auth::user()->facility_id) + ->pluck('count'); + $appointment_honoured_female = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->where('tbl_appointment.date_attended', '=', DB::raw('tbl_appointment.appntmnt_date')) + ->where('tbl_client.gender', '=', '1') + ->where('tbl_client.mfl_code', Auth::user()->facility_id) + ->count(); + $appointment_honoured_uknown_gender = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->where('tbl_appointment.date_attended', '=', DB::raw('tbl_appointment.appntmnt_date')) + ->where('tbl_client.gender', '!=', '1') + ->where('tbl_client.gender', '!=', '2') + ->where('tbl_client.mfl_code', Auth::user()->facility_id) + ->count(); + // appointment honored by age + $appointment_honored_to_nine = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) > 0) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 9)) then `tbl_client`.`id` end)) AS count")) + ->where('tbl_appointment.date_attended', '=', DB::raw('tbl_appointment.appntmnt_date')) + ->where('tbl_client.mfl_code', Auth::user()->facility_id) + ->pluck('count'); + $appointment_honored_to_fourteen = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 10) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 14)) then `tbl_client`.`id` end)) AS count")) + ->where('tbl_appointment.date_attended', '=', DB::raw('tbl_appointment.appntmnt_date')) + ->where('tbl_client.mfl_code', Auth::user()->facility_id) + ->pluck('count'); + $appointment_honored_to_nineteen = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 15) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 19)) then `tbl_client`.`id` end)) AS count")) + ->where('tbl_appointment.date_attended', '=', DB::raw('tbl_appointment.appntmnt_date')) + ->where('tbl_client.mfl_code', Auth::user()->facility_id) + ->pluck('count'); + + $appointment_honored_to_twentyfour = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 20) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 24)) then `tbl_client`.`id` end)) AS count")) + ->where('tbl_appointment.date_attended', '=', DB::raw('tbl_appointment.appntmnt_date')) + ->where('tbl_client.mfl_code', Auth::user()->facility_id) + ->pluck('count'); + + $appointment_honored_to_twentyfive_above = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 25)) then `tbl_client`.`id` end)) AS count")) + ->where('tbl_appointment.date_attended', '=', DB::raw('tbl_appointment.appntmnt_date')) + ->where('tbl_client.mfl_code', Auth::user()->facility_id) + ->pluck('count'); + + $appointment_honored_to_uknown_age = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->select('tbl_client.dob') + ->where('tbl_appointment.date_attended', '=', DB::raw('tbl_appointment.appntmnt_date')) + ->where('tbl_client.dob', '=', '') + ->orWhereNull('tbl_client.dob') + ->where('tbl_client.mfl_code', Auth::user()->facility_id) + ->count(); + // appointment not honored by gender + $appointment_not_honoured_male = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->where('tbl_client.gender', '=', '2') + ->whereIn('tbl_appointment.app_status', ['Defaulted', 'LTFU', 'Missed']) + ->where('tbl_client.mfl_code', Auth::user()->facility_id) + ->count(); + + $appointment_not_honoured_female = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->where('tbl_client.gender', '=', '1') + ->whereIn('tbl_appointment.app_status', ['Defaulted', 'LTFU', 'Missed']) + ->where('tbl_client.mfl_code', Auth::user()->facility_id) + ->count(); + $appointment_not_honoured_uknown_gender = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->where('tbl_client.gender', '!=', '1') + ->where('tbl_client.gender', '!=', '2') + ->whereIn('tbl_appointment.app_status', ['Defaulted', 'LTFU', 'Missed']) + ->where('tbl_client.mfl_code', Auth::user()->facility_id) + ->count(); + // appointment not honored by age + $appointment_not_honored_to_nine = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) > 0) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 9)) then `tbl_client`.`id` end)) AS count")) + ->whereIn('tbl_appointment.app_status', ['Defaulted', 'LTFU', 'Missed']) + ->where('tbl_client.mfl_code', Auth::user()->facility_id) + ->pluck('count'); + + $appointment_not_honored_to_fourteen = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 10) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 14)) then `tbl_client`.`id` end)) AS count")) + ->whereIn('tbl_appointment.app_status', ['Defaulted', 'LTFU', 'Missed']) + ->where('tbl_client.mfl_code', Auth::user()->facility_id) + ->pluck('count'); + + $appointment_not_honored_to_nineteen = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 15) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 19)) then `tbl_client`.`id` end)) AS count")) + ->whereIn('tbl_appointment.app_status', ['Defaulted', 'LTFU', 'Missed']) + ->where('tbl_client.mfl_code', Auth::user()->facility_id) + ->pluck('count'); + $appointment_not_honored_to_twentyfour = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 20) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 24)) then `tbl_client`.`id` end)) AS count")) + ->whereIn('tbl_appointment.app_status', ['Defaulted', 'LTFU', 'Missed']) + ->where('tbl_client.mfl_code', Auth::user()->facility_id) + ->pluck('count'); + $appointment_not_honored_to_twentyfive_above = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 25)) then `tbl_client`.`id` end)) AS count")) + ->whereIn('tbl_appointment.app_status', ['Defaulted', 'LTFU', 'Missed']) + ->where('tbl_client.mfl_code', Auth::user()->facility_id) + ->pluck('count'); + + $appointment_not_honored_to_uknown_age = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->select('tbl_client.dob') + ->where('tbl_client.dob', '=', '') + ->orWhereNull('tbl_client.dob') + ->whereIn('tbl_appointment.app_status', ['Defaulted', 'LTFU', 'Missed']) + ->where('tbl_client.mfl_code', Auth::user()->facility_id) + ->count(); + } + if (Auth::user()->access_level == 'Partner') { + $all_partners = Partner::where('status', '=', 'Active')->pluck('name', 'id'); + $indicator = Indicator::select(['name', 'description'])->get(); + // main appointments + $appointment = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select('tbl_appointment.id') + ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) + ->count(); + $appointment_honoured = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select('tbl_appointment.id') + ->where('tbl_appointment.date_attended', '=', DB::raw('tbl_appointment.appntmnt_date')) + ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) + ->count(); + + // dd($appointment_honoured); + $appointment_not_honoured = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select('tbl_appointment.id') + ->whereIn('tbl_appointment.app_status', ['Defaulted', 'LTFU', 'Missed']) + ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) + ->count(); + + // appointment honored by gender + $appointment_honoured_male = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select(\DB::raw("COUNT(tbl_appointment.id) as count")) + ->where('tbl_appointment.date_attended', '=', DB::raw('tbl_appointment.appntmnt_date')) + ->where('tbl_client.gender', '=', '2') + ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) + ->pluck('count'); + $appointment_honoured_female = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->where('tbl_appointment.date_attended', '=', DB::raw('tbl_appointment.appntmnt_date')) + ->where('tbl_client.gender', '=', '1') + ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) + ->count(); + $appointment_honoured_uknown_gender = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->where('tbl_appointment.date_attended', '=', DB::raw('tbl_appointment.appntmnt_date')) + ->where('tbl_client.gender', '!=', '1') + ->where('tbl_client.gender', '!=', '2') + ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) + ->count(); + // appointment honored by age + $appointment_honored_to_nine = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) > 0) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 9)) then `tbl_client`.`id` end)) AS count")) + ->where('tbl_appointment.date_attended', '=', DB::raw('tbl_appointment.appntmnt_date')) + ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) + ->pluck('count'); + $appointment_honored_to_fourteen = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 10) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 14)) then `tbl_client`.`id` end)) AS count")) + ->where('tbl_appointment.date_attended', '=', DB::raw('tbl_appointment.appntmnt_date')) + ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) + ->pluck('count'); + $appointment_honored_to_nineteen = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 15) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 19)) then `tbl_client`.`id` end)) AS count")) + ->where('tbl_appointment.date_attended', '=', DB::raw('tbl_appointment.appntmnt_date')) + ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) + ->pluck('count'); + + $appointment_honored_to_twentyfour = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 20) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 24)) then `tbl_client`.`id` end)) AS count")) + ->where('tbl_appointment.date_attended', '=', DB::raw('tbl_appointment.appntmnt_date')) + ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) + ->pluck('count'); + + $appointment_honored_to_twentyfive_above = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 25)) then `tbl_client`.`id` end)) AS count")) + ->where('tbl_appointment.date_attended', '=', DB::raw('tbl_appointment.appntmnt_date')) + ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) + ->pluck('count'); + + $appointment_honored_to_uknown_age = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select('tbl_client.dob') + ->where('tbl_appointment.date_attended', '=', DB::raw('tbl_appointment.appntmnt_date')) + ->where('tbl_client.dob', '=', '') + ->orWhereNull('tbl_client.dob') + ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) + ->count(); + // appointment not honored by gender + $appointment_not_honoured_male = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->where('tbl_client.gender', '=', '2') + ->whereIn('tbl_appointment.app_status', ['Defaulted', 'LTFU', 'Missed']) + ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) + ->count(); + + $appointment_not_honoured_female = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->where('tbl_client.gender', '=', '1') + ->whereIn('tbl_appointment.app_status', ['Defaulted', 'LTFU', 'Missed']) + ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) + ->count(); + $appointment_not_honoured_uknown_gender = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->where('tbl_client.gender', '!=', '1') + ->where('tbl_client.gender', '!=', '2') + ->whereIn('tbl_appointment.app_status', ['Defaulted', 'LTFU', 'Missed']) + ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) + ->count(); + // appointment not honored by age + $appointment_not_honored_to_nine = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) > 0) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 9)) then `tbl_client`.`id` end)) AS count")) + ->whereIn('tbl_appointment.app_status', ['Defaulted', 'LTFU', 'Missed']) + ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) + ->pluck('count'); + + $appointment_not_honored_to_fourteen = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 10) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 14)) then `tbl_client`.`id` end)) AS count")) + ->whereIn('tbl_appointment.app_status', ['Defaulted', 'LTFU', 'Missed']) + ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) + ->pluck('count'); + + $appointment_not_honored_to_nineteen = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 15) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 19)) then `tbl_client`.`id` end)) AS count")) + ->whereIn('tbl_appointment.app_status', ['Defaulted', 'LTFU', 'Missed']) + ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) + ->pluck('count'); + $appointment_not_honored_to_twentyfour = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 20) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 24)) then `tbl_client`.`id` end)) AS count")) + ->whereIn('tbl_appointment.app_status', ['Defaulted', 'LTFU', 'Missed']) + ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) + ->pluck('count'); + $appointment_not_honored_to_twentyfive_above = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 25)) then `tbl_client`.`id` end)) AS count")) + ->whereIn('tbl_appointment.app_status', ['Defaulted', 'LTFU', 'Missed']) + ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) + ->pluck('count'); + + $appointment_not_honored_to_uknown_age = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select('tbl_client.dob') + ->where('tbl_client.dob', '=', '') + ->orWhereNull('tbl_client.dob') + ->whereIn('tbl_appointment.app_status', ['Defaulted', 'LTFU', 'Missed']) + ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) + ->count(); + } + + if (Auth::user()->access_level == 'Admin' || Auth::user()->access_level == 'Donor') { + $all_partners = Partner::where('status', '=', 'Active')->pluck('name', 'id'); + $indicator = Indicator::select(['name', 'description'])->get(); + // main appointments + $appointment = Appointments::select('id') + ->count(); + $appointment_honoured = Appointments::select('id') + ->where('date_attended', '=', DB::raw('appntmnt_date')) + ->count(); + // dd($appointment_honoured); + $appointment_not_honoured = Appointments::select('id') + ->whereIn('app_status', ['Defaulted', 'LTFU', 'Missed']) + ->count(); + + // appointment honored by gender + $appointment_honoured_male = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->select('tbl_appointment.id') + ->where('tbl_appointment.date_attended', '=', DB::raw('tbl_appointment.appntmnt_date')) + ->where('tbl_client.gender', '=', '2') + ->count(); + $appointment_honoured_female = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->where('tbl_appointment.date_attended', '=', DB::raw('tbl_appointment.appntmnt_date')) + ->where('tbl_client.gender', '=', '1') + ->count(); + $appointment_honoured_uknown_gender = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->where('tbl_appointment.date_attended', '=', DB::raw('tbl_appointment.appntmnt_date')) + ->where('tbl_client.gender', '!=', '1') + ->where('tbl_client.gender', '!=', '2') + ->count(); + // appointment honored by age + $appointment_honored_to_nine = Cache::remember('appointment-honored-to-nine', 10, function () { + return Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) > 0) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 9)) then `tbl_client`.`id` end)) AS count")) ->where('tbl_appointment.date_attended', '=', DB::raw('tbl_appointment.appntmnt_date')) - ->where('tbl_client.mfl_code', Auth::user()->facility_id) ->pluck('count'); - $appointment_honored_to_fourteen = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + }); + $appointment_honored_to_fourteen = Cache::remember('appointment-honored-to-fourteen', 10, function () { + return Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 10) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 14)) then `tbl_client`.`id` end)) AS count")) ->where('tbl_appointment.date_attended', '=', DB::raw('tbl_appointment.appntmnt_date')) - ->where('tbl_client.mfl_code', Auth::user()->facility_id) ->pluck('count'); - $appointment_honored_to_nineteen = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + }); + $appointment_honored_to_nineteen = Cache::remember('appointment-honored-to-nineteen', 10, function () { + return Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 15) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 19)) then `tbl_client`.`id` end)) AS count")) ->where('tbl_appointment.date_attended', '=', DB::raw('tbl_appointment.appntmnt_date')) - ->where('tbl_client.mfl_code', Auth::user()->facility_id) ->pluck('count'); - - $appointment_honored_to_twentyfour = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + }); + $appointment_honored_to_twentyfour = Cache::remember('appointment-honored-to-twentyfour', 10, function () { + return Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 20) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 24)) then `tbl_client`.`id` end)) AS count")) ->where('tbl_appointment.date_attended', '=', DB::raw('tbl_appointment.appntmnt_date')) - ->where('tbl_client.mfl_code', Auth::user()->facility_id) ->pluck('count'); - - $appointment_honored_to_twentyfive_above = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + }); + $appointment_honored_to_twentyfive_above = Cache::remember('appointment-honored-to-twentyfive_above', 10, function () { + return Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 25)) then `tbl_client`.`id` end)) AS count")) ->where('tbl_appointment.date_attended', '=', DB::raw('tbl_appointment.appntmnt_date')) - ->where('tbl_client.mfl_code', Auth::user()->facility_id) ->pluck('count'); - - $appointment_honored_to_uknown_age = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + }); + $appointment_honored_to_uknown_age = Cache::remember('appointment_honored-to-uknown-age', 10, function () { + return Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') ->select('tbl_client.dob') ->where('tbl_appointment.date_attended', '=', DB::raw('tbl_appointment.appntmnt_date')) ->where('tbl_client.dob', '=', '') ->orWhereNull('tbl_client.dob') - ->where('tbl_client.mfl_code', Auth::user()->facility_id) ->count(); - // appointment not honored by gender - $appointment_not_honoured_male = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + }); + + // appointment not honored by gender + $appointment_not_honoured_male = Cache::remember('appointment-not-honoured-male', 10, function () { + return Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') ->where('tbl_client.gender', '=', '2') - ->whereIn('tbl_appointment.app_status', ['Defaulted', 'LTFU', 'Missed']) - ->where('tbl_client.mfl_code', Auth::user()->facility_id) + ->whereIn('app_status', ['Defaulted', 'LTFU', 'Missed']) ->count(); - - $appointment_not_honoured_female = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + }); + $appointment_not_honoured_female = Cache::remember('appointment-not-honoured-female', 10, function () { + return Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') ->where('tbl_client.gender', '=', '1') - ->whereIn('tbl_appointment.app_status', ['Defaulted', 'LTFU', 'Missed']) - ->where('tbl_client.mfl_code', Auth::user()->facility_id) + ->whereIn('app_status', ['Defaulted', 'LTFU', 'Missed']) ->count(); - $appointment_not_honoured_uknown_gender = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + }); + $appointment_not_honoured_uknown_gender = Cache::remember('appointment-not-honoured-uknown-gender', 10, function () { + return Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') ->where('tbl_client.gender', '!=', '1') ->where('tbl_client.gender', '!=', '2') - ->whereIn('tbl_appointment.app_status', ['Defaulted', 'LTFU', 'Missed']) - ->where('tbl_client.mfl_code', Auth::user()->facility_id) + ->whereIn('app_status', ['Defaulted', 'LTFU', 'Missed']) ->count(); - // appointment not honored by age - $appointment_not_honored_to_nine = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + }); + // appointment not honored by age + $appointment_not_honored_to_nine = Cache::remember('appointment-not-honored-to-nine', 10, function () { + return Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) > 0) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 9)) then `tbl_client`.`id` end)) AS count")) - ->whereIn('tbl_appointment.app_status', ['Defaulted', 'LTFU', 'Missed']) - ->where('tbl_client.mfl_code', Auth::user()->facility_id) + ->whereIn('app_status', ['Defaulted', 'LTFU', 'Missed']) ->pluck('count'); - - $appointment_not_honored_to_fourteen = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + }); + $appointment_not_honored_to_fourteen = Cache::remember('appointment-not-honored-to-fourteen', 10, function () { + return Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 10) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 14)) then `tbl_client`.`id` end)) AS count")) - ->whereIn('tbl_appointment.app_status', ['Defaulted', 'LTFU', 'Missed']) - ->where('tbl_client.mfl_code', Auth::user()->facility_id) + ->whereIn('app_status', ['Defaulted', 'LTFU', 'Missed']) ->pluck('count'); - - $appointment_not_honored_to_nineteen = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + }); + $appointment_not_honored_to_nineteen = Cache::remember('appointment_not_honored_to_nineteen', 10, function () { + return Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 15) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 19)) then `tbl_client`.`id` end)) AS count")) - ->whereIn('tbl_appointment.app_status', ['Defaulted', 'LTFU', 'Missed']) - ->where('tbl_client.mfl_code', Auth::user()->facility_id) + ->whereIn('app_status', ['Defaulted', 'LTFU', 'Missed']) ->pluck('count'); - $appointment_not_honored_to_twentyfour = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') - ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') - ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 20) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 24)) then `tbl_client`.`id` end)) AS count")) - ->whereIn('tbl_appointment.app_status', ['Defaulted', 'LTFU', 'Missed']) - ->where('tbl_client.mfl_code', Auth::user()->facility_id) - ->pluck('count'); - $appointment_not_honored_to_twentyfive_above = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') - ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') - ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 25)) then `tbl_client`.`id` end)) AS count")) - ->whereIn('tbl_appointment.app_status', ['Defaulted', 'LTFU', 'Missed']) - ->where('tbl_client.mfl_code', Auth::user()->facility_id) - ->pluck('count'); - - $appointment_not_honored_to_uknown_age = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') - ->select('tbl_client.dob') - ->where('tbl_client.dob', '=', '') - ->orWhereNull('tbl_client.dob') - ->whereIn('tbl_appointment.app_status', ['Defaulted', 'LTFU', 'Missed']) - ->where('tbl_client.mfl_code', Auth::user()->facility_id) - ->count(); - - } - if (Auth::user()->access_level == 'Partner') { - $all_partners = Partner::where('status', '=', 'Active')->pluck('name', 'id'); - $indicator = Indicator::select(['name', 'description'])->get(); - // main appointments - $appointment = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') - ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') - ->select('tbl_appointment.id') - ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) - ->count(); - $appointment_honoured = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') - ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') - ->select('tbl_appointment.id') - ->where('tbl_appointment.date_attended', '=', DB::raw('tbl_appointment.appntmnt_date')) - ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) - ->count(); - - // dd($appointment_honoured); - $appointment_not_honoured = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') - ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') - ->select('tbl_appointment.id') - ->whereIn('tbl_appointment.app_status', ['Defaulted', 'LTFU', 'Missed']) - ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) - ->count(); - - // appointment honored by gender - $appointment_honoured_male = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') - ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') - ->select(\DB::raw("COUNT(tbl_appointment.id) as count")) - ->where('tbl_appointment.date_attended', '=', DB::raw('tbl_appointment.appntmnt_date')) - ->where('tbl_client.gender', '=', '2') - ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) - ->pluck('count'); - $appointment_honoured_female = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') - ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') - ->where('tbl_appointment.date_attended', '=', DB::raw('tbl_appointment.appntmnt_date')) - ->where('tbl_client.gender', '=', '1') - ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) - ->count(); - $appointment_honoured_uknown_gender = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') - ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') - ->where('tbl_appointment.date_attended', '=', DB::raw('tbl_appointment.appntmnt_date')) - ->where('tbl_client.gender', '!=', '1') - ->where('tbl_client.gender', '!=', '2') - ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) - ->count(); - // appointment honored by age - $appointment_honored_to_nine = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') - ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') - ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) > 0) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 9)) then `tbl_client`.`id` end)) AS count")) - ->where('tbl_appointment.date_attended', '=', DB::raw('tbl_appointment.appntmnt_date')) - ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) - ->pluck('count'); - $appointment_honored_to_fourteen = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') - ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') - ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 10) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 14)) then `tbl_client`.`id` end)) AS count")) - ->where('tbl_appointment.date_attended', '=', DB::raw('tbl_appointment.appntmnt_date')) - ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) - ->pluck('count'); - $appointment_honored_to_nineteen = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') - ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') - ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 15) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 19)) then `tbl_client`.`id` end)) AS count")) - ->where('tbl_appointment.date_attended', '=', DB::raw('tbl_appointment.appntmnt_date')) - ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) - ->pluck('count'); - - $appointment_honored_to_twentyfour = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') - ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') - ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 20) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 24)) then `tbl_client`.`id` end)) AS count")) - ->where('tbl_appointment.date_attended', '=', DB::raw('tbl_appointment.appntmnt_date')) - ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) - ->pluck('count'); - - $appointment_honored_to_twentyfive_above = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') - ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') - ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 25)) then `tbl_client`.`id` end)) AS count")) - ->where('tbl_appointment.date_attended', '=', DB::raw('tbl_appointment.appntmnt_date')) - ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) - ->pluck('count'); - - $appointment_honored_to_uknown_age = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') - ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') - ->select('tbl_client.dob') - ->where('tbl_appointment.date_attended', '=', DB::raw('tbl_appointment.appntmnt_date')) - ->where('tbl_client.dob', '=', '') - ->orWhereNull('tbl_client.dob') - ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) - ->count(); - // appointment not honored by gender - $appointment_not_honoured_male = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') - ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') - ->where('tbl_client.gender', '=', '2') - ->whereIn('tbl_appointment.app_status', ['Defaulted', 'LTFU', 'Missed']) - ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) - ->count(); - - $appointment_not_honoured_female = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') - ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') - ->where('tbl_client.gender', '=', '1') - ->whereIn('tbl_appointment.app_status', ['Defaulted', 'LTFU', 'Missed']) - ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) - ->count(); - $appointment_not_honoured_uknown_gender = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') - ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') - ->where('tbl_client.gender', '!=', '1') - ->where('tbl_client.gender', '!=', '2') - ->whereIn('tbl_appointment.app_status', ['Defaulted', 'LTFU', 'Missed']) - ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) - ->count(); - // appointment not honored by age - $appointment_not_honored_to_nine = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') - ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') - ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) > 0) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 9)) then `tbl_client`.`id` end)) AS count")) - ->whereIn('tbl_appointment.app_status', ['Defaulted', 'LTFU', 'Missed']) - ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) - ->pluck('count'); - - $appointment_not_honored_to_fourteen = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') - ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') - ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 10) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 14)) then `tbl_client`.`id` end)) AS count")) - ->whereIn('tbl_appointment.app_status', ['Defaulted', 'LTFU', 'Missed']) - ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) - ->pluck('count'); - - $appointment_not_honored_to_nineteen = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') - ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') - ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 15) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 19)) then `tbl_client`.`id` end)) AS count")) - ->whereIn('tbl_appointment.app_status', ['Defaulted', 'LTFU', 'Missed']) - ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) - ->pluck('count'); - $appointment_not_honored_to_twentyfour = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') - ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') - ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 20) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 24)) then `tbl_client`.`id` end)) AS count")) - ->whereIn('tbl_appointment.app_status', ['Defaulted', 'LTFU', 'Missed']) - ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) - ->pluck('count'); - $appointment_not_honored_to_twentyfive_above = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') - ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') - ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 25)) then `tbl_client`.`id` end)) AS count")) - ->whereIn('tbl_appointment.app_status', ['Defaulted', 'LTFU', 'Missed']) - ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) - ->pluck('count'); - - $appointment_not_honored_to_uknown_age = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') - ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') - ->select('tbl_client.dob') - ->where('tbl_client.dob', '=', '') - ->orWhereNull('tbl_client.dob') - ->whereIn('tbl_appointment.app_status', ['Defaulted', 'LTFU', 'Missed']) - ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) - ->count(); - - - } - - if (Auth::user()->access_level == 'Admin' || Auth::user()->access_level == 'Donor') { - $all_partners = Partner::where('status', '=', 'Active')->pluck('name', 'id'); - $indicator = Indicator::select(['name', 'description'])->get(); - // main appointments - $appointment = Appointments::select('id') - ->count(); - $appointment_honoured = Appointments::select('id') - ->where('date_attended', '=', DB::raw('appntmnt_date')) - ->count(); - // dd($appointment_honoured); - $appointment_not_honoured = Appointments::select('id') - ->whereIn('app_status', ['Defaulted', 'LTFU', 'Missed']) - ->count(); - - // appointment honored by gender - $appointment_honoured_male = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') - ->select('tbl_appointment.id') - ->where('tbl_appointment.date_attended', '=', DB::raw('tbl_appointment.appntmnt_date')) - ->where('tbl_client.gender', '=', '2') - ->count(); - $appointment_honoured_female = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') - ->where('tbl_appointment.date_attended', '=', DB::raw('tbl_appointment.appntmnt_date')) - ->where('tbl_client.gender', '=', '1') - ->count(); - $appointment_honoured_uknown_gender = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') - ->where('tbl_appointment.date_attended', '=', DB::raw('tbl_appointment.appntmnt_date')) - ->where('tbl_client.gender', '!=', '1') - ->where('tbl_client.gender', '!=', '2') - ->count(); - // appointment honored by age - $appointment_honored_to_nine = Cache::remember('appointment-honored-to-nine', 10, function () { - return Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') - ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') - ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) > 0) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 9)) then `tbl_client`.`id` end)) AS count")) - ->where('tbl_appointment.date_attended', '=', DB::raw('tbl_appointment.appntmnt_date')) - ->pluck('count'); - }); - $appointment_honored_to_fourteen = Cache::remember('appointment-honored-to-fourteen', 10, function () { - return Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') - ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') - ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 10) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 14)) then `tbl_client`.`id` end)) AS count")) - ->where('tbl_appointment.date_attended', '=', DB::raw('tbl_appointment.appntmnt_date')) - ->pluck('count'); - }); - $appointment_honored_to_nineteen = Cache::remember('appointment-honored-to-nineteen', 10, function () { - return Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') - ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') - ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 15) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 19)) then `tbl_client`.`id` end)) AS count")) - ->where('tbl_appointment.date_attended', '=', DB::raw('tbl_appointment.appntmnt_date')) - ->pluck('count'); - }); - $appointment_honored_to_twentyfour = Cache::remember('appointment-honored-to-twentyfour', 10, function () { - return Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') - ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') - ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 20) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 24)) then `tbl_client`.`id` end)) AS count")) - ->where('tbl_appointment.date_attended', '=', DB::raw('tbl_appointment.appntmnt_date')) - ->pluck('count'); - }); - $appointment_honored_to_twentyfive_above = Cache::remember('appointment-honored-to-twentyfive_above', 10, function () { - return Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') - ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') - ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 25)) then `tbl_client`.`id` end)) AS count")) - ->where('tbl_appointment.date_attended', '=', DB::raw('tbl_appointment.appntmnt_date')) - ->pluck('count'); - }); - $appointment_honored_to_uknown_age = Cache::remember('appointment_honored-to-uknown-age', 10, function () { - return Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') - ->select('tbl_client.dob') - ->where('tbl_appointment.date_attended', '=', DB::raw('tbl_appointment.appntmnt_date')) - ->where('tbl_client.dob', '=', '') - ->orWhereNull('tbl_client.dob') - ->count(); - }); - - // appointment not honored by gender - $appointment_not_honoured_male = Cache::remember('appointment-not-honoured-male', 10, function () { - return Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') - ->where('tbl_client.gender', '=', '2') - ->whereIn('app_status', ['Defaulted', 'LTFU', 'Missed']) - ->count(); - }); - $appointment_not_honoured_female = Cache::remember('appointment-not-honoured-female', 10, function () { - return Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') - ->where('tbl_client.gender', '=', '1') - ->whereIn('app_status', ['Defaulted', 'LTFU', 'Missed']) - ->count(); - }); - $appointment_not_honoured_uknown_gender = Cache::remember('appointment-not-honoured-uknown-gender', 10, function () { - return Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') - ->where('tbl_client.gender', '!=', '1') - ->where('tbl_client.gender', '!=', '2') - ->whereIn('app_status', ['Defaulted', 'LTFU', 'Missed']) - ->count(); - }); - // appointment not honored by age - $appointment_not_honored_to_nine = Cache::remember('appointment-not-honored-to-nine', 10, function () { - return Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') - ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') - ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) > 0) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 9)) then `tbl_client`.`id` end)) AS count")) - ->whereIn('app_status', ['Defaulted', 'LTFU', 'Missed']) - ->pluck('count'); - }); - $appointment_not_honored_to_fourteen = Cache::remember('appointment-not-honored-to-fourteen', 10, function () { - return Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') - ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') - ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 10) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 14)) then `tbl_client`.`id` end)) AS count")) - ->whereIn('app_status', ['Defaulted', 'LTFU', 'Missed']) - ->pluck('count'); - }); - $appointment_not_honored_to_nineteen = Cache::remember('appointment_not_honored_to_nineteen', 10, function () { - return Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') - ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') - ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 15) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 19)) then `tbl_client`.`id` end)) AS count")) - ->whereIn('app_status', ['Defaulted', 'LTFU', 'Missed']) - ->pluck('count'); - }); - $appointment_not_honored_to_twentyfour = Cache::remember('appointment_not_honored_to_twentyfour', 10, function () { - return Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + }); + $appointment_not_honored_to_twentyfour = Cache::remember('appointment_not_honored_to_twentyfour', 10, function () { + return Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 20) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 24)) then `tbl_client`.`id` end)) AS count")) ->whereIn('app_status', ['Defaulted', 'LTFU', 'Missed']) ->pluck('count'); - }); - $appointment_not_honored_to_twentyfive_above = Cache::remember('appointment_not_honored_to_twentyfive_above', 10, function () { - return Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + }); + $appointment_not_honored_to_twentyfive_above = Cache::remember('appointment_not_honored_to_twentyfive_above', 10, function () { + return Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 25)) then `tbl_client`.`id` end)) AS count")) ->whereIn('app_status', ['Defaulted', 'LTFU', 'Missed']) ->pluck('count'); - }); - $appointment_not_honored_to_uknown_age = Cache::remember('appointment_not_honored_to_uknown_age', 10, function () { - return Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + }); + $appointment_not_honored_to_uknown_age = Cache::remember('appointment_not_honored_to_uknown_age', 10, function () { + return Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') ->select('tbl_client.dob') ->where('tbl_client.dob', '=', '') ->orWhereNull('tbl_client.dob') ->whereIn('app_status', ['Defaulted', 'LTFU', 'Missed']) ->count(); - }); - + }); } - return view('new_dashboard.appointment_dashboard', compact('all_partners', 'indicator', 'appointment', 'appointment_honoured', - 'appointment_not_honoured', - 'appointment_honoured_male', - 'appointment_honoured_female', - 'appointment_honoured_uknown_gender', - 'appointment_honored_to_nine', - 'appointment_honored_to_fourteen', - 'appointment_honored_to_nineteen', - 'appointment_honored_to_twentyfour', - 'appointment_honored_to_twentyfive_above', - 'appointment_honored_to_uknown_age', - 'appointment_not_honoured_male', - 'appointment_not_honoured_female', - 'appointment_not_honoured_uknown_gender', - 'appointment_not_honored_to_nine', - 'appointment_not_honored_to_fourteen', - 'appointment_not_honored_to_nineteen', - 'appointment_not_honored_to_twentyfour', - 'appointment_not_honored_to_twentyfive_above', - 'appointment_not_honored_to_uknown_age', - )); + return view('new_dashboard.appointment_dashboard', compact( + 'all_partners', + 'indicator', + 'appointment', + 'appointment_honoured', + 'appointment_not_honoured', + 'appointment_honoured_male', + 'appointment_honoured_female', + 'appointment_honoured_uknown_gender', + 'appointment_honored_to_nine', + 'appointment_honored_to_fourteen', + 'appointment_honored_to_nineteen', + 'appointment_honored_to_twentyfour', + 'appointment_honored_to_twentyfive_above', + 'appointment_honored_to_uknown_age', + 'appointment_not_honoured_male', + 'appointment_not_honoured_female', + 'appointment_not_honoured_uknown_gender', + 'appointment_not_honored_to_nine', + 'appointment_not_honored_to_fourteen', + 'appointment_not_honored_to_nineteen', + 'appointment_not_honored_to_twentyfour', + 'appointment_not_honored_to_twentyfive_above', + 'appointment_not_honored_to_uknown_age', + )); } public function missed_appointment_charts() { @@ -1483,1285 +1479,1288 @@ public function missed_appointment_charts() $all_partners = Partner::where('status', '=', 'Active')->pluck('name', 'id'); $indicator = Indicator::select(['name', 'description'])->get(); - // dd($appointment_honoured); - $appointment_not_honoured = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + // dd($appointment_honoured); + $appointment_not_honoured = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') ->select('tbl_appointment.id') - ->whereIn('tbl_appointment.app_status', ['Defaulted', 'LTFU', 'Missed']) - ->where('tbl_client.mfl_code', Auth::user()->facility_id) - ->count(); + ->whereIn('tbl_appointment.app_status', ['Defaulted', 'LTFU', 'Missed']) + ->where('tbl_client.mfl_code', Auth::user()->facility_id) + ->count(); - // missed appointments + // missed appointments - $appointment_missed = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + $appointment_missed = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') ->where('tbl_appointment.app_status', '=', 'Missed') ->where('tbl_client.mfl_code', Auth::user()->facility_id) ->count(); - $appointment_defaulted = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + $appointment_defaulted = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') ->where('tbl_appointment.app_status', '=', 'Defaulted') ->where('tbl_client.mfl_code', Auth::user()->facility_id) ->count(); - $appointment_lftu = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + $appointment_lftu = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') ->where('tbl_appointment.app_status', '=', 'LTFU') ->where('tbl_client.mfl_code', Auth::user()->facility_id) ->count(); - // missed appointment by gender - $appointment_missed_female = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') - ->where('tbl_appointment.app_status', '=', 'Missed') - ->where('tbl_client.gender', '=', '1') - ->where('tbl_client.mfl_code', Auth::user()->facility_id) - ->count(); - $appointment_missed_male = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') - ->where('tbl_appointment.app_status', '=', 'Missed') - ->where('tbl_client.gender', '=', '2') - ->where('tbl_client.mfl_code', Auth::user()->facility_id) - ->count(); + // missed appointment by gender + $appointment_missed_female = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->where('tbl_appointment.app_status', '=', 'Missed') + ->where('tbl_client.gender', '=', '1') + ->where('tbl_client.mfl_code', Auth::user()->facility_id) + ->count(); + $appointment_missed_male = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->where('tbl_appointment.app_status', '=', 'Missed') + ->where('tbl_client.gender', '=', '2') + ->where('tbl_client.mfl_code', Auth::user()->facility_id) + ->count(); - $appointment_missed_uknown_gender = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') - ->where('tbl_appointment.app_status', '=', 'Missed') - ->where('tbl_client.gender', '!=', '1') - ->where('tbl_client.gender', '!=', '2') - ->where('tbl_client.mfl_code', Auth::user()->facility_id) - ->count(); + $appointment_missed_uknown_gender = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->where('tbl_appointment.app_status', '=', 'Missed') + ->where('tbl_client.gender', '!=', '1') + ->where('tbl_client.gender', '!=', '2') + ->where('tbl_client.mfl_code', Auth::user()->facility_id) + ->count(); - // missed appointment by age - $appointment_missed_to_nine = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + // missed appointment by age + $appointment_missed_to_nine = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) > 0) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 9)) then `tbl_client`.`id` end)) AS count")) - ->where('tbl_appointment.app_status', '=', 'Missed') - ->where('tbl_client.mfl_code', Auth::user()->facility_id) - ->pluck('count'); - $appointment_missed_to_fourteen = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->where('tbl_appointment.app_status', '=', 'Missed') + ->where('tbl_client.mfl_code', Auth::user()->facility_id) + ->pluck('count'); + $appointment_missed_to_fourteen = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 10) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 14)) then `tbl_client`.`id` end)) AS count")) - ->where('tbl_appointment.app_status', '=', 'Missed') - ->where('tbl_client.mfl_code', Auth::user()->facility_id) - ->pluck('count'); + ->where('tbl_appointment.app_status', '=', 'Missed') + ->where('tbl_client.mfl_code', Auth::user()->facility_id) + ->pluck('count'); - $appointment_missed_to_nineteen = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + $appointment_missed_to_nineteen = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 15) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 19)) then `tbl_client`.`id` end)) AS count")) - ->where('tbl_appointment.app_status', '=', 'Missed') - ->where('tbl_client.mfl_code', Auth::user()->facility_id) - ->pluck('count'); - $appointment_missed_to_twentyfour = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->where('tbl_appointment.app_status', '=', 'Missed') + ->where('tbl_client.mfl_code', Auth::user()->facility_id) + ->pluck('count'); + $appointment_missed_to_twentyfour = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 20) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 24)) then `tbl_client`.`id` end)) AS count")) - ->where('tbl_appointment.app_status', '=', 'Missed') - ->where('tbl_client.mfl_code', Auth::user()->facility_id) - ->pluck('count'); - $appointment_missed_to_twentyfive_above = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->where('tbl_appointment.app_status', '=', 'Missed') + ->where('tbl_client.mfl_code', Auth::user()->facility_id) + ->pluck('count'); + $appointment_missed_to_twentyfive_above = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 25)) then `tbl_client`.`id` end)) AS count")) - ->where('tbl_appointment.app_status', '=', 'Missed') - ->where('tbl_client.mfl_code', Auth::user()->facility_id) - ->pluck('count'); - $appointment_missed_to_uknown_age = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') - ->select('tbl_client.dob') - ->where('tbl_client.dob', '=', '') - ->orWhereNull('tbl_client.dob') - ->where('tbl_appointment.app_status', '=', 'Missed') - ->where('tbl_client.mfl_code', Auth::user()->facility_id) - ->count(); - - // defaulted appointment by gender - $appointment_defaulted_female = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') - ->where('tbl_appointment.app_status', '=', 'Defaulted') - ->where('tbl_client.gender', '=', '1') - ->where('tbl_client.mfl_code', Auth::user()->facility_id) - ->count(); - $appointment_defaulted_male = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') - ->where('tbl_appointment.app_status', '=', 'Defaulted') - ->where('tbl_client.gender', '=', '2') - ->where('tbl_client.mfl_code', Auth::user()->facility_id) - ->count(); + ->where('tbl_appointment.app_status', '=', 'Missed') + ->where('tbl_client.mfl_code', Auth::user()->facility_id) + ->pluck('count'); + $appointment_missed_to_uknown_age = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->select('tbl_client.dob') + ->where('tbl_client.dob', '=', '') + ->orWhereNull('tbl_client.dob') + ->where('tbl_appointment.app_status', '=', 'Missed') + ->where('tbl_client.mfl_code', Auth::user()->facility_id) + ->count(); - $appointment_defaulted_uknown_gender = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') - ->where('tbl_appointment.app_status', '=', 'Defaulted') - ->where('tbl_client.gender', '!=', '1') - ->where('tbl_client.gender', '!=', '2') - ->where('tbl_client.mfl_code', Auth::user()->facility_id) - ->count(); - // defaulted appointment by age - $appointment_defaulted_to_nine = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + // defaulted appointment by gender + $appointment_defaulted_female = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->where('tbl_appointment.app_status', '=', 'Defaulted') + ->where('tbl_client.gender', '=', '1') + ->where('tbl_client.mfl_code', Auth::user()->facility_id) + ->count(); + $appointment_defaulted_male = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->where('tbl_appointment.app_status', '=', 'Defaulted') + ->where('tbl_client.gender', '=', '2') + ->where('tbl_client.mfl_code', Auth::user()->facility_id) + ->count(); + + $appointment_defaulted_uknown_gender = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->where('tbl_appointment.app_status', '=', 'Defaulted') + ->where('tbl_client.gender', '!=', '1') + ->where('tbl_client.gender', '!=', '2') + ->where('tbl_client.mfl_code', Auth::user()->facility_id) + ->count(); + // defaulted appointment by age + $appointment_defaulted_to_nine = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) > 0) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 9)) then `tbl_client`.`id` end)) AS count")) - ->where('tbl_appointment.app_status', '=', 'Defaulted') - ->where('tbl_client.mfl_code', Auth::user()->facility_id) - ->pluck('count'); - $appointment_defaulted_to_fourteen = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->where('tbl_appointment.app_status', '=', 'Defaulted') + ->where('tbl_client.mfl_code', Auth::user()->facility_id) + ->pluck('count'); + $appointment_defaulted_to_fourteen = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 10) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 14)) then `tbl_client`.`id` end)) AS count")) - ->where('tbl_appointment.app_status', '=', 'Defaulted') - ->where('tbl_client.mfl_code', Auth::user()->facility_id) - ->pluck('count'); - $appointment_defaulted_to_nineteen = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->where('tbl_appointment.app_status', '=', 'Defaulted') + ->where('tbl_client.mfl_code', Auth::user()->facility_id) + ->pluck('count'); + $appointment_defaulted_to_nineteen = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 15) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 19)) then `tbl_client`.`id` end)) AS count")) - ->where('tbl_appointment.app_status', '=', 'Defaulted') - ->where('tbl_client.mfl_code', Auth::user()->facility_id) - ->pluck('count'); - $appointment_defaulted_to_twentyfour = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->where('tbl_appointment.app_status', '=', 'Defaulted') + ->where('tbl_client.mfl_code', Auth::user()->facility_id) + ->pluck('count'); + $appointment_defaulted_to_twentyfour = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 20) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 24)) then `tbl_client`.`id` end)) AS count")) - ->where('tbl_appointment.app_status', '=', 'Defaulted') - ->where('tbl_client.mfl_code', Auth::user()->facility_id) - ->pluck('count'); + ->where('tbl_appointment.app_status', '=', 'Defaulted') + ->where('tbl_client.mfl_code', Auth::user()->facility_id) + ->pluck('count'); - $appointment_defaulted_to_twentyfive_above = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + $appointment_defaulted_to_twentyfive_above = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 25)) then `tbl_client`.`id` end)) AS count")) - ->where('tbl_appointment.app_status', '=', 'Defaulted') - ->where('tbl_client.mfl_code', Auth::user()->facility_id) - ->pluck('count'); + ->where('tbl_appointment.app_status', '=', 'Defaulted') + ->where('tbl_client.mfl_code', Auth::user()->facility_id) + ->pluck('count'); - $appointment_defaulted_to_uknown_age = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') - ->select('tbl_client.dob') - ->where('tbl_client.dob', '=', '') - ->orWhereNull('tbl_client.dob') - ->where('tbl_appointment.app_status', '=', 'Defaulted') - ->where('tbl_client.mfl_code', Auth::user()->facility_id) - ->count(); - // ltfu appointment by gender - $appointment_ltfu_female = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') - ->where('tbl_appointment.app_status', '=', 'LTFU') - ->where('tbl_client.gender', '=', '1') - ->where('tbl_client.mfl_code', Auth::user()->facility_id) - ->count(); + $appointment_defaulted_to_uknown_age = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->select('tbl_client.dob') + ->where('tbl_client.dob', '=', '') + ->orWhereNull('tbl_client.dob') + ->where('tbl_appointment.app_status', '=', 'Defaulted') + ->where('tbl_client.mfl_code', Auth::user()->facility_id) + ->count(); + // ltfu appointment by gender + $appointment_ltfu_female = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->where('tbl_appointment.app_status', '=', 'LTFU') + ->where('tbl_client.gender', '=', '1') + ->where('tbl_client.mfl_code', Auth::user()->facility_id) + ->count(); - $appointment_ltfu_male = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') - ->where('tbl_appointment.app_status', '=', 'LTFU') - ->where('tbl_client.gender', '=', '2') - ->where('tbl_client.mfl_code', Auth::user()->facility_id) - ->count(); - $appointment_ltfu_uknown_gender = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') - ->where('tbl_appointment.app_status', '=', 'LTFU') - ->where('tbl_client.gender', '!=', '1') - ->where('tbl_client.gender', '!=', '2') - ->where('tbl_client.mfl_code', Auth::user()->facility_id) - ->count(); + $appointment_ltfu_male = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->where('tbl_appointment.app_status', '=', 'LTFU') + ->where('tbl_client.gender', '=', '2') + ->where('tbl_client.mfl_code', Auth::user()->facility_id) + ->count(); + $appointment_ltfu_uknown_gender = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->where('tbl_appointment.app_status', '=', 'LTFU') + ->where('tbl_client.gender', '!=', '1') + ->where('tbl_client.gender', '!=', '2') + ->where('tbl_client.mfl_code', Auth::user()->facility_id) + ->count(); - // ltfu appointment by age - $appointment_ltfu_to_nine = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + // ltfu appointment by age + $appointment_ltfu_to_nine = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) > 0) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 9)) then `tbl_client`.`id` end)) AS count")) - ->where('tbl_appointment.app_status', '=', 'LTFU') - ->where('tbl_client.mfl_code', Auth::user()->facility_id) - ->pluck('count'); + ->where('tbl_appointment.app_status', '=', 'LTFU') + ->where('tbl_client.mfl_code', Auth::user()->facility_id) + ->pluck('count'); - $appointment_ltfu_to_fourteen = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + $appointment_ltfu_to_fourteen = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 10) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 14)) then `tbl_client`.`id` end)) AS count")) - ->where('tbl_appointment.app_status', '=', 'LTFU') - ->where('tbl_client.mfl_code', Auth::user()->facility_id) - ->pluck('count'); + ->where('tbl_appointment.app_status', '=', 'LTFU') + ->where('tbl_client.mfl_code', Auth::user()->facility_id) + ->pluck('count'); - $appointment_ltfu_to_nineteen = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + $appointment_ltfu_to_nineteen = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 15) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 19)) then `tbl_client`.`id` end)) AS count")) - ->where('tbl_appointment.app_status', '=', 'LTFU') - ->where('tbl_client.mfl_code', Auth::user()->facility_id) - ->pluck('count'); + ->where('tbl_appointment.app_status', '=', 'LTFU') + ->where('tbl_client.mfl_code', Auth::user()->facility_id) + ->pluck('count'); - $appointment_ltfu_to_twentyfour = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + $appointment_ltfu_to_twentyfour = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 20) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 24)) then `tbl_client`.`id` end)) AS count")) - ->where('tbl_appointment.app_status', '=', 'LTFU') - ->where('tbl_client.mfl_code', Auth::user()->facility_id) - ->pluck('count'); - $appointment_ltfu_to_twentyfive_above = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->where('tbl_appointment.app_status', '=', 'LTFU') + ->where('tbl_client.mfl_code', Auth::user()->facility_id) + ->pluck('count'); + $appointment_ltfu_to_twentyfive_above = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 25)) then `tbl_client`.`id` end)) AS count")) - ->where('tbl_appointment.app_status', '=', 'LTFU') - ->where('tbl_client.mfl_code', Auth::user()->facility_id) - ->pluck('count'); + ->where('tbl_appointment.app_status', '=', 'LTFU') + ->where('tbl_client.mfl_code', Auth::user()->facility_id) + ->pluck('count'); - $appointment_ltfu_to_uknown_age = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') - ->select('tbl_client.dob') - ->where('tbl_client.dob', '=', '') - ->orWhereNull('tbl_client.dob') - ->where('tbl_appointment.app_status', '=', 'LTFU') - ->where('tbl_client.mfl_code', Auth::user()->facility_id) - ->count(); + $appointment_ltfu_to_uknown_age = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->select('tbl_client.dob') + ->where('tbl_client.dob', '=', '') + ->orWhereNull('tbl_client.dob') + ->where('tbl_appointment.app_status', '=', 'LTFU') + ->where('tbl_client.mfl_code', Auth::user()->facility_id) + ->count(); } if (Auth::user()->access_level == 'Partner') { $all_partners = Partner::where('status', '=', 'Active')->pluck('name', 'id'); $indicator = Indicator::select(['name', 'description'])->get(); - // dd($appointment_honoured); - $appointment_not_honoured = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + // dd($appointment_honoured); + $appointment_not_honoured = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') ->select('tbl_appointment.id') - ->whereIn('tbl_appointment.app_status', ['Defaulted', 'LTFU', 'Missed']) - ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) - ->count(); + ->whereIn('tbl_appointment.app_status', ['Defaulted', 'LTFU', 'Missed']) + ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) + ->count(); - // missed appointments + // missed appointments - $appointment_missed = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + $appointment_missed = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') ->where('tbl_appointment.app_status', '=', 'Missed') ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) ->count(); - $appointment_defaulted = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + $appointment_defaulted = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') ->where('tbl_appointment.app_status', '=', 'Defaulted') ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) ->count(); - $appointment_lftu = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + $appointment_lftu = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') ->where('tbl_appointment.app_status', '=', 'LTFU') ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) ->count(); - // missed appointment by gender - $appointment_missed_female = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + // missed appointment by gender + $appointment_missed_female = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') - ->where('tbl_appointment.app_status', '=', 'Missed') - ->where('tbl_client.gender', '=', '1') - ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) - ->count(); - $appointment_missed_male = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->where('tbl_appointment.app_status', '=', 'Missed') + ->where('tbl_client.gender', '=', '1') + ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) + ->count(); + $appointment_missed_male = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') - ->where('tbl_appointment.app_status', '=', 'Missed') - ->where('tbl_client.gender', '=', '2') - ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) - ->count(); + ->where('tbl_appointment.app_status', '=', 'Missed') + ->where('tbl_client.gender', '=', '2') + ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) + ->count(); - $appointment_missed_uknown_gender = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') - ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') - ->where('tbl_appointment.app_status', '=', 'Missed') - ->where('tbl_client.gender', '!=', '1') - ->where('tbl_client.gender', '!=', '2') - ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) - ->count(); + $appointment_missed_uknown_gender = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->where('tbl_appointment.app_status', '=', 'Missed') + ->where('tbl_client.gender', '!=', '1') + ->where('tbl_client.gender', '!=', '2') + ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) + ->count(); - // missed appointment by age - $appointment_missed_to_nine = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + // missed appointment by age + $appointment_missed_to_nine = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) > 0) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 9)) then `tbl_client`.`id` end)) AS count")) - ->where('tbl_appointment.app_status', '=', 'Missed') - ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) - ->pluck('count'); - $appointment_missed_to_fourteen = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->where('tbl_appointment.app_status', '=', 'Missed') + ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) + ->pluck('count'); + $appointment_missed_to_fourteen = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 10) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 14)) then `tbl_client`.`id` end)) AS count")) - ->where('tbl_appointment.app_status', '=', 'Missed') - ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) - ->pluck('count'); + ->where('tbl_appointment.app_status', '=', 'Missed') + ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) + ->pluck('count'); - $appointment_missed_to_nineteen = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + $appointment_missed_to_nineteen = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 15) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 19)) then `tbl_client`.`id` end)) AS count")) - ->where('tbl_appointment.app_status', '=', 'Missed') - ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) - ->pluck('count'); - $appointment_missed_to_twentyfour = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->where('tbl_appointment.app_status', '=', 'Missed') + ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) + ->pluck('count'); + $appointment_missed_to_twentyfour = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 20) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 24)) then `tbl_client`.`id` end)) AS count")) - ->where('tbl_appointment.app_status', '=', 'Missed') - ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) - ->pluck('count'); - $appointment_missed_to_twentyfive_above = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->where('tbl_appointment.app_status', '=', 'Missed') + ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) + ->pluck('count'); + $appointment_missed_to_twentyfive_above = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 25)) then `tbl_client`.`id` end)) AS count")) - ->where('tbl_appointment.app_status', '=', 'Missed') - ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) - ->pluck('count'); - $appointment_missed_to_uknown_age = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->where('tbl_appointment.app_status', '=', 'Missed') + ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) + ->pluck('count'); + $appointment_missed_to_uknown_age = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') - ->select('tbl_client.dob') - ->where('tbl_client.dob', '=', '') - ->orWhereNull('tbl_client.dob') - ->where('tbl_appointment.app_status', '=', 'Missed') - ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) - ->count(); + ->select('tbl_client.dob') + ->where('tbl_client.dob', '=', '') + ->orWhereNull('tbl_client.dob') + ->where('tbl_appointment.app_status', '=', 'Missed') + ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) + ->count(); - // defaulted appointment by gender - $appointment_defaulted_female = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + // defaulted appointment by gender + $appointment_defaulted_female = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') - ->where('tbl_appointment.app_status', '=', 'Defaulted') - ->where('tbl_client.gender', '=', '1') - ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) - ->count(); - $appointment_defaulted_male = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->where('tbl_appointment.app_status', '=', 'Defaulted') + ->where('tbl_client.gender', '=', '1') + ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) + ->count(); + $appointment_defaulted_male = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') - ->where('tbl_appointment.app_status', '=', 'Defaulted') - ->where('tbl_client.gender', '=', '2') - ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) - ->count(); + ->where('tbl_appointment.app_status', '=', 'Defaulted') + ->where('tbl_client.gender', '=', '2') + ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) + ->count(); - $appointment_defaulted_uknown_gender = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + $appointment_defaulted_uknown_gender = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') - ->where('tbl_appointment.app_status', '=', 'Defaulted') - ->where('tbl_client.gender', '!=', '1') - ->where('tbl_client.gender', '!=', '2') - ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) - ->count(); - // defaulted appointment by age - $appointment_defaulted_to_nine = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->where('tbl_appointment.app_status', '=', 'Defaulted') + ->where('tbl_client.gender', '!=', '1') + ->where('tbl_client.gender', '!=', '2') + ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) + ->count(); + // defaulted appointment by age + $appointment_defaulted_to_nine = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) > 0) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 9)) then `tbl_client`.`id` end)) AS count")) - ->where('tbl_appointment.app_status', '=', 'Defaulted') - ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) - ->pluck('count'); - $appointment_defaulted_to_fourteen = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->where('tbl_appointment.app_status', '=', 'Defaulted') + ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) + ->pluck('count'); + $appointment_defaulted_to_fourteen = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 10) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 14)) then `tbl_client`.`id` end)) AS count")) - ->where('tbl_appointment.app_status', '=', 'Defaulted') - ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) - ->pluck('count'); - $appointment_defaulted_to_nineteen = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->where('tbl_appointment.app_status', '=', 'Defaulted') + ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) + ->pluck('count'); + $appointment_defaulted_to_nineteen = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 15) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 19)) then `tbl_client`.`id` end)) AS count")) - ->where('tbl_appointment.app_status', '=', 'Defaulted') - ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) - ->pluck('count'); - $appointment_defaulted_to_twentyfour = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->where('tbl_appointment.app_status', '=', 'Defaulted') + ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) + ->pluck('count'); + $appointment_defaulted_to_twentyfour = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 20) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 24)) then `tbl_client`.`id` end)) AS count")) - ->where('tbl_appointment.app_status', '=', 'Defaulted') - ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) - ->pluck('count'); + ->where('tbl_appointment.app_status', '=', 'Defaulted') + ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) + ->pluck('count'); - $appointment_defaulted_to_twentyfive_above = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + $appointment_defaulted_to_twentyfive_above = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 25)) then `tbl_client`.`id` end)) AS count")) - ->where('tbl_appointment.app_status', '=', 'Defaulted') - ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) - ->pluck('count'); + ->where('tbl_appointment.app_status', '=', 'Defaulted') + ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) + ->pluck('count'); - $appointment_defaulted_to_uknown_age = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') - ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') - ->select('tbl_client.dob') - ->where('tbl_client.dob', '=', '') - ->orWhereNull('tbl_client.dob') - ->where('tbl_appointment.app_status', '=', 'Defaulted') - ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) - ->count(); - // ltfu appointment by gender - $appointment_ltfu_female = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + $appointment_defaulted_to_uknown_age = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') - ->where('tbl_appointment.app_status', '=', 'LTFU') - ->where('tbl_client.gender', '=', '1') - ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) - ->count(); + ->select('tbl_client.dob') + ->where('tbl_client.dob', '=', '') + ->orWhereNull('tbl_client.dob') + ->where('tbl_appointment.app_status', '=', 'Defaulted') + ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) + ->count(); + // ltfu appointment by gender + $appointment_ltfu_female = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->where('tbl_appointment.app_status', '=', 'LTFU') + ->where('tbl_client.gender', '=', '1') + ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) + ->count(); - $appointment_ltfu_male = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + $appointment_ltfu_male = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') - ->where('tbl_appointment.app_status', '=', 'LTFU') - ->where('tbl_client.gender', '=', '2') - ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) - ->count(); - $appointment_ltfu_uknown_gender = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->where('tbl_appointment.app_status', '=', 'LTFU') + ->where('tbl_client.gender', '=', '2') + ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) + ->count(); + $appointment_ltfu_uknown_gender = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') - ->where('tbl_appointment.app_status', '=', 'LTFU') - ->where('tbl_client.gender', '!=', '1') - ->where('tbl_client.gender', '!=', '2') - ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) - ->count(); + ->where('tbl_appointment.app_status', '=', 'LTFU') + ->where('tbl_client.gender', '!=', '1') + ->where('tbl_client.gender', '!=', '2') + ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) + ->count(); - // ltfu appointment by age - $appointment_ltfu_to_nine = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + // ltfu appointment by age + $appointment_ltfu_to_nine = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) > 0) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 9)) then `tbl_client`.`id` end)) AS count")) - ->where('tbl_appointment.app_status', '=', 'LTFU') - ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) - ->pluck('count'); + ->where('tbl_appointment.app_status', '=', 'LTFU') + ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) + ->pluck('count'); - $appointment_ltfu_to_fourteen = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + $appointment_ltfu_to_fourteen = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 10) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 14)) then `tbl_client`.`id` end)) AS count")) - ->where('tbl_appointment.app_status', '=', 'LTFU') - ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) - ->pluck('count'); + ->where('tbl_appointment.app_status', '=', 'LTFU') + ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) + ->pluck('count'); - $appointment_ltfu_to_nineteen = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + $appointment_ltfu_to_nineteen = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 15) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 19)) then `tbl_client`.`id` end)) AS count")) - ->where('tbl_appointment.app_status', '=', 'LTFU') - ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) - ->pluck('count'); + ->where('tbl_appointment.app_status', '=', 'LTFU') + ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) + ->pluck('count'); - $appointment_ltfu_to_twentyfour = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + $appointment_ltfu_to_twentyfour = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 20) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 24)) then `tbl_client`.`id` end)) AS count")) - ->where('tbl_appointment.app_status', '=', 'LTFU') - ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) - ->pluck('count'); - $appointment_ltfu_to_twentyfive_above = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->where('tbl_appointment.app_status', '=', 'LTFU') + ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) + ->pluck('count'); + $appointment_ltfu_to_twentyfive_above = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 25)) then `tbl_client`.`id` end)) AS count")) - ->where('tbl_appointment.app_status', '=', 'LTFU') - ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) - ->pluck('count'); + ->where('tbl_appointment.app_status', '=', 'LTFU') + ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) + ->pluck('count'); - $appointment_ltfu_to_uknown_age = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + $appointment_ltfu_to_uknown_age = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') - ->select('tbl_client.dob') - ->where('tbl_client.dob', '=', '') - ->orWhereNull('tbl_client.dob') - ->where('tbl_appointment.app_status', '=', 'LTFU') - ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) - ->count(); + ->select('tbl_client.dob') + ->where('tbl_client.dob', '=', '') + ->orWhereNull('tbl_client.dob') + ->where('tbl_appointment.app_status', '=', 'LTFU') + ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) + ->count(); } if (Auth::user()->access_level == 'Admin' || Auth::user()->access_level == 'Donor') { $all_partners = Partner::where('status', '=', 'Active')->pluck('name', 'id'); $indicator = Indicator::select(['name', 'description'])->get(); - // main appointments - // dd($appointment_honoured); - $appointment_not_honoured = Cache::remember('appointment-not-honoured', 10, function () { - return Appointments::select(\DB::raw("COUNT(id) as count")) + // main appointments + // dd($appointment_honoured); + $appointment_not_honoured = Cache::remember('appointment-not-honoured', 10, function () { + return Appointments::select(\DB::raw("COUNT(id) as count")) ->whereIn('app_status', ['Defaulted', 'LTFU', 'Missed']) ->pluck('count'); - }); + }); - // missed appointments + // missed appointments - $appointment_missed = Cache::remember('appointment_missed', 10, function () { - return Appointments::where('app_status', '=', 'Missed') + $appointment_missed = Cache::remember('appointment_missed', 10, function () { + return Appointments::where('app_status', '=', 'Missed') ->count(); - }); - $appointment_defaulted = Cache::remember('appointment_defaulted', 10, function () { - return Appointments::where('app_status', '=', 'Defaulted') + }); + $appointment_defaulted = Cache::remember('appointment_defaulted', 10, function () { + return Appointments::where('app_status', '=', 'Defaulted') ->count(); - }); - $appointment_lftu = Cache::remember('appointment_lftu', 10, function () { - return Appointments::where('app_status', '=', 'LTFU') + }); + $appointment_lftu = Cache::remember('appointment_lftu', 10, function () { + return Appointments::where('app_status', '=', 'LTFU') ->count(); - }); + }); - // missed appointment by gender - $appointment_missed_female = Cache::remember('appointment_missed_female', 10, function () { - return Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + // missed appointment by gender + $appointment_missed_female = Cache::remember('appointment_missed_female', 10, function () { + return Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') ->where('tbl_appointment.app_status', '=', 'Missed') ->where('tbl_client.gender', '=', '1') ->count(); - }); - $appointment_missed_male = Cache::remember('appointment_missed_male', 10, function () { - return Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + }); + $appointment_missed_male = Cache::remember('appointment_missed_male', 10, function () { + return Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') ->where('tbl_appointment.app_status', '=', 'Missed') ->where('tbl_client.gender', '=', '2') ->count(); - }); - $appointment_missed_uknown_gender = Cache::remember('appointment_missed_uknown_gender', 10, function () { - return Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + }); + $appointment_missed_uknown_gender = Cache::remember('appointment_missed_uknown_gender', 10, function () { + return Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') ->where('tbl_appointment.app_status', '=', 'Missed') ->where('tbl_client.gender', '!=', '1') ->where('tbl_client.gender', '!=', '2') ->count(); - }); - // missed appointment by age - $appointment_missed_to_nine = Cache::remember('appointment_missed_to_nine', 10, function () { + }); + // missed appointment by age + $appointment_missed_to_nine = Cache::remember('appointment_missed_to_nine', 10, function () { return Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') - ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) > 0) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 9)) then `tbl_client`.`id` end)) AS count")) + ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) > 0) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 9)) then `tbl_client`.`id` end)) AS count")) ->where('tbl_appointment.app_status', '=', 'Missed') ->pluck('count'); - }); - $appointment_missed_to_fourteen = Cache::remember('appointment_missed_to_fourteen', 10, function () { - return Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') - ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 10) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 14)) then `tbl_client`.`id` end)) AS count")) + }); + $appointment_missed_to_fourteen = Cache::remember('appointment_missed_to_fourteen', 10, function () { + return Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 10) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 14)) then `tbl_client`.`id` end)) AS count")) ->where('tbl_appointment.app_status', '=', 'Missed') ->pluck('count'); - }); - $appointment_missed_to_nineteen = Cache::remember('appointment_missed_to_nineteen', 10, function () { - return Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') - ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 15) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 19)) then `tbl_client`.`id` end)) AS count")) + }); + $appointment_missed_to_nineteen = Cache::remember('appointment_missed_to_nineteen', 10, function () { + return Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 15) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 19)) then `tbl_client`.`id` end)) AS count")) ->where('tbl_appointment.app_status', '=', 'Missed') ->pluck('count'); - }); - $appointment_missed_to_twentyfour = Cache::remember('appointment_missed_to_twentyfour', 10, function () { - return Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') - ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 20) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 24)) then `tbl_client`.`id` end)) AS count")) + }); + $appointment_missed_to_twentyfour = Cache::remember('appointment_missed_to_twentyfour', 10, function () { + return Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 20) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 24)) then `tbl_client`.`id` end)) AS count")) ->where('tbl_appointment.app_status', '=', 'Missed') ->pluck('count'); - }); - $appointment_missed_to_twentyfive_above = Cache::remember('appointment_missed_to_twentyfive_above', 10, function () { - return Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') - ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 25)) then `tbl_client`.`id` end)) AS count")) + }); + $appointment_missed_to_twentyfive_above = Cache::remember('appointment_missed_to_twentyfive_above', 10, function () { + return Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 25)) then `tbl_client`.`id` end)) AS count")) ->where('tbl_appointment.app_status', '=', 'Missed') ->pluck('count'); - }); - $appointment_missed_to_uknown_age = Cache::remember('appointment_missed_to_uknown_age', 10, function () { - return Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + }); + $appointment_missed_to_uknown_age = Cache::remember('appointment_missed_to_uknown_age', 10, function () { + return Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') ->select('tbl_client.dob') ->where('tbl_client.dob', '=', '') ->orWhereNull('tbl_client.dob') ->where('tbl_appointment.app_status', '=', 'Missed') ->count(); - }); + }); - // defaulted appointment by gender - $appointment_defaulted_female = Cache::remember('appointment_defaulted_female', 10, function () { - return Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + // defaulted appointment by gender + $appointment_defaulted_female = Cache::remember('appointment_defaulted_female', 10, function () { + return Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') ->where('tbl_appointment.app_status', '=', 'Defaulted') ->where('tbl_client.gender', '=', '1') ->count(); - }); - $appointment_defaulted_male = Cache::remember('appointment_defaulted_male', 10, function () { - return Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + }); + $appointment_defaulted_male = Cache::remember('appointment_defaulted_male', 10, function () { + return Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') ->where('tbl_appointment.app_status', '=', 'Defaulted') ->where('tbl_client.gender', '=', '2') ->count(); - }); - $appointment_defaulted_uknown_gender = Cache::remember('appointment_defaulted_uknown_gender', 10, function () { - return Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + }); + $appointment_defaulted_uknown_gender = Cache::remember('appointment_defaulted_uknown_gender', 10, function () { + return Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') ->where('tbl_appointment.app_status', '=', 'Defaulted') ->where('tbl_client.gender', '!=', '1') ->where('tbl_client.gender', '!=', '2') ->count(); - }); + }); - // defaulted appointment by age - $appointment_defaulted_to_nine = Cache::remember('appointment_defaulted_to_nine', 10, function () { - return Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') - ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) > 0) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 9)) then `tbl_client`.`id` end)) AS count")) + // defaulted appointment by age + $appointment_defaulted_to_nine = Cache::remember('appointment_defaulted_to_nine', 10, function () { + return Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) > 0) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 9)) then `tbl_client`.`id` end)) AS count")) ->where('tbl_appointment.app_status', '=', 'Defaulted') ->pluck('count'); - }); - $appointment_defaulted_to_fourteen = Cache::remember('appointment_defaulted_to_fourteen', 10, function () { - return Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') - ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 10) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 14)) then `tbl_client`.`id` end)) AS count")) + }); + $appointment_defaulted_to_fourteen = Cache::remember('appointment_defaulted_to_fourteen', 10, function () { + return Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 10) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 14)) then `tbl_client`.`id` end)) AS count")) ->where('tbl_appointment.app_status', '=', 'Defaulted') ->pluck('count'); - }); - $appointment_defaulted_to_nineteen = Cache::remember('appointment_defaulted_to_nineteen', 10, function () { - return Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') - ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 15) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 19)) then `tbl_client`.`id` end)) AS count")) + }); + $appointment_defaulted_to_nineteen = Cache::remember('appointment_defaulted_to_nineteen', 10, function () { + return Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 15) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 19)) then `tbl_client`.`id` end)) AS count")) ->where('tbl_appointment.app_status', '=', 'Defaulted') ->pluck('count'); - }); - $appointment_defaulted_to_twentyfour = Cache::remember('appointment_defaulted_to_twentyfour', 10, function () { - return Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') - ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 20) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 24)) then `tbl_client`.`id` end)) AS count")) + }); + $appointment_defaulted_to_twentyfour = Cache::remember('appointment_defaulted_to_twentyfour', 10, function () { + return Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 20) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 24)) then `tbl_client`.`id` end)) AS count")) ->where('tbl_appointment.app_status', '=', 'Defaulted') ->pluck('count'); - }); - $appointment_defaulted_to_twentyfive_above = Cache::remember('appointment_defaulted_to_twentyfive_above', 10, function () { - return Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') - ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 25)) then `tbl_client`.`id` end)) AS count")) + }); + $appointment_defaulted_to_twentyfive_above = Cache::remember('appointment_defaulted_to_twentyfive_above', 10, function () { + return Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 25)) then `tbl_client`.`id` end)) AS count")) ->where('tbl_appointment.app_status', '=', 'Defaulted') ->pluck('count'); - }); - $appointment_defaulted_to_uknown_age = Cache::remember('appointment_defaulted_to_uknown_age', 10, function () { - return Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + }); + $appointment_defaulted_to_uknown_age = Cache::remember('appointment_defaulted_to_uknown_age', 10, function () { + return Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') ->select('tbl_client.dob') ->where('tbl_client.dob', '=', '') ->orWhereNull('tbl_client.dob') ->where('tbl_appointment.app_status', '=', 'Defaulted') ->count(); - }); - // ltfu appointment by gender - $appointment_ltfu_female = Cache::remember('appointment_ltfu_female', 10, function () { - return Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + }); + // ltfu appointment by gender + $appointment_ltfu_female = Cache::remember('appointment_ltfu_female', 10, function () { + return Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') ->where('tbl_appointment.app_status', '=', 'LTFU') ->where('tbl_client.gender', '=', '1') ->count(); - }); - $appointment_ltfu_male = Cache::remember('appointment_ltfu_male', 10, function () { - return Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + }); + $appointment_ltfu_male = Cache::remember('appointment_ltfu_male', 10, function () { + return Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') ->where('tbl_appointment.app_status', '=', 'LTFU') ->where('tbl_client.gender', '=', '2') ->count(); - }); - $appointment_ltfu_uknown_gender = Cache::remember('appointment_ltfu_uknown_gender', 10, function () { - return Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + }); + $appointment_ltfu_uknown_gender = Cache::remember('appointment_ltfu_uknown_gender', 10, function () { + return Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') ->where('tbl_appointment.app_status', '=', 'LTFU') ->where('tbl_client.gender', '!=', '1') ->where('tbl_client.gender', '!=', '2') ->count(); - }); + }); - // ltfu appointment by age - $appointment_ltfu_to_nine = Cache::remember('appointment_ltfu_to_nine', 10, function () { - return Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') - ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) > 0) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 9)) then `tbl_client`.`id` end)) AS count")) + // ltfu appointment by age + $appointment_ltfu_to_nine = Cache::remember('appointment_ltfu_to_nine', 10, function () { + return Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) > 0) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 9)) then `tbl_client`.`id` end)) AS count")) ->where('tbl_appointment.app_status', '=', 'LTFU') ->pluck('count'); - }); - $appointment_ltfu_to_fourteen = Cache::remember('appointment_ltfu_to_fourteen', 10, function () { - return Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') - ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 10) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 14)) then `tbl_client`.`id` end)) AS count")) + }); + $appointment_ltfu_to_fourteen = Cache::remember('appointment_ltfu_to_fourteen', 10, function () { + return Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 10) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 14)) then `tbl_client`.`id` end)) AS count")) ->where('tbl_appointment.app_status', '=', 'LTFU') ->pluck('count'); - }); - $appointment_ltfu_to_nineteen = Cache::remember('appointment_ltfu_to_nineteen', 10, function () { - return Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') - ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 15) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 19)) then `tbl_client`.`id` end)) AS count")) + }); + $appointment_ltfu_to_nineteen = Cache::remember('appointment_ltfu_to_nineteen', 10, function () { + return Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 15) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 19)) then `tbl_client`.`id` end)) AS count")) ->where('tbl_appointment.app_status', '=', 'LTFU') ->pluck('count'); - }); - $appointment_ltfu_to_twentyfour = Cache::remember('appointment_ltfu_to_twentyfour', 10, function () { - return Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') - ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 20) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 24)) then `tbl_client`.`id` end)) AS count")) + }); + $appointment_ltfu_to_twentyfour = Cache::remember('appointment_ltfu_to_twentyfour', 10, function () { + return Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 20) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 24)) then `tbl_client`.`id` end)) AS count")) ->where('tbl_appointment.app_status', '=', 'LTFU') ->pluck('count'); - }); - $appointment_ltfu_to_twentyfive_above = Cache::remember('appointment_ltfu_to_twentyfive_above', 10, function () { - return Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') - ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 25)) then `tbl_client`.`id` end)) AS count")) + }); + $appointment_ltfu_to_twentyfive_above = Cache::remember('appointment_ltfu_to_twentyfive_above', 10, function () { + return Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 25)) then `tbl_client`.`id` end)) AS count")) ->where('tbl_appointment.app_status', '=', 'LTFU') ->pluck('count'); - }); - $appointment_ltfu_to_uknown_age = Cache::remember('appointment_ltfu_to_uknown_age', 10, function () { - return Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + }); + $appointment_ltfu_to_uknown_age = Cache::remember('appointment_ltfu_to_uknown_age', 10, function () { + return Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') ->select('tbl_client.dob') ->where('tbl_client.dob', '=', '') ->orWhereNull('tbl_client.dob') ->where('tbl_appointment.app_status', '=', 'LTFU') ->count(); - }); + }); } - - return view('new_dashboard.missed_dashboard', compact('all_partners', 'indicator', - 'appointment_not_honoured', - 'appointment_missed', - 'appointment_defaulted', - 'appointment_lftu', - 'appointment_missed_female', - 'appointment_missed_male', - 'appointment_missed_uknown_gender', - 'appointment_missed_to_nine', - 'appointment_missed_to_fourteen', - 'appointment_missed_to_nineteen', - 'appointment_missed_to_twentyfour', - 'appointment_missed_to_twentyfive_above', - 'appointment_missed_to_uknown_age', - 'appointment_defaulted_female', - 'appointment_defaulted_male', - 'appointment_defaulted_uknown_gender', - 'appointment_defaulted_to_nine', - 'appointment_defaulted_to_fourteen', - 'appointment_defaulted_to_nineteen', - 'appointment_defaulted_to_twentyfour', - 'appointment_defaulted_to_twentyfive_above', - 'appointment_defaulted_to_uknown_age', - 'appointment_ltfu_female', - 'appointment_ltfu_male', - 'appointment_ltfu_uknown_gender', - 'appointment_ltfu_to_nine', - 'appointment_ltfu_to_fourteen', - 'appointment_ltfu_to_nineteen', - 'appointment_ltfu_to_twentyfour', - 'appointment_ltfu_to_twentyfive_above', - 'appointment_ltfu_to_uknown_age' - )); + return view('new_dashboard.missed_dashboard', compact( + 'all_partners', + 'indicator', + 'appointment_not_honoured', + 'appointment_missed', + 'appointment_defaulted', + 'appointment_lftu', + 'appointment_missed_female', + 'appointment_missed_male', + 'appointment_missed_uknown_gender', + 'appointment_missed_to_nine', + 'appointment_missed_to_fourteen', + 'appointment_missed_to_nineteen', + 'appointment_missed_to_twentyfour', + 'appointment_missed_to_twentyfive_above', + 'appointment_missed_to_uknown_age', + 'appointment_defaulted_female', + 'appointment_defaulted_male', + 'appointment_defaulted_uknown_gender', + 'appointment_defaulted_to_nine', + 'appointment_defaulted_to_fourteen', + 'appointment_defaulted_to_nineteen', + 'appointment_defaulted_to_twentyfour', + 'appointment_defaulted_to_twentyfive_above', + 'appointment_defaulted_to_uknown_age', + 'appointment_ltfu_female', + 'appointment_ltfu_male', + 'appointment_ltfu_uknown_gender', + 'appointment_ltfu_to_nine', + 'appointment_ltfu_to_fourteen', + 'appointment_ltfu_to_nineteen', + 'appointment_ltfu_to_twentyfour', + 'appointment_ltfu_to_twentyfive_above', + 'appointment_ltfu_to_uknown_age' + )); } public function filter_charts(Request $request) { // $data = []; - $selected_partners = $request->partners; - $selected_counties = $request->counties; - $selected_subcounties = $request->subcounties; - $selected_facilites = $request->facilities; + $selected_partners = $request->partners; + $selected_counties = $request->counties; + $selected_subcounties = $request->subcounties; + $selected_facilites = $request->facilities; - if (Auth::user()->access_level == 'Facility'){} - if (Auth::user()->access_level == 'Partner'){} - $all_partners = Partner::where('status', '=', 'Active')->pluck('name', 'id'); - $indicator = Indicator::select(['name', 'description'])->get(); + if (Auth::user()->access_level == 'Facility') { + } + if (Auth::user()->access_level == 'Partner') { + } + $all_partners = Partner::where('status', '=', 'Active')->pluck('name', 'id'); + $indicator = Indicator::select(['name', 'description'])->get(); - $client = Client::join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + $client = Client::join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') ->where('tbl_client.status', '=', 'Active') ->whereNull('tbl_client.hei_no') ->where('tbl_client.created_at', '>=', date($request->from))->where('tbl_client.created_at', '<=', date($request->to)); - $appointment = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + $appointment = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') ->select('tbl_appointment.id') ->where('tbl_appointment.created_at', '>=', date($request->from))->where('tbl_appointment.created_at', '<=', date($request->to)); - $missed_appointment = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + $missed_appointment = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') ->select('tbl_appointment.id') ->whereIn('tbl_appointment.app_status', ['Defaulted', 'LTFU', 'Missed']) ->where('tbl_appointment.created_at', '>=', date($request->from))->where('tbl_appointment.created_at', '<=', date($request->to)); - $active_facilities = PartnerFacility::join('tbl_client', 'tbl_partner_facility.mfl_code', '=', 'tbl_client.mfl_code') - ->join('tbl_appointment', 'tbl_client.id', '=', 'tbl_appointment.client_id') - ->select('tbl_partner_facility.mfl_code') - ->where('tbl_appointment.created_at', '>=', Carbon::now()->subMonths(6)) - ->where('tbl_appointment.created_at', '>=', date($request->from))->where('tbl_appointment.created_at', '<=', date($request->to)) - ->orderBy('tbl_appointment.created_at', 'DESC') - ->groupBy('tbl_partner_facility.mfl_code') - ->get(); - // active clients by gender - $clients_male = Client::join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + $active_facilities = PartnerFacility::join('tbl_client', 'tbl_partner_facility.mfl_code', '=', 'tbl_client.mfl_code') + ->join('tbl_appointment', 'tbl_client.id', '=', 'tbl_appointment.client_id') + ->select('tbl_partner_facility.mfl_code') + ->where('tbl_appointment.created_at', '>=', Carbon::now()->subMonths(6)) + ->where('tbl_appointment.created_at', '>=', date($request->from))->where('tbl_appointment.created_at', '<=', date($request->to)) + ->orderBy('tbl_appointment.created_at', 'DESC') + ->groupBy('tbl_partner_facility.mfl_code') + ->get(); + // active clients by gender + $clients_male = Client::join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') ->select('tbl_client.id') ->where([['tbl_client.gender', '=', '2'], ['tbl_client.status', '=', 'Active'],]) - ->whereNull('tbl_client.hei_no') - ->where('tbl_client.created_at', '>=', date($request->from))->where('tbl_client.created_at', '<=', date($request->to)); + ->whereNull('tbl_client.hei_no') + ->where('tbl_client.created_at', '>=', date($request->from))->where('tbl_client.created_at', '<=', date($request->to)); - $clients_female = Client::join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + $clients_female = Client::join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') ->where([['tbl_client.gender', '=', '2'], ['tbl_client.status', '=', 'Active'],]) - ->whereNull('tbl_client.hei_no') - ->where('tbl_client.created_at', '>=', date($request->from))->where('tbl_client.created_at', '<=', date($request->to)); - $unknown_gender = Client::join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->whereNull('tbl_client.hei_no') + ->where('tbl_client.created_at', '>=', date($request->from))->where('tbl_client.created_at', '<=', date($request->to)); + $unknown_gender = Client::join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') ->where([['tbl_client.gender', '!=', '1'], ['tbl_client.gender', '!=', '2'], ['tbl_client.status', '=', 'Active'],]) - ->whereNull('tbl_client.hei_no') - ->where('tbl_client.created_at', '>=', date($request->from))->where('tbl_client.created_at', '<=', date($request->to)); + ->whereNull('tbl_client.hei_no') + ->where('tbl_client.created_at', '>=', date($request->from))->where('tbl_client.created_at', '<=', date($request->to)); - $client_to_nine = Client::join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + $client_to_nine = Client::join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') ->select(\DB::raw("case when (((year(curdate()) - year(`tbl_client`.`dob`)) > 0) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 9)) then `tbl_client`.`dob` end")) - ->where('tbl_client.status', '=', 'Active') - ->whereNull('tbl_client.hei_no') - ->where('tbl_client.created_at', '>=', date($request->from))->where('tbl_client.created_at', '<=', date($request->to)); + ->where('tbl_client.status', '=', 'Active') + ->whereNull('tbl_client.hei_no') + ->where('tbl_client.created_at', '>=', date($request->from))->where('tbl_client.created_at', '<=', date($request->to)); - $client_to_fourteen = Client::join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + $client_to_fourteen = Client::join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') ->select(\DB::raw("case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 10) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 14)) then `tbl_client`.`dob` end")) - ->where('tbl_client.status', '=', 'Active') - ->whereNull('tbl_client.hei_no') - ->where('tbl_client.created_at', '>=', date($request->from))->where('tbl_client.created_at', '<=', date($request->to)); + ->where('tbl_client.status', '=', 'Active') + ->whereNull('tbl_client.hei_no') + ->where('tbl_client.created_at', '>=', date($request->from))->where('tbl_client.created_at', '<=', date($request->to)); - $client_to_nineteen = Client::join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + $client_to_nineteen = Client::join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') ->select(\DB::raw("case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 15) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 19)) then `tbl_client`.`dob` end")) - ->where('tbl_client.status', '=', 'Active') - ->whereNull('tbl_client.hei_no') - ->where('tbl_client.created_at', '>=', date($request->from))->where('tbl_client.created_at', '<=', date($request->to)); + ->where('tbl_client.status', '=', 'Active') + ->whereNull('tbl_client.hei_no') + ->where('tbl_client.created_at', '>=', date($request->from))->where('tbl_client.created_at', '<=', date($request->to)); - $client_to_twentyfour = Client::join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + $client_to_twentyfour = Client::join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') ->select(\DB::raw("case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 20) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 24)) then `id` end")) - ->where('tbl_client.status', '=', 'Active') - ->whereNull('tbl_client.hei_no') - ->where('tbl_client.created_at', '>=', date($request->from))->where('tbl_client.created_at', '<=', date($request->to)); + ->where('tbl_client.status', '=', 'Active') + ->whereNull('tbl_client.hei_no') + ->where('tbl_client.created_at', '>=', date($request->from))->where('tbl_client.created_at', '<=', date($request->to)); - $client_to_twentyfive_above = Client::join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + $client_to_twentyfive_above = Client::join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') ->select(\DB::raw("case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 25)) then `id` end")) - ->where('tbl_client.status', '=', 'Active') - ->whereNull('tbl_client.hei_no') - ->where('tbl_client.created_at', '>=', date($request->from))->where('tbl_client.created_at', '<=', date($request->to)); + ->where('tbl_client.status', '=', 'Active') + ->whereNull('tbl_client.hei_no') + ->where('tbl_client.created_at', '>=', date($request->from))->where('tbl_client.created_at', '<=', date($request->to)); - $client_unknown_age = Client::join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + $client_unknown_age = Client::join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') ->where('tbl_client.dob', '=', '') - ->orWhereNull('tbl_client.dob') - ->where('tbl_client.status', '=', 'Active') - ->whereNull('tbl_client.hei_no') - ->where('tbl_client.created_at', '>=', date($request->from))->where('tbl_client.created_at', '<=', date($request->to)); + ->orWhereNull('tbl_client.dob') + ->where('tbl_client.status', '=', 'Active') + ->whereNull('tbl_client.hei_no') + ->where('tbl_client.created_at', '>=', date($request->from))->where('tbl_client.created_at', '<=', date($request->to)); - // appointment by gender - $appointment_male = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + // appointment by gender + $appointment_male = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') - ->select('tbl_appointment.id') - ->where('tbl_client.gender', '=', '2') - ->where('tbl_appointment.created_at', '>=', date($request->from))->where('tbl_appointment.created_at', '<=', date($request->to)); + ->select('tbl_appointment.id') + ->where('tbl_client.gender', '=', '2') + ->where('tbl_appointment.created_at', '>=', date($request->from))->where('tbl_appointment.created_at', '<=', date($request->to)); - $appointment_female = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + $appointment_female = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') - ->select('tbl_appointment.id') - ->where('tbl_client.gender', '=', '1') - ->where('tbl_appointment.created_at', '>=', date($request->from))->where('tbl_appointment.created_at', '<=', date($request->to)); + ->select('tbl_appointment.id') + ->where('tbl_client.gender', '=', '1') + ->where('tbl_appointment.created_at', '>=', date($request->from))->where('tbl_appointment.created_at', '<=', date($request->to)); - $appointment_uknown_gender = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + $appointment_uknown_gender = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') - ->select('tbl_appointment.id') - ->where('tbl_client.gender', '!=', '1') - ->where('tbl_client.gender', '!=', '2') - ->where('tbl_appointment.created_at', '>=', date($request->from))->where('tbl_appointment.created_at', '<=', date($request->to)); + ->select('tbl_appointment.id') + ->where('tbl_client.gender', '!=', '1') + ->where('tbl_client.gender', '!=', '2') + ->where('tbl_appointment.created_at', '>=', date($request->from))->where('tbl_appointment.created_at', '<=', date($request->to)); - // appointment by age - $appointment_to_nine = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') - ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') - ->select(\DB::raw("case when (((year(curdate()) - year(`tbl_client`.`tbl_client`.`dob`)) > 0) and ((year(curdate()) - year(`tbl_client`.`tbl_client`.`dob`)) <= 9)) then `tbl_client`.`id` end")) - ->where('tbl_appointment.created_at', '>=', date($request->from))->where('tbl_appointment.created_at', '<=', date($request->to)); + // appointment by age + $appointment_to_nine = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select(\DB::raw("case when (((year(curdate()) - year(`tbl_client`.`tbl_client`.`dob`)) > 0) and ((year(curdate()) - year(`tbl_client`.`tbl_client`.`dob`)) <= 9)) then `tbl_client`.`id` end")) + ->where('tbl_appointment.created_at', '>=', date($request->from))->where('tbl_appointment.created_at', '<=', date($request->to)); - $appointment_to_fourteen = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') - ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') - ->select(\DB::raw("case when (((year(curdate()) - year(`tbl_client`.`tbl_client`.`dob`)) >= 10) and ((year(curdate()) - year(`tbl_client`.`tbl_client`.`dob`)) <= 14)) then `tbl_client`.`id` end")) - ->where('tbl_appointment.created_at', '>=', date($request->from))->where('tbl_appointment.created_at', '<=', date($request->to)); + $appointment_to_fourteen = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select(\DB::raw("case when (((year(curdate()) - year(`tbl_client`.`tbl_client`.`dob`)) >= 10) and ((year(curdate()) - year(`tbl_client`.`tbl_client`.`dob`)) <= 14)) then `tbl_client`.`id` end")) + ->where('tbl_appointment.created_at', '>=', date($request->from))->where('tbl_appointment.created_at', '<=', date($request->to)); - $appointment_to_nineteen = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + $appointment_to_nineteen = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') - ->select(\DB::raw("case when (((year(curdate()) - year(`tbl_client`.`tbl_client`.`dob`)) >= 15) and ((year(curdate()) - year(`tbl_client`.`tbl_client`.`dob`)) <= 19)) then `tbl_client`.`id` end")) - ->where('tbl_appointment.created_at', '>=', date($request->from))->where('tbl_appointment.created_at', '<=', date($request->to)); + ->select(\DB::raw("case when (((year(curdate()) - year(`tbl_client`.`tbl_client`.`dob`)) >= 15) and ((year(curdate()) - year(`tbl_client`.`tbl_client`.`dob`)) <= 19)) then `tbl_client`.`id` end")) + ->where('tbl_appointment.created_at', '>=', date($request->from))->where('tbl_appointment.created_at', '<=', date($request->to)); - $appointment_to_twentyfour = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + $appointment_to_twentyfour = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') - ->select(\DB::raw("case when (((year(curdate()) - year(`tbl_client`.`tbl_client`.`dob`)) >= 20) and ((year(curdate()) - year(`tbl_client`.`tbl_client`.`dob`)) <= 24)) then `tbl_client`.`id` end")) - ->where('tbl_appointment.created_at', '>=', date($request->from))->where('tbl_appointment.created_at', '<=', date($request->to)); + ->select(\DB::raw("case when (((year(curdate()) - year(`tbl_client`.`tbl_client`.`dob`)) >= 20) and ((year(curdate()) - year(`tbl_client`.`tbl_client`.`dob`)) <= 24)) then `tbl_client`.`id` end")) + ->where('tbl_appointment.created_at', '>=', date($request->from))->where('tbl_appointment.created_at', '<=', date($request->to)); - $appointment_to_twentyfive_above = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + $appointment_to_twentyfive_above = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') - ->select(\DB::raw("case when (((year(curdate()) - year(`tbl_client`.`tbl_client`.`dob`)) >= 25)) then `tbl_client`.`id` end")) - ->where('tbl_appointment.created_at', '>=', date($request->from))->where('tbl_appointment.created_at', '<=', date($request->to)); + ->select(\DB::raw("case when (((year(curdate()) - year(`tbl_client`.`tbl_client`.`dob`)) >= 25)) then `tbl_client`.`id` end")) + ->where('tbl_appointment.created_at', '>=', date($request->from))->where('tbl_appointment.created_at', '<=', date($request->to)); - $appointment_uknown_age = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + $appointment_uknown_age = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') - ->where('tbl_client.dob', '=', '') - ->orWhereNull('tbl_client.dob') - ->where('tbl_appointment.created_at', '>=', date($request->from))->where('tbl_appointment.created_at', '<=', date($request->to)); + ->where('tbl_client.dob', '=', '') + ->orWhereNull('tbl_client.dob') + ->where('tbl_appointment.created_at', '>=', date($request->from))->where('tbl_appointment.created_at', '<=', date($request->to)); - // Total missed appointment by gender - $appointment_total_missed_female = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + // Total missed appointment by gender + $appointment_total_missed_female = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') ->whereIn('tbl_appointment.app_status', ['Defaulted', 'LTFU', 'Missed']) - ->where('tbl_client.gender', '=', '1') - ->where('tbl_appointment.created_at', '>=', date($request->from))->where('tbl_appointment.created_at', '<=', date($request->to)); + ->where('tbl_client.gender', '=', '1') + ->where('tbl_appointment.created_at', '>=', date($request->from))->where('tbl_appointment.created_at', '<=', date($request->to)); - $appointment_total_missed_male = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + $appointment_total_missed_male = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') - ->where('tbl_client.gender', '=', '2') - ->whereIn('tbl_appointment.app_status', ['Defaulted', 'LTFU', 'Missed']) - ->where('tbl_appointment.created_at', '>=', date($request->from))->where('tbl_appointment.created_at', '<=', date($request->to)); + ->where('tbl_client.gender', '=', '2') + ->whereIn('tbl_appointment.app_status', ['Defaulted', 'LTFU', 'Missed']) + ->where('tbl_appointment.created_at', '>=', date($request->from))->where('tbl_appointment.created_at', '<=', date($request->to)); - $appointment_total_missed_uknown_gender = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + $appointment_total_missed_uknown_gender = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') - ->whereIn('tbl_appointment.app_status', ['Defaulted', 'LTFU', 'Missed']) - ->where('tbl_client.gender', '!=', '1') - ->where('tbl_client.gender', '!=', '2') - ->where('tbl_appointment.created_at', '>=', date($request->from))->where('tbl_appointment.created_at', '<=', date($request->to)); + ->whereIn('tbl_appointment.app_status', ['Defaulted', 'LTFU', 'Missed']) + ->where('tbl_client.gender', '!=', '1') + ->where('tbl_client.gender', '!=', '2') + ->where('tbl_appointment.created_at', '>=', date($request->from))->where('tbl_appointment.created_at', '<=', date($request->to)); - // Total missed appointment by age - $appointment_total_missed_to_nine = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + // Total missed appointment by age + $appointment_total_missed_to_nine = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') - ->select(\DB::raw("case when (((year(curdate()) - year(`tbl_client`.`tbl_client`.`dob`)) > 0) and ((year(curdate()) - year(`tbl_client`.`tbl_client`.`dob`)) <= 9)) then `tbl_client`.`id` end")) - ->whereIn('tbl_appointment.app_status', ['Defaulted', 'LTFU', 'Missed']) - ->where('tbl_appointment.created_at', '>=', date($request->from))->where('tbl_appointment.created_at', '<=', date($request->to)); + ->select(\DB::raw("case when (((year(curdate()) - year(`tbl_client`.`tbl_client`.`dob`)) > 0) and ((year(curdate()) - year(`tbl_client`.`tbl_client`.`dob`)) <= 9)) then `tbl_client`.`id` end")) + ->whereIn('tbl_appointment.app_status', ['Defaulted', 'LTFU', 'Missed']) + ->where('tbl_appointment.created_at', '>=', date($request->from))->where('tbl_appointment.created_at', '<=', date($request->to)); - $appointment_total_missed_to_fourteen = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + $appointment_total_missed_to_fourteen = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') - ->select(\DB::raw("case when (((year(curdate()) - year(`tbl_client`.`tbl_client`.`dob`)) >= 10) and ((year(curdate()) - year(`tbl_client`.`tbl_client`.`dob`)) <= 14)) then `tbl_client`.`id` end")) - ->whereIn('tbl_appointment.app_status', ['Defaulted', 'LTFU', 'Missed']) - ->where('tbl_appointment.created_at', '>=', date($request->from))->where('tbl_appointment.created_at', '<=', date($request->to)); + ->select(\DB::raw("case when (((year(curdate()) - year(`tbl_client`.`tbl_client`.`dob`)) >= 10) and ((year(curdate()) - year(`tbl_client`.`tbl_client`.`dob`)) <= 14)) then `tbl_client`.`id` end")) + ->whereIn('tbl_appointment.app_status', ['Defaulted', 'LTFU', 'Missed']) + ->where('tbl_appointment.created_at', '>=', date($request->from))->where('tbl_appointment.created_at', '<=', date($request->to)); - $appointment_total_missed_to_nineteen = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + $appointment_total_missed_to_nineteen = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') - ->select(\DB::raw("case when (((year(curdate()) - year(`tbl_client`.`tbl_client`.`dob`)) >= 15) and ((year(curdate()) - year(`tbl_client`.`tbl_client`.`dob`)) <= 19)) then `tbl_client`.`id` end")) - ->whereIn('tbl_appointment.app_status', ['Defaulted', 'LTFU', 'Missed']) - ->where('tbl_appointment.created_at', '>=', date($request->from))->where('tbl_appointment.created_at', '<=', date($request->to)); + ->select(\DB::raw("case when (((year(curdate()) - year(`tbl_client`.`tbl_client`.`dob`)) >= 15) and ((year(curdate()) - year(`tbl_client`.`tbl_client`.`dob`)) <= 19)) then `tbl_client`.`id` end")) + ->whereIn('tbl_appointment.app_status', ['Defaulted', 'LTFU', 'Missed']) + ->where('tbl_appointment.created_at', '>=', date($request->from))->where('tbl_appointment.created_at', '<=', date($request->to)); - $appointment_total_missed_to_twentyfour = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + $appointment_total_missed_to_twentyfour = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') - ->select(\DB::raw("case when (((year(curdate()) - year(`tbl_client`.`tbl_client`.`dob`)) >= 20) and ((year(curdate()) - year(`tbl_client`.`tbl_client`.`dob`)) <= 24)) then `tbl_client`.`id` end")) - ->whereIn('tbl_appointment.app_status', ['Defaulted', 'LTFU', 'Missed']) - ->where('tbl_appointment.created_at', '>=', date($request->from))->where('tbl_appointment.created_at', '<=', date($request->to)); + ->select(\DB::raw("case when (((year(curdate()) - year(`tbl_client`.`tbl_client`.`dob`)) >= 20) and ((year(curdate()) - year(`tbl_client`.`tbl_client`.`dob`)) <= 24)) then `tbl_client`.`id` end")) + ->whereIn('tbl_appointment.app_status', ['Defaulted', 'LTFU', 'Missed']) + ->where('tbl_appointment.created_at', '>=', date($request->from))->where('tbl_appointment.created_at', '<=', date($request->to)); - $appointment_total_missed_to_twentyfive_above = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + $appointment_total_missed_to_twentyfive_above = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') - ->select(\DB::raw("case when (((year(curdate()) - year(`tbl_client`.`tbl_client`.`dob`)) >= 25)) then `tbl_client`.`id` end")) - ->whereIn('tbl_appointment.app_status', ['Defaulted', 'LTFU', 'Missed']) - ->where('tbl_appointment.created_at', '>=', date($request->from))->where('tbl_appointment.created_at', '<=', date($request->to)); + ->select(\DB::raw("case when (((year(curdate()) - year(`tbl_client`.`tbl_client`.`dob`)) >= 25)) then `tbl_client`.`id` end")) + ->whereIn('tbl_appointment.app_status', ['Defaulted', 'LTFU', 'Missed']) + ->where('tbl_appointment.created_at', '>=', date($request->from))->where('tbl_appointment.created_at', '<=', date($request->to)); - $appointment_total_missed_uknown_age = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + $appointment_total_missed_uknown_age = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') - ->orWhereNull('tbl_client.dob') - ->whereIn('tbl_appointment.app_status', ['Defaulted', 'LTFU', 'Missed']) - ->where('tbl_appointment.created_at', '>=', date($request->from))->where('tbl_appointment.created_at', '<=', date($request->to)); + ->orWhereNull('tbl_client.dob') + ->whereIn('tbl_appointment.app_status', ['Defaulted', 'LTFU', 'Missed']) + ->where('tbl_appointment.created_at', '>=', date($request->from))->where('tbl_appointment.created_at', '<=', date($request->to)); - // client charts - $client_consented = Client::join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + // client charts + $client_consented = Client::join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') ->select('tbl_client.id') - ->where('tbl_client.status', '=', 'Active') - ->whereNull('tbl_client.hei_no') - ->where('tbl_client.smsenable', '=', 'Yes') - ->where('tbl_client.created_at', '>=', date($request->from))->where('tbl_client.created_at', '<=', date($request->to)); + ->where('tbl_client.status', '=', 'Active') + ->whereNull('tbl_client.hei_no') + ->where('tbl_client.smsenable', '=', 'Yes') + ->where('tbl_client.created_at', '>=', date($request->from))->where('tbl_client.created_at', '<=', date($request->to)); - $client_nonconsented = Client::join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + $client_nonconsented = Client::join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') ->select('tbl_client.id') - ->where('tbl_client.status', '=', 'Active') - ->whereNull('tbl_client.hei_no') - ->where('tbl_client.smsenable', '!=', 'Yes') - ->where('tbl_client.created_at', '>=', date($request->from))->where('tbl_client.created_at', '<=', date($request->to)); + ->where('tbl_client.status', '=', 'Active') + ->whereNull('tbl_client.hei_no') + ->where('tbl_client.smsenable', '!=', 'Yes') + ->where('tbl_client.created_at', '>=', date($request->from))->where('tbl_client.created_at', '<=', date($request->to)); - // consented clients by gender + // consented clients by gender - $client_consented_male = Client::join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + $client_consented_male = Client::join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') ->where('tbl_client.smsenable', '=', 'Yes') - ->where('tbl_client.status', '=', 'Active') - ->whereNull('tbl_client.hei_no') - ->where('tbl_client.gender', '=', '2') - ->where('tbl_client.created_at', '>=', date($request->from))->where('tbl_client.created_at', '<=', date($request->to)); + ->where('tbl_client.status', '=', 'Active') + ->whereNull('tbl_client.hei_no') + ->where('tbl_client.gender', '=', '2') + ->where('tbl_client.created_at', '>=', date($request->from))->where('tbl_client.created_at', '<=', date($request->to)); - $client_consented_female = Client::join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + $client_consented_female = Client::join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') ->where('tbl_client.smsenable', '=', 'Yes') - ->where('tbl_client.status', '=', 'Active') - ->whereNull('tbl_client.hei_no') - ->where('tbl_client.gender', '=', '1') - ->where('tbl_client.created_at', '>=', date($request->from))->where('tbl_client.created_at', '<=', date($request->to)); + ->where('tbl_client.status', '=', 'Active') + ->whereNull('tbl_client.hei_no') + ->where('tbl_client.gender', '=', '1') + ->where('tbl_client.created_at', '>=', date($request->from))->where('tbl_client.created_at', '<=', date($request->to)); - $client_consented_uknown_gender = Client::join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + $client_consented_uknown_gender = Client::join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') ->where('tbl_client.smsenable', '=', 'Yes') - ->where('tbl_client.status', '=', 'Active') - ->whereNull('tbl_client.hei_no') - ->where('tbl_client.gender', '!=', '1') - ->where('tbl_client.gender', '!=', '2') - ->where('tbl_client.created_at', '>=', date($request->from))->where('tbl_client.created_at', '<=', date($request->to)); + ->where('tbl_client.status', '=', 'Active') + ->whereNull('tbl_client.hei_no') + ->where('tbl_client.gender', '!=', '1') + ->where('tbl_client.gender', '!=', '2') + ->where('tbl_client.created_at', '>=', date($request->from))->where('tbl_client.created_at', '<=', date($request->to)); - // non consented clients by gender - $client_nonconsented_male = Client::join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + // non consented clients by gender + $client_nonconsented_male = Client::join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') ->where('tbl_client.smsenable', '!=', 'Yes') - ->where('tbl_client.status', '=', 'Active') - ->whereNull('tbl_client.hei_no') - ->where('tbl_client.gender', '=', '2') - ->where('tbl_client.created_at', '>=', date($request->from))->where('tbl_client.created_at', '<=', date($request->to)); + ->where('tbl_client.status', '=', 'Active') + ->whereNull('tbl_client.hei_no') + ->where('tbl_client.gender', '=', '2') + ->where('tbl_client.created_at', '>=', date($request->from))->where('tbl_client.created_at', '<=', date($request->to)); - $client_nonconsented_female = Client::join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + $client_nonconsented_female = Client::join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') ->where('tbl_client.smsenable', '!=', 'Yes') - ->where('tbl_client.status', '=', 'Active') - ->whereNull('tbl_client.hei_no') - ->where('tbl_client.gender', '=', '1') - ->where('tbl_client.created_at', '>=', date($request->from))->where('tbl_client.created_at', '<=', date($request->to)); + ->where('tbl_client.status', '=', 'Active') + ->whereNull('tbl_client.hei_no') + ->where('tbl_client.gender', '=', '1') + ->where('tbl_client.created_at', '>=', date($request->from))->where('tbl_client.created_at', '<=', date($request->to)); - $client_nonconsented_uknown_gender = Client::join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + $client_nonconsented_uknown_gender = Client::join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') ->where('tbl_client.smsenable', '!=', 'Yes') - ->where('tbl_client.gender', '!=', '1') - ->where('tbl_client.gender', '!=', '2') - ->where('tbl_client.created_at', '>=', date($request->from))->where('tbl_client.created_at', '<=', date($request->to)); + ->where('tbl_client.gender', '!=', '1') + ->where('tbl_client.gender', '!=', '2') + ->where('tbl_client.created_at', '>=', date($request->from))->where('tbl_client.created_at', '<=', date($request->to)); - // consented clients by age distribution - $client_consented_to_nine = Client::join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + // consented clients by age distribution + $client_consented_to_nine = Client::join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') ->select(\DB::raw("case when (((year(curdate()) - year(`tbl_client`.`tbl_client`.`dob`)) > 0) and ((year(curdate()) - year(`tbl_client`.`tbl_client`.`dob`)) <= 9)) then `tbl_client`.`id` end")) - ->where('tbl_client.smsenable', '=', 'Yes') - ->where('tbl_client.status', '=', 'Active') - ->whereNull('tbl_client.hei_no') - ->where('tbl_client.created_at', '>=', date($request->from))->where('tbl_client.created_at', '<=', date($request->to)); + ->where('tbl_client.smsenable', '=', 'Yes') + ->where('tbl_client.status', '=', 'Active') + ->whereNull('tbl_client.hei_no') + ->where('tbl_client.created_at', '>=', date($request->from))->where('tbl_client.created_at', '<=', date($request->to)); - $client_consented_to_fourteen = Client::join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + $client_consented_to_fourteen = Client::join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') ->select(\DB::raw("case when (((year(curdate()) - year(`tbl_client`.`tbl_client`.`dob`)) >= 10) and ((year(curdate()) - year(`tbl_client`.`tbl_client`.`dob`)) <= 14)) then `tbl_client`.`id` end")) - ->where('tbl_client.smsenable', '=', 'Yes') - ->where('tbl_client.status', '=', 'Active') - ->whereNull('tbl_client.hei_no') - ->where('tbl_client.created_at', '>=', date($request->from))->where('tbl_client.created_at', '<=', date($request->to)); + ->where('tbl_client.smsenable', '=', 'Yes') + ->where('tbl_client.status', '=', 'Active') + ->whereNull('tbl_client.hei_no') + ->where('tbl_client.created_at', '>=', date($request->from))->where('tbl_client.created_at', '<=', date($request->to)); - $client_consented_to_nineteen = Client::join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + $client_consented_to_nineteen = Client::join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') ->select(\DB::raw("case when (((year(curdate()) - year(`tbl_client`.`tbl_client`.`dob`)) >= 15) and ((year(curdate()) - year(`tbl_client`.`tbl_client`.`dob`)) <= 19)) then `tbl_client`.`id` end")) - ->where('tbl_client.smsenable', '=', 'Yes') - ->where('tbl_client.status', '=', 'Active') - ->whereNull('tbl_client.hei_no') - ->where('tbl_client.created_at', '>=', date($request->from))->where('tbl_client.created_at', '<=', date($request->to)); + ->where('tbl_client.smsenable', '=', 'Yes') + ->where('tbl_client.status', '=', 'Active') + ->whereNull('tbl_client.hei_no') + ->where('tbl_client.created_at', '>=', date($request->from))->where('tbl_client.created_at', '<=', date($request->to)); - $client_consented_to_twentyfour = Client::join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + $client_consented_to_twentyfour = Client::join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') ->select(\DB::raw("case when (((year(curdate()) - year(`tbl_client`.`tbl_client`.`dob`)) >= 20) and ((year(curdate()) - year(`tbl_client`.`tbl_client`.`dob`)) <= 24)) then `tbl_client`.`id` end")) - ->where('tbl_client.smsenable', '=', 'Yes') - ->where('tbl_client.status', '=', 'Active') - ->whereNull('tbl_client.hei_no') - ->where('tbl_client.created_at', '>=', date($request->from))->where('tbl_client.created_at', '<=', date($request->to)); + ->where('tbl_client.smsenable', '=', 'Yes') + ->where('tbl_client.status', '=', 'Active') + ->whereNull('tbl_client.hei_no') + ->where('tbl_client.created_at', '>=', date($request->from))->where('tbl_client.created_at', '<=', date($request->to)); - $client_consented_to_twentyfive_above = Client::join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + $client_consented_to_twentyfive_above = Client::join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') ->select(\DB::raw("case when (((year(curdate()) - year(`tbl_client`.`tbl_client`.`dob`)) >= 25)) then `tbl_client`.`id` end")) - ->where('tbl_client.smsenable', '=', 'Yes') - ->where('tbl_client.status', '=', 'Active') - ->whereNull('tbl_client.hei_no') - ->where('tbl_client.created_at', '>=', date($request->from))->where('tbl_client.created_at', '<=', date($request->to)); + ->where('tbl_client.smsenable', '=', 'Yes') + ->where('tbl_client.status', '=', 'Active') + ->whereNull('tbl_client.hei_no') + ->where('tbl_client.created_at', '>=', date($request->from))->where('tbl_client.created_at', '<=', date($request->to)); - $client_consented_uknown_age = Client::join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + $client_consented_uknown_age = Client::join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') ->select('tbl_client.smsenable') - ->where('tbl_client.dob', '=', '') - ->where('tbl_client.status', '=', 'Active') - ->whereNull('tbl_client.hei_no') - ->orWhereNull('tbl_client.dob') - ->where('tbl_client.smsenable', '=', 'Yes') - ->where('tbl_client.created_at', '>=', date($request->from))->where('tbl_client.created_at', '<=', date($request->to)); + ->where('tbl_client.dob', '=', '') + ->where('tbl_client.status', '=', 'Active') + ->whereNull('tbl_client.hei_no') + ->orWhereNull('tbl_client.dob') + ->where('tbl_client.smsenable', '=', 'Yes') + ->where('tbl_client.created_at', '>=', date($request->from))->where('tbl_client.created_at', '<=', date($request->to)); - // non consented clients by age distribution - $client_nonconsented_to_nine = Client::join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + // non consented clients by age distribution + $client_nonconsented_to_nine = Client::join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') ->select(\DB::raw("case when (((year(curdate()) - year(`tbl_client`.`tbl_client`.`dob`)) > 0) and ((year(curdate()) - year(`tbl_client`.`tbl_client`.`dob`)) <= 9)) then `tbl_client`.`id` end")) - ->where('tbl_client.smsenable', '!=', 'Yes') - ->where('tbl_client.status', '=', 'Active') - ->whereNull('tbl_client.hei_no') - ->where('tbl_client.created_at', '>=', date($request->from))->where('tbl_client.created_at', '<=', date($request->to)); + ->where('tbl_client.smsenable', '!=', 'Yes') + ->where('tbl_client.status', '=', 'Active') + ->whereNull('tbl_client.hei_no') + ->where('tbl_client.created_at', '>=', date($request->from))->where('tbl_client.created_at', '<=', date($request->to)); - $client_nonconsented_to_fourteen = Client::join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + $client_nonconsented_to_fourteen = Client::join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') ->select(\DB::raw("case when (((year(curdate()) - year(`tbl_client`.`tbl_client`.`dob`)) >= 10) and ((year(curdate()) - year(`tbl_client`.`tbl_client`.`dob`)) <= 14)) then `tbl_client`.`id` end")) - ->where('tbl_client.smsenable', '!=', 'Yes') - ->where('tbl_client.status', '=', 'Active') - ->whereNull('tbl_client.hei_no') - ->where('tbl_client.created_at', '>=', date($request->from))->where('tbl_client.created_at', '<=', date($request->to)); + ->where('tbl_client.smsenable', '!=', 'Yes') + ->where('tbl_client.status', '=', 'Active') + ->whereNull('tbl_client.hei_no') + ->where('tbl_client.created_at', '>=', date($request->from))->where('tbl_client.created_at', '<=', date($request->to)); - $client_nonconsented_to_nineteen = Client::join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + $client_nonconsented_to_nineteen = Client::join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') ->select(\DB::raw("case when (((year(curdate()) - year(`tbl_client`.`tbl_client`.`dob`)) >= 15) and ((year(curdate()) - year(`tbl_client`.`tbl_client`.`dob`)) <= 19)) then `tbl_client`.`id` end")) - ->where('tbl_client.smsenable', '!=', 'Yes') - ->where('tbl_client.status', '=', 'Active') - ->whereNull('tbl_client.hei_no') - ->where('tbl_client.created_at', '>=', date($request->from))->where('tbl_client.created_at', '<=', date($request->to)); + ->where('tbl_client.smsenable', '!=', 'Yes') + ->where('tbl_client.status', '=', 'Active') + ->whereNull('tbl_client.hei_no') + ->where('tbl_client.created_at', '>=', date($request->from))->where('tbl_client.created_at', '<=', date($request->to)); - $client_nonconsented_to_twentyfour = Client::join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + $client_nonconsented_to_twentyfour = Client::join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') ->select(\DB::raw("case when (((year(curdate()) - year(`tbl_client`.`tbl_client`.`dob`)) >= 20) and ((year(curdate()) - year(`tbl_client`.`tbl_client`.`dob`)) <= 24)) then `tbl_client`.`id` end")) - ->where('tbl_client.smsenable', '!=', 'Yes') - ->where('tbl_client.status', '=', 'Active') - ->whereNull('tbl_client.hei_no') - ->where('tbl_client.created_at', '>=', date($request->from))->where('tbl_client.created_at', '<=', date($request->to)); + ->where('tbl_client.smsenable', '!=', 'Yes') + ->where('tbl_client.status', '=', 'Active') + ->whereNull('tbl_client.hei_no') + ->where('tbl_client.created_at', '>=', date($request->from))->where('tbl_client.created_at', '<=', date($request->to)); - $client_nonconsented_to_twentyfive_above = Client::join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + $client_nonconsented_to_twentyfive_above = Client::join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') ->select(\DB::raw("case when (((year(curdate()) - year(`tbl_client`.`tbl_client`.`dob`)) >= 25)) then `tbl_client`.`id` end")) - ->where('tbl_client.smsenable', '!=', 'Yes') - ->where('tbl_client.status', '=', 'Active') - ->whereNull('tbl_client.hei_no') - ->where('tbl_client.created_at', '>=', date($request->from))->where('tbl_client.created_at', '<=', date($request->to)); + ->where('tbl_client.smsenable', '!=', 'Yes') + ->where('tbl_client.status', '=', 'Active') + ->whereNull('tbl_client.hei_no') + ->where('tbl_client.created_at', '>=', date($request->from))->where('tbl_client.created_at', '<=', date($request->to)); - $client_nonconsented_uknown_age = Client::join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + $client_nonconsented_uknown_age = Client::join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') ->select('tbl_client.smsenable') - ->where('tbl_client.status', '=', 'Active') - ->whereNull('tbl_client.hei_no') - ->where('tbl_client.dob', '=', '') - ->orWhereNull('tbl_client.dob') - ->where('tbl_client.smsenable', '!=', 'Yes') - ->where('tbl_client.created_at', '>=', date($request->from))->where('tbl_client.created_at', '<=', date($request->to)); + ->where('tbl_client.status', '=', 'Active') + ->whereNull('tbl_client.hei_no') + ->where('tbl_client.dob', '=', '') + ->orWhereNull('tbl_client.dob') + ->where('tbl_client.smsenable', '!=', 'Yes') + ->where('tbl_client.created_at', '>=', date($request->from))->where('tbl_client.created_at', '<=', date($request->to)); - if (!empty($selected_partners)) { - $client = $client->where('tbl_partner_facility.partner_id', $selected_partners); - $appointment = $appointment->where('tbl_partner_facility.partner_id', $selected_partners); - $missed_appointment = $missed_appointment->where('tbl_partner_facility.partner_id', $selected_partners); - // $active_facilities = $active_facilities->where('tbl_partner_facility.partner_id', $selected_partners); - $clients_male = $clients_male->where('tbl_partner_facility.partner_id', $selected_partners); - $clients_female = $clients_female->where('tbl_partner_facility.partner_id', $selected_partners); - $unknown_gender = $unknown_gender->where('tbl_partner_facility.partner_id', $selected_partners); - $client_to_nine = $client_to_nine->where('tbl_partner_facility.partner_id', $selected_partners); - $client_to_fourteen = $client_to_fourteen->where('tbl_partner_facility.partner_id', $selected_partners); - $client_to_nineteen = $client_to_nineteen->where('tbl_partner_facility.partner_id', $selected_partners); - $client_to_twentyfour = $client_to_twentyfour->where('tbl_partner_facility.partner_id', $selected_partners); - $client_to_twentyfive_above = $client_to_twentyfive_above->where('tbl_partner_facility.partner_id', $selected_partners); - $client_unknown_age = $client_unknown_age->where('tbl_partner_facility.partner_id', $selected_partners); - $appointment_male = $appointment_male->where('tbl_partner_facility.partner_id', $selected_partners); - $appointment_female = $appointment_female->where('tbl_partner_facility.partner_id', $selected_partners); - $appointment_uknown_gender = $appointment_uknown_gender->where('tbl_partner_facility.partner_id', $selected_partners); - $appointment_to_nine = $appointment_to_nine->where('tbl_partner_facility.partner_id', $selected_partners); - $appointment_to_fourteen = $appointment_to_fourteen->where('tbl_partner_facility.partner_id', $selected_partners); - $appointment_to_nineteen = $appointment_to_nineteen->where('tbl_partner_facility.partner_id', $selected_partners); - $appointment_to_twentyfour = $appointment_to_twentyfour->where('tbl_partner_facility.partner_id', $selected_partners); - $appointment_to_twentyfive_above = $appointment_to_twentyfive_above->where('tbl_partner_facility.partner_id', $selected_partners); - $appointment_uknown_age = $appointment_uknown_age->where('tbl_partner_facility.partner_id', $selected_partners); - $appointment_total_missed_female = $appointment_total_missed_female->where('tbl_partner_facility.partner_id', $selected_partners); - $appointment_total_missed_male = $appointment_total_missed_male->where('tbl_partner_facility.partner_id', $selected_partners); - $appointment_total_missed_uknown_gender = $appointment_total_missed_uknown_gender->where('tbl_partner_facility.partner_id', $selected_partners); - $appointment_total_missed_to_nine = $appointment_total_missed_to_nine->where('tbl_partner_facility.partner_id', $selected_partners); - $appointment_total_missed_to_fourteen = $appointment_total_missed_to_fourteen->where('tbl_partner_facility.partner_id', $selected_partners); - $appointment_total_missed_to_nineteen = $appointment_total_missed_to_nineteen->where('tbl_partner_facility.partner_id', $selected_partners); - $appointment_total_missed_to_twentyfour = $appointment_total_missed_to_twentyfour->where('tbl_partner_facility.partner_id', $selected_partners); - $appointment_total_missed_to_twentyfive_above = $appointment_total_missed_to_twentyfive_above->where('tbl_partner_facility.partner_id', $selected_partners); - $appointment_total_missed_uknown_age = $appointment_total_missed_uknown_age->where('tbl_partner_facility.partner_id', $selected_partners); - - $client_consented = $client_consented->where('tbl_partner_facility.partner_id', $selected_partners); - $client_nonconsented = $client_nonconsented->where('tbl_partner_facility.partner_id', $selected_partners); - $client_consented_male = $client_consented_male->where('tbl_partner_facility.partner_id', $selected_partners); - $client_consented_female = $client_consented_female->where('tbl_partner_facility.partner_id', $selected_partners); - $client_consented_uknown_gender = $client_consented_uknown_gender->where('tbl_partner_facility.partner_id', $selected_partners); - $client_nonconsented_male = $client_nonconsented_male->where('tbl_partner_facility.partner_id', $selected_partners); - $client_nonconsented_female = $client_nonconsented_female->where('tbl_partner_facility.partner_id', $selected_partners); - $client_nonconsented_uknown_gender = $client_nonconsented_uknown_gender->where('tbl_partner_facility.partner_id', $selected_partners); - $client_consented_to_nine = $client_consented_to_nine->where('tbl_partner_facility.partner_id', $selected_partners); - $client_consented_to_fourteen = $client_consented_to_fourteen->where('tbl_partner_facility.partner_id', $selected_partners); - $client_consented_to_nineteen = $client_consented_to_nineteen->where('tbl_partner_facility.partner_id', $selected_partners); - $client_consented_to_twentyfour = $client_consented_to_twentyfour->where('tbl_partner_facility.partner_id', $selected_partners); - $client_consented_to_twentyfive_above = $client_consented_to_twentyfive_above->where('tbl_partner_facility.partner_id', $selected_partners); - $client_consented_uknown_age = $client_consented_uknown_age->where('tbl_partner_facility.partner_id', $selected_partners); - $client_nonconsented_to_nine = $client_nonconsented_to_nine->where('tbl_partner_facility.partner_id', $selected_partners); - $client_nonconsented_to_fourteen = $client_nonconsented_to_fourteen->where('tbl_partner_facility.partner_id', $selected_partners); - $client_nonconsented_to_nineteen = $client_nonconsented_to_nineteen->where('tbl_partner_facility.partner_id', $selected_partners); - $client_nonconsented_to_twentyfour = $client_nonconsented_to_twentyfour->where('tbl_partner_facility.partner_id', $selected_partners); - $client_nonconsented_to_twentyfive_above = $client_nonconsented_to_twentyfive_above->where('tbl_partner_facility.partner_id', $selected_partners); - $client_nonconsented_uknown_age = $client_nonconsented_uknown_age->where('tbl_partner_facility.partner_id', $selected_partners); - } - if (!empty($selected_counties)) { - $client = $client->where('tbl_partner_facility.county_id', $selected_counties); - $appointment = $appointment->where('tbl_partner_facility.county_id', $selected_counties); - $missed_appointment = $missed_appointment->where('tbl_partner_facility.county_id', $selected_counties); - // $active_facilities = $active_facilities->where('tbl_partner_facility.county_id', $selected_counties); - $clients_male = $clients_male->where('tbl_partner_facility.county_id', $selected_counties); - $clients_female = $clients_female->where('tbl_partner_facility.county_id', $selected_counties); - $unknown_gender = $unknown_gender->where('tbl_partner_facility.county_id', $selected_counties); - $client_to_nine = $client_to_nine->where('tbl_partner_facility.county_id', $selected_counties); - $client_to_fourteen = $client_to_fourteen->where('tbl_partner_facility.county_id', $selected_counties); - $client_to_nineteen = $client_to_nineteen->where('tbl_partner_facility.county_id', $selected_counties); - $client_to_twentyfour = $client_to_twentyfour->where('tbl_partner_facility.county_id', $selected_counties); - $client_to_twentyfive_above = $client_to_twentyfive_above->where('tbl_partner_facility.county_id', $selected_counties); - $client_unknown_age = $client_unknown_age->where('tbl_partner_facility.county_id', $selected_counties); - $appointment_male = $appointment_male->where('tbl_partner_facility.county_id', $selected_counties); - $appointment_female = $appointment_female->where('tbl_partner_facility.county_id', $selected_counties); - $appointment_uknown_gender = $appointment_uknown_gender->where('tbl_partner_facility.county_id', $selected_counties); - $appointment_to_nine = $appointment_to_nine->where('tbl_partner_facility.county_id', $selected_counties); - $appointment_to_fourteen = $appointment_to_fourteen->where('tbl_partner_facility.county_id', $selected_counties); - $appointment_to_nineteen = $appointment_to_nineteen->where('tbl_partner_facility.county_id', $selected_counties); - $appointment_to_twentyfour = $appointment_to_twentyfour->where('tbl_partner_facility.county_id', $selected_counties); - $appointment_to_twentyfive_above = $appointment_to_twentyfive_above->where('tbl_partner_facility.county_id', $selected_counties); - $appointment_uknown_age = $appointment_uknown_age->where('tbl_partner_facility.county_id', $selected_counties); - $appointment_total_missed_female = $appointment_total_missed_female->where('tbl_partner_facility.county_id', $selected_counties); - $appointment_total_missed_male = $appointment_total_missed_male->where('tbl_partner_facility.county_id', $selected_counties); - $appointment_total_missed_uknown_gender = $appointment_total_missed_uknown_gender->where('tbl_partner_facility.county_id', $selected_counties); - $appointment_total_missed_to_nine = $appointment_total_missed_to_nine->where('tbl_partner_facility.county_id', $selected_counties); - $appointment_total_missed_to_fourteen = $appointment_total_missed_to_fourteen->where('tbl_partner_facility.county_id', $selected_counties); - $appointment_total_missed_to_nineteen = $appointment_total_missed_to_nineteen->where('tbl_partner_facility.county_id', $selected_counties); - $appointment_total_missed_to_twentyfour = $appointment_total_missed_to_twentyfour->where('tbl_partner_facility.county_id', $selected_counties); - $appointment_total_missed_to_twentyfive_above = $appointment_total_missed_to_twentyfive_above->where('tbl_partner_facility.county_id', $selected_counties); - $appointment_total_missed_uknown_age = $appointment_total_missed_uknown_age->where('tbl_partner_facility.county_id', $selected_counties); - - $client_consented = $client_consented->where('tbl_partner_facility.county_id', $selected_counties); - $client_nonconsented = $client_nonconsented->where('tbl_partner_facility.county_id', $selected_counties); - $client_consented_male = $client_consented_male->where('tbl_partner_facility.county_id', $selected_counties); - $client_consented_female = $client_consented_female->where('tbl_partner_facility.county_id', $selected_counties); - $client_consented_uknown_gender = $client_consented_uknown_gender->where('tbl_partner_facility.county_id', $selected_counties); - $client_nonconsented_male = $client_nonconsented_male->where('tbl_partner_facility.county_id', $selected_counties); - $client_nonconsented_female = $client_nonconsented_female->where('tbl_partner_facility.county_id', $selected_counties); - $client_nonconsented_uknown_gender = $client_nonconsented_uknown_gender->where('tbl_partner_facility.county_id', $selected_counties); - $client_consented_to_nine = $client_consented_to_nine->where('tbl_partner_facility.county_id', $selected_counties); - $client_consented_to_fourteen = $client_consented_to_fourteen->where('tbl_partner_facility.county_id', $selected_counties); - $client_consented_to_nineteen = $client_consented_to_nineteen->where('tbl_partner_facility.county_id', $selected_counties); - $client_consented_to_twentyfour = $client_consented_to_twentyfour->where('tbl_partner_facility.county_id', $selected_counties); - $client_consented_to_twentyfive_above = $client_consented_to_twentyfive_above->where('tbl_partner_facility.county_id', $selected_counties); - $client_consented_uknown_age = $client_consented_uknown_age->where('tbl_partner_facility.county_id', $selected_counties); - $client_nonconsented_to_nine = $client_nonconsented_to_nine->where('tbl_partner_facility.county_id', $selected_counties); - $client_nonconsented_to_fourteen = $client_nonconsented_to_fourteen->where('tbl_partner_facility.county_id', $selected_counties); - $client_nonconsented_to_nineteen = $client_nonconsented_to_nineteen->where('tbl_partner_facility.county_id', $selected_counties); - $client_nonconsented_to_twentyfour = $client_nonconsented_to_twentyfour->where('tbl_partner_facility.county_id', $selected_counties); - $client_nonconsented_to_twentyfive_above = $client_nonconsented_to_twentyfive_above->where('tbl_partner_facility.county_id', $selected_counties); - $client_nonconsented_uknown_age = $client_nonconsented_uknown_age->where('tbl_partner_facility.county_id', $selected_counties); - } - if (!empty($selected_subcounties)) { - $client = $client->where('tbl_partner_facility.sub_county_id', $selected_subcounties); - $appointment = $appointment->where('tbl_partner_facility.sub_county_id', $selected_subcounties); - $missed_appointment = $missed_appointment->where('tbl_partner_facility.sub_county_id', $selected_subcounties); - // $active_facilities = $active_facilities->where('tbl_partner_facility.sub_county_id', $selected_subcounties); - $clients_male = $clients_male->where('tbl_partner_facility.sub_county_id', $selected_subcounties); - $clients_female = $clients_female->where('tbl_partner_facility.sub_county_id', $selected_subcounties); - $unknown_gender = $unknown_gender->where('tbl_partner_facility.sub_county_id', $selected_subcounties); - $client_to_nine = $client_to_nine->where('tbl_partner_facility.sub_county_id', $selected_subcounties); - $client_to_fourteen = $client_to_fourteen->where('tbl_partner_facility.sub_county_id', $selected_subcounties); - $client_to_nineteen = $client_to_nineteen->where('tbl_partner_facility.sub_county_id', $selected_subcounties); - $client_to_twentyfour = $client_to_twentyfour->where('tbl_partner_facility.sub_county_id', $selected_subcounties); - $client_to_twentyfive_above = $client_to_twentyfive_above->where('tbl_partner_facility.sub_county_id', $selected_subcounties); - $client_unknown_age = $client_unknown_age->where('tbl_partner_facility.sub_county_id', $selected_subcounties); - $appointment_male = $appointment_male->where('tbl_partner_facility.sub_county_id', $selected_subcounties); - $appointment_female = $appointment_female->where('tbl_partner_facility.sub_county_id', $selected_subcounties); - $appointment_uknown_gender = $appointment_uknown_gender->where('tbl_partner_facility.sub_county_id', $selected_subcounties); - $appointment_to_nine = $appointment_to_nine->where('tbl_partner_facility.sub_county_id', $selected_subcounties); - $appointment_to_fourteen = $appointment_to_fourteen->where('tbl_partner_facility.sub_county_id', $selected_subcounties); - $appointment_to_nineteen = $appointment_to_nineteen->where('tbl_partner_facility.sub_county_id', $selected_subcounties); - $appointment_to_twentyfour = $appointment_to_twentyfour->where('tbl_partner_facility.sub_county_id', $selected_subcounties); - $appointment_to_twentyfive_above = $appointment_to_twentyfive_above->where('tbl_partner_facility.sub_county_id', $selected_subcounties); - $appointment_uknown_age = $appointment_uknown_age->where('tbl_partner_facility.sub_county_id', $selected_subcounties); - $appointment_total_missed_female = $appointment_total_missed_female->where('tbl_partner_facility.sub_county_id', $selected_subcounties); - $appointment_total_missed_male = $appointment_total_missed_male->where('tbl_partner_facility.sub_county_id', $selected_subcounties); - $appointment_total_missed_uknown_gender = $appointment_total_missed_uknown_gender->where('tbl_partner_facility.sub_county_id', $selected_subcounties); - $appointment_total_missed_to_nine = $appointment_total_missed_to_nine->where('tbl_partner_facility.sub_county_id', $selected_subcounties); - $appointment_total_missed_to_fourteen = $appointment_total_missed_to_fourteen->where('tbl_partner_facility.sub_county_id', $selected_subcounties); - $appointment_total_missed_to_nineteen = $appointment_total_missed_to_nineteen->where('tbl_partner_facility.sub_county_id', $selected_subcounties); - $appointment_total_missed_to_twentyfour = $appointment_total_missed_to_twentyfour->where('tbl_partner_facility.sub_county_id', $selected_subcounties); - $appointment_total_missed_to_twentyfive_above = $appointment_total_missed_to_twentyfive_above->where('tbl_partner_facility.sub_county_id', $selected_subcounties); - $appointment_total_missed_uknown_age = $appointment_total_missed_uknown_age->where('tbl_partner_facility.sub_county_id', $selected_subcounties); - - $client_consented = $client_consented->where('tbl_partner_facility.sub_county_id', $selected_subcounties); - $client_nonconsented = $client_nonconsented->where('tbl_partner_facility.sub_county_id', $selected_subcounties); - $client_consented_male = $client_consented_male->where('tbl_partner_facility.sub_county_id', $selected_subcounties); - $client_consented_female = $client_consented_female->where('tbl_partner_facility.sub_county_id', $selected_subcounties); - $client_consented_uknown_gender = $client_consented_uknown_gender->where('tbl_partner_facility.sub_county_id', $selected_subcounties); - $client_nonconsented_male = $client_nonconsented_male->where('tbl_partner_facility.sub_county_id', $selected_subcounties); - $client_nonconsented_female = $client_nonconsented_female->where('tbl_partner_facility.sub_county_id', $selected_subcounties); - $client_nonconsented_uknown_gender = $client_nonconsented_uknown_gender->where('tbl_partner_facility.sub_county_id', $selected_subcounties); - $client_consented_to_nine = $client_consented_to_nine->where('tbl_partner_facility.sub_county_id', $selected_subcounties); - $client_consented_to_fourteen = $client_consented_to_fourteen->where('tbl_partner_facility.sub_county_id', $selected_subcounties); - $client_consented_to_nineteen = $client_consented_to_nineteen->where('tbl_partner_facility.sub_county_id', $selected_subcounties); - $client_consented_to_twentyfour = $client_consented_to_twentyfour->where('tbl_partner_facility.sub_county_id', $selected_subcounties); - $client_consented_to_twentyfive_above = $client_consented_to_twentyfive_above->where('tbl_partner_facility.sub_county_id', $selected_subcounties); - $client_consented_uknown_age = $client_consented_uknown_age->where('tbl_partner_facility.sub_county_id', $selected_subcounties); - $client_nonconsented_to_nine = $client_nonconsented_to_nine->where('tbl_partner_facility.sub_county_id', $selected_subcounties); - $client_nonconsented_to_fourteen = $client_nonconsented_to_fourteen->where('tbl_partner_facility.sub_county_id', $selected_subcounties); - $client_nonconsented_to_nineteen = $client_nonconsented_to_nineteen->where('tbl_partner_facility.sub_county_id', $selected_subcounties); - $client_nonconsented_to_twentyfour = $client_nonconsented_to_twentyfour->where('tbl_partner_facility.sub_county_id', $selected_subcounties); - $client_nonconsented_to_twentyfive_above = $client_nonconsented_to_twentyfive_above->where('tbl_partner_facility.sub_county_id', $selected_subcounties); - $client_nonconsented_uknown_age = $client_nonconsented_uknown_age->where('tbl_partner_facility.sub_county_id', $selected_subcounties); - } - if (!empty($selected_facilites)) { - $client = $client->where('tbl_partner_facility.mfl_code', $selected_facilites); - $appointment = $appointment->where('tbl_partner_facility.mfl_code', $selected_facilites); - // $missed_appointment = $missed_appointment->where('tbl_partner_facility.mfl_code', $selected_facilites); - $active_facilities = $active_facilities->where('tbl_partner_facility.mfl_code', $selected_facilites); - $clients_male = $clients_male->where('tbl_partner_facility.mfl_code', $selected_facilites); - $clients_female = $clients_female->where('tbl_partner_facility.mfl_code', $selected_facilites); - $unknown_gender = $unknown_gender->where('tbl_partner_facility.mfl_code', $selected_facilites); - $client_to_nine = $client_to_nine->where('tbl_partner_facility.mfl_code', $selected_facilites); - $client_to_fourteen = $client_to_fourteen->where('tbl_partner_facility.mfl_code', $selected_facilites); - $client_to_nineteen = $client_to_nineteen->where('tbl_partner_facility.mfl_code', $selected_facilites); - $client_to_twentyfour = $client_to_twentyfour->where('tbl_partner_facility.mfl_code', $selected_facilites); - $client_to_twentyfive_above = $client_to_twentyfive_above->where('tbl_partner_facility.mfl_code', $selected_facilites); - $client_unknown_age = $client_unknown_age->where('tbl_partner_facility.mfl_code', $selected_facilites); - $appointment_male = $appointment_male->where('tbl_partner_facility.mfl_code', $selected_facilites); - $appointment_female = $appointment_female->where('tbl_partner_facility.mfl_code', $selected_facilites); - $appointment_uknown_gender = $appointment_uknown_gender->where('tbl_partner_facility.mfl_code', $selected_facilites); - $appointment_to_nine = $appointment_to_nine->where('tbl_partner_facility.mfl_code', $selected_facilites); - $appointment_to_fourteen = $appointment_to_fourteen->where('tbl_partner_facility.mfl_code', $selected_facilites); - $appointment_to_nineteen = $appointment_to_nineteen->where('tbl_partner_facility.mfl_code', $selected_facilites); - $appointment_to_twentyfour = $appointment_to_twentyfour->where('tbl_partner_facility.mfl_code', $selected_facilites); - $appointment_to_twentyfive_above = $appointment_to_twentyfive_above->where('tbl_partner_facility.mfl_code', $selected_facilites); - $appointment_uknown_age = $appointment_uknown_age->where('tbl_partner_facility.mfl_code', $selected_facilites); - $appointment_total_missed_female = $appointment_total_missed_female->where('tbl_partner_facility.mfl_code', $selected_facilites); - $appointment_total_missed_male = $appointment_total_missed_male->where('tbl_partner_facility.mfl_code', $selected_facilites); - $appointment_total_missed_uknown_gender = $appointment_total_missed_uknown_gender->where('tbl_partner_facility.mfl_code', $selected_facilites); - $appointment_total_missed_to_nine = $appointment_total_missed_to_nine->where('tbl_partner_facility.mfl_code', $selected_facilites); - $appointment_total_missed_to_fourteen = $appointment_total_missed_to_fourteen->where('tbl_partner_facility.mfl_code', $selected_facilites); - $appointment_total_missed_to_nineteen = $appointment_total_missed_to_nineteen->where('tbl_partner_facility.mfl_code', $selected_facilites); - $appointment_total_missed_to_twentyfour = $appointment_total_missed_to_twentyfour->where('tbl_partner_facility.mfl_code', $selected_facilites); - $appointment_total_missed_to_twentyfive_above = $appointment_total_missed_to_twentyfive_above->where('tbl_partner_facility.mfl_code', $selected_facilites); - $appointment_total_missed_uknown_age = $appointment_total_missed_uknown_age->where('tbl_partner_facility.mfl_code', $selected_facilites); - - $client_consented = $client_consented->where('tbl_partner_facility.mfl_code', $selected_facilites); - $client_nonconsented = $client_nonconsented->where('tbl_partner_facility.mfl_code', $selected_facilites); - $client_consented_male = $client_consented_male->where('tbl_partner_facility.mfl_code', $selected_facilites); - $client_consented_female = $client_consented_female->where('tbl_partner_facility.mfl_code', $selected_facilites); - $client_consented_uknown_gender = $client_consented_uknown_gender->where('tbl_partner_facility.mfl_code', $selected_facilites); - $client_nonconsented_male = $client_nonconsented_male->where('tbl_partner_facility.mfl_code', $selected_facilites); - $client_nonconsented_female = $client_nonconsented_female->where('tbl_partner_facility.mfl_code', $selected_facilites); - $client_nonconsented_uknown_gender = $client_nonconsented_uknown_gender->where('tbl_partner_facility.mfl_code', $selected_facilites); - $client_consented_to_nine = $client_consented_to_nine->where('tbl_partner_facility.mfl_code', $selected_facilites); - $client_consented_to_fourteen = $client_consented_to_fourteen->where('tbl_partner_facility.mfl_code', $selected_facilites); - $client_consented_to_nineteen = $client_consented_to_nineteen->where('tbl_partner_facility.mfl_code', $selected_facilites); - $client_consented_to_twentyfour = $client_consented_to_twentyfour->where('tbl_partner_facility.mfl_code', $selected_facilites); - $client_consented_to_twentyfive_above = $client_consented_to_twentyfive_above->where('tbl_partner_facility.mfl_code', $selected_facilites); - $client_consented_uknown_age = $client_consented_uknown_age->where('tbl_partner_facility.mfl_code', $selected_facilites); - $client_nonconsented_to_nine = $client_nonconsented_to_nine->where('tbl_partner_facility.mfl_code', $selected_facilites); - $client_nonconsented_to_fourteen = $client_nonconsented_to_fourteen->where('tbl_partner_facility.mfl_code', $selected_facilites); - $client_nonconsented_to_nineteen = $client_nonconsented_to_nineteen->where('tbl_partner_facility.mfl_code', $selected_facilites); - $client_nonconsented_to_twentyfour = $client_nonconsented_to_twentyfour->where('tbl_partner_facility.mfl_code', $selected_facilites); - $client_nonconsented_to_twentyfive_above = $client_nonconsented_to_twentyfive_above->where('tbl_partner_facility.mfl_code', $selected_facilites); - $client_nonconsented_uknown_age = $client_nonconsented_uknown_age->where('tbl_partner_facility.mfl_code', $selected_facilites); - } - $data["client"] = $client->count(); - $data["appointment"] = $appointment->count(); - $data["missed_appointment"] = $missed_appointment->count(); - $data["clients_male"] = $clients_male->count(); - $data["clients_female"] = $clients_female->count(); - $data["unknown_gender"] = $unknown_gender->count(); - $data["client_to_nine"] = $client_to_nine->count(); - $data["client_to_fourteen"] = $client_to_fourteen->count(); - $data["client_to_nineteen"] = $client_to_nineteen->count(); - $data["client_to_twentyfour"] = $client_to_twentyfour->count(); - $data["client_to_twentyfive_above"] = $client_to_twentyfive_above->count(); - $data["client_unknown_age"] = $client_unknown_age->count(); - $data["appointment_male"] = $appointment_male->count(); - $data["appointment_female"] = $appointment_female->count(); - $data["appointment_uknown_gender"] = $appointment_uknown_gender->count(); - $data["appointment_to_nine"] = $appointment_to_nine->count(); - $data["appointment_to_fourteen"] = $appointment_to_fourteen->count(); - $data["appointment_to_nineteen"] = $appointment_to_nineteen->count(); - $data["appointment_to_twentyfour"] = $appointment_to_twentyfour->count(); - $data["appointment_to_twentyfive_above"] = $appointment_to_twentyfive_above->count(); - $data["appointment_uknown_age"] = $appointment_uknown_age->count(); - $data["appointment_total_missed_female"] = $appointment_total_missed_female->count(); - $data["appointment_total_missed_male"] = $appointment_total_missed_male->count(); - $data["appointment_total_missed_uknown_gender"] = $appointment_total_missed_uknown_gender->count(); - $data["appointment_total_missed_to_nine"] = $appointment_total_missed_to_nine->count(); - $data["appointment_total_missed_to_fourteen"] = $appointment_total_missed_to_fourteen->count(); - $data["appointment_total_missed_to_nineteen"] = $appointment_total_missed_to_nineteen->count(); - $data["appointment_total_missed_to_twentyfour"] = $appointment_total_missed_to_twentyfour->count(); - $data["appointment_total_missed_to_twentyfive_above"] = $appointment_total_missed_to_twentyfive_above->count(); - $data["appointment_total_missed_uknown_age"] = $appointment_total_missed_uknown_age->count(); - - $data["client_consented"] = $client_consented->count(); - $data["client_nonconsented"] = $client_nonconsented->count(); - $data["client_consented_male"] = $client_consented_male->count(); - $data["client_consented_female"] = $client_consented_female->count(); - $data["client_consented_uknown_gender"] = $client_consented_uknown_gender->count(); - $data["client_nonconsented_male"] = $client_nonconsented_male->count(); - $data["client_nonconsented_female"] = $client_nonconsented_female->count(); - $data["client_nonconsented_uknown_gender"] = $client_nonconsented_uknown_gender->count(); - $data["client_consented_to_nine"] = $client_consented_to_nine->count(); - $data["client_consented_to_fourteen"] = $client_consented_to_fourteen->count(); - $data["client_consented_to_nineteen"] = $client_consented_to_nineteen->count(); - $data["client_consented_to_twentyfour"] = $client_consented_to_twentyfour->count(); - $data["client_consented_to_twentyfive_above"] = $client_consented_to_twentyfive_above->count(); - $data["client_consented_uknown_age"] = $client_consented_uknown_age->count(); - $data["client_nonconsented_to_nine"] = $client_nonconsented_to_nine->count(); - $data["client_nonconsented_to_fourteen"] = $client_nonconsented_to_fourteen->count(); - $data["client_nonconsented_to_nineteen"] = $client_nonconsented_to_nineteen->count(); - $data["client_nonconsented_to_twentyfour"] = $client_nonconsented_to_twentyfour->count(); - $data["client_nonconsented_to_twentyfive_above"] = $client_nonconsented_to_twentyfive_above->count(); - $data["client_nonconsented_uknown_age"] = $client_nonconsented_uknown_age->count(); + if (!empty($selected_partners)) { + $client = $client->where('tbl_partner_facility.partner_id', $selected_partners); + $appointment = $appointment->where('tbl_partner_facility.partner_id', $selected_partners); + $missed_appointment = $missed_appointment->where('tbl_partner_facility.partner_id', $selected_partners); + // $active_facilities = $active_facilities->where('tbl_partner_facility.partner_id', $selected_partners); + $clients_male = $clients_male->where('tbl_partner_facility.partner_id', $selected_partners); + $clients_female = $clients_female->where('tbl_partner_facility.partner_id', $selected_partners); + $unknown_gender = $unknown_gender->where('tbl_partner_facility.partner_id', $selected_partners); + $client_to_nine = $client_to_nine->where('tbl_partner_facility.partner_id', $selected_partners); + $client_to_fourteen = $client_to_fourteen->where('tbl_partner_facility.partner_id', $selected_partners); + $client_to_nineteen = $client_to_nineteen->where('tbl_partner_facility.partner_id', $selected_partners); + $client_to_twentyfour = $client_to_twentyfour->where('tbl_partner_facility.partner_id', $selected_partners); + $client_to_twentyfive_above = $client_to_twentyfive_above->where('tbl_partner_facility.partner_id', $selected_partners); + $client_unknown_age = $client_unknown_age->where('tbl_partner_facility.partner_id', $selected_partners); + $appointment_male = $appointment_male->where('tbl_partner_facility.partner_id', $selected_partners); + $appointment_female = $appointment_female->where('tbl_partner_facility.partner_id', $selected_partners); + $appointment_uknown_gender = $appointment_uknown_gender->where('tbl_partner_facility.partner_id', $selected_partners); + $appointment_to_nine = $appointment_to_nine->where('tbl_partner_facility.partner_id', $selected_partners); + $appointment_to_fourteen = $appointment_to_fourteen->where('tbl_partner_facility.partner_id', $selected_partners); + $appointment_to_nineteen = $appointment_to_nineteen->where('tbl_partner_facility.partner_id', $selected_partners); + $appointment_to_twentyfour = $appointment_to_twentyfour->where('tbl_partner_facility.partner_id', $selected_partners); + $appointment_to_twentyfive_above = $appointment_to_twentyfive_above->where('tbl_partner_facility.partner_id', $selected_partners); + $appointment_uknown_age = $appointment_uknown_age->where('tbl_partner_facility.partner_id', $selected_partners); + $appointment_total_missed_female = $appointment_total_missed_female->where('tbl_partner_facility.partner_id', $selected_partners); + $appointment_total_missed_male = $appointment_total_missed_male->where('tbl_partner_facility.partner_id', $selected_partners); + $appointment_total_missed_uknown_gender = $appointment_total_missed_uknown_gender->where('tbl_partner_facility.partner_id', $selected_partners); + $appointment_total_missed_to_nine = $appointment_total_missed_to_nine->where('tbl_partner_facility.partner_id', $selected_partners); + $appointment_total_missed_to_fourteen = $appointment_total_missed_to_fourteen->where('tbl_partner_facility.partner_id', $selected_partners); + $appointment_total_missed_to_nineteen = $appointment_total_missed_to_nineteen->where('tbl_partner_facility.partner_id', $selected_partners); + $appointment_total_missed_to_twentyfour = $appointment_total_missed_to_twentyfour->where('tbl_partner_facility.partner_id', $selected_partners); + $appointment_total_missed_to_twentyfive_above = $appointment_total_missed_to_twentyfive_above->where('tbl_partner_facility.partner_id', $selected_partners); + $appointment_total_missed_uknown_age = $appointment_total_missed_uknown_age->where('tbl_partner_facility.partner_id', $selected_partners); + + $client_consented = $client_consented->where('tbl_partner_facility.partner_id', $selected_partners); + $client_nonconsented = $client_nonconsented->where('tbl_partner_facility.partner_id', $selected_partners); + $client_consented_male = $client_consented_male->where('tbl_partner_facility.partner_id', $selected_partners); + $client_consented_female = $client_consented_female->where('tbl_partner_facility.partner_id', $selected_partners); + $client_consented_uknown_gender = $client_consented_uknown_gender->where('tbl_partner_facility.partner_id', $selected_partners); + $client_nonconsented_male = $client_nonconsented_male->where('tbl_partner_facility.partner_id', $selected_partners); + $client_nonconsented_female = $client_nonconsented_female->where('tbl_partner_facility.partner_id', $selected_partners); + $client_nonconsented_uknown_gender = $client_nonconsented_uknown_gender->where('tbl_partner_facility.partner_id', $selected_partners); + $client_consented_to_nine = $client_consented_to_nine->where('tbl_partner_facility.partner_id', $selected_partners); + $client_consented_to_fourteen = $client_consented_to_fourteen->where('tbl_partner_facility.partner_id', $selected_partners); + $client_consented_to_nineteen = $client_consented_to_nineteen->where('tbl_partner_facility.partner_id', $selected_partners); + $client_consented_to_twentyfour = $client_consented_to_twentyfour->where('tbl_partner_facility.partner_id', $selected_partners); + $client_consented_to_twentyfive_above = $client_consented_to_twentyfive_above->where('tbl_partner_facility.partner_id', $selected_partners); + $client_consented_uknown_age = $client_consented_uknown_age->where('tbl_partner_facility.partner_id', $selected_partners); + $client_nonconsented_to_nine = $client_nonconsented_to_nine->where('tbl_partner_facility.partner_id', $selected_partners); + $client_nonconsented_to_fourteen = $client_nonconsented_to_fourteen->where('tbl_partner_facility.partner_id', $selected_partners); + $client_nonconsented_to_nineteen = $client_nonconsented_to_nineteen->where('tbl_partner_facility.partner_id', $selected_partners); + $client_nonconsented_to_twentyfour = $client_nonconsented_to_twentyfour->where('tbl_partner_facility.partner_id', $selected_partners); + $client_nonconsented_to_twentyfive_above = $client_nonconsented_to_twentyfive_above->where('tbl_partner_facility.partner_id', $selected_partners); + $client_nonconsented_uknown_age = $client_nonconsented_uknown_age->where('tbl_partner_facility.partner_id', $selected_partners); + } + if (!empty($selected_counties)) { + $client = $client->where('tbl_partner_facility.county_id', $selected_counties); + $appointment = $appointment->where('tbl_partner_facility.county_id', $selected_counties); + $missed_appointment = $missed_appointment->where('tbl_partner_facility.county_id', $selected_counties); + // $active_facilities = $active_facilities->where('tbl_partner_facility.county_id', $selected_counties); + $clients_male = $clients_male->where('tbl_partner_facility.county_id', $selected_counties); + $clients_female = $clients_female->where('tbl_partner_facility.county_id', $selected_counties); + $unknown_gender = $unknown_gender->where('tbl_partner_facility.county_id', $selected_counties); + $client_to_nine = $client_to_nine->where('tbl_partner_facility.county_id', $selected_counties); + $client_to_fourteen = $client_to_fourteen->where('tbl_partner_facility.county_id', $selected_counties); + $client_to_nineteen = $client_to_nineteen->where('tbl_partner_facility.county_id', $selected_counties); + $client_to_twentyfour = $client_to_twentyfour->where('tbl_partner_facility.county_id', $selected_counties); + $client_to_twentyfive_above = $client_to_twentyfive_above->where('tbl_partner_facility.county_id', $selected_counties); + $client_unknown_age = $client_unknown_age->where('tbl_partner_facility.county_id', $selected_counties); + $appointment_male = $appointment_male->where('tbl_partner_facility.county_id', $selected_counties); + $appointment_female = $appointment_female->where('tbl_partner_facility.county_id', $selected_counties); + $appointment_uknown_gender = $appointment_uknown_gender->where('tbl_partner_facility.county_id', $selected_counties); + $appointment_to_nine = $appointment_to_nine->where('tbl_partner_facility.county_id', $selected_counties); + $appointment_to_fourteen = $appointment_to_fourteen->where('tbl_partner_facility.county_id', $selected_counties); + $appointment_to_nineteen = $appointment_to_nineteen->where('tbl_partner_facility.county_id', $selected_counties); + $appointment_to_twentyfour = $appointment_to_twentyfour->where('tbl_partner_facility.county_id', $selected_counties); + $appointment_to_twentyfive_above = $appointment_to_twentyfive_above->where('tbl_partner_facility.county_id', $selected_counties); + $appointment_uknown_age = $appointment_uknown_age->where('tbl_partner_facility.county_id', $selected_counties); + $appointment_total_missed_female = $appointment_total_missed_female->where('tbl_partner_facility.county_id', $selected_counties); + $appointment_total_missed_male = $appointment_total_missed_male->where('tbl_partner_facility.county_id', $selected_counties); + $appointment_total_missed_uknown_gender = $appointment_total_missed_uknown_gender->where('tbl_partner_facility.county_id', $selected_counties); + $appointment_total_missed_to_nine = $appointment_total_missed_to_nine->where('tbl_partner_facility.county_id', $selected_counties); + $appointment_total_missed_to_fourteen = $appointment_total_missed_to_fourteen->where('tbl_partner_facility.county_id', $selected_counties); + $appointment_total_missed_to_nineteen = $appointment_total_missed_to_nineteen->where('tbl_partner_facility.county_id', $selected_counties); + $appointment_total_missed_to_twentyfour = $appointment_total_missed_to_twentyfour->where('tbl_partner_facility.county_id', $selected_counties); + $appointment_total_missed_to_twentyfive_above = $appointment_total_missed_to_twentyfive_above->where('tbl_partner_facility.county_id', $selected_counties); + $appointment_total_missed_uknown_age = $appointment_total_missed_uknown_age->where('tbl_partner_facility.county_id', $selected_counties); + + $client_consented = $client_consented->where('tbl_partner_facility.county_id', $selected_counties); + $client_nonconsented = $client_nonconsented->where('tbl_partner_facility.county_id', $selected_counties); + $client_consented_male = $client_consented_male->where('tbl_partner_facility.county_id', $selected_counties); + $client_consented_female = $client_consented_female->where('tbl_partner_facility.county_id', $selected_counties); + $client_consented_uknown_gender = $client_consented_uknown_gender->where('tbl_partner_facility.county_id', $selected_counties); + $client_nonconsented_male = $client_nonconsented_male->where('tbl_partner_facility.county_id', $selected_counties); + $client_nonconsented_female = $client_nonconsented_female->where('tbl_partner_facility.county_id', $selected_counties); + $client_nonconsented_uknown_gender = $client_nonconsented_uknown_gender->where('tbl_partner_facility.county_id', $selected_counties); + $client_consented_to_nine = $client_consented_to_nine->where('tbl_partner_facility.county_id', $selected_counties); + $client_consented_to_fourteen = $client_consented_to_fourteen->where('tbl_partner_facility.county_id', $selected_counties); + $client_consented_to_nineteen = $client_consented_to_nineteen->where('tbl_partner_facility.county_id', $selected_counties); + $client_consented_to_twentyfour = $client_consented_to_twentyfour->where('tbl_partner_facility.county_id', $selected_counties); + $client_consented_to_twentyfive_above = $client_consented_to_twentyfive_above->where('tbl_partner_facility.county_id', $selected_counties); + $client_consented_uknown_age = $client_consented_uknown_age->where('tbl_partner_facility.county_id', $selected_counties); + $client_nonconsented_to_nine = $client_nonconsented_to_nine->where('tbl_partner_facility.county_id', $selected_counties); + $client_nonconsented_to_fourteen = $client_nonconsented_to_fourteen->where('tbl_partner_facility.county_id', $selected_counties); + $client_nonconsented_to_nineteen = $client_nonconsented_to_nineteen->where('tbl_partner_facility.county_id', $selected_counties); + $client_nonconsented_to_twentyfour = $client_nonconsented_to_twentyfour->where('tbl_partner_facility.county_id', $selected_counties); + $client_nonconsented_to_twentyfive_above = $client_nonconsented_to_twentyfive_above->where('tbl_partner_facility.county_id', $selected_counties); + $client_nonconsented_uknown_age = $client_nonconsented_uknown_age->where('tbl_partner_facility.county_id', $selected_counties); + } + if (!empty($selected_subcounties)) { + $client = $client->where('tbl_partner_facility.sub_county_id', $selected_subcounties); + $appointment = $appointment->where('tbl_partner_facility.sub_county_id', $selected_subcounties); + $missed_appointment = $missed_appointment->where('tbl_partner_facility.sub_county_id', $selected_subcounties); + // $active_facilities = $active_facilities->where('tbl_partner_facility.sub_county_id', $selected_subcounties); + $clients_male = $clients_male->where('tbl_partner_facility.sub_county_id', $selected_subcounties); + $clients_female = $clients_female->where('tbl_partner_facility.sub_county_id', $selected_subcounties); + $unknown_gender = $unknown_gender->where('tbl_partner_facility.sub_county_id', $selected_subcounties); + $client_to_nine = $client_to_nine->where('tbl_partner_facility.sub_county_id', $selected_subcounties); + $client_to_fourteen = $client_to_fourteen->where('tbl_partner_facility.sub_county_id', $selected_subcounties); + $client_to_nineteen = $client_to_nineteen->where('tbl_partner_facility.sub_county_id', $selected_subcounties); + $client_to_twentyfour = $client_to_twentyfour->where('tbl_partner_facility.sub_county_id', $selected_subcounties); + $client_to_twentyfive_above = $client_to_twentyfive_above->where('tbl_partner_facility.sub_county_id', $selected_subcounties); + $client_unknown_age = $client_unknown_age->where('tbl_partner_facility.sub_county_id', $selected_subcounties); + $appointment_male = $appointment_male->where('tbl_partner_facility.sub_county_id', $selected_subcounties); + $appointment_female = $appointment_female->where('tbl_partner_facility.sub_county_id', $selected_subcounties); + $appointment_uknown_gender = $appointment_uknown_gender->where('tbl_partner_facility.sub_county_id', $selected_subcounties); + $appointment_to_nine = $appointment_to_nine->where('tbl_partner_facility.sub_county_id', $selected_subcounties); + $appointment_to_fourteen = $appointment_to_fourteen->where('tbl_partner_facility.sub_county_id', $selected_subcounties); + $appointment_to_nineteen = $appointment_to_nineteen->where('tbl_partner_facility.sub_county_id', $selected_subcounties); + $appointment_to_twentyfour = $appointment_to_twentyfour->where('tbl_partner_facility.sub_county_id', $selected_subcounties); + $appointment_to_twentyfive_above = $appointment_to_twentyfive_above->where('tbl_partner_facility.sub_county_id', $selected_subcounties); + $appointment_uknown_age = $appointment_uknown_age->where('tbl_partner_facility.sub_county_id', $selected_subcounties); + $appointment_total_missed_female = $appointment_total_missed_female->where('tbl_partner_facility.sub_county_id', $selected_subcounties); + $appointment_total_missed_male = $appointment_total_missed_male->where('tbl_partner_facility.sub_county_id', $selected_subcounties); + $appointment_total_missed_uknown_gender = $appointment_total_missed_uknown_gender->where('tbl_partner_facility.sub_county_id', $selected_subcounties); + $appointment_total_missed_to_nine = $appointment_total_missed_to_nine->where('tbl_partner_facility.sub_county_id', $selected_subcounties); + $appointment_total_missed_to_fourteen = $appointment_total_missed_to_fourteen->where('tbl_partner_facility.sub_county_id', $selected_subcounties); + $appointment_total_missed_to_nineteen = $appointment_total_missed_to_nineteen->where('tbl_partner_facility.sub_county_id', $selected_subcounties); + $appointment_total_missed_to_twentyfour = $appointment_total_missed_to_twentyfour->where('tbl_partner_facility.sub_county_id', $selected_subcounties); + $appointment_total_missed_to_twentyfive_above = $appointment_total_missed_to_twentyfive_above->where('tbl_partner_facility.sub_county_id', $selected_subcounties); + $appointment_total_missed_uknown_age = $appointment_total_missed_uknown_age->where('tbl_partner_facility.sub_county_id', $selected_subcounties); + + $client_consented = $client_consented->where('tbl_partner_facility.sub_county_id', $selected_subcounties); + $client_nonconsented = $client_nonconsented->where('tbl_partner_facility.sub_county_id', $selected_subcounties); + $client_consented_male = $client_consented_male->where('tbl_partner_facility.sub_county_id', $selected_subcounties); + $client_consented_female = $client_consented_female->where('tbl_partner_facility.sub_county_id', $selected_subcounties); + $client_consented_uknown_gender = $client_consented_uknown_gender->where('tbl_partner_facility.sub_county_id', $selected_subcounties); + $client_nonconsented_male = $client_nonconsented_male->where('tbl_partner_facility.sub_county_id', $selected_subcounties); + $client_nonconsented_female = $client_nonconsented_female->where('tbl_partner_facility.sub_county_id', $selected_subcounties); + $client_nonconsented_uknown_gender = $client_nonconsented_uknown_gender->where('tbl_partner_facility.sub_county_id', $selected_subcounties); + $client_consented_to_nine = $client_consented_to_nine->where('tbl_partner_facility.sub_county_id', $selected_subcounties); + $client_consented_to_fourteen = $client_consented_to_fourteen->where('tbl_partner_facility.sub_county_id', $selected_subcounties); + $client_consented_to_nineteen = $client_consented_to_nineteen->where('tbl_partner_facility.sub_county_id', $selected_subcounties); + $client_consented_to_twentyfour = $client_consented_to_twentyfour->where('tbl_partner_facility.sub_county_id', $selected_subcounties); + $client_consented_to_twentyfive_above = $client_consented_to_twentyfive_above->where('tbl_partner_facility.sub_county_id', $selected_subcounties); + $client_consented_uknown_age = $client_consented_uknown_age->where('tbl_partner_facility.sub_county_id', $selected_subcounties); + $client_nonconsented_to_nine = $client_nonconsented_to_nine->where('tbl_partner_facility.sub_county_id', $selected_subcounties); + $client_nonconsented_to_fourteen = $client_nonconsented_to_fourteen->where('tbl_partner_facility.sub_county_id', $selected_subcounties); + $client_nonconsented_to_nineteen = $client_nonconsented_to_nineteen->where('tbl_partner_facility.sub_county_id', $selected_subcounties); + $client_nonconsented_to_twentyfour = $client_nonconsented_to_twentyfour->where('tbl_partner_facility.sub_county_id', $selected_subcounties); + $client_nonconsented_to_twentyfive_above = $client_nonconsented_to_twentyfive_above->where('tbl_partner_facility.sub_county_id', $selected_subcounties); + $client_nonconsented_uknown_age = $client_nonconsented_uknown_age->where('tbl_partner_facility.sub_county_id', $selected_subcounties); + } + if (!empty($selected_facilites)) { + $client = $client->where('tbl_partner_facility.mfl_code', $selected_facilites); + $appointment = $appointment->where('tbl_partner_facility.mfl_code', $selected_facilites); + // $missed_appointment = $missed_appointment->where('tbl_partner_facility.mfl_code', $selected_facilites); + $active_facilities = $active_facilities->where('tbl_partner_facility.mfl_code', $selected_facilites); + $clients_male = $clients_male->where('tbl_partner_facility.mfl_code', $selected_facilites); + $clients_female = $clients_female->where('tbl_partner_facility.mfl_code', $selected_facilites); + $unknown_gender = $unknown_gender->where('tbl_partner_facility.mfl_code', $selected_facilites); + $client_to_nine = $client_to_nine->where('tbl_partner_facility.mfl_code', $selected_facilites); + $client_to_fourteen = $client_to_fourteen->where('tbl_partner_facility.mfl_code', $selected_facilites); + $client_to_nineteen = $client_to_nineteen->where('tbl_partner_facility.mfl_code', $selected_facilites); + $client_to_twentyfour = $client_to_twentyfour->where('tbl_partner_facility.mfl_code', $selected_facilites); + $client_to_twentyfive_above = $client_to_twentyfive_above->where('tbl_partner_facility.mfl_code', $selected_facilites); + $client_unknown_age = $client_unknown_age->where('tbl_partner_facility.mfl_code', $selected_facilites); + $appointment_male = $appointment_male->where('tbl_partner_facility.mfl_code', $selected_facilites); + $appointment_female = $appointment_female->where('tbl_partner_facility.mfl_code', $selected_facilites); + $appointment_uknown_gender = $appointment_uknown_gender->where('tbl_partner_facility.mfl_code', $selected_facilites); + $appointment_to_nine = $appointment_to_nine->where('tbl_partner_facility.mfl_code', $selected_facilites); + $appointment_to_fourteen = $appointment_to_fourteen->where('tbl_partner_facility.mfl_code', $selected_facilites); + $appointment_to_nineteen = $appointment_to_nineteen->where('tbl_partner_facility.mfl_code', $selected_facilites); + $appointment_to_twentyfour = $appointment_to_twentyfour->where('tbl_partner_facility.mfl_code', $selected_facilites); + $appointment_to_twentyfive_above = $appointment_to_twentyfive_above->where('tbl_partner_facility.mfl_code', $selected_facilites); + $appointment_uknown_age = $appointment_uknown_age->where('tbl_partner_facility.mfl_code', $selected_facilites); + $appointment_total_missed_female = $appointment_total_missed_female->where('tbl_partner_facility.mfl_code', $selected_facilites); + $appointment_total_missed_male = $appointment_total_missed_male->where('tbl_partner_facility.mfl_code', $selected_facilites); + $appointment_total_missed_uknown_gender = $appointment_total_missed_uknown_gender->where('tbl_partner_facility.mfl_code', $selected_facilites); + $appointment_total_missed_to_nine = $appointment_total_missed_to_nine->where('tbl_partner_facility.mfl_code', $selected_facilites); + $appointment_total_missed_to_fourteen = $appointment_total_missed_to_fourteen->where('tbl_partner_facility.mfl_code', $selected_facilites); + $appointment_total_missed_to_nineteen = $appointment_total_missed_to_nineteen->where('tbl_partner_facility.mfl_code', $selected_facilites); + $appointment_total_missed_to_twentyfour = $appointment_total_missed_to_twentyfour->where('tbl_partner_facility.mfl_code', $selected_facilites); + $appointment_total_missed_to_twentyfive_above = $appointment_total_missed_to_twentyfive_above->where('tbl_partner_facility.mfl_code', $selected_facilites); + $appointment_total_missed_uknown_age = $appointment_total_missed_uknown_age->where('tbl_partner_facility.mfl_code', $selected_facilites); + + $client_consented = $client_consented->where('tbl_partner_facility.mfl_code', $selected_facilites); + $client_nonconsented = $client_nonconsented->where('tbl_partner_facility.mfl_code', $selected_facilites); + $client_consented_male = $client_consented_male->where('tbl_partner_facility.mfl_code', $selected_facilites); + $client_consented_female = $client_consented_female->where('tbl_partner_facility.mfl_code', $selected_facilites); + $client_consented_uknown_gender = $client_consented_uknown_gender->where('tbl_partner_facility.mfl_code', $selected_facilites); + $client_nonconsented_male = $client_nonconsented_male->where('tbl_partner_facility.mfl_code', $selected_facilites); + $client_nonconsented_female = $client_nonconsented_female->where('tbl_partner_facility.mfl_code', $selected_facilites); + $client_nonconsented_uknown_gender = $client_nonconsented_uknown_gender->where('tbl_partner_facility.mfl_code', $selected_facilites); + $client_consented_to_nine = $client_consented_to_nine->where('tbl_partner_facility.mfl_code', $selected_facilites); + $client_consented_to_fourteen = $client_consented_to_fourteen->where('tbl_partner_facility.mfl_code', $selected_facilites); + $client_consented_to_nineteen = $client_consented_to_nineteen->where('tbl_partner_facility.mfl_code', $selected_facilites); + $client_consented_to_twentyfour = $client_consented_to_twentyfour->where('tbl_partner_facility.mfl_code', $selected_facilites); + $client_consented_to_twentyfive_above = $client_consented_to_twentyfive_above->where('tbl_partner_facility.mfl_code', $selected_facilites); + $client_consented_uknown_age = $client_consented_uknown_age->where('tbl_partner_facility.mfl_code', $selected_facilites); + $client_nonconsented_to_nine = $client_nonconsented_to_nine->where('tbl_partner_facility.mfl_code', $selected_facilites); + $client_nonconsented_to_fourteen = $client_nonconsented_to_fourteen->where('tbl_partner_facility.mfl_code', $selected_facilites); + $client_nonconsented_to_nineteen = $client_nonconsented_to_nineteen->where('tbl_partner_facility.mfl_code', $selected_facilites); + $client_nonconsented_to_twentyfour = $client_nonconsented_to_twentyfour->where('tbl_partner_facility.mfl_code', $selected_facilites); + $client_nonconsented_to_twentyfive_above = $client_nonconsented_to_twentyfive_above->where('tbl_partner_facility.mfl_code', $selected_facilites); + $client_nonconsented_uknown_age = $client_nonconsented_uknown_age->where('tbl_partner_facility.mfl_code', $selected_facilites); + } + $data["client"] = $client->count(); + $data["appointment"] = $appointment->count(); + $data["missed_appointment"] = $missed_appointment->count(); + $data["clients_male"] = $clients_male->count(); + $data["clients_female"] = $clients_female->count(); + $data["unknown_gender"] = $unknown_gender->count(); + $data["client_to_nine"] = $client_to_nine->count(); + $data["client_to_fourteen"] = $client_to_fourteen->count(); + $data["client_to_nineteen"] = $client_to_nineteen->count(); + $data["client_to_twentyfour"] = $client_to_twentyfour->count(); + $data["client_to_twentyfive_above"] = $client_to_twentyfive_above->count(); + $data["client_unknown_age"] = $client_unknown_age->count(); + $data["appointment_male"] = $appointment_male->count(); + $data["appointment_female"] = $appointment_female->count(); + $data["appointment_uknown_gender"] = $appointment_uknown_gender->count(); + $data["appointment_to_nine"] = $appointment_to_nine->count(); + $data["appointment_to_fourteen"] = $appointment_to_fourteen->count(); + $data["appointment_to_nineteen"] = $appointment_to_nineteen->count(); + $data["appointment_to_twentyfour"] = $appointment_to_twentyfour->count(); + $data["appointment_to_twentyfive_above"] = $appointment_to_twentyfive_above->count(); + $data["appointment_uknown_age"] = $appointment_uknown_age->count(); + $data["appointment_total_missed_female"] = $appointment_total_missed_female->count(); + $data["appointment_total_missed_male"] = $appointment_total_missed_male->count(); + $data["appointment_total_missed_uknown_gender"] = $appointment_total_missed_uknown_gender->count(); + $data["appointment_total_missed_to_nine"] = $appointment_total_missed_to_nine->count(); + $data["appointment_total_missed_to_fourteen"] = $appointment_total_missed_to_fourteen->count(); + $data["appointment_total_missed_to_nineteen"] = $appointment_total_missed_to_nineteen->count(); + $data["appointment_total_missed_to_twentyfour"] = $appointment_total_missed_to_twentyfour->count(); + $data["appointment_total_missed_to_twentyfive_above"] = $appointment_total_missed_to_twentyfive_above->count(); + $data["appointment_total_missed_uknown_age"] = $appointment_total_missed_uknown_age->count(); + + $data["client_consented"] = $client_consented->count(); + $data["client_nonconsented"] = $client_nonconsented->count(); + $data["client_consented_male"] = $client_consented_male->count(); + $data["client_consented_female"] = $client_consented_female->count(); + $data["client_consented_uknown_gender"] = $client_consented_uknown_gender->count(); + $data["client_nonconsented_male"] = $client_nonconsented_male->count(); + $data["client_nonconsented_female"] = $client_nonconsented_female->count(); + $data["client_nonconsented_uknown_gender"] = $client_nonconsented_uknown_gender->count(); + $data["client_consented_to_nine"] = $client_consented_to_nine->count(); + $data["client_consented_to_fourteen"] = $client_consented_to_fourteen->count(); + $data["client_consented_to_nineteen"] = $client_consented_to_nineteen->count(); + $data["client_consented_to_twentyfour"] = $client_consented_to_twentyfour->count(); + $data["client_consented_to_twentyfive_above"] = $client_consented_to_twentyfive_above->count(); + $data["client_consented_uknown_age"] = $client_consented_uknown_age->count(); + $data["client_nonconsented_to_nine"] = $client_nonconsented_to_nine->count(); + $data["client_nonconsented_to_fourteen"] = $client_nonconsented_to_fourteen->count(); + $data["client_nonconsented_to_nineteen"] = $client_nonconsented_to_nineteen->count(); + $data["client_nonconsented_to_twentyfour"] = $client_nonconsented_to_twentyfour->count(); + $data["client_nonconsented_to_twentyfive_above"] = $client_nonconsented_to_twentyfive_above->count(); + $data["client_nonconsented_uknown_age"] = $client_nonconsented_uknown_age->count(); //return view('new_dashboard.main_dashbaord', compact('data')); @@ -2821,455 +2820,2286 @@ public function filter_charts(Request $request) 'client_nonconsented_uknown_age' )); - } public function filter_dashboard_charts(Request $request) { - // $data = []; - - $selected_partners = $request->partners; - $selected_counties = $request->counties; - $selected_subcounties = $request->subcounties; - $selected_facilites = $request->facilities; + $data = []; - if (Auth::user()->access_level == 'Facility'){} - if (Auth::user()->access_level == 'Partner'){} - $all_partners = Partner::where('status', '=', 'Active')->pluck('name', 'id'); - $indicator = Indicator::select(['name', 'description'])->get(); + $selected_partners = $request->partners; + $selected_counties = $request->counties; + $selected_subcounties = $request->subcounties; + $selected_facilites = $request->facilities; + $selected_from = $request->from; + $selected_to = $request->to; + if (Auth::user()->access_level == 'Facility') { + $facilities_ever_enrolled = PartnerFacility::where('created_at', '>=', date($request->from))->where('created_at', '<=', date($request->to)); $client = Client::join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') - ->where('tbl_client.status', '=', 'Active') - ->whereNull('tbl_client.hei_no') - ->whereDate('tbl_client.created_at', '>=', date($request->from))->whereDate('tbl_client.created_at', '<=', date($request->to)); + ->where('tbl_client.status', '=', 'Active') + ->whereNull('tbl_client.hei_no') + ->where('tbl_client.mfl_code', Auth::user()->facility_id) + ->whereDate('tbl_client.created_at', '>=', date($request->from))->whereDate('tbl_client.created_at', '<=', date($request->to)); $client_ever_enrolled = Client::join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') - ->whereNull('tbl_client.hei_no') - ->where('tbl_client.created_at', '>=', date($request->from))->where('tbl_client.created_at', '<=', date($request->to)); - $active_facilities = PartnerFacility::join('tbl_client', 'tbl_partner_facility.mfl_code', '=', 'tbl_client.mfl_code') - ->join('tbl_appointment', 'tbl_client.id', '=', 'tbl_appointment.client_id') - ->select('tbl_partner_facility.mfl_code') - ->where('tbl_appointment.created_at', '>=', Carbon::now()->subMonths(6)) - ->where('tbl_appointment.created_at', '>=', date($request->from))->where('tbl_appointment.created_at', '<=', date($request->to)) - ->orderBy('tbl_appointment.created_at', 'DESC') - ->groupBy('tbl_partner_facility.mfl_code') - ->get(); - $facilities_ever_enrolled = PartnerFacility::where('created_at', '>=', date($request->from))->where('created_at', '<=', date($request->to)); + ->whereNull('tbl_client.hei_no') + ->where('tbl_client.mfl_code', Auth::user()->facility_id) + ->where('tbl_client.created_at', '>=', date($request->from))->where('tbl_client.created_at', '<=', date($request->to)); // active clients by gender $clients_male = Client::join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') - ->select('tbl_client.id') - ->where([['tbl_client.gender', '=', '2'], ['tbl_client.status', '=', 'Active'],]) - ->whereNull('tbl_client.hei_no') - ->whereDate('tbl_client.created_at', '>=', date($request->from))->whereDate('tbl_client.created_at', '<=', date($request->to)); + ->select('tbl_client.id') + ->where([['tbl_client.gender', '=', '2'], ['tbl_client.status', '=', 'Active'],]) + ->whereNull('tbl_client.hei_no') + ->where('tbl_client.mfl_code', Auth::user()->facility_id) + ->whereDate('tbl_client.created_at', '>=', date($request->from))->whereDate('tbl_client.created_at', '<=', date($request->to)); $clients_female = Client::join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') - ->where([['tbl_client.gender', '=', '1'], ['tbl_client.status', '=', 'Active'],]) - ->whereNull('tbl_client.hei_no') - ->whereDate('tbl_client.created_at', '>=', date($request->from))->whereDate('tbl_client.created_at', '<=', date($request->to)); + ->where([['tbl_client.gender', '=', '1'], ['tbl_client.status', '=', 'Active'],]) + ->whereNull('tbl_client.hei_no') + ->where('tbl_client.mfl_code', Auth::user()->facility_id) + ->whereDate('tbl_client.created_at', '>=', date($request->from))->whereDate('tbl_client.created_at', '<=', date($request->to)); $unknown_gender = Client::join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') - ->where([['tbl_client.gender', '!=', '1'], ['tbl_client.gender', '!=', '2'], ['tbl_client.status', '=', 'Active'],]) - ->whereNull('tbl_client.hei_no') - ->whereDate('tbl_client.created_at', '>=', date($request->from))->whereDate('tbl_client.created_at', '<=', date($request->to)); + ->where([['tbl_client.gender', '!=', '1'], ['tbl_client.gender', '!=', '2'], ['tbl_client.status', '=', 'Active'],]) + ->whereNull('tbl_client.hei_no') + ->where('tbl_client.mfl_code', Auth::user()->facility_id) + ->whereDate('tbl_client.created_at', '>=', date($request->from))->whereDate('tbl_client.created_at', '<=', date($request->to)); $client_to_nine = Client::join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') - ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) > 0) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 9)) then `tbl_client`.`dob` end)) AS count")) - ->where('tbl_client.status', '=', 'Active') - ->whereNull('tbl_client.hei_no') - ->whereDate('tbl_client.created_at', '>=', date($request->from))->whereDate('tbl_client.created_at', '<=', date($request->to)); + ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) > 0) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 9)) then `tbl_client`.`dob` end)) AS count")) + ->where('tbl_client.status', '=', 'Active') + ->whereNull('tbl_client.hei_no') + ->where('tbl_client.mfl_code', Auth::user()->facility_id) + ->whereDate('tbl_client.created_at', '>=', date($request->from))->whereDate('tbl_client.created_at', '<=', date($request->to)); $client_to_fourteen = Client::join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') - ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 10) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 14)) then `tbl_client`.`dob` end)) AS count")) - ->where('tbl_client.status', '=', 'Active') - ->whereNull('tbl_client.hei_no') - ->whereDate('tbl_client.created_at', '>=', date($request->from))->whereDate('tbl_client.created_at', '<=', date($request->to)); + ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 10) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 14)) then `tbl_client`.`dob` end)) AS count")) + ->where('tbl_client.status', '=', 'Active') + ->whereNull('tbl_client.hei_no') + ->where('tbl_client.mfl_code', Auth::user()->facility_id) + ->whereDate('tbl_client.created_at', '>=', date($request->from))->whereDate('tbl_client.created_at', '<=', date($request->to)); $client_to_nineteen = Client::join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') - ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 15) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 19)) then `tbl_client`.`dob` end)) AS count")) + ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 15) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 19)) then `tbl_client`.`dob` end)) AS count")) ->where('tbl_client.status', '=', 'Active') ->whereNull('tbl_client.hei_no') + ->where('tbl_client.mfl_code', Auth::user()->facility_id) ->whereDate('tbl_client.created_at', '>=', date($request->from))->whereDate('tbl_client.created_at', '<=', date($request->to)); $client_to_twentyfour = Client::join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') - ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 20) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 24)) then `tbl_client`.`dob` end)) AS count")) + ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 20) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 24)) then `tbl_client`.`dob` end)) AS count")) ->where('tbl_client.status', '=', 'Active') ->whereNull('tbl_client.hei_no') + ->where('tbl_client.mfl_code', Auth::user()->facility_id) ->whereDate('tbl_client.created_at', '>=', date($request->from))->whereDate('tbl_client.created_at', '<=', date($request->to)); $client_to_twentyfive_above = Client::join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') - ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 25)) then `tbl_client`.`dob` end)) AS count")) + ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 25)) then `tbl_client`.`dob` end)) AS count")) ->where('tbl_client.status', '=', 'Active') ->whereNull('tbl_client.hei_no') + ->where('tbl_client.mfl_code', Auth::user()->facility_id) ->whereDate('tbl_client.created_at', '>=', date($request->from))->whereDate('tbl_client.created_at', '<=', date($request->to)); $client_unknown_age = Client::join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') - ->where('tbl_client.dob', '=', '') + ->where('tbl_client.dob', '=', '') ->WhereNull('tbl_client.dob') ->where('tbl_client.status', '=', 'Active') ->whereNull('tbl_client.hei_no') + ->where('tbl_client.mfl_code', Auth::user()->facility_id) ->whereDate('tbl_client.created_at', '>=', date($request->from))->whereDate('tbl_client.created_at', '<=', date($request->to)); + } + if (Auth::user()->access_level == 'Partner') { + $all_partners = Partner::where('status', '=', 'Active')->pluck('name', 'id'); + $indicator = Indicator::select(['name', 'description'])->get(); - if (!empty($selected_partners)) { - $client = $client->where('tbl_partner_facility.partner_id', $selected_partners); - $client_ever_enrolled = $client_ever_enrolled->where('tbl_partner_facility.partner_id', $selected_partners); - $facilities_ever_enrolled = $facilities_ever_enrolled->where('tbl_partner_facility.partner_id', $selected_partners); - $clients_male = $clients_male->where('tbl_partner_facility.partner_id', $selected_partners); - $clients_female = $clients_female->where('tbl_partner_facility.partner_id', $selected_partners); - $unknown_gender = $unknown_gender->where('tbl_partner_facility.partner_id', $selected_partners); - $client_to_nine = $client_to_nine->where('tbl_partner_facility.partner_id', $selected_partners); - $client_to_fourteen = $client_to_fourteen->where('tbl_partner_facility.partner_id', $selected_partners); - $client_to_nineteen = $client_to_nineteen->where('tbl_partner_facility.partner_id', $selected_partners); - $client_to_twentyfour = $client_to_twentyfour->where('tbl_partner_facility.partner_id', $selected_partners); - $client_to_twentyfive_above = $client_to_twentyfive_above->where('tbl_partner_facility.partner_id', $selected_partners); - $client_unknown_age = $client_unknown_age->where('tbl_partner_facility.partner_id', $selected_partners); - - } - if (!empty($selected_counties)) { - $client = $client->where('tbl_partner_facility.county_id', $selected_counties); - $client_ever_enrolled = $client_ever_enrolled->where('tbl_partner_facility.county_id', $selected_counties); - $facilities_ever_enrolled = $facilities_ever_enrolled->where('tbl_partner_facility.county_id', $selected_counties); - $clients_male = $clients_male->where('tbl_partner_facility.county_id', $selected_counties); - $clients_female = $clients_female->where('tbl_partner_facility.county_id', $selected_counties); - $unknown_gender = $unknown_gender->where('tbl_partner_facility.county_id', $selected_counties); - $client_to_nine = $client_to_nine->where('tbl_partner_facility.county_id', $selected_counties); - $client_to_fourteen = $client_to_fourteen->where('tbl_partner_facility.county_id', $selected_counties); - $client_to_nineteen = $client_to_nineteen->where('tbl_partner_facility.county_id', $selected_counties); - $client_to_twentyfour = $client_to_twentyfour->where('tbl_partner_facility.county_id', $selected_counties); - $client_to_twentyfive_above = $client_to_twentyfive_above->where('tbl_partner_facility.county_id', $selected_counties); - $client_unknown_age = $client_unknown_age->where('tbl_partner_facility.county_id', $selected_counties); - } - if (!empty($selected_subcounties)) { - $client = $client->where('tbl_partner_facility.sub_county_id', $selected_subcounties); - $client_ever_enrolled = $client_ever_enrolled->where('tbl_partner_facility.sub_county_id', $selected_subcounties); - $facilities_ever_enrolled = $facilities_ever_enrolled->where('tbl_partner_facility.sub_county_id', $selected_subcounties); - $clients_male = $clients_male->where('tbl_partner_facility.sub_county_id', $selected_subcounties); - $clients_female = $clients_female->where('tbl_partner_facility.sub_county_id', $selected_subcounties); - $unknown_gender = $unknown_gender->where('tbl_partner_facility.sub_county_id', $selected_subcounties); - $client_to_nine = $client_to_nine->where('tbl_partner_facility.sub_county_id', $selected_subcounties); - $client_to_fourteen = $client_to_fourteen->where('tbl_partner_facility.sub_county_id', $selected_subcounties); - $client_to_nineteen = $client_to_nineteen->where('tbl_partner_facility.sub_county_id', $selected_subcounties); - $client_to_twentyfour = $client_to_twentyfour->where('tbl_partner_facility.sub_county_id', $selected_subcounties); - $client_to_twentyfive_above = $client_to_twentyfive_above->where('tbl_partner_facility.sub_county_id', $selected_subcounties); - $client_unknown_age = $client_unknown_age->where('tbl_partner_facility.sub_county_id', $selected_subcounties); - - } - if (!empty($selected_facilites)) { - $client = $client->where('tbl_partner_facility.mfl_code', $selected_facilites); - $client_ever_enrolled = $client_ever_enrolled->where('tbl_partner_facility.mfl_code', $selected_facilites); - $active_facilities = $active_facilities->where('tbl_partner_facility.mfl_code', $selected_facilites); - $facilities_ever_enrolled = $facilities_ever_enrolled->where('tbl_partner_facility.mfl_code', $selected_facilites); - $clients_male = $clients_male->where('tbl_partner_facility.mfl_code', $selected_facilites); - $clients_female = $clients_female->where('tbl_partner_facility.mfl_code', $selected_facilites); - $unknown_gender = $unknown_gender->where('tbl_partner_facility.mfl_code', $selected_facilites); - $client_to_nine = $client_to_nine->where('tbl_partner_facility.mfl_code', $selected_facilites); - $client_to_fourteen = $client_to_fourteen->where('tbl_partner_facility.mfl_code', $selected_facilites); - $client_to_nineteen = $client_to_nineteen->where('tbl_partner_facility.mfl_code', $selected_facilites); - $client_to_twentyfour = $client_to_twentyfour->where('tbl_partner_facility.mfl_code', $selected_facilites); - $client_to_twentyfive_above = $client_to_twentyfive_above->where('tbl_partner_facility.mfl_code', $selected_facilites); - $client_unknown_age = $client_unknown_age->where('tbl_partner_facility.mfl_code', $selected_facilites); - } - $data["client"] = $client->count(); - $data["facilities_ever_enrolled"] = $facilities_ever_enrolled->count(); - $data["client_ever_enrolled"] = $client_ever_enrolled->count(); - $data["clients_male"] = $clients_male->count(); - $data["clients_female"] = $clients_female->count(); - $data["unknown_gender"] = $unknown_gender->count(); - $data["client_to_nine"] = $client_to_nine->pluck('count'); - $data["client_to_fourteen"] = $client_to_fourteen->pluck('count'); - $data["client_to_nineteen"] = $client_to_nineteen->pluck('count'); - $data["client_to_twentyfour"] = $client_to_twentyfour->pluck('count'); - $data["client_to_twentyfive_above"] = $client_to_twentyfive_above->pluck('count'); - $data["client_unknown_age"] = $client_unknown_age->count(); + $client = Client::join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->where('tbl_client.status', '=', 'Active') + ->whereNull('tbl_client.hei_no') + ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id); + $client_ever_enrolled = Client::join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->whereNull('tbl_client.hei_no') + ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id); + $active_facilities = PartnerFacility::join('tbl_client', 'tbl_partner_facility.mfl_code', '=', 'tbl_client.mfl_code') + ->join('tbl_appointment', 'tbl_client.id', '=', 'tbl_appointment.client_id') + ->select('tbl_partner_facility.mfl_code') + ->where('tbl_appointment.created_at', '>=', Carbon::now()->subMonths(6)) + ->orderBy('tbl_appointment.created_at', 'DESC') + ->groupBy('tbl_partner_facility.mfl_code') + ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) + ->get(); + $facilities_ever_enrolled = PartnerFacility::where('partner_id', Auth::user()->partner_id) + ->where('created_at', '>=', date($request->from))->where('created_at', '<=', date($request->to)); + // active clients by gender + $clients_male = Client::join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select('tbl_client.id') + ->where([['tbl_client.gender', '=', '2'], ['tbl_client.status', '=', 'Active'],]) + ->whereNull('tbl_client.hei_no') + ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id); + $clients_female = Client::join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->where([['tbl_client.gender', '=', '1'], ['tbl_client.status', '=', 'Active'],]) + ->whereNull('tbl_client.hei_no') + ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id); - return $data; + $unknown_gender = Client::join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->where([['tbl_client.gender', '!=', '1'], ['tbl_client.gender', '!=', '2'], ['tbl_client.status', '=', 'Active'],]) + ->whereNull('tbl_client.hei_no') + ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id); - } - public function filter_client_charts(Request $request) - { - $data = []; - // client charts - $selected_partners = $request->partners; - $selected_counties = $request->counties; - $selected_subcounties = $request->subcounties; - $selected_facilites = $request->facilities; - if (Auth::user()->access_level == 'Facility'){} - if (Auth::user()->access_level == 'Partner'){} + $client_to_nine = Client::join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) > 0) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 9)) then `tbl_client`.`dob` end)) AS count")) + ->where('tbl_client.status', '=', 'Active') + ->whereNull('tbl_client.hei_no') + ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id); - $client = Client::join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') - ->where('tbl_client.status', '=', 'Active') - ->whereNull('tbl_client.hei_no') - ->where('tbl_client.created_at', '>=', date($request->from))->where('tbl_client.created_at', '<=', date($request->to)); - $client_consented = Client::join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') - ->select('tbl_client.id') - ->where('tbl_client.status', '=', 'Active') - ->whereNull('tbl_client.hei_no') - ->where('tbl_client.smsenable', '=', 'Yes') - ->where('tbl_client.created_at', '>=', date($request->from))->where('tbl_client.created_at', '<=', date($request->to)); - $client_nonconsented = Client::join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') - ->select('tbl_client.id') - ->where('tbl_client.status', '=', 'Active') - ->whereNull('tbl_client.hei_no') - ->where('tbl_client.smsenable', '!=', 'Yes') - ->where('tbl_client.created_at', '>=', date($request->from))->where('tbl_client.created_at', '<=', date($request->to)); + $client_to_fourteen = Client::join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 10) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 14)) then `tbl_client`.`dob` end)) AS count")) + ->where('tbl_client.status', '=', 'Active') + ->whereNull('tbl_client.hei_no') + ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id); - // consented clients by gender - $client_consented_male = Client::join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') - ->where('tbl_client.smsenable', '=', 'Yes') - ->where('tbl_client.status', '=', 'Active') - ->whereNull('tbl_client.hei_no') - ->where('tbl_client.gender', '=', '2') - ->where('tbl_client.created_at', '>=', date($request->from))->where('tbl_client.created_at', '<=', date($request->to)); + $client_to_nineteen = Client::join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 15) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 19)) then `tbl_client`.`dob` end)) AS count")) + ->where('tbl_client.status', '=', 'Active') + ->whereNull('tbl_client.hei_no') + ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id); - $client_consented_female = Client::join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') - ->where('tbl_client.smsenable', '=', 'Yes') - ->where('tbl_client.status', '=', 'Active') - ->whereNull('tbl_client.hei_no') - ->where('tbl_client.gender', '=', '1') - ->where('tbl_client.created_at', '>=', date($request->from))->where('tbl_client.created_at', '<=', date($request->to)); + $client_to_twentyfour = Client::join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 20) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 24)) then `tbl_client`.`dob` end)) AS count")) + ->where('tbl_client.status', '=', 'Active') + ->whereNull('tbl_client.hei_no') + ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id); - $client_consented_uknown_gender = Client::join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') - ->where('tbl_client.smsenable', '=', 'Yes') - ->where('tbl_client.status', '=', 'Active') - ->whereNull('tbl_client.hei_no') - ->where('tbl_client.gender', '!=', '1') - ->where('tbl_client.gender', '!=', '2') - ->where('tbl_client.created_at', '>=', date($request->from))->where('tbl_client.created_at', '<=', date($request->to)); + $client_to_twentyfive_above = Client::join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 25)) then `tbl_client`.`dob` end)) AS count")) + ->where('tbl_client.status', '=', 'Active') + ->whereNull('tbl_client.hei_no') + ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id); - // non consented clients by gender - $client_nonconsented_male = Client::join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') - ->where('tbl_client.smsenable', '!=', 'Yes') - ->where('tbl_client.status', '=', 'Active') - ->whereNull('tbl_client.hei_no') - ->where('tbl_client.gender', '=', '2') - ->where('tbl_client.created_at', '>=', date($request->from))->where('tbl_client.created_at', '<=', date($request->to)); + $client_unknown_age = Client::join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->where('tbl_client.dob', '=', '') + ->WhereNull('tbl_client.dob') + ->where('tbl_client.status', '=', 'Active') + ->whereNull('tbl_client.hei_no') + ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id); + } - $client_nonconsented_female = Client::join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') - ->where('tbl_client.smsenable', '!=', 'Yes') - ->where('tbl_client.status', '=', 'Active') - ->whereNull('tbl_client.hei_no') - ->where('tbl_client.gender', '=', '1') - ->where('tbl_client.created_at', '>=', date($request->from))->where('tbl_client.created_at', '<=', date($request->to)); + if (Auth::user()->access_level == 'Admin' || Auth::user()->access_level == 'Donor') { - $client_nonconsented_uknown_gender = Client::join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') - ->where('tbl_client.smsenable', '!=', 'Yes') - ->where('tbl_client.gender', '!=', '1') - ->where('tbl_client.gender', '!=', '2') - ->where('tbl_client.created_at', '>=', date($request->from))->where('tbl_client.created_at', '<=', date($request->to)); + $all_partners = Partner::where('status', '=', 'Active')->pluck('name', 'id'); + $indicator = Indicator::select(['name', 'description'])->get(); - // consented clients by age distribution - $client_consented_to_nine = Client::join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') - ->select(\DB::raw("case when (((year(curdate()) - year(`tbl_client`.`tbl_client`.`dob`)) > 0) and ((year(curdate()) - year(`tbl_client`.`tbl_client`.`dob`)) <= 9)) then `tbl_client`.`id` end")) - ->where('tbl_client.smsenable', '=', 'Yes') - ->where('tbl_client.status', '=', 'Active') - ->whereNull('tbl_client.hei_no') - ->where('tbl_client.created_at', '>=', date($request->from))->where('tbl_client.created_at', '<=', date($request->to)); - $client_consented_to_fourteen = Client::join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') - ->select(\DB::raw("case when (((year(curdate()) - year(`tbl_client`.`tbl_client`.`dob`)) >= 10) and ((year(curdate()) - year(`tbl_client`.`tbl_client`.`dob`)) <= 14)) then `tbl_client`.`id` end")) - ->where('tbl_client.smsenable', '=', 'Yes') - ->where('tbl_client.status', '=', 'Active') - ->whereNull('tbl_client.hei_no') - ->where('tbl_client.created_at', '>=', date($request->from))->where('tbl_client.created_at', '<=', date($request->to)); + $client = Client::join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->where('tbl_client.status', '=', 'Active') + ->whereNull('tbl_client.hei_no'); + $client_ever_enrolled = Client::join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->whereNull('tbl_client.hei_no'); + $active_facilities = PartnerFacility::join('tbl_client', 'tbl_partner_facility.mfl_code', '=', 'tbl_client.mfl_code') + ->join('tbl_appointment', 'tbl_client.id', '=', 'tbl_appointment.client_id') + ->select('tbl_partner_facility.mfl_code') + ->where('tbl_appointment.created_at', '>=', Carbon::now()->subMonths(6)) + ->orderBy('tbl_appointment.created_at', 'DESC') + ->groupBy('tbl_partner_facility.mfl_code') + ->get(); + $facilities_ever_enrolled = PartnerFacility::select('mfl_code'); + // active clients by gender + $clients_male = Client::join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select('tbl_client.id') + ->where([['tbl_client.gender', '=', '2'], ['tbl_client.status', '=', 'Active'],]) + ->whereNull('tbl_client.hei_no'); - $client_consented_to_nineteen = Client::join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') - ->select(\DB::raw("case when (((year(curdate()) - year(`tbl_client`.`tbl_client`.`dob`)) >= 15) and ((year(curdate()) - year(`tbl_client`.`tbl_client`.`dob`)) <= 19)) then `tbl_client`.`id` end")) - ->where('tbl_client.smsenable', '=', 'Yes') - ->where('tbl_client.status', '=', 'Active') - ->whereNull('tbl_client.hei_no') - ->where('tbl_client.created_at', '>=', date($request->from))->where('tbl_client.created_at', '<=', date($request->to)); + $clients_female = Client::join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->where([['tbl_client.gender', '=', '1'], ['tbl_client.status', '=', 'Active'],]) + ->whereNull('tbl_client.hei_no'); - $client_consented_to_twentyfour = Client::join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') - ->select(\DB::raw("case when (((year(curdate()) - year(`tbl_client`.`tbl_client`.`dob`)) >= 20) and ((year(curdate()) - year(`tbl_client`.`tbl_client`.`dob`)) <= 24)) then `tbl_client`.`id` end")) - ->where('tbl_client.smsenable', '=', 'Yes') - ->where('tbl_client.status', '=', 'Active') - ->whereNull('tbl_client.hei_no') - ->where('tbl_client.created_at', '>=', date($request->from))->where('tbl_client.created_at', '<=', date($request->to)); + $unknown_gender = Client::join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->where([['tbl_client.gender', '!=', '1'], ['tbl_client.gender', '!=', '2'], ['tbl_client.status', '=', 'Active'],]) + ->whereNull('tbl_client.hei_no'); - $client_consented_to_twentyfive_above = Client::join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') - ->select(\DB::raw("case when (((year(curdate()) - year(`tbl_client`.`tbl_client`.`dob`)) >= 25)) then `tbl_client`.`id` end")) - ->where('tbl_client.smsenable', '=', 'Yes') - ->where('tbl_client.status', '=', 'Active') - ->whereNull('tbl_client.hei_no') - ->where('tbl_client.created_at', '>=', date($request->from))->where('tbl_client.created_at', '<=', date($request->to)); + $client_to_nine = Client::join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) > 0) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 9)) then `tbl_client`.`dob` end)) AS count")) + ->where('tbl_client.status', '=', 'Active') + ->whereNull('tbl_client.hei_no'); - $client_consented_uknown_age = Client::join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') - ->select('tbl_client.smsenable') - ->where('tbl_client.dob', '=', '') - ->where('tbl_client.status', '=', 'Active') - ->whereNull('tbl_client.hei_no') - ->orWhereNull('tbl_client.dob') - ->where('tbl_client.smsenable', '=', 'Yes') - ->where('tbl_client.created_at', '>=', date($request->from))->where('tbl_client.created_at', '<=', date($request->to)); + $client_to_fourteen = Client::join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 10) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 14)) then `tbl_client`.`dob` end)) AS count")) + ->where('tbl_client.status', '=', 'Active') + ->whereNull('tbl_client.hei_no'); - // non consented clients by age distribution - $client_nonconsented_to_nine = Client::join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') - ->select(\DB::raw("case when (((year(curdate()) - year(`tbl_client`.`tbl_client`.`dob`)) > 0) and ((year(curdate()) - year(`tbl_client`.`tbl_client`.`dob`)) <= 9)) then `tbl_client`.`id` end")) - ->where('tbl_client.smsenable', '!=', 'Yes') - ->where('tbl_client.status', '=', 'Active') - ->whereNull('tbl_client.hei_no') - ->where('tbl_client.created_at', '>=', date($request->from))->where('tbl_client.created_at', '<=', date($request->to)); - $client_nonconsented_to_fourteen = Client::join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') - ->select(\DB::raw("case when (((year(curdate()) - year(`tbl_client`.`tbl_client`.`dob`)) >= 10) and ((year(curdate()) - year(`tbl_client`.`tbl_client`.`dob`)) <= 14)) then `tbl_client`.`id` end")) - ->where('tbl_client.smsenable', '!=', 'Yes') - ->where('tbl_client.status', '=', 'Active') - ->whereNull('tbl_client.hei_no') - ->where('tbl_client.created_at', '>=', date($request->from))->where('tbl_client.created_at', '<=', date($request->to)); + $client_to_nineteen = Client::join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 15) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 19)) then `tbl_client`.`dob` end)) AS count")) + ->where('tbl_client.status', '=', 'Active') + ->whereNull('tbl_client.hei_no'); - $client_nonconsented_to_nineteen = Client::join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') - ->select(\DB::raw("case when (((year(curdate()) - year(`tbl_client`.`tbl_client`.`dob`)) >= 15) and ((year(curdate()) - year(`tbl_client`.`tbl_client`.`dob`)) <= 19)) then `tbl_client`.`id` end")) - ->where('tbl_client.smsenable', '!=', 'Yes') - ->where('tbl_client.status', '=', 'Active') - ->whereNull('tbl_client.hei_no') - ->where('tbl_client.created_at', '>=', date($request->from))->where('tbl_client.created_at', '<=', date($request->to)); + $client_to_twentyfour = Client::join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 20) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 24)) then `tbl_client`.`dob` end)) AS count")) + ->where('tbl_client.status', '=', 'Active') + ->whereNull('tbl_client.hei_no'); - $client_nonconsented_to_twentyfour = Client::join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') - ->select(\DB::raw("case when (((year(curdate()) - year(`tbl_client`.`tbl_client`.`dob`)) >= 20) and ((year(curdate()) - year(`tbl_client`.`tbl_client`.`dob`)) <= 24)) then `tbl_client`.`id` end")) - ->where('tbl_client.smsenable', '!=', 'Yes') - ->where('tbl_client.status', '=', 'Active') - ->whereNull('tbl_client.hei_no') - ->where('tbl_client.created_at', '>=', date($request->from))->where('tbl_client.created_at', '<=', date($request->to)); + $client_to_twentyfive_above = Client::join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 25)) then `tbl_client`.`dob` end)) AS count")) + ->where('tbl_client.status', '=', 'Active') + ->whereNull('tbl_client.hei_no'); - $client_nonconsented_to_twentyfive_above = Client::join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') - ->select(\DB::raw("case when (((year(curdate()) - year(`tbl_client`.`tbl_client`.`dob`)) >= 25)) then `tbl_client`.`id` end")) - ->where('tbl_client.smsenable', '!=', 'Yes') - ->where('tbl_client.status', '=', 'Active') - ->whereNull('tbl_client.hei_no') - ->where('tbl_client.created_at', '>=', date($request->from))->where('tbl_client.created_at', '<=', date($request->to)); - $client_nonconsented_uknown_age = Client::join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') - ->select('tbl_client.smsenable') - ->where('tbl_client.status', '=', 'Active') - ->whereNull('tbl_client.hei_no') - ->where('tbl_client.dob', '=', '') - ->orWhereNull('tbl_client.dob') - ->where('tbl_client.smsenable', '!=', 'Yes') - ->where('tbl_client.created_at', '>=', date($request->from))->where('tbl_client.created_at', '<=', date($request->to)); + $client_unknown_age = Client::join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->where('tbl_client.dob', '=', '') + ->WhereNull('tbl_client.dob') + ->where('tbl_client.status', '=', 'Active') + ->whereNull('tbl_client.hei_no'); + } - if (!empty($selected_partners)) { - $client = $client->where('tbl_partner_facility.partner_id', $selected_partners); - $client_consented = $client_consented->where('tbl_partner_facility.partner_id', $selected_partners); - $client_nonconsented = $client_nonconsented->where('tbl_partner_facility.partner_id', $selected_partners); - $client_consented_male = $client_consented_male->where('tbl_partner_facility.partner_id', $selected_partners); - $client_consented_female = $client_consented_female->where('tbl_partner_facility.partner_id', $selected_partners); - $client_consented_uknown_gender = $client_consented_uknown_gender->where('tbl_partner_facility.partner_id', $selected_partners); - $client_nonconsented_male = $client_nonconsented_male->where('tbl_partner_facility.partner_id', $selected_partners); - $client_nonconsented_female = $client_nonconsented_female->where('tbl_partner_facility.partner_id', $selected_partners); - $client_nonconsented_uknown_gender = $client_nonconsented_uknown_gender->where('tbl_partner_facility.partner_id', $selected_partners); - $client_consented_to_nine = $client_consented_to_nine->where('tbl_partner_facility.partner_id', $selected_partners); - $client_consented_to_fourteen = $client_consented_to_fourteen->where('tbl_partner_facility.partner_id', $selected_partners); - $client_consented_to_nineteen = $client_consented_to_nineteen->where('tbl_partner_facility.partner_id', $selected_partners); - $client_consented_to_twentyfour = $client_consented_to_twentyfour->where('tbl_partner_facility.partner_id', $selected_partners); - $client_consented_to_twentyfive_above = $client_consented_to_twentyfive_above->where('tbl_partner_facility.partner_id', $selected_partners); - $client_consented_uknown_age = $client_consented_uknown_age->where('tbl_partner_facility.partner_id', $selected_partners); - $client_nonconsented_to_nine = $client_nonconsented_to_nine->where('tbl_partner_facility.partner_id', $selected_partners); - $client_nonconsented_to_fourteen = $client_nonconsented_to_fourteen->where('tbl_partner_facility.partner_id', $selected_partners); - $client_nonconsented_to_nineteen = $client_nonconsented_to_nineteen->where('tbl_partner_facility.partner_id', $selected_partners); - $client_nonconsented_to_twentyfour = $client_nonconsented_to_twentyfour->where('tbl_partner_facility.partner_id', $selected_partners); - $client_nonconsented_to_twentyfive_above = $client_nonconsented_to_twentyfive_above->where('tbl_partner_facility.partner_id', $selected_partners); - $client_nonconsented_uknown_age = $client_nonconsented_uknown_age->where('tbl_partner_facility.partner_id', $selected_partners); - } - if (!empty($selected_counties)) { - $client = $client->where('tbl_partner_facility.county_id', $selected_counties); - $client_consented = $client_consented->where('tbl_partner_facility.county_id', $selected_counties); - $client_nonconsented = $client_nonconsented->where('tbl_partner_facility.county_id', $selected_counties); - $client_consented_male = $client_consented_male->where('tbl_partner_facility.county_id', $selected_counties); - $client_consented_female = $client_consented_female->where('tbl_partner_facility.county_id', $selected_counties); - $client_consented_uknown_gender = $client_consented_uknown_gender->where('tbl_partner_facility.county_id', $selected_counties); - $client_nonconsented_male = $client_nonconsented_male->where('tbl_partner_facility.county_id', $selected_counties); - $client_nonconsented_female = $client_nonconsented_female->where('tbl_partner_facility.county_id', $selected_counties); - $client_nonconsented_uknown_gender = $client_nonconsented_uknown_gender->where('tbl_partner_facility.county_id', $selected_counties); - $client_consented_to_nine = $client_consented_to_nine->where('tbl_partner_facility.county_id', $selected_counties); - $client_consented_to_fourteen = $client_consented_to_fourteen->where('tbl_partner_facility.county_id', $selected_counties); - $client_consented_to_nineteen = $client_consented_to_nineteen->where('tbl_partner_facility.county_id', $selected_counties); - $client_consented_to_twentyfour = $client_consented_to_twentyfour->where('tbl_partner_facility.county_id', $selected_counties); - $client_consented_to_twentyfive_above = $client_consented_to_twentyfive_above->where('tbl_partner_facility.county_id', $selected_counties); - $client_consented_uknown_age = $client_consented_uknown_age->where('tbl_partner_facility.county_id', $selected_counties); - $client_nonconsented_to_nine = $client_nonconsented_to_nine->where('tbl_partner_facility.county_id', $selected_counties); - $client_nonconsented_to_fourteen = $client_nonconsented_to_fourteen->where('tbl_partner_facility.county_id', $selected_counties); - $client_nonconsented_to_nineteen = $client_nonconsented_to_nineteen->where('tbl_partner_facility.county_id', $selected_counties); - $client_nonconsented_to_twentyfour = $client_nonconsented_to_twentyfour->where('tbl_partner_facility.county_id', $selected_counties); - $client_nonconsented_to_twentyfive_above = $client_nonconsented_to_twentyfive_above->where('tbl_partner_facility.county_id', $selected_counties); - $client_nonconsented_uknown_age = $client_nonconsented_uknown_age->where('tbl_partner_facility.county_id', $selected_counties); - } - if (!empty($selected_subcounties)) { - $client = $client->where('tbl_partner_facility.sub_county_id', $selected_subcounties); - $client_consented = $client_consented->where('tbl_partner_facility.sub_county_id', $selected_subcounties); - $client_nonconsented = $client_nonconsented->where('tbl_partner_facility.sub_county_id', $selected_subcounties); - $client_consented_male = $client_consented_male->where('tbl_partner_facility.sub_county_id', $selected_subcounties); - $client_consented_female = $client_consented_female->where('tbl_partner_facility.sub_county_id', $selected_subcounties); - $client_consented_uknown_gender = $client_consented_uknown_gender->where('tbl_partner_facility.sub_county_id', $selected_subcounties); - $client_nonconsented_male = $client_nonconsented_male->where('tbl_partner_facility.sub_county_id', $selected_subcounties); - $client_nonconsented_female = $client_nonconsented_female->where('tbl_partner_facility.sub_county_id', $selected_subcounties); - $client_nonconsented_uknown_gender = $client_nonconsented_uknown_gender->where('tbl_partner_facility.sub_county_id', $selected_subcounties); - $client_consented_to_nine = $client_consented_to_nine->where('tbl_partner_facility.sub_county_id', $selected_subcounties); - $client_consented_to_fourteen = $client_consented_to_fourteen->where('tbl_partner_facility.sub_county_id', $selected_subcounties); - $client_consented_to_nineteen = $client_consented_to_nineteen->where('tbl_partner_facility.sub_county_id', $selected_subcounties); - $client_consented_to_twentyfour = $client_consented_to_twentyfour->where('tbl_partner_facility.sub_county_id', $selected_subcounties); - $client_consented_to_twentyfive_above = $client_consented_to_twentyfive_above->where('tbl_partner_facility.sub_county_id', $selected_subcounties); - $client_consented_uknown_age = $client_consented_uknown_age->where('tbl_partner_facility.sub_county_id', $selected_subcounties); - $client_nonconsented_to_nine = $client_nonconsented_to_nine->where('tbl_partner_facility.sub_county_id', $selected_subcounties); - $client_nonconsented_to_fourteen = $client_nonconsented_to_fourteen->where('tbl_partner_facility.sub_county_id', $selected_subcounties); - $client_nonconsented_to_nineteen = $client_nonconsented_to_nineteen->where('tbl_partner_facility.sub_county_id', $selected_subcounties); - $client_nonconsented_to_twentyfour = $client_nonconsented_to_twentyfour->where('tbl_partner_facility.sub_county_id', $selected_subcounties); - $client_nonconsented_to_twentyfive_above = $client_nonconsented_to_twentyfive_above->where('tbl_partner_facility.sub_county_id', $selected_subcounties); - $client_nonconsented_uknown_age = $client_nonconsented_uknown_age->where('tbl_partner_facility.sub_county_id', $selected_subcounties); - } - if (!empty($selected_facilites)) { - $client = $client->where('tbl_partner_facility.mfl_code', $selected_facilites); - $client_consented = $client_consented->where('tbl_partner_facility.mfl_code', $selected_facilites); - $client_nonconsented = $client_nonconsented->where('tbl_partner_facility.mfl_code', $selected_facilites); - $client_consented_male = $client_consented_male->where('tbl_partner_facility.mfl_code', $selected_facilites); - $client_consented_female = $client_consented_female->where('tbl_partner_facility.mfl_code', $selected_facilites); - $client_consented_uknown_gender = $client_consented_uknown_gender->where('tbl_partner_facility.mfl_code', $selected_facilites); - $client_nonconsented_male = $client_nonconsented_male->where('tbl_partner_facility.mfl_code', $selected_facilites); - $client_nonconsented_female = $client_nonconsented_female->where('tbl_partner_facility.mfl_code', $selected_facilites); - $client_nonconsented_uknown_gender = $client_nonconsented_uknown_gender->where('tbl_partner_facility.mfl_code', $selected_facilites); - $client_consented_to_nine = $client_consented_to_nine->where('tbl_partner_facility.mfl_code', $selected_facilites); - $client_consented_to_fourteen = $client_consented_to_fourteen->where('tbl_partner_facility.mfl_code', $selected_facilites); - $client_consented_to_nineteen = $client_consented_to_nineteen->where('tbl_partner_facility.mfl_code', $selected_facilites); - $client_consented_to_twentyfour = $client_consented_to_twentyfour->where('tbl_partner_facility.mfl_code', $selected_facilites); - $client_consented_to_twentyfive_above = $client_consented_to_twentyfive_above->where('tbl_partner_facility.mfl_code', $selected_facilites); - $client_consented_uknown_age = $client_consented_uknown_age->where('tbl_partner_facility.mfl_code', $selected_facilites); - $client_nonconsented_to_nine = $client_nonconsented_to_nine->where('tbl_partner_facility.mfl_code', $selected_facilites); - $client_nonconsented_to_fourteen = $client_nonconsented_to_fourteen->where('tbl_partner_facility.mfl_code', $selected_facilites); - $client_nonconsented_to_nineteen = $client_nonconsented_to_nineteen->where('tbl_partner_facility.mfl_code', $selected_facilites); - $client_nonconsented_to_twentyfour = $client_nonconsented_to_twentyfour->where('tbl_partner_facility.mfl_code', $selected_facilites); - $client_nonconsented_to_twentyfive_above = $client_nonconsented_to_twentyfive_above->where('tbl_partner_facility.mfl_code', $selected_facilites); - $client_nonconsented_uknown_age = $client_nonconsented_uknown_age->where('tbl_partner_facility.mfl_code', $selected_facilites); - } - $data["client"] = $client->count(); - $data["client_consented"] = $client_consented->count(); - $data["client_nonconsented"] = $client_nonconsented->count(); - $data["client_consented_male"] = $client_consented_male->count(); - $data["client_consented_female"] = $client_consented_female->count(); - $data["client_consented_uknown_gender"] = $client_consented_uknown_gender->count(); - $data["client_nonconsented_male"] = $client_nonconsented_male->count(); - $data["client_nonconsented_female"] = $client_nonconsented_female->count(); - $data["client_nonconsented_uknown_gender"] = $client_nonconsented_uknown_gender->count(); - $data["client_consented_to_nine"] = $client_consented_to_nine->count(); - $data["client_consented_to_fourteen"] = $client_consented_to_fourteen->count(); - $data["client_consented_to_nineteen"] = $client_consented_to_nineteen->count(); - $data["client_consented_to_twentyfour"] = $client_consented_to_twentyfour->count(); - $data["client_consented_to_twentyfive_above"] = $client_consented_to_twentyfive_above->count(); - $data["client_consented_uknown_age"] = $client_consented_uknown_age->count(); - $data["client_nonconsented_to_nine"] = $client_nonconsented_to_nine->count(); - $data["client_nonconsented_to_fourteen"] = $client_nonconsented_to_fourteen->count(); - $data["client_nonconsented_to_nineteen"] = $client_nonconsented_to_nineteen->count(); - $data["client_nonconsented_to_twentyfour"] = $client_nonconsented_to_twentyfour->count(); - $data["client_nonconsented_to_twentyfive_above"] = $client_nonconsented_to_twentyfive_above->count(); - $data["client_nonconsented_uknown_age"] = $client_nonconsented_uknown_age->count(); - - return $data; + if (!empty($selected_partners)) { + $client = $client->where('tbl_partner_facility.partner_id', $selected_partners); + $client_ever_enrolled = $client_ever_enrolled->where('tbl_partner_facility.partner_id', $selected_partners); + $facilities_ever_enrolled = $facilities_ever_enrolled->where('tbl_partner_facility.partner_id', $selected_partners); + $clients_male = $clients_male->where('tbl_partner_facility.partner_id', $selected_partners); + $clients_female = $clients_female->where('tbl_partner_facility.partner_id', $selected_partners); + $unknown_gender = $unknown_gender->where('tbl_partner_facility.partner_id', $selected_partners); + $client_to_nine = $client_to_nine->where('tbl_partner_facility.partner_id', $selected_partners); + $client_to_fourteen = $client_to_fourteen->where('tbl_partner_facility.partner_id', $selected_partners); + $client_to_nineteen = $client_to_nineteen->where('tbl_partner_facility.partner_id', $selected_partners); + $client_to_twentyfour = $client_to_twentyfour->where('tbl_partner_facility.partner_id', $selected_partners); + $client_to_twentyfive_above = $client_to_twentyfive_above->where('tbl_partner_facility.partner_id', $selected_partners); + $client_unknown_age = $client_unknown_age->where('tbl_partner_facility.partner_id', $selected_partners); + } + if (!empty($selected_counties)) { + $client = $client->where('tbl_partner_facility.county_id', $selected_counties); + $client_ever_enrolled = $client_ever_enrolled->where('tbl_partner_facility.county_id', $selected_counties); + $facilities_ever_enrolled = $facilities_ever_enrolled->where('tbl_partner_facility.county_id', $selected_counties); + $clients_male = $clients_male->where('tbl_partner_facility.county_id', $selected_counties); + $clients_female = $clients_female->where('tbl_partner_facility.county_id', $selected_counties); + $unknown_gender = $unknown_gender->where('tbl_partner_facility.county_id', $selected_counties); + $client_to_nine = $client_to_nine->where('tbl_partner_facility.county_id', $selected_counties); + $client_to_fourteen = $client_to_fourteen->where('tbl_partner_facility.county_id', $selected_counties); + $client_to_nineteen = $client_to_nineteen->where('tbl_partner_facility.county_id', $selected_counties); + $client_to_twentyfour = $client_to_twentyfour->where('tbl_partner_facility.county_id', $selected_counties); + $client_to_twentyfive_above = $client_to_twentyfive_above->where('tbl_partner_facility.county_id', $selected_counties); + $client_unknown_age = $client_unknown_age->where('tbl_partner_facility.county_id', $selected_counties); + } + if (!empty($selected_subcounties)) { + $client = $client->where('tbl_partner_facility.sub_county_id', $selected_subcounties); + $client_ever_enrolled = $client_ever_enrolled->where('tbl_partner_facility.sub_county_id', $selected_subcounties); + $facilities_ever_enrolled = $facilities_ever_enrolled->where('tbl_partner_facility.sub_county_id', $selected_subcounties); + $clients_male = $clients_male->where('tbl_partner_facility.sub_county_id', $selected_subcounties); + $clients_female = $clients_female->where('tbl_partner_facility.sub_county_id', $selected_subcounties); + $unknown_gender = $unknown_gender->where('tbl_partner_facility.sub_county_id', $selected_subcounties); + $client_to_nine = $client_to_nine->where('tbl_partner_facility.sub_county_id', $selected_subcounties); + $client_to_fourteen = $client_to_fourteen->where('tbl_partner_facility.sub_county_id', $selected_subcounties); + $client_to_nineteen = $client_to_nineteen->where('tbl_partner_facility.sub_county_id', $selected_subcounties); + $client_to_twentyfour = $client_to_twentyfour->where('tbl_partner_facility.sub_county_id', $selected_subcounties); + $client_to_twentyfive_above = $client_to_twentyfive_above->where('tbl_partner_facility.sub_county_id', $selected_subcounties); + $client_unknown_age = $client_unknown_age->where('tbl_partner_facility.sub_county_id', $selected_subcounties); + } + if (!empty($selected_facilites)) { + $client = $client->where('tbl_partner_facility.mfl_code', $selected_facilites); + $client_ever_enrolled = $client_ever_enrolled->where('tbl_partner_facility.mfl_code', $selected_facilites); + $active_facilities = $active_facilities->where('tbl_partner_facility.mfl_code', $selected_facilites); + $facilities_ever_enrolled = $facilities_ever_enrolled->where('tbl_partner_facility.mfl_code', $selected_facilites); + $clients_male = $clients_male->where('tbl_partner_facility.mfl_code', $selected_facilites); + $clients_female = $clients_female->where('tbl_partner_facility.mfl_code', $selected_facilites); + $unknown_gender = $unknown_gender->where('tbl_partner_facility.mfl_code', $selected_facilites); + $client_to_nine = $client_to_nine->where('tbl_partner_facility.mfl_code', $selected_facilites); + $client_to_fourteen = $client_to_fourteen->where('tbl_partner_facility.mfl_code', $selected_facilites); + $client_to_nineteen = $client_to_nineteen->where('tbl_partner_facility.mfl_code', $selected_facilites); + $client_to_twentyfour = $client_to_twentyfour->where('tbl_partner_facility.mfl_code', $selected_facilites); + $client_to_twentyfive_above = $client_to_twentyfive_above->where('tbl_partner_facility.mfl_code', $selected_facilites); + $client_unknown_age = $client_unknown_age->where('tbl_partner_facility.mfl_code', $selected_facilites); + } + if (!empty($selected_from || $selected_to)) { + $client = $client->where('tbl_client.created_at', '>=', date($request->from))->where('tbl_client.created_at', '<=', date($request->to)); + $client_ever_enrolled = $client_ever_enrolled->where('tbl_client.created_at', '>=', date($request->from))->where('tbl_client.created_at', '<=', date($request->to)); + $active_facilities = $active_facilities->where('tbl_appointment.created_at', '>=', date($request->from))->where('tbl_appointment.created_at', '>=', date($request->to)); + $facilities_ever_enrolled = $facilities_ever_enrolled->where('created_at', '>=', date($request->from))->where('created_at', '<=', date($request->to)); + $clients_male = $clients_male->where('tbl_client.created_at', '>=', date($request->from))->where('tbl_client.created_at', '<=', date($request->to)); + $clients_female = $clients_female->where('tbl_client.created_at', '>=', date($request->from))->where('tbl_client.created_at', '<=', date($request->to)); + $unknown_gender = $unknown_gender->where('tbl_client.created_at', '>=', date($request->from))->where('tbl_client.created_at', '<=', date($request->to)); + $client_to_nine = $client_to_nine->where('tbl_client.created_at', '>=', date($request->from))->where('tbl_client.created_at', '<=', date($request->to)); + $client_to_fourteen = $client_to_fourteen->where('tbl_client.created_at', '>=', date($request->from))->where('tbl_client.created_at', '<=', date($request->to)); + $client_to_nineteen = $client_to_nineteen->where('tbl_client.created_at', '>=', date($request->from))->where('tbl_client.created_at', '<=', date($request->to)); + $client_to_twentyfour = $client_to_twentyfour->where('tbl_client.created_at', '>=', date($request->from))->where('tbl_client.created_at', '<=', date($request->to)); + $client_to_twentyfive_above = $client_to_twentyfive_above->where('tbl_client.created_at', '>=', date($request->from))->where('tbl_client.created_at', '<=', date($request->to)); + $client_unknown_age = $client_unknown_age->where('tbl_client.created_at', '>=', date($request->from))->where('tbl_client.created_at', '<=', date($request->to)); + } + $data["client"] = $client->count(); + $data["facilities_ever_enrolled"] = $facilities_ever_enrolled->count(); + $data["client_ever_enrolled"] = $client_ever_enrolled->count(); + $data["active_facilities"] = $active_facilities; + $data["clients_male"] = $clients_male->count(); + $data["clients_female"] = $clients_female->count(); + $data["unknown_gender"] = $unknown_gender->count(); + $data["client_to_nine"] = $client_to_nine->pluck('count'); + $data["client_to_fourteen"] = $client_to_fourteen->pluck('count'); + $data["client_to_nineteen"] = $client_to_nineteen->pluck('count'); + $data["client_to_twentyfour"] = $client_to_twentyfour->pluck('count'); + $data["client_to_twentyfive_above"] = $client_to_twentyfive_above->pluck('count'); + $data["client_unknown_age"] = $client_unknown_age->count(); + + + return $data; } + public function filter_client_charts(Request $request) + { + $data = []; + // client charts + $selected_partners = $request->partners; + $selected_counties = $request->counties; + $selected_subcounties = $request->subcounties; + $selected_facilites = $request->facilities; + $selected_from = $request->from; + $selected_to = $request->to; + + if (Auth::user()->access_level == 'Facility') { + + $client = Client::join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->where('tbl_client.status', '=', 'Active') + ->whereNull('tbl_client.hei_no') + ->where('tbl_client.mfl_code', Auth::user()->facility_id); + $client_consented = Client::join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select('tbl_client.id') + ->where('tbl_client.status', '=', 'Active') + ->whereNull('tbl_client.hei_no') + ->where('tbl_client.smsenable', '=', 'Yes') + ->where('tbl_client.mfl_code', Auth::user()->facility_id); + + $client_nonconsented = Client::join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select('tbl_client.id') + ->where('tbl_client.status', '=', 'Active') + ->whereNull('tbl_client.hei_no') + ->where('tbl_client.smsenable', '!=', 'Yes') + ->where('tbl_client.mfl_code', Auth::user()->facility_id); + + // consented clients by gender + + $client_consented_male = Client::join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->where('tbl_client.smsenable', '=', 'Yes') + ->where('tbl_client.status', '=', 'Active') + ->whereNull('tbl_client.hei_no') + ->where('tbl_client.gender', '=', '2') + ->where('tbl_client.mfl_code', Auth::user()->facility_id); + + $client_consented_female = Client::join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->where('tbl_client.smsenable', '=', 'Yes') + ->where('tbl_client.status', '=', 'Active') + ->whereNull('tbl_client.hei_no') + ->where('tbl_client.gender', '=', '1') + ->where('tbl_client.mfl_code', Auth::user()->facility_id); + + $client_consented_uknown_gender = Client::join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->where('tbl_client.smsenable', '=', 'Yes') + ->where('tbl_client.status', '=', 'Active') + ->whereNull('tbl_client.hei_no') + ->where('tbl_client.gender', '!=', '1') + ->where('tbl_client.gender', '!=', '2') + ->where('tbl_client.mfl_code', Auth::user()->facility_id); + + // non consented clients by gender + $client_nonconsented_male = Client::join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->where('tbl_client.smsenable', '!=', 'Yes') + ->where('tbl_client.status', '=', 'Active') + ->whereNull('tbl_client.hei_no') + ->where('tbl_client.gender', '=', '2') + ->where('tbl_client.mfl_code', Auth::user()->facility_id); + + + $client_nonconsented_female = Client::join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->where('tbl_client.smsenable', '!=', 'Yes') + ->where('tbl_client.status', '=', 'Active') + ->whereNull('tbl_client.hei_no') + ->where('tbl_client.gender', '=', '1') + ->where('tbl_client.mfl_code', Auth::user()->facility_id); + + $client_nonconsented_uknown_gender = Client::join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->where('tbl_client.smsenable', '!=', 'Yes') + ->where('tbl_client.gender', '!=', '1') + ->where('tbl_client.gender', '!=', '2') + ->where('tbl_client.mfl_code', Auth::user()->facility_id); + + // consented clients by age distribution + $client_consented_to_nine = Client::join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) > 0) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 9)) then `tbl_client`.`dob` end)) AS count")) + ->where('tbl_client.smsenable', '=', 'Yes') + ->where('tbl_client.status', '=', 'Active') + ->whereNull('tbl_client.hei_no') + ->where('tbl_client.mfl_code', Auth::user()->facility_id); + + $client_consented_to_fourteen = Client::join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 10) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 14)) then `tbl_client`.`dob` end)) AS count")) + ->where('tbl_client.smsenable', '=', 'Yes') + ->where('tbl_client.status', '=', 'Active') + ->whereNull('tbl_client.hei_no') + ->where('tbl_client.mfl_code', Auth::user()->facility_id); + + $client_consented_to_nineteen = Client::join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 15) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 19)) then `tbl_client`.`dob` end)) AS count")) + ->where('tbl_client.smsenable', '=', 'Yes') + ->where('tbl_client.status', '=', 'Active') + ->whereNull('tbl_client.hei_no') + ->where('tbl_client.mfl_code', Auth::user()->facility_id); + + $client_consented_to_twentyfour = Client::join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 20) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 24)) then `tbl_client`.`dob` end)) AS count")) + ->where('tbl_client.smsenable', '=', 'Yes') + ->where('tbl_client.status', '=', 'Active') + ->whereNull('tbl_client.hei_no') + ->where('tbl_client.mfl_code', Auth::user()->facility_id); + + $client_consented_to_twentyfive_above = Client::join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 25)) then `tbl_client`.`dob` end)) AS count")) + ->where('tbl_client.smsenable', '=', 'Yes') + ->where('tbl_client.status', '=', 'Active') + ->whereNull('tbl_client.hei_no') + ->where('tbl_client.mfl_code', Auth::user()->facility_id); + + $client_consented_uknown_age = Client::join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select('tbl_client.smsenable') + ->where('tbl_client.dob', '=', '') + ->where('tbl_client.status', '=', 'Active') + ->whereNull('tbl_client.hei_no') + ->orWhereNull('tbl_client.dob') + ->where('tbl_client.smsenable', '=', 'Yes') + ->where('tbl_client.mfl_code', Auth::user()->facility_id); + + // non consented clients by age distribution + $client_nonconsented_to_nine = Client::join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) > 0) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 9)) then `tbl_client`.`dob` end)) AS count")) + ->where('tbl_client.smsenable', '!=', 'Yes') + ->where('tbl_client.status', '=', 'Active') + ->whereNull('tbl_client.hei_no') + ->where('tbl_client.mfl_code', Auth::user()->facility_id); + + $client_nonconsented_to_fourteen = Client::join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 10) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 14)) then `tbl_client`.`dob` end)) AS count")) + ->where('tbl_client.smsenable', '!=', 'Yes') + ->where('tbl_client.status', '=', 'Active') + ->whereNull('tbl_client.hei_no') + ->where('tbl_client.mfl_code', Auth::user()->facility_id); + + $client_nonconsented_to_nineteen = Client::join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 15) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 19)) then `tbl_client`.`dob` end)) AS count")) + ->where('tbl_client.smsenable', '!=', 'Yes') + ->where('tbl_client.status', '=', 'Active') + ->whereNull('tbl_client.hei_no') + ->where('tbl_client.mfl_code', Auth::user()->facility_id); + + $client_nonconsented_to_twentyfour = Client::join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 20) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 24)) then `tbl_client`.`dob` end)) AS count")) + ->where('tbl_client.smsenable', '!=', 'Yes') + ->where('tbl_client.status', '=', 'Active') + ->whereNull('tbl_client.hei_no') + ->where('tbl_client.mfl_code', Auth::user()->facility_id); + + $client_nonconsented_to_twentyfive_above = Client::join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 25)) then `tbl_client`.`dob` end)) AS count")) + ->where('tbl_client.smsenable', '!=', 'Yes') + ->where('tbl_client.status', '=', 'Active') + ->whereNull('tbl_client.hei_no') + ->where('tbl_client.mfl_code', Auth::user()->facility_id); + $client_nonconsented_uknown_age = Client::join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select('tbl_client.smsenable') + ->where('tbl_client.status', '=', 'Active') + ->whereNull('tbl_client.hei_no') + ->where('tbl_client.dob', '=', '') + ->orWhereNull('tbl_client.dob') + ->where('tbl_client.smsenable', '!=', 'Yes') + ->where('tbl_client.mfl_code', Auth::user()->facility_id); + } + + if (Auth::user()->access_level == 'Partner') { + $client = Client::join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->where('tbl_client.status', '=', 'Active') + ->whereNull('tbl_client.hei_no') + ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id); + $client_consented = Client::join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select('tbl_client.id') + ->where('tbl_client.status', '=', 'Active') + ->whereNull('tbl_client.hei_no') + ->where('tbl_client.smsenable', '=', 'Yes') + ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id); + + $client_nonconsented = Client::join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select('tbl_client.id') + ->where('tbl_client.status', '=', 'Active') + ->whereNull('tbl_client.hei_no') + ->where('tbl_client.smsenable', '!=', 'Yes') + ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id); + + // consented clients by gender + + $client_consented_male = Client::join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->where('tbl_client.smsenable', '=', 'Yes') + ->where('tbl_client.status', '=', 'Active') + ->whereNull('tbl_client.hei_no') + ->where('tbl_client.gender', '=', '2') + ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id); + + $client_consented_female = Client::join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->where('tbl_client.smsenable', '=', 'Yes') + ->where('tbl_client.status', '=', 'Active') + ->whereNull('tbl_client.hei_no') + ->where('tbl_client.gender', '=', '1') + ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id); + + $client_consented_uknown_gender = Client::join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->where('tbl_client.smsenable', '=', 'Yes') + ->where('tbl_client.status', '=', 'Active') + ->whereNull('tbl_client.hei_no') + ->where('tbl_client.gender', '!=', '1') + ->where('tbl_client.gender', '!=', '2') + ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id); + + // non consented clients by gender + $client_nonconsented_male = Client::join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->where('tbl_client.smsenable', '!=', 'Yes') + ->where('tbl_client.status', '=', 'Active') + ->whereNull('tbl_client.hei_no') + ->where('tbl_client.gender', '=', '2') + ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id); + + + $client_nonconsented_female = Client::join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->where('tbl_client.smsenable', '!=', 'Yes') + ->where('tbl_client.status', '=', 'Active') + ->whereNull('tbl_client.hei_no') + ->where('tbl_client.gender', '=', '1') + ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id); + + $client_nonconsented_uknown_gender = Client::join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->where('tbl_client.smsenable', '!=', 'Yes') + ->where('tbl_client.gender', '!=', '1') + ->where('tbl_client.gender', '!=', '2') + ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id); + + // consented clients by age distribution + $client_consented_to_nine = Client::join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) > 0) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 9)) then `tbl_client`.`dob` end)) AS count")) + ->where('tbl_client.smsenable', '=', 'Yes') + ->where('tbl_client.status', '=', 'Active') + ->whereNull('tbl_client.hei_no') + ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id); + + $client_consented_to_fourteen = Client::join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 10) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 14)) then `tbl_client`.`dob` end)) AS count")) + ->where('tbl_client.smsenable', '=', 'Yes') + ->where('tbl_client.status', '=', 'Active') + ->whereNull('tbl_client.hei_no') + ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id); + + $client_consented_to_nineteen = Client::join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 15) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 19)) then `tbl_client`.`dob` end)) AS count")) + ->where('tbl_client.smsenable', '=', 'Yes') + ->where('tbl_client.status', '=', 'Active') + ->whereNull('tbl_client.hei_no') + ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id); + + $client_consented_to_twentyfour = Client::join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 20) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 24)) then `tbl_client`.`dob` end)) AS count")) + ->where('tbl_client.smsenable', '=', 'Yes') + ->where('tbl_client.status', '=', 'Active') + ->whereNull('tbl_client.hei_no') + ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id); + + $client_consented_to_twentyfive_above = Client::join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 25)) then `tbl_client`.`dob` end)) AS count")) + ->where('tbl_client.smsenable', '=', 'Yes') + ->where('tbl_client.status', '=', 'Active') + ->whereNull('tbl_client.hei_no') + ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id); + + $client_consented_uknown_age = Client::join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select('tbl_client.smsenable') + ->where('tbl_client.dob', '=', '') + ->where('tbl_client.status', '=', 'Active') + ->whereNull('tbl_client.hei_no') + ->orWhereNull('tbl_client.dob') + ->where('tbl_client.smsenable', '=', 'Yes') + ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id); + + // non consented clients by age distribution + $client_nonconsented_to_nine = Client::join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) > 0) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 9)) then `tbl_client`.`dob` end)) AS count")) + ->where('tbl_client.smsenable', '!=', 'Yes') + ->where('tbl_client.status', '=', 'Active') + ->whereNull('tbl_client.hei_no') + ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id); + + $client_nonconsented_to_fourteen = Client::join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 10) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 14)) then `tbl_client`.`dob` end)) AS count")) + ->where('tbl_client.smsenable', '!=', 'Yes') + ->where('tbl_client.status', '=', 'Active') + ->whereNull('tbl_client.hei_no') + ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id); + + $client_nonconsented_to_nineteen = Client::join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 15) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 19)) then `tbl_client`.`dob` end)) AS count")) + ->where('tbl_client.smsenable', '!=', 'Yes') + ->where('tbl_client.status', '=', 'Active') + ->whereNull('tbl_client.hei_no') + ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id); + + $client_nonconsented_to_twentyfour = Client::join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 20) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 24)) then `tbl_client`.`dob` end)) AS count")) + ->where('tbl_client.smsenable', '!=', 'Yes') + ->where('tbl_client.status', '=', 'Active') + ->whereNull('tbl_client.hei_no') + ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id); + + $client_nonconsented_to_twentyfive_above = Client::join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 25)) then `tbl_client`.`dob` end)) AS count")) + ->where('tbl_client.smsenable', '!=', 'Yes') + ->where('tbl_client.status', '=', 'Active') + ->whereNull('tbl_client.hei_no') + ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id); + + $client_nonconsented_uknown_age = Client::join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select('tbl_client.smsenable') + ->where('tbl_client.status', '=', 'Active') + ->whereNull('tbl_client.hei_no') + ->where('tbl_client.dob', '=', '') + ->orWhereNull('tbl_client.dob') + ->where('tbl_client.smsenable', '!=', 'Yes') + ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id); + } + if (Auth::user()->access_level == 'Admin' || Auth::user()->access_level == 'Donor') { + + $client = Client::join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->where('tbl_client.status', '=', 'Active') + ->whereNull('tbl_client.hei_no'); + $client_consented = Client::join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select('tbl_client.id') + ->where('tbl_client.status', '=', 'Active') + ->whereNull('tbl_client.hei_no') + ->where('tbl_client.smsenable', '=', 'Yes'); + + $client_nonconsented = Client::join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select('tbl_client.id') + ->where('tbl_client.status', '=', 'Active') + ->whereNull('tbl_client.hei_no') + ->where('tbl_client.smsenable', '!=', 'Yes'); + + // consented clients by gender + + $client_consented_male = Client::join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->where('tbl_client.smsenable', '=', 'Yes') + ->where('tbl_client.status', '=', 'Active') + ->whereNull('tbl_client.hei_no') + ->where('tbl_client.gender', '=', '2'); + + $client_consented_female = Client::join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->where('tbl_client.smsenable', '=', 'Yes') + ->where('tbl_client.status', '=', 'Active') + ->whereNull('tbl_client.hei_no') + ->where('tbl_client.gender', '=', '1'); + + $client_consented_uknown_gender = Client::join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->where('tbl_client.smsenable', '=', 'Yes') + ->where('tbl_client.status', '=', 'Active') + ->whereNull('tbl_client.hei_no') + ->where('tbl_client.gender', '!=', '1') + ->where('tbl_client.gender', '!=', '2'); + + // non consented clients by gender + $client_nonconsented_male = Client::join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->where('tbl_client.smsenable', '!=', 'Yes') + ->where('tbl_client.status', '=', 'Active') + ->whereNull('tbl_client.hei_no') + ->where('tbl_client.gender', '=', '2'); + + + $client_nonconsented_female = Client::join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->where('tbl_client.smsenable', '!=', 'Yes') + ->where('tbl_client.status', '=', 'Active') + ->whereNull('tbl_client.hei_no') + ->where('tbl_client.gender', '=', '1'); + + $client_nonconsented_uknown_gender = Client::join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->where('tbl_client.smsenable', '!=', 'Yes') + ->where('tbl_client.gender', '!=', '1') + ->where('tbl_client.gender', '!=', '2'); + + // consented clients by age distribution + $client_consented_to_nine = Client::join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) > 0) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 9)) then `tbl_client`.`dob` end)) AS count")) + ->where('tbl_client.smsenable', '=', 'Yes') + ->where('tbl_client.status', '=', 'Active') + ->whereNull('tbl_client.hei_no'); + + $client_consented_to_fourteen = Client::join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 10) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 14)) then `tbl_client`.`dob` end)) AS count")) + ->where('tbl_client.smsenable', '=', 'Yes') + ->where('tbl_client.status', '=', 'Active') + ->whereNull('tbl_client.hei_no'); + + $client_consented_to_nineteen = Client::join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 15) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 19)) then `tbl_client`.`dob` end)) AS count")) + ->where('tbl_client.smsenable', '=', 'Yes') + ->where('tbl_client.status', '=', 'Active') + ->whereNull('tbl_client.hei_no'); + + $client_consented_to_twentyfour = Client::join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 20) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 24)) then `tbl_client`.`dob` end)) AS count")) + ->where('tbl_client.smsenable', '=', 'Yes') + ->where('tbl_client.status', '=', 'Active') + ->whereNull('tbl_client.hei_no'); + + $client_consented_to_twentyfive_above = Client::join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 25)) then `tbl_client`.`dob` end)) AS count")) + ->where('tbl_client.smsenable', '=', 'Yes') + ->where('tbl_client.status', '=', 'Active') + ->whereNull('tbl_client.hei_no'); + + $client_consented_uknown_age = Client::join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select('tbl_client.smsenable') + ->where('tbl_client.dob', '=', '') + ->where('tbl_client.status', '=', 'Active') + ->whereNull('tbl_client.hei_no') + ->orWhereNull('tbl_client.dob') + ->where('tbl_client.smsenable', '=', 'Yes'); + + // non consented clients by age distribution + $client_nonconsented_to_nine = Client::join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) > 0) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 9)) then `tbl_client`.`dob` end)) AS count")) + ->where('tbl_client.smsenable', '!=', 'Yes') + ->where('tbl_client.status', '=', 'Active') + ->whereNull('tbl_client.hei_no'); + + $client_nonconsented_to_fourteen = Client::join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 10) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 14)) then `tbl_client`.`dob` end)) AS count")) + ->where('tbl_client.smsenable', '!=', 'Yes') + ->where('tbl_client.status', '=', 'Active') + ->whereNull('tbl_client.hei_no'); + + $client_nonconsented_to_nineteen = Client::join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 15) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 19)) then `tbl_client`.`dob` end)) AS count")) + ->where('tbl_client.smsenable', '!=', 'Yes') + ->where('tbl_client.status', '=', 'Active') + ->whereNull('tbl_client.hei_no'); + + $client_nonconsented_to_twentyfour = Client::join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 20) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 24)) then `tbl_client`.`dob` end)) AS count")) + ->where('tbl_client.smsenable', '!=', 'Yes') + ->where('tbl_client.status', '=', 'Active') + ->whereNull('tbl_client.hei_no'); + + $client_nonconsented_to_twentyfive_above = Client::join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 25)) then `tbl_client`.`dob` end)) AS count")) + ->where('tbl_client.smsenable', '!=', 'Yes') + ->where('tbl_client.status', '=', 'Active') + ->whereNull('tbl_client.hei_no'); + + $client_nonconsented_uknown_age = Client::join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select('tbl_client.smsenable') + ->where('tbl_client.status', '=', 'Active') + ->whereNull('tbl_client.hei_no') + ->where('tbl_client.dob', '=', '') + ->orWhereNull('tbl_client.dob') + ->where('tbl_client.smsenable', '!=', 'Yes'); + } + + if (!empty($selected_partners)) { + $client = $client->where('tbl_partner_facility.partner_id', $selected_partners); + $client_consented = $client_consented->where('tbl_partner_facility.partner_id', $selected_partners); + $client_nonconsented = $client_nonconsented->where('tbl_partner_facility.partner_id', $selected_partners); + $client_consented_male = $client_consented_male->where('tbl_partner_facility.partner_id', $selected_partners); + $client_consented_female = $client_consented_female->where('tbl_partner_facility.partner_id', $selected_partners); + $client_consented_uknown_gender = $client_consented_uknown_gender->where('tbl_partner_facility.partner_id', $selected_partners); + $client_nonconsented_male = $client_nonconsented_male->where('tbl_partner_facility.partner_id', $selected_partners); + $client_nonconsented_female = $client_nonconsented_female->where('tbl_partner_facility.partner_id', $selected_partners); + $client_nonconsented_uknown_gender = $client_nonconsented_uknown_gender->where('tbl_partner_facility.partner_id', $selected_partners); + $client_consented_to_nine = $client_consented_to_nine->where('tbl_partner_facility.partner_id', $selected_partners); + $client_consented_to_fourteen = $client_consented_to_fourteen->where('tbl_partner_facility.partner_id', $selected_partners); + $client_consented_to_nineteen = $client_consented_to_nineteen->where('tbl_partner_facility.partner_id', $selected_partners); + $client_consented_to_twentyfour = $client_consented_to_twentyfour->where('tbl_partner_facility.partner_id', $selected_partners); + $client_consented_to_twentyfive_above = $client_consented_to_twentyfive_above->where('tbl_partner_facility.partner_id', $selected_partners); + $client_consented_uknown_age = $client_consented_uknown_age->where('tbl_partner_facility.partner_id', $selected_partners); + $client_nonconsented_to_nine = $client_nonconsented_to_nine->where('tbl_partner_facility.partner_id', $selected_partners); + $client_nonconsented_to_fourteen = $client_nonconsented_to_fourteen->where('tbl_partner_facility.partner_id', $selected_partners); + $client_nonconsented_to_nineteen = $client_nonconsented_to_nineteen->where('tbl_partner_facility.partner_id', $selected_partners); + $client_nonconsented_to_twentyfour = $client_nonconsented_to_twentyfour->where('tbl_partner_facility.partner_id', $selected_partners); + $client_nonconsented_to_twentyfive_above = $client_nonconsented_to_twentyfive_above->where('tbl_partner_facility.partner_id', $selected_partners); + $client_nonconsented_uknown_age = $client_nonconsented_uknown_age->where('tbl_partner_facility.partner_id', $selected_partners); + } + if (!empty($selected_counties)) { + $client = $client->where('tbl_partner_facility.county_id', $selected_counties); + $client_consented = $client_consented->where('tbl_partner_facility.county_id', $selected_counties); + $client_nonconsented = $client_nonconsented->where('tbl_partner_facility.county_id', $selected_counties); + $client_consented_male = $client_consented_male->where('tbl_partner_facility.county_id', $selected_counties); + $client_consented_female = $client_consented_female->where('tbl_partner_facility.county_id', $selected_counties); + $client_consented_uknown_gender = $client_consented_uknown_gender->where('tbl_partner_facility.county_id', $selected_counties); + $client_nonconsented_male = $client_nonconsented_male->where('tbl_partner_facility.county_id', $selected_counties); + $client_nonconsented_female = $client_nonconsented_female->where('tbl_partner_facility.county_id', $selected_counties); + $client_nonconsented_uknown_gender = $client_nonconsented_uknown_gender->where('tbl_partner_facility.county_id', $selected_counties); + $client_consented_to_nine = $client_consented_to_nine->where('tbl_partner_facility.county_id', $selected_counties); + $client_consented_to_fourteen = $client_consented_to_fourteen->where('tbl_partner_facility.county_id', $selected_counties); + $client_consented_to_nineteen = $client_consented_to_nineteen->where('tbl_partner_facility.county_id', $selected_counties); + $client_consented_to_twentyfour = $client_consented_to_twentyfour->where('tbl_partner_facility.county_id', $selected_counties); + $client_consented_to_twentyfive_above = $client_consented_to_twentyfive_above->where('tbl_partner_facility.county_id', $selected_counties); + $client_consented_uknown_age = $client_consented_uknown_age->where('tbl_partner_facility.county_id', $selected_counties); + $client_nonconsented_to_nine = $client_nonconsented_to_nine->where('tbl_partner_facility.county_id', $selected_counties); + $client_nonconsented_to_fourteen = $client_nonconsented_to_fourteen->where('tbl_partner_facility.county_id', $selected_counties); + $client_nonconsented_to_nineteen = $client_nonconsented_to_nineteen->where('tbl_partner_facility.county_id', $selected_counties); + $client_nonconsented_to_twentyfour = $client_nonconsented_to_twentyfour->where('tbl_partner_facility.county_id', $selected_counties); + $client_nonconsented_to_twentyfive_above = $client_nonconsented_to_twentyfive_above->where('tbl_partner_facility.county_id', $selected_counties); + $client_nonconsented_uknown_age = $client_nonconsented_uknown_age->where('tbl_partner_facility.county_id', $selected_counties); + } + if (!empty($selected_subcounties)) { + $client = $client->where('tbl_partner_facility.sub_county_id', $selected_subcounties); + $client_consented = $client_consented->where('tbl_partner_facility.sub_county_id', $selected_subcounties); + $client_nonconsented = $client_nonconsented->where('tbl_partner_facility.sub_county_id', $selected_subcounties); + $client_consented_male = $client_consented_male->where('tbl_partner_facility.sub_county_id', $selected_subcounties); + $client_consented_female = $client_consented_female->where('tbl_partner_facility.sub_county_id', $selected_subcounties); + $client_consented_uknown_gender = $client_consented_uknown_gender->where('tbl_partner_facility.sub_county_id', $selected_subcounties); + $client_nonconsented_male = $client_nonconsented_male->where('tbl_partner_facility.sub_county_id', $selected_subcounties); + $client_nonconsented_female = $client_nonconsented_female->where('tbl_partner_facility.sub_county_id', $selected_subcounties); + $client_nonconsented_uknown_gender = $client_nonconsented_uknown_gender->where('tbl_partner_facility.sub_county_id', $selected_subcounties); + $client_consented_to_nine = $client_consented_to_nine->where('tbl_partner_facility.sub_county_id', $selected_subcounties); + $client_consented_to_fourteen = $client_consented_to_fourteen->where('tbl_partner_facility.sub_county_id', $selected_subcounties); + $client_consented_to_nineteen = $client_consented_to_nineteen->where('tbl_partner_facility.sub_county_id', $selected_subcounties); + $client_consented_to_twentyfour = $client_consented_to_twentyfour->where('tbl_partner_facility.sub_county_id', $selected_subcounties); + $client_consented_to_twentyfive_above = $client_consented_to_twentyfive_above->where('tbl_partner_facility.sub_county_id', $selected_subcounties); + $client_consented_uknown_age = $client_consented_uknown_age->where('tbl_partner_facility.sub_county_id', $selected_subcounties); + $client_nonconsented_to_nine = $client_nonconsented_to_nine->where('tbl_partner_facility.sub_county_id', $selected_subcounties); + $client_nonconsented_to_fourteen = $client_nonconsented_to_fourteen->where('tbl_partner_facility.sub_county_id', $selected_subcounties); + $client_nonconsented_to_nineteen = $client_nonconsented_to_nineteen->where('tbl_partner_facility.sub_county_id', $selected_subcounties); + $client_nonconsented_to_twentyfour = $client_nonconsented_to_twentyfour->where('tbl_partner_facility.sub_county_id', $selected_subcounties); + $client_nonconsented_to_twentyfive_above = $client_nonconsented_to_twentyfive_above->where('tbl_partner_facility.sub_county_id', $selected_subcounties); + $client_nonconsented_uknown_age = $client_nonconsented_uknown_age->where('tbl_partner_facility.sub_county_id', $selected_subcounties); + } + if (!empty($selected_facilites)) { + $client = $client->where('tbl_partner_facility.mfl_code', $selected_facilites); + $client_consented = $client_consented->where('tbl_partner_facility.mfl_code', $selected_facilites); + $client_nonconsented = $client_nonconsented->where('tbl_partner_facility.mfl_code', $selected_facilites); + $client_consented_male = $client_consented_male->where('tbl_partner_facility.mfl_code', $selected_facilites); + $client_consented_female = $client_consented_female->where('tbl_partner_facility.mfl_code', $selected_facilites); + $client_consented_uknown_gender = $client_consented_uknown_gender->where('tbl_partner_facility.mfl_code', $selected_facilites); + $client_nonconsented_male = $client_nonconsented_male->where('tbl_partner_facility.mfl_code', $selected_facilites); + $client_nonconsented_female = $client_nonconsented_female->where('tbl_partner_facility.mfl_code', $selected_facilites); + $client_nonconsented_uknown_gender = $client_nonconsented_uknown_gender->where('tbl_partner_facility.mfl_code', $selected_facilites); + $client_consented_to_nine = $client_consented_to_nine->where('tbl_partner_facility.mfl_code', $selected_facilites); + $client_consented_to_fourteen = $client_consented_to_fourteen->where('tbl_partner_facility.mfl_code', $selected_facilites); + $client_consented_to_nineteen = $client_consented_to_nineteen->where('tbl_partner_facility.mfl_code', $selected_facilites); + $client_consented_to_twentyfour = $client_consented_to_twentyfour->where('tbl_partner_facility.mfl_code', $selected_facilites); + $client_consented_to_twentyfive_above = $client_consented_to_twentyfive_above->where('tbl_partner_facility.mfl_code', $selected_facilites); + $client_consented_uknown_age = $client_consented_uknown_age->where('tbl_partner_facility.mfl_code', $selected_facilites); + $client_nonconsented_to_nine = $client_nonconsented_to_nine->where('tbl_partner_facility.mfl_code', $selected_facilites); + $client_nonconsented_to_fourteen = $client_nonconsented_to_fourteen->where('tbl_partner_facility.mfl_code', $selected_facilites); + $client_nonconsented_to_nineteen = $client_nonconsented_to_nineteen->where('tbl_partner_facility.mfl_code', $selected_facilites); + $client_nonconsented_to_twentyfour = $client_nonconsented_to_twentyfour->where('tbl_partner_facility.mfl_code', $selected_facilites); + $client_nonconsented_to_twentyfive_above = $client_nonconsented_to_twentyfive_above->where('tbl_partner_facility.mfl_code', $selected_facilites); + $client_nonconsented_uknown_age = $client_nonconsented_uknown_age->where('tbl_partner_facility.mfl_code', $selected_facilites); + } + if (!empty($selected_from || $selected_to)) { + $client = $client ->where('tbl_client.created_at', '>=', date($selected_from))->where('tbl_client.created_at', '<=', date($selected_to)); + $client_consented = $client_consented->where('tbl_client.created_at', '>=', date($request->from))->where('tbl_client.created_at', '<=', date($request->to)); + $client_nonconsented = $client_nonconsented->where('tbl_client.created_at', '>=', date($request->from))->where('tbl_client.created_at', '<=', date($request->to)); + $client_consented_male = $client_consented_male->where('tbl_client.created_at', '>=', date($request->from))->where('tbl_client.created_at', '<=', date($request->to)); + $client_consented_female = $client_consented_female->where('tbl_client.created_at', '>=', date($request->from))->where('tbl_client.created_at', '<=', date($request->to)); + $client_consented_uknown_gender = $client_consented_uknown_gender->where('tbl_client.created_at', '>=', date($request->from))->where('tbl_client.created_at', '<=', date($request->to)); + $client_nonconsented_male = $client_nonconsented_male->where('tbl_client.created_at', '>=', date($request->from))->where('tbl_client.created_at', '<=', date($request->to)); + $client_nonconsented_female = $client_nonconsented_female->where('tbl_client.created_at', '>=', date($request->from))->where('tbl_client.created_at', '<=', date($request->to)); + $client_nonconsented_uknown_gender = $client_nonconsented_uknown_gender->where('tbl_client.created_at', '>=', date($request->from))->where('tbl_client.created_at', '<=', date($request->to)); + $client_consented_to_nine = $client_consented_to_nine->where('tbl_client.created_at', '>=', date($request->from))->where('tbl_client.created_at', '<=', date($request->to)); + $client_consented_to_fourteen = $client_consented_to_fourteen->where('tbl_client.created_at', '>=', date($request->from))->where('tbl_client.created_at', '<=', date($request->to)); + $client_consented_to_nineteen = $client_consented_to_nineteen->where('tbl_client.created_at', '>=', date($request->from))->where('tbl_client.created_at', '<=', date($request->to)); + $client_consented_to_twentyfour = $client_consented_to_twentyfour->where('tbl_client.created_at', '>=', date($request->from))->where('tbl_client.created_at', '<=', date($request->to)); + $client_consented_to_twentyfive_above = $client_consented_to_twentyfive_above->where('tbl_client.created_at', '>=', date($request->from))->where('tbl_client.created_at', '<=', date($request->to)); + $client_consented_uknown_age = $client_consented_uknown_age->where('tbl_client.created_at', '>=', date($request->from))->where('tbl_client.created_at', '<=', date($request->to)); + $client_nonconsented_to_nine = $client_nonconsented_to_nine->where('tbl_client.created_at', '>=', date($request->from))->where('tbl_client.created_at', '<=', date($request->to)); + $client_nonconsented_to_fourteen = $client_nonconsented_to_fourteen->where('tbl_client.created_at', '>=', date($request->from))->where('tbl_client.created_at', '<=', date($request->to)); + $client_nonconsented_to_nineteen = $client_nonconsented_to_nineteen->where('tbl_client.created_at', '>=', date($request->from))->where('tbl_client.created_at', '<=', date($request->to)); + $client_nonconsented_to_twentyfour = $client_nonconsented_to_twentyfour->where('tbl_client.created_at', '>=', date($request->from))->where('tbl_client.created_at', '<=', date($request->to)); + $client_nonconsented_to_twentyfive_above = $client_nonconsented_to_twentyfive_above->where('tbl_client.created_at', '>=', date($request->from))->where('tbl_client.created_at', '<=', date($request->to)); + $client_nonconsented_uknown_age = $client_nonconsented_uknown_age->where('tbl_client.created_at', '>=', date($request->from))->where('tbl_client.created_at', '<=', date($request->to)); + } + + + $data["client"] = $client->count(); + $data["client_consented"] = $client_consented->count(); + $data["client_nonconsented"] = $client_nonconsented->count(); + $data["client_consented_male"] = $client_consented_male->count(); + $data["client_consented_female"] = $client_consented_female->count(); + $data["client_consented_uknown_gender"] = $client_consented_uknown_gender->count(); + $data["client_nonconsented_male"] = $client_nonconsented_male->count(); + $data["client_nonconsented_female"] = $client_nonconsented_female->count(); + $data["client_nonconsented_uknown_gender"] = $client_nonconsented_uknown_gender->count(); + $data["client_consented_to_nine"] = $client_consented_to_nine->pluck('count'); + $data["client_consented_to_fourteen"] = $client_consented_to_fourteen->pluck('count'); + $data["client_consented_to_nineteen"] = $client_consented_to_nineteen->pluck('count'); + $data["client_consented_to_twentyfour"] = $client_consented_to_twentyfour->pluck('count'); + $data["client_consented_to_twentyfive_above"] = $client_consented_to_twentyfive_above->pluck('count'); + $data["client_consented_uknown_age"] = $client_consented_uknown_age->count(); + $data["client_nonconsented_to_nine"] = $client_nonconsented_to_nine->pluck('count'); + $data["client_nonconsented_to_fourteen"] = $client_nonconsented_to_fourteen->pluck('count'); + $data["client_nonconsented_to_nineteen"] = $client_nonconsented_to_nineteen->pluck('count'); + $data["client_nonconsented_to_twentyfour"] = $client_nonconsented_to_twentyfour->pluck('count'); + $data["client_nonconsented_to_twentyfive_above"] = $client_nonconsented_to_twentyfive_above->pluck('count'); + $data["client_nonconsented_uknown_age"] = $client_nonconsented_uknown_age->count(); + + return $data; + } + public function filter_appointment_charts(Request $request) + { + $data = []; + // client charts + $selected_partners = $request->partners; + $selected_counties = $request->counties; + $selected_subcounties = $request->subcounties; + $selected_facilites = $request->facilities; + $selected_from = $request->from; + $selected_to = $request->to; + + if (Auth::user()->access_level == 'Facility') { + $appointment = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select('tbl_appointment.id') + ->where('tbl_client.mfl_code', Auth::user()->facility_id); + $appointment_honoured = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select('tbl_appointment.id') + ->where('tbl_appointment.date_attended', '=', DB::raw('tbl_appointment.appntmnt_date')) + ->where('tbl_client.mfl_code', Auth::user()->facility_id); + $appointment_not_honoured = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select('tbl_appointment.id') + ->whereIn('tbl_appointment.app_status', ['Defaulted', 'LTFU', 'Missed']) + ->where('tbl_client.mfl_code', Auth::user()->facility_id); + // appointment honored by gender + $appointment_honoured_male = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select('tbl_appointment.id') + ->where('tbl_appointment.date_attended', '=', DB::raw('tbl_appointment.appntmnt_date')) + ->where('tbl_client.gender', '=', '2') + ->where('tbl_client.mfl_code', Auth::user()->facility_id); + $appointment_honoured_female = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->where('tbl_appointment.date_attended', '=', DB::raw('tbl_appointment.appntmnt_date')) + ->where('tbl_client.gender', '=', '1') + ->where('tbl_client.mfl_code', Auth::user()->facility_id); + $appointment_honoured_uknown_gender = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->where('tbl_appointment.date_attended', '=', DB::raw('tbl_appointment.appntmnt_date')) + ->where('tbl_client.gender', '!=', '1') + ->where('tbl_client.gender', '!=', '2') + ->where('tbl_client.mfl_code', Auth::user()->facility_id); + // appointment honored by age + $appointment_honored_to_nine = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) > 0) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 9)) then `tbl_client`.`id` end)) AS count")) + ->where('tbl_appointment.date_attended', '=', DB::raw('tbl_appointment.appntmnt_date')) + ->where('tbl_client.mfl_code', Auth::user()->facility_id); + + $appointment_honored_to_fourteen = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 10) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 14)) then `tbl_client`.`id` end)) AS count")) + ->where('tbl_appointment.date_attended', '=', DB::raw('tbl_appointment.appntmnt_date')) + ->where('tbl_client.mfl_code', Auth::user()->facility_id); + + $appointment_honored_to_nineteen = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 15) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 19)) then `tbl_client`.`id` end)) AS count")) + ->where('tbl_appointment.date_attended', '=', DB::raw('tbl_appointment.appntmnt_date')) + ->where('tbl_client.mfl_code', Auth::user()->facility_id); + + $appointment_honored_to_twentyfour = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 20) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 24)) then `tbl_client`.`id` end)) AS count")) + ->where('tbl_appointment.date_attended', '=', DB::raw('tbl_appointment.appntmnt_date')) + ->where('tbl_client.mfl_code', Auth::user()->facility_id); + + $appointment_honored_to_twentyfive_above = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 25)) then `tbl_client`.`id` end)) AS count")) + ->where('tbl_appointment.date_attended', '=', DB::raw('tbl_appointment.appntmnt_date')) + ->where('tbl_client.mfl_code', Auth::user()->facility_id); + $appointment_honored_to_uknown_age = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select('tbl_client.dob') + ->where('tbl_appointment.date_attended', '=', DB::raw('tbl_appointment.appntmnt_date')) + ->where('tbl_client.dob', '=', '') + ->orWhereNull('tbl_client.dob') + ->where('tbl_client.mfl_code', Auth::user()->facility_id); + + // appointment not honored by gender + $appointment_not_honoured_male = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->where('tbl_client.gender', '=', '2') + ->whereIn('app_status', ['Defaulted', 'LTFU', 'Missed']) + ->where('tbl_client.mfl_code', Auth::user()->facility_id); + + $appointment_not_honoured_female = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->where('tbl_client.gender', '=', '1') + ->whereIn('app_status', ['Defaulted', 'LTFU', 'Missed']) + ->where('tbl_client.mfl_code', Auth::user()->facility_id); + + $appointment_not_honoured_uknown_gender = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->where('tbl_client.gender', '!=', '1') + ->where('tbl_client.gender', '!=', '2') + ->whereIn('app_status', ['Defaulted', 'LTFU', 'Missed']) + ->where('tbl_client.mfl_code', Auth::user()->facility_id); + // appointment not honored by age + $appointment_not_honored_to_nine = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) > 0) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 9)) then `tbl_client`.`id` end)) AS count")) + ->whereIn('app_status', ['Defaulted', 'LTFU', 'Missed']) + ->where('tbl_client.mfl_code', Auth::user()->facility_id); + + $appointment_not_honored_to_fourteen = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 10) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 14)) then `tbl_client`.`id` end)) AS count")) + ->whereIn('app_status', ['Defaulted', 'LTFU', 'Missed']) + ->where('tbl_client.mfl_code', Auth::user()->facility_id); + + $appointment_not_honored_to_nineteen = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 15) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 19)) then `tbl_client`.`id` end)) AS count")) + ->whereIn('app_status', ['Defaulted', 'LTFU', 'Missed']) + ->where('tbl_client.mfl_code', Auth::user()->facility_id); + + $appointment_not_honored_to_twentyfour = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 20) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 24)) then `tbl_client`.`id` end)) AS count")) + ->whereIn('app_status', ['Defaulted', 'LTFU', 'Missed']) + ->where('tbl_client.mfl_code', Auth::user()->facility_id); + + $appointment_not_honored_to_twentyfive_above = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 25)) then `tbl_client`.`id` end)) AS count")) + ->whereIn('app_status', ['Defaulted', 'LTFU', 'Missed']) + ->where('tbl_client.mfl_code', Auth::user()->facility_id); + + $appointment_not_honored_to_uknown_age = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select('tbl_client.dob') + ->where('tbl_client.dob', '=', '') + ->orWhereNull('tbl_client.dob') + ->whereIn('app_status', ['Defaulted', 'LTFU', 'Missed']) + ->where('tbl_client.mfl_code', Auth::user()->facility_id); + } + if (Auth::user()->access_level == 'Partner') { + $appointment = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select('tbl_appointment.id') + ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id); + $appointment_honoured = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select('tbl_appointment.id') + ->where('tbl_appointment.date_attended', '=', DB::raw('tbl_appointment.appntmnt_date')) + ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id); + $appointment_not_honoured = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select('tbl_appointment.id') + ->whereIn('tbl_appointment.app_status', ['Defaulted', 'LTFU', 'Missed']) + ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id); + // appointment honored by gender + $appointment_honoured_male = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select('tbl_appointment.id') + ->where('tbl_appointment.date_attended', '=', DB::raw('tbl_appointment.appntmnt_date')) + ->where('tbl_client.gender', '=', '2') + ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id); + $appointment_honoured_female = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->where('tbl_appointment.date_attended', '=', DB::raw('tbl_appointment.appntmnt_date')) + ->where('tbl_client.gender', '=', '1') + ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id); + $appointment_honoured_uknown_gender = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->where('tbl_appointment.date_attended', '=', DB::raw('tbl_appointment.appntmnt_date')) + ->where('tbl_client.gender', '!=', '1') + ->where('tbl_client.gender', '!=', '2') + ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id); + // appointment honored by age + $appointment_honored_to_nine = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) > 0) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 9)) then `tbl_client`.`id` end)) AS count")) + ->where('tbl_appointment.date_attended', '=', DB::raw('tbl_appointment.appntmnt_date')) + ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id); + + $appointment_honored_to_fourteen = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 10) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 14)) then `tbl_client`.`id` end)) AS count")) + ->where('tbl_appointment.date_attended', '=', DB::raw('tbl_appointment.appntmnt_date')) + ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id); + + $appointment_honored_to_nineteen = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 15) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 19)) then `tbl_client`.`id` end)) AS count")) + ->where('tbl_appointment.date_attended', '=', DB::raw('tbl_appointment.appntmnt_date')) + ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id); + + $appointment_honored_to_twentyfour = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 20) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 24)) then `tbl_client`.`id` end)) AS count")) + ->where('tbl_appointment.date_attended', '=', DB::raw('tbl_appointment.appntmnt_date')) + ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id); + + $appointment_honored_to_twentyfive_above = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 25)) then `tbl_client`.`id` end)) AS count")) + ->where('tbl_appointment.date_attended', '=', DB::raw('tbl_appointment.appntmnt_date')) + ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id); + $appointment_honored_to_uknown_age = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select('tbl_client.dob') + ->where('tbl_appointment.date_attended', '=', DB::raw('tbl_appointment.appntmnt_date')) + ->where('tbl_client.dob', '=', '') + ->orWhereNull('tbl_client.dob') + ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id; + + // appointment not honored by gender + $appointment_not_honoured_male = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->where('tbl_client.gender', '=', '2') + ->whereIn('app_status', ['Defaulted', 'LTFU', 'Missed']) + ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id); + + $appointment_not_honoured_female = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->where('tbl_client.gender', '=', '1') + ->whereIn('app_status', ['Defaulted', 'LTFU', 'Missed']) + ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id); + + $appointment_not_honoured_uknown_gender = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->where('tbl_client.gender', '!=', '1') + ->where('tbl_client.gender', '!=', '2') + ->whereIn('app_status', ['Defaulted', 'LTFU', 'Missed']) + ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id); + // appointment not honored by age + $appointment_not_honored_to_nine = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) > 0) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 9)) then `tbl_client`.`id` end)) AS count")) + ->whereIn('app_status', ['Defaulted', 'LTFU', 'Missed']) + ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id); + + $appointment_not_honored_to_fourteen = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 10) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 14)) then `tbl_client`.`id` end)) AS count")) + ->whereIn('app_status', ['Defaulted', 'LTFU', 'Missed']) + ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id); + + $appointment_not_honored_to_nineteen = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 15) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 19)) then `tbl_client`.`id` end)) AS count")) + ->whereIn('app_status', ['Defaulted', 'LTFU', 'Missed']) + ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id); + + $appointment_not_honored_to_twentyfour = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 20) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 24)) then `tbl_client`.`id` end)) AS count")) + ->whereIn('app_status', ['Defaulted', 'LTFU', 'Missed']) + ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id); + + $appointment_not_honored_to_twentyfive_above = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 25)) then `tbl_client`.`id` end)) AS count")) + ->whereIn('app_status', ['Defaulted', 'LTFU', 'Missed']) + ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id); + + $appointment_not_honored_to_uknown_age = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select('tbl_client.dob') + ->where('tbl_client.dob', '=', '') + ->orWhereNull('tbl_client.dob') + ->whereIn('app_status', ['Defaulted', 'LTFU', 'Missed']) + ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id); + } + if (Auth::user()->access_level == 'Admin' || Auth::user()->access_level == 'Donor') { + $appointment = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select('tbl_appointment.id'); + $appointment_honoured = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select('tbl_appointment.id') + ->where('tbl_appointment.date_attended', '=', DB::raw('tbl_appointment.appntmnt_date')); + $appointment_not_honoured = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select('tbl_appointment.id') + ->whereIn('tbl_appointment.app_status', ['Defaulted', 'LTFU', 'Missed']); + // appointment honored by gender + $appointment_honoured_male = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select('tbl_appointment.id') + ->where('tbl_appointment.date_attended', '=', DB::raw('tbl_appointment.appntmnt_date')) + ->where('tbl_client.gender', '=', '2'); + $appointment_honoured_female = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->where('tbl_appointment.date_attended', '=', DB::raw('tbl_appointment.appntmnt_date')) + ->where('tbl_client.gender', '=', '1'); + $appointment_honoured_uknown_gender = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->where('tbl_appointment.date_attended', '=', DB::raw('tbl_appointment.appntmnt_date')) + ->where('tbl_client.gender', '!=', '1') + ->where('tbl_client.gender', '!=', '2'); + // appointment honored by age + $appointment_honored_to_nine = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) > 0) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 9)) then `tbl_client`.`id` end)) AS count")) + ->where('tbl_appointment.date_attended', '=', DB::raw('tbl_appointment.appntmnt_date')); + + $appointment_honored_to_fourteen = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 10) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 14)) then `tbl_client`.`id` end)) AS count")) + ->where('tbl_appointment.date_attended', '=', DB::raw('tbl_appointment.appntmnt_date')); + + $appointment_honored_to_nineteen = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 15) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 19)) then `tbl_client`.`id` end)) AS count")) + ->where('tbl_appointment.date_attended', '=', DB::raw('tbl_appointment.appntmnt_date')); + + $appointment_honored_to_twentyfour = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 20) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 24)) then `tbl_client`.`id` end)) AS count")) + ->where('tbl_appointment.date_attended', '=', DB::raw('tbl_appointment.appntmnt_date')); + + $appointment_honored_to_twentyfive_above = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 25)) then `tbl_client`.`id` end)) AS count")) + ->where('tbl_appointment.date_attended', '=', DB::raw('tbl_appointment.appntmnt_date')); + $appointment_honored_to_uknown_age = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select('tbl_client.dob') + ->where('tbl_appointment.date_attended', '=', DB::raw('tbl_appointment.appntmnt_date')) + ->where('tbl_client.dob', '=', '') + ->orWhereNull('tbl_client.dob'); + + // appointment not honored by gender + $appointment_not_honoured_male = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->where('tbl_client.gender', '=', '2') + ->whereIn('app_status', ['Defaulted', 'LTFU', 'Missed']); + + $appointment_not_honoured_female = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->where('tbl_client.gender', '=', '1') + ->whereIn('app_status', ['Defaulted', 'LTFU', 'Missed']); + + $appointment_not_honoured_uknown_gender = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->where('tbl_client.gender', '!=', '1') + ->where('tbl_client.gender', '!=', '2') + ->whereIn('app_status', ['Defaulted', 'LTFU', 'Missed']); + // appointment not honored by age + $appointment_not_honored_to_nine = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) > 0) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 9)) then `tbl_client`.`id` end)) AS count")) + ->whereIn('app_status', ['Defaulted', 'LTFU', 'Missed']); + + $appointment_not_honored_to_fourteen = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 10) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 14)) then `tbl_client`.`id` end)) AS count")) + ->whereIn('app_status', ['Defaulted', 'LTFU', 'Missed']); + + $appointment_not_honored_to_nineteen = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 15) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 19)) then `tbl_client`.`id` end)) AS count")) + ->whereIn('app_status', ['Defaulted', 'LTFU', 'Missed']); + + $appointment_not_honored_to_twentyfour = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 20) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 24)) then `tbl_client`.`id` end)) AS count")) + ->whereIn('app_status', ['Defaulted', 'LTFU', 'Missed']); + + $appointment_not_honored_to_twentyfive_above = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 25)) then `tbl_client`.`id` end)) AS count")) + ->whereIn('app_status', ['Defaulted', 'LTFU', 'Missed']); + + $appointment_not_honored_to_uknown_age = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select('tbl_client.dob') + ->where('tbl_client.dob', '=', '') + ->orWhereNull('tbl_client.dob') + ->whereIn('app_status', ['Defaulted', 'LTFU', 'Missed']); + } + + if (!empty($selected_partners)) { + $appointment = $appointment->where('tbl_partner_facility.partner_id', $selected_partners); + $appointment_honoured = $appointment_honoured->where('tbl_partner_facility.partner_id', $selected_partners); + $appointment_not_honoured = $appointment_not_honoured->where('tbl_partner_facility.partner_id', $selected_partners); + $appointment_honoured_male = $appointment_honoured_male->where('tbl_partner_facility.partner_id', $selected_partners); + $appointment_honoured_female = $appointment_honoured_female->where('tbl_partner_facility.partner_id', $selected_partners); + $appointment_honoured_uknown_gender = $appointment_honoured_uknown_gender->where('tbl_partner_facility.partner_id', $selected_partners); + $appointment_honored_to_nine = $appointment_honored_to_nine->where('tbl_partner_facility.partner_id', $selected_partners); + $appointment_honored_to_fourteen = $appointment_honored_to_fourteen->where('tbl_partner_facility.partner_id', $selected_partners); + $appointment_honored_to_nineteen = $appointment_honored_to_nineteen->where('tbl_partner_facility.partner_id', $selected_partners); + $appointment_honored_to_twentyfour = $appointment_honored_to_twentyfour->where('tbl_partner_facility.partner_id', $selected_partners); + $appointment_honored_to_twentyfive_above = $appointment_honored_to_twentyfive_above->where('tbl_partner_facility.partner_id', $selected_partners); + $appointment_honored_to_uknown_age = $appointment_honored_to_uknown_age->where('tbl_partner_facility.partner_id', $selected_partners); + $appointment_not_honoured_male = $appointment_not_honoured_male->where('tbl_partner_facility.partner_id', $selected_partners); + $appointment_not_honoured_female = $appointment_not_honoured_female->where('tbl_partner_facility.partner_id', $selected_partners); + $appointment_not_honoured_uknown_gender = $appointment_not_honoured_uknown_gender->where('tbl_partner_facility.partner_id', $selected_partners); + $appointment_not_honored_to_nine = $appointment_not_honored_to_nine->where('tbl_partner_facility.partner_id', $selected_partners); + $appointment_not_honored_to_fourteen = $appointment_not_honored_to_fourteen->where('tbl_partner_facility.partner_id', $selected_partners); + $appointment_not_honored_to_nineteen = $appointment_not_honored_to_nineteen->where('tbl_partner_facility.partner_id', $selected_partners); + $appointment_not_honored_to_twentyfour = $appointment_not_honored_to_twentyfour->where('tbl_partner_facility.partner_id', $selected_partners); + $appointment_not_honored_to_twentyfive_above = $appointment_not_honored_to_twentyfive_above->where('tbl_partner_facility.partner_id', $selected_partners); + $appointment_not_honored_to_uknown_age = $appointment_not_honored_to_uknown_age->where('tbl_partner_facility.partner_id', $selected_partners); + } + if (!empty($selected_counties)) { + $appointment = $appointment->where('tbl_partner_facility.county_id', $selected_counties); + $appointment_honoured = $appointment_honoured->where('tbl_partner_facility.county_id', $selected_counties); + $appointment_not_honoured = $appointment_not_honoured->where('tbl_partner_facility.county_id', $selected_counties); + $appointment_honoured_male = $appointment_honoured_male->where('tbl_partner_facility.county_id', $selected_counties); + $appointment_honoured_female = $appointment_honoured_female->where('tbl_partner_facility.county_id', $selected_counties); + $appointment_honoured_uknown_gender = $appointment_honoured_uknown_gender->where('tbl_partner_facility.county_id', $selected_counties); + $appointment_honored_to_nine = $appointment_honored_to_nine->where('tbl_partner_facility.county_id', $selected_counties); + $appointment_honored_to_fourteen = $appointment_honored_to_fourteen->where('tbl_partner_facility.county_id', $selected_counties); + $appointment_honored_to_nineteen = $appointment_honored_to_nineteen->where('tbl_partner_facility.county_id', $selected_counties); + $appointment_honored_to_twentyfour = $appointment_honored_to_twentyfour->where('tbl_partner_facility.county_id', $selected_counties); + $appointment_honored_to_twentyfive_above = $appointment_honored_to_twentyfive_above->where('tbl_partner_facility.county_id', $selected_counties); + $appointment_honored_to_uknown_age = $appointment_honored_to_uknown_age->where('tbl_partner_facility.county_id', $selected_counties); + $appointment_not_honoured_male = $appointment_not_honoured_male->where('tbl_partner_facility.county_id', $selected_counties); + $appointment_not_honoured_female = $appointment_not_honoured_female->where('tbl_partner_facility.county_id', $selected_counties); + $appointment_not_honoured_uknown_gender = $appointment_not_honoured_uknown_gender->where('tbl_partner_facility.county_id', $selected_counties); + $appointment_not_honored_to_nine = $appointment_not_honored_to_nine->where('tbl_partner_facility.county_id', $selected_counties); + $appointment_not_honored_to_fourteen = $appointment_not_honored_to_fourteen->where('tbl_partner_facility.county_id', $selected_counties); + $appointment_not_honored_to_nineteen = $appointment_not_honored_to_nineteen->where('tbl_partner_facility.county_id', $selected_counties); + $appointment_not_honored_to_twentyfour = $appointment_not_honored_to_twentyfour->where('tbl_partner_facility.county_id', $selected_counties); + $appointment_not_honored_to_twentyfive_above = $appointment_not_honored_to_twentyfive_above->where('tbl_partner_facility.county_id', $selected_counties); + $appointment_not_honored_to_uknown_age = $appointment_not_honored_to_uknown_age->where('tbl_partner_facility.county_id', $selected_counties); + } + if (!empty($selected_subcounties)) { + $appointment = $appointment->where('tbl_partner_facility.sub_county_id', $selected_subcounties); + $appointment_honoured = $appointment_honoured->where('tbl_partner_facility.sub_county_id', $selected_subcounties); + $appointment_not_honoured = $appointment_not_honoured->where('tbl_partner_facility.sub_county_id', $selected_subcounties); + $appointment_honoured_male = $appointment_honoured_male->where('tbl_partner_facility.sub_county_id', $selected_subcounties); + $appointment_honoured_female = $appointment_honoured_female->where('tbl_partner_facility.sub_county_id', $selected_subcounties); + $appointment_honoured_uknown_gender = $appointment_honoured_uknown_gender->where('tbl_partner_facility.sub_county_id', $selected_subcounties); + $appointment_honored_to_nine = $appointment_honored_to_nine->where('tbl_partner_facility.sub_county_id', $selected_subcounties); + $appointment_honored_to_fourteen = $appointment_honored_to_fourteen->where('tbl_partner_facility.sub_county_id', $selected_subcounties); + $appointment_honored_to_nineteen = $appointment_honored_to_nineteen->where('tbl_partner_facility.sub_county_id', $selected_subcounties); + $appointment_honored_to_twentyfour = $appointment_honored_to_twentyfour->where('tbl_partner_facility.sub_county_id', $selected_subcounties); + $appointment_honored_to_twentyfive_above = $appointment_honored_to_twentyfive_above->where('tbl_partner_facility.sub_county_id', $selected_subcounties); + $appointment_honored_to_uknown_age = $appointment_honored_to_uknown_age->where('tbl_partner_facility.sub_county_id', $selected_subcounties); + $appointment_not_honoured_male = $appointment_not_honoured_male->where('tbl_partner_facility.sub_county_id', $selected_subcounties); + $appointment_not_honoured_female = $appointment_not_honoured_female->where('tbl_partner_facility.sub_county_id', $selected_subcounties); + $appointment_not_honoured_uknown_gender = $appointment_not_honoured_uknown_gender->where('tbl_partner_facility.sub_county_id', $selected_subcounties); + $appointment_not_honored_to_nine = $appointment_not_honored_to_nine->where('tbl_partner_facility.sub_county_id', $selected_subcounties); + $appointment_not_honored_to_fourteen = $appointment_not_honored_to_fourteen->where('tbl_partner_facility.sub_county_id', $selected_subcounties); + $appointment_not_honored_to_nineteen = $appointment_not_honored_to_nineteen->where('tbl_partner_facility.sub_county_id', $selected_subcounties); + $appointment_not_honored_to_twentyfour = $appointment_not_honored_to_twentyfour->where('tbl_partner_facility.sub_county_id', $selected_subcounties); + $appointment_not_honored_to_twentyfive_above = $appointment_not_honored_to_twentyfive_above->where('tbl_partner_facility.sub_county_id', $selected_subcounties); + $appointment_not_honored_to_uknown_age = $appointment_not_honored_to_uknown_age->where('tbl_partner_facility.sub_county_id', $selected_subcounties); + } + if (!empty($selected_facilites)) { + $appointment = $appointment->where('tbl_partner_facility.mfl_code', $selected_facilites); + $appointment_honoured = $appointment_honoured->where('tbl_partner_facility.mfl_code', $selected_facilites); + $appointment_not_honoured = $appointment_not_honoured->where('tbl_partner_facility.mfl_code', $selected_facilites); + $appointment_honoured_male = $appointment_honoured_male->where('tbl_partner_facility.mfl_code', $selected_facilites); + $appointment_honoured_female = $appointment_honoured_female->where('tbl_partner_facility.mfl_code', $selected_facilites); + $appointment_honoured_uknown_gender = $appointment_honoured_uknown_gender->where('tbl_partner_facility.mfl_code', $selected_facilites); + $appointment_honored_to_nine = $appointment_honored_to_nine->where('tbl_partner_facility.mfl_code', $selected_facilites); + $appointment_honored_to_fourteen = $appointment_honored_to_fourteen->where('tbl_partner_facility.mfl_code', $selected_facilites); + $appointment_honored_to_nineteen = $appointment_honored_to_nineteen->where('tbl_partner_facility.mfl_code', $selected_facilites); + $appointment_honored_to_twentyfour = $appointment_honored_to_twentyfour->where('tbl_partner_facility.mfl_code', $selected_facilites); + $appointment_honored_to_twentyfive_above = $appointment_honored_to_twentyfive_above->where('tbl_partner_facility.mfl_code', $selected_facilites); + $appointment_honored_to_uknown_age = $appointment_honored_to_uknown_age->where('tbl_partner_facility.mfl_code', $selected_facilites); + $appointment_not_honoured_male = $appointment_not_honoured_male->where('tbl_partner_facility.mfl_code', $selected_facilites); + $appointment_not_honoured_female = $appointment_not_honoured_female->where('tbl_partner_facility.mfl_code', $selected_facilites); + $appointment_not_honoured_uknown_gender = $appointment_not_honoured_uknown_gender->where('tbl_partner_facility.mfl_code', $selected_facilites); + $appointment_not_honored_to_nine = $appointment_not_honored_to_nine->where('tbl_partner_facility.mfl_code', $selected_facilites); + $appointment_not_honored_to_fourteen = $appointment_not_honored_to_fourteen->where('tbl_partner_facility.mfl_code', $selected_facilites); + $appointment_not_honored_to_nineteen = $appointment_not_honored_to_nineteen->where('tbl_partner_facility.mfl_code', $selected_facilites); + $appointment_not_honored_to_twentyfour = $appointment_not_honored_to_twentyfour->where('tbl_partner_facility.mfl_code', $selected_facilites); + $appointment_not_honored_to_twentyfive_above = $appointment_not_honored_to_twentyfive_above->where('tbl_partner_facility.mfl_code', $selected_facilites); + $appointment_not_honored_to_uknown_age = $appointment_not_honored_to_uknown_age->where('tbl_partner_facility.mfl_code', $selected_facilites); + } + if (!empty($selected_from || $selected_to)) { + $appointment = $appointment->where('tbl_appointment.created_at', '>=', date($request->from))->where('tbl_appointment.created_at', '<=', date($request->to)); + $appointment_honoured = $appointment_honoured->where('tbl_appointment.created_at', '>=', date($request->from))->where('tbl_appointment.created_at', '<=', date($request->to)); + $appointment_not_honoured = $appointment_not_honoured->where('tbl_appointment.created_at', '>=', date($request->from))->where('tbl_appointment.created_at', '<=', date($request->to)); + $appointment_honoured_male = $appointment_honoured_male->where('tbl_appointment.created_at', '>=', date($request->from))->where('tbl_appointment.created_at', '<=', date($request->to)); + $appointment_honoured_female = $appointment_honoured_female->where('tbl_appointment.created_at', '>=', date($request->from))->where('tbl_appointment.created_at', '<=', date($request->to)); + $appointment_honoured_uknown_gender = $appointment_honoured_uknown_gender->where('tbl_appointment.created_at', '>=', date($request->from))->where('tbl_appointment.created_at', '<=', date($request->to)); + $appointment_honored_to_nine = $appointment_honored_to_nine->where('tbl_appointment.created_at', '>=', date($request->from))->where('tbl_appointment.created_at', '<=', date($request->to)); + $appointment_honored_to_fourteen = $appointment_honored_to_fourteen->where('tbl_appointment.created_at', '>=', date($request->from))->where('tbl_appointment.created_at', '<=', date($request->to)); + $appointment_honored_to_nineteen = $appointment_honored_to_nineteen->where('tbl_appointment.created_at', '>=', date($request->from))->where('tbl_appointment.created_at', '<=', date($request->to)); + $appointment_honored_to_twentyfour = $appointment_honored_to_twentyfour->where('tbl_appointment.created_at', '>=', date($request->from))->where('tbl_appointment.created_at', '<=', date($request->to)); + $appointment_honored_to_twentyfive_above = $appointment_honored_to_twentyfive_above->where('tbl_appointment.created_at', '>=', date($request->from))->where('tbl_appointment.created_at', '<=', date($request->to)); + $appointment_honored_to_uknown_age = $appointment_honored_to_uknown_age->where('tbl_appointment.created_at', '>=', date($request->from))->where('tbl_appointment.created_at', '<=', date($request->to)); + $appointment_not_honoured_male = $appointment_not_honoured_male->where('tbl_appointment.created_at', '>=', date($request->from))->where('tbl_appointment.created_at', '<=', date($request->to)); + $appointment_not_honoured_female = $appointment_not_honoured_female->where('tbl_appointment.created_at', '>=', date($request->from))->where('tbl_appointment.created_at', '<=', date($request->to)); + $appointment_not_honoured_uknown_gender = $appointment_not_honoured_uknown_gender->where('tbl_appointment.created_at', '>=', date($request->from))->where('tbl_appointment.created_at', '<=', date($request->to)); + $appointment_not_honored_to_nine = $appointment_not_honored_to_nine->where('tbl_appointment.created_at', '>=', date($request->from))->where('tbl_appointment.created_at', '<=', date($request->to)); + $appointment_not_honored_to_fourteen = $appointment_not_honored_to_fourteen->where('tbl_appointment.created_at', '>=', date($request->from))->where('tbl_appointment.created_at', '<=', date($request->to)); + $appointment_not_honored_to_nineteen = $appointment_not_honored_to_nineteen->where('tbl_appointment.created_at', '>=', date($request->from))->where('tbl_appointment.created_at', '<=', date($request->to)); + $appointment_not_honored_to_twentyfour = $appointment_not_honored_to_twentyfour->where('tbl_appointment.created_at', '>=', date($request->from))->where('tbl_appointment.created_at', '<=', date($request->to)); + $appointment_not_honored_to_twentyfive_above = $appointment_not_honored_to_twentyfive_above->where('tbl_appointment.created_at', '>=', date($request->from))->where('tbl_appointment.created_at', '<=', date($request->to)); + $appointment_not_honored_to_uknown_age = $appointment_not_honored_to_uknown_age->where('tbl_appointment.created_at', '>=', date($request->from))->where('tbl_appointment.created_at', '<=', date($request->to)); + } + + $data["appointment"] = $appointment->count(); + $data["appointment_honoured"] = $appointment_honoured->count(); + $data["appointment_not_honoured"] = $appointment_not_honoured->count(); + $data["appointment_honoured_male"] = $appointment_honoured_male->count(); + $data["appointment_honoured_female"] = $appointment_honoured_female->count(); + $data["appointment_honoured_uknown_gender"] = $appointment_honoured_uknown_gender->count(); + $data["appointment_honored_to_nine"] = $appointment_honored_to_nine->pluck('count'); + $data["appointment_honored_to_fourteen"] = $appointment_honored_to_fourteen->pluck('count'); + $data["appointment_honored_to_nineteen"] = $appointment_honored_to_nineteen->pluck('count'); + $data["appointment_honored_to_twentyfour"] = $appointment_honored_to_twentyfour->pluck('count'); + $data["appointment_honored_to_twentyfive_above"] = $appointment_honored_to_twentyfive_above->pluck('count'); + $data["appointment_honored_to_uknown_age"] = $appointment_honored_to_uknown_age->count(); + $data["appointment_not_honoured_male"] = $appointment_not_honoured_male->count(); + $data["appointment_not_honoured_female"] = $appointment_not_honoured_female->count(); + $data["appointment_not_honoured_uknown_gender"] = $appointment_not_honoured_uknown_gender->count(); + $data["appointment_not_honored_to_nine"] = $appointment_not_honored_to_nine->pluck('count'); + $data["appointment_not_honored_to_fourteen"] = $appointment_not_honored_to_fourteen - pluck('count'); + $data["appointment_not_honored_to_nineteen"] = $appointment_not_honored_to_nineteen->pluck('count'); + $data["appointment_not_honored_to_twentyfour"] = $appointment_not_honored_to_twentyfour->pluck('count'); + $data["appointment_not_honored_to_twentyfive_above"] = $appointment_not_honored_to_twentyfive_above->pluck('count'); + $data["appointment_not_honored_to_uknown_age"] = $appointment_not_honored_to_uknown_age->count(); + + return $data; + } + public function filter_missed_appointment_charts(Request $request) + { + $data = []; + // client charts + $selected_partners = $request->partners; + $selected_counties = $request->counties; + $selected_subcounties = $request->subcounties; + $selected_facilites = $request->facilities; + + if (Auth::user()->access_level == 'Facility') { + $appointment_not_honoured = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select(\DB::raw("COUNT(id) as count")) + ->whereIn('app_status', ['Defaulted', 'LTFU', 'Missed']) + ->where('tbl_client.mfl_code', Auth::user()->facility_id) + ->where('tbl_appointment.created_at', '>=', date($request->from))->where('tbl_appointment.created_at', '<=', date($request->to)); + // missed appointments + + $appointment_missed = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->where('app_status', '=', 'Missed') + ->where('tbl_client.mfl_code', Auth::user()->facility_id) + ->where('tbl_appointment.created_at', '>=', date($request->from))->where('tbl_appointment.created_at', '<=', date($request->to)); + + $appointment_defaulted = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->where('app_status', '=', 'Defaulted') + ->where('tbl_client.mfl_code', Auth::user()->facility_id) + ->where('tbl_appointment.created_at', '>=', date($request->from))->where('tbl_appointment.created_at', '<=', date($request->to)); + + $appointment_lftu = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->where('app_status', '=', 'LTFU') + ->where('tbl_client.mfl_code', Auth::user()->facility_id) + ->where('tbl_appointment.created_at', '>=', date($request->from))->where('tbl_appointment.created_at', '<=', date($request->to)); + // missed appointment by gender + $appointment_missed_female = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->where('tbl_appointment.app_status', '=', 'Missed') + ->where('tbl_client.gender', '=', '1') + ->where('tbl_client.mfl_code', Auth::user()->facility_id) + ->where('tbl_appointment.created_at', '>=', date($request->from))->where('tbl_appointment.created_at', '<=', date($request->to)); + + $appointment_missed_male = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->where('tbl_appointment.app_status', '=', 'Missed') + ->where('tbl_client.gender', '=', '2') + ->where('tbl_client.mfl_code', Auth::user()->facility_id) + ->where('tbl_appointment.created_at', '>=', date($request->from))->where('tbl_appointment.created_at', '<=', date($request->to)); + + $appointment_missed_uknown_gender = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->where('tbl_appointment.app_status', '=', 'Missed') + ->where('tbl_client.gender', '!=', '1') + ->where('tbl_client.gender', '!=', '2') + ->where('tbl_client.mfl_code', Auth::user()->facility_id) + ->where('tbl_appointment.created_at', '>=', date($request->from))->where('tbl_appointment.created_at', '<=', date($request->to)); + // missed appointment by age + $appointment_missed_to_nine = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) > 0) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 9)) then `tbl_client`.`id` end)) AS count")) + ->where('tbl_appointment.app_status', '=', 'Missed') + ->where('tbl_client.mfl_code', Auth::user()->facility_id) + ->where('tbl_appointment.created_at', '>=', date($request->from))->where('tbl_appointment.created_at', '<=', date($request->to)); + + $appointment_missed_to_fourteen = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 10) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 14)) then `tbl_client`.`id` end)) AS count")) + ->where('tbl_appointment.app_status', '=', 'Missed') + ->where('tbl_client.mfl_code', Auth::user()->facility_id) + ->where('tbl_appointment.created_at', '>=', date($request->from))->where('tbl_appointment.created_at', '<=', date($request->to)); + + $appointment_missed_to_nineteen = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 15) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 19)) then `tbl_client`.`id` end)) AS count")) + ->where('tbl_appointment.app_status', '=', 'Missed') + ->where('tbl_client.mfl_code', Auth::user()->facility_id) + ->where('tbl_appointment.created_at', '>=', date($request->from))->where('tbl_appointment.created_at', '<=', date($request->to)); + + $appointment_missed_to_twentyfour = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 20) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 24)) then `tbl_client`.`id` end)) AS count")) + ->where('tbl_appointment.app_status', '=', 'Missed') + ->where('tbl_client.mfl_code', Auth::user()->facility_id) + ->where('tbl_appointment.created_at', '>=', date($request->from))->where('tbl_appointment.created_at', '<=', date($request->to)); + + $appointment_missed_to_twentyfive_above = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 25)) then `tbl_client`.`id` end)) AS count")) + ->where('tbl_appointment.app_status', '=', 'Missed') + ->where('tbl_client.mfl_code', Auth::user()->facility_id) + ->where('tbl_appointment.created_at', '>=', date($request->from))->where('tbl_appointment.created_at', '<=', date($request->to)); + + $appointment_missed_to_uknown_age = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select('tbl_client.dob') + ->where('tbl_client.dob', '=', '') + ->orWhereNull('tbl_client.dob') + ->where('tbl_appointment.app_status', '=', 'Missed') + ->where('tbl_client.mfl_code', Auth::user()->facility_id) + ->where('tbl_appointment.created_at', '>=', date($request->from))->where('tbl_appointment.created_at', '<=', date($request->to)); + + // defaulted appointment by gender + $appointment_defaulted_female = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->where('tbl_appointment.app_status', '=', 'Defaulted') + ->where('tbl_client.gender', '=', '1') + ->where('tbl_client.mfl_code', Auth::user()->facility_id) + ->where('tbl_appointment.created_at', '>=', date($request->from))->where('tbl_appointment.created_at', '<=', date($request->to)); + + $appointment_defaulted_male = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->where('tbl_appointment.app_status', '=', 'Defaulted') + ->where('tbl_client.gender', '=', '2') + ->where('tbl_client.mfl_code', Auth::user()->facility_id) + ->where('tbl_appointment.created_at', '>=', date($request->from))->where('tbl_appointment.created_at', '<=', date($request->to)); + + $appointment_defaulted_uknown_gender = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->where('tbl_appointment.app_status', '=', 'Defaulted') + ->where('tbl_client.gender', '!=', '1') + ->where('tbl_client.gender', '!=', '2') + ->where('tbl_client.mfl_code', Auth::user()->facility_id) + ->where('tbl_appointment.created_at', '>=', date($request->from))->where('tbl_appointment.created_at', '<=', date($request->to)); + + // defaulted appointment by age + $appointment_defaulted_to_nine = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) > 0) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 9)) then `tbl_client`.`id` end)) AS count")) + ->where('tbl_appointment.app_status', '=', 'Defaulted') + ->where('tbl_client.mfl_code', Auth::user()->facility_id) + ->where('tbl_appointment.created_at', '>=', date($request->from))->where('tbl_appointment.created_at', '<=', date($request->to)); + + $appointment_defaulted_to_fourteen = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 10) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 14)) then `tbl_client`.`id` end)) AS count")) + ->where('tbl_appointment.app_status', '=', 'Defaulted') + ->where('tbl_client.mfl_code', Auth::user()->facility_id) + ->where('tbl_appointment.created_at', '>=', date($request->from))->where('tbl_appointment.created_at', '<=', date($request->to)); + + $appointment_defaulted_to_nineteen = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 15) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 19)) then `tbl_client`.`id` end)) AS count")) + ->where('tbl_appointment.app_status', '=', 'Defaulted') + ->where('tbl_client.mfl_code', Auth::user()->facility_id) + ->where('tbl_appointment.created_at', '>=', date($request->from))->where('tbl_appointment.created_at', '<=', date($request->to)); + + $appointment_defaulted_to_twentyfour = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 20) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 24)) then `tbl_client`.`id` end)) AS count")) + ->where('tbl_appointment.app_status', '=', 'Defaulted') + ->where('tbl_client.mfl_code', Auth::user()->facility_id) + ->where('tbl_appointment.created_at', '>=', date($request->from))->where('tbl_appointment.created_at', '<=', date($request->to)); + + $appointment_defaulted_to_twentyfive_above = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 25)) then `tbl_client`.`id` end)) AS count")) + ->where('tbl_appointment.app_status', '=', 'Defaulted') + ->where('tbl_client.mfl_code', Auth::user()->facility_id) + ->where('tbl_appointment.created_at', '>=', date($request->from))->where('tbl_appointment.created_at', '<=', date($request->to)); + + $appointment_defaulted_to_uknown_age = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select('tbl_client.dob') + ->where('tbl_client.dob', '=', '') + ->orWhereNull('tbl_client.dob') + ->where('tbl_appointment.app_status', '=', 'Defaulted') + ->where('tbl_client.mfl_code', Auth::user()->facility_id) + ->where('tbl_appointment.created_at', '>=', date($request->from))->where('tbl_appointment.created_at', '<=', date($request->to)); + + // ltfu appointment by gender + $appointment_ltfu_female = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->where('tbl_appointment.app_status', '=', 'LTFU') + ->where('tbl_client.gender', '=', '1') + ->where('tbl_client.mfl_code', Auth::user()->facility_id) + ->where('tbl_appointment.created_at', '>=', date($request->from))->where('tbl_appointment.created_at', '<=', date($request->to)); + + $appointment_ltfu_male = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->where('tbl_appointment.app_status', '=', 'LTFU') + ->where('tbl_client.gender', '=', '2') + ->where('tbl_client.mfl_code', Auth::user()->facility_id) + ->where('tbl_appointment.created_at', '>=', date($request->from))->where('tbl_appointment.created_at', '<=', date($request->to)); + + $appointment_ltfu_uknown_gender = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->where('tbl_appointment.app_status', '=', 'LTFU') + ->where('tbl_client.gender', '!=', '1') + ->where('tbl_client.gender', '!=', '2') + ->where('tbl_client.mfl_code', Auth::user()->facility_id) + ->where('tbl_appointment.created_at', '>=', date($request->from))->where('tbl_appointment.created_at', '<=', date($request->to)); + + // ltfu appointment by age + $appointment_ltfu_to_nine = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) > 0) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 9)) then `tbl_client`.`id` end)) AS count")) + ->where('tbl_appointment.app_status', '=', 'LTFU') + ->where('tbl_client.mfl_code', Auth::user()->facility_id) + ->where('tbl_appointment.created_at', '>=', date($request->from))->where('tbl_appointment.created_at', '<=', date($request->to)); + + $appointment_ltfu_to_fourteen = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 10) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 14)) then `tbl_client`.`id` end)) AS count")) + ->where('tbl_appointment.app_status', '=', 'LTFU') + ->where('tbl_client.mfl_code', Auth::user()->facility_id) + ->where('tbl_appointment.created_at', '>=', date($request->from))->where('tbl_appointment.created_at', '<=', date($request->to)); + + $appointment_ltfu_to_nineteen = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 15) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 19)) then `tbl_client`.`id` end)) AS count")) + ->where('tbl_appointment.app_status', '=', 'LTFU') + ->where('tbl_client.mfl_code', Auth::user()->facility_id) + ->where('tbl_appointment.created_at', '>=', date($request->from))->where('tbl_appointment.created_at', '<=', date($request->to)); + + $appointment_ltfu_to_twentyfour = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 20) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 24)) then `tbl_client`.`id` end)) AS count")) + ->where('tbl_appointment.app_status', '=', 'LTFU') + ->where('tbl_client.mfl_code', Auth::user()->facility_id) + ->where('tbl_appointment.created_at', '>=', date($request->from))->where('tbl_appointment.created_at', '<=', date($request->to)); + + $appointment_ltfu_to_twentyfive_above = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 25)) then `tbl_client`.`id` end)) AS count")) + ->where('tbl_appointment.app_status', '=', 'LTFU') + ->where('tbl_client.mfl_code', Auth::user()->facility_id) + ->where('tbl_appointment.created_at', '>=', date($request->from))->where('tbl_appointment.created_at', '<=', date($request->to)); + + $appointment_ltfu_to_uknown_age = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select('tbl_client.dob') + ->where('tbl_client.dob', '=', '') + ->orWhereNull('tbl_client.dob') + ->where('tbl_appointment.app_status', '=', 'LTFU') + ->where('tbl_client.mfl_code', Auth::user()->facility_id) + ->where('tbl_appointment.created_at', '>=', date($request->from))->where('tbl_appointment.created_at', '<=', date($request->to)); + } + if (Auth::user()->access_level == 'Partner') { + $appointment_not_honoured = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select(\DB::raw("COUNT(id) as count")) + ->whereIn('app_status', ['Defaulted', 'LTFU', 'Missed']) + ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) + ->where('tbl_appointment.created_at', '>=', date($request->from))->where('tbl_appointment.created_at', '<=', date($request->to)); + // missed appointments + + $appointment_missed = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->where('app_status', '=', 'Missed') + ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) + ->where('tbl_appointment.created_at', '>=', date($request->from))->where('tbl_appointment.created_at', '<=', date($request->to)); + + $appointment_defaulted = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->where('app_status', '=', 'Defaulted') + ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) + ->where('tbl_appointment.created_at', '>=', date($request->from))->where('tbl_appointment.created_at', '<=', date($request->to)); + + $appointment_lftu = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->where('app_status', '=', 'LTFU') + ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) + ->where('tbl_appointment.created_at', '>=', date($request->from))->where('tbl_appointment.created_at', '<=', date($request->to)); + // missed appointment by gender + $appointment_missed_female = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->where('tbl_appointment.app_status', '=', 'Missed') + ->where('tbl_client.gender', '=', '1') + ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) + ->where('tbl_appointment.created_at', '>=', date($request->from))->where('tbl_appointment.created_at', '<=', date($request->to)); + + $appointment_missed_male = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->where('tbl_appointment.app_status', '=', 'Missed') + ->where('tbl_client.gender', '=', '2') + ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) + ->where('tbl_appointment.created_at', '>=', date($request->from))->where('tbl_appointment.created_at', '<=', date($request->to)); + + $appointment_missed_uknown_gender = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->where('tbl_appointment.app_status', '=', 'Missed') + ->where('tbl_client.gender', '!=', '1') + ->where('tbl_client.gender', '!=', '2') + ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) + ->where('tbl_appointment.created_at', '>=', date($request->from))->where('tbl_appointment.created_at', '<=', date($request->to)); + // missed appointment by age + $appointment_missed_to_nine = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) > 0) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 9)) then `tbl_client`.`id` end)) AS count")) + ->where('tbl_appointment.app_status', '=', 'Missed') + ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) + ->where('tbl_appointment.created_at', '>=', date($request->from))->where('tbl_appointment.created_at', '<=', date($request->to)); + + $appointment_missed_to_fourteen = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 10) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 14)) then `tbl_client`.`id` end)) AS count")) + ->where('tbl_appointment.app_status', '=', 'Missed') + ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) + ->where('tbl_appointment.created_at', '>=', date($request->from))->where('tbl_appointment.created_at', '<=', date($request->to)); + + $appointment_missed_to_nineteen = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 15) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 19)) then `tbl_client`.`id` end)) AS count")) + ->where('tbl_appointment.app_status', '=', 'Missed') + ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) + ->where('tbl_appointment.created_at', '>=', date($request->from))->where('tbl_appointment.created_at', '<=', date($request->to)); + + $appointment_missed_to_twentyfour = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 20) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 24)) then `tbl_client`.`id` end)) AS count")) + ->where('tbl_appointment.app_status', '=', 'Missed') + ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) + ->where('tbl_appointment.created_at', '>=', date($request->from))->where('tbl_appointment.created_at', '<=', date($request->to)); + + $appointment_missed_to_twentyfive_above = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 25)) then `tbl_client`.`id` end)) AS count")) + ->where('tbl_appointment.app_status', '=', 'Missed') + ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) + ->where('tbl_appointment.created_at', '>=', date($request->from))->where('tbl_appointment.created_at', '<=', date($request->to)); + + $appointment_missed_to_uknown_age = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select('tbl_client.dob') + ->where('tbl_client.dob', '=', '') + ->orWhereNull('tbl_client.dob') + ->where('tbl_appointment.app_status', '=', 'Missed') + ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) + ->where('tbl_appointment.created_at', '>=', date($request->from))->where('tbl_appointment.created_at', '<=', date($request->to)); + + // defaulted appointment by gender + $appointment_defaulted_female = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->where('tbl_appointment.app_status', '=', 'Defaulted') + ->where('tbl_client.gender', '=', '1') + ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) + ->where('tbl_appointment.created_at', '>=', date($request->from))->where('tbl_appointment.created_at', '<=', date($request->to)); + + $appointment_defaulted_male = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->where('tbl_appointment.app_status', '=', 'Defaulted') + ->where('tbl_client.gender', '=', '2') + ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) + ->where('tbl_appointment.created_at', '>=', date($request->from))->where('tbl_appointment.created_at', '<=', date($request->to)); + + $appointment_defaulted_uknown_gender = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->where('tbl_appointment.app_status', '=', 'Defaulted') + ->where('tbl_client.gender', '!=', '1') + ->where('tbl_client.gender', '!=', '2') + ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) + ->where('tbl_appointment.created_at', '>=', date($request->from))->where('tbl_appointment.created_at', '<=', date($request->to)); + + // defaulted appointment by age + $appointment_defaulted_to_nine = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) > 0) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 9)) then `tbl_client`.`id` end)) AS count")) + ->where('tbl_appointment.app_status', '=', 'Defaulted') + ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) + ->where('tbl_appointment.created_at', '>=', date($request->from))->where('tbl_appointment.created_at', '<=', date($request->to)); + + $appointment_defaulted_to_fourteen = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 10) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 14)) then `tbl_client`.`id` end)) AS count")) + ->where('tbl_appointment.app_status', '=', 'Defaulted') + ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) + ->where('tbl_appointment.created_at', '>=', date($request->from))->where('tbl_appointment.created_at', '<=', date($request->to)); + + $appointment_defaulted_to_nineteen = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 15) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 19)) then `tbl_client`.`id` end)) AS count")) + ->where('tbl_appointment.app_status', '=', 'Defaulted') + ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) + ->where('tbl_appointment.created_at', '>=', date($request->from))->where('tbl_appointment.created_at', '<=', date($request->to)); + + $appointment_defaulted_to_twentyfour = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 20) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 24)) then `tbl_client`.`id` end)) AS count")) + ->where('tbl_appointment.app_status', '=', 'Defaulted') + ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) + ->where('tbl_appointment.created_at', '>=', date($request->from))->where('tbl_appointment.created_at', '<=', date($request->to)); + + $appointment_defaulted_to_twentyfive_above = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 25)) then `tbl_client`.`id` end)) AS count")) + ->where('tbl_appointment.app_status', '=', 'Defaulted') + ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) + ->where('tbl_appointment.created_at', '>=', date($request->from))->where('tbl_appointment.created_at', '<=', date($request->to)); + + $appointment_defaulted_to_uknown_age = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select('tbl_client.dob') + ->where('tbl_client.dob', '=', '') + ->orWhereNull('tbl_client.dob') + ->where('tbl_appointment.app_status', '=', 'Defaulted') + ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) + ->where('tbl_appointment.created_at', '>=', date($request->from))->where('tbl_appointment.created_at', '<=', date($request->to)); + + // ltfu appointment by gender + $appointment_ltfu_female = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->where('tbl_appointment.app_status', '=', 'LTFU') + ->where('tbl_client.gender', '=', '1') + ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) + ->where('tbl_appointment.created_at', '>=', date($request->from))->where('tbl_appointment.created_at', '<=', date($request->to)); + + $appointment_ltfu_male = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->where('tbl_appointment.app_status', '=', 'LTFU') + ->where('tbl_client.gender', '=', '2') + ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) + ->where('tbl_appointment.created_at', '>=', date($request->from))->where('tbl_appointment.created_at', '<=', date($request->to)); + + $appointment_ltfu_uknown_gender = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->where('tbl_appointment.app_status', '=', 'LTFU') + ->where('tbl_client.gender', '!=', '1') + ->where('tbl_client.gender', '!=', '2') + ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) + ->where('tbl_appointment.created_at', '>=', date($request->from))->where('tbl_appointment.created_at', '<=', date($request->to)); + + // ltfu appointment by age + $appointment_ltfu_to_nine = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) > 0) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 9)) then `tbl_client`.`id` end)) AS count")) + ->where('tbl_appointment.app_status', '=', 'LTFU') + ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) + ->where('tbl_appointment.created_at', '>=', date($request->from))->where('tbl_appointment.created_at', '<=', date($request->to)); + + $appointment_ltfu_to_fourteen = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 10) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 14)) then `tbl_client`.`id` end)) AS count")) + ->where('tbl_appointment.app_status', '=', 'LTFU') + ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) + ->where('tbl_appointment.created_at', '>=', date($request->from))->where('tbl_appointment.created_at', '<=', date($request->to)); + + $appointment_ltfu_to_nineteen = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 15) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 19)) then `tbl_client`.`id` end)) AS count")) + ->where('tbl_appointment.app_status', '=', 'LTFU') + ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) + ->where('tbl_appointment.created_at', '>=', date($request->from))->where('tbl_appointment.created_at', '<=', date($request->to)); + + $appointment_ltfu_to_twentyfour = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 20) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 24)) then `tbl_client`.`id` end)) AS count")) + ->where('tbl_appointment.app_status', '=', 'LTFU') + ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) + ->where('tbl_appointment.created_at', '>=', date($request->from))->where('tbl_appointment.created_at', '<=', date($request->to)); + + $appointment_ltfu_to_twentyfive_above = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 25)) then `tbl_client`.`id` end)) AS count")) + ->where('tbl_appointment.app_status', '=', 'LTFU') + ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) + ->where('tbl_appointment.created_at', '>=', date($request->from))->where('tbl_appointment.created_at', '<=', date($request->to)); + + $appointment_ltfu_to_uknown_age = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select('tbl_client.dob') + ->where('tbl_client.dob', '=', '') + ->orWhereNull('tbl_client.dob') + ->where('tbl_appointment.app_status', '=', 'LTFU') + ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) + ->where('tbl_appointment.created_at', '>=', date($request->from))->where('tbl_appointment.created_at', '<=', date($request->to)); + } + if (Auth::user()->access_level == 'Admin' || Auth::user()->access_level == 'Donor') { + $appointment_not_honoured = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select(\DB::raw("COUNT(id) as count")) + ->whereIn('app_status', ['Defaulted', 'LTFU', 'Missed']) + ->where('tbl_appointment.created_at', '>=', date($request->from))->where('tbl_appointment.created_at', '<=', date($request->to)); + // missed appointments + + $appointment_missed = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->where('app_status', '=', 'Missed') + ->where('tbl_appointment.created_at', '>=', date($request->from))->where('tbl_appointment.created_at', '<=', date($request->to)); + + $appointment_defaulted = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->where('app_status', '=', 'Defaulted') + ->where('tbl_appointment.created_at', '>=', date($request->from))->where('tbl_appointment.created_at', '<=', date($request->to)); + + $appointment_lftu = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->where('app_status', '=', 'LTFU') + ->where('tbl_appointment.created_at', '>=', date($request->from))->where('tbl_appointment.created_at', '<=', date($request->to)); + // missed appointment by gender + $appointment_missed_female = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->where('tbl_appointment.app_status', '=', 'Missed') + ->where('tbl_client.gender', '=', '1') + ->where('tbl_appointment.created_at', '>=', date($request->from))->where('tbl_appointment.created_at', '<=', date($request->to)); + + $appointment_missed_male = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->where('tbl_appointment.app_status', '=', 'Missed') + ->where('tbl_client.gender', '=', '2') + ->where('tbl_appointment.created_at', '>=', date($request->from))->where('tbl_appointment.created_at', '<=', date($request->to)); + + $appointment_missed_uknown_gender = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->where('tbl_appointment.app_status', '=', 'Missed') + ->where('tbl_client.gender', '!=', '1') + ->where('tbl_client.gender', '!=', '2') + ->where('tbl_appointment.created_at', '>=', date($request->from))->where('tbl_appointment.created_at', '<=', date($request->to)); + // missed appointment by age + $appointment_missed_to_nine = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) > 0) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 9)) then `tbl_client`.`id` end)) AS count")) + ->where('tbl_appointment.app_status', '=', 'Missed') + ->where('tbl_appointment.created_at', '>=', date($request->from))->where('tbl_appointment.created_at', '<=', date($request->to)); + + $appointment_missed_to_fourteen = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 10) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 14)) then `tbl_client`.`id` end)) AS count")) + ->where('tbl_appointment.app_status', '=', 'Missed') + ->where('tbl_appointment.created_at', '>=', date($request->from))->where('tbl_appointment.created_at', '<=', date($request->to)); + + $appointment_missed_to_nineteen = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 15) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 19)) then `tbl_client`.`id` end)) AS count")) + ->where('tbl_appointment.app_status', '=', 'Missed') + ->where('tbl_appointment.created_at', '>=', date($request->from))->where('tbl_appointment.created_at', '<=', date($request->to)); + + $appointment_missed_to_twentyfour = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 20) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 24)) then `tbl_client`.`id` end)) AS count")) + ->where('tbl_appointment.app_status', '=', 'Missed') + ->where('tbl_appointment.created_at', '>=', date($request->from))->where('tbl_appointment.created_at', '<=', date($request->to)); + + $appointment_missed_to_twentyfive_above = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 25)) then `tbl_client`.`id` end)) AS count")) + ->where('tbl_appointment.app_status', '=', 'Missed') + ->where('tbl_appointment.created_at', '>=', date($request->from))->where('tbl_appointment.created_at', '<=', date($request->to)); + + $appointment_missed_to_uknown_age = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select('tbl_client.dob') + ->where('tbl_client.dob', '=', '') + ->orWhereNull('tbl_client.dob') + ->where('tbl_appointment.app_status', '=', 'Missed') + ->where('tbl_appointment.created_at', '>=', date($request->from))->where('tbl_appointment.created_at', '<=', date($request->to)); + + // defaulted appointment by gender + $appointment_defaulted_female = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->where('tbl_appointment.app_status', '=', 'Defaulted') + ->where('tbl_client.gender', '=', '1') + ->where('tbl_appointment.created_at', '>=', date($request->from))->where('tbl_appointment.created_at', '<=', date($request->to)); + + $appointment_defaulted_male = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->where('tbl_appointment.app_status', '=', 'Defaulted') + ->where('tbl_client.gender', '=', '2') + ->where('tbl_appointment.created_at', '>=', date($request->from))->where('tbl_appointment.created_at', '<=', date($request->to)); + + $appointment_defaulted_uknown_gender = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->where('tbl_appointment.app_status', '=', 'Defaulted') + ->where('tbl_client.gender', '!=', '1') + ->where('tbl_client.gender', '!=', '2') + ->where('tbl_appointment.created_at', '>=', date($request->from))->where('tbl_appointment.created_at', '<=', date($request->to)); + + // defaulted appointment by age + $appointment_defaulted_to_nine = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) > 0) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 9)) then `tbl_client`.`id` end)) AS count")) + ->where('tbl_appointment.app_status', '=', 'Defaulted') + ->where('tbl_appointment.created_at', '>=', date($request->from))->where('tbl_appointment.created_at', '<=', date($request->to)); + + $appointment_defaulted_to_fourteen = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 10) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 14)) then `tbl_client`.`id` end)) AS count")) + ->where('tbl_appointment.app_status', '=', 'Defaulted') + ->where('tbl_appointment.created_at', '>=', date($request->from))->where('tbl_appointment.created_at', '<=', date($request->to)); + + $appointment_defaulted_to_nineteen = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 15) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 19)) then `tbl_client`.`id` end)) AS count")) + ->where('tbl_appointment.app_status', '=', 'Defaulted') + ->where('tbl_appointment.created_at', '>=', date($request->from))->where('tbl_appointment.created_at', '<=', date($request->to)); + + $appointment_defaulted_to_twentyfour = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 20) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 24)) then `tbl_client`.`id` end)) AS count")) + ->where('tbl_appointment.app_status', '=', 'Defaulted') + ->where('tbl_appointment.created_at', '>=', date($request->from))->where('tbl_appointment.created_at', '<=', date($request->to)); + + $appointment_defaulted_to_twentyfive_above = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 25)) then `tbl_client`.`id` end)) AS count")) + ->where('tbl_appointment.app_status', '=', 'Defaulted') + ->where('tbl_appointment.created_at', '>=', date($request->from))->where('tbl_appointment.created_at', '<=', date($request->to)); + + $appointment_defaulted_to_uknown_age = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select('tbl_client.dob') + ->where('tbl_client.dob', '=', '') + ->orWhereNull('tbl_client.dob') + ->where('tbl_appointment.app_status', '=', 'Defaulted') + ->where('tbl_appointment.created_at', '>=', date($request->from))->where('tbl_appointment.created_at', '<=', date($request->to)); + + // ltfu appointment by gender + $appointment_ltfu_female = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->where('tbl_appointment.app_status', '=', 'LTFU') + ->where('tbl_client.gender', '=', '1') + ->where('tbl_appointment.created_at', '>=', date($request->from))->where('tbl_appointment.created_at', '<=', date($request->to)); + + $appointment_ltfu_male = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->where('tbl_appointment.app_status', '=', 'LTFU') + ->where('tbl_client.gender', '=', '2') + ->where('tbl_appointment.created_at', '>=', date($request->from))->where('tbl_appointment.created_at', '<=', date($request->to)); + + $appointment_ltfu_uknown_gender = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->where('tbl_appointment.app_status', '=', 'LTFU') + ->where('tbl_client.gender', '!=', '1') + ->where('tbl_client.gender', '!=', '2') + ->where('tbl_appointment.created_at', '>=', date($request->from))->where('tbl_appointment.created_at', '<=', date($request->to)); + + // ltfu appointment by age + $appointment_ltfu_to_nine = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) > 0) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 9)) then `tbl_client`.`id` end)) AS count")) + ->where('tbl_appointment.app_status', '=', 'LTFU') + ->where('tbl_appointment.created_at', '>=', date($request->from))->where('tbl_appointment.created_at', '<=', date($request->to)); + + $appointment_ltfu_to_fourteen = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 10) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 14)) then `tbl_client`.`id` end)) AS count")) + ->where('tbl_appointment.app_status', '=', 'LTFU') + ->where('tbl_appointment.created_at', '>=', date($request->from))->where('tbl_appointment.created_at', '<=', date($request->to)); + + $appointment_ltfu_to_nineteen = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 15) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 19)) then `tbl_client`.`id` end)) AS count")) + ->where('tbl_appointment.app_status', '=', 'LTFU') + ->where('tbl_appointment.created_at', '>=', date($request->from))->where('tbl_appointment.created_at', '<=', date($request->to)); + + $appointment_ltfu_to_twentyfour = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 20) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 24)) then `tbl_client`.`id` end)) AS count")) + ->where('tbl_appointment.app_status', '=', 'LTFU') + ->where('tbl_appointment.created_at', '>=', date($request->from))->where('tbl_appointment.created_at', '<=', date($request->to)); + + $appointment_ltfu_to_twentyfive_above = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 25)) then `tbl_client`.`id` end)) AS count")) + ->where('tbl_appointment.app_status', '=', 'LTFU') + ->where('tbl_appointment.created_at', '>=', date($request->from))->where('tbl_appointment.created_at', '<=', date($request->to)); + + $appointment_ltfu_to_uknown_age = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select('tbl_client.dob') + ->where('tbl_client.dob', '=', '') + ->orWhereNull('tbl_client.dob') + ->where('tbl_appointment.app_status', '=', 'LTFU') + ->where('tbl_appointment.created_at', '>=', date($request->from))->where('tbl_appointment.created_at', '<=', date($request->to)); + } + + if (!empty($selected_partners)) { + $appointment_not_honoured = $appointment_not_honoured->where('tbl_partner_facility.partner_id', $selected_partners); + $appointment_missed = $appointment_missed->where('tbl_partner_facility.partner_id', $selected_partners); + $appointment_defaulted = $appointment_defaulted->where('tbl_partner_facility.partner_id', $selected_partners); + $appointment_lftu = $appointment_lftu->where('tbl_partner_facility.partner_id', $selected_partners); + $appointment_missed_female = $appointment_missed_female->where('tbl_partner_facility.partner_id', $selected_partners); + $appointment_missed_male = $appointment_missed_male->where('tbl_partner_facility.partner_id', $selected_partners); + $appointment_missed_uknown_gender = $appointment_missed_uknown_gender->where('tbl_partner_facility.partner_id', $selected_partners); + $appointment_missed_to_nine = $appointment_missed_to_nine->where('tbl_partner_facility.partner_id', $selected_partners); + $appointment_missed_to_fourteen = $appointment_missed_to_fourteen->where('tbl_partner_facility.partner_id', $selected_partners); + $appointment_missed_to_nineteen = $appointment_missed_to_nineteen->where('tbl_partner_facility.partner_id', $selected_partners); + $appointment_missed_to_twentyfour = $appointment_missed_to_twentyfour->where('tbl_partner_facility.partner_id', $selected_partners); + $appointment_missed_to_twentyfive_above = $appointment_missed_to_twentyfive_above->where('tbl_partner_facility.partner_id', $selected_partners); + $appointment_missed_to_uknown_age = $appointment_missed_to_uknown_age->where('tbl_partner_facility.partner_id', $selected_partners); + $appointment_defaulted_female = $appointment_defaulted_female->where('tbl_partner_facility.partner_id', $selected_partners); + $appointment_defaulted_male = $appointment_defaulted_male->where('tbl_partner_facility.partner_id', $selected_partners); + $appointment_defaulted_uknown_gender = $appointment_defaulted_uknown_gender->where('tbl_partner_facility.partner_id', $selected_partners); + $appointment_defaulted_to_nine = $appointment_defaulted_to_nine->where('tbl_partner_facility.partner_id', $selected_partners); + $appointment_defaulted_to_fourteen = $appointment_defaulted_to_fourteen->where('tbl_partner_facility.partner_id', $selected_partners); + $appointment_defaulted_to_nineteen = $appointment_defaulted_to_nineteen->where('tbl_partner_facility.partner_id', $selected_partners); + $appointment_defaulted_to_twentyfour = $appointment_defaulted_to_twentyfour->where('tbl_partner_facility.partner_id', $selected_partners); + $appointment_defaulted_to_twentyfive_above = $appointment_defaulted_to_twentyfive_above->where('tbl_partner_facility.partner_id', $selected_partners); + $appointment_defaulted_to_uknown_age = $appointment_defaulted_to_uknown_age->where('tbl_partner_facility.partner_id', $selected_partners); + $appointment_ltfu_female = $appointment_ltfu_female->where('tbl_partner_facility.partner_id', $selected_partners); + $appointment_ltfu_male = $appointment_ltfu_male->where('tbl_partner_facility.partner_id', $selected_partners); + $appointment_ltfu_uknown_gender = $appointment_ltfu_uknown_gender->where('tbl_partner_facility.partner_id', $selected_partners); + $appointment_ltfu_to_nine = $appointment_ltfu_to_nine->where('tbl_partner_facility.partner_id', $selected_partners); + $appointment_ltfu_to_fourteen = $appointment_ltfu_to_fourteen->where('tbl_partner_facility.partner_id', $selected_partners); + $appointment_ltfu_to_nineteen = $appointment_ltfu_to_nineteen->where('tbl_partner_facility.partner_id', $selected_partners); + $appointment_ltfu_to_twentyfour = $appointment_ltfu_to_twentyfour->where('tbl_partner_facility.partner_id', $selected_partners); + $appointment_ltfu_to_twentyfive_above = $appointment_ltfu_to_twentyfive_above->where('tbl_partner_facility.partner_id', $selected_partners); + $appointment_ltfu_to_uknown_age = $appointment_ltfu_to_uknown_age->where('tbl_partner_facility.partner_id', $selected_partners); + } + if (!empty($selected_counties)) { + $appointment_not_honoured = $appointment_not_honoured->where('tbl_partner_facility.county_id', $selected_counties); + $appointment_missed = $appointment_missed->where('tbl_partner_facility.county_id', $selected_counties); + $appointment_defaulted = $appointment_defaulted->where('tbl_partner_facility.county_id', $selected_counties); + $appointment_lftu = $appointment_lftu->where('tbl_partner_facility.county_id', $selected_counties); + $appointment_missed_female = $appointment_missed_female->where('tbl_partner_facility.county_id', $selected_counties); + $appointment_missed_male = $appointment_missed_male->where('tbl_partner_facility.county_id', $selected_counties); + $appointment_missed_uknown_gender = $appointment_missed_uknown_gender->where('tbl_partner_facility.county_id', $selected_counties); + $appointment_missed_to_nine = $appointment_missed_to_nine->where('tbl_partner_facility.county_id', $selected_counties); + $appointment_missed_to_fourteen = $appointment_missed_to_fourteen->where('tbl_partner_facility.county_id', $selected_counties); + $appointment_missed_to_nineteen = $appointment_missed_to_nineteen->where('tbl_partner_facility.county_id', $selected_counties); + $appointment_missed_to_twentyfour = $appointment_missed_to_twentyfour->where('tbl_partner_facility.county_id', $selected_counties); + $appointment_missed_to_twentyfive_above = $appointment_missed_to_twentyfive_above->where('tbl_partner_facility.county_id', $selected_counties); + $appointment_missed_to_uknown_age = $appointment_missed_to_uknown_age->where('tbl_partner_facility.county_id', $selected_counties); + $appointment_defaulted_female = $appointment_defaulted_female->where('tbl_partner_facility.county_id', $selected_counties); + $appointment_defaulted_male = $appointment_defaulted_male->where('tbl_partner_facility.county_id', $selected_counties); + $appointment_defaulted_uknown_gender = $appointment_defaulted_uknown_gender->where('tbl_partner_facility.county_id', $selected_counties); + $appointment_defaulted_to_nine = $appointment_defaulted_to_nine->where('tbl_partner_facility.county_id', $selected_counties); + $appointment_defaulted_to_fourteen = $appointment_defaulted_to_fourteen->where('tbl_partner_facility.county_id', $selected_counties); + $appointment_defaulted_to_nineteen = $appointment_defaulted_to_nineteen->where('tbl_partner_facility.county_id', $selected_counties); + $appointment_defaulted_to_twentyfour = $appointment_defaulted_to_twentyfour->where('tbl_partner_facility.county_id', $selected_counties); + $appointment_defaulted_to_twentyfive_above = $appointment_defaulted_to_twentyfive_above->where('tbl_partner_facility.county_id', $selected_counties); + $appointment_defaulted_to_uknown_age = $appointment_defaulted_to_uknown_age->where('tbl_partner_facility.county_id', $selected_counties); + $appointment_ltfu_female = $appointment_ltfu_female->where('tbl_partner_facility.county_id', $selected_counties); + $appointment_ltfu_male = $appointment_ltfu_male->where('tbl_partner_facility.county_id', $selected_counties); + $appointment_ltfu_uknown_gender = $appointment_ltfu_uknown_gender->where('tbl_partner_facility.county_id', $selected_counties); + $appointment_ltfu_to_nine = $appointment_ltfu_to_nine->where('tbl_partner_facility.county_id', $selected_counties); + $appointment_ltfu_to_fourteen = $appointment_ltfu_to_fourteen->where('tbl_partner_facility.county_id', $selected_counties); + $appointment_ltfu_to_nineteen = $appointment_ltfu_to_nineteen->where('tbl_partner_facility.county_id', $selected_counties); + $appointment_ltfu_to_twentyfour = $appointment_ltfu_to_twentyfour->where('tbl_partner_facility.county_id', $selected_counties); + $appointment_ltfu_to_twentyfive_above = $appointment_ltfu_to_twentyfive_above->where('tbl_partner_facility.county_id', $selected_counties); + $appointment_ltfu_to_uknown_age = $appointment_ltfu_to_uknown_age->where('tbl_partner_facility.county_id', $selected_counties); + } + if (!empty($selected_subcounties)) { + $appointment_not_honoured = $appointment_not_honoured->where('tbl_partner_facility.sub_county_id', $selected_subcounties); + $appointment_missed = $appointment_missed->where('tbl_partner_facility.sub_county_id', $selected_subcounties); + $appointment_defaulted = $appointment_defaulted->where('tbl_partner_facility.sub_county_id', $selected_subcounties); + $appointment_lftu = $appointment_lftu->where('tbl_partner_facility.sub_county_id', $selected_subcounties); + $appointment_missed_female = $appointment_missed_female->where('tbl_partner_facility.sub_county_id', $selected_subcounties); + $appointment_missed_male = $appointment_missed_male->where('tbl_partner_facility.sub_county_id', $selected_subcounties); + $appointment_missed_uknown_gender = $appointment_missed_uknown_gender->where('tbl_partner_facility.sub_county_id', $selected_subcounties); + $appointment_missed_to_nine = $appointment_missed_to_nine->where('tbl_partner_facility.sub_county_id', $selected_subcounties); + $appointment_missed_to_fourteen = $appointment_missed_to_fourteen->where('tbl_partner_facility.sub_county_id', $selected_subcounties); + $appointment_missed_to_nineteen = $appointment_missed_to_nineteen->where('tbl_partner_facility.sub_county_id', $selected_subcounties); + $appointment_missed_to_twentyfour = $appointment_missed_to_twentyfour->where('tbl_partner_facility.sub_county_id', $selected_subcounties); + $appointment_missed_to_twentyfive_above = $appointment_missed_to_twentyfive_above->where('tbl_partner_facility.sub_county_id', $selected_subcounties); + $appointment_missed_to_uknown_age = $appointment_missed_to_uknown_age->where('tbl_partner_facility.sub_county_id', $selected_subcounties); + $appointment_defaulted_female = $appointment_defaulted_female->where('tbl_partner_facility.sub_county_id', $selected_subcounties); + $appointment_defaulted_male = $appointment_defaulted_male->where('tbl_partner_facility.sub_county_id', $selected_subcounties); + $appointment_defaulted_uknown_gender = $appointment_defaulted_uknown_gender->where('tbl_partner_facility.sub_county_id', $selected_subcounties); + $appointment_defaulted_to_nine = $appointment_defaulted_to_nine->where('tbl_partner_facility.sub_county_id', $selected_subcounties); + $appointment_defaulted_to_fourteen = $appointment_defaulted_to_fourteen->where('tbl_partner_facility.sub_county_id', $selected_subcounties); + $appointment_defaulted_to_nineteen = $appointment_defaulted_to_nineteen->where('tbl_partner_facility.sub_county_id', $selected_subcounties); + $appointment_defaulted_to_twentyfour = $appointment_defaulted_to_twentyfour->where('tbl_partner_facility.sub_county_id', $selected_subcounties); + $appointment_defaulted_to_twentyfive_above = $appointment_defaulted_to_twentyfive_above->where('tbl_partner_facility.sub_county_id', $selected_subcounties); + $appointment_defaulted_to_uknown_age = $appointment_defaulted_to_uknown_age->where('tbl_partner_facility.sub_county_id', $selected_subcounties); + $appointment_ltfu_female = $appointment_ltfu_female->where('tbl_partner_facility.sub_county_id', $selected_subcounties); + $appointment_ltfu_male = $appointment_ltfu_male->where('tbl_partner_facility.sub_county_id', $selected_subcounties); + $appointment_ltfu_uknown_gender = $appointment_ltfu_uknown_gender->where('tbl_partner_facility.sub_county_id', $selected_subcounties); + $appointment_ltfu_to_nine = $appointment_ltfu_to_nine->where('tbl_partner_facility.sub_county_id', $selected_subcounties); + $appointment_ltfu_to_fourteen = $appointment_ltfu_to_fourteen->where('tbl_partner_facility.sub_county_id', $selected_subcounties); + $appointment_ltfu_to_nineteen = $appointment_ltfu_to_nineteen->where('tbl_partner_facility.sub_county_id', $selected_subcounties); + $appointment_ltfu_to_twentyfour = $appointment_ltfu_to_twentyfour->where('tbl_partner_facility.sub_county_id', $selected_subcounties); + $appointment_ltfu_to_twentyfive_above = $appointment_ltfu_to_twentyfive_above->where('tbl_partner_facility.sub_county_id', $selected_subcounties); + $appointment_ltfu_to_uknown_age = $appointment_ltfu_to_uknown_age->where('tbl_partner_facility.sub_county_id', $selected_subcounties); + } + if (!empty($selected_facilites)) { + $appointment_not_honoured = $appointment_not_honoured->where('tbl_partner_facility.mfl_code', $selected_facilites); + $appointment_missed = $appointment_missed->where('tbl_partner_facility.mfl_code', $selected_facilites); + $appointment_defaulted = $appointment_defaulted->where('tbl_partner_facility.mfl_code', $selected_facilites); + $appointment_lftu = $appointment_lftu->where('tbl_partner_facility.mfl_code', $selected_facilites); + $appointment_missed_female = $appointment_missed_female->where('tbl_partner_facility.mfl_code', $selected_facilites); + $appointment_missed_male = $appointment_missed_male->where('tbl_partner_facility.mfl_code', $selected_facilites); + $appointment_missed_uknown_gender = $appointment_missed_uknown_gender->where('tbl_partner_facility.mfl_code', $selected_facilites); + $appointment_missed_to_nine = $appointment_missed_to_nine->where('tbl_partner_facility.mfl_code', $selected_facilites); + $appointment_missed_to_fourteen = $appointment_missed_to_fourteen->where('tbl_partner_facility.mfl_code', $selected_facilites); + $appointment_missed_to_nineteen = $appointment_missed_to_nineteen->where('tbl_partner_facility.mfl_code', $selected_facilites); + $appointment_missed_to_twentyfour = $appointment_missed_to_twentyfour->where('tbl_partner_facility.mfl_code', $selected_facilites); + $appointment_missed_to_twentyfive_above = $appointment_missed_to_twentyfive_above->where('tbl_partner_facility.mfl_code', $selected_facilites); + $appointment_missed_to_uknown_age = $appointment_missed_to_uknown_age->where('tbl_partner_facility.mfl_code', $selected_facilites); + $appointment_defaulted_female = $appointment_defaulted_female->where('tbl_partner_facility.mfl_code', $selected_facilites); + $appointment_defaulted_male = $appointment_defaulted_male->where('tbl_partner_facility.mfl_code', $selected_facilites); + $appointment_defaulted_uknown_gender = $appointment_defaulted_uknown_gender->where('tbl_partner_facility.mfl_code', $selected_facilites); + $appointment_defaulted_to_nine = $appointment_defaulted_to_nine->where('tbl_partner_facility.mfl_code', $selected_facilites); + $appointment_defaulted_to_fourteen = $appointment_defaulted_to_fourteen->where('tbl_partner_facility.mfl_code', $selected_facilites); + $appointment_defaulted_to_nineteen = $appointment_defaulted_to_nineteen->where('tbl_partner_facility.mfl_code', $selected_facilites); + $appointment_defaulted_to_twentyfour = $appointment_defaulted_to_twentyfour->where('tbl_partner_facility.mfl_code', $selected_facilites); + $appointment_defaulted_to_twentyfive_above = $appointment_defaulted_to_twentyfive_above->where('tbl_partner_facility.mfl_code', $selected_facilites); + $appointment_defaulted_to_uknown_age = $appointment_defaulted_to_uknown_age->where('tbl_partner_facility.mfl_code', $selected_facilites); + $appointment_ltfu_female = $appointment_ltfu_female->where('tbl_partner_facility.mfl_code', $selected_facilites); + $appointment_ltfu_male = $appointment_ltfu_male->where('tbl_partner_facility.mfl_code', $selected_facilites); + $appointment_ltfu_uknown_gender = $appointment_ltfu_uknown_gender->where('tbl_partner_facility.mfl_code', $selected_facilites); + $appointment_ltfu_to_nine = $appointment_ltfu_to_nine->where('tbl_partner_facility.mfl_code', $selected_facilites); + $appointment_ltfu_to_fourteen = $appointment_ltfu_to_fourteen->where('tbl_partner_facility.mfl_code', $selected_facilites); + $appointment_ltfu_to_nineteen = $appointment_ltfu_to_nineteen->where('tbl_partner_facility.mfl_code', $selected_facilites); + $appointment_ltfu_to_twentyfour = $appointment_ltfu_to_twentyfour->where('tbl_partner_facility.mfl_code', $selected_facilites); + $appointment_ltfu_to_twentyfive_above = $appointment_ltfu_to_twentyfive_above->where('tbl_partner_facility.mfl_code', $selected_facilites); + $appointment_ltfu_to_uknown_age = $appointment_ltfu_to_uknown_age->where('tbl_partner_facility.mfl_code', $selected_facilites); + } + + $data["appointment_not_honoured"] = $appointment_not_honoured->count(); + $data["appointment_missed"] = $appointment_missed->count(); + $data["appointment_defaulted"] = $appointment_defaulted->count(); + $data["appointment_lftu"] = $appointment_lftu->count(); + $data["appointment_missed_female"] = $appointment_missed_female->count(); + $data["appointment_missed_male"] = $appointment_missed_male->count(); + $data["appointment_missed_uknown_gender"] = $appointment_missed_uknown_gender->count(); + $data["appointment_missed_to_nine"] = $appointment_missed_to_nine->pluck('count'); + $data["appointment_missed_to_fourteen"] = $appointment_missed_to_fourteen->pluck('count'); + $data["appointment_missed_to_nineteen"] = $appointment_missed_to_nineteen->pluck('count'); + $data["appointment_missed_to_twentyfour"] = $appointment_missed_to_twentyfour->pluck('count'); + $data["appointment_missed_to_twentyfive_above"] = $appointment_missed_to_twentyfive_above->pluck('count'); + $data["appointment_missed_to_uknown_age"] = $appointment_missed_to_uknown_age->count(); + $data["appointment_defaulted_female"] = $appointment_defaulted_female->count(); + $data["appointment_defaulted_male"] = $appointment_defaulted_male->count(); + $data["appointment_defaulted_uknown_gender"] = $appointment_defaulted_uknown_gender->count(); + $data["appointment_defaulted_to_nine"] = $appointment_defaulted_to_nine->pluck('count'); + $data["appointment_defaulted_to_fourteen"] = $appointment_defaulted_to_fourteen->pluck('count'); + $data["appointment_defaulted_to_nineteen"] = $appointment_defaulted_to_nineteen->pluck('count'); + $data["appointment_defaulted_to_twentyfour"] = $appointment_defaulted_to_twentyfour->pluck('count'); + $data["appointment_defaulted_to_twentyfive_above"] = $appointment_defaulted_to_twentyfive_above->pluck('count'); + $data["appointment_defaulted_to_uknown_age"] = $appointment_defaulted_to_uknown_age->count(); + $data["appointment_ltfu_female"] = $appointment_ltfu_female->count(); + $data["appointment_ltfu_male"] = $appointment_ltfu_male->count(); + $data["appointment_ltfu_uknown_gender"] = $appointment_ltfu_uknown_gender->count(); + $data["appointment_ltfu_to_nine"] = $appointment_ltfu_to_nine->pluck('count'); + $data["appointment_ltfu_to_fourteen"] = $appointment_ltfu_to_fourteen->pluck('count'); + $data["appointment_ltfu_to_nineteen"] = $appointment_ltfu_to_nineteen->pluck('count'); + $data["appointment_ltfu_to_twentyfour"] = $appointment_ltfu_to_twentyfour->pluck('count'); + $data["appointment_ltfu_to_twentyfive_above"] = $appointment_ltfu_to_twentyfive_above->pluck('count'); + $data["appointment_ltfu_to_uknown_age"] = $appointment_ltfu_to_uknown_age->count(); + + return $data; + } } diff --git a/resources/views/clients/upload-clients-form.blade.php b/resources/views/clients/upload-clients-form.blade.php index 5b2be07..a585369 100644 --- a/resources/views/clients/upload-clients-form.blade.php +++ b/resources/views/clients/upload-clients-form.blade.php @@ -8,10 +8,11 @@
+
@@ -87,7 +88,7 @@ }) }); - diff --git a/resources/views/layouts/large-vertical-sidebar/sidebar.blade.php b/resources/views/layouts/large-vertical-sidebar/sidebar.blade.php index 9be54eb..3d91762 100644 --- a/resources/views/layouts/large-vertical-sidebar/sidebar.blade.php +++ b/resources/views/layouts/large-vertical-sidebar/sidebar.blade.php @@ -111,7 +111,7 @@ @endif @if (Auth::user()->access_level == 'Sub County') @@ -180,6 +180,11 @@ Clients +
@@ -156,7 +222,7 @@

Not Honored

-

{{number_format($appointment_not_honoured)}}

+

{{number_format($appointment_not_honoured)}}

@@ -331,6 +397,8 @@ let counties = $('#counties').val(); let subcounties = $('#subcounties').val(); let facilities = $('#facilities').val(); + let from = $('#from').val(); + let to = $('#to').val(); $.ajaxSetup({ headers: { 'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content') @@ -343,19 +411,46 @@ "partners": partners, "counties": counties, "subcounties": subcounties, - "facilities": facilities + "facilities": facilities, + "from": from, + "to": to }, url: "{{ route('filter_appointment_dashboard') }}", success: function(data) { - - + $("#appointment").html(data.appointment); + $("#appointment_honoured").html(data.appointment_honoured); + $("#appointment_not_honoured").html(data.appointment_not_honoured); + + Appointment_honoured_male = parseInt(data.appointment_honoured_male) + Appointment_honoured_female = parseInt(data.appointment_honoured_female) + Appointment_honoured_uknown_gender = parseInt(data.appointment_honoured_uknown_gender) + Appointment_honored_to_nine = parseInt(data.appointment_honored_to_nine) + Appointment_honored_to_fourteen = parseInt(data.appointment_honored_to_fourteen) + Appointment_honored_to_nineteen = parseInt(data.appointment_honored_to_nineteen) + Appointment_honored_to_twentyfour = parseInt(data.appointment_honored_to_twentyfour) + Appointment_honored_to_twentyfive_above = parseInt(data.appointment_honored_to_twentyfive_above) + Appointment_honored_to_uknown_age = parseInt(data.appointment_honored_to_uknown_age) + Appointment_not_honoured_male = parseInt(data.appointment_not_honoured_male) + Appointment_not_honoured_female = parseInt(data.appointment_not_honoured_female) + Appointment_not_honoured_uknown_gender = parseInt(data.appointment_not_honoured_uknown_gender) + Appointment_not_honored_to_nine = parseInt(data.appointment_not_honored_to_nine) + Appointment_not_honored_to_fourteen = parseInt(data.appointment_not_honored_to_fourteen) + Appointment_not_honored_to_nineteen = parseInt(data.appointment_not_honored_to_nineteen) + Appointment_not_honored_to_twentyfour = parseInt(data.appointment_not_honored_to_twentyfour) + Appointment_not_honored_to_twentyfive_above = parseInt(data.appointment_not_honored_to_twentyfive_above) + Appointment_not_honored_to_uknown_age = parseInt(data.appointment_not_honored_to_uknown_age) + + appointment_honouredGender.series[0].setData([Appointment_honoured_male, Appointment_honoured_female, Appointment_honoured_uknown_gender]); + appointment_honouredAge.series[0].setData([Appointment_honored_to_nine, Appointment_honored_to_fourteen, Appointment_honored_to_nineteen, Appointment_honored_to_twentyfour, Appointment_honored_to_twentyfive_above, Appointment_honored_to_uknown_age]); + appointment_not_honouredGender.series[0].setData([Appointment_not_honoured_male, Appointment_not_honoured_female, Appointment_not_honoured_uknown_gender]); + appointment_not_honouredAge.series[0].setData([Appointment_not_honored_to_nine, Appointment_not_honored_to_fourteen, Appointment_not_honored_to_nineteen, Appointment_not_honored_to_twentyfour, Appointment_not_honored_to_twentyfive_above, Appointment_not_honored_to_uknown_age]); } }); }); //APPOINTMENT HONOURED GENDER - var appChart = Highcharts.chart('appointment_honoured_gender', { + var appointment_honouredGender = Highcharts.chart('appointment_honoured_gender', { chart: { type: 'column' }, @@ -399,7 +494,7 @@ }); // APPOINTMENT HONOURED AGE - var appChart = Highcharts.chart('appointment_honoured_age', { + var appointment_honouredAge = Highcharts.chart('appointment_honoured_age', { chart: { type: 'column' }, @@ -444,7 +539,7 @@ }); //APPOINTMENT NOT HONOURED GENDER - var appChart = Highcharts.chart('appointment_not_honoured_gender', { + var appointment_not_honouredGender = Highcharts.chart('appointment_not_honoured_gender', { chart: { type: 'column' }, @@ -488,7 +583,7 @@ }); // APPOINTMENT NOT HONOURED AGE - var appChart = Highcharts.chart('appointment_not_honoured_age', { + var appointment_not_honouredAge = Highcharts.chart('appointment_not_honoured_age', { chart: { type: 'column' }, diff --git a/resources/views/new_dashboard/client_dashboard.blade.php b/resources/views/new_dashboard/client_dashboard.blade.php index 4b309d1..318772b 100644 --- a/resources/views/new_dashboard/client_dashboard.blade.php +++ b/resources/views/new_dashboard/client_dashboard.blade.php @@ -12,7 +12,7 @@
--> @if (Auth::user()->access_level == 'Admin' || Auth::user()->access_level == 'Partner' || Auth::user()->access_level == 'Donor')
-
+ {{ csrf_field() }}
@@ -67,46 +67,46 @@
-
-
- -
- - -
-
- -
-
-
-
+
+
+ +
+ + +
+
+ +
+
+
+
-
-
-
- -
- - -
-
- -
-
-
+
+
+
+ +
+ +
-
-
- - +
+ +
+
+
+
+
+
+ + +
-
@@ -114,11 +114,11 @@ @endif @if (Auth::user()->access_level == 'Facility')
-
+ {{ csrf_field() }}
-
+
@@ -130,40 +130,40 @@
-
-
-
- -
- - -
-
- -
-
-
-
-
-
-
-
- -
- - -
-
- -
-
-
-
-
+
+
+
+ +
+ + +
+
+ +
+
+
+
+ +
+
+
+ +
+ + +
+
+ +
+
+
+
+
-
-
-
-
+
+
+ +
+ + +
+
+ +
+
+
+
-
-
- -
- - -
-
- -
-
-
-
+
+
+ +
+ + +
+
+ +
+
+
+
@@ -119,11 +119,11 @@
- + {{ csrf_field() }}
-
+
@@ -135,47 +135,46 @@
-
-
-
- -
- - -
-
- -
-
-
+
+
+
+ +
+ + +
+
+ +
+
+
+
+
+
+
+ +
+ +
-
-
-
-
- -
- - -
-
- -
-
-
+
+
-
-
- - +
+
+
+
+
+ + +
-
@@ -184,7 +183,7 @@ +
- @endif - @if (Auth::user()->access_level == 'Facility') -
+ @endif + @if (Auth::user()->access_level == 'Facility') +
@@ -255,8 +254,8 @@
-
-
+
+
@@ -266,7 +265,7 @@
-
+
@endif
@@ -311,8 +310,33 @@ + + + + + + + + + + + + +@endsection diff --git a/routes/web.php b/routes/web.php index 1472c90..2697ca7 100644 --- a/routes/web.php +++ b/routes/web.php @@ -206,5 +206,9 @@ Route::get('/filter_charts', ['uses' => 'App\Http\Controllers\NewDashboardController@filter_charts', 'as' => 'filter_charts']); Route::get('/filter_dashboard_charts', ['uses' => 'App\Http\Controllers\NewDashboardController@filter_dashboard_charts', 'as' => 'filter_dashboard_charts']); Route::get('/filter_missed_appointment_charts', ['uses' => 'App\Http\Controllers\NewDashboardController@filter_missed_appointment_charts', 'as' => 'filter_missed_appointment_charts']); + Route::get('/filter_appointment_charts', ['uses' => 'App\Http\Controllers\NewDashboardController@filter_appointment_charts', 'as' => 'filter_appointment_charts']); Route::get('/filter_client_charts', ['uses' => 'App\Http\Controllers\NewDashboardController@filter_client_charts', 'as' => 'filter_client_charts']); + + // new linelists rooutes + Route::get('/new/clients/list', ['uses' => 'App\Http\Controllers\NewReportController@clients_list', 'as' => 'clients_list']); }); From fcac321038cc61e5039862b127228ad84c22d369 Mon Sep 17 00:00:00 2001 From: Ronald-pro <36841157+Ronald-pro@users.noreply.github.com> Date: Mon, 16 May 2022 08:40:41 +0300 Subject: [PATCH 049/171] adjusted latest changes --- app/Http/Controllers/NewReportController.php | 50 +++++++++++++++++++- app/Http/Controllers/SMSReportController.php | 21 +++++--- config/app.php | 2 +- resources/views/sms/sms_report.blade.php | 4 ++ 4 files changed, 68 insertions(+), 9 deletions(-) diff --git a/app/Http/Controllers/NewReportController.php b/app/Http/Controllers/NewReportController.php index 53c23f2..18a395d 100644 --- a/app/Http/Controllers/NewReportController.php +++ b/app/Http/Controllers/NewReportController.php @@ -16,7 +16,9 @@ class NewReportController extends Controller { public function clients_list() { - $clients = Client::join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + if (Auth::user()->access_level == 'Facility') + { + $clients = Client::join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') ->join('tbl_master_facility', 'tbl_client.mfl_code', '=', 'tbl_master_facility.code') ->join('tbl_partner', 'tbl_partner_facility.partner_id', '=', 'tbl_partner.id') ->join('tbl_gender', 'tbl_client.gender', '=', 'tbl_gender.id') @@ -24,8 +26,52 @@ public function clients_list() ->select('tbl_client.clinic_number', 'tbl_client.f_name', 'tbl_client.m_name', 'tbl_client.l_name', 'tbl_client.dob', 'tbl_client.created_at', 'tbl_client.smsenable', 'tbl_client.phone_no', 'tbl_gender.name as gender', 'tbl_master_facility.code', 'tbl_master_facility.name as facility', 'tbl_partner.name as partner', 'tbl_county.name as county') ->where('tbl_client.status', '=', 'Active') ->whereNull('tbl_client.hei_no') - ->paginate(100); + ->where('tbl_client.mfl_code', Auth::user()->facility_id) + ->paginate(1000); + } + if (Auth::user()->access_level == 'Partner') + { + $clients = Client::join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->join('tbl_master_facility', 'tbl_client.mfl_code', '=', 'tbl_master_facility.code') + ->join('tbl_partner', 'tbl_partner_facility.partner_id', '=', 'tbl_partner.id') + ->join('tbl_gender', 'tbl_client.gender', '=', 'tbl_gender.id') + ->join('tbl_county', 'tbl_partner_facility.county_id', '=', 'tbl_county.id') + ->select('tbl_client.clinic_number', 'tbl_client.f_name', 'tbl_client.m_name', 'tbl_client.l_name', 'tbl_client.dob', 'tbl_client.created_at', 'tbl_client.smsenable', 'tbl_client.phone_no', 'tbl_gender.name as gender', 'tbl_master_facility.code', 'tbl_master_facility.name as facility', 'tbl_partner.name as partner', 'tbl_county.name as county') + ->where('tbl_client.status', '=', 'Active') + ->whereNull('tbl_client.hei_no') + ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) + ->paginate(1000); + } + if (Auth::user()->access_level == 'Admin' || Auth::user()->access_level == 'Donor') + { + $clients = Client::join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->join('tbl_master_facility', 'tbl_client.mfl_code', '=', 'tbl_master_facility.code') + ->join('tbl_partner', 'tbl_partner_facility.partner_id', '=', 'tbl_partner.id') + ->join('tbl_gender', 'tbl_client.gender', '=', 'tbl_gender.id') + ->join('tbl_county', 'tbl_partner_facility.county_id', '=', 'tbl_county.id') + ->select('tbl_client.clinic_number', 'tbl_client.f_name', 'tbl_client.m_name', 'tbl_client.l_name', 'tbl_client.dob', 'tbl_client.created_at', 'tbl_client.smsenable', 'tbl_client.phone_no', 'tbl_gender.name as gender', 'tbl_master_facility.code', 'tbl_master_facility.name as facility', 'tbl_partner.name as partner', 'tbl_county.name as county') + ->where('tbl_client.status', '=', 'Active') + ->whereNull('tbl_client.hei_no') + ->paginate(1000); + } + return view('new_reports.clients', compact('clients')); } + + public function appointment_list() + { + $appointments = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->join('tbl_master_facility', 'tbl_client.mfl_code', '=', 'tbl_master_facility.code') + ->join('tbl_partner', 'tbl_partner_facility.partner_id', '=', 'tbl_partner.id') + ->join('tbl_gender', 'tbl_client.gender', '=', 'tbl_gender.id') + ->join('tbl_county', 'tbl_partner_facility.county_id', '=', 'tbl_county.id') + ->join('tbl_appointment_types', 'tbl_appointment.app_type_1', '=', 'tbl_appointment_types.id') + ->select('tbl_client.clinic_number', 'tbl_client.f_name', 'tbl_client.m_name', 'tbl_client.l_name', 'tbl_client.dob', 'tbl_client.smsenable', 'tbl_client.phone_no', 'tbl_gender.name as gender', 'tbl_appointment_types.name as app_type', 'tbl_appointment.appntmnt_date', 'tbl_appointment.app_status', 'tbl_appointment.created_at', 'tbl_master_facility.code', 'tbl_master_facility.name as facility', 'tbl_partner.name as partner', 'tbl_county.name as county') + ->where('tbl_client.status', '=', 'Active') + ->paginate(1000); + + return view('new_reports.appointments', compact('appointments')); + } } diff --git a/app/Http/Controllers/SMSReportController.php b/app/Http/Controllers/SMSReportController.php index 51da299..b6a213e 100644 --- a/app/Http/Controllers/SMSReportController.php +++ b/app/Http/Controllers/SMSReportController.php @@ -21,8 +21,8 @@ public function success_sms() $all_partners = Partner::where('status', '=', 'Active')->pluck('name', 'id'); $delivered_partners = ClientOutgoing::join('tbl_client', 'tbl_clnt_outgoing.clnt_usr_id', '=', 'tbl_client.id') - ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') - ->join('tbl_partner', 'tbl_partner_facility.partner_id', '=', 'tbl_partner.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->join('tbl_partner', 'tbl_partner_facility.partner_id', '=', 'tbl_partner.id') ->select('tbl_partner.name', DB::raw('count(tbl_clnt_outgoing.callback_status) as total')) ->where('tbl_clnt_outgoing.callback_status', '=', 'Success') ->groupBy('tbl_partner.name') @@ -30,8 +30,8 @@ public function success_sms() ->get(); // dd($delivered_partners); $failed_partners = ClientOutgoing::join('tbl_client', 'tbl_clnt_outgoing.clnt_usr_id', '=', 'tbl_client.id') - ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') - ->join('tbl_partner', 'tbl_partner_facility.partner_id', '=', 'tbl_partner.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->join('tbl_partner', 'tbl_partner_facility.partner_id', '=', 'tbl_partner.id') ->select('tbl_partner.name', DB::raw('count(tbl_clnt_outgoing.callback_status) as total')) ->where('tbl_clnt_outgoing.callback_status', '=', 'Failed') ->groupBy('tbl_partner.name') @@ -124,6 +124,9 @@ public function success_sms() ->where('callback_status', '=', 'Rejected') ->where('failure_reason', '=', 'DeliveryFailure') ->pluck('total_cost'); + $total_cost = ClientOutgoing::select(\DB::raw("ROUND(SUM(SUBSTRING(cost, 5)), 0) as total_cost")) + ->whereNotNull('callback_status') + ->pluck('total_cost'); $all_partners = Partner::where('status', '=', 'Active') ->pluck('name', 'id'); @@ -149,7 +152,8 @@ public function success_sms() 'delivered_partners', 'failed_partners', 'cost_partners', - 'cost_counties' + 'cost_counties', + 'total_cost' )); } @@ -480,6 +484,10 @@ public function filtering_sms(Request $request) ->where('failure_reason', '=', 'DeliveryFailure') ->whereDate('tbl_clnt_outgoing.created_at', '>=', date($request->from))->whereDate('tbl_clnt_outgoing.created_at', '<=', date($request->to)) ->pluck('total_cost'); + $total_cost = ClientOutgoing::select(\DB::raw("ROUND(SUM(SUBSTRING(cost, 5)), 0) as total_cost")) + ->whereNotNull('callback_status') + ->whereDate('tbl_clnt_outgoing.created_at', '>=', date($request->from))->whereDate('tbl_clnt_outgoing.created_at', '<=', date($request->to)) + ->pluck('total_cost'); return view('sms.sms_report', compact( 'success', @@ -501,7 +509,8 @@ public function filtering_sms(Request $request) 'delivered_partners', 'failed_partners', 'cost_partners', - 'cost_counties' + 'cost_counties', + 'total_cost' )); } } diff --git a/config/app.php b/config/app.php index b797cff..652374d 100644 --- a/config/app.php +++ b/config/app.php @@ -175,7 +175,7 @@ App\Providers\EventServiceProvider::class, App\Providers\RouteServiceProvider::class, Maatwebsite\Excel\ExcelServiceProvider::class, - Barryvdh\Debugbar\ServiceProvider::class, + //Barryvdh\Debugbar\ServiceProvider::class, // MaddHatter\LaravelFullcalendar\ServiceProvider::class, diff --git a/resources/views/sms/sms_report.blade.php b/resources/views/sms/sms_report.blade.php index 95fe23f..c0d54d9 100644 --- a/resources/views/sms/sms_report.blade.php +++ b/resources/views/sms/sms_report.blade.php @@ -73,6 +73,9 @@
+
Total SMS Cost: Ksh.{{number_format(trim($total_cost, '[]'))}}
+
+
@@ -290,6 +293,7 @@ }); }); + var Total_cost = ; var Success = ; var Failed_blacklist = ; var Failed_absent = ; From 4407cad0f089aadd7cfeda7311084fc62d5bccc4 Mon Sep 17 00:00:00 2001 From: Ronald-pro <36841157+Ronald-pro@users.noreply.github.com> Date: Mon, 23 May 2022 22:03:52 +0300 Subject: [PATCH 050/171] updated changes --- app/Http/Controllers/Auth/LoginController.php | 6 +- .../Controllers/NewDashboardController.php | 162 ++++++++++-------- .../Middleware/RedirectIfAuthenticated.php | 4 +- .../large-vertical-sidebar/sidebar.blade.php | 10 ++ .../new_dashboard/main_dashbaord.blade.php | 67 ++++---- .../views/new_reports/appointments.blade.php | 117 +++++++++++++ resources/views/new_reports/clients.blade.php | 19 +- routes/web.php | 1 + 8 files changed, 280 insertions(+), 106 deletions(-) create mode 100644 resources/views/new_reports/appointments.blade.php diff --git a/app/Http/Controllers/Auth/LoginController.php b/app/Http/Controllers/Auth/LoginController.php index 8c5b5ef..83e1e32 100644 --- a/app/Http/Controllers/Auth/LoginController.php +++ b/app/Http/Controllers/Auth/LoginController.php @@ -32,13 +32,13 @@ protected function redirectTo() { } else if (Auth::user()->access_level == 'Facility') { Session::flash('statuscode', 'Login Success!, You will be redirected to your Home page in a few.'); - return '/Reports/facility_home'; + return '/admin/dashboard'; } else if (Auth::user()->access_level == 'Partner') { Session::flash('statuscode', 'success'); - return '/Reports/dashboard'; + return '/admin/dashboard'; } else if (Auth::user()->access_level == 'Admin') { Session::flash('statuscode', 'success'); - return '/Reports/dashboard'; + return '/admin/dashboard'; }else { return '/'; } diff --git a/app/Http/Controllers/NewDashboardController.php b/app/Http/Controllers/NewDashboardController.php index 09638fc..ae1dbc2 100644 --- a/app/Http/Controllers/NewDashboardController.php +++ b/app/Http/Controllers/NewDashboardController.php @@ -118,7 +118,7 @@ public function dashboard() }); } if (Auth::user()->access_level == 'Partner') { - $all_partners = Partner::where('status', '=', 'Active')->pluck('name', 'id'); + $all_partners = Partner::where('status', '=', 'Active')->where('id', Auth::user()->partner_id)->pluck('name', 'id'); $client = Client::join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') ->where('tbl_client.status', '=', 'Active') ->whereNull('tbl_client.hei_no') @@ -221,8 +221,8 @@ public function dashboard() if (Auth::user()->access_level == 'Admin' || Auth::user()->access_level == 'Donor') { $all_partners = Partner::where('status', '=', 'Active')->pluck('name', 'id'); - $client = Client::where('status', '=', 'Active')->whereNull('hei_no')->count('clinic_number'); - $client_ever_enrolled = Client::whereNull('hei_no')->count('clinic_number'); + $client = Client::where('status', '=', 'Active')->whereNull('hei_no')->count('id'); + $client_ever_enrolled = Client::whereNull('hei_no')->count('id'); $indicator = Indicator::select(['name', 'description'])->get(); @@ -236,64 +236,45 @@ public function dashboard() ->get(); $facilities_ever_enrolled = PartnerFacility::count('mfl_code'); - // dd($active_facilities); - // active clients by gender - $clients_male = Client::select('id')->where([['gender', '=', '2'], ['status', '=', 'Active'],]) + $clients_male = Client::where([['gender', '=', '2'], ['status', '=', 'Active'],]) ->whereNull('hei_no') - ->count(); + ->count('id'); - $clients_female = Client::where('gender', '=', '1') - ->where('status', '=', 'Active') + $clients_female = Client::where([['gender', '=', '1'], ['status', '=', 'Active'],]) ->whereNull('hei_no') - ->count(); - $unknown_gender = Client::where('gender', '!=', '1') - ->where('gender', '!=', '2') - ->where('status', '=', 'Active') + ->count('id'); + $unknown_gender = Client::where([['gender', '!=', '1'], ['gender', '!=', '2'], ['status', '=', 'Active'],]) ->whereNull('hei_no') - ->count(); + ->count('id'); - $client_to_nine = Cache::remember('client_to_nine', 10, function () { - return Client::select(\DB::raw("count((case when (((year(curdate()) - year(`dob`)) > 0) and ((year(curdate()) - year(`dob`)) <= 9)) then `dob` end)) AS count")) + $client_to_nine = Client::select(\DB::raw("count((case when (((year(curdate()) - year(`dob`)) > 0) and ((year(curdate()) - year(`dob`)) <= 9)) then `dob` end)) AS count")) ->where('status', '=', 'Active') ->whereNull('hei_no') ->pluck('count'); - }); - $client_to_fourteen = Cache::remember('client-fourteen', 10, function () { - return Client::select(\DB::raw("count((case when (((year(curdate()) - year(`dob`)) >= 10) and ((year(curdate()) - year(`dob`)) <= 14)) then `dob` end)) AS count")) + $client_to_fourteen = Client::select(\DB::raw("count((case when (((year(curdate()) - year(`dob`)) >= 10) and ((year(curdate()) - year(`dob`)) <= 14)) then `dob` end)) AS count")) ->where('status', '=', 'Active') ->whereNull('hei_no') ->pluck('count'); - }); - - $client_to_nineteen = Cache::remember('client-nineteen', 10, function () { - return Client::select(\DB::raw("count((case when (((year(curdate()) - year(`dob`)) >= 15) and ((year(curdate()) - year(`dob`)) <= 19)) then `dob` end)) AS count")) + $client_to_nineteen = Client::select(\DB::raw("count((case when (((year(curdate()) - year(`dob`)) >= 15) and ((year(curdate()) - year(`dob`)) <= 19)) then `dob` end)) AS count")) ->where('status', '=', 'Active') ->whereNull('hei_no') ->pluck('count'); - }); - - $client_to_twentyfour = Cache::remember('client-twentyfour', 10, function () { - return Client::select(\DB::raw("count((case when (((year(curdate()) - year(`dob`)) >= 20) and ((year(curdate()) - year(`dob`)) <= 24)) then `id` end)) AS count")) + $client_to_twentyfour = Client::select(\DB::raw("count((case when (((year(curdate()) - year(`dob`)) >= 20) and ((year(curdate()) - year(`dob`)) <= 24)) then `id` end)) AS count")) ->where('status', '=', 'Active') ->whereNull('hei_no') ->pluck('count'); - }); - $client_to_twentyfive_above = Cache::remember('client-twentyfive-above', 10, function () { - return Client::select(\DB::raw("count((case when (((year(curdate()) - year(`dob`)) >= 25)) then `id` end)) AS count")) + $client_to_twentyfive_above = Client::select(\DB::raw("count((case when (((year(curdate()) - year(`dob`)) >= 25)) then `id` end)) AS count")) ->where('status', '=', 'Active') ->whereNull('hei_no') ->pluck('count'); - }); - $client_unknown_age = Cache::remember('client-unknown-age', 10, function () { - return Client::where('dob', '=', '') + $client_unknown_age = Client::where('dob', '=', '') ->orWhereNull('dob') ->where('status', '=', 'Active') ->whereNull('hei_no') - ->count(); - }); + ->count('id'); // // appointment by gender // $appointment_male = Cache::remember('appointment-male', 10, function () { @@ -624,7 +605,7 @@ public function client_dashboard() }); } if (Auth::user()->access_level == 'Partner') { - $all_partners = Partner::where('status', '=', 'Active')->pluck('name', 'id'); + $all_partners = Partner::where('status', '=', 'Active')->where('id', Auth::user()->partner_id)->pluck('name', 'id'); $client = Client::join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') ->where('tbl_client.status', '=', 'Active') ->whereNull('tbl_client.hei_no') @@ -1155,7 +1136,7 @@ public function appointment_charts() ->count(); } if (Auth::user()->access_level == 'Partner') { - $all_partners = Partner::where('status', '=', 'Active')->pluck('name', 'id'); + $all_partners = Partner::where('status', '=', 'Active')->where('id', Auth::user()->partner_id)->pluck('name', 'id'); $indicator = Indicator::select(['name', 'description'])->get(); // main appointments $appointment = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') @@ -1666,7 +1647,7 @@ public function missed_appointment_charts() ->count(); } if (Auth::user()->access_level == 'Partner') { - $all_partners = Partner::where('status', '=', 'Active')->pluck('name', 'id'); + $all_partners = Partner::where('status', '=', 'Active')->where('id', Auth::user()->partner_id)->pluck('name', 'id'); $indicator = Indicator::select(['name', 'description'])->get(); // dd($appointment_honoured); @@ -2831,74 +2812,71 @@ public function filter_dashboard_charts(Request $request) $selected_module = $request->module; if (Auth::user()->access_level == 'Facility') { - $facilities_ever_enrolled = PartnerFacility::where('created_at', '>=', date($request->from))->where('created_at', '<=', date($request->to)); + $facilities_ever_enrolled = PartnerFacility::where('tbl_partner_facility.mfl_code', Auth::user()->facility_id); + $active_facilities = PartnerFacility::join('tbl_client', 'tbl_partner_facility.mfl_code', '=', 'tbl_client.mfl_code') + ->join('tbl_appointment', 'tbl_client.id', '=', 'tbl_appointment.client_id') + ->select('tbl_partner_facility.mfl_code') + ->where('tbl_appointment.created_at', '>=', Carbon::now()->subMonths(6)) + ->orderBy('tbl_appointment.created_at', 'DESC') + ->groupBy('tbl_partner_facility.mfl_code') + ->where('tbl_partner_facility.mfl_code', Auth::user()->facility_id); $client = Client::join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') ->where('tbl_client.status', '=', 'Active') ->whereNull('tbl_client.hei_no') - ->where('tbl_client.mfl_code', Auth::user()->facility_id) - ->whereDate('tbl_client.created_at', '>=', date($request->from))->whereDate('tbl_client.created_at', '<=', date($request->to)); + ->where('tbl_client.mfl_code', Auth::user()->facility_id); $client_ever_enrolled = Client::join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') ->whereNull('tbl_client.hei_no') - ->where('tbl_client.mfl_code', Auth::user()->facility_id) - ->where('tbl_client.created_at', '>=', date($request->from))->where('tbl_client.created_at', '<=', date($request->to)); + ->where('tbl_client.mfl_code', Auth::user()->facility_id); // active clients by gender $clients_male = Client::join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') ->select('tbl_client.id') ->where([['tbl_client.gender', '=', '2'], ['tbl_client.status', '=', 'Active'],]) ->whereNull('tbl_client.hei_no') - ->where('tbl_client.mfl_code', Auth::user()->facility_id) - ->whereDate('tbl_client.created_at', '>=', date($request->from))->whereDate('tbl_client.created_at', '<=', date($request->to)); + ->where('tbl_client.mfl_code', Auth::user()->facility_id); $clients_female = Client::join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') ->where([['tbl_client.gender', '=', '1'], ['tbl_client.status', '=', 'Active'],]) ->whereNull('tbl_client.hei_no') - ->where('tbl_client.mfl_code', Auth::user()->facility_id) - ->whereDate('tbl_client.created_at', '>=', date($request->from))->whereDate('tbl_client.created_at', '<=', date($request->to)); + ->where('tbl_client.mfl_code', Auth::user()->facility_id); $unknown_gender = Client::join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') ->where([['tbl_client.gender', '!=', '1'], ['tbl_client.gender', '!=', '2'], ['tbl_client.status', '=', 'Active'],]) ->whereNull('tbl_client.hei_no') - ->where('tbl_client.mfl_code', Auth::user()->facility_id) - ->whereDate('tbl_client.created_at', '>=', date($request->from))->whereDate('tbl_client.created_at', '<=', date($request->to)); + ->where('tbl_client.mfl_code', Auth::user()->facility_id); $client_to_nine = Client::join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) > 0) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 9)) then `tbl_client`.`dob` end)) AS count")) ->where('tbl_client.status', '=', 'Active') ->whereNull('tbl_client.hei_no') - ->where('tbl_client.mfl_code', Auth::user()->facility_id) - ->whereDate('tbl_client.created_at', '>=', date($request->from))->whereDate('tbl_client.created_at', '<=', date($request->to)); + ->where('tbl_client.mfl_code', Auth::user()->facility_id); $client_to_fourteen = Client::join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 10) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 14)) then `tbl_client`.`dob` end)) AS count")) ->where('tbl_client.status', '=', 'Active') ->whereNull('tbl_client.hei_no') - ->where('tbl_client.mfl_code', Auth::user()->facility_id) - ->whereDate('tbl_client.created_at', '>=', date($request->from))->whereDate('tbl_client.created_at', '<=', date($request->to)); + ->where('tbl_client.mfl_code', Auth::user()->facility_id); $client_to_nineteen = Client::join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 15) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 19)) then `tbl_client`.`dob` end)) AS count")) ->where('tbl_client.status', '=', 'Active') ->whereNull('tbl_client.hei_no') - ->where('tbl_client.mfl_code', Auth::user()->facility_id) - ->whereDate('tbl_client.created_at', '>=', date($request->from))->whereDate('tbl_client.created_at', '<=', date($request->to)); + ->where('tbl_client.mfl_code', Auth::user()->facility_id); $client_to_twentyfour = Client::join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 20) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 24)) then `tbl_client`.`dob` end)) AS count")) ->where('tbl_client.status', '=', 'Active') ->whereNull('tbl_client.hei_no') - ->where('tbl_client.mfl_code', Auth::user()->facility_id) - ->whereDate('tbl_client.created_at', '>=', date($request->from))->whereDate('tbl_client.created_at', '<=', date($request->to)); + ->where('tbl_client.mfl_code', Auth::user()->facility_id); $client_to_twentyfive_above = Client::join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') ->select(\DB::raw("count((case when (((year(curdate()) - year(`tbl_client`.`dob`)) >= 25)) then `tbl_client`.`dob` end)) AS count")) ->where('tbl_client.status', '=', 'Active') ->whereNull('tbl_client.hei_no') - ->where('tbl_client.mfl_code', Auth::user()->facility_id) - ->whereDate('tbl_client.created_at', '>=', date($request->from))->whereDate('tbl_client.created_at', '<=', date($request->to)); + ->where('tbl_client.mfl_code', Auth::user()->facility_id); $client_unknown_age = Client::join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') @@ -2906,11 +2884,10 @@ public function filter_dashboard_charts(Request $request) ->WhereNull('tbl_client.dob') ->where('tbl_client.status', '=', 'Active') ->whereNull('tbl_client.hei_no') - ->where('tbl_client.mfl_code', Auth::user()->facility_id) - ->whereDate('tbl_client.created_at', '>=', date($request->from))->whereDate('tbl_client.created_at', '<=', date($request->to)); + ->where('tbl_client.mfl_code', Auth::user()->facility_id); } if (Auth::user()->access_level == 'Partner') { - $all_partners = Partner::where('status', '=', 'Active')->pluck('name', 'id'); + $indicator = Indicator::select(['name', 'description'])->get(); @@ -2927,10 +2904,9 @@ public function filter_dashboard_charts(Request $request) ->where('tbl_appointment.created_at', '>=', Carbon::now()->subMonths(6)) ->orderBy('tbl_appointment.created_at', 'DESC') ->groupBy('tbl_partner_facility.mfl_code') - ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) - ->get(); - $facilities_ever_enrolled = PartnerFacility::where('partner_id', Auth::user()->partner_id) - ->where('created_at', '>=', date($request->from))->where('created_at', '<=', date($request->to)); + ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id); + $facilities_ever_enrolled = PartnerFacility::join('tbl_client', 'tbl_partner_facility.mfl_code', '=', 'tbl_client.mfl_code') + ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id); // active clients by gender $clients_male = Client::join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') ->select('tbl_client.id') @@ -2992,7 +2968,6 @@ public function filter_dashboard_charts(Request $request) if (Auth::user()->access_level == 'Admin' || Auth::user()->access_level == 'Donor') { - $all_partners = Partner::where('status', '=', 'Active')->pluck('name', 'id'); $indicator = Indicator::select(['name', 'description'])->get(); @@ -3007,7 +2982,7 @@ public function filter_dashboard_charts(Request $request) ->where('tbl_appointment.created_at', '>=', Carbon::now()->subMonths(6)) ->orderBy('tbl_appointment.created_at', 'DESC') ->groupBy('tbl_partner_facility.mfl_code'); - $facilities_ever_enrolled = PartnerFacility::select('mfl_code'); + $facilities_ever_enrolled = PartnerFacility::select('tbl_partner_facility.mfl_code'); // active clients by gender $clients_male = Client::join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') ->select('tbl_client.id') @@ -3120,7 +3095,7 @@ public function filter_dashboard_charts(Request $request) $client = $client->where('tbl_client.created_at', '>=', date($request->from))->where('tbl_client.created_at', '<=', date($request->to)); $client_ever_enrolled = $client_ever_enrolled->where('tbl_client.created_at', '>=', date($request->from))->where('tbl_client.created_at', '<=', date($request->to)); $active_facilities = $active_facilities->where('tbl_appointment.created_at', '>=', date($request->from))->where('tbl_appointment.created_at', '>=', date($request->to)); - $facilities_ever_enrolled = $facilities_ever_enrolled->where('created_at', '>=', date($request->from))->where('created_at', '<=', date($request->to)); + $facilities_ever_enrolled = $facilities_ever_enrolled->where('tbl_partner_facility.created_at', '>=', date($request->from))->where('tbl_partner_facility.created_at', '<=', date($request->to)); $clients_male = $clients_male->where('tbl_client.created_at', '>=', date($request->from))->where('tbl_client.created_at', '<=', date($request->to)); $clients_female = $clients_female->where('tbl_client.created_at', '>=', date($request->from))->where('tbl_client.created_at', '<=', date($request->to)); $unknown_gender = $unknown_gender->where('tbl_client.created_at', '>=', date($request->from))->where('tbl_client.created_at', '<=', date($request->to)); @@ -3164,7 +3139,7 @@ public function filter_dashboard_charts(Request $request) $data["client"] = $client->count(); $data["facilities_ever_enrolled"] = $facilities_ever_enrolled->count(); $data["client_ever_enrolled"] = $client_ever_enrolled->count(); - $data["active_facilities"] = $active_facilities->count(); + $data["active_facilities"] = $active_facilities->get()->count(); $data["clients_male"] = $clients_male->count(); $data["clients_female"] = $clients_female->count(); $data["unknown_gender"] = $unknown_gender->count(); @@ -3835,6 +3810,7 @@ public function filter_appointment_charts(Request $request) $selected_facilites = $request->facilities; $selected_from = $request->from; $selected_to = $request->to; + $selected_module = $request->module; if (Auth::user()->access_level == 'Facility') { $appointment = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') @@ -4318,6 +4294,52 @@ public function filter_appointment_charts(Request $request) $appointment_not_honored_to_twentyfive_above = $appointment_not_honored_to_twentyfive_above->where('tbl_appointment.created_at', '>=', date($request->from))->where('tbl_appointment.created_at', '<=', date($request->to)); $appointment_not_honored_to_uknown_age = $appointment_not_honored_to_uknown_age->where('tbl_appointment.created_at', '>=', date($request->from))->where('tbl_appointment.created_at', '<=', date($request->to)); } + if (!empty($selected_module == 'DSD')) { + $appointment = $appointment->join('tbl_dfc_module', 'tbl_client.id', '=', 'tbl_dfc_module.client_id'); + $appointment_honoured = $appointment_honoured->join('tbl_dfc_module', 'tbl_client.id', '=', 'tbl_dfc_module.client_id'); + $appointment_not_honoured = $appointment_not_honoured->join('tbl_dfc_module', 'tbl_client.id', '=', 'tbl_dfc_module.client_id'); + $appointment_honoured_male = $appointment_honoured_male->join('tbl_dfc_module', 'tbl_client.id', '=', 'tbl_dfc_module.client_id'); + $appointment_honoured_female = $appointment_honoured_female->join('tbl_dfc_module', 'tbl_client.id', '=', 'tbl_dfc_module.client_id'); + $appointment_honoured_uknown_gender = $appointment_honoured_uknown_gender->join('tbl_dfc_module', 'tbl_client.id', '=', 'tbl_dfc_module.client_id'); + $appointment_honored_to_nine = $appointment_honored_to_nine->join('tbl_dfc_module', 'tbl_client.id', '=', 'tbl_dfc_module.client_id'); + $appointment_honored_to_fourteen = $appointment_honored_to_fourteen->join('tbl_dfc_module', 'tbl_client.id', '=', 'tbl_dfc_module.client_id'); + $appointment_honored_to_nineteen = $appointment_honored_to_nineteen->join('tbl_dfc_module', 'tbl_client.id', '=', 'tbl_dfc_module.client_id'); + $appointment_honored_to_twentyfour = $appointment_honored_to_twentyfour->join('tbl_dfc_module', 'tbl_client.id', '=', 'tbl_dfc_module.client_id'); + $appointment_honored_to_twentyfive_above = $appointment_honored_to_twentyfive_above->join('tbl_dfc_module', 'tbl_client.id', '=', 'tbl_dfc_module.client_id'); + $appointment_honored_to_uknown_age = $appointment_honored_to_uknown_age->join('tbl_dfc_module', 'tbl_client.id', '=', 'tbl_dfc_module.client_id'); + $appointment_not_honoured_male = $appointment_not_honoured_male->join('tbl_dfc_module', 'tbl_client.id', '=', 'tbl_dfc_module.client_id'); + $appointment_not_honoured_female = $appointment_not_honoured_female->join('tbl_dfc_module', 'tbl_client.id', '=', 'tbl_dfc_module.client_id'); + $appointment_not_honoured_uknown_gender = $appointment_not_honoured_uknown_gender->join('tbl_dfc_module', 'tbl_client.id', '=', 'tbl_dfc_module.client_id'); + $appointment_not_honored_to_nine = $appointment_not_honored_to_nine->join('tbl_dfc_module', 'tbl_client.id', '=', 'tbl_dfc_module.client_id'); + $appointment_not_honored_to_fourteen = $appointment_not_honored_to_fourteen->join('tbl_dfc_module', 'tbl_client.id', '=', 'tbl_dfc_module.client_id'); + $appointment_not_honored_to_nineteen = $appointment_not_honored_to_nineteen->join('tbl_dfc_module', 'tbl_client.id', '=', 'tbl_dfc_module.client_id'); + $appointment_not_honored_to_twentyfour = $appointment_not_honored_to_twentyfour->join('tbl_dfc_module', 'tbl_client.id', '=', 'tbl_dfc_module.client_id'); + $appointment_not_honored_to_twentyfive_above = $appointment_not_honored_to_twentyfive_above->join('tbl_dfc_module', 'tbl_client.id', '=', 'tbl_dfc_module.client_id'); + $appointment_not_honored_to_uknown_age = $appointment_not_honored_to_uknown_age->join('tbl_dfc_module', 'tbl_client.id', '=', 'tbl_dfc_module.client_id'); + } + if (!empty($selected_module == 'PMTCT')) { + $appointment = $appointment->join('tbl_pmtct', 'tbl_client.id', '=', 'tbl_pmtct.client_id'); + $appointment_honoured = $appointment_honoured->join('tbl_pmtct', 'tbl_client.id', '=', 'tbl_pmtct.client_id'); + $appointment_not_honoured = $appointment_not_honoured->join('tbl_pmtct', 'tbl_client.id', '=', 'tbl_pmtct.client_id'); + $appointment_honoured_male = $appointment_honoured_male->join('tbl_pmtct', 'tbl_client.id', '=', 'tbl_pmtct.client_id'); + $appointment_honoured_female = $appointment_honoured_female->join('tbl_pmtct', 'tbl_client.id', '=', 'tbl_pmtct.client_id'); + $appointment_honoured_uknown_gender = $appointment_honoured_uknown_gender->join('tbl_pmtct', 'tbl_client.id', '=', 'tbl_pmtct.client_id'); + $appointment_honored_to_nine = $appointment_honored_to_nine->join('tbl_pmtct', 'tbl_client.id', '=', 'tbl_pmtct.client_id'); + $appointment_honored_to_fourteen = $appointment_honored_to_fourteen->join('tbl_pmtct', 'tbl_client.id', '=', 'tbl_pmtct.client_id'); + $appointment_honored_to_nineteen = $appointment_honored_to_nineteen->join('tbl_pmtct', 'tbl_client.id', '=', 'tbl_pmtct.client_id'); + $appointment_honored_to_twentyfour = $appointment_honored_to_twentyfour->join('tbl_pmtct', 'tbl_client.id', '=', 'tbl_pmtct.client_id'); + $appointment_honored_to_twentyfive_above = $appointment_honored_to_twentyfive_above->join('tbl_pmtct', 'tbl_client.id', '=', 'tbl_pmtct.client_id'); + $appointment_honored_to_uknown_age = $appointment_honored_to_uknown_age->join('tbl_pmtct', 'tbl_client.id', '=', 'tbl_pmtct.client_id'); + $appointment_not_honoured_male = $appointment_not_honoured_male->join('tbl_pmtct', 'tbl_client.id', '=', 'tbl_pmtct.client_id'); + $appointment_not_honoured_female = $appointment_not_honoured_female->join('tbl_pmtct', 'tbl_client.id', '=', 'tbl_pmtct.client_id'); + $appointment_not_honoured_uknown_gender = $appointment_not_honoured_uknown_gender->join('tbl_pmtct', 'tbl_client.id', '=', 'tbl_pmtct.client_id'); + $appointment_not_honored_to_nine = $appointment_not_honored_to_nine->join('tbl_pmtct', 'tbl_client.id', '=', 'tbl_pmtct.client_id'); + $appointment_not_honored_to_fourteen = $appointment_not_honored_to_fourteen->join('tbl_pmtct', 'tbl_client.id', '=', 'tbl_pmtct.client_id'); + $appointment_not_honored_to_nineteen = $appointment_not_honored_to_nineteen->join('tbl_pmtct', 'tbl_client.id', '=', 'tbl_pmtct.client_id'); + $appointment_not_honored_to_twentyfour = $appointment_not_honored_to_twentyfour->join('tbl_pmtct', 'tbl_client.id', '=', 'tbl_pmtct.client_id'); + $appointment_not_honored_to_twentyfive_above = $appointment_not_honored_to_twentyfive_above->join('tbl_pmtct', 'tbl_client.id', '=', 'tbl_pmtct.client_id'); + $appointment_not_honored_to_uknown_age = $appointment_not_honored_to_uknown_age->join('tbl_pmtct', 'tbl_client.id', '=', 'tbl_pmtct.client_id'); + } $data["appointment"] = $appointment->count(); $data["appointment_honoured"] = $appointment_honoured->count(); diff --git a/app/Http/Middleware/RedirectIfAuthenticated.php b/app/Http/Middleware/RedirectIfAuthenticated.php index 3238635..fb5014e 100644 --- a/app/Http/Middleware/RedirectIfAuthenticated.php +++ b/app/Http/Middleware/RedirectIfAuthenticated.php @@ -22,10 +22,10 @@ public function handle($request, Closure $next, $guard = null) if (Auth::guard($guard)->check()) { if (Auth::user()->access_level == 'Admin' || Auth::user()->access_level == 'Partner' || Auth::user()->access_level == 'Donor') { - return redirect('/Reports/dashboard')->with('success', 'Login Success! You will be redirected to your Home page in a few.'); + return redirect('/admin/dashboard')->with('success', 'Login Success! You will be redirected to your Home page in a few.'); } if (Auth::user()->access_level == 'Facility') { - return redirect('/Reports/facility_home')->with('success', 'Login Success! You will be redirected to your Home page in a few.'); + return redirect('/admin/dashboard')->with('success', 'Login Success! You will be redirected to your Home page in a few.'); } } return $next($request); diff --git a/resources/views/layouts/large-vertical-sidebar/sidebar.blade.php b/resources/views/layouts/large-vertical-sidebar/sidebar.blade.php index 90302be..4e37b97 100644 --- a/resources/views/layouts/large-vertical-sidebar/sidebar.blade.php +++ b/resources/views/layouts/large-vertical-sidebar/sidebar.blade.php @@ -243,6 +243,16 @@ Appointments + + - - + @@ -97,9 +104,12 @@ @endif @if (Auth::user()->access_level == 'Admin' || Auth::user()->access_level == 'Partner' || Auth::user()->access_level == 'Donor' || Auth::user()->access_level == 'County' || Auth::user()->access_level == 'Sub County') @@ -112,17 +122,17 @@ - + @endif + @if (Auth::user()->access_level == 'Partner' || Auth::user()->access_level == 'Admin' || Auth::user()->access_level == 'Donor' || Auth::user()->access_level == 'County' || Auth::user()->access_level == 'Sub County' || Auth::user()->access_level == 'Facility') - + @if (Auth::user()->access_level == 'Partner' || Auth::user()->access_level == 'Admin' || Auth::user()->access_level == 'Facility') + @endif @if (Auth::user()->access_level == 'Admin') + @endif
diff --git a/resources/views/new_dashboard/main_dashbaord.blade.php b/resources/views/new_dashboard/main_dashbaord.blade.php index ea8f1cf..33db8b4 100644 --- a/resources/views/new_dashboard/main_dashbaord.blade.php +++ b/resources/views/new_dashboard/main_dashbaord.blade.php @@ -10,7 +10,7 @@
  • --> -@if (Auth::user()->access_level == 'Admin' || Auth::user()->access_level == 'Partner' || Auth::user()->access_level == 'Donor') +@if (Auth::user()->access_level == 'Admin' || Auth::user()->access_level == 'Partner' || Auth::user()->access_level == 'Donor' || Auth::user()->access_level == 'County' || Auth::user()->access_level == 'Sub County')
    @@ -83,7 +83,7 @@
    - +
    @@ -99,7 +99,7 @@
    - +
    @@ -152,7 +152,7 @@
    - +
    @@ -168,7 +168,7 @@
    - +
    @@ -473,7 +473,7 @@ }, url: "{{ route('filter_dashboard_charts') }}", success: function(data) { - + $("#client").html(data.client); $("#client_ever_enrolled").html(data.client_ever_enrolled); $("#facilities_ever_enrolled").html(data.facilities_ever_enrolled); From d7c31a70adf3cca22d51a24c892b70f46d87ba7d Mon Sep 17 00:00:00 2001 From: Ronald-pro <36841157+Ronald-pro@users.noreply.github.com> Date: Mon, 5 Dec 2022 11:05:28 +0300 Subject: [PATCH 127/171] refine county and subcounty content view --- .../Controllers/NewDashboardController.php | 2736 +++++++++++++---- .../appointment_dashboard.blade.php | 2 +- .../new_dashboard/client_dashboard.blade.php | 10 +- .../new_dashboard/missed_dashboard.blade.php | 2 +- 4 files changed, 2153 insertions(+), 597 deletions(-) diff --git a/app/Http/Controllers/NewDashboardController.php b/app/Http/Controllers/NewDashboardController.php index ab06f1a..0964cd2 100644 --- a/app/Http/Controllers/NewDashboardController.php +++ b/app/Http/Controllers/NewDashboardController.php @@ -4854,6 +4854,212 @@ public function filter_dashboard_charts(Request $request) ->whereNull('tbl_client.hei_no') ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id); } + if (Auth::user()->access_level == 'Sub County') { + + $client = Client::join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->where('tbl_client.status', '=', 'Active') + ->whereNull('tbl_client.hei_no') + ->where('tbl_partner_facility.sub_county_id', Auth::user()->subcounty_id); + $client_ever_enrolled = Client::join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->whereNull('tbl_client.hei_no') + ->where('tbl_partner_facility.sub_county_id', Auth::user()->subcounty_id); + $active_facilities = PartnerFacility::join('tbl_client', 'tbl_partner_facility.mfl_code', '=', 'tbl_client.mfl_code') + ->join('tbl_appointment', 'tbl_client.id', '=', 'tbl_appointment.client_id') + ->select('tbl_partner_facility.mfl_code') + ->where('tbl_appointment.created_at', '>=', Carbon::now()->subMonths(6)) + ->orderBy('tbl_appointment.created_at', 'DESC') + ->groupBy('tbl_partner_facility.mfl_code') + ->where('tbl_partner_facility.sub_county_id', Auth::user()->subcounty_id); + $facilities_ever_enrolled = PartnerFacility::select('tbl_partner_facility.mfl_code')->where('tbl_partner_facility.sub_county_id', Auth::user()->subcounty_id); + // active clients by gender + $clients_male = Client::join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select('tbl_client.id') + ->where([['tbl_client.gender', '=', '2'], ['tbl_client.status', '=', 'Active'],]) + ->whereNull('tbl_client.hei_no') + ->where('tbl_partner_facility.sub_county_id', Auth::user()->subcounty_id); + + $clients_female = Client::join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->where([['tbl_client.gender', '=', '1'], ['tbl_client.status', '=', 'Active'],]) + ->whereNull('tbl_client.hei_no') + ->where('tbl_partner_facility.sub_county_id', Auth::user()->subcounty_id); + + $unknown_gender = Client::join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->where([['tbl_client.gender', '!=', '1'], ['tbl_client.gender', '!=', '2'], ['tbl_client.status', '=', 'Active'],]) + ->whereNull('tbl_client.hei_no') + ->where('tbl_partner_facility.sub_county_id', Auth::user()->subcounty_id); + + + $client_to_nine = Client::join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select(\DB::raw("count((case when (((year(curdate()) - year(CASE + WHEN ( locate( '/', `tbl_client`.`dob` ) > 0 ) THEN + date_format( str_to_date( `tbl_client`.`dob`, '%m/%d/%Y' ), '%Y-%m-%d' ) + WHEN ( locate( '-', `tbl_client`.`dob` ) > 0 ) THEN + date_format( str_to_date( `tbl_client`.`dob`, '%Y-%m-%d' ), '%Y-%m-%d' ) END)) > 0) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 9)) then `tbl_client`.`dob` end)) AS count")) + ->where('tbl_client.status', '=', 'Active') + ->whereNull('tbl_client.hei_no') + ->where('tbl_partner_facility.sub_county_id', Auth::user()->subcounty_id); + + + $client_to_fourteen = Client::join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select(\DB::raw("count((case when (((year(curdate()) - year(CASE + WHEN ( locate( '/', `tbl_client`.`dob` ) > 0 ) THEN + date_format( str_to_date( `tbl_client`.`dob`, '%m/%d/%Y' ), '%Y-%m-%d' ) + WHEN ( locate( '-', `tbl_client`.`dob` ) > 0 ) THEN + date_format( str_to_date( `tbl_client`.`dob`, '%Y-%m-%d' ), '%Y-%m-%d' ) END)) >= 10) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 14)) then `tbl_client`.`dob` end)) AS count")) + ->where('tbl_client.status', '=', 'Active') + ->whereNull('tbl_client.hei_no') + ->where('tbl_partner_facility.sub_county_id', Auth::user()->subcounty_id); + + + $client_to_nineteen = Client::join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select(\DB::raw("count((case when (((year(curdate()) - year(CASE + WHEN ( locate( '/', `tbl_client`.`dob` ) > 0 ) THEN + date_format( str_to_date( `tbl_client`.`dob`, '%m/%d/%Y' ), '%Y-%m-%d' ) + WHEN ( locate( '-', `tbl_client`.`dob` ) > 0 ) THEN + date_format( str_to_date( `tbl_client`.`dob`, '%Y-%m-%d' ), '%Y-%m-%d' ) END)) >= 15) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 19)) then `tbl_client`.`dob` end)) AS count")) + ->where('tbl_client.status', '=', 'Active') + ->whereNull('tbl_client.hei_no') + ->where('tbl_partner_facility.sub_county_id', Auth::user()->subcounty_id); + + $client_to_twentyfour = Client::join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select(\DB::raw("count((case when (((year(curdate()) - year(CASE + WHEN ( locate( '/', `tbl_client`.`dob` ) > 0 ) THEN + date_format( str_to_date( `tbl_client`.`dob`, '%m/%d/%Y' ), '%Y-%m-%d' ) + WHEN ( locate( '-', `tbl_client`.`dob` ) > 0 ) THEN + date_format( str_to_date( `tbl_client`.`dob`, '%Y-%m-%d' ), '%Y-%m-%d' ) END)) >= 20) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 24)) then `tbl_client`.`dob` end)) AS count")) + ->where('tbl_client.status', '=', 'Active') + ->whereNull('tbl_client.hei_no') + ->where('tbl_partner_facility.sub_county_id', Auth::user()->subcounty_id); + + $client_to_twentyfive_above = Client::join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select(\DB::raw("count((case when (((year(curdate()) - year(CASE + WHEN ( locate( '/', `tbl_client`.`dob` ) > 0 ) THEN + date_format( str_to_date( `tbl_client`.`dob`, '%m/%d/%Y' ), '%Y-%m-%d' ) + WHEN ( locate( '-', `tbl_client`.`dob` ) > 0 ) THEN + date_format( str_to_date( `tbl_client`.`dob`, '%Y-%m-%d' ), '%Y-%m-%d' ) END)) >= 25)) then `tbl_client`.`dob` end)) AS count")) + ->where('tbl_client.status', '=', 'Active') + ->whereNull('tbl_client.hei_no') + ->where('tbl_partner_facility.sub_county_id', Auth::user()->subcounty_id); + + + $client_unknown_age = Client::join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->where(\DB::raw("CASE + WHEN ( locate( '/', `tbl_client`.`dob` ) > 0 ) THEN + date_format( str_to_date( `tbl_client`.`dob`, '%m/%d/%Y' ), '%Y-%m-%d' ) + WHEN ( locate( '-', `tbl_client`.`dob` ) > 0 ) THEN + date_format( str_to_date( `tbl_client`.`dob`, '%Y-%m-%d' ), '%Y-%m-%d' ) END"), '=', '') + ->orWhereNull(\DB::raw("CASE + WHEN ( locate( '/', `tbl_client`.`dob` ) > 0 ) THEN + date_format( str_to_date( `tbl_client`.`dob`, '%m/%d/%Y' ), '%Y-%m-%d' ) + WHEN ( locate( '-', `tbl_client`.`dob` ) > 0 ) THEN + date_format( str_to_date( `tbl_client`.`dob`, '%Y-%m-%d' ), '%Y-%m-%d' ) END")) + ->where('tbl_client.status', '=', 'Active') + ->whereNull('tbl_client.hei_no') + ->where('tbl_partner_facility.sub_county_id', Auth::user()->subcounty_id); + } + if (Auth::user()->access_level == 'County') { + + $client = Client::join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->where('tbl_client.status', '=', 'Active') + ->whereNull('tbl_client.hei_no') + ->where('tbl_partner_facility.county_id', Auth::user()->county_id); + $client_ever_enrolled = Client::join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->whereNull('tbl_client.hei_no') + ->where('tbl_partner_facility.county_id', Auth::user()->county_id); + $active_facilities = PartnerFacility::join('tbl_client', 'tbl_partner_facility.mfl_code', '=', 'tbl_client.mfl_code') + ->join('tbl_appointment', 'tbl_client.id', '=', 'tbl_appointment.client_id') + ->select('tbl_partner_facility.mfl_code') + ->where('tbl_appointment.created_at', '>=', Carbon::now()->subMonths(6)) + ->orderBy('tbl_appointment.created_at', 'DESC') + ->groupBy('tbl_partner_facility.mfl_code') + ->where('tbl_partner_facility.county_id', Auth::user()->county_id); + $facilities_ever_enrolled = PartnerFacility::select('tbl_partner_facility.mfl_code')->where('tbl_partner_facility.sub_county_id', Auth::user()->subcounty_id); + // active clients by gender + $clients_male = Client::join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select('tbl_client.id') + ->where([['tbl_client.gender', '=', '2'], ['tbl_client.status', '=', 'Active'],]) + ->whereNull('tbl_client.hei_no') + ->where('tbl_partner_facility.county_id', Auth::user()->county_id); + + $clients_female = Client::join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->where([['tbl_client.gender', '=', '1'], ['tbl_client.status', '=', 'Active'],]) + ->whereNull('tbl_client.hei_no') + ->where('tbl_partner_facility.county_id', Auth::user()->county_id); + + $unknown_gender = Client::join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->where([['tbl_client.gender', '!=', '1'], ['tbl_client.gender', '!=', '2'], ['tbl_client.status', '=', 'Active'],]) + ->whereNull('tbl_client.hei_no') + ->where('tbl_partner_facility.county_id', Auth::user()->county_id); + + + $client_to_nine = Client::join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select(\DB::raw("count((case when (((year(curdate()) - year(CASE + WHEN ( locate( '/', `tbl_client`.`dob` ) > 0 ) THEN + date_format( str_to_date( `tbl_client`.`dob`, '%m/%d/%Y' ), '%Y-%m-%d' ) + WHEN ( locate( '-', `tbl_client`.`dob` ) > 0 ) THEN + date_format( str_to_date( `tbl_client`.`dob`, '%Y-%m-%d' ), '%Y-%m-%d' ) END)) > 0) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 9)) then `tbl_client`.`dob` end)) AS count")) + ->where('tbl_client.status', '=', 'Active') + ->whereNull('tbl_client.hei_no') + ->where('tbl_partner_facility.county_id', Auth::user()->county_id); + + + $client_to_fourteen = Client::join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select(\DB::raw("count((case when (((year(curdate()) - year(CASE + WHEN ( locate( '/', `tbl_client`.`dob` ) > 0 ) THEN + date_format( str_to_date( `tbl_client`.`dob`, '%m/%d/%Y' ), '%Y-%m-%d' ) + WHEN ( locate( '-', `tbl_client`.`dob` ) > 0 ) THEN + date_format( str_to_date( `tbl_client`.`dob`, '%Y-%m-%d' ), '%Y-%m-%d' ) END)) >= 10) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 14)) then `tbl_client`.`dob` end)) AS count")) + ->where('tbl_client.status', '=', 'Active') + ->whereNull('tbl_client.hei_no') + ->where('tbl_partner_facility.county_id', Auth::user()->county_id); + + + $client_to_nineteen = Client::join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select(\DB::raw("count((case when (((year(curdate()) - year(CASE + WHEN ( locate( '/', `tbl_client`.`dob` ) > 0 ) THEN + date_format( str_to_date( `tbl_client`.`dob`, '%m/%d/%Y' ), '%Y-%m-%d' ) + WHEN ( locate( '-', `tbl_client`.`dob` ) > 0 ) THEN + date_format( str_to_date( `tbl_client`.`dob`, '%Y-%m-%d' ), '%Y-%m-%d' ) END)) >= 15) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 19)) then `tbl_client`.`dob` end)) AS count")) + ->where('tbl_client.status', '=', 'Active') + ->whereNull('tbl_client.hei_no') + ->where('tbl_partner_facility.county_id', Auth::user()->county_id); + + $client_to_twentyfour = Client::join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select(\DB::raw("count((case when (((year(curdate()) - year(CASE + WHEN ( locate( '/', `tbl_client`.`dob` ) > 0 ) THEN + date_format( str_to_date( `tbl_client`.`dob`, '%m/%d/%Y' ), '%Y-%m-%d' ) + WHEN ( locate( '-', `tbl_client`.`dob` ) > 0 ) THEN + date_format( str_to_date( `tbl_client`.`dob`, '%Y-%m-%d' ), '%Y-%m-%d' ) END)) >= 20) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 24)) then `tbl_client`.`dob` end)) AS count")) + ->where('tbl_client.status', '=', 'Active') + ->whereNull('tbl_client.hei_no') + ->where('tbl_partner_facility.county_id', Auth::user()->county_id); + + $client_to_twentyfive_above = Client::join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select(\DB::raw("count((case when (((year(curdate()) - year(CASE + WHEN ( locate( '/', `tbl_client`.`dob` ) > 0 ) THEN + date_format( str_to_date( `tbl_client`.`dob`, '%m/%d/%Y' ), '%Y-%m-%d' ) + WHEN ( locate( '-', `tbl_client`.`dob` ) > 0 ) THEN + date_format( str_to_date( `tbl_client`.`dob`, '%Y-%m-%d' ), '%Y-%m-%d' ) END)) >= 25)) then `tbl_client`.`dob` end)) AS count")) + ->where('tbl_client.status', '=', 'Active') + ->whereNull('tbl_client.hei_no') + ->where('tbl_partner_facility.county_id', Auth::user()->county_id); + + + $client_unknown_age = Client::join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->where(\DB::raw("CASE + WHEN ( locate( '/', `tbl_client`.`dob` ) > 0 ) THEN + date_format( str_to_date( `tbl_client`.`dob`, '%m/%d/%Y' ), '%Y-%m-%d' ) + WHEN ( locate( '-', `tbl_client`.`dob` ) > 0 ) THEN + date_format( str_to_date( `tbl_client`.`dob`, '%Y-%m-%d' ), '%Y-%m-%d' ) END"), '=', '') + ->orWhereNull(\DB::raw("CASE + WHEN ( locate( '/', `tbl_client`.`dob` ) > 0 ) THEN + date_format( str_to_date( `tbl_client`.`dob`, '%m/%d/%Y' ), '%Y-%m-%d' ) + WHEN ( locate( '-', `tbl_client`.`dob` ) > 0 ) THEN + date_format( str_to_date( `tbl_client`.`dob`, '%Y-%m-%d' ), '%Y-%m-%d' ) END")) + ->where('tbl_client.status', '=', 'Active') + ->whereNull('tbl_client.hei_no') + ->where('tbl_partner_facility.county_id', Auth::user()->county_id); + } if (Auth::user()->access_level == 'Admin' || Auth::user()->access_level == 'Donor') { @@ -5504,22 +5710,24 @@ public function filter_client_charts(Request $request) ->where('tbl_client.smsenable', '!=', 'Yes') ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id); } - if (Auth::user()->access_level == 'Admin' || Auth::user()->access_level == 'Donor') { - + if (Auth::user()->access_level == 'Sub County') { $client = Client::join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') ->where('tbl_client.status', '=', 'Active') - ->whereNull('tbl_client.hei_no'); + ->whereNull('tbl_client.hei_no') + ->where('tbl_partner_facility.sub_county_id', Auth::user()->subcounty_id); $client_consented = Client::join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') ->select('tbl_client.id') ->where('tbl_client.status', '=', 'Active') ->whereNull('tbl_client.hei_no') - ->where('tbl_client.smsenable', '=', 'Yes'); + ->where('tbl_client.smsenable', '=', 'Yes') + ->where('tbl_partner_facility.sub_county_id', Auth::user()->subcounty_id); $client_nonconsented = Client::join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') ->select('tbl_client.id') ->where('tbl_client.status', '=', 'Active') ->whereNull('tbl_client.hei_no') - ->where('tbl_client.smsenable', '!=', 'Yes'); + ->where('tbl_client.smsenable', '!=', 'Yes') + ->where('tbl_partner_facility.sub_county_id', Auth::user()->subcounty_id); // consented clients by gender @@ -5527,39 +5735,45 @@ public function filter_client_charts(Request $request) ->where('tbl_client.smsenable', '=', 'Yes') ->where('tbl_client.status', '=', 'Active') ->whereNull('tbl_client.hei_no') - ->where('tbl_client.gender', '=', '2'); + ->where('tbl_client.gender', '=', '2') + ->where('tbl_partner_facility.sub_county_id', Auth::user()->subcounty_id); $client_consented_female = Client::join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') ->where('tbl_client.smsenable', '=', 'Yes') ->where('tbl_client.status', '=', 'Active') ->whereNull('tbl_client.hei_no') - ->where('tbl_client.gender', '=', '1'); + ->where('tbl_client.gender', '=', '1') + ->where('tbl_partner_facility.sub_county_id', Auth::user()->subcounty_id); $client_consented_uknown_gender = Client::join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') ->where('tbl_client.smsenable', '=', 'Yes') ->where('tbl_client.status', '=', 'Active') ->whereNull('tbl_client.hei_no') ->where('tbl_client.gender', '!=', '1') - ->where('tbl_client.gender', '!=', '2'); + ->where('tbl_client.gender', '!=', '2') + ->where('tbl_partner_facility.sub_county_id', Auth::user()->subcounty_id); // non consented clients by gender $client_nonconsented_male = Client::join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') ->where('tbl_client.smsenable', '!=', 'Yes') ->where('tbl_client.status', '=', 'Active') ->whereNull('tbl_client.hei_no') - ->where('tbl_client.gender', '=', '2'); + ->where('tbl_client.gender', '=', '2') + ->where('tbl_partner_facility.sub_county_id', Auth::user()->subcounty_id); $client_nonconsented_female = Client::join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') ->where('tbl_client.smsenable', '!=', 'Yes') ->where('tbl_client.status', '=', 'Active') ->whereNull('tbl_client.hei_no') - ->where('tbl_client.gender', '=', '1'); + ->where('tbl_client.gender', '=', '1') + ->where('tbl_partner_facility.sub_county_id', Auth::user()->subcounty_id); $client_nonconsented_uknown_gender = Client::join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') ->where('tbl_client.smsenable', '!=', 'Yes') ->where('tbl_client.gender', '!=', '1') - ->where('tbl_client.gender', '!=', '2'); + ->where('tbl_client.gender', '!=', '2') + ->where('tbl_partner_facility.sub_county_id', Auth::user()->subcounty_id); // consented clients by age distribution $client_consented_to_nine = Client::join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') @@ -5570,7 +5784,8 @@ public function filter_client_charts(Request $request) date_format( str_to_date( `tbl_client`.`dob`, '%Y-%m-%d' ), '%Y-%m-%d' ) END)) > 0) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 9)) then `tbl_client`.`dob` end)) AS count")) ->where('tbl_client.smsenable', '=', 'Yes') ->where('tbl_client.status', '=', 'Active') - ->whereNull('tbl_client.hei_no'); + ->whereNull('tbl_client.hei_no') + ->where('tbl_partner_facility.sub_county_id', Auth::user()->subcounty_id); $client_consented_to_fourteen = Client::join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') ->select(\DB::raw("count((case when (((year(curdate()) - year(CASE @@ -5580,7 +5795,8 @@ public function filter_client_charts(Request $request) date_format( str_to_date( `tbl_client`.`dob`, '%Y-%m-%d' ), '%Y-%m-%d' ) END)) >= 10) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 14)) then `tbl_client`.`dob` end)) AS count")) ->where('tbl_client.smsenable', '=', 'Yes') ->where('tbl_client.status', '=', 'Active') - ->whereNull('tbl_client.hei_no'); + ->whereNull('tbl_client.hei_no') + ->where('tbl_partner_facility.sub_county_id', Auth::user()->subcounty_id); $client_consented_to_nineteen = Client::join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') ->select(\DB::raw("count((case when (((year(curdate()) - year(CASE @@ -5590,7 +5806,8 @@ public function filter_client_charts(Request $request) date_format( str_to_date( `tbl_client`.`dob`, '%Y-%m-%d' ), '%Y-%m-%d' ) END)) >= 15) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 19)) then `tbl_client`.`dob` end)) AS count")) ->where('tbl_client.smsenable', '=', 'Yes') ->where('tbl_client.status', '=', 'Active') - ->whereNull('tbl_client.hei_no'); + ->whereNull('tbl_client.hei_no') + ->where('tbl_partner_facility.sub_county_id', Auth::user()->subcounty_id); $client_consented_to_twentyfour = Client::join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') ->select(\DB::raw("count((case when (((year(curdate()) - year(CASE @@ -5600,7 +5817,8 @@ public function filter_client_charts(Request $request) date_format( str_to_date( `tbl_client`.`dob`, '%Y-%m-%d' ), '%Y-%m-%d' ) END)) >= 20) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 24)) then `tbl_client`.`dob` end)) AS count")) ->where('tbl_client.smsenable', '=', 'Yes') ->where('tbl_client.status', '=', 'Active') - ->whereNull('tbl_client.hei_no'); + ->whereNull('tbl_client.hei_no') + ->where('tbl_partner_facility.sub_county_id', Auth::user()->subcounty_id); $client_consented_to_twentyfive_above = Client::join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') ->select(\DB::raw("count((case when (((year(curdate()) - year(CASE @@ -5610,12 +5828,11 @@ public function filter_client_charts(Request $request) date_format( str_to_date( `tbl_client`.`dob`, '%Y-%m-%d' ), '%Y-%m-%d' ) END)) >= 25)) then `tbl_client`.`dob` end)) AS count")) ->where('tbl_client.smsenable', '=', 'Yes') ->where('tbl_client.status', '=', 'Active') - ->whereNull('tbl_client.hei_no'); + ->whereNull('tbl_client.hei_no') + ->where('tbl_partner_facility.sub_county_id', Auth::user()->subcounty_id); $client_consented_uknown_age = Client::join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') ->select('tbl_client.smsenable') - ->where('tbl_client.status', '=', 'Active') - ->whereNull('tbl_client.hei_no') ->where(\DB::raw("CASE WHEN ( locate( '/', `tbl_client`.`dob` ) > 0 ) THEN date_format( str_to_date( `tbl_client`.`dob`, '%m/%d/%Y' ), '%Y-%m-%d' ) @@ -5626,7 +5843,10 @@ public function filter_client_charts(Request $request) date_format( str_to_date( `tbl_client`.`dob`, '%m/%d/%Y' ), '%Y-%m-%d' ) WHEN ( locate( '-', `tbl_client`.`dob` ) > 0 ) THEN date_format( str_to_date( `tbl_client`.`dob`, '%Y-%m-%d' ), '%Y-%m-%d' ) END")) - ->where('tbl_client.smsenable', '=', 'Yes'); + ->where('tbl_client.status', '=', 'Active') + ->whereNull('tbl_client.hei_no') + ->where('tbl_client.smsenable', '=', 'Yes') + ->where('tbl_partner_facility.sub_county_id', Auth::user()->subcounty_id); // non consented clients by age distribution $client_nonconsented_to_nine = Client::join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') @@ -5637,7 +5857,8 @@ public function filter_client_charts(Request $request) date_format( str_to_date( `tbl_client`.`dob`, '%Y-%m-%d' ), '%Y-%m-%d' ) END)) > 0) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 9)) then `tbl_client`.`dob` end)) AS count")) ->where('tbl_client.smsenable', '!=', 'Yes') ->where('tbl_client.status', '=', 'Active') - ->whereNull('tbl_client.hei_no'); + ->whereNull('tbl_client.hei_no') + ->where('tbl_partner_facility.sub_county_id', Auth::user()->subcounty_id); $client_nonconsented_to_fourteen = Client::join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') ->select(\DB::raw("count((case when (((year(curdate()) - year(CASE @@ -5647,7 +5868,8 @@ public function filter_client_charts(Request $request) date_format( str_to_date( `tbl_client`.`dob`, '%Y-%m-%d' ), '%Y-%m-%d' ) END)) >= 10) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 14)) then `tbl_client`.`dob` end)) AS count")) ->where('tbl_client.smsenable', '!=', 'Yes') ->where('tbl_client.status', '=', 'Active') - ->whereNull('tbl_client.hei_no'); + ->whereNull('tbl_client.hei_no') + ->where('tbl_partner_facility.sub_county_id', Auth::user()->subcounty_id); $client_nonconsented_to_nineteen = Client::join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') ->select(\DB::raw("count((case when (((year(curdate()) - year(CASE @@ -5657,7 +5879,8 @@ public function filter_client_charts(Request $request) date_format( str_to_date( `tbl_client`.`dob`, '%Y-%m-%d' ), '%Y-%m-%d' ) END)) >= 15) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 19)) then `tbl_client`.`dob` end)) AS count")) ->where('tbl_client.smsenable', '!=', 'Yes') ->where('tbl_client.status', '=', 'Active') - ->whereNull('tbl_client.hei_no'); + ->whereNull('tbl_client.hei_no') + ->where('tbl_partner_facility.sub_county_id', Auth::user()->subcounty_id); $client_nonconsented_to_twentyfour = Client::join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') ->select(\DB::raw("count((case when (((year(curdate()) - year(CASE @@ -5667,7 +5890,8 @@ public function filter_client_charts(Request $request) date_format( str_to_date( `tbl_client`.`dob`, '%Y-%m-%d' ), '%Y-%m-%d' ) END)) >= 20) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 24)) then `tbl_client`.`dob` end)) AS count")) ->where('tbl_client.smsenable', '!=', 'Yes') ->where('tbl_client.status', '=', 'Active') - ->whereNull('tbl_client.hei_no'); + ->whereNull('tbl_client.hei_no') + ->where('tbl_partner_facility.sub_county_id', Auth::user()->subcounty_id); $client_nonconsented_to_twentyfive_above = Client::join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') ->select(\DB::raw("count((case when (((year(curdate()) - year(CASE @@ -5677,7 +5901,8 @@ public function filter_client_charts(Request $request) date_format( str_to_date( `tbl_client`.`dob`, '%Y-%m-%d' ), '%Y-%m-%d' ) END)) >= 25)) then `tbl_client`.`dob` end)) AS count")) ->where('tbl_client.smsenable', '!=', 'Yes') ->where('tbl_client.status', '=', 'Active') - ->whereNull('tbl_client.hei_no'); + ->whereNull('tbl_client.hei_no') + ->where('tbl_partner_facility.sub_county_id', Auth::user()->subcounty_id); $client_nonconsented_uknown_age = Client::join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') ->select('tbl_client.smsenable') @@ -5693,27 +5918,430 @@ public function filter_client_charts(Request $request) date_format( str_to_date( `tbl_client`.`dob`, '%m/%d/%Y' ), '%Y-%m-%d' ) WHEN ( locate( '-', `tbl_client`.`dob` ) > 0 ) THEN date_format( str_to_date( `tbl_client`.`dob`, '%Y-%m-%d' ), '%Y-%m-%d' ) END")) - ->where('tbl_client.smsenable', '!=', 'Yes'); + ->where('tbl_client.smsenable', '!=', 'Yes') + ->where('tbl_partner_facility.sub_county_id', Auth::user()->subcounty_id); } + if (Auth::user()->access_level == 'County') { + $client = Client::join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->where('tbl_client.status', '=', 'Active') + ->whereNull('tbl_client.hei_no') + ->where('tbl_partner_facility.county_id', Auth::user()->county_id); + $client_consented = Client::join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select('tbl_client.id') + ->where('tbl_client.status', '=', 'Active') + ->whereNull('tbl_client.hei_no') + ->where('tbl_client.smsenable', '=', 'Yes') + ->where('tbl_partner_facility.county_id', Auth::user()->county_id); - if (!empty($selected_partners)) { - $client = $client->where('tbl_partner_facility.partner_id', $selected_partners); - $client_consented = $client_consented->where('tbl_partner_facility.partner_id', $selected_partners); - $client_nonconsented = $client_nonconsented->where('tbl_partner_facility.partner_id', $selected_partners); - $client_consented_male = $client_consented_male->where('tbl_partner_facility.partner_id', $selected_partners); - $client_consented_female = $client_consented_female->where('tbl_partner_facility.partner_id', $selected_partners); - $client_consented_uknown_gender = $client_consented_uknown_gender->where('tbl_partner_facility.partner_id', $selected_partners); - $client_nonconsented_male = $client_nonconsented_male->where('tbl_partner_facility.partner_id', $selected_partners); - $client_nonconsented_female = $client_nonconsented_female->where('tbl_partner_facility.partner_id', $selected_partners); - $client_nonconsented_uknown_gender = $client_nonconsented_uknown_gender->where('tbl_partner_facility.partner_id', $selected_partners); - $client_consented_to_nine = $client_consented_to_nine->where('tbl_partner_facility.partner_id', $selected_partners); - $client_consented_to_fourteen = $client_consented_to_fourteen->where('tbl_partner_facility.partner_id', $selected_partners); - $client_consented_to_nineteen = $client_consented_to_nineteen->where('tbl_partner_facility.partner_id', $selected_partners); - $client_consented_to_twentyfour = $client_consented_to_twentyfour->where('tbl_partner_facility.partner_id', $selected_partners); - $client_consented_to_twentyfive_above = $client_consented_to_twentyfive_above->where('tbl_partner_facility.partner_id', $selected_partners); - $client_consented_uknown_age = $client_consented_uknown_age->where('tbl_partner_facility.partner_id', $selected_partners); - $client_nonconsented_to_nine = $client_nonconsented_to_nine->where('tbl_partner_facility.partner_id', $selected_partners); - $client_nonconsented_to_fourteen = $client_nonconsented_to_fourteen->where('tbl_partner_facility.partner_id', $selected_partners); + $client_nonconsented = Client::join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select('tbl_client.id') + ->where('tbl_client.status', '=', 'Active') + ->whereNull('tbl_client.hei_no') + ->where('tbl_client.smsenable', '!=', 'Yes') + ->where('tbl_partner_facility.county_id', Auth::user()->county_id); + + // consented clients by gender + + $client_consented_male = Client::join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->where('tbl_client.smsenable', '=', 'Yes') + ->where('tbl_client.status', '=', 'Active') + ->whereNull('tbl_client.hei_no') + ->where('tbl_client.gender', '=', '2') + ->where('tbl_partner_facility.county_id', Auth::user()->county_id); + + $client_consented_female = Client::join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->where('tbl_client.smsenable', '=', 'Yes') + ->where('tbl_client.status', '=', 'Active') + ->whereNull('tbl_client.hei_no') + ->where('tbl_client.gender', '=', '1') + ->where('tbl_partner_facility.county_id', Auth::user()->county_id); + + $client_consented_uknown_gender = Client::join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->where('tbl_client.smsenable', '=', 'Yes') + ->where('tbl_client.status', '=', 'Active') + ->whereNull('tbl_client.hei_no') + ->where('tbl_client.gender', '!=', '1') + ->where('tbl_client.gender', '!=', '2') + ->where('tbl_partner_facility.county_id', Auth::user()->county_id); + + // non consented clients by gender + $client_nonconsented_male = Client::join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->where('tbl_client.smsenable', '!=', 'Yes') + ->where('tbl_client.status', '=', 'Active') + ->whereNull('tbl_client.hei_no') + ->where('tbl_client.gender', '=', '2') + ->where('tbl_partner_facility.county_id', Auth::user()->county_id); + + + $client_nonconsented_female = Client::join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->where('tbl_client.smsenable', '!=', 'Yes') + ->where('tbl_client.status', '=', 'Active') + ->whereNull('tbl_client.hei_no') + ->where('tbl_client.gender', '=', '1') + ->where('tbl_partner_facility.county_id', Auth::user()->county_id); + + $client_nonconsented_uknown_gender = Client::join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->where('tbl_client.smsenable', '!=', 'Yes') + ->where('tbl_client.gender', '!=', '1') + ->where('tbl_client.gender', '!=', '2') + ->where('tbl_partner_facility.county_id', Auth::user()->county_id); + + // consented clients by age distribution + $client_consented_to_nine = Client::join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select(\DB::raw("count((case when (((year(curdate()) - year(CASE + WHEN ( locate( '/', `tbl_client`.`dob` ) > 0 ) THEN + date_format( str_to_date( `tbl_client`.`dob`, '%m/%d/%Y' ), '%Y-%m-%d' ) + WHEN ( locate( '-', `tbl_client`.`dob` ) > 0 ) THEN + date_format( str_to_date( `tbl_client`.`dob`, '%Y-%m-%d' ), '%Y-%m-%d' ) END)) > 0) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 9)) then `tbl_client`.`dob` end)) AS count")) + ->where('tbl_client.smsenable', '=', 'Yes') + ->where('tbl_client.status', '=', 'Active') + ->whereNull('tbl_client.hei_no') + ->where('tbl_partner_facility.county_id', Auth::user()->county_id); + + $client_consented_to_fourteen = Client::join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select(\DB::raw("count((case when (((year(curdate()) - year(CASE + WHEN ( locate( '/', `tbl_client`.`dob` ) > 0 ) THEN + date_format( str_to_date( `tbl_client`.`dob`, '%m/%d/%Y' ), '%Y-%m-%d' ) + WHEN ( locate( '-', `tbl_client`.`dob` ) > 0 ) THEN + date_format( str_to_date( `tbl_client`.`dob`, '%Y-%m-%d' ), '%Y-%m-%d' ) END)) >= 10) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 14)) then `tbl_client`.`dob` end)) AS count")) + ->where('tbl_client.smsenable', '=', 'Yes') + ->where('tbl_client.status', '=', 'Active') + ->whereNull('tbl_client.hei_no') + ->where('tbl_partner_facility.county_id', Auth::user()->county_id); + + $client_consented_to_nineteen = Client::join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select(\DB::raw("count((case when (((year(curdate()) - year(CASE + WHEN ( locate( '/', `tbl_client`.`dob` ) > 0 ) THEN + date_format( str_to_date( `tbl_client`.`dob`, '%m/%d/%Y' ), '%Y-%m-%d' ) + WHEN ( locate( '-', `tbl_client`.`dob` ) > 0 ) THEN + date_format( str_to_date( `tbl_client`.`dob`, '%Y-%m-%d' ), '%Y-%m-%d' ) END)) >= 15) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 19)) then `tbl_client`.`dob` end)) AS count")) + ->where('tbl_client.smsenable', '=', 'Yes') + ->where('tbl_client.status', '=', 'Active') + ->whereNull('tbl_client.hei_no') + ->where('tbl_partner_facility.county_id', Auth::user()->county_id); + + $client_consented_to_twentyfour = Client::join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select(\DB::raw("count((case when (((year(curdate()) - year(CASE + WHEN ( locate( '/', `tbl_client`.`dob` ) > 0 ) THEN + date_format( str_to_date( `tbl_client`.`dob`, '%m/%d/%Y' ), '%Y-%m-%d' ) + WHEN ( locate( '-', `tbl_client`.`dob` ) > 0 ) THEN + date_format( str_to_date( `tbl_client`.`dob`, '%Y-%m-%d' ), '%Y-%m-%d' ) END)) >= 20) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 24)) then `tbl_client`.`dob` end)) AS count")) + ->where('tbl_client.smsenable', '=', 'Yes') + ->where('tbl_client.status', '=', 'Active') + ->whereNull('tbl_client.hei_no') + ->where('tbl_partner_facility.county_id', Auth::user()->county_id); + + $client_consented_to_twentyfive_above = Client::join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select(\DB::raw("count((case when (((year(curdate()) - year(CASE + WHEN ( locate( '/', `tbl_client`.`dob` ) > 0 ) THEN + date_format( str_to_date( `tbl_client`.`dob`, '%m/%d/%Y' ), '%Y-%m-%d' ) + WHEN ( locate( '-', `tbl_client`.`dob` ) > 0 ) THEN + date_format( str_to_date( `tbl_client`.`dob`, '%Y-%m-%d' ), '%Y-%m-%d' ) END)) >= 25)) then `tbl_client`.`dob` end)) AS count")) + ->where('tbl_client.smsenable', '=', 'Yes') + ->where('tbl_client.status', '=', 'Active') + ->whereNull('tbl_client.hei_no') + ->where('tbl_partner_facility.county_id', Auth::user()->county_id); + + $client_consented_uknown_age = Client::join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select('tbl_client.smsenable') + ->where(\DB::raw("CASE + WHEN ( locate( '/', `tbl_client`.`dob` ) > 0 ) THEN + date_format( str_to_date( `tbl_client`.`dob`, '%m/%d/%Y' ), '%Y-%m-%d' ) + WHEN ( locate( '-', `tbl_client`.`dob` ) > 0 ) THEN + date_format( str_to_date( `tbl_client`.`dob`, '%Y-%m-%d' ), '%Y-%m-%d' ) END"), '=', '') + ->orWhereNull(\DB::raw("CASE + WHEN ( locate( '/', `tbl_client`.`dob` ) > 0 ) THEN + date_format( str_to_date( `tbl_client`.`dob`, '%m/%d/%Y' ), '%Y-%m-%d' ) + WHEN ( locate( '-', `tbl_client`.`dob` ) > 0 ) THEN + date_format( str_to_date( `tbl_client`.`dob`, '%Y-%m-%d' ), '%Y-%m-%d' ) END")) + ->where('tbl_client.status', '=', 'Active') + ->whereNull('tbl_client.hei_no') + ->where('tbl_client.smsenable', '=', 'Yes') + ->where('tbl_partner_facility.county_id', Auth::user()->county_id); + + // non consented clients by age distribution + $client_nonconsented_to_nine = Client::join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select(\DB::raw("count((case when (((year(curdate()) - year(CASE + WHEN ( locate( '/', `tbl_client`.`dob` ) > 0 ) THEN + date_format( str_to_date( `tbl_client`.`dob`, '%m/%d/%Y' ), '%Y-%m-%d' ) + WHEN ( locate( '-', `tbl_client`.`dob` ) > 0 ) THEN + date_format( str_to_date( `tbl_client`.`dob`, '%Y-%m-%d' ), '%Y-%m-%d' ) END)) > 0) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 9)) then `tbl_client`.`dob` end)) AS count")) + ->where('tbl_client.smsenable', '!=', 'Yes') + ->where('tbl_client.status', '=', 'Active') + ->whereNull('tbl_client.hei_no') + ->where('tbl_partner_facility.county_id', Auth::user()->county_id); + + $client_nonconsented_to_fourteen = Client::join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select(\DB::raw("count((case when (((year(curdate()) - year(CASE + WHEN ( locate( '/', `tbl_client`.`dob` ) > 0 ) THEN + date_format( str_to_date( `tbl_client`.`dob`, '%m/%d/%Y' ), '%Y-%m-%d' ) + WHEN ( locate( '-', `tbl_client`.`dob` ) > 0 ) THEN + date_format( str_to_date( `tbl_client`.`dob`, '%Y-%m-%d' ), '%Y-%m-%d' ) END)) >= 10) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 14)) then `tbl_client`.`dob` end)) AS count")) + ->where('tbl_client.smsenable', '!=', 'Yes') + ->where('tbl_client.status', '=', 'Active') + ->whereNull('tbl_client.hei_no') + ->where('tbl_partner_facility.county_id', Auth::user()->county_id); + + $client_nonconsented_to_nineteen = Client::join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select(\DB::raw("count((case when (((year(curdate()) - year(CASE + WHEN ( locate( '/', `tbl_client`.`dob` ) > 0 ) THEN + date_format( str_to_date( `tbl_client`.`dob`, '%m/%d/%Y' ), '%Y-%m-%d' ) + WHEN ( locate( '-', `tbl_client`.`dob` ) > 0 ) THEN + date_format( str_to_date( `tbl_client`.`dob`, '%Y-%m-%d' ), '%Y-%m-%d' ) END)) >= 15) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 19)) then `tbl_client`.`dob` end)) AS count")) + ->where('tbl_client.smsenable', '!=', 'Yes') + ->where('tbl_client.status', '=', 'Active') + ->whereNull('tbl_client.hei_no') + ->where('tbl_partner_facility.county_id', Auth::user()->county_id); + + $client_nonconsented_to_twentyfour = Client::join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select(\DB::raw("count((case when (((year(curdate()) - year(CASE + WHEN ( locate( '/', `tbl_client`.`dob` ) > 0 ) THEN + date_format( str_to_date( `tbl_client`.`dob`, '%m/%d/%Y' ), '%Y-%m-%d' ) + WHEN ( locate( '-', `tbl_client`.`dob` ) > 0 ) THEN + date_format( str_to_date( `tbl_client`.`dob`, '%Y-%m-%d' ), '%Y-%m-%d' ) END)) >= 20) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 24)) then `tbl_client`.`dob` end)) AS count")) + ->where('tbl_client.smsenable', '!=', 'Yes') + ->where('tbl_client.status', '=', 'Active') + ->whereNull('tbl_client.hei_no') + ->where('tbl_partner_facility.county_id', Auth::user()->county_id); + + $client_nonconsented_to_twentyfive_above = Client::join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select(\DB::raw("count((case when (((year(curdate()) - year(CASE + WHEN ( locate( '/', `tbl_client`.`dob` ) > 0 ) THEN + date_format( str_to_date( `tbl_client`.`dob`, '%m/%d/%Y' ), '%Y-%m-%d' ) + WHEN ( locate( '-', `tbl_client`.`dob` ) > 0 ) THEN + date_format( str_to_date( `tbl_client`.`dob`, '%Y-%m-%d' ), '%Y-%m-%d' ) END)) >= 25)) then `tbl_client`.`dob` end)) AS count")) + ->where('tbl_client.smsenable', '!=', 'Yes') + ->where('tbl_client.status', '=', 'Active') + ->whereNull('tbl_client.hei_no') + ->where('tbl_partner_facility.county_id', Auth::user()->county_id); + + $client_nonconsented_uknown_age = Client::join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select('tbl_client.smsenable') + ->where('tbl_client.status', '=', 'Active') + ->whereNull('tbl_client.hei_no') + ->where(\DB::raw("CASE + WHEN ( locate( '/', `tbl_client`.`dob` ) > 0 ) THEN + date_format( str_to_date( `tbl_client`.`dob`, '%m/%d/%Y' ), '%Y-%m-%d' ) + WHEN ( locate( '-', `tbl_client`.`dob` ) > 0 ) THEN + date_format( str_to_date( `tbl_client`.`dob`, '%Y-%m-%d' ), '%Y-%m-%d' ) END"), '=', '') + ->orWhereNull(\DB::raw("CASE + WHEN ( locate( '/', `tbl_client`.`dob` ) > 0 ) THEN + date_format( str_to_date( `tbl_client`.`dob`, '%m/%d/%Y' ), '%Y-%m-%d' ) + WHEN ( locate( '-', `tbl_client`.`dob` ) > 0 ) THEN + date_format( str_to_date( `tbl_client`.`dob`, '%Y-%m-%d' ), '%Y-%m-%d' ) END")) + ->where('tbl_client.smsenable', '!=', 'Yes') + ->where('tbl_partner_facility.county_id', Auth::user()->county_id); + } + if (Auth::user()->access_level == 'Admin' || Auth::user()->access_level == 'Donor') { + + $client = Client::join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->where('tbl_client.status', '=', 'Active') + ->whereNull('tbl_client.hei_no'); + $client_consented = Client::join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select('tbl_client.id') + ->where('tbl_client.status', '=', 'Active') + ->whereNull('tbl_client.hei_no') + ->where('tbl_client.smsenable', '=', 'Yes'); + + $client_nonconsented = Client::join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select('tbl_client.id') + ->where('tbl_client.status', '=', 'Active') + ->whereNull('tbl_client.hei_no') + ->where('tbl_client.smsenable', '!=', 'Yes'); + + // consented clients by gender + + $client_consented_male = Client::join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->where('tbl_client.smsenable', '=', 'Yes') + ->where('tbl_client.status', '=', 'Active') + ->whereNull('tbl_client.hei_no') + ->where('tbl_client.gender', '=', '2'); + + $client_consented_female = Client::join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->where('tbl_client.smsenable', '=', 'Yes') + ->where('tbl_client.status', '=', 'Active') + ->whereNull('tbl_client.hei_no') + ->where('tbl_client.gender', '=', '1'); + + $client_consented_uknown_gender = Client::join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->where('tbl_client.smsenable', '=', 'Yes') + ->where('tbl_client.status', '=', 'Active') + ->whereNull('tbl_client.hei_no') + ->where('tbl_client.gender', '!=', '1') + ->where('tbl_client.gender', '!=', '2'); + + // non consented clients by gender + $client_nonconsented_male = Client::join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->where('tbl_client.smsenable', '!=', 'Yes') + ->where('tbl_client.status', '=', 'Active') + ->whereNull('tbl_client.hei_no') + ->where('tbl_client.gender', '=', '2'); + + + $client_nonconsented_female = Client::join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->where('tbl_client.smsenable', '!=', 'Yes') + ->where('tbl_client.status', '=', 'Active') + ->whereNull('tbl_client.hei_no') + ->where('tbl_client.gender', '=', '1'); + + $client_nonconsented_uknown_gender = Client::join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->where('tbl_client.smsenable', '!=', 'Yes') + ->where('tbl_client.gender', '!=', '1') + ->where('tbl_client.gender', '!=', '2'); + + // consented clients by age distribution + $client_consented_to_nine = Client::join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select(\DB::raw("count((case when (((year(curdate()) - year(CASE + WHEN ( locate( '/', `tbl_client`.`dob` ) > 0 ) THEN + date_format( str_to_date( `tbl_client`.`dob`, '%m/%d/%Y' ), '%Y-%m-%d' ) + WHEN ( locate( '-', `tbl_client`.`dob` ) > 0 ) THEN + date_format( str_to_date( `tbl_client`.`dob`, '%Y-%m-%d' ), '%Y-%m-%d' ) END)) > 0) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 9)) then `tbl_client`.`dob` end)) AS count")) + ->where('tbl_client.smsenable', '=', 'Yes') + ->where('tbl_client.status', '=', 'Active') + ->whereNull('tbl_client.hei_no'); + + $client_consented_to_fourteen = Client::join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select(\DB::raw("count((case when (((year(curdate()) - year(CASE + WHEN ( locate( '/', `tbl_client`.`dob` ) > 0 ) THEN + date_format( str_to_date( `tbl_client`.`dob`, '%m/%d/%Y' ), '%Y-%m-%d' ) + WHEN ( locate( '-', `tbl_client`.`dob` ) > 0 ) THEN + date_format( str_to_date( `tbl_client`.`dob`, '%Y-%m-%d' ), '%Y-%m-%d' ) END)) >= 10) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 14)) then `tbl_client`.`dob` end)) AS count")) + ->where('tbl_client.smsenable', '=', 'Yes') + ->where('tbl_client.status', '=', 'Active') + ->whereNull('tbl_client.hei_no'); + + $client_consented_to_nineteen = Client::join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select(\DB::raw("count((case when (((year(curdate()) - year(CASE + WHEN ( locate( '/', `tbl_client`.`dob` ) > 0 ) THEN + date_format( str_to_date( `tbl_client`.`dob`, '%m/%d/%Y' ), '%Y-%m-%d' ) + WHEN ( locate( '-', `tbl_client`.`dob` ) > 0 ) THEN + date_format( str_to_date( `tbl_client`.`dob`, '%Y-%m-%d' ), '%Y-%m-%d' ) END)) >= 15) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 19)) then `tbl_client`.`dob` end)) AS count")) + ->where('tbl_client.smsenable', '=', 'Yes') + ->where('tbl_client.status', '=', 'Active') + ->whereNull('tbl_client.hei_no'); + + $client_consented_to_twentyfour = Client::join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select(\DB::raw("count((case when (((year(curdate()) - year(CASE + WHEN ( locate( '/', `tbl_client`.`dob` ) > 0 ) THEN + date_format( str_to_date( `tbl_client`.`dob`, '%m/%d/%Y' ), '%Y-%m-%d' ) + WHEN ( locate( '-', `tbl_client`.`dob` ) > 0 ) THEN + date_format( str_to_date( `tbl_client`.`dob`, '%Y-%m-%d' ), '%Y-%m-%d' ) END)) >= 20) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 24)) then `tbl_client`.`dob` end)) AS count")) + ->where('tbl_client.smsenable', '=', 'Yes') + ->where('tbl_client.status', '=', 'Active') + ->whereNull('tbl_client.hei_no'); + + $client_consented_to_twentyfive_above = Client::join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select(\DB::raw("count((case when (((year(curdate()) - year(CASE + WHEN ( locate( '/', `tbl_client`.`dob` ) > 0 ) THEN + date_format( str_to_date( `tbl_client`.`dob`, '%m/%d/%Y' ), '%Y-%m-%d' ) + WHEN ( locate( '-', `tbl_client`.`dob` ) > 0 ) THEN + date_format( str_to_date( `tbl_client`.`dob`, '%Y-%m-%d' ), '%Y-%m-%d' ) END)) >= 25)) then `tbl_client`.`dob` end)) AS count")) + ->where('tbl_client.smsenable', '=', 'Yes') + ->where('tbl_client.status', '=', 'Active') + ->whereNull('tbl_client.hei_no'); + + $client_consented_uknown_age = Client::join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select('tbl_client.smsenable') + ->where('tbl_client.status', '=', 'Active') + ->whereNull('tbl_client.hei_no') + ->where(\DB::raw("CASE + WHEN ( locate( '/', `tbl_client`.`dob` ) > 0 ) THEN + date_format( str_to_date( `tbl_client`.`dob`, '%m/%d/%Y' ), '%Y-%m-%d' ) + WHEN ( locate( '-', `tbl_client`.`dob` ) > 0 ) THEN + date_format( str_to_date( `tbl_client`.`dob`, '%Y-%m-%d' ), '%Y-%m-%d' ) END"), '=', '') + ->orWhereNull(\DB::raw("CASE + WHEN ( locate( '/', `tbl_client`.`dob` ) > 0 ) THEN + date_format( str_to_date( `tbl_client`.`dob`, '%m/%d/%Y' ), '%Y-%m-%d' ) + WHEN ( locate( '-', `tbl_client`.`dob` ) > 0 ) THEN + date_format( str_to_date( `tbl_client`.`dob`, '%Y-%m-%d' ), '%Y-%m-%d' ) END")) + ->where('tbl_client.smsenable', '=', 'Yes'); + + // non consented clients by age distribution + $client_nonconsented_to_nine = Client::join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select(\DB::raw("count((case when (((year(curdate()) - year(CASE + WHEN ( locate( '/', `tbl_client`.`dob` ) > 0 ) THEN + date_format( str_to_date( `tbl_client`.`dob`, '%m/%d/%Y' ), '%Y-%m-%d' ) + WHEN ( locate( '-', `tbl_client`.`dob` ) > 0 ) THEN + date_format( str_to_date( `tbl_client`.`dob`, '%Y-%m-%d' ), '%Y-%m-%d' ) END)) > 0) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 9)) then `tbl_client`.`dob` end)) AS count")) + ->where('tbl_client.smsenable', '!=', 'Yes') + ->where('tbl_client.status', '=', 'Active') + ->whereNull('tbl_client.hei_no'); + + $client_nonconsented_to_fourteen = Client::join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select(\DB::raw("count((case when (((year(curdate()) - year(CASE + WHEN ( locate( '/', `tbl_client`.`dob` ) > 0 ) THEN + date_format( str_to_date( `tbl_client`.`dob`, '%m/%d/%Y' ), '%Y-%m-%d' ) + WHEN ( locate( '-', `tbl_client`.`dob` ) > 0 ) THEN + date_format( str_to_date( `tbl_client`.`dob`, '%Y-%m-%d' ), '%Y-%m-%d' ) END)) >= 10) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 14)) then `tbl_client`.`dob` end)) AS count")) + ->where('tbl_client.smsenable', '!=', 'Yes') + ->where('tbl_client.status', '=', 'Active') + ->whereNull('tbl_client.hei_no'); + + $client_nonconsented_to_nineteen = Client::join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select(\DB::raw("count((case when (((year(curdate()) - year(CASE + WHEN ( locate( '/', `tbl_client`.`dob` ) > 0 ) THEN + date_format( str_to_date( `tbl_client`.`dob`, '%m/%d/%Y' ), '%Y-%m-%d' ) + WHEN ( locate( '-', `tbl_client`.`dob` ) > 0 ) THEN + date_format( str_to_date( `tbl_client`.`dob`, '%Y-%m-%d' ), '%Y-%m-%d' ) END)) >= 15) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 19)) then `tbl_client`.`dob` end)) AS count")) + ->where('tbl_client.smsenable', '!=', 'Yes') + ->where('tbl_client.status', '=', 'Active') + ->whereNull('tbl_client.hei_no'); + + $client_nonconsented_to_twentyfour = Client::join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select(\DB::raw("count((case when (((year(curdate()) - year(CASE + WHEN ( locate( '/', `tbl_client`.`dob` ) > 0 ) THEN + date_format( str_to_date( `tbl_client`.`dob`, '%m/%d/%Y' ), '%Y-%m-%d' ) + WHEN ( locate( '-', `tbl_client`.`dob` ) > 0 ) THEN + date_format( str_to_date( `tbl_client`.`dob`, '%Y-%m-%d' ), '%Y-%m-%d' ) END)) >= 20) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 24)) then `tbl_client`.`dob` end)) AS count")) + ->where('tbl_client.smsenable', '!=', 'Yes') + ->where('tbl_client.status', '=', 'Active') + ->whereNull('tbl_client.hei_no'); + + $client_nonconsented_to_twentyfive_above = Client::join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select(\DB::raw("count((case when (((year(curdate()) - year(CASE + WHEN ( locate( '/', `tbl_client`.`dob` ) > 0 ) THEN + date_format( str_to_date( `tbl_client`.`dob`, '%m/%d/%Y' ), '%Y-%m-%d' ) + WHEN ( locate( '-', `tbl_client`.`dob` ) > 0 ) THEN + date_format( str_to_date( `tbl_client`.`dob`, '%Y-%m-%d' ), '%Y-%m-%d' ) END)) >= 25)) then `tbl_client`.`dob` end)) AS count")) + ->where('tbl_client.smsenable', '!=', 'Yes') + ->where('tbl_client.status', '=', 'Active') + ->whereNull('tbl_client.hei_no'); + + $client_nonconsented_uknown_age = Client::join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select('tbl_client.smsenable') + ->where('tbl_client.status', '=', 'Active') + ->whereNull('tbl_client.hei_no') + ->where(\DB::raw("CASE + WHEN ( locate( '/', `tbl_client`.`dob` ) > 0 ) THEN + date_format( str_to_date( `tbl_client`.`dob`, '%m/%d/%Y' ), '%Y-%m-%d' ) + WHEN ( locate( '-', `tbl_client`.`dob` ) > 0 ) THEN + date_format( str_to_date( `tbl_client`.`dob`, '%Y-%m-%d' ), '%Y-%m-%d' ) END"), '=', '') + ->orWhereNull(\DB::raw("CASE + WHEN ( locate( '/', `tbl_client`.`dob` ) > 0 ) THEN + date_format( str_to_date( `tbl_client`.`dob`, '%m/%d/%Y' ), '%Y-%m-%d' ) + WHEN ( locate( '-', `tbl_client`.`dob` ) > 0 ) THEN + date_format( str_to_date( `tbl_client`.`dob`, '%Y-%m-%d' ), '%Y-%m-%d' ) END")) + ->where('tbl_client.smsenable', '!=', 'Yes'); + } + + if (!empty($selected_partners)) { + $client = $client->where('tbl_partner_facility.partner_id', $selected_partners); + $client_consented = $client_consented->where('tbl_partner_facility.partner_id', $selected_partners); + $client_nonconsented = $client_nonconsented->where('tbl_partner_facility.partner_id', $selected_partners); + $client_consented_male = $client_consented_male->where('tbl_partner_facility.partner_id', $selected_partners); + $client_consented_female = $client_consented_female->where('tbl_partner_facility.partner_id', $selected_partners); + $client_consented_uknown_gender = $client_consented_uknown_gender->where('tbl_partner_facility.partner_id', $selected_partners); + $client_nonconsented_male = $client_nonconsented_male->where('tbl_partner_facility.partner_id', $selected_partners); + $client_nonconsented_female = $client_nonconsented_female->where('tbl_partner_facility.partner_id', $selected_partners); + $client_nonconsented_uknown_gender = $client_nonconsented_uknown_gender->where('tbl_partner_facility.partner_id', $selected_partners); + $client_consented_to_nine = $client_consented_to_nine->where('tbl_partner_facility.partner_id', $selected_partners); + $client_consented_to_fourteen = $client_consented_to_fourteen->where('tbl_partner_facility.partner_id', $selected_partners); + $client_consented_to_nineteen = $client_consented_to_nineteen->where('tbl_partner_facility.partner_id', $selected_partners); + $client_consented_to_twentyfour = $client_consented_to_twentyfour->where('tbl_partner_facility.partner_id', $selected_partners); + $client_consented_to_twentyfive_above = $client_consented_to_twentyfive_above->where('tbl_partner_facility.partner_id', $selected_partners); + $client_consented_uknown_age = $client_consented_uknown_age->where('tbl_partner_facility.partner_id', $selected_partners); + $client_nonconsented_to_nine = $client_nonconsented_to_nine->where('tbl_partner_facility.partner_id', $selected_partners); + $client_nonconsented_to_fourteen = $client_nonconsented_to_fourteen->where('tbl_partner_facility.partner_id', $selected_partners); $client_nonconsented_to_nineteen = $client_nonconsented_to_nineteen->where('tbl_partner_facility.partner_id', $selected_partners); $client_nonconsented_to_twentyfour = $client_nonconsented_to_twentyfour->where('tbl_partner_facility.partner_id', $selected_partners); $client_nonconsented_to_twentyfive_above = $client_nonconsented_to_twentyfive_above->where('tbl_partner_facility.partner_id', $selected_partners); @@ -5834,100 +6462,654 @@ public function filter_client_charts(Request $request) $client_nonconsented_to_twentyfive_above = $client_nonconsented_to_twentyfive_above->join('tbl_dfc_module', 'tbl_client.id', '=', 'tbl_dfc_module.client_id'); $client_nonconsented_uknown_age = $client_nonconsented_uknown_age->join('tbl_dfc_module', 'tbl_client.id', '=', 'tbl_dfc_module.client_id'); } - if (!empty($selected_module == 'PMTCT')) { - $client = $client->join('tbl_pmtct', 'tbl_client.id', '=', 'tbl_pmtct.client_id'); - $client_consented = $client_consented->join('tbl_pmtct', 'tbl_client.id', '=', 'tbl_pmtct.client_id'); - $client_nonconsented = $client_nonconsented->join('tbl_pmtct', 'tbl_client.id', '=', 'tbl_pmtct.client_id'); - $client_consented_male = $client_consented_male->join('tbl_pmtct', 'tbl_client.id', '=', 'tbl_pmtct.client_id'); - $client_consented_female = $client_consented_female->join('tbl_pmtct', 'tbl_client.id', '=', 'tbl_pmtct.client_id'); - $client_consented_uknown_gender = $client_consented_uknown_gender->join('tbl_pmtct', 'tbl_client.id', '=', 'tbl_pmtct.client_id'); - $client_nonconsented_male = $client_nonconsented_male->join('tbl_pmtct', 'tbl_client.id', '=', 'tbl_pmtct.client_id'); - $client_nonconsented_female = $client_nonconsented_female->join('tbl_pmtct', 'tbl_client.id', '=', 'tbl_pmtct.client_id'); - $client_nonconsented_uknown_gender = $client_nonconsented_uknown_gender->join('tbl_pmtct', 'tbl_client.id', '=', 'tbl_pmtct.client_id'); - $client_consented_to_nine = $client_consented_to_nine->join('tbl_pmtct', 'tbl_client.id', '=', 'tbl_pmtct.client_id'); - $client_consented_to_fourteen = $client_consented_to_fourteen->join('tbl_pmtct', 'tbl_client.id', '=', 'tbl_pmtct.client_id'); - $client_consented_to_nineteen = $client_consented_to_nineteen->join('tbl_pmtct', 'tbl_client.id', '=', 'tbl_pmtct.client_id'); - $client_consented_to_twentyfour = $client_consented_to_twentyfour->join('tbl_pmtct', 'tbl_client.id', '=', 'tbl_pmtct.client_id'); - $client_consented_to_twentyfive_above = $client_consented_to_twentyfive_above->join('tbl_pmtct', 'tbl_client.id', '=', 'tbl_pmtct.client_id'); - $client_consented_uknown_age = $client_consented_uknown_age->join('tbl_pmtct', 'tbl_client.id', '=', 'tbl_pmtct.client_id'); - $client_nonconsented_to_nine = $client_nonconsented_to_nine->join('tbl_pmtct', 'tbl_client.id', '=', 'tbl_pmtct.client_id'); - $client_nonconsented_to_fourteen = $client_nonconsented_to_fourteen->join('tbl_pmtct', 'tbl_client.id', '=', 'tbl_pmtct.client_id'); - $client_nonconsented_to_nineteen = $client_nonconsented_to_nineteen->join('tbl_pmtct', 'tbl_client.id', '=', 'tbl_pmtct.client_id'); - $client_nonconsented_to_twentyfour = $client_nonconsented_to_twentyfour->join('tbl_pmtct', 'tbl_client.id', '=', 'tbl_pmtct.client_id'); - $client_nonconsented_to_twentyfive_above = $client_nonconsented_to_twentyfive_above->join('tbl_pmtct', 'tbl_client.id', '=', 'tbl_pmtct.client_id'); - $client_nonconsented_uknown_age = $client_nonconsented_uknown_age->join('tbl_pmtct', 'tbl_client.id', '=', 'tbl_pmtct.client_id'); + if (!empty($selected_module == 'PMTCT')) { + $client = $client->join('tbl_pmtct', 'tbl_client.id', '=', 'tbl_pmtct.client_id'); + $client_consented = $client_consented->join('tbl_pmtct', 'tbl_client.id', '=', 'tbl_pmtct.client_id'); + $client_nonconsented = $client_nonconsented->join('tbl_pmtct', 'tbl_client.id', '=', 'tbl_pmtct.client_id'); + $client_consented_male = $client_consented_male->join('tbl_pmtct', 'tbl_client.id', '=', 'tbl_pmtct.client_id'); + $client_consented_female = $client_consented_female->join('tbl_pmtct', 'tbl_client.id', '=', 'tbl_pmtct.client_id'); + $client_consented_uknown_gender = $client_consented_uknown_gender->join('tbl_pmtct', 'tbl_client.id', '=', 'tbl_pmtct.client_id'); + $client_nonconsented_male = $client_nonconsented_male->join('tbl_pmtct', 'tbl_client.id', '=', 'tbl_pmtct.client_id'); + $client_nonconsented_female = $client_nonconsented_female->join('tbl_pmtct', 'tbl_client.id', '=', 'tbl_pmtct.client_id'); + $client_nonconsented_uknown_gender = $client_nonconsented_uknown_gender->join('tbl_pmtct', 'tbl_client.id', '=', 'tbl_pmtct.client_id'); + $client_consented_to_nine = $client_consented_to_nine->join('tbl_pmtct', 'tbl_client.id', '=', 'tbl_pmtct.client_id'); + $client_consented_to_fourteen = $client_consented_to_fourteen->join('tbl_pmtct', 'tbl_client.id', '=', 'tbl_pmtct.client_id'); + $client_consented_to_nineteen = $client_consented_to_nineteen->join('tbl_pmtct', 'tbl_client.id', '=', 'tbl_pmtct.client_id'); + $client_consented_to_twentyfour = $client_consented_to_twentyfour->join('tbl_pmtct', 'tbl_client.id', '=', 'tbl_pmtct.client_id'); + $client_consented_to_twentyfive_above = $client_consented_to_twentyfive_above->join('tbl_pmtct', 'tbl_client.id', '=', 'tbl_pmtct.client_id'); + $client_consented_uknown_age = $client_consented_uknown_age->join('tbl_pmtct', 'tbl_client.id', '=', 'tbl_pmtct.client_id'); + $client_nonconsented_to_nine = $client_nonconsented_to_nine->join('tbl_pmtct', 'tbl_client.id', '=', 'tbl_pmtct.client_id'); + $client_nonconsented_to_fourteen = $client_nonconsented_to_fourteen->join('tbl_pmtct', 'tbl_client.id', '=', 'tbl_pmtct.client_id'); + $client_nonconsented_to_nineteen = $client_nonconsented_to_nineteen->join('tbl_pmtct', 'tbl_client.id', '=', 'tbl_pmtct.client_id'); + $client_nonconsented_to_twentyfour = $client_nonconsented_to_twentyfour->join('tbl_pmtct', 'tbl_client.id', '=', 'tbl_pmtct.client_id'); + $client_nonconsented_to_twentyfive_above = $client_nonconsented_to_twentyfive_above->join('tbl_pmtct', 'tbl_client.id', '=', 'tbl_pmtct.client_id'); + $client_nonconsented_uknown_age = $client_nonconsented_uknown_age->join('tbl_pmtct', 'tbl_client.id', '=', 'tbl_pmtct.client_id'); + } + + + $data["client"] = $client->count(); + $data["client_consented"] = $client_consented->count(); + $data["client_nonconsented"] = $client_nonconsented->count(); + $data["client_consented_male"] = $client_consented_male->count(); + $data["client_consented_female"] = $client_consented_female->count(); + $data["client_consented_uknown_gender"] = $client_consented_uknown_gender->count(); + $data["client_nonconsented_male"] = $client_nonconsented_male->count(); + $data["client_nonconsented_female"] = $client_nonconsented_female->count(); + $data["client_nonconsented_uknown_gender"] = $client_nonconsented_uknown_gender->count(); + $data["client_consented_to_nine"] = $client_consented_to_nine->pluck('count'); + $data["client_consented_to_fourteen"] = $client_consented_to_fourteen->pluck('count'); + $data["client_consented_to_nineteen"] = $client_consented_to_nineteen->pluck('count'); + $data["client_consented_to_twentyfour"] = $client_consented_to_twentyfour->pluck('count'); + $data["client_consented_to_twentyfive_above"] = $client_consented_to_twentyfive_above->pluck('count'); + $data["client_consented_uknown_age"] = $client_consented_uknown_age->count(); + $data["client_nonconsented_to_nine"] = $client_nonconsented_to_nine->pluck('count'); + $data["client_nonconsented_to_fourteen"] = $client_nonconsented_to_fourteen->pluck('count'); + $data["client_nonconsented_to_nineteen"] = $client_nonconsented_to_nineteen->pluck('count'); + $data["client_nonconsented_to_twentyfour"] = $client_nonconsented_to_twentyfour->pluck('count'); + $data["client_nonconsented_to_twentyfive_above"] = $client_nonconsented_to_twentyfive_above->pluck('count'); + $data["client_nonconsented_uknown_age"] = $client_nonconsented_uknown_age->count(); + + return $data; + } + public function filter_appointment_charts(Request $request) + { + $data = []; + // client charts + $selected_partners = $request->partners; + $selected_counties = $request->counties; + $selected_subcounties = $request->subcounties; + $selected_facilites = $request->facilities; + $selected_from = $request->from; + $selected_to = $request->to; + $selected_module = $request->module; + + if (Auth::user()->access_level == 'Facility') { + $appointment = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select('tbl_appointment.id') + ->where('tbl_client.mfl_code', Auth::user()->facility_id); + $appointment_honoured = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select('tbl_appointment.id') + ->where('tbl_appointment.date_attended', '=', DB::raw('tbl_appointment.appntmnt_date')) + ->where('tbl_client.mfl_code', Auth::user()->facility_id); + $appointment_not_honoured = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select('tbl_appointment.id') + ->whereIn('tbl_appointment.app_status', ['Defaulted', 'LTFU', 'Missed']) + ->where('tbl_client.mfl_code', Auth::user()->facility_id); + // appointment honored by gender + $appointment_honoured_male = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select('tbl_appointment.id') + ->where('tbl_appointment.date_attended', '=', DB::raw('tbl_appointment.appntmnt_date')) + ->where('tbl_client.gender', '=', '2') + ->where('tbl_client.mfl_code', Auth::user()->facility_id); + $appointment_honoured_female = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->where('tbl_appointment.date_attended', '=', DB::raw('tbl_appointment.appntmnt_date')) + ->where('tbl_client.gender', '=', '1') + ->where('tbl_client.mfl_code', Auth::user()->facility_id); + $appointment_honoured_uknown_gender = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->where('tbl_appointment.date_attended', '=', DB::raw('tbl_appointment.appntmnt_date')) + ->where('tbl_client.gender', '!=', '1') + ->where('tbl_client.gender', '!=', '2') + ->where('tbl_client.mfl_code', Auth::user()->facility_id); + // appointment honored by age + $appointment_honored_to_nine = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select(\DB::raw("count((case when (((year(curdate()) - year(CASE + WHEN ( locate( '/', `tbl_client`.`dob` ) > 0 ) THEN + date_format( str_to_date( `tbl_client`.`dob`, '%m/%d/%Y' ), '%Y-%m-%d' ) + WHEN ( locate( '-', `tbl_client`.`dob` ) > 0 ) THEN + date_format( str_to_date( `tbl_client`.`dob`, '%Y-%m-%d' ), '%Y-%m-%d' ) END)) > 0) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 9)) then `tbl_client`.`id` end)) AS count")) + ->where('tbl_appointment.date_attended', '=', DB::raw('tbl_appointment.appntmnt_date')) + ->where('tbl_client.mfl_code', Auth::user()->facility_id); + + $appointment_honored_to_fourteen = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select(\DB::raw("count((case when (((year(curdate()) - year(CASE + WHEN ( locate( '/', `tbl_client`.`dob` ) > 0 ) THEN + date_format( str_to_date( `tbl_client`.`dob`, '%m/%d/%Y' ), '%Y-%m-%d' ) + WHEN ( locate( '-', `tbl_client`.`dob` ) > 0 ) THEN + date_format( str_to_date( `tbl_client`.`dob`, '%Y-%m-%d' ), '%Y-%m-%d' ) END)) >= 10) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 14)) then `tbl_client`.`id` end)) AS count")) + ->where('tbl_appointment.date_attended', '=', DB::raw('tbl_appointment.appntmnt_date')) + ->where('tbl_client.mfl_code', Auth::user()->facility_id); + + $appointment_honored_to_nineteen = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select(\DB::raw("count((case when (((year(curdate()) - year(CASE + WHEN ( locate( '/', `tbl_client`.`dob` ) > 0 ) THEN + date_format( str_to_date( `tbl_client`.`dob`, '%m/%d/%Y' ), '%Y-%m-%d' ) + WHEN ( locate( '-', `tbl_client`.`dob` ) > 0 ) THEN + date_format( str_to_date( `tbl_client`.`dob`, '%Y-%m-%d' ), '%Y-%m-%d' ) END)) >= 15) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 19)) then `tbl_client`.`id` end)) AS count")) + ->where('tbl_appointment.date_attended', '=', DB::raw('tbl_appointment.appntmnt_date')) + ->where('tbl_client.mfl_code', Auth::user()->facility_id); + + $appointment_honored_to_twentyfour = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select(\DB::raw("count((case when (((year(curdate()) - year(CASE + WHEN ( locate( '/', `tbl_client`.`dob` ) > 0 ) THEN + date_format( str_to_date( `tbl_client`.`dob`, '%m/%d/%Y' ), '%Y-%m-%d' ) + WHEN ( locate( '-', `tbl_client`.`dob` ) > 0 ) THEN + date_format( str_to_date( `tbl_client`.`dob`, '%Y-%m-%d' ), '%Y-%m-%d' ) END)) >= 20) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 24)) then `tbl_client`.`id` end)) AS count")) + ->where('tbl_appointment.date_attended', '=', DB::raw('tbl_appointment.appntmnt_date')) + ->where('tbl_client.mfl_code', Auth::user()->facility_id); + + $appointment_honored_to_twentyfive_above = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select(\DB::raw("count((case when (((year(curdate()) - year(CASE + WHEN ( locate( '/', `tbl_client`.`dob` ) > 0 ) THEN + date_format( str_to_date( `tbl_client`.`dob`, '%m/%d/%Y' ), '%Y-%m-%d' ) + WHEN ( locate( '-', `tbl_client`.`dob` ) > 0 ) THEN + date_format( str_to_date( `tbl_client`.`dob`, '%Y-%m-%d' ), '%Y-%m-%d' ) END)) >= 25)) then `tbl_client`.`id` end)) AS count")) + ->where('tbl_appointment.date_attended', '=', DB::raw('tbl_appointment.appntmnt_date')) + ->where('tbl_client.mfl_code', Auth::user()->facility_id); + $appointment_honored_to_uknown_age = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select('tbl_client.dob') + ->where('tbl_appointment.date_attended', '=', DB::raw('tbl_appointment.appntmnt_date')) + ->where(\DB::raw("CASE + WHEN ( locate( '/', `tbl_client`.`dob` ) > 0 ) THEN + date_format( str_to_date( `tbl_client`.`dob`, '%m/%d/%Y' ), '%Y-%m-%d' ) + WHEN ( locate( '-', `tbl_client`.`dob` ) > 0 ) THEN + date_format( str_to_date( `tbl_client`.`dob`, '%Y-%m-%d' ), '%Y-%m-%d' ) END"), '=', '') + ->orWhereNull(\DB::raw("CASE + WHEN ( locate( '/', `tbl_client`.`dob` ) > 0 ) THEN + date_format( str_to_date( `tbl_client`.`dob`, '%m/%d/%Y' ), '%Y-%m-%d' ) + WHEN ( locate( '-', `tbl_client`.`dob` ) > 0 ) THEN + date_format( str_to_date( `tbl_client`.`dob`, '%Y-%m-%d' ), '%Y-%m-%d' ) END")) + ->where('tbl_client.mfl_code', Auth::user()->facility_id); + + // appointment not honored by gender + $appointment_not_honoured_male = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->where('tbl_client.gender', '=', '2') + ->whereIn('app_status', ['Defaulted', 'LTFU', 'Missed']) + ->where('tbl_client.mfl_code', Auth::user()->facility_id); + + $appointment_not_honoured_female = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->where('tbl_client.gender', '=', '1') + ->whereIn('app_status', ['Defaulted', 'LTFU', 'Missed']) + ->where('tbl_client.mfl_code', Auth::user()->facility_id); + + $appointment_not_honoured_uknown_gender = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->where('tbl_client.gender', '!=', '1') + ->where('tbl_client.gender', '!=', '2') + ->whereIn('app_status', ['Defaulted', 'LTFU', 'Missed']) + ->where('tbl_client.mfl_code', Auth::user()->facility_id); + // appointment not honored by age + $appointment_not_honored_to_nine = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select(\DB::raw("count((case when (((year(curdate()) - year(CASE + WHEN ( locate( '/', `tbl_client`.`dob` ) > 0 ) THEN + date_format( str_to_date( `tbl_client`.`dob`, '%m/%d/%Y' ), '%Y-%m-%d' ) + WHEN ( locate( '-', `tbl_client`.`dob` ) > 0 ) THEN + date_format( str_to_date( `tbl_client`.`dob`, '%Y-%m-%d' ), '%Y-%m-%d' ) END)) > 0) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 9)) then `tbl_client`.`id` end)) AS count")) + ->whereIn('app_status', ['Defaulted', 'LTFU', 'Missed']) + ->where('tbl_client.mfl_code', Auth::user()->facility_id); + + $appointment_not_honored_to_fourteen = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select(\DB::raw("count((case when (((year(curdate()) - year(CASE + WHEN ( locate( '/', `tbl_client`.`dob` ) > 0 ) THEN + date_format( str_to_date( `tbl_client`.`dob`, '%m/%d/%Y' ), '%Y-%m-%d' ) + WHEN ( locate( '-', `tbl_client`.`dob` ) > 0 ) THEN + date_format( str_to_date( `tbl_client`.`dob`, '%Y-%m-%d' ), '%Y-%m-%d' ) END)) >= 10) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 14)) then `tbl_client`.`id` end)) AS count")) + ->whereIn('app_status', ['Defaulted', 'LTFU', 'Missed']) + ->where('tbl_client.mfl_code', Auth::user()->facility_id); + + $appointment_not_honored_to_nineteen = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select(\DB::raw("count((case when (((year(curdate()) - year(CASE + WHEN ( locate( '/', `tbl_client`.`dob` ) > 0 ) THEN + date_format( str_to_date( `tbl_client`.`dob`, '%m/%d/%Y' ), '%Y-%m-%d' ) + WHEN ( locate( '-', `tbl_client`.`dob` ) > 0 ) THEN + date_format( str_to_date( `tbl_client`.`dob`, '%Y-%m-%d' ), '%Y-%m-%d' ) END)) >= 15) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 19)) then `tbl_client`.`id` end)) AS count")) + ->whereIn('app_status', ['Defaulted', 'LTFU', 'Missed']) + ->where('tbl_client.mfl_code', Auth::user()->facility_id); + + $appointment_not_honored_to_twentyfour = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select(\DB::raw("count((case when (((year(curdate()) - year(CASE + WHEN ( locate( '/', `tbl_client`.`dob` ) > 0 ) THEN + date_format( str_to_date( `tbl_client`.`dob`, '%m/%d/%Y' ), '%Y-%m-%d' ) + WHEN ( locate( '-', `tbl_client`.`dob` ) > 0 ) THEN + date_format( str_to_date( `tbl_client`.`dob`, '%Y-%m-%d' ), '%Y-%m-%d' ) END)) >= 20) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 24)) then `tbl_client`.`id` end)) AS count")) + ->whereIn('app_status', ['Defaulted', 'LTFU', 'Missed']) + ->where('tbl_client.mfl_code', Auth::user()->facility_id); + + $appointment_not_honored_to_twentyfive_above = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select(\DB::raw("count((case when (((year(curdate()) - year(CASE + WHEN ( locate( '/', `tbl_client`.`dob` ) > 0 ) THEN + date_format( str_to_date( `tbl_client`.`dob`, '%m/%d/%Y' ), '%Y-%m-%d' ) + WHEN ( locate( '-', `tbl_client`.`dob` ) > 0 ) THEN + date_format( str_to_date( `tbl_client`.`dob`, '%Y-%m-%d' ), '%Y-%m-%d' ) END)) >= 25)) then `tbl_client`.`id` end)) AS count")) + ->whereIn('app_status', ['Defaulted', 'LTFU', 'Missed']) + ->where('tbl_client.mfl_code', Auth::user()->facility_id); + + $appointment_not_honored_to_uknown_age = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->where(\DB::raw("CASE + WHEN ( locate( '/', `tbl_client`.`dob` ) > 0 ) THEN + date_format( str_to_date( `tbl_client`.`dob`, '%m/%d/%Y' ), '%Y-%m-%d' ) + WHEN ( locate( '-', `tbl_client`.`dob` ) > 0 ) THEN + date_format( str_to_date( `tbl_client`.`dob`, '%Y-%m-%d' ), '%Y-%m-%d' ) END"), '=', '') + ->orWhereNull(\DB::raw("CASE + WHEN ( locate( '/', `tbl_client`.`dob` ) > 0 ) THEN + date_format( str_to_date( `tbl_client`.`dob`, '%m/%d/%Y' ), '%Y-%m-%d' ) + WHEN ( locate( '-', `tbl_client`.`dob` ) > 0 ) THEN + date_format( str_to_date( `tbl_client`.`dob`, '%Y-%m-%d' ), '%Y-%m-%d' ) END")) + ->whereIn('app_status', ['Defaulted', 'LTFU', 'Missed']) + ->where('tbl_client.mfl_code', Auth::user()->facility_id); + } + if (Auth::user()->access_level == 'Partner') { + $appointment = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select('tbl_appointment.id') + ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id); + $appointment_honoured = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select('tbl_appointment.id') + ->where('tbl_appointment.date_attended', '=', DB::raw('tbl_appointment.appntmnt_date')) + ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id); + $appointment_not_honoured = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select('tbl_appointment.id') + ->whereIn('tbl_appointment.app_status', ['Defaulted', 'LTFU', 'Missed']) + ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id); + // appointment honored by gender + $appointment_honoured_male = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select('tbl_appointment.id') + ->where('tbl_appointment.date_attended', '=', DB::raw('tbl_appointment.appntmnt_date')) + ->where('tbl_client.gender', '=', '2') + ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id); + $appointment_honoured_female = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->where('tbl_appointment.date_attended', '=', DB::raw('tbl_appointment.appntmnt_date')) + ->where('tbl_client.gender', '=', '1') + ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id); + $appointment_honoured_uknown_gender = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->where('tbl_appointment.date_attended', '=', DB::raw('tbl_appointment.appntmnt_date')) + ->where('tbl_client.gender', '!=', '1') + ->where('tbl_client.gender', '!=', '2') + ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id); + // appointment honored by age + $appointment_honored_to_nine = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select(\DB::raw("count((case when (((year(curdate()) - year(CASE + WHEN ( locate( '/', `tbl_client`.`dob` ) > 0 ) THEN + date_format( str_to_date( `tbl_client`.`dob`, '%m/%d/%Y' ), '%Y-%m-%d' ) + WHEN ( locate( '-', `tbl_client`.`dob` ) > 0 ) THEN + date_format( str_to_date( `tbl_client`.`dob`, '%Y-%m-%d' ), '%Y-%m-%d' ) END)) > 0) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 9)) then `tbl_client`.`id` end)) AS count")) + ->where('tbl_appointment.date_attended', '=', DB::raw('tbl_appointment.appntmnt_date')) + ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id); + + $appointment_honored_to_fourteen = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select(\DB::raw("count((case when (((year(curdate()) - year(CASE + WHEN ( locate( '/', `tbl_client`.`dob` ) > 0 ) THEN + date_format( str_to_date( `tbl_client`.`dob`, '%m/%d/%Y' ), '%Y-%m-%d' ) + WHEN ( locate( '-', `tbl_client`.`dob` ) > 0 ) THEN + date_format( str_to_date( `tbl_client`.`dob`, '%Y-%m-%d' ), '%Y-%m-%d' ) END)) >= 10) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 14)) then `tbl_client`.`id` end)) AS count")) + ->where('tbl_appointment.date_attended', '=', DB::raw('tbl_appointment.appntmnt_date')) + ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id); + + $appointment_honored_to_nineteen = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select(\DB::raw("count((case when (((year(curdate()) - year(CASE + WHEN ( locate( '/', `tbl_client`.`dob` ) > 0 ) THEN + date_format( str_to_date( `tbl_client`.`dob`, '%m/%d/%Y' ), '%Y-%m-%d' ) + WHEN ( locate( '-', `tbl_client`.`dob` ) > 0 ) THEN + date_format( str_to_date( `tbl_client`.`dob`, '%Y-%m-%d' ), '%Y-%m-%d' ) END)) >= 15) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 19)) then `tbl_client`.`id` end)) AS count")) + ->where('tbl_appointment.date_attended', '=', DB::raw('tbl_appointment.appntmnt_date')) + ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id); + + $appointment_honored_to_twentyfour = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select(\DB::raw("count((case when (((year(curdate()) - year(CASE + WHEN ( locate( '/', `tbl_client`.`dob` ) > 0 ) THEN + date_format( str_to_date( `tbl_client`.`dob`, '%m/%d/%Y' ), '%Y-%m-%d' ) + WHEN ( locate( '-', `tbl_client`.`dob` ) > 0 ) THEN + date_format( str_to_date( `tbl_client`.`dob`, '%Y-%m-%d' ), '%Y-%m-%d' ) END)) >= 20) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 24)) then `tbl_client`.`id` end)) AS count")) + ->where('tbl_appointment.date_attended', '=', DB::raw('tbl_appointment.appntmnt_date')) + ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id); + + $appointment_honored_to_twentyfive_above = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select(\DB::raw("count((case when (((year(curdate()) - year(CASE + WHEN ( locate( '/', `tbl_client`.`dob` ) > 0 ) THEN + date_format( str_to_date( `tbl_client`.`dob`, '%m/%d/%Y' ), '%Y-%m-%d' ) + WHEN ( locate( '-', `tbl_client`.`dob` ) > 0 ) THEN + date_format( str_to_date( `tbl_client`.`dob`, '%Y-%m-%d' ), '%Y-%m-%d' ) END)) >= 25)) then `tbl_client`.`id` end)) AS count")) + ->where('tbl_appointment.date_attended', '=', DB::raw('tbl_appointment.appntmnt_date')) + ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id); + $appointment_honored_to_uknown_age = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select('tbl_client.dob') + ->where('tbl_appointment.date_attended', '=', DB::raw('tbl_appointment.appntmnt_date')) + ->where(\DB::raw("CASE + WHEN ( locate( '/', `tbl_client`.`dob` ) > 0 ) THEN + date_format( str_to_date( `tbl_client`.`dob`, '%m/%d/%Y' ), '%Y-%m-%d' ) + WHEN ( locate( '-', `tbl_client`.`dob` ) > 0 ) THEN + date_format( str_to_date( `tbl_client`.`dob`, '%Y-%m-%d' ), '%Y-%m-%d' ) END"), '=', '') + ->orWhereNull(\DB::raw("CASE + WHEN ( locate( '/', `tbl_client`.`dob` ) > 0 ) THEN + date_format( str_to_date( `tbl_client`.`dob`, '%m/%d/%Y' ), '%Y-%m-%d' ) + WHEN ( locate( '-', `tbl_client`.`dob` ) > 0 ) THEN + date_format( str_to_date( `tbl_client`.`dob`, '%Y-%m-%d' ), '%Y-%m-%d' ) END")) + ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id); + + // appointment not honored by gender + $appointment_not_honoured_male = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->where('tbl_client.gender', '=', '2') + ->whereIn('app_status', ['Defaulted', 'LTFU', 'Missed']) + ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id); + + $appointment_not_honoured_female = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->where('tbl_client.gender', '=', '1') + ->whereIn('app_status', ['Defaulted', 'LTFU', 'Missed']) + ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id); + + $appointment_not_honoured_uknown_gender = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->where('tbl_client.gender', '!=', '1') + ->where('tbl_client.gender', '!=', '2') + ->whereIn('app_status', ['Defaulted', 'LTFU', 'Missed']) + ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id); + // appointment not honored by age + $appointment_not_honored_to_nine = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select(\DB::raw("count((case when (((year(curdate()) - year(CASE + WHEN ( locate( '/', `tbl_client`.`dob` ) > 0 ) THEN + date_format( str_to_date( `tbl_client`.`dob`, '%m/%d/%Y' ), '%Y-%m-%d' ) + WHEN ( locate( '-', `tbl_client`.`dob` ) > 0 ) THEN + date_format( str_to_date( `tbl_client`.`dob`, '%Y-%m-%d' ), '%Y-%m-%d' ) END)) > 0) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 9)) then `tbl_client`.`id` end)) AS count")) + ->whereIn('app_status', ['Defaulted', 'LTFU', 'Missed']) + ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id); + + $appointment_not_honored_to_fourteen = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select(\DB::raw("count((case when (((year(curdate()) - year(CASE + WHEN ( locate( '/', `tbl_client`.`dob` ) > 0 ) THEN + date_format( str_to_date( `tbl_client`.`dob`, '%m/%d/%Y' ), '%Y-%m-%d' ) + WHEN ( locate( '-', `tbl_client`.`dob` ) > 0 ) THEN + date_format( str_to_date( `tbl_client`.`dob`, '%Y-%m-%d' ), '%Y-%m-%d' ) END)) >= 10) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 14)) then `tbl_client`.`id` end)) AS count")) + ->whereIn('app_status', ['Defaulted', 'LTFU', 'Missed']) + ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id); + + $appointment_not_honored_to_nineteen = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select(\DB::raw("count((case when (((year(curdate()) - year(CASE + WHEN ( locate( '/', `tbl_client`.`dob` ) > 0 ) THEN + date_format( str_to_date( `tbl_client`.`dob`, '%m/%d/%Y' ), '%Y-%m-%d' ) + WHEN ( locate( '-', `tbl_client`.`dob` ) > 0 ) THEN + date_format( str_to_date( `tbl_client`.`dob`, '%Y-%m-%d' ), '%Y-%m-%d' ) END)) >= 15) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 19)) then `tbl_client`.`id` end)) AS count")) + ->whereIn('app_status', ['Defaulted', 'LTFU', 'Missed']) + ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id); + + $appointment_not_honored_to_twentyfour = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select(\DB::raw("count((case when (((year(curdate()) - year(CASE + WHEN ( locate( '/', `tbl_client`.`dob` ) > 0 ) THEN + date_format( str_to_date( `tbl_client`.`dob`, '%m/%d/%Y' ), '%Y-%m-%d' ) + WHEN ( locate( '-', `tbl_client`.`dob` ) > 0 ) THEN + date_format( str_to_date( `tbl_client`.`dob`, '%Y-%m-%d' ), '%Y-%m-%d' ) END)) >= 20) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 24)) then `tbl_client`.`id` end)) AS count")) + ->whereIn('app_status', ['Defaulted', 'LTFU', 'Missed']) + ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id); + + $appointment_not_honored_to_twentyfive_above = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select(\DB::raw("count((case when (((year(curdate()) - year(CASE + WHEN ( locate( '/', `tbl_client`.`dob` ) > 0 ) THEN + date_format( str_to_date( `tbl_client`.`dob`, '%m/%d/%Y' ), '%Y-%m-%d' ) + WHEN ( locate( '-', `tbl_client`.`dob` ) > 0 ) THEN + date_format( str_to_date( `tbl_client`.`dob`, '%Y-%m-%d' ), '%Y-%m-%d' ) END)) >= 25)) then `tbl_client`.`id` end)) AS count")) + ->whereIn('app_status', ['Defaulted', 'LTFU', 'Missed']) + ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id); + + $appointment_not_honored_to_uknown_age = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select('tbl_client.dob') + ->where(\DB::raw("CASE + WHEN ( locate( '/', `tbl_client`.`dob` ) > 0 ) THEN + date_format( str_to_date( `tbl_client`.`dob`, '%m/%d/%Y' ), '%Y-%m-%d' ) + WHEN ( locate( '-', `tbl_client`.`dob` ) > 0 ) THEN + date_format( str_to_date( `tbl_client`.`dob`, '%Y-%m-%d' ), '%Y-%m-%d' ) END"), '=', '') + ->orWhereNull(\DB::raw("CASE + WHEN ( locate( '/', `tbl_client`.`dob` ) > 0 ) THEN + date_format( str_to_date( `tbl_client`.`dob`, '%m/%d/%Y' ), '%Y-%m-%d' ) + WHEN ( locate( '-', `tbl_client`.`dob` ) > 0 ) THEN + date_format( str_to_date( `tbl_client`.`dob`, '%Y-%m-%d' ), '%Y-%m-%d' ) END")) + ->whereIn('app_status', ['Defaulted', 'LTFU', 'Missed']) + ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id); } + if (Auth::user()->access_level == 'Sub County') { + $appointment = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select('tbl_appointment.id') + ->where('tbl_partner_facility.sub_county_id', Auth::user()->subcounty_id); + $appointment_honoured = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select('tbl_appointment.id') + ->where('tbl_appointment.date_attended', '=', DB::raw('tbl_appointment.appntmnt_date')) + ->where('tbl_partner_facility.sub_county_id', Auth::user()->subcounty_id); + $appointment_not_honoured = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select('tbl_appointment.id') + ->whereIn('tbl_appointment.app_status', ['Defaulted', 'LTFU', 'Missed']) + ->where('tbl_partner_facility.sub_county_id', Auth::user()->subcounty_id); + // appointment honored by gender + $appointment_honoured_male = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select('tbl_appointment.id') + ->where('tbl_appointment.date_attended', '=', DB::raw('tbl_appointment.appntmnt_date')) + ->where('tbl_client.gender', '=', '2') + ->where('tbl_partner_facility.sub_county_id', Auth::user()->subcounty_id); + $appointment_honoured_female = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->where('tbl_appointment.date_attended', '=', DB::raw('tbl_appointment.appntmnt_date')) + ->where('tbl_client.gender', '=', '1') + ->where('tbl_partner_facility.sub_county_id', Auth::user()->subcounty_id); + $appointment_honoured_uknown_gender = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->where('tbl_appointment.date_attended', '=', DB::raw('tbl_appointment.appntmnt_date')) + ->where('tbl_client.gender', '!=', '1') + ->where('tbl_client.gender', '!=', '2') + ->where('tbl_partner_facility.sub_county_id', Auth::user()->subcounty_id); + // appointment honored by age + $appointment_honored_to_nine = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select(\DB::raw("count((case when (((year(curdate()) - year(CASE + WHEN ( locate( '/', `tbl_client`.`dob` ) > 0 ) THEN + date_format( str_to_date( `tbl_client`.`dob`, '%m/%d/%Y' ), '%Y-%m-%d' ) + WHEN ( locate( '-', `tbl_client`.`dob` ) > 0 ) THEN + date_format( str_to_date( `tbl_client`.`dob`, '%Y-%m-%d' ), '%Y-%m-%d' ) END)) > 0) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 9)) then `tbl_client`.`id` end)) AS count")) + ->where('tbl_appointment.date_attended', '=', DB::raw('tbl_appointment.appntmnt_date')) + ->where('tbl_partner_facility.sub_county_id', Auth::user()->subcounty_id); + $appointment_honored_to_fourteen = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select(\DB::raw("count((case when (((year(curdate()) - year(CASE + WHEN ( locate( '/', `tbl_client`.`dob` ) > 0 ) THEN + date_format( str_to_date( `tbl_client`.`dob`, '%m/%d/%Y' ), '%Y-%m-%d' ) + WHEN ( locate( '-', `tbl_client`.`dob` ) > 0 ) THEN + date_format( str_to_date( `tbl_client`.`dob`, '%Y-%m-%d' ), '%Y-%m-%d' ) END)) >= 10) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 14)) then `tbl_client`.`id` end)) AS count")) + ->where('tbl_appointment.date_attended', '=', DB::raw('tbl_appointment.appntmnt_date')) + ->where('tbl_partner_facility.sub_county_id', Auth::user()->subcounty_id); - $data["client"] = $client->count(); - $data["client_consented"] = $client_consented->count(); - $data["client_nonconsented"] = $client_nonconsented->count(); - $data["client_consented_male"] = $client_consented_male->count(); - $data["client_consented_female"] = $client_consented_female->count(); - $data["client_consented_uknown_gender"] = $client_consented_uknown_gender->count(); - $data["client_nonconsented_male"] = $client_nonconsented_male->count(); - $data["client_nonconsented_female"] = $client_nonconsented_female->count(); - $data["client_nonconsented_uknown_gender"] = $client_nonconsented_uknown_gender->count(); - $data["client_consented_to_nine"] = $client_consented_to_nine->pluck('count'); - $data["client_consented_to_fourteen"] = $client_consented_to_fourteen->pluck('count'); - $data["client_consented_to_nineteen"] = $client_consented_to_nineteen->pluck('count'); - $data["client_consented_to_twentyfour"] = $client_consented_to_twentyfour->pluck('count'); - $data["client_consented_to_twentyfive_above"] = $client_consented_to_twentyfive_above->pluck('count'); - $data["client_consented_uknown_age"] = $client_consented_uknown_age->count(); - $data["client_nonconsented_to_nine"] = $client_nonconsented_to_nine->pluck('count'); - $data["client_nonconsented_to_fourteen"] = $client_nonconsented_to_fourteen->pluck('count'); - $data["client_nonconsented_to_nineteen"] = $client_nonconsented_to_nineteen->pluck('count'); - $data["client_nonconsented_to_twentyfour"] = $client_nonconsented_to_twentyfour->pluck('count'); - $data["client_nonconsented_to_twentyfive_above"] = $client_nonconsented_to_twentyfive_above->pluck('count'); - $data["client_nonconsented_uknown_age"] = $client_nonconsented_uknown_age->count(); + $appointment_honored_to_nineteen = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select(\DB::raw("count((case when (((year(curdate()) - year(CASE + WHEN ( locate( '/', `tbl_client`.`dob` ) > 0 ) THEN + date_format( str_to_date( `tbl_client`.`dob`, '%m/%d/%Y' ), '%Y-%m-%d' ) + WHEN ( locate( '-', `tbl_client`.`dob` ) > 0 ) THEN + date_format( str_to_date( `tbl_client`.`dob`, '%Y-%m-%d' ), '%Y-%m-%d' ) END)) >= 15) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 19)) then `tbl_client`.`id` end)) AS count")) + ->where('tbl_appointment.date_attended', '=', DB::raw('tbl_appointment.appntmnt_date')) + ->where('tbl_partner_facility.sub_county_id', Auth::user()->subcounty_id); - return $data; - } - public function filter_appointment_charts(Request $request) - { - $data = []; - // client charts - $selected_partners = $request->partners; - $selected_counties = $request->counties; - $selected_subcounties = $request->subcounties; - $selected_facilites = $request->facilities; - $selected_from = $request->from; - $selected_to = $request->to; - $selected_module = $request->module; + $appointment_honored_to_twentyfour = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select(\DB::raw("count((case when (((year(curdate()) - year(CASE + WHEN ( locate( '/', `tbl_client`.`dob` ) > 0 ) THEN + date_format( str_to_date( `tbl_client`.`dob`, '%m/%d/%Y' ), '%Y-%m-%d' ) + WHEN ( locate( '-', `tbl_client`.`dob` ) > 0 ) THEN + date_format( str_to_date( `tbl_client`.`dob`, '%Y-%m-%d' ), '%Y-%m-%d' ) END)) >= 20) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 24)) then `tbl_client`.`id` end)) AS count")) + ->where('tbl_appointment.date_attended', '=', DB::raw('tbl_appointment.appntmnt_date')) + ->where('tbl_partner_facility.sub_county_id', Auth::user()->subcounty_id); - if (Auth::user()->access_level == 'Facility') { + $appointment_honored_to_twentyfive_above = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select(\DB::raw("count((case when (((year(curdate()) - year(CASE + WHEN ( locate( '/', `tbl_client`.`dob` ) > 0 ) THEN + date_format( str_to_date( `tbl_client`.`dob`, '%m/%d/%Y' ), '%Y-%m-%d' ) + WHEN ( locate( '-', `tbl_client`.`dob` ) > 0 ) THEN + date_format( str_to_date( `tbl_client`.`dob`, '%Y-%m-%d' ), '%Y-%m-%d' ) END)) >= 25)) then `tbl_client`.`id` end)) AS count")) + ->where('tbl_appointment.date_attended', '=', DB::raw('tbl_appointment.appntmnt_date')) + ->where('tbl_partner_facility.sub_county_id', Auth::user()->subcounty_id); + $appointment_honored_to_uknown_age = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select('tbl_client.dob') + ->where('tbl_appointment.date_attended', '=', DB::raw('tbl_appointment.appntmnt_date')) + ->where(\DB::raw("CASE + WHEN ( locate( '/', `tbl_client`.`dob` ) > 0 ) THEN + date_format( str_to_date( `tbl_client`.`dob`, '%m/%d/%Y' ), '%Y-%m-%d' ) + WHEN ( locate( '-', `tbl_client`.`dob` ) > 0 ) THEN + date_format( str_to_date( `tbl_client`.`dob`, '%Y-%m-%d' ), '%Y-%m-%d' ) END"), '=', '') + ->orWhereNull(\DB::raw("CASE + WHEN ( locate( '/', `tbl_client`.`dob` ) > 0 ) THEN + date_format( str_to_date( `tbl_client`.`dob`, '%m/%d/%Y' ), '%Y-%m-%d' ) + WHEN ( locate( '-', `tbl_client`.`dob` ) > 0 ) THEN + date_format( str_to_date( `tbl_client`.`dob`, '%Y-%m-%d' ), '%Y-%m-%d' ) END")) + ->where('tbl_partner_facility.sub_county_id', Auth::user()->subcounty_id); + + // appointment not honored by gender + $appointment_not_honoured_male = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->where('tbl_client.gender', '=', '2') + ->whereIn('app_status', ['Defaulted', 'LTFU', 'Missed']) + ->where('tbl_partner_facility.sub_county_id', Auth::user()->subcounty_id); + + $appointment_not_honoured_female = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->where('tbl_client.gender', '=', '1') + ->whereIn('app_status', ['Defaulted', 'LTFU', 'Missed']) + ->where('tbl_partner_facility.sub_county_id', Auth::user()->subcounty_id); + + $appointment_not_honoured_uknown_gender = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->where('tbl_client.gender', '!=', '1') + ->where('tbl_client.gender', '!=', '2') + ->whereIn('app_status', ['Defaulted', 'LTFU', 'Missed']) + ->where('tbl_partner_facility.sub_county_id', Auth::user()->subcounty_id); + // appointment not honored by age + $appointment_not_honored_to_nine = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select(\DB::raw("count((case when (((year(curdate()) - year(CASE + WHEN ( locate( '/', `tbl_client`.`dob` ) > 0 ) THEN + date_format( str_to_date( `tbl_client`.`dob`, '%m/%d/%Y' ), '%Y-%m-%d' ) + WHEN ( locate( '-', `tbl_client`.`dob` ) > 0 ) THEN + date_format( str_to_date( `tbl_client`.`dob`, '%Y-%m-%d' ), '%Y-%m-%d' ) END)) > 0) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 9)) then `tbl_client`.`id` end)) AS count")) + ->whereIn('app_status', ['Defaulted', 'LTFU', 'Missed']) + ->where('tbl_partner_facility.sub_county_id', Auth::user()->subcounty_id); + + $appointment_not_honored_to_fourteen = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select(\DB::raw("count((case when (((year(curdate()) - year(CASE + WHEN ( locate( '/', `tbl_client`.`dob` ) > 0 ) THEN + date_format( str_to_date( `tbl_client`.`dob`, '%m/%d/%Y' ), '%Y-%m-%d' ) + WHEN ( locate( '-', `tbl_client`.`dob` ) > 0 ) THEN + date_format( str_to_date( `tbl_client`.`dob`, '%Y-%m-%d' ), '%Y-%m-%d' ) END)) >= 10) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 14)) then `tbl_client`.`id` end)) AS count")) + ->whereIn('app_status', ['Defaulted', 'LTFU', 'Missed']) + ->where('tbl_partner_facility.sub_county_id', Auth::user()->subcounty_id); + + $appointment_not_honored_to_nineteen = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select(\DB::raw("count((case when (((year(curdate()) - year(CASE + WHEN ( locate( '/', `tbl_client`.`dob` ) > 0 ) THEN + date_format( str_to_date( `tbl_client`.`dob`, '%m/%d/%Y' ), '%Y-%m-%d' ) + WHEN ( locate( '-', `tbl_client`.`dob` ) > 0 ) THEN + date_format( str_to_date( `tbl_client`.`dob`, '%Y-%m-%d' ), '%Y-%m-%d' ) END)) >= 15) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 19)) then `tbl_client`.`id` end)) AS count")) + ->whereIn('app_status', ['Defaulted', 'LTFU', 'Missed']) + ->where('tbl_partner_facility.sub_county_id', Auth::user()->subcounty_id); + + $appointment_not_honored_to_twentyfour = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select(\DB::raw("count((case when (((year(curdate()) - year(CASE + WHEN ( locate( '/', `tbl_client`.`dob` ) > 0 ) THEN + date_format( str_to_date( `tbl_client`.`dob`, '%m/%d/%Y' ), '%Y-%m-%d' ) + WHEN ( locate( '-', `tbl_client`.`dob` ) > 0 ) THEN + date_format( str_to_date( `tbl_client`.`dob`, '%Y-%m-%d' ), '%Y-%m-%d' ) END)) >= 20) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 24)) then `tbl_client`.`id` end)) AS count")) + ->whereIn('app_status', ['Defaulted', 'LTFU', 'Missed']) + ->where('tbl_partner_facility.sub_county_id', Auth::user()->subcounty_id); + + $appointment_not_honored_to_twentyfive_above = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select(\DB::raw("count((case when (((year(curdate()) - year(CASE + WHEN ( locate( '/', `tbl_client`.`dob` ) > 0 ) THEN + date_format( str_to_date( `tbl_client`.`dob`, '%m/%d/%Y' ), '%Y-%m-%d' ) + WHEN ( locate( '-', `tbl_client`.`dob` ) > 0 ) THEN + date_format( str_to_date( `tbl_client`.`dob`, '%Y-%m-%d' ), '%Y-%m-%d' ) END)) >= 25)) then `tbl_client`.`id` end)) AS count")) + ->whereIn('app_status', ['Defaulted', 'LTFU', 'Missed']) + ->where('tbl_partner_facility.sub_county_id', Auth::user()->subcounty_id); + + $appointment_not_honored_to_uknown_age = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select('tbl_client.dob') + ->where(\DB::raw("CASE + WHEN ( locate( '/', `tbl_client`.`dob` ) > 0 ) THEN + date_format( str_to_date( `tbl_client`.`dob`, '%m/%d/%Y' ), '%Y-%m-%d' ) + WHEN ( locate( '-', `tbl_client`.`dob` ) > 0 ) THEN + date_format( str_to_date( `tbl_client`.`dob`, '%Y-%m-%d' ), '%Y-%m-%d' ) END"), '=', '') + ->orWhereNull(\DB::raw("CASE + WHEN ( locate( '/', `tbl_client`.`dob` ) > 0 ) THEN + date_format( str_to_date( `tbl_client`.`dob`, '%m/%d/%Y' ), '%Y-%m-%d' ) + WHEN ( locate( '-', `tbl_client`.`dob` ) > 0 ) THEN + date_format( str_to_date( `tbl_client`.`dob`, '%Y-%m-%d' ), '%Y-%m-%d' ) END")) + ->whereIn('app_status', ['Defaulted', 'LTFU', 'Missed']) + ->where('tbl_partner_facility.sub_county_id', Auth::user()->subcounty_id); + } + if (Auth::user()->access_level == 'County') { $appointment = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') ->select('tbl_appointment.id') - ->where('tbl_client.mfl_code', Auth::user()->facility_id); + ->where('tbl_partner_facility.county_id', Auth::user()->county_id); $appointment_honoured = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') ->select('tbl_appointment.id') ->where('tbl_appointment.date_attended', '=', DB::raw('tbl_appointment.appntmnt_date')) - ->where('tbl_client.mfl_code', Auth::user()->facility_id); + ->where('tbl_partner_facility.county_id', Auth::user()->county_id); $appointment_not_honoured = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') ->select('tbl_appointment.id') ->whereIn('tbl_appointment.app_status', ['Defaulted', 'LTFU', 'Missed']) - ->where('tbl_client.mfl_code', Auth::user()->facility_id); + ->where('tbl_partner_facility.county_id', Auth::user()->county_id); // appointment honored by gender $appointment_honoured_male = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') ->select('tbl_appointment.id') ->where('tbl_appointment.date_attended', '=', DB::raw('tbl_appointment.appntmnt_date')) ->where('tbl_client.gender', '=', '2') - ->where('tbl_client.mfl_code', Auth::user()->facility_id); + ->where('tbl_partner_facility.county_id', Auth::user()->county_id); $appointment_honoured_female = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') ->where('tbl_appointment.date_attended', '=', DB::raw('tbl_appointment.appntmnt_date')) ->where('tbl_client.gender', '=', '1') - ->where('tbl_client.mfl_code', Auth::user()->facility_id); + ->where('tbl_partner_facility.county_id', Auth::user()->county_id); $appointment_honoured_uknown_gender = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') ->where('tbl_appointment.date_attended', '=', DB::raw('tbl_appointment.appntmnt_date')) ->where('tbl_client.gender', '!=', '1') ->where('tbl_client.gender', '!=', '2') - ->where('tbl_client.mfl_code', Auth::user()->facility_id); + ->where('tbl_partner_facility.county_id', Auth::user()->county_id); // appointment honored by age $appointment_honored_to_nine = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') @@ -5937,7 +7119,7 @@ public function filter_appointment_charts(Request $request) WHEN ( locate( '-', `tbl_client`.`dob` ) > 0 ) THEN date_format( str_to_date( `tbl_client`.`dob`, '%Y-%m-%d' ), '%Y-%m-%d' ) END)) > 0) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 9)) then `tbl_client`.`id` end)) AS count")) ->where('tbl_appointment.date_attended', '=', DB::raw('tbl_appointment.appntmnt_date')) - ->where('tbl_client.mfl_code', Auth::user()->facility_id); + ->where('tbl_partner_facility.county_id', Auth::user()->county_id); $appointment_honored_to_fourteen = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') @@ -5947,41 +7129,290 @@ public function filter_appointment_charts(Request $request) WHEN ( locate( '-', `tbl_client`.`dob` ) > 0 ) THEN date_format( str_to_date( `tbl_client`.`dob`, '%Y-%m-%d' ), '%Y-%m-%d' ) END)) >= 10) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 14)) then `tbl_client`.`id` end)) AS count")) ->where('tbl_appointment.date_attended', '=', DB::raw('tbl_appointment.appntmnt_date')) - ->where('tbl_client.mfl_code', Auth::user()->facility_id); + ->where('tbl_partner_facility.county_id', Auth::user()->county_id); + + $appointment_honored_to_nineteen = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select(\DB::raw("count((case when (((year(curdate()) - year(CASE + WHEN ( locate( '/', `tbl_client`.`dob` ) > 0 ) THEN + date_format( str_to_date( `tbl_client`.`dob`, '%m/%d/%Y' ), '%Y-%m-%d' ) + WHEN ( locate( '-', `tbl_client`.`dob` ) > 0 ) THEN + date_format( str_to_date( `tbl_client`.`dob`, '%Y-%m-%d' ), '%Y-%m-%d' ) END)) >= 15) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 19)) then `tbl_client`.`id` end)) AS count")) + ->where('tbl_appointment.date_attended', '=', DB::raw('tbl_appointment.appntmnt_date')) + ->where('tbl_partner_facility.county_id', Auth::user()->county_id); + + $appointment_honored_to_twentyfour = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select(\DB::raw("count((case when (((year(curdate()) - year(CASE + WHEN ( locate( '/', `tbl_client`.`dob` ) > 0 ) THEN + date_format( str_to_date( `tbl_client`.`dob`, '%m/%d/%Y' ), '%Y-%m-%d' ) + WHEN ( locate( '-', `tbl_client`.`dob` ) > 0 ) THEN + date_format( str_to_date( `tbl_client`.`dob`, '%Y-%m-%d' ), '%Y-%m-%d' ) END)) >= 20) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 24)) then `tbl_client`.`id` end)) AS count")) + ->where('tbl_appointment.date_attended', '=', DB::raw('tbl_appointment.appntmnt_date')) + ->where('tbl_partner_facility.county_id', Auth::user()->county_id); + + $appointment_honored_to_twentyfive_above = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select(\DB::raw("count((case when (((year(curdate()) - year(CASE + WHEN ( locate( '/', `tbl_client`.`dob` ) > 0 ) THEN + date_format( str_to_date( `tbl_client`.`dob`, '%m/%d/%Y' ), '%Y-%m-%d' ) + WHEN ( locate( '-', `tbl_client`.`dob` ) > 0 ) THEN + date_format( str_to_date( `tbl_client`.`dob`, '%Y-%m-%d' ), '%Y-%m-%d' ) END)) >= 25)) then `tbl_client`.`id` end)) AS count")) + ->where('tbl_appointment.date_attended', '=', DB::raw('tbl_appointment.appntmnt_date')) + ->where('tbl_partner_facility.county_id', Auth::user()->county_id); + $appointment_honored_to_uknown_age = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select('tbl_client.dob') + ->where('tbl_appointment.date_attended', '=', DB::raw('tbl_appointment.appntmnt_date')) + ->where(\DB::raw("CASE + WHEN ( locate( '/', `tbl_client`.`dob` ) > 0 ) THEN + date_format( str_to_date( `tbl_client`.`dob`, '%m/%d/%Y' ), '%Y-%m-%d' ) + WHEN ( locate( '-', `tbl_client`.`dob` ) > 0 ) THEN + date_format( str_to_date( `tbl_client`.`dob`, '%Y-%m-%d' ), '%Y-%m-%d' ) END"), '=', '') + ->orWhereNull(\DB::raw("CASE + WHEN ( locate( '/', `tbl_client`.`dob` ) > 0 ) THEN + date_format( str_to_date( `tbl_client`.`dob`, '%m/%d/%Y' ), '%Y-%m-%d' ) + WHEN ( locate( '-', `tbl_client`.`dob` ) > 0 ) THEN + date_format( str_to_date( `tbl_client`.`dob`, '%Y-%m-%d' ), '%Y-%m-%d' ) END")) + ->where('tbl_partner_facility.county_id', Auth::user()->county_id); + + // appointment not honored by gender + $appointment_not_honoured_male = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->where('tbl_client.gender', '=', '2') + ->whereIn('app_status', ['Defaulted', 'LTFU', 'Missed']) + ->where('tbl_partner_facility.county_id', Auth::user()->county_id); + + $appointment_not_honoured_female = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->where('tbl_client.gender', '=', '1') + ->whereIn('app_status', ['Defaulted', 'LTFU', 'Missed']) + ->where('tbl_partner_facility.county_id', Auth::user()->county_id); + + $appointment_not_honoured_uknown_gender = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->where('tbl_client.gender', '!=', '1') + ->where('tbl_client.gender', '!=', '2') + ->whereIn('app_status', ['Defaulted', 'LTFU', 'Missed']) + ->where('tbl_partner_facility.county_id', Auth::user()->county_id); + // appointment not honored by age + $appointment_not_honored_to_nine = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select(\DB::raw("count((case when (((year(curdate()) - year(CASE + WHEN ( locate( '/', `tbl_client`.`dob` ) > 0 ) THEN + date_format( str_to_date( `tbl_client`.`dob`, '%m/%d/%Y' ), '%Y-%m-%d' ) + WHEN ( locate( '-', `tbl_client`.`dob` ) > 0 ) THEN + date_format( str_to_date( `tbl_client`.`dob`, '%Y-%m-%d' ), '%Y-%m-%d' ) END)) > 0) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 9)) then `tbl_client`.`id` end)) AS count")) + ->whereIn('app_status', ['Defaulted', 'LTFU', 'Missed']) + ->where('tbl_partner_facility.county_id', Auth::user()->county_id); + + $appointment_not_honored_to_fourteen = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select(\DB::raw("count((case when (((year(curdate()) - year(CASE + WHEN ( locate( '/', `tbl_client`.`dob` ) > 0 ) THEN + date_format( str_to_date( `tbl_client`.`dob`, '%m/%d/%Y' ), '%Y-%m-%d' ) + WHEN ( locate( '-', `tbl_client`.`dob` ) > 0 ) THEN + date_format( str_to_date( `tbl_client`.`dob`, '%Y-%m-%d' ), '%Y-%m-%d' ) END)) >= 10) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 14)) then `tbl_client`.`id` end)) AS count")) + ->whereIn('app_status', ['Defaulted', 'LTFU', 'Missed']) + ->where('tbl_partner_facility.county_id', Auth::user()->county_id); + + $appointment_not_honored_to_nineteen = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select(\DB::raw("count((case when (((year(curdate()) - year(CASE + WHEN ( locate( '/', `tbl_client`.`dob` ) > 0 ) THEN + date_format( str_to_date( `tbl_client`.`dob`, '%m/%d/%Y' ), '%Y-%m-%d' ) + WHEN ( locate( '-', `tbl_client`.`dob` ) > 0 ) THEN + date_format( str_to_date( `tbl_client`.`dob`, '%Y-%m-%d' ), '%Y-%m-%d' ) END)) >= 15) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 19)) then `tbl_client`.`id` end)) AS count")) + ->whereIn('app_status', ['Defaulted', 'LTFU', 'Missed']) + ->where('tbl_partner_facility.county_id', Auth::user()->county_id); + + $appointment_not_honored_to_twentyfour = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select(\DB::raw("count((case when (((year(curdate()) - year(CASE + WHEN ( locate( '/', `tbl_client`.`dob` ) > 0 ) THEN + date_format( str_to_date( `tbl_client`.`dob`, '%m/%d/%Y' ), '%Y-%m-%d' ) + WHEN ( locate( '-', `tbl_client`.`dob` ) > 0 ) THEN + date_format( str_to_date( `tbl_client`.`dob`, '%Y-%m-%d' ), '%Y-%m-%d' ) END)) >= 20) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 24)) then `tbl_client`.`id` end)) AS count")) + ->whereIn('app_status', ['Defaulted', 'LTFU', 'Missed']) + ->where('tbl_partner_facility.county_id', Auth::user()->county_id); + + $appointment_not_honored_to_twentyfive_above = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select(\DB::raw("count((case when (((year(curdate()) - year(CASE + WHEN ( locate( '/', `tbl_client`.`dob` ) > 0 ) THEN + date_format( str_to_date( `tbl_client`.`dob`, '%m/%d/%Y' ), '%Y-%m-%d' ) + WHEN ( locate( '-', `tbl_client`.`dob` ) > 0 ) THEN + date_format( str_to_date( `tbl_client`.`dob`, '%Y-%m-%d' ), '%Y-%m-%d' ) END)) >= 25)) then `tbl_client`.`id` end)) AS count")) + ->whereIn('app_status', ['Defaulted', 'LTFU', 'Missed']) + ->where('tbl_partner_facility.county_id', Auth::user()->county_id); + + $appointment_not_honored_to_uknown_age = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select('tbl_client.dob') + ->where(\DB::raw("CASE + WHEN ( locate( '/', `tbl_client`.`dob` ) > 0 ) THEN + date_format( str_to_date( `tbl_client`.`dob`, '%m/%d/%Y' ), '%Y-%m-%d' ) + WHEN ( locate( '-', `tbl_client`.`dob` ) > 0 ) THEN + date_format( str_to_date( `tbl_client`.`dob`, '%Y-%m-%d' ), '%Y-%m-%d' ) END"), '=', '') + ->orWhereNull(\DB::raw("CASE + WHEN ( locate( '/', `tbl_client`.`dob` ) > 0 ) THEN + date_format( str_to_date( `tbl_client`.`dob`, '%m/%d/%Y' ), '%Y-%m-%d' ) + WHEN ( locate( '-', `tbl_client`.`dob` ) > 0 ) THEN + date_format( str_to_date( `tbl_client`.`dob`, '%Y-%m-%d' ), '%Y-%m-%d' ) END")) + ->whereIn('app_status', ['Defaulted', 'LTFU', 'Missed']) + ->where('tbl_partner_facility.county_id', Auth::user()->county_id); + } + if (Auth::user()->access_level == 'Admin' || Auth::user()->access_level == 'Donor') { + $appointment = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select('tbl_appointment.id'); + $appointment_honoured = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select('tbl_appointment.id') + ->where('tbl_appointment.date_attended', '=', DB::raw('tbl_appointment.appntmnt_date')); + $appointment_not_honoured = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select('tbl_appointment.id') + ->whereIn('tbl_appointment.app_status', ['Defaulted', 'LTFU', 'Missed']); + // appointment honored by gender + $appointment_honoured_male = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select('tbl_appointment.id') + ->where('tbl_appointment.date_attended', '=', DB::raw('tbl_appointment.appntmnt_date')) + ->where('tbl_client.gender', '=', '2'); + $appointment_honoured_female = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->where('tbl_appointment.date_attended', '=', DB::raw('tbl_appointment.appntmnt_date')) + ->where('tbl_client.gender', '=', '1'); + $appointment_honoured_uknown_gender = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->where('tbl_appointment.date_attended', '=', DB::raw('tbl_appointment.appntmnt_date')) + ->where('tbl_client.gender', '!=', '1') + ->where('tbl_client.gender', '!=', '2'); + // appointment honored by age + $appointment_honored_to_nine = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select(\DB::raw("count((case when (((year(curdate()) - year(CASE + WHEN ( locate( '/', `tbl_client`.`dob` ) > 0 ) THEN + date_format( str_to_date( `tbl_client`.`dob`, '%m/%d/%Y' ), '%Y-%m-%d' ) + WHEN ( locate( '-', `tbl_client`.`dob` ) > 0 ) THEN + date_format( str_to_date( `tbl_client`.`dob`, '%Y-%m-%d' ), '%Y-%m-%d' ) END)) > 0) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 9)) then `tbl_client`.`id` end)) AS count")) + ->where('tbl_appointment.date_attended', '=', DB::raw('tbl_appointment.appntmnt_date')); + + $appointment_honored_to_fourteen = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select(\DB::raw("count((case when (((year(curdate()) - year(CASE + WHEN ( locate( '/', `tbl_client`.`dob` ) > 0 ) THEN + date_format( str_to_date( `tbl_client`.`dob`, '%m/%d/%Y' ), '%Y-%m-%d' ) + WHEN ( locate( '-', `tbl_client`.`dob` ) > 0 ) THEN + date_format( str_to_date( `tbl_client`.`dob`, '%Y-%m-%d' ), '%Y-%m-%d' ) END)) >= 10) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 14)) then `tbl_client`.`id` end)) AS count")) + ->where('tbl_appointment.date_attended', '=', DB::raw('tbl_appointment.appntmnt_date')); + + $appointment_honored_to_nineteen = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select(\DB::raw("count((case when (((year(curdate()) - year(CASE + WHEN ( locate( '/', `tbl_client`.`dob` ) > 0 ) THEN + date_format( str_to_date( `tbl_client`.`dob`, '%m/%d/%Y' ), '%Y-%m-%d' ) + WHEN ( locate( '-', `tbl_client`.`dob` ) > 0 ) THEN + date_format( str_to_date( `tbl_client`.`dob`, '%Y-%m-%d' ), '%Y-%m-%d' ) END)) >= 15) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 19)) then `tbl_client`.`id` end)) AS count")) + ->where('tbl_appointment.date_attended', '=', DB::raw('tbl_appointment.appntmnt_date')); + + $appointment_honored_to_twentyfour = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select(\DB::raw("count((case when (((year(curdate()) - year(CASE + WHEN ( locate( '/', `tbl_client`.`dob` ) > 0 ) THEN + date_format( str_to_date( `tbl_client`.`dob`, '%m/%d/%Y' ), '%Y-%m-%d' ) + WHEN ( locate( '-', `tbl_client`.`dob` ) > 0 ) THEN + date_format( str_to_date( `tbl_client`.`dob`, '%Y-%m-%d' ), '%Y-%m-%d' ) END)) >= 20) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 24)) then `tbl_client`.`id` end)) AS count")) + ->where('tbl_appointment.date_attended', '=', DB::raw('tbl_appointment.appntmnt_date')); + + $appointment_honored_to_twentyfive_above = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select(\DB::raw("count((case when (((year(curdate()) - year(CASE + WHEN ( locate( '/', `tbl_client`.`dob` ) > 0 ) THEN + date_format( str_to_date( `tbl_client`.`dob`, '%m/%d/%Y' ), '%Y-%m-%d' ) + WHEN ( locate( '-', `tbl_client`.`dob` ) > 0 ) THEN + date_format( str_to_date( `tbl_client`.`dob`, '%Y-%m-%d' ), '%Y-%m-%d' ) END)) >= 25)) then `tbl_client`.`id` end)) AS count")) + ->where('tbl_appointment.date_attended', '=', DB::raw('tbl_appointment.appntmnt_date')); + $appointment_honored_to_uknown_age = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select('tbl_client.dob') + ->where('tbl_appointment.date_attended', '=', DB::raw('tbl_appointment.appntmnt_date')) + ->where(\DB::raw("CASE + WHEN ( locate( '/', `tbl_client`.`dob` ) > 0 ) THEN + date_format( str_to_date( `tbl_client`.`dob`, '%m/%d/%Y' ), '%Y-%m-%d' ) + WHEN ( locate( '-', `tbl_client`.`dob` ) > 0 ) THEN + date_format( str_to_date( `tbl_client`.`dob`, '%Y-%m-%d' ), '%Y-%m-%d' ) END"), '=', '') + ->orWhereNull(\DB::raw("CASE + WHEN ( locate( '/', `tbl_client`.`dob` ) > 0 ) THEN + date_format( str_to_date( `tbl_client`.`dob`, '%m/%d/%Y' ), '%Y-%m-%d' ) + WHEN ( locate( '-', `tbl_client`.`dob` ) > 0 ) THEN + date_format( str_to_date( `tbl_client`.`dob`, '%Y-%m-%d' ), '%Y-%m-%d' ) END")); + + // appointment not honored by gender + $appointment_not_honoured_male = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->where('tbl_client.gender', '=', '2') + ->whereIn('app_status', ['Defaulted', 'LTFU', 'Missed']); + + $appointment_not_honoured_female = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->where('tbl_client.gender', '=', '1') + ->whereIn('app_status', ['Defaulted', 'LTFU', 'Missed']); + + $appointment_not_honoured_uknown_gender = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->where('tbl_client.gender', '!=', '1') + ->where('tbl_client.gender', '!=', '2') + ->whereIn('app_status', ['Defaulted', 'LTFU', 'Missed']); + // appointment not honored by age + $appointment_not_honored_to_nine = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select(\DB::raw("count((case when (((year(curdate()) - year(CASE + WHEN ( locate( '/', `tbl_client`.`dob` ) > 0 ) THEN + date_format( str_to_date( `tbl_client`.`dob`, '%m/%d/%Y' ), '%Y-%m-%d' ) + WHEN ( locate( '-', `tbl_client`.`dob` ) > 0 ) THEN + date_format( str_to_date( `tbl_client`.`dob`, '%Y-%m-%d' ), '%Y-%m-%d' ) END)) > 0) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 9)) then `tbl_client`.`id` end)) AS count")) + ->whereIn('app_status', ['Defaulted', 'LTFU', 'Missed']); + + $appointment_not_honored_to_fourteen = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select(\DB::raw("count((case when (((year(curdate()) - year(CASE + WHEN ( locate( '/', `tbl_client`.`dob` ) > 0 ) THEN + date_format( str_to_date( `tbl_client`.`dob`, '%m/%d/%Y' ), '%Y-%m-%d' ) + WHEN ( locate( '-', `tbl_client`.`dob` ) > 0 ) THEN + date_format( str_to_date( `tbl_client`.`dob`, '%Y-%m-%d' ), '%Y-%m-%d' ) END)) >= 10) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 14)) then `tbl_client`.`id` end)) AS count")) + ->whereIn('app_status', ['Defaulted', 'LTFU', 'Missed']); - $appointment_honored_to_nineteen = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + $appointment_not_honored_to_nineteen = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') ->select(\DB::raw("count((case when (((year(curdate()) - year(CASE WHEN ( locate( '/', `tbl_client`.`dob` ) > 0 ) THEN date_format( str_to_date( `tbl_client`.`dob`, '%m/%d/%Y' ), '%Y-%m-%d' ) WHEN ( locate( '-', `tbl_client`.`dob` ) > 0 ) THEN date_format( str_to_date( `tbl_client`.`dob`, '%Y-%m-%d' ), '%Y-%m-%d' ) END)) >= 15) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 19)) then `tbl_client`.`id` end)) AS count")) - ->where('tbl_appointment.date_attended', '=', DB::raw('tbl_appointment.appntmnt_date')) - ->where('tbl_client.mfl_code', Auth::user()->facility_id); + ->whereIn('app_status', ['Defaulted', 'LTFU', 'Missed']); - $appointment_honored_to_twentyfour = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + $appointment_not_honored_to_twentyfour = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') ->select(\DB::raw("count((case when (((year(curdate()) - year(CASE WHEN ( locate( '/', `tbl_client`.`dob` ) > 0 ) THEN date_format( str_to_date( `tbl_client`.`dob`, '%m/%d/%Y' ), '%Y-%m-%d' ) WHEN ( locate( '-', `tbl_client`.`dob` ) > 0 ) THEN date_format( str_to_date( `tbl_client`.`dob`, '%Y-%m-%d' ), '%Y-%m-%d' ) END)) >= 20) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 24)) then `tbl_client`.`id` end)) AS count")) - ->where('tbl_appointment.date_attended', '=', DB::raw('tbl_appointment.appntmnt_date')) - ->where('tbl_client.mfl_code', Auth::user()->facility_id); + ->whereIn('app_status', ['Defaulted', 'LTFU', 'Missed']); - $appointment_honored_to_twentyfive_above = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + $appointment_not_honored_to_twentyfive_above = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') ->select(\DB::raw("count((case when (((year(curdate()) - year(CASE WHEN ( locate( '/', `tbl_client`.`dob` ) > 0 ) THEN date_format( str_to_date( `tbl_client`.`dob`, '%m/%d/%Y' ), '%Y-%m-%d' ) WHEN ( locate( '-', `tbl_client`.`dob` ) > 0 ) THEN date_format( str_to_date( `tbl_client`.`dob`, '%Y-%m-%d' ), '%Y-%m-%d' ) END)) >= 25)) then `tbl_client`.`id` end)) AS count")) - ->where('tbl_appointment.date_attended', '=', DB::raw('tbl_appointment.appntmnt_date')) - ->where('tbl_client.mfl_code', Auth::user()->facility_id); - $appointment_honored_to_uknown_age = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->whereIn('app_status', ['Defaulted', 'LTFU', 'Missed']); + + $appointment_not_honored_to_uknown_age = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') - ->select('tbl_client.dob') - ->where('tbl_appointment.date_attended', '=', DB::raw('tbl_appointment.appntmnt_date')) ->where(\DB::raw("CASE WHEN ( locate( '/', `tbl_client`.`dob` ) > 0 ) THEN date_format( str_to_date( `tbl_client`.`dob`, '%m/%d/%Y' ), '%Y-%m-%d' ) @@ -5992,180 +7423,301 @@ public function filter_appointment_charts(Request $request) date_format( str_to_date( `tbl_client`.`dob`, '%m/%d/%Y' ), '%Y-%m-%d' ) WHEN ( locate( '-', `tbl_client`.`dob` ) > 0 ) THEN date_format( str_to_date( `tbl_client`.`dob`, '%Y-%m-%d' ), '%Y-%m-%d' ) END")) - ->where('tbl_client.mfl_code', Auth::user()->facility_id); - - // appointment not honored by gender - $appointment_not_honoured_male = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') - ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') - ->where('tbl_client.gender', '=', '2') - ->whereIn('app_status', ['Defaulted', 'LTFU', 'Missed']) - ->where('tbl_client.mfl_code', Auth::user()->facility_id); + ->whereIn('app_status', ['Defaulted', 'LTFU', 'Missed']); + } - $appointment_not_honoured_female = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') - ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') - ->where('tbl_client.gender', '=', '1') - ->whereIn('app_status', ['Defaulted', 'LTFU', 'Missed']) - ->where('tbl_client.mfl_code', Auth::user()->facility_id); + if (!empty($selected_partners)) { + $appointment = $appointment->where('tbl_partner_facility.partner_id', $selected_partners); + $appointment_honoured = $appointment_honoured->where('tbl_partner_facility.partner_id', $selected_partners); + $appointment_not_honoured = $appointment_not_honoured->where('tbl_partner_facility.partner_id', $selected_partners); + $appointment_honoured_male = $appointment_honoured_male->where('tbl_partner_facility.partner_id', $selected_partners); + $appointment_honoured_female = $appointment_honoured_female->where('tbl_partner_facility.partner_id', $selected_partners); + $appointment_honoured_uknown_gender = $appointment_honoured_uknown_gender->where('tbl_partner_facility.partner_id', $selected_partners); + $appointment_honored_to_nine = $appointment_honored_to_nine->where('tbl_partner_facility.partner_id', $selected_partners); + $appointment_honored_to_fourteen = $appointment_honored_to_fourteen->where('tbl_partner_facility.partner_id', $selected_partners); + $appointment_honored_to_nineteen = $appointment_honored_to_nineteen->where('tbl_partner_facility.partner_id', $selected_partners); + $appointment_honored_to_twentyfour = $appointment_honored_to_twentyfour->where('tbl_partner_facility.partner_id', $selected_partners); + $appointment_honored_to_twentyfive_above = $appointment_honored_to_twentyfive_above->where('tbl_partner_facility.partner_id', $selected_partners); + $appointment_honored_to_uknown_age = $appointment_honored_to_uknown_age->where('tbl_partner_facility.partner_id', $selected_partners); + $appointment_not_honoured_male = $appointment_not_honoured_male->where('tbl_partner_facility.partner_id', $selected_partners); + $appointment_not_honoured_female = $appointment_not_honoured_female->where('tbl_partner_facility.partner_id', $selected_partners); + $appointment_not_honoured_uknown_gender = $appointment_not_honoured_uknown_gender->where('tbl_partner_facility.partner_id', $selected_partners); + $appointment_not_honored_to_nine = $appointment_not_honored_to_nine->where('tbl_partner_facility.partner_id', $selected_partners); + $appointment_not_honored_to_fourteen = $appointment_not_honored_to_fourteen->where('tbl_partner_facility.partner_id', $selected_partners); + $appointment_not_honored_to_nineteen = $appointment_not_honored_to_nineteen->where('tbl_partner_facility.partner_id', $selected_partners); + $appointment_not_honored_to_twentyfour = $appointment_not_honored_to_twentyfour->where('tbl_partner_facility.partner_id', $selected_partners); + $appointment_not_honored_to_twentyfive_above = $appointment_not_honored_to_twentyfive_above->where('tbl_partner_facility.partner_id', $selected_partners); + $appointment_not_honored_to_uknown_age = $appointment_not_honored_to_uknown_age->where('tbl_partner_facility.partner_id', $selected_partners); + } + if (!empty($selected_counties)) { + $appointment = $appointment->where('tbl_partner_facility.county_id', $selected_counties); + $appointment_honoured = $appointment_honoured->where('tbl_partner_facility.county_id', $selected_counties); + $appointment_not_honoured = $appointment_not_honoured->where('tbl_partner_facility.county_id', $selected_counties); + $appointment_honoured_male = $appointment_honoured_male->where('tbl_partner_facility.county_id', $selected_counties); + $appointment_honoured_female = $appointment_honoured_female->where('tbl_partner_facility.county_id', $selected_counties); + $appointment_honoured_uknown_gender = $appointment_honoured_uknown_gender->where('tbl_partner_facility.county_id', $selected_counties); + $appointment_honored_to_nine = $appointment_honored_to_nine->where('tbl_partner_facility.county_id', $selected_counties); + $appointment_honored_to_fourteen = $appointment_honored_to_fourteen->where('tbl_partner_facility.county_id', $selected_counties); + $appointment_honored_to_nineteen = $appointment_honored_to_nineteen->where('tbl_partner_facility.county_id', $selected_counties); + $appointment_honored_to_twentyfour = $appointment_honored_to_twentyfour->where('tbl_partner_facility.county_id', $selected_counties); + $appointment_honored_to_twentyfive_above = $appointment_honored_to_twentyfive_above->where('tbl_partner_facility.county_id', $selected_counties); + $appointment_honored_to_uknown_age = $appointment_honored_to_uknown_age->where('tbl_partner_facility.county_id', $selected_counties); + $appointment_not_honoured_male = $appointment_not_honoured_male->where('tbl_partner_facility.county_id', $selected_counties); + $appointment_not_honoured_female = $appointment_not_honoured_female->where('tbl_partner_facility.county_id', $selected_counties); + $appointment_not_honoured_uknown_gender = $appointment_not_honoured_uknown_gender->where('tbl_partner_facility.county_id', $selected_counties); + $appointment_not_honored_to_nine = $appointment_not_honored_to_nine->where('tbl_partner_facility.county_id', $selected_counties); + $appointment_not_honored_to_fourteen = $appointment_not_honored_to_fourteen->where('tbl_partner_facility.county_id', $selected_counties); + $appointment_not_honored_to_nineteen = $appointment_not_honored_to_nineteen->where('tbl_partner_facility.county_id', $selected_counties); + $appointment_not_honored_to_twentyfour = $appointment_not_honored_to_twentyfour->where('tbl_partner_facility.county_id', $selected_counties); + $appointment_not_honored_to_twentyfive_above = $appointment_not_honored_to_twentyfive_above->where('tbl_partner_facility.county_id', $selected_counties); + $appointment_not_honored_to_uknown_age = $appointment_not_honored_to_uknown_age->where('tbl_partner_facility.county_id', $selected_counties); + } + if (!empty($selected_subcounties)) { + $appointment = $appointment->where('tbl_partner_facility.sub_county_id', $selected_subcounties); + $appointment_honoured = $appointment_honoured->where('tbl_partner_facility.sub_county_id', $selected_subcounties); + $appointment_not_honoured = $appointment_not_honoured->where('tbl_partner_facility.sub_county_id', $selected_subcounties); + $appointment_honoured_male = $appointment_honoured_male->where('tbl_partner_facility.sub_county_id', $selected_subcounties); + $appointment_honoured_female = $appointment_honoured_female->where('tbl_partner_facility.sub_county_id', $selected_subcounties); + $appointment_honoured_uknown_gender = $appointment_honoured_uknown_gender->where('tbl_partner_facility.sub_county_id', $selected_subcounties); + $appointment_honored_to_nine = $appointment_honored_to_nine->where('tbl_partner_facility.sub_county_id', $selected_subcounties); + $appointment_honored_to_fourteen = $appointment_honored_to_fourteen->where('tbl_partner_facility.sub_county_id', $selected_subcounties); + $appointment_honored_to_nineteen = $appointment_honored_to_nineteen->where('tbl_partner_facility.sub_county_id', $selected_subcounties); + $appointment_honored_to_twentyfour = $appointment_honored_to_twentyfour->where('tbl_partner_facility.sub_county_id', $selected_subcounties); + $appointment_honored_to_twentyfive_above = $appointment_honored_to_twentyfive_above->where('tbl_partner_facility.sub_county_id', $selected_subcounties); + $appointment_honored_to_uknown_age = $appointment_honored_to_uknown_age->where('tbl_partner_facility.sub_county_id', $selected_subcounties); + $appointment_not_honoured_male = $appointment_not_honoured_male->where('tbl_partner_facility.sub_county_id', $selected_subcounties); + $appointment_not_honoured_female = $appointment_not_honoured_female->where('tbl_partner_facility.sub_county_id', $selected_subcounties); + $appointment_not_honoured_uknown_gender = $appointment_not_honoured_uknown_gender->where('tbl_partner_facility.sub_county_id', $selected_subcounties); + $appointment_not_honored_to_nine = $appointment_not_honored_to_nine->where('tbl_partner_facility.sub_county_id', $selected_subcounties); + $appointment_not_honored_to_fourteen = $appointment_not_honored_to_fourteen->where('tbl_partner_facility.sub_county_id', $selected_subcounties); + $appointment_not_honored_to_nineteen = $appointment_not_honored_to_nineteen->where('tbl_partner_facility.sub_county_id', $selected_subcounties); + $appointment_not_honored_to_twentyfour = $appointment_not_honored_to_twentyfour->where('tbl_partner_facility.sub_county_id', $selected_subcounties); + $appointment_not_honored_to_twentyfive_above = $appointment_not_honored_to_twentyfive_above->where('tbl_partner_facility.sub_county_id', $selected_subcounties); + $appointment_not_honored_to_uknown_age = $appointment_not_honored_to_uknown_age->where('tbl_partner_facility.sub_county_id', $selected_subcounties); + } + if (!empty($selected_facilites)) { + $appointment = $appointment->where('tbl_partner_facility.mfl_code', $selected_facilites); + $appointment_honoured = $appointment_honoured->where('tbl_partner_facility.mfl_code', $selected_facilites); + $appointment_not_honoured = $appointment_not_honoured->where('tbl_partner_facility.mfl_code', $selected_facilites); + $appointment_honoured_male = $appointment_honoured_male->where('tbl_partner_facility.mfl_code', $selected_facilites); + $appointment_honoured_female = $appointment_honoured_female->where('tbl_partner_facility.mfl_code', $selected_facilites); + $appointment_honoured_uknown_gender = $appointment_honoured_uknown_gender->where('tbl_partner_facility.mfl_code', $selected_facilites); + $appointment_honored_to_nine = $appointment_honored_to_nine->where('tbl_partner_facility.mfl_code', $selected_facilites); + $appointment_honored_to_fourteen = $appointment_honored_to_fourteen->where('tbl_partner_facility.mfl_code', $selected_facilites); + $appointment_honored_to_nineteen = $appointment_honored_to_nineteen->where('tbl_partner_facility.mfl_code', $selected_facilites); + $appointment_honored_to_twentyfour = $appointment_honored_to_twentyfour->where('tbl_partner_facility.mfl_code', $selected_facilites); + $appointment_honored_to_twentyfive_above = $appointment_honored_to_twentyfive_above->where('tbl_partner_facility.mfl_code', $selected_facilites); + $appointment_honored_to_uknown_age = $appointment_honored_to_uknown_age->where('tbl_partner_facility.mfl_code', $selected_facilites); + $appointment_not_honoured_male = $appointment_not_honoured_male->where('tbl_partner_facility.mfl_code', $selected_facilites); + $appointment_not_honoured_female = $appointment_not_honoured_female->where('tbl_partner_facility.mfl_code', $selected_facilites); + $appointment_not_honoured_uknown_gender = $appointment_not_honoured_uknown_gender->where('tbl_partner_facility.mfl_code', $selected_facilites); + $appointment_not_honored_to_nine = $appointment_not_honored_to_nine->where('tbl_partner_facility.mfl_code', $selected_facilites); + $appointment_not_honored_to_fourteen = $appointment_not_honored_to_fourteen->where('tbl_partner_facility.mfl_code', $selected_facilites); + $appointment_not_honored_to_nineteen = $appointment_not_honored_to_nineteen->where('tbl_partner_facility.mfl_code', $selected_facilites); + $appointment_not_honored_to_twentyfour = $appointment_not_honored_to_twentyfour->where('tbl_partner_facility.mfl_code', $selected_facilites); + $appointment_not_honored_to_twentyfive_above = $appointment_not_honored_to_twentyfive_above->where('tbl_partner_facility.mfl_code', $selected_facilites); + $appointment_not_honored_to_uknown_age = $appointment_not_honored_to_uknown_age->where('tbl_partner_facility.mfl_code', $selected_facilites); + } + if (!empty($selected_from || $selected_to)) { + $appointment = $appointment->where('tbl_appointment.created_at', '>=', date($request->from))->where('tbl_appointment.created_at', '<=', date($request->to)); + $appointment_honoured = $appointment_honoured->where('tbl_appointment.created_at', '>=', date($request->from))->where('tbl_appointment.created_at', '<=', date($request->to)); + $appointment_not_honoured = $appointment_not_honoured->where('tbl_appointment.created_at', '>=', date($request->from))->where('tbl_appointment.created_at', '<=', date($request->to)); + $appointment_honoured_male = $appointment_honoured_male->where('tbl_appointment.created_at', '>=', date($request->from))->where('tbl_appointment.created_at', '<=', date($request->to)); + $appointment_honoured_female = $appointment_honoured_female->where('tbl_appointment.created_at', '>=', date($request->from))->where('tbl_appointment.created_at', '<=', date($request->to)); + $appointment_honoured_uknown_gender = $appointment_honoured_uknown_gender->where('tbl_appointment.created_at', '>=', date($request->from))->where('tbl_appointment.created_at', '<=', date($request->to)); + $appointment_honored_to_nine = $appointment_honored_to_nine->where('tbl_appointment.created_at', '>=', date($request->from))->where('tbl_appointment.created_at', '<=', date($request->to)); + $appointment_honored_to_fourteen = $appointment_honored_to_fourteen->where('tbl_appointment.created_at', '>=', date($request->from))->where('tbl_appointment.created_at', '<=', date($request->to)); + $appointment_honored_to_nineteen = $appointment_honored_to_nineteen->where('tbl_appointment.created_at', '>=', date($request->from))->where('tbl_appointment.created_at', '<=', date($request->to)); + $appointment_honored_to_twentyfour = $appointment_honored_to_twentyfour->where('tbl_appointment.created_at', '>=', date($request->from))->where('tbl_appointment.created_at', '<=', date($request->to)); + $appointment_honored_to_twentyfive_above = $appointment_honored_to_twentyfive_above->where('tbl_appointment.created_at', '>=', date($request->from))->where('tbl_appointment.created_at', '<=', date($request->to)); + $appointment_honored_to_uknown_age = $appointment_honored_to_uknown_age->where('tbl_appointment.created_at', '>=', date($request->from))->where('tbl_appointment.created_at', '<=', date($request->to)); + $appointment_not_honoured_male = $appointment_not_honoured_male->where('tbl_appointment.created_at', '>=', date($request->from))->where('tbl_appointment.created_at', '<=', date($request->to)); + $appointment_not_honoured_female = $appointment_not_honoured_female->where('tbl_appointment.created_at', '>=', date($request->from))->where('tbl_appointment.created_at', '<=', date($request->to)); + $appointment_not_honoured_uknown_gender = $appointment_not_honoured_uknown_gender->where('tbl_appointment.created_at', '>=', date($request->from))->where('tbl_appointment.created_at', '<=', date($request->to)); + $appointment_not_honored_to_nine = $appointment_not_honored_to_nine->where('tbl_appointment.created_at', '>=', date($request->from))->where('tbl_appointment.created_at', '<=', date($request->to)); + $appointment_not_honored_to_fourteen = $appointment_not_honored_to_fourteen->where('tbl_appointment.created_at', '>=', date($request->from))->where('tbl_appointment.created_at', '<=', date($request->to)); + $appointment_not_honored_to_nineteen = $appointment_not_honored_to_nineteen->where('tbl_appointment.created_at', '>=', date($request->from))->where('tbl_appointment.created_at', '<=', date($request->to)); + $appointment_not_honored_to_twentyfour = $appointment_not_honored_to_twentyfour->where('tbl_appointment.created_at', '>=', date($request->from))->where('tbl_appointment.created_at', '<=', date($request->to)); + $appointment_not_honored_to_twentyfive_above = $appointment_not_honored_to_twentyfive_above->where('tbl_appointment.created_at', '>=', date($request->from))->where('tbl_appointment.created_at', '<=', date($request->to)); + $appointment_not_honored_to_uknown_age = $appointment_not_honored_to_uknown_age->where('tbl_appointment.created_at', '>=', date($request->from))->where('tbl_appointment.created_at', '<=', date($request->to)); + } + if (!empty($selected_module == 'DSD')) { + $appointment = $appointment->join('tbl_dfc_module', 'tbl_client.id', '=', 'tbl_dfc_module.client_id'); + $appointment_honoured = $appointment_honoured->join('tbl_dfc_module', 'tbl_client.id', '=', 'tbl_dfc_module.client_id'); + $appointment_not_honoured = $appointment_not_honoured->join('tbl_dfc_module', 'tbl_client.id', '=', 'tbl_dfc_module.client_id'); + $appointment_honoured_male = $appointment_honoured_male->join('tbl_dfc_module', 'tbl_client.id', '=', 'tbl_dfc_module.client_id'); + $appointment_honoured_female = $appointment_honoured_female->join('tbl_dfc_module', 'tbl_client.id', '=', 'tbl_dfc_module.client_id'); + $appointment_honoured_uknown_gender = $appointment_honoured_uknown_gender->join('tbl_dfc_module', 'tbl_client.id', '=', 'tbl_dfc_module.client_id'); + $appointment_honored_to_nine = $appointment_honored_to_nine->join('tbl_dfc_module', 'tbl_client.id', '=', 'tbl_dfc_module.client_id'); + $appointment_honored_to_fourteen = $appointment_honored_to_fourteen->join('tbl_dfc_module', 'tbl_client.id', '=', 'tbl_dfc_module.client_id'); + $appointment_honored_to_nineteen = $appointment_honored_to_nineteen->join('tbl_dfc_module', 'tbl_client.id', '=', 'tbl_dfc_module.client_id'); + $appointment_honored_to_twentyfour = $appointment_honored_to_twentyfour->join('tbl_dfc_module', 'tbl_client.id', '=', 'tbl_dfc_module.client_id'); + $appointment_honored_to_twentyfive_above = $appointment_honored_to_twentyfive_above->join('tbl_dfc_module', 'tbl_client.id', '=', 'tbl_dfc_module.client_id'); + $appointment_honored_to_uknown_age = $appointment_honored_to_uknown_age->join('tbl_dfc_module', 'tbl_client.id', '=', 'tbl_dfc_module.client_id'); + $appointment_not_honoured_male = $appointment_not_honoured_male->join('tbl_dfc_module', 'tbl_client.id', '=', 'tbl_dfc_module.client_id'); + $appointment_not_honoured_female = $appointment_not_honoured_female->join('tbl_dfc_module', 'tbl_client.id', '=', 'tbl_dfc_module.client_id'); + $appointment_not_honoured_uknown_gender = $appointment_not_honoured_uknown_gender->join('tbl_dfc_module', 'tbl_client.id', '=', 'tbl_dfc_module.client_id'); + $appointment_not_honored_to_nine = $appointment_not_honored_to_nine->join('tbl_dfc_module', 'tbl_client.id', '=', 'tbl_dfc_module.client_id'); + $appointment_not_honored_to_fourteen = $appointment_not_honored_to_fourteen->join('tbl_dfc_module', 'tbl_client.id', '=', 'tbl_dfc_module.client_id'); + $appointment_not_honored_to_nineteen = $appointment_not_honored_to_nineteen->join('tbl_dfc_module', 'tbl_client.id', '=', 'tbl_dfc_module.client_id'); + $appointment_not_honored_to_twentyfour = $appointment_not_honored_to_twentyfour->join('tbl_dfc_module', 'tbl_client.id', '=', 'tbl_dfc_module.client_id'); + $appointment_not_honored_to_twentyfive_above = $appointment_not_honored_to_twentyfive_above->join('tbl_dfc_module', 'tbl_client.id', '=', 'tbl_dfc_module.client_id'); + $appointment_not_honored_to_uknown_age = $appointment_not_honored_to_uknown_age->join('tbl_dfc_module', 'tbl_client.id', '=', 'tbl_dfc_module.client_id'); + } + if (!empty($selected_module == 'PMTCT')) { + $appointment = $appointment->join('tbl_pmtct', 'tbl_client.id', '=', 'tbl_pmtct.client_id'); + $appointment_honoured = $appointment_honoured->join('tbl_pmtct', 'tbl_client.id', '=', 'tbl_pmtct.client_id'); + $appointment_not_honoured = $appointment_not_honoured->join('tbl_pmtct', 'tbl_client.id', '=', 'tbl_pmtct.client_id'); + $appointment_honoured_male = $appointment_honoured_male->join('tbl_pmtct', 'tbl_client.id', '=', 'tbl_pmtct.client_id'); + $appointment_honoured_female = $appointment_honoured_female->join('tbl_pmtct', 'tbl_client.id', '=', 'tbl_pmtct.client_id'); + $appointment_honoured_uknown_gender = $appointment_honoured_uknown_gender->join('tbl_pmtct', 'tbl_client.id', '=', 'tbl_pmtct.client_id'); + $appointment_honored_to_nine = $appointment_honored_to_nine->join('tbl_pmtct', 'tbl_client.id', '=', 'tbl_pmtct.client_id'); + $appointment_honored_to_fourteen = $appointment_honored_to_fourteen->join('tbl_pmtct', 'tbl_client.id', '=', 'tbl_pmtct.client_id'); + $appointment_honored_to_nineteen = $appointment_honored_to_nineteen->join('tbl_pmtct', 'tbl_client.id', '=', 'tbl_pmtct.client_id'); + $appointment_honored_to_twentyfour = $appointment_honored_to_twentyfour->join('tbl_pmtct', 'tbl_client.id', '=', 'tbl_pmtct.client_id'); + $appointment_honored_to_twentyfive_above = $appointment_honored_to_twentyfive_above->join('tbl_pmtct', 'tbl_client.id', '=', 'tbl_pmtct.client_id'); + $appointment_honored_to_uknown_age = $appointment_honored_to_uknown_age->join('tbl_pmtct', 'tbl_client.id', '=', 'tbl_pmtct.client_id'); + $appointment_not_honoured_male = $appointment_not_honoured_male->join('tbl_pmtct', 'tbl_client.id', '=', 'tbl_pmtct.client_id'); + $appointment_not_honoured_female = $appointment_not_honoured_female->join('tbl_pmtct', 'tbl_client.id', '=', 'tbl_pmtct.client_id'); + $appointment_not_honoured_uknown_gender = $appointment_not_honoured_uknown_gender->join('tbl_pmtct', 'tbl_client.id', '=', 'tbl_pmtct.client_id'); + $appointment_not_honored_to_nine = $appointment_not_honored_to_nine->join('tbl_pmtct', 'tbl_client.id', '=', 'tbl_pmtct.client_id'); + $appointment_not_honored_to_fourteen = $appointment_not_honored_to_fourteen->join('tbl_pmtct', 'tbl_client.id', '=', 'tbl_pmtct.client_id'); + $appointment_not_honored_to_nineteen = $appointment_not_honored_to_nineteen->join('tbl_pmtct', 'tbl_client.id', '=', 'tbl_pmtct.client_id'); + $appointment_not_honored_to_twentyfour = $appointment_not_honored_to_twentyfour->join('tbl_pmtct', 'tbl_client.id', '=', 'tbl_pmtct.client_id'); + $appointment_not_honored_to_twentyfive_above = $appointment_not_honored_to_twentyfive_above->join('tbl_pmtct', 'tbl_client.id', '=', 'tbl_pmtct.client_id'); + $appointment_not_honored_to_uknown_age = $appointment_not_honored_to_uknown_age->join('tbl_pmtct', 'tbl_client.id', '=', 'tbl_pmtct.client_id'); + } - $appointment_not_honoured_uknown_gender = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') - ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') - ->where('tbl_client.gender', '!=', '1') - ->where('tbl_client.gender', '!=', '2') - ->whereIn('app_status', ['Defaulted', 'LTFU', 'Missed']) - ->where('tbl_client.mfl_code', Auth::user()->facility_id); - // appointment not honored by age - $appointment_not_honored_to_nine = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') - ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') - ->select(\DB::raw("count((case when (((year(curdate()) - year(CASE - WHEN ( locate( '/', `tbl_client`.`dob` ) > 0 ) THEN - date_format( str_to_date( `tbl_client`.`dob`, '%m/%d/%Y' ), '%Y-%m-%d' ) - WHEN ( locate( '-', `tbl_client`.`dob` ) > 0 ) THEN - date_format( str_to_date( `tbl_client`.`dob`, '%Y-%m-%d' ), '%Y-%m-%d' ) END)) > 0) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 9)) then `tbl_client`.`id` end)) AS count")) - ->whereIn('app_status', ['Defaulted', 'LTFU', 'Missed']) - ->where('tbl_client.mfl_code', Auth::user()->facility_id); + $data["appointment"] = $appointment->count(); + $data["appointment_honoured"] = $appointment_honoured->count(); + $data["appointment_not_honoured"] = $appointment_not_honoured->count(); + $data["appointment_honoured_male"] = $appointment_honoured_male->count(); + $data["appointment_honoured_female"] = $appointment_honoured_female->count(); + $data["appointment_honoured_uknown_gender"] = $appointment_honoured_uknown_gender->count(); + $data["appointment_honored_to_nine"] = $appointment_honored_to_nine->pluck('count'); + $data["appointment_honored_to_fourteen"] = $appointment_honored_to_fourteen->pluck('count'); + $data["appointment_honored_to_nineteen"] = $appointment_honored_to_nineteen->pluck('count'); + $data["appointment_honored_to_twentyfour"] = $appointment_honored_to_twentyfour->pluck('count'); + $data["appointment_honored_to_twentyfive_above"] = $appointment_honored_to_twentyfive_above->pluck('count'); + $data["appointment_honored_to_uknown_age"] = $appointment_honored_to_uknown_age->count(); + $data["appointment_not_honoured_male"] = $appointment_not_honoured_male->count(); + $data["appointment_not_honoured_female"] = $appointment_not_honoured_female->count(); + $data["appointment_not_honoured_uknown_gender"] = $appointment_not_honoured_uknown_gender->count(); + $data["appointment_not_honored_to_nine"] = $appointment_not_honored_to_nine->pluck('count'); + $data["appointment_not_honored_to_fourteen"] = $appointment_not_honored_to_fourteen->pluck('count'); + $data["appointment_not_honored_to_nineteen"] = $appointment_not_honored_to_nineteen->pluck('count'); + $data["appointment_not_honored_to_twentyfour"] = $appointment_not_honored_to_twentyfour->pluck('count'); + $data["appointment_not_honored_to_twentyfive_above"] = $appointment_not_honored_to_twentyfive_above->pluck('count'); + $data["appointment_not_honored_to_uknown_age"] = $appointment_not_honored_to_uknown_age->count(); - $appointment_not_honored_to_fourteen = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') - ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') - ->select(\DB::raw("count((case when (((year(curdate()) - year(CASE - WHEN ( locate( '/', `tbl_client`.`dob` ) > 0 ) THEN - date_format( str_to_date( `tbl_client`.`dob`, '%m/%d/%Y' ), '%Y-%m-%d' ) - WHEN ( locate( '-', `tbl_client`.`dob` ) > 0 ) THEN - date_format( str_to_date( `tbl_client`.`dob`, '%Y-%m-%d' ), '%Y-%m-%d' ) END)) >= 10) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 14)) then `tbl_client`.`id` end)) AS count")) - ->whereIn('app_status', ['Defaulted', 'LTFU', 'Missed']) - ->where('tbl_client.mfl_code', Auth::user()->facility_id); + return $data; + } + public function filter_missed_appointment_charts(Request $request) + { + $data = []; + // client charts + $selected_partners = $request->partners; + $selected_counties = $request->counties; + $selected_subcounties = $request->subcounties; + $selected_facilites = $request->facilities; + $selected_from = $request->from; + $selected_to = $request->to; + $selected_module = $request->module; - $appointment_not_honored_to_nineteen = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + if (Auth::user()->access_level == 'Facility') { + $appointment_not_honoured = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') - ->select(\DB::raw("count((case when (((year(curdate()) - year(CASE - WHEN ( locate( '/', `tbl_client`.`dob` ) > 0 ) THEN - date_format( str_to_date( `tbl_client`.`dob`, '%m/%d/%Y' ), '%Y-%m-%d' ) - WHEN ( locate( '-', `tbl_client`.`dob` ) > 0 ) THEN - date_format( str_to_date( `tbl_client`.`dob`, '%Y-%m-%d' ), '%Y-%m-%d' ) END)) >= 15) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 19)) then `tbl_client`.`id` end)) AS count")) + ->select(\DB::raw("COUNT(id) as count")) ->whereIn('app_status', ['Defaulted', 'LTFU', 'Missed']) ->where('tbl_client.mfl_code', Auth::user()->facility_id); + // missed appointments - $appointment_not_honored_to_twentyfour = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + $appointment_missed = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') - ->select(\DB::raw("count((case when (((year(curdate()) - year(CASE - WHEN ( locate( '/', `tbl_client`.`dob` ) > 0 ) THEN - date_format( str_to_date( `tbl_client`.`dob`, '%m/%d/%Y' ), '%Y-%m-%d' ) - WHEN ( locate( '-', `tbl_client`.`dob` ) > 0 ) THEN - date_format( str_to_date( `tbl_client`.`dob`, '%Y-%m-%d' ), '%Y-%m-%d' ) END)) >= 20) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 24)) then `tbl_client`.`id` end)) AS count")) - ->whereIn('app_status', ['Defaulted', 'LTFU', 'Missed']) + ->where('app_status', '=', 'Missed') ->where('tbl_client.mfl_code', Auth::user()->facility_id); - $appointment_not_honored_to_twentyfive_above = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + $appointment_defaulted = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') - ->select(\DB::raw("count((case when (((year(curdate()) - year(CASE - WHEN ( locate( '/', `tbl_client`.`dob` ) > 0 ) THEN - date_format( str_to_date( `tbl_client`.`dob`, '%m/%d/%Y' ), '%Y-%m-%d' ) - WHEN ( locate( '-', `tbl_client`.`dob` ) > 0 ) THEN - date_format( str_to_date( `tbl_client`.`dob`, '%Y-%m-%d' ), '%Y-%m-%d' ) END)) >= 25)) then `tbl_client`.`id` end)) AS count")) - ->whereIn('app_status', ['Defaulted', 'LTFU', 'Missed']) + ->where('app_status', '=', 'Defaulted') ->where('tbl_client.mfl_code', Auth::user()->facility_id); - $appointment_not_honored_to_uknown_age = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + $appointment_lftu = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') - ->where(\DB::raw("CASE - WHEN ( locate( '/', `tbl_client`.`dob` ) > 0 ) THEN - date_format( str_to_date( `tbl_client`.`dob`, '%m/%d/%Y' ), '%Y-%m-%d' ) - WHEN ( locate( '-', `tbl_client`.`dob` ) > 0 ) THEN - date_format( str_to_date( `tbl_client`.`dob`, '%Y-%m-%d' ), '%Y-%m-%d' ) END"), '=', '') - ->orWhereNull(\DB::raw("CASE - WHEN ( locate( '/', `tbl_client`.`dob` ) > 0 ) THEN - date_format( str_to_date( `tbl_client`.`dob`, '%m/%d/%Y' ), '%Y-%m-%d' ) - WHEN ( locate( '-', `tbl_client`.`dob` ) > 0 ) THEN - date_format( str_to_date( `tbl_client`.`dob`, '%Y-%m-%d' ), '%Y-%m-%d' ) END")) - ->whereIn('app_status', ['Defaulted', 'LTFU', 'Missed']) + ->where('app_status', '=', 'LTFU') ->where('tbl_client.mfl_code', Auth::user()->facility_id); - } - if (Auth::user()->access_level == 'Partner') { - $appointment = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') - ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') - ->select('tbl_appointment.id') - ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id); - $appointment_honoured = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') - ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') - ->select('tbl_appointment.id') - ->where('tbl_appointment.date_attended', '=', DB::raw('tbl_appointment.appntmnt_date')) - ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id); - $appointment_not_honoured = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + // missed appointment by gender + $appointment_missed_female = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') - ->select('tbl_appointment.id') - ->whereIn('tbl_appointment.app_status', ['Defaulted', 'LTFU', 'Missed']) - ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id); - // appointment honored by gender - $appointment_honoured_male = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->where('tbl_appointment.app_status', '=', 'Missed') + ->where('tbl_client.gender', '=', '1') + ->where('tbl_client.mfl_code', Auth::user()->facility_id); + + $appointment_missed_male = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') - ->select('tbl_appointment.id') - ->where('tbl_appointment.date_attended', '=', DB::raw('tbl_appointment.appntmnt_date')) + ->where('tbl_appointment.app_status', '=', 'Missed') ->where('tbl_client.gender', '=', '2') - ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id); - $appointment_honoured_female = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') - ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') - ->where('tbl_appointment.date_attended', '=', DB::raw('tbl_appointment.appntmnt_date')) - ->where('tbl_client.gender', '=', '1') - ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id); - $appointment_honoured_uknown_gender = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->where('tbl_client.mfl_code', Auth::user()->facility_id); + + $appointment_missed_uknown_gender = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') - ->where('tbl_appointment.date_attended', '=', DB::raw('tbl_appointment.appntmnt_date')) + ->where('tbl_appointment.app_status', '=', 'Missed') ->where('tbl_client.gender', '!=', '1') ->where('tbl_client.gender', '!=', '2') - ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id); - // appointment honored by age - $appointment_honored_to_nine = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->where('tbl_client.mfl_code', Auth::user()->facility_id); + // missed appointment by age + $appointment_missed_to_nine = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') ->select(\DB::raw("count((case when (((year(curdate()) - year(CASE WHEN ( locate( '/', `tbl_client`.`dob` ) > 0 ) THEN date_format( str_to_date( `tbl_client`.`dob`, '%m/%d/%Y' ), '%Y-%m-%d' ) WHEN ( locate( '-', `tbl_client`.`dob` ) > 0 ) THEN date_format( str_to_date( `tbl_client`.`dob`, '%Y-%m-%d' ), '%Y-%m-%d' ) END)) > 0) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 9)) then `tbl_client`.`id` end)) AS count")) - ->where('tbl_appointment.date_attended', '=', DB::raw('tbl_appointment.appntmnt_date')) - ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id); + ->where('tbl_appointment.app_status', '=', 'Missed') + ->where('tbl_client.mfl_code', Auth::user()->facility_id); - $appointment_honored_to_fourteen = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + $appointment_missed_to_fourteen = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') ->select(\DB::raw("count((case when (((year(curdate()) - year(CASE WHEN ( locate( '/', `tbl_client`.`dob` ) > 0 ) THEN date_format( str_to_date( `tbl_client`.`dob`, '%m/%d/%Y' ), '%Y-%m-%d' ) WHEN ( locate( '-', `tbl_client`.`dob` ) > 0 ) THEN date_format( str_to_date( `tbl_client`.`dob`, '%Y-%m-%d' ), '%Y-%m-%d' ) END)) >= 10) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 14)) then `tbl_client`.`id` end)) AS count")) - ->where('tbl_appointment.date_attended', '=', DB::raw('tbl_appointment.appntmnt_date')) - ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id); + ->where('tbl_appointment.app_status', '=', 'Missed') + ->where('tbl_client.mfl_code', Auth::user()->facility_id); - $appointment_honored_to_nineteen = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + $appointment_missed_to_nineteen = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') ->select(\DB::raw("count((case when (((year(curdate()) - year(CASE WHEN ( locate( '/', `tbl_client`.`dob` ) > 0 ) THEN date_format( str_to_date( `tbl_client`.`dob`, '%m/%d/%Y' ), '%Y-%m-%d' ) WHEN ( locate( '-', `tbl_client`.`dob` ) > 0 ) THEN date_format( str_to_date( `tbl_client`.`dob`, '%Y-%m-%d' ), '%Y-%m-%d' ) END)) >= 15) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 19)) then `tbl_client`.`id` end)) AS count")) - ->where('tbl_appointment.date_attended', '=', DB::raw('tbl_appointment.appntmnt_date')) - ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id); + ->where('tbl_appointment.app_status', '=', 'Missed') + ->where('tbl_client.mfl_code', Auth::user()->facility_id); - $appointment_honored_to_twentyfour = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + $appointment_missed_to_twentyfour = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') ->select(\DB::raw("count((case when (((year(curdate()) - year(CASE WHEN ( locate( '/', `tbl_client`.`dob` ) > 0 ) THEN date_format( str_to_date( `tbl_client`.`dob`, '%m/%d/%Y' ), '%Y-%m-%d' ) WHEN ( locate( '-', `tbl_client`.`dob` ) > 0 ) THEN date_format( str_to_date( `tbl_client`.`dob`, '%Y-%m-%d' ), '%Y-%m-%d' ) END)) >= 20) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 24)) then `tbl_client`.`id` end)) AS count")) - ->where('tbl_appointment.date_attended', '=', DB::raw('tbl_appointment.appntmnt_date')) - ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id); + ->where('tbl_appointment.app_status', '=', 'Missed') + ->where('tbl_client.mfl_code', Auth::user()->facility_id); - $appointment_honored_to_twentyfive_above = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + $appointment_missed_to_twentyfive_above = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') ->select(\DB::raw("count((case when (((year(curdate()) - year(CASE WHEN ( locate( '/', `tbl_client`.`dob` ) > 0 ) THEN date_format( str_to_date( `tbl_client`.`dob`, '%m/%d/%Y' ), '%Y-%m-%d' ) WHEN ( locate( '-', `tbl_client`.`dob` ) > 0 ) THEN date_format( str_to_date( `tbl_client`.`dob`, '%Y-%m-%d' ), '%Y-%m-%d' ) END)) >= 25)) then `tbl_client`.`id` end)) AS count")) - ->where('tbl_appointment.date_attended', '=', DB::raw('tbl_appointment.appntmnt_date')) - ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id); - $appointment_honored_to_uknown_age = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->where('tbl_appointment.app_status', '=', 'Missed') + ->where('tbl_client.mfl_code', Auth::user()->facility_id); + + $appointment_missed_to_uknown_age = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') - ->select('tbl_client.dob') - ->where('tbl_appointment.date_attended', '=', DB::raw('tbl_appointment.appntmnt_date')) ->where(\DB::raw("CASE WHEN ( locate( '/', `tbl_client`.`dob` ) > 0 ) THEN date_format( str_to_date( `tbl_client`.`dob`, '%m/%d/%Y' ), '%Y-%m-%d' ) @@ -6176,81 +7728,82 @@ public function filter_appointment_charts(Request $request) date_format( str_to_date( `tbl_client`.`dob`, '%m/%d/%Y' ), '%Y-%m-%d' ) WHEN ( locate( '-', `tbl_client`.`dob` ) > 0 ) THEN date_format( str_to_date( `tbl_client`.`dob`, '%Y-%m-%d' ), '%Y-%m-%d' ) END")) - ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id); + ->where('tbl_appointment.app_status', '=', 'Missed') + ->where('tbl_client.mfl_code', Auth::user()->facility_id); - // appointment not honored by gender - $appointment_not_honoured_male = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + // defaulted appointment by gender + $appointment_defaulted_female = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') - ->where('tbl_client.gender', '=', '2') - ->whereIn('app_status', ['Defaulted', 'LTFU', 'Missed']) - ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id); + ->where('tbl_appointment.app_status', '=', 'Defaulted') + ->where('tbl_client.gender', '=', '1') + ->where('tbl_client.mfl_code', Auth::user()->facility_id); - $appointment_not_honoured_female = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + $appointment_defaulted_male = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') - ->where('tbl_client.gender', '=', '1') - ->whereIn('app_status', ['Defaulted', 'LTFU', 'Missed']) - ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id); + ->where('tbl_appointment.app_status', '=', 'Defaulted') + ->where('tbl_client.gender', '=', '2') + ->where('tbl_client.mfl_code', Auth::user()->facility_id); - $appointment_not_honoured_uknown_gender = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + $appointment_defaulted_uknown_gender = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->where('tbl_appointment.app_status', '=', 'Defaulted') ->where('tbl_client.gender', '!=', '1') ->where('tbl_client.gender', '!=', '2') - ->whereIn('app_status', ['Defaulted', 'LTFU', 'Missed']) - ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id); - // appointment not honored by age - $appointment_not_honored_to_nine = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->where('tbl_client.mfl_code', Auth::user()->facility_id); + + // defaulted appointment by age + $appointment_defaulted_to_nine = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') ->select(\DB::raw("count((case when (((year(curdate()) - year(CASE WHEN ( locate( '/', `tbl_client`.`dob` ) > 0 ) THEN date_format( str_to_date( `tbl_client`.`dob`, '%m/%d/%Y' ), '%Y-%m-%d' ) WHEN ( locate( '-', `tbl_client`.`dob` ) > 0 ) THEN date_format( str_to_date( `tbl_client`.`dob`, '%Y-%m-%d' ), '%Y-%m-%d' ) END)) > 0) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 9)) then `tbl_client`.`id` end)) AS count")) - ->whereIn('app_status', ['Defaulted', 'LTFU', 'Missed']) - ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id); + ->where('tbl_appointment.app_status', '=', 'Defaulted') + ->where('tbl_client.mfl_code', Auth::user()->facility_id); - $appointment_not_honored_to_fourteen = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + $appointment_defaulted_to_fourteen = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') ->select(\DB::raw("count((case when (((year(curdate()) - year(CASE WHEN ( locate( '/', `tbl_client`.`dob` ) > 0 ) THEN date_format( str_to_date( `tbl_client`.`dob`, '%m/%d/%Y' ), '%Y-%m-%d' ) WHEN ( locate( '-', `tbl_client`.`dob` ) > 0 ) THEN date_format( str_to_date( `tbl_client`.`dob`, '%Y-%m-%d' ), '%Y-%m-%d' ) END)) >= 10) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 14)) then `tbl_client`.`id` end)) AS count")) - ->whereIn('app_status', ['Defaulted', 'LTFU', 'Missed']) - ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id); + ->where('tbl_appointment.app_status', '=', 'Defaulted') + ->where('tbl_client.mfl_code', Auth::user()->facility_id); - $appointment_not_honored_to_nineteen = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + $appointment_defaulted_to_nineteen = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') ->select(\DB::raw("count((case when (((year(curdate()) - year(CASE WHEN ( locate( '/', `tbl_client`.`dob` ) > 0 ) THEN date_format( str_to_date( `tbl_client`.`dob`, '%m/%d/%Y' ), '%Y-%m-%d' ) WHEN ( locate( '-', `tbl_client`.`dob` ) > 0 ) THEN date_format( str_to_date( `tbl_client`.`dob`, '%Y-%m-%d' ), '%Y-%m-%d' ) END)) >= 15) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 19)) then `tbl_client`.`id` end)) AS count")) - ->whereIn('app_status', ['Defaulted', 'LTFU', 'Missed']) - ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id); + ->where('tbl_appointment.app_status', '=', 'Defaulted') + ->where('tbl_client.mfl_code', Auth::user()->facility_id); - $appointment_not_honored_to_twentyfour = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + $appointment_defaulted_to_twentyfour = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') ->select(\DB::raw("count((case when (((year(curdate()) - year(CASE WHEN ( locate( '/', `tbl_client`.`dob` ) > 0 ) THEN date_format( str_to_date( `tbl_client`.`dob`, '%m/%d/%Y' ), '%Y-%m-%d' ) WHEN ( locate( '-', `tbl_client`.`dob` ) > 0 ) THEN date_format( str_to_date( `tbl_client`.`dob`, '%Y-%m-%d' ), '%Y-%m-%d' ) END)) >= 20) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 24)) then `tbl_client`.`id` end)) AS count")) - ->whereIn('app_status', ['Defaulted', 'LTFU', 'Missed']) - ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id); + ->where('tbl_appointment.app_status', '=', 'Defaulted') + ->where('tbl_client.mfl_code', Auth::user()->facility_id); - $appointment_not_honored_to_twentyfive_above = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + $appointment_defaulted_to_twentyfive_above = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') ->select(\DB::raw("count((case when (((year(curdate()) - year(CASE WHEN ( locate( '/', `tbl_client`.`dob` ) > 0 ) THEN date_format( str_to_date( `tbl_client`.`dob`, '%m/%d/%Y' ), '%Y-%m-%d' ) WHEN ( locate( '-', `tbl_client`.`dob` ) > 0 ) THEN date_format( str_to_date( `tbl_client`.`dob`, '%Y-%m-%d' ), '%Y-%m-%d' ) END)) >= 25)) then `tbl_client`.`id` end)) AS count")) - ->whereIn('app_status', ['Defaulted', 'LTFU', 'Missed']) - ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id); + ->where('tbl_appointment.app_status', '=', 'Defaulted') + ->where('tbl_client.mfl_code', Auth::user()->facility_id); - $appointment_not_honored_to_uknown_age = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + $appointment_defaulted_to_uknown_age = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') - ->select('tbl_client.dob') ->where(\DB::raw("CASE WHEN ( locate( '/', `tbl_client`.`dob` ) > 0 ) THEN date_format( str_to_date( `tbl_client`.`dob`, '%m/%d/%Y' ), '%Y-%m-%d' ) @@ -6261,85 +7814,82 @@ public function filter_appointment_charts(Request $request) date_format( str_to_date( `tbl_client`.`dob`, '%m/%d/%Y' ), '%Y-%m-%d' ) WHEN ( locate( '-', `tbl_client`.`dob` ) > 0 ) THEN date_format( str_to_date( `tbl_client`.`dob`, '%Y-%m-%d' ), '%Y-%m-%d' ) END")) - ->whereIn('app_status', ['Defaulted', 'LTFU', 'Missed']) - ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id); - } - if (Auth::user()->access_level == 'Admin' || Auth::user()->access_level == 'Donor') { - $appointment = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') - ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') - ->select('tbl_appointment.id'); - $appointment_honoured = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') - ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') - ->select('tbl_appointment.id') - ->where('tbl_appointment.date_attended', '=', DB::raw('tbl_appointment.appntmnt_date')); - $appointment_not_honoured = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') - ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') - ->select('tbl_appointment.id') - ->whereIn('tbl_appointment.app_status', ['Defaulted', 'LTFU', 'Missed']); - // appointment honored by gender - $appointment_honoured_male = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->where('tbl_appointment.app_status', '=', 'Defaulted') + ->where('tbl_client.mfl_code', Auth::user()->facility_id); + + // ltfu appointment by gender + $appointment_ltfu_female = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') - ->select('tbl_appointment.id') - ->where('tbl_appointment.date_attended', '=', DB::raw('tbl_appointment.appntmnt_date')) - ->where('tbl_client.gender', '=', '2'); - $appointment_honoured_female = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->where('tbl_appointment.app_status', '=', 'LTFU') + ->where('tbl_client.gender', '=', '1') + ->where('tbl_client.mfl_code', Auth::user()->facility_id); + + $appointment_ltfu_male = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') - ->where('tbl_appointment.date_attended', '=', DB::raw('tbl_appointment.appntmnt_date')) - ->where('tbl_client.gender', '=', '1'); - $appointment_honoured_uknown_gender = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->where('tbl_appointment.app_status', '=', 'LTFU') + ->where('tbl_client.gender', '=', '2') + ->where('tbl_client.mfl_code', Auth::user()->facility_id); + + $appointment_ltfu_uknown_gender = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') - ->where('tbl_appointment.date_attended', '=', DB::raw('tbl_appointment.appntmnt_date')) + ->where('tbl_appointment.app_status', '=', 'LTFU') ->where('tbl_client.gender', '!=', '1') - ->where('tbl_client.gender', '!=', '2'); - // appointment honored by age - $appointment_honored_to_nine = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->where('tbl_client.gender', '!=', '2') + ->where('tbl_client.mfl_code', Auth::user()->facility_id); + + // ltfu appointment by age + $appointment_ltfu_to_nine = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') ->select(\DB::raw("count((case when (((year(curdate()) - year(CASE WHEN ( locate( '/', `tbl_client`.`dob` ) > 0 ) THEN date_format( str_to_date( `tbl_client`.`dob`, '%m/%d/%Y' ), '%Y-%m-%d' ) WHEN ( locate( '-', `tbl_client`.`dob` ) > 0 ) THEN date_format( str_to_date( `tbl_client`.`dob`, '%Y-%m-%d' ), '%Y-%m-%d' ) END)) > 0) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 9)) then `tbl_client`.`id` end)) AS count")) - ->where('tbl_appointment.date_attended', '=', DB::raw('tbl_appointment.appntmnt_date')); + ->where('tbl_appointment.app_status', '=', 'LTFU') + ->where('tbl_client.mfl_code', Auth::user()->facility_id); - $appointment_honored_to_fourteen = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + $appointment_ltfu_to_fourteen = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') ->select(\DB::raw("count((case when (((year(curdate()) - year(CASE WHEN ( locate( '/', `tbl_client`.`dob` ) > 0 ) THEN date_format( str_to_date( `tbl_client`.`dob`, '%m/%d/%Y' ), '%Y-%m-%d' ) WHEN ( locate( '-', `tbl_client`.`dob` ) > 0 ) THEN date_format( str_to_date( `tbl_client`.`dob`, '%Y-%m-%d' ), '%Y-%m-%d' ) END)) >= 10) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 14)) then `tbl_client`.`id` end)) AS count")) - ->where('tbl_appointment.date_attended', '=', DB::raw('tbl_appointment.appntmnt_date')); + ->where('tbl_appointment.app_status', '=', 'LTFU') + ->where('tbl_client.mfl_code', Auth::user()->facility_id); - $appointment_honored_to_nineteen = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + $appointment_ltfu_to_nineteen = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') ->select(\DB::raw("count((case when (((year(curdate()) - year(CASE WHEN ( locate( '/', `tbl_client`.`dob` ) > 0 ) THEN date_format( str_to_date( `tbl_client`.`dob`, '%m/%d/%Y' ), '%Y-%m-%d' ) WHEN ( locate( '-', `tbl_client`.`dob` ) > 0 ) THEN date_format( str_to_date( `tbl_client`.`dob`, '%Y-%m-%d' ), '%Y-%m-%d' ) END)) >= 15) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 19)) then `tbl_client`.`id` end)) AS count")) - ->where('tbl_appointment.date_attended', '=', DB::raw('tbl_appointment.appntmnt_date')); + ->where('tbl_appointment.app_status', '=', 'LTFU') + ->where('tbl_client.mfl_code', Auth::user()->facility_id); - $appointment_honored_to_twentyfour = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + $appointment_ltfu_to_twentyfour = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') ->select(\DB::raw("count((case when (((year(curdate()) - year(CASE WHEN ( locate( '/', `tbl_client`.`dob` ) > 0 ) THEN date_format( str_to_date( `tbl_client`.`dob`, '%m/%d/%Y' ), '%Y-%m-%d' ) WHEN ( locate( '-', `tbl_client`.`dob` ) > 0 ) THEN date_format( str_to_date( `tbl_client`.`dob`, '%Y-%m-%d' ), '%Y-%m-%d' ) END)) >= 20) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 24)) then `tbl_client`.`id` end)) AS count")) - ->where('tbl_appointment.date_attended', '=', DB::raw('tbl_appointment.appntmnt_date')); + ->where('tbl_appointment.app_status', '=', 'LTFU') + ->where('tbl_client.mfl_code', Auth::user()->facility_id); - $appointment_honored_to_twentyfive_above = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + $appointment_ltfu_to_twentyfive_above = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') ->select(\DB::raw("count((case when (((year(curdate()) - year(CASE WHEN ( locate( '/', `tbl_client`.`dob` ) > 0 ) THEN date_format( str_to_date( `tbl_client`.`dob`, '%m/%d/%Y' ), '%Y-%m-%d' ) WHEN ( locate( '-', `tbl_client`.`dob` ) > 0 ) THEN date_format( str_to_date( `tbl_client`.`dob`, '%Y-%m-%d' ), '%Y-%m-%d' ) END)) >= 25)) then `tbl_client`.`id` end)) AS count")) - ->where('tbl_appointment.date_attended', '=', DB::raw('tbl_appointment.appntmnt_date')); - $appointment_honored_to_uknown_age = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->where('tbl_appointment.app_status', '=', 'LTFU') + ->where('tbl_client.mfl_code', Auth::user()->facility_id); + + $appointment_ltfu_to_uknown_age = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') - ->select('tbl_client.dob') - ->where('tbl_appointment.date_attended', '=', DB::raw('tbl_appointment.appntmnt_date')) ->where(\DB::raw("CASE WHEN ( locate( '/', `tbl_client`.`dob` ) > 0 ) THEN date_format( str_to_date( `tbl_client`.`dob`, '%m/%d/%Y' ), '%Y-%m-%d' ) @@ -6349,71 +7899,103 @@ public function filter_appointment_charts(Request $request) WHEN ( locate( '/', `tbl_client`.`dob` ) > 0 ) THEN date_format( str_to_date( `tbl_client`.`dob`, '%m/%d/%Y' ), '%Y-%m-%d' ) WHEN ( locate( '-', `tbl_client`.`dob` ) > 0 ) THEN - date_format( str_to_date( `tbl_client`.`dob`, '%Y-%m-%d' ), '%Y-%m-%d' ) END")); + date_format( str_to_date( `tbl_client`.`dob`, '%Y-%m-%d' ), '%Y-%m-%d' ) END")) + ->where('tbl_appointment.app_status', '=', 'LTFU') + ->where('tbl_client.mfl_code', Auth::user()->facility_id); + } + if (Auth::user()->access_level == 'Partner') { + $appointment_not_honoured = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select(\DB::raw("COUNT(id) as count")) + ->whereIn('app_status', ['Defaulted', 'LTFU', 'Missed']) + ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id); + // missed appointments - // appointment not honored by gender - $appointment_not_honoured_male = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + $appointment_missed = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') - ->where('tbl_client.gender', '=', '2') - ->whereIn('app_status', ['Defaulted', 'LTFU', 'Missed']); + ->where('app_status', '=', 'Missed') + ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id); - $appointment_not_honoured_female = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + $appointment_defaulted = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->where('app_status', '=', 'Defaulted') + ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id); + + $appointment_lftu = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->where('app_status', '=', 'LTFU') + ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id); + // missed appointment by gender + $appointment_missed_female = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->where('tbl_appointment.app_status', '=', 'Missed') ->where('tbl_client.gender', '=', '1') - ->whereIn('app_status', ['Defaulted', 'LTFU', 'Missed']); + ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id); - $appointment_not_honoured_uknown_gender = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + $appointment_missed_male = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->where('tbl_appointment.app_status', '=', 'Missed') + ->where('tbl_client.gender', '=', '2') + ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id); + + $appointment_missed_uknown_gender = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->where('tbl_appointment.app_status', '=', 'Missed') ->where('tbl_client.gender', '!=', '1') ->where('tbl_client.gender', '!=', '2') - ->whereIn('app_status', ['Defaulted', 'LTFU', 'Missed']); - // appointment not honored by age - $appointment_not_honored_to_nine = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id); + // missed appointment by age + $appointment_missed_to_nine = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') ->select(\DB::raw("count((case when (((year(curdate()) - year(CASE WHEN ( locate( '/', `tbl_client`.`dob` ) > 0 ) THEN date_format( str_to_date( `tbl_client`.`dob`, '%m/%d/%Y' ), '%Y-%m-%d' ) WHEN ( locate( '-', `tbl_client`.`dob` ) > 0 ) THEN date_format( str_to_date( `tbl_client`.`dob`, '%Y-%m-%d' ), '%Y-%m-%d' ) END)) > 0) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 9)) then `tbl_client`.`id` end)) AS count")) - ->whereIn('app_status', ['Defaulted', 'LTFU', 'Missed']); + ->where('tbl_appointment.app_status', '=', 'Missed') + ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id); - $appointment_not_honored_to_fourteen = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + $appointment_missed_to_fourteen = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') ->select(\DB::raw("count((case when (((year(curdate()) - year(CASE WHEN ( locate( '/', `tbl_client`.`dob` ) > 0 ) THEN date_format( str_to_date( `tbl_client`.`dob`, '%m/%d/%Y' ), '%Y-%m-%d' ) WHEN ( locate( '-', `tbl_client`.`dob` ) > 0 ) THEN date_format( str_to_date( `tbl_client`.`dob`, '%Y-%m-%d' ), '%Y-%m-%d' ) END)) >= 10) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 14)) then `tbl_client`.`id` end)) AS count")) - ->whereIn('app_status', ['Defaulted', 'LTFU', 'Missed']); + ->where('tbl_appointment.app_status', '=', 'Missed') + ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id); - $appointment_not_honored_to_nineteen = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + $appointment_missed_to_nineteen = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') ->select(\DB::raw("count((case when (((year(curdate()) - year(CASE WHEN ( locate( '/', `tbl_client`.`dob` ) > 0 ) THEN date_format( str_to_date( `tbl_client`.`dob`, '%m/%d/%Y' ), '%Y-%m-%d' ) WHEN ( locate( '-', `tbl_client`.`dob` ) > 0 ) THEN date_format( str_to_date( `tbl_client`.`dob`, '%Y-%m-%d' ), '%Y-%m-%d' ) END)) >= 15) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 19)) then `tbl_client`.`id` end)) AS count")) - ->whereIn('app_status', ['Defaulted', 'LTFU', 'Missed']); + ->where('tbl_appointment.app_status', '=', 'Missed') + ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id); - $appointment_not_honored_to_twentyfour = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + $appointment_missed_to_twentyfour = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') ->select(\DB::raw("count((case when (((year(curdate()) - year(CASE WHEN ( locate( '/', `tbl_client`.`dob` ) > 0 ) THEN date_format( str_to_date( `tbl_client`.`dob`, '%m/%d/%Y' ), '%Y-%m-%d' ) WHEN ( locate( '-', `tbl_client`.`dob` ) > 0 ) THEN date_format( str_to_date( `tbl_client`.`dob`, '%Y-%m-%d' ), '%Y-%m-%d' ) END)) >= 20) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 24)) then `tbl_client`.`id` end)) AS count")) - ->whereIn('app_status', ['Defaulted', 'LTFU', 'Missed']); + ->where('tbl_appointment.app_status', '=', 'Missed') + ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id); - $appointment_not_honored_to_twentyfive_above = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + $appointment_missed_to_twentyfive_above = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') ->select(\DB::raw("count((case when (((year(curdate()) - year(CASE WHEN ( locate( '/', `tbl_client`.`dob` ) > 0 ) THEN date_format( str_to_date( `tbl_client`.`dob`, '%m/%d/%Y' ), '%Y-%m-%d' ) WHEN ( locate( '-', `tbl_client`.`dob` ) > 0 ) THEN date_format( str_to_date( `tbl_client`.`dob`, '%Y-%m-%d' ), '%Y-%m-%d' ) END)) >= 25)) then `tbl_client`.`id` end)) AS count")) - ->whereIn('app_status', ['Defaulted', 'LTFU', 'Missed']); + ->where('tbl_appointment.app_status', '=', 'Missed') + ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id); - $appointment_not_honored_to_uknown_age = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + $appointment_missed_to_uknown_age = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') ->where(\DB::raw("CASE WHEN ( locate( '/', `tbl_client`.`dob` ) > 0 ) THEN @@ -6425,248 +8007,222 @@ public function filter_appointment_charts(Request $request) date_format( str_to_date( `tbl_client`.`dob`, '%m/%d/%Y' ), '%Y-%m-%d' ) WHEN ( locate( '-', `tbl_client`.`dob` ) > 0 ) THEN date_format( str_to_date( `tbl_client`.`dob`, '%Y-%m-%d' ), '%Y-%m-%d' ) END")) - ->whereIn('app_status', ['Defaulted', 'LTFU', 'Missed']); - } + ->where('tbl_appointment.app_status', '=', 'Missed') + ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id); - if (!empty($selected_partners)) { - $appointment = $appointment->where('tbl_partner_facility.partner_id', $selected_partners); - $appointment_honoured = $appointment_honoured->where('tbl_partner_facility.partner_id', $selected_partners); - $appointment_not_honoured = $appointment_not_honoured->where('tbl_partner_facility.partner_id', $selected_partners); - $appointment_honoured_male = $appointment_honoured_male->where('tbl_partner_facility.partner_id', $selected_partners); - $appointment_honoured_female = $appointment_honoured_female->where('tbl_partner_facility.partner_id', $selected_partners); - $appointment_honoured_uknown_gender = $appointment_honoured_uknown_gender->where('tbl_partner_facility.partner_id', $selected_partners); - $appointment_honored_to_nine = $appointment_honored_to_nine->where('tbl_partner_facility.partner_id', $selected_partners); - $appointment_honored_to_fourteen = $appointment_honored_to_fourteen->where('tbl_partner_facility.partner_id', $selected_partners); - $appointment_honored_to_nineteen = $appointment_honored_to_nineteen->where('tbl_partner_facility.partner_id', $selected_partners); - $appointment_honored_to_twentyfour = $appointment_honored_to_twentyfour->where('tbl_partner_facility.partner_id', $selected_partners); - $appointment_honored_to_twentyfive_above = $appointment_honored_to_twentyfive_above->where('tbl_partner_facility.partner_id', $selected_partners); - $appointment_honored_to_uknown_age = $appointment_honored_to_uknown_age->where('tbl_partner_facility.partner_id', $selected_partners); - $appointment_not_honoured_male = $appointment_not_honoured_male->where('tbl_partner_facility.partner_id', $selected_partners); - $appointment_not_honoured_female = $appointment_not_honoured_female->where('tbl_partner_facility.partner_id', $selected_partners); - $appointment_not_honoured_uknown_gender = $appointment_not_honoured_uknown_gender->where('tbl_partner_facility.partner_id', $selected_partners); - $appointment_not_honored_to_nine = $appointment_not_honored_to_nine->where('tbl_partner_facility.partner_id', $selected_partners); - $appointment_not_honored_to_fourteen = $appointment_not_honored_to_fourteen->where('tbl_partner_facility.partner_id', $selected_partners); - $appointment_not_honored_to_nineteen = $appointment_not_honored_to_nineteen->where('tbl_partner_facility.partner_id', $selected_partners); - $appointment_not_honored_to_twentyfour = $appointment_not_honored_to_twentyfour->where('tbl_partner_facility.partner_id', $selected_partners); - $appointment_not_honored_to_twentyfive_above = $appointment_not_honored_to_twentyfive_above->where('tbl_partner_facility.partner_id', $selected_partners); - $appointment_not_honored_to_uknown_age = $appointment_not_honored_to_uknown_age->where('tbl_partner_facility.partner_id', $selected_partners); - } - if (!empty($selected_counties)) { - $appointment = $appointment->where('tbl_partner_facility.county_id', $selected_counties); - $appointment_honoured = $appointment_honoured->where('tbl_partner_facility.county_id', $selected_counties); - $appointment_not_honoured = $appointment_not_honoured->where('tbl_partner_facility.county_id', $selected_counties); - $appointment_honoured_male = $appointment_honoured_male->where('tbl_partner_facility.county_id', $selected_counties); - $appointment_honoured_female = $appointment_honoured_female->where('tbl_partner_facility.county_id', $selected_counties); - $appointment_honoured_uknown_gender = $appointment_honoured_uknown_gender->where('tbl_partner_facility.county_id', $selected_counties); - $appointment_honored_to_nine = $appointment_honored_to_nine->where('tbl_partner_facility.county_id', $selected_counties); - $appointment_honored_to_fourteen = $appointment_honored_to_fourteen->where('tbl_partner_facility.county_id', $selected_counties); - $appointment_honored_to_nineteen = $appointment_honored_to_nineteen->where('tbl_partner_facility.county_id', $selected_counties); - $appointment_honored_to_twentyfour = $appointment_honored_to_twentyfour->where('tbl_partner_facility.county_id', $selected_counties); - $appointment_honored_to_twentyfive_above = $appointment_honored_to_twentyfive_above->where('tbl_partner_facility.county_id', $selected_counties); - $appointment_honored_to_uknown_age = $appointment_honored_to_uknown_age->where('tbl_partner_facility.county_id', $selected_counties); - $appointment_not_honoured_male = $appointment_not_honoured_male->where('tbl_partner_facility.county_id', $selected_counties); - $appointment_not_honoured_female = $appointment_not_honoured_female->where('tbl_partner_facility.county_id', $selected_counties); - $appointment_not_honoured_uknown_gender = $appointment_not_honoured_uknown_gender->where('tbl_partner_facility.county_id', $selected_counties); - $appointment_not_honored_to_nine = $appointment_not_honored_to_nine->where('tbl_partner_facility.county_id', $selected_counties); - $appointment_not_honored_to_fourteen = $appointment_not_honored_to_fourteen->where('tbl_partner_facility.county_id', $selected_counties); - $appointment_not_honored_to_nineteen = $appointment_not_honored_to_nineteen->where('tbl_partner_facility.county_id', $selected_counties); - $appointment_not_honored_to_twentyfour = $appointment_not_honored_to_twentyfour->where('tbl_partner_facility.county_id', $selected_counties); - $appointment_not_honored_to_twentyfive_above = $appointment_not_honored_to_twentyfive_above->where('tbl_partner_facility.county_id', $selected_counties); - $appointment_not_honored_to_uknown_age = $appointment_not_honored_to_uknown_age->where('tbl_partner_facility.county_id', $selected_counties); - } - if (!empty($selected_subcounties)) { - $appointment = $appointment->where('tbl_partner_facility.sub_county_id', $selected_subcounties); - $appointment_honoured = $appointment_honoured->where('tbl_partner_facility.sub_county_id', $selected_subcounties); - $appointment_not_honoured = $appointment_not_honoured->where('tbl_partner_facility.sub_county_id', $selected_subcounties); - $appointment_honoured_male = $appointment_honoured_male->where('tbl_partner_facility.sub_county_id', $selected_subcounties); - $appointment_honoured_female = $appointment_honoured_female->where('tbl_partner_facility.sub_county_id', $selected_subcounties); - $appointment_honoured_uknown_gender = $appointment_honoured_uknown_gender->where('tbl_partner_facility.sub_county_id', $selected_subcounties); - $appointment_honored_to_nine = $appointment_honored_to_nine->where('tbl_partner_facility.sub_county_id', $selected_subcounties); - $appointment_honored_to_fourteen = $appointment_honored_to_fourteen->where('tbl_partner_facility.sub_county_id', $selected_subcounties); - $appointment_honored_to_nineteen = $appointment_honored_to_nineteen->where('tbl_partner_facility.sub_county_id', $selected_subcounties); - $appointment_honored_to_twentyfour = $appointment_honored_to_twentyfour->where('tbl_partner_facility.sub_county_id', $selected_subcounties); - $appointment_honored_to_twentyfive_above = $appointment_honored_to_twentyfive_above->where('tbl_partner_facility.sub_county_id', $selected_subcounties); - $appointment_honored_to_uknown_age = $appointment_honored_to_uknown_age->where('tbl_partner_facility.sub_county_id', $selected_subcounties); - $appointment_not_honoured_male = $appointment_not_honoured_male->where('tbl_partner_facility.sub_county_id', $selected_subcounties); - $appointment_not_honoured_female = $appointment_not_honoured_female->where('tbl_partner_facility.sub_county_id', $selected_subcounties); - $appointment_not_honoured_uknown_gender = $appointment_not_honoured_uknown_gender->where('tbl_partner_facility.sub_county_id', $selected_subcounties); - $appointment_not_honored_to_nine = $appointment_not_honored_to_nine->where('tbl_partner_facility.sub_county_id', $selected_subcounties); - $appointment_not_honored_to_fourteen = $appointment_not_honored_to_fourteen->where('tbl_partner_facility.sub_county_id', $selected_subcounties); - $appointment_not_honored_to_nineteen = $appointment_not_honored_to_nineteen->where('tbl_partner_facility.sub_county_id', $selected_subcounties); - $appointment_not_honored_to_twentyfour = $appointment_not_honored_to_twentyfour->where('tbl_partner_facility.sub_county_id', $selected_subcounties); - $appointment_not_honored_to_twentyfive_above = $appointment_not_honored_to_twentyfive_above->where('tbl_partner_facility.sub_county_id', $selected_subcounties); - $appointment_not_honored_to_uknown_age = $appointment_not_honored_to_uknown_age->where('tbl_partner_facility.sub_county_id', $selected_subcounties); - } - if (!empty($selected_facilites)) { - $appointment = $appointment->where('tbl_partner_facility.mfl_code', $selected_facilites); - $appointment_honoured = $appointment_honoured->where('tbl_partner_facility.mfl_code', $selected_facilites); - $appointment_not_honoured = $appointment_not_honoured->where('tbl_partner_facility.mfl_code', $selected_facilites); - $appointment_honoured_male = $appointment_honoured_male->where('tbl_partner_facility.mfl_code', $selected_facilites); - $appointment_honoured_female = $appointment_honoured_female->where('tbl_partner_facility.mfl_code', $selected_facilites); - $appointment_honoured_uknown_gender = $appointment_honoured_uknown_gender->where('tbl_partner_facility.mfl_code', $selected_facilites); - $appointment_honored_to_nine = $appointment_honored_to_nine->where('tbl_partner_facility.mfl_code', $selected_facilites); - $appointment_honored_to_fourteen = $appointment_honored_to_fourteen->where('tbl_partner_facility.mfl_code', $selected_facilites); - $appointment_honored_to_nineteen = $appointment_honored_to_nineteen->where('tbl_partner_facility.mfl_code', $selected_facilites); - $appointment_honored_to_twentyfour = $appointment_honored_to_twentyfour->where('tbl_partner_facility.mfl_code', $selected_facilites); - $appointment_honored_to_twentyfive_above = $appointment_honored_to_twentyfive_above->where('tbl_partner_facility.mfl_code', $selected_facilites); - $appointment_honored_to_uknown_age = $appointment_honored_to_uknown_age->where('tbl_partner_facility.mfl_code', $selected_facilites); - $appointment_not_honoured_male = $appointment_not_honoured_male->where('tbl_partner_facility.mfl_code', $selected_facilites); - $appointment_not_honoured_female = $appointment_not_honoured_female->where('tbl_partner_facility.mfl_code', $selected_facilites); - $appointment_not_honoured_uknown_gender = $appointment_not_honoured_uknown_gender->where('tbl_partner_facility.mfl_code', $selected_facilites); - $appointment_not_honored_to_nine = $appointment_not_honored_to_nine->where('tbl_partner_facility.mfl_code', $selected_facilites); - $appointment_not_honored_to_fourteen = $appointment_not_honored_to_fourteen->where('tbl_partner_facility.mfl_code', $selected_facilites); - $appointment_not_honored_to_nineteen = $appointment_not_honored_to_nineteen->where('tbl_partner_facility.mfl_code', $selected_facilites); - $appointment_not_honored_to_twentyfour = $appointment_not_honored_to_twentyfour->where('tbl_partner_facility.mfl_code', $selected_facilites); - $appointment_not_honored_to_twentyfive_above = $appointment_not_honored_to_twentyfive_above->where('tbl_partner_facility.mfl_code', $selected_facilites); - $appointment_not_honored_to_uknown_age = $appointment_not_honored_to_uknown_age->where('tbl_partner_facility.mfl_code', $selected_facilites); - } - if (!empty($selected_from || $selected_to)) { - $appointment = $appointment->where('tbl_appointment.created_at', '>=', date($request->from))->where('tbl_appointment.created_at', '<=', date($request->to)); - $appointment_honoured = $appointment_honoured->where('tbl_appointment.created_at', '>=', date($request->from))->where('tbl_appointment.created_at', '<=', date($request->to)); - $appointment_not_honoured = $appointment_not_honoured->where('tbl_appointment.created_at', '>=', date($request->from))->where('tbl_appointment.created_at', '<=', date($request->to)); - $appointment_honoured_male = $appointment_honoured_male->where('tbl_appointment.created_at', '>=', date($request->from))->where('tbl_appointment.created_at', '<=', date($request->to)); - $appointment_honoured_female = $appointment_honoured_female->where('tbl_appointment.created_at', '>=', date($request->from))->where('tbl_appointment.created_at', '<=', date($request->to)); - $appointment_honoured_uknown_gender = $appointment_honoured_uknown_gender->where('tbl_appointment.created_at', '>=', date($request->from))->where('tbl_appointment.created_at', '<=', date($request->to)); - $appointment_honored_to_nine = $appointment_honored_to_nine->where('tbl_appointment.created_at', '>=', date($request->from))->where('tbl_appointment.created_at', '<=', date($request->to)); - $appointment_honored_to_fourteen = $appointment_honored_to_fourteen->where('tbl_appointment.created_at', '>=', date($request->from))->where('tbl_appointment.created_at', '<=', date($request->to)); - $appointment_honored_to_nineteen = $appointment_honored_to_nineteen->where('tbl_appointment.created_at', '>=', date($request->from))->where('tbl_appointment.created_at', '<=', date($request->to)); - $appointment_honored_to_twentyfour = $appointment_honored_to_twentyfour->where('tbl_appointment.created_at', '>=', date($request->from))->where('tbl_appointment.created_at', '<=', date($request->to)); - $appointment_honored_to_twentyfive_above = $appointment_honored_to_twentyfive_above->where('tbl_appointment.created_at', '>=', date($request->from))->where('tbl_appointment.created_at', '<=', date($request->to)); - $appointment_honored_to_uknown_age = $appointment_honored_to_uknown_age->where('tbl_appointment.created_at', '>=', date($request->from))->where('tbl_appointment.created_at', '<=', date($request->to)); - $appointment_not_honoured_male = $appointment_not_honoured_male->where('tbl_appointment.created_at', '>=', date($request->from))->where('tbl_appointment.created_at', '<=', date($request->to)); - $appointment_not_honoured_female = $appointment_not_honoured_female->where('tbl_appointment.created_at', '>=', date($request->from))->where('tbl_appointment.created_at', '<=', date($request->to)); - $appointment_not_honoured_uknown_gender = $appointment_not_honoured_uknown_gender->where('tbl_appointment.created_at', '>=', date($request->from))->where('tbl_appointment.created_at', '<=', date($request->to)); - $appointment_not_honored_to_nine = $appointment_not_honored_to_nine->where('tbl_appointment.created_at', '>=', date($request->from))->where('tbl_appointment.created_at', '<=', date($request->to)); - $appointment_not_honored_to_fourteen = $appointment_not_honored_to_fourteen->where('tbl_appointment.created_at', '>=', date($request->from))->where('tbl_appointment.created_at', '<=', date($request->to)); - $appointment_not_honored_to_nineteen = $appointment_not_honored_to_nineteen->where('tbl_appointment.created_at', '>=', date($request->from))->where('tbl_appointment.created_at', '<=', date($request->to)); - $appointment_not_honored_to_twentyfour = $appointment_not_honored_to_twentyfour->where('tbl_appointment.created_at', '>=', date($request->from))->where('tbl_appointment.created_at', '<=', date($request->to)); - $appointment_not_honored_to_twentyfive_above = $appointment_not_honored_to_twentyfive_above->where('tbl_appointment.created_at', '>=', date($request->from))->where('tbl_appointment.created_at', '<=', date($request->to)); - $appointment_not_honored_to_uknown_age = $appointment_not_honored_to_uknown_age->where('tbl_appointment.created_at', '>=', date($request->from))->where('tbl_appointment.created_at', '<=', date($request->to)); - } - if (!empty($selected_module == 'DSD')) { - $appointment = $appointment->join('tbl_dfc_module', 'tbl_client.id', '=', 'tbl_dfc_module.client_id'); - $appointment_honoured = $appointment_honoured->join('tbl_dfc_module', 'tbl_client.id', '=', 'tbl_dfc_module.client_id'); - $appointment_not_honoured = $appointment_not_honoured->join('tbl_dfc_module', 'tbl_client.id', '=', 'tbl_dfc_module.client_id'); - $appointment_honoured_male = $appointment_honoured_male->join('tbl_dfc_module', 'tbl_client.id', '=', 'tbl_dfc_module.client_id'); - $appointment_honoured_female = $appointment_honoured_female->join('tbl_dfc_module', 'tbl_client.id', '=', 'tbl_dfc_module.client_id'); - $appointment_honoured_uknown_gender = $appointment_honoured_uknown_gender->join('tbl_dfc_module', 'tbl_client.id', '=', 'tbl_dfc_module.client_id'); - $appointment_honored_to_nine = $appointment_honored_to_nine->join('tbl_dfc_module', 'tbl_client.id', '=', 'tbl_dfc_module.client_id'); - $appointment_honored_to_fourteen = $appointment_honored_to_fourteen->join('tbl_dfc_module', 'tbl_client.id', '=', 'tbl_dfc_module.client_id'); - $appointment_honored_to_nineteen = $appointment_honored_to_nineteen->join('tbl_dfc_module', 'tbl_client.id', '=', 'tbl_dfc_module.client_id'); - $appointment_honored_to_twentyfour = $appointment_honored_to_twentyfour->join('tbl_dfc_module', 'tbl_client.id', '=', 'tbl_dfc_module.client_id'); - $appointment_honored_to_twentyfive_above = $appointment_honored_to_twentyfive_above->join('tbl_dfc_module', 'tbl_client.id', '=', 'tbl_dfc_module.client_id'); - $appointment_honored_to_uknown_age = $appointment_honored_to_uknown_age->join('tbl_dfc_module', 'tbl_client.id', '=', 'tbl_dfc_module.client_id'); - $appointment_not_honoured_male = $appointment_not_honoured_male->join('tbl_dfc_module', 'tbl_client.id', '=', 'tbl_dfc_module.client_id'); - $appointment_not_honoured_female = $appointment_not_honoured_female->join('tbl_dfc_module', 'tbl_client.id', '=', 'tbl_dfc_module.client_id'); - $appointment_not_honoured_uknown_gender = $appointment_not_honoured_uknown_gender->join('tbl_dfc_module', 'tbl_client.id', '=', 'tbl_dfc_module.client_id'); - $appointment_not_honored_to_nine = $appointment_not_honored_to_nine->join('tbl_dfc_module', 'tbl_client.id', '=', 'tbl_dfc_module.client_id'); - $appointment_not_honored_to_fourteen = $appointment_not_honored_to_fourteen->join('tbl_dfc_module', 'tbl_client.id', '=', 'tbl_dfc_module.client_id'); - $appointment_not_honored_to_nineteen = $appointment_not_honored_to_nineteen->join('tbl_dfc_module', 'tbl_client.id', '=', 'tbl_dfc_module.client_id'); - $appointment_not_honored_to_twentyfour = $appointment_not_honored_to_twentyfour->join('tbl_dfc_module', 'tbl_client.id', '=', 'tbl_dfc_module.client_id'); - $appointment_not_honored_to_twentyfive_above = $appointment_not_honored_to_twentyfive_above->join('tbl_dfc_module', 'tbl_client.id', '=', 'tbl_dfc_module.client_id'); - $appointment_not_honored_to_uknown_age = $appointment_not_honored_to_uknown_age->join('tbl_dfc_module', 'tbl_client.id', '=', 'tbl_dfc_module.client_id'); - } - if (!empty($selected_module == 'PMTCT')) { - $appointment = $appointment->join('tbl_pmtct', 'tbl_client.id', '=', 'tbl_pmtct.client_id'); - $appointment_honoured = $appointment_honoured->join('tbl_pmtct', 'tbl_client.id', '=', 'tbl_pmtct.client_id'); - $appointment_not_honoured = $appointment_not_honoured->join('tbl_pmtct', 'tbl_client.id', '=', 'tbl_pmtct.client_id'); - $appointment_honoured_male = $appointment_honoured_male->join('tbl_pmtct', 'tbl_client.id', '=', 'tbl_pmtct.client_id'); - $appointment_honoured_female = $appointment_honoured_female->join('tbl_pmtct', 'tbl_client.id', '=', 'tbl_pmtct.client_id'); - $appointment_honoured_uknown_gender = $appointment_honoured_uknown_gender->join('tbl_pmtct', 'tbl_client.id', '=', 'tbl_pmtct.client_id'); - $appointment_honored_to_nine = $appointment_honored_to_nine->join('tbl_pmtct', 'tbl_client.id', '=', 'tbl_pmtct.client_id'); - $appointment_honored_to_fourteen = $appointment_honored_to_fourteen->join('tbl_pmtct', 'tbl_client.id', '=', 'tbl_pmtct.client_id'); - $appointment_honored_to_nineteen = $appointment_honored_to_nineteen->join('tbl_pmtct', 'tbl_client.id', '=', 'tbl_pmtct.client_id'); - $appointment_honored_to_twentyfour = $appointment_honored_to_twentyfour->join('tbl_pmtct', 'tbl_client.id', '=', 'tbl_pmtct.client_id'); - $appointment_honored_to_twentyfive_above = $appointment_honored_to_twentyfive_above->join('tbl_pmtct', 'tbl_client.id', '=', 'tbl_pmtct.client_id'); - $appointment_honored_to_uknown_age = $appointment_honored_to_uknown_age->join('tbl_pmtct', 'tbl_client.id', '=', 'tbl_pmtct.client_id'); - $appointment_not_honoured_male = $appointment_not_honoured_male->join('tbl_pmtct', 'tbl_client.id', '=', 'tbl_pmtct.client_id'); - $appointment_not_honoured_female = $appointment_not_honoured_female->join('tbl_pmtct', 'tbl_client.id', '=', 'tbl_pmtct.client_id'); - $appointment_not_honoured_uknown_gender = $appointment_not_honoured_uknown_gender->join('tbl_pmtct', 'tbl_client.id', '=', 'tbl_pmtct.client_id'); - $appointment_not_honored_to_nine = $appointment_not_honored_to_nine->join('tbl_pmtct', 'tbl_client.id', '=', 'tbl_pmtct.client_id'); - $appointment_not_honored_to_fourteen = $appointment_not_honored_to_fourteen->join('tbl_pmtct', 'tbl_client.id', '=', 'tbl_pmtct.client_id'); - $appointment_not_honored_to_nineteen = $appointment_not_honored_to_nineteen->join('tbl_pmtct', 'tbl_client.id', '=', 'tbl_pmtct.client_id'); - $appointment_not_honored_to_twentyfour = $appointment_not_honored_to_twentyfour->join('tbl_pmtct', 'tbl_client.id', '=', 'tbl_pmtct.client_id'); - $appointment_not_honored_to_twentyfive_above = $appointment_not_honored_to_twentyfive_above->join('tbl_pmtct', 'tbl_client.id', '=', 'tbl_pmtct.client_id'); - $appointment_not_honored_to_uknown_age = $appointment_not_honored_to_uknown_age->join('tbl_pmtct', 'tbl_client.id', '=', 'tbl_pmtct.client_id'); - } + // defaulted appointment by gender + $appointment_defaulted_female = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->where('tbl_appointment.app_status', '=', 'Defaulted') + ->where('tbl_client.gender', '=', '1') + ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id); + + $appointment_defaulted_male = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->where('tbl_appointment.app_status', '=', 'Defaulted') + ->where('tbl_client.gender', '=', '2') + ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id); + + $appointment_defaulted_uknown_gender = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->where('tbl_appointment.app_status', '=', 'Defaulted') + ->where('tbl_client.gender', '!=', '1') + ->where('tbl_client.gender', '!=', '2') + ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id); - $data["appointment"] = $appointment->count(); - $data["appointment_honoured"] = $appointment_honoured->count(); - $data["appointment_not_honoured"] = $appointment_not_honoured->count(); - $data["appointment_honoured_male"] = $appointment_honoured_male->count(); - $data["appointment_honoured_female"] = $appointment_honoured_female->count(); - $data["appointment_honoured_uknown_gender"] = $appointment_honoured_uknown_gender->count(); - $data["appointment_honored_to_nine"] = $appointment_honored_to_nine->pluck('count'); - $data["appointment_honored_to_fourteen"] = $appointment_honored_to_fourteen->pluck('count'); - $data["appointment_honored_to_nineteen"] = $appointment_honored_to_nineteen->pluck('count'); - $data["appointment_honored_to_twentyfour"] = $appointment_honored_to_twentyfour->pluck('count'); - $data["appointment_honored_to_twentyfive_above"] = $appointment_honored_to_twentyfive_above->pluck('count'); - $data["appointment_honored_to_uknown_age"] = $appointment_honored_to_uknown_age->count(); - $data["appointment_not_honoured_male"] = $appointment_not_honoured_male->count(); - $data["appointment_not_honoured_female"] = $appointment_not_honoured_female->count(); - $data["appointment_not_honoured_uknown_gender"] = $appointment_not_honoured_uknown_gender->count(); - $data["appointment_not_honored_to_nine"] = $appointment_not_honored_to_nine->pluck('count'); - $data["appointment_not_honored_to_fourteen"] = $appointment_not_honored_to_fourteen->pluck('count'); - $data["appointment_not_honored_to_nineteen"] = $appointment_not_honored_to_nineteen->pluck('count'); - $data["appointment_not_honored_to_twentyfour"] = $appointment_not_honored_to_twentyfour->pluck('count'); - $data["appointment_not_honored_to_twentyfive_above"] = $appointment_not_honored_to_twentyfive_above->pluck('count'); - $data["appointment_not_honored_to_uknown_age"] = $appointment_not_honored_to_uknown_age->count(); + // defaulted appointment by age + $appointment_defaulted_to_nine = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select(\DB::raw("count((case when (((year(curdate()) - year(CASE + WHEN ( locate( '/', `tbl_client`.`dob` ) > 0 ) THEN + date_format( str_to_date( `tbl_client`.`dob`, '%m/%d/%Y' ), '%Y-%m-%d' ) + WHEN ( locate( '-', `tbl_client`.`dob` ) > 0 ) THEN + date_format( str_to_date( `tbl_client`.`dob`, '%Y-%m-%d' ), '%Y-%m-%d' ) END)) > 0) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 9)) then `tbl_client`.`id` end)) AS count")) + ->where('tbl_appointment.app_status', '=', 'Defaulted') + ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id); - return $data; - } - public function filter_missed_appointment_charts(Request $request) - { - $data = []; - // client charts - $selected_partners = $request->partners; - $selected_counties = $request->counties; - $selected_subcounties = $request->subcounties; - $selected_facilites = $request->facilities; - $selected_from = $request->from; - $selected_to = $request->to; - $selected_module = $request->module; + $appointment_defaulted_to_fourteen = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select(\DB::raw("count((case when (((year(curdate()) - year(CASE + WHEN ( locate( '/', `tbl_client`.`dob` ) > 0 ) THEN + date_format( str_to_date( `tbl_client`.`dob`, '%m/%d/%Y' ), '%Y-%m-%d' ) + WHEN ( locate( '-', `tbl_client`.`dob` ) > 0 ) THEN + date_format( str_to_date( `tbl_client`.`dob`, '%Y-%m-%d' ), '%Y-%m-%d' ) END)) >= 10) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 14)) then `tbl_client`.`id` end)) AS count")) + ->where('tbl_appointment.app_status', '=', 'Defaulted') + ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id); - if (Auth::user()->access_level == 'Facility') { + $appointment_defaulted_to_nineteen = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select(\DB::raw("count((case when (((year(curdate()) - year(CASE + WHEN ( locate( '/', `tbl_client`.`dob` ) > 0 ) THEN + date_format( str_to_date( `tbl_client`.`dob`, '%m/%d/%Y' ), '%Y-%m-%d' ) + WHEN ( locate( '-', `tbl_client`.`dob` ) > 0 ) THEN + date_format( str_to_date( `tbl_client`.`dob`, '%Y-%m-%d' ), '%Y-%m-%d' ) END)) >= 15) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 19)) then `tbl_client`.`id` end)) AS count")) + ->where('tbl_appointment.app_status', '=', 'Defaulted') + ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id); + + $appointment_defaulted_to_twentyfour = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select(\DB::raw("count((case when (((year(curdate()) - year(CASE + WHEN ( locate( '/', `tbl_client`.`dob` ) > 0 ) THEN + date_format( str_to_date( `tbl_client`.`dob`, '%m/%d/%Y' ), '%Y-%m-%d' ) + WHEN ( locate( '-', `tbl_client`.`dob` ) > 0 ) THEN + date_format( str_to_date( `tbl_client`.`dob`, '%Y-%m-%d' ), '%Y-%m-%d' ) END)) >= 20) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 24)) then `tbl_client`.`id` end)) AS count")) + ->where('tbl_appointment.app_status', '=', 'Defaulted') + ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id); + + $appointment_defaulted_to_twentyfive_above = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select(\DB::raw("count((case when (((year(curdate()) - year(CASE + WHEN ( locate( '/', `tbl_client`.`dob` ) > 0 ) THEN + date_format( str_to_date( `tbl_client`.`dob`, '%m/%d/%Y' ), '%Y-%m-%d' ) + WHEN ( locate( '-', `tbl_client`.`dob` ) > 0 ) THEN + date_format( str_to_date( `tbl_client`.`dob`, '%Y-%m-%d' ), '%Y-%m-%d' ) END)) >= 25)) then `tbl_client`.`id` end)) AS count")) + ->where('tbl_appointment.app_status', '=', 'Defaulted') + ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id); + + $appointment_defaulted_to_uknown_age = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->where(\DB::raw("CASE + WHEN ( locate( '/', `tbl_client`.`dob` ) > 0 ) THEN + date_format( str_to_date( `tbl_client`.`dob`, '%m/%d/%Y' ), '%Y-%m-%d' ) + WHEN ( locate( '-', `tbl_client`.`dob` ) > 0 ) THEN + date_format( str_to_date( `tbl_client`.`dob`, '%Y-%m-%d' ), '%Y-%m-%d' ) END"), '=', '') + ->orWhereNull(\DB::raw("CASE + WHEN ( locate( '/', `tbl_client`.`dob` ) > 0 ) THEN + date_format( str_to_date( `tbl_client`.`dob`, '%m/%d/%Y' ), '%Y-%m-%d' ) + WHEN ( locate( '-', `tbl_client`.`dob` ) > 0 ) THEN + date_format( str_to_date( `tbl_client`.`dob`, '%Y-%m-%d' ), '%Y-%m-%d' ) END")) + ->where('tbl_appointment.app_status', '=', 'Defaulted') + ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id); + + // ltfu appointment by gender + $appointment_ltfu_female = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->where('tbl_appointment.app_status', '=', 'LTFU') + ->where('tbl_client.gender', '=', '1') + ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id); + + $appointment_ltfu_male = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->where('tbl_appointment.app_status', '=', 'LTFU') + ->where('tbl_client.gender', '=', '2') + ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id); + + $appointment_ltfu_uknown_gender = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->where('tbl_appointment.app_status', '=', 'LTFU') + ->where('tbl_client.gender', '!=', '1') + ->where('tbl_client.gender', '!=', '2') + ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id); + + // ltfu appointment by age + $appointment_ltfu_to_nine = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select(\DB::raw("count((case when (((year(curdate()) - year(CASE + WHEN ( locate( '/', `tbl_client`.`dob` ) > 0 ) THEN + date_format( str_to_date( `tbl_client`.`dob`, '%m/%d/%Y' ), '%Y-%m-%d' ) + WHEN ( locate( '-', `tbl_client`.`dob` ) > 0 ) THEN + date_format( str_to_date( `tbl_client`.`dob`, '%Y-%m-%d' ), '%Y-%m-%d' ) END)) > 0) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 9)) then `tbl_client`.`id` end)) AS count")) + ->where('tbl_appointment.app_status', '=', 'LTFU') + ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id); + + $appointment_ltfu_to_fourteen = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select(\DB::raw("count((case when (((year(curdate()) - year(CASE + WHEN ( locate( '/', `tbl_client`.`dob` ) > 0 ) THEN + date_format( str_to_date( `tbl_client`.`dob`, '%m/%d/%Y' ), '%Y-%m-%d' ) + WHEN ( locate( '-', `tbl_client`.`dob` ) > 0 ) THEN + date_format( str_to_date( `tbl_client`.`dob`, '%Y-%m-%d' ), '%Y-%m-%d' ) END)) >= 10) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 14)) then `tbl_client`.`id` end)) AS count")) + ->where('tbl_appointment.app_status', '=', 'LTFU') + ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id); + + $appointment_ltfu_to_nineteen = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select(\DB::raw("count((case when (((year(curdate()) - year(CASE + WHEN ( locate( '/', `tbl_client`.`dob` ) > 0 ) THEN + date_format( str_to_date( `tbl_client`.`dob`, '%m/%d/%Y' ), '%Y-%m-%d' ) + WHEN ( locate( '-', `tbl_client`.`dob` ) > 0 ) THEN + date_format( str_to_date( `tbl_client`.`dob`, '%Y-%m-%d' ), '%Y-%m-%d' ) END)) >= 15) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 19)) then `tbl_client`.`id` end)) AS count")) + ->where('tbl_appointment.app_status', '=', 'LTFU') + ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id); + + $appointment_ltfu_to_twentyfour = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select(\DB::raw("count((case when (((year(curdate()) - year(CASE + WHEN ( locate( '/', `tbl_client`.`dob` ) > 0 ) THEN + date_format( str_to_date( `tbl_client`.`dob`, '%m/%d/%Y' ), '%Y-%m-%d' ) + WHEN ( locate( '-', `tbl_client`.`dob` ) > 0 ) THEN + date_format( str_to_date( `tbl_client`.`dob`, '%Y-%m-%d' ), '%Y-%m-%d' ) END)) >= 20) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 24)) then `tbl_client`.`id` end)) AS count")) + ->where('tbl_appointment.app_status', '=', 'LTFU') + ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id); + + $appointment_ltfu_to_twentyfive_above = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->select(\DB::raw("count((case when (((year(curdate()) - year(CASE + WHEN ( locate( '/', `tbl_client`.`dob` ) > 0 ) THEN + date_format( str_to_date( `tbl_client`.`dob`, '%m/%d/%Y' ), '%Y-%m-%d' ) + WHEN ( locate( '-', `tbl_client`.`dob` ) > 0 ) THEN + date_format( str_to_date( `tbl_client`.`dob`, '%Y-%m-%d' ), '%Y-%m-%d' ) END)) >= 25)) then `tbl_client`.`id` end)) AS count")) + ->where('tbl_appointment.app_status', '=', 'LTFU') + ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id); + + $appointment_ltfu_to_uknown_age = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') + ->where(\DB::raw("CASE + WHEN ( locate( '/', `tbl_client`.`dob` ) > 0 ) THEN + date_format( str_to_date( `tbl_client`.`dob`, '%m/%d/%Y' ), '%Y-%m-%d' ) + WHEN ( locate( '-', `tbl_client`.`dob` ) > 0 ) THEN + date_format( str_to_date( `tbl_client`.`dob`, '%Y-%m-%d' ), '%Y-%m-%d' ) END"), '=', '') + ->orWhereNull(\DB::raw("CASE + WHEN ( locate( '/', `tbl_client`.`dob` ) > 0 ) THEN + date_format( str_to_date( `tbl_client`.`dob`, '%m/%d/%Y' ), '%Y-%m-%d' ) + WHEN ( locate( '-', `tbl_client`.`dob` ) > 0 ) THEN + date_format( str_to_date( `tbl_client`.`dob`, '%Y-%m-%d' ), '%Y-%m-%d' ) END")) + ->where('tbl_appointment.app_status', '=', 'LTFU') + ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id); + } + if (Auth::user()->access_level == 'Sub County') { $appointment_not_honoured = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') ->select(\DB::raw("COUNT(id) as count")) ->whereIn('app_status', ['Defaulted', 'LTFU', 'Missed']) - ->where('tbl_client.mfl_code', Auth::user()->facility_id); + ->where('tbl_partner_facility.sub_county_id', Auth::user()->subcounty_id); // missed appointments $appointment_missed = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') ->where('app_status', '=', 'Missed') - ->where('tbl_client.mfl_code', Auth::user()->facility_id); + ->where('tbl_partner_facility.sub_county_id', Auth::user()->subcounty_id); $appointment_defaulted = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') ->where('app_status', '=', 'Defaulted') - ->where('tbl_client.mfl_code', Auth::user()->facility_id); + ->where('tbl_partner_facility.sub_county_id', Auth::user()->subcounty_id); $appointment_lftu = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') ->where('app_status', '=', 'LTFU') - ->where('tbl_client.mfl_code', Auth::user()->facility_id); + ->where('tbl_partner_facility.sub_county_id', Auth::user()->subcounty_id); // missed appointment by gender $appointment_missed_female = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') ->where('tbl_appointment.app_status', '=', 'Missed') ->where('tbl_client.gender', '=', '1') - ->where('tbl_client.mfl_code', Auth::user()->facility_id); + ->where('tbl_partner_facility.sub_county_id', Auth::user()->subcounty_id); $appointment_missed_male = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') ->where('tbl_appointment.app_status', '=', 'Missed') ->where('tbl_client.gender', '=', '2') - ->where('tbl_client.mfl_code', Auth::user()->facility_id); + ->where('tbl_partner_facility.sub_county_id', Auth::user()->subcounty_id); $appointment_missed_uknown_gender = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') ->where('tbl_appointment.app_status', '=', 'Missed') ->where('tbl_client.gender', '!=', '1') ->where('tbl_client.gender', '!=', '2') - ->where('tbl_client.mfl_code', Auth::user()->facility_id); + ->where('tbl_partner_facility.sub_county_id', Auth::user()->subcounty_id); // missed appointment by age $appointment_missed_to_nine = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') @@ -6676,7 +8232,7 @@ public function filter_missed_appointment_charts(Request $request) WHEN ( locate( '-', `tbl_client`.`dob` ) > 0 ) THEN date_format( str_to_date( `tbl_client`.`dob`, '%Y-%m-%d' ), '%Y-%m-%d' ) END)) > 0) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 9)) then `tbl_client`.`id` end)) AS count")) ->where('tbl_appointment.app_status', '=', 'Missed') - ->where('tbl_client.mfl_code', Auth::user()->facility_id); + ->where('tbl_partner_facility.sub_county_id', Auth::user()->subcounty_id); $appointment_missed_to_fourteen = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') @@ -6686,7 +8242,7 @@ public function filter_missed_appointment_charts(Request $request) WHEN ( locate( '-', `tbl_client`.`dob` ) > 0 ) THEN date_format( str_to_date( `tbl_client`.`dob`, '%Y-%m-%d' ), '%Y-%m-%d' ) END)) >= 10) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 14)) then `tbl_client`.`id` end)) AS count")) ->where('tbl_appointment.app_status', '=', 'Missed') - ->where('tbl_client.mfl_code', Auth::user()->facility_id); + ->where('tbl_partner_facility.sub_county_id', Auth::user()->subcounty_id); $appointment_missed_to_nineteen = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') @@ -6696,7 +8252,7 @@ public function filter_missed_appointment_charts(Request $request) WHEN ( locate( '-', `tbl_client`.`dob` ) > 0 ) THEN date_format( str_to_date( `tbl_client`.`dob`, '%Y-%m-%d' ), '%Y-%m-%d' ) END)) >= 15) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 19)) then `tbl_client`.`id` end)) AS count")) ->where('tbl_appointment.app_status', '=', 'Missed') - ->where('tbl_client.mfl_code', Auth::user()->facility_id); + ->where('tbl_partner_facility.sub_county_id', Auth::user()->subcounty_id); $appointment_missed_to_twentyfour = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') @@ -6706,7 +8262,7 @@ public function filter_missed_appointment_charts(Request $request) WHEN ( locate( '-', `tbl_client`.`dob` ) > 0 ) THEN date_format( str_to_date( `tbl_client`.`dob`, '%Y-%m-%d' ), '%Y-%m-%d' ) END)) >= 20) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 24)) then `tbl_client`.`id` end)) AS count")) ->where('tbl_appointment.app_status', '=', 'Missed') - ->where('tbl_client.mfl_code', Auth::user()->facility_id); + ->where('tbl_partner_facility.sub_county_id', Auth::user()->subcounty_id); $appointment_missed_to_twentyfive_above = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') @@ -6716,7 +8272,7 @@ public function filter_missed_appointment_charts(Request $request) WHEN ( locate( '-', `tbl_client`.`dob` ) > 0 ) THEN date_format( str_to_date( `tbl_client`.`dob`, '%Y-%m-%d' ), '%Y-%m-%d' ) END)) >= 25)) then `tbl_client`.`id` end)) AS count")) ->where('tbl_appointment.app_status', '=', 'Missed') - ->where('tbl_client.mfl_code', Auth::user()->facility_id); + ->where('tbl_partner_facility.sub_county_id', Auth::user()->subcounty_id); $appointment_missed_to_uknown_age = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') @@ -6731,27 +8287,27 @@ public function filter_missed_appointment_charts(Request $request) WHEN ( locate( '-', `tbl_client`.`dob` ) > 0 ) THEN date_format( str_to_date( `tbl_client`.`dob`, '%Y-%m-%d' ), '%Y-%m-%d' ) END")) ->where('tbl_appointment.app_status', '=', 'Missed') - ->where('tbl_client.mfl_code', Auth::user()->facility_id); + ->where('tbl_partner_facility.sub_county_id', Auth::user()->subcounty_id); // defaulted appointment by gender $appointment_defaulted_female = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') ->where('tbl_appointment.app_status', '=', 'Defaulted') ->where('tbl_client.gender', '=', '1') - ->where('tbl_client.mfl_code', Auth::user()->facility_id); + ->where('tbl_partner_facility.sub_county_id', Auth::user()->subcounty_id); $appointment_defaulted_male = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') ->where('tbl_appointment.app_status', '=', 'Defaulted') ->where('tbl_client.gender', '=', '2') - ->where('tbl_client.mfl_code', Auth::user()->facility_id); + ->where('tbl_partner_facility.sub_county_id', Auth::user()->subcounty_id); $appointment_defaulted_uknown_gender = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') ->where('tbl_appointment.app_status', '=', 'Defaulted') ->where('tbl_client.gender', '!=', '1') ->where('tbl_client.gender', '!=', '2') - ->where('tbl_client.mfl_code', Auth::user()->facility_id); + ->where('tbl_partner_facility.sub_county_id', Auth::user()->subcounty_id); // defaulted appointment by age $appointment_defaulted_to_nine = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') @@ -6762,7 +8318,7 @@ public function filter_missed_appointment_charts(Request $request) WHEN ( locate( '-', `tbl_client`.`dob` ) > 0 ) THEN date_format( str_to_date( `tbl_client`.`dob`, '%Y-%m-%d' ), '%Y-%m-%d' ) END)) > 0) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 9)) then `tbl_client`.`id` end)) AS count")) ->where('tbl_appointment.app_status', '=', 'Defaulted') - ->where('tbl_client.mfl_code', Auth::user()->facility_id); + ->where('tbl_partner_facility.sub_county_id', Auth::user()->subcounty_id); $appointment_defaulted_to_fourteen = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') @@ -6772,7 +8328,7 @@ public function filter_missed_appointment_charts(Request $request) WHEN ( locate( '-', `tbl_client`.`dob` ) > 0 ) THEN date_format( str_to_date( `tbl_client`.`dob`, '%Y-%m-%d' ), '%Y-%m-%d' ) END)) >= 10) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 14)) then `tbl_client`.`id` end)) AS count")) ->where('tbl_appointment.app_status', '=', 'Defaulted') - ->where('tbl_client.mfl_code', Auth::user()->facility_id); + ->where('tbl_partner_facility.sub_county_id', Auth::user()->subcounty_id); $appointment_defaulted_to_nineteen = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') @@ -6782,7 +8338,7 @@ public function filter_missed_appointment_charts(Request $request) WHEN ( locate( '-', `tbl_client`.`dob` ) > 0 ) THEN date_format( str_to_date( `tbl_client`.`dob`, '%Y-%m-%d' ), '%Y-%m-%d' ) END)) >= 15) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 19)) then `tbl_client`.`id` end)) AS count")) ->where('tbl_appointment.app_status', '=', 'Defaulted') - ->where('tbl_client.mfl_code', Auth::user()->facility_id); + ->where('tbl_partner_facility.sub_county_id', Auth::user()->subcounty_id); $appointment_defaulted_to_twentyfour = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') @@ -6792,7 +8348,7 @@ public function filter_missed_appointment_charts(Request $request) WHEN ( locate( '-', `tbl_client`.`dob` ) > 0 ) THEN date_format( str_to_date( `tbl_client`.`dob`, '%Y-%m-%d' ), '%Y-%m-%d' ) END)) >= 20) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 24)) then `tbl_client`.`id` end)) AS count")) ->where('tbl_appointment.app_status', '=', 'Defaulted') - ->where('tbl_client.mfl_code', Auth::user()->facility_id); + ->where('tbl_partner_facility.sub_county_id', Auth::user()->subcounty_id); $appointment_defaulted_to_twentyfive_above = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') @@ -6802,7 +8358,7 @@ public function filter_missed_appointment_charts(Request $request) WHEN ( locate( '-', `tbl_client`.`dob` ) > 0 ) THEN date_format( str_to_date( `tbl_client`.`dob`, '%Y-%m-%d' ), '%Y-%m-%d' ) END)) >= 25)) then `tbl_client`.`id` end)) AS count")) ->where('tbl_appointment.app_status', '=', 'Defaulted') - ->where('tbl_client.mfl_code', Auth::user()->facility_id); + ->where('tbl_partner_facility.sub_county_id', Auth::user()->subcounty_id); $appointment_defaulted_to_uknown_age = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') @@ -6817,27 +8373,27 @@ public function filter_missed_appointment_charts(Request $request) WHEN ( locate( '-', `tbl_client`.`dob` ) > 0 ) THEN date_format( str_to_date( `tbl_client`.`dob`, '%Y-%m-%d' ), '%Y-%m-%d' ) END")) ->where('tbl_appointment.app_status', '=', 'Defaulted') - ->where('tbl_client.mfl_code', Auth::user()->facility_id); + ->where('tbl_partner_facility.sub_county_id', Auth::user()->subcounty_id); // ltfu appointment by gender $appointment_ltfu_female = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') ->where('tbl_appointment.app_status', '=', 'LTFU') ->where('tbl_client.gender', '=', '1') - ->where('tbl_client.mfl_code', Auth::user()->facility_id); + ->where('tbl_partner_facility.sub_county_id', Auth::user()->subcounty_id); $appointment_ltfu_male = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') ->where('tbl_appointment.app_status', '=', 'LTFU') ->where('tbl_client.gender', '=', '2') - ->where('tbl_client.mfl_code', Auth::user()->facility_id); + ->where('tbl_partner_facility.sub_county_id', Auth::user()->subcounty_id); $appointment_ltfu_uknown_gender = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') ->where('tbl_appointment.app_status', '=', 'LTFU') ->where('tbl_client.gender', '!=', '1') ->where('tbl_client.gender', '!=', '2') - ->where('tbl_client.mfl_code', Auth::user()->facility_id); + ->where('tbl_partner_facility.sub_county_id', Auth::user()->subcounty_id); // ltfu appointment by age $appointment_ltfu_to_nine = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') @@ -6848,7 +8404,7 @@ public function filter_missed_appointment_charts(Request $request) WHEN ( locate( '-', `tbl_client`.`dob` ) > 0 ) THEN date_format( str_to_date( `tbl_client`.`dob`, '%Y-%m-%d' ), '%Y-%m-%d' ) END)) > 0) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 9)) then `tbl_client`.`id` end)) AS count")) ->where('tbl_appointment.app_status', '=', 'LTFU') - ->where('tbl_client.mfl_code', Auth::user()->facility_id); + ->where('tbl_partner_facility.sub_county_id', Auth::user()->subcounty_id); $appointment_ltfu_to_fourteen = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') @@ -6858,7 +8414,7 @@ public function filter_missed_appointment_charts(Request $request) WHEN ( locate( '-', `tbl_client`.`dob` ) > 0 ) THEN date_format( str_to_date( `tbl_client`.`dob`, '%Y-%m-%d' ), '%Y-%m-%d' ) END)) >= 10) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 14)) then `tbl_client`.`id` end)) AS count")) ->where('tbl_appointment.app_status', '=', 'LTFU') - ->where('tbl_client.mfl_code', Auth::user()->facility_id); + ->where('tbl_partner_facility.sub_county_id', Auth::user()->subcounty_id); $appointment_ltfu_to_nineteen = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') @@ -6868,7 +8424,7 @@ public function filter_missed_appointment_charts(Request $request) WHEN ( locate( '-', `tbl_client`.`dob` ) > 0 ) THEN date_format( str_to_date( `tbl_client`.`dob`, '%Y-%m-%d' ), '%Y-%m-%d' ) END)) >= 15) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 19)) then `tbl_client`.`id` end)) AS count")) ->where('tbl_appointment.app_status', '=', 'LTFU') - ->where('tbl_client.mfl_code', Auth::user()->facility_id); + ->where('tbl_partner_facility.sub_county_id', Auth::user()->subcounty_id); $appointment_ltfu_to_twentyfour = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') @@ -6878,7 +8434,7 @@ public function filter_missed_appointment_charts(Request $request) WHEN ( locate( '-', `tbl_client`.`dob` ) > 0 ) THEN date_format( str_to_date( `tbl_client`.`dob`, '%Y-%m-%d' ), '%Y-%m-%d' ) END)) >= 20) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 24)) then `tbl_client`.`id` end)) AS count")) ->where('tbl_appointment.app_status', '=', 'LTFU') - ->where('tbl_client.mfl_code', Auth::user()->facility_id); + ->where('tbl_partner_facility.sub_county_id', Auth::user()->subcounty_id); $appointment_ltfu_to_twentyfive_above = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') @@ -6888,7 +8444,7 @@ public function filter_missed_appointment_charts(Request $request) WHEN ( locate( '-', `tbl_client`.`dob` ) > 0 ) THEN date_format( str_to_date( `tbl_client`.`dob`, '%Y-%m-%d' ), '%Y-%m-%d' ) END)) >= 25)) then `tbl_client`.`id` end)) AS count")) ->where('tbl_appointment.app_status', '=', 'LTFU') - ->where('tbl_client.mfl_code', Auth::user()->facility_id); + ->where('tbl_partner_facility.sub_county_id', Auth::user()->subcounty_id); $appointment_ltfu_to_uknown_age = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') @@ -6903,49 +8459,49 @@ public function filter_missed_appointment_charts(Request $request) WHEN ( locate( '-', `tbl_client`.`dob` ) > 0 ) THEN date_format( str_to_date( `tbl_client`.`dob`, '%Y-%m-%d' ), '%Y-%m-%d' ) END")) ->where('tbl_appointment.app_status', '=', 'LTFU') - ->where('tbl_client.mfl_code', Auth::user()->facility_id); + ->where('tbl_partner_facility.sub_county_id', Auth::user()->subcounty_id); } - if (Auth::user()->access_level == 'Partner') { + if (Auth::user()->access_level == 'County') { $appointment_not_honoured = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') ->select(\DB::raw("COUNT(id) as count")) ->whereIn('app_status', ['Defaulted', 'LTFU', 'Missed']) - ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id); + ->where('tbl_partner_facility.county_id', Auth::user()->county_id); // missed appointments $appointment_missed = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') ->where('app_status', '=', 'Missed') - ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id); + ->where('tbl_partner_facility.county_id', Auth::user()->county_id); $appointment_defaulted = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') ->where('app_status', '=', 'Defaulted') - ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id); + ->where('tbl_partner_facility.county_id', Auth::user()->county_id); $appointment_lftu = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') ->where('app_status', '=', 'LTFU') - ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id); + ->where('tbl_partner_facility.county_id', Auth::user()->county_id); // missed appointment by gender $appointment_missed_female = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') ->where('tbl_appointment.app_status', '=', 'Missed') ->where('tbl_client.gender', '=', '1') - ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id); + ->where('tbl_partner_facility.county_id', Auth::user()->county_id); $appointment_missed_male = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') ->where('tbl_appointment.app_status', '=', 'Missed') ->where('tbl_client.gender', '=', '2') - ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id); + ->where('tbl_partner_facility.county_id', Auth::user()->county_id); $appointment_missed_uknown_gender = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') ->where('tbl_appointment.app_status', '=', 'Missed') ->where('tbl_client.gender', '!=', '1') ->where('tbl_client.gender', '!=', '2') - ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id); + ->where('tbl_partner_facility.county_id', Auth::user()->county_id); // missed appointment by age $appointment_missed_to_nine = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') @@ -6955,7 +8511,7 @@ public function filter_missed_appointment_charts(Request $request) WHEN ( locate( '-', `tbl_client`.`dob` ) > 0 ) THEN date_format( str_to_date( `tbl_client`.`dob`, '%Y-%m-%d' ), '%Y-%m-%d' ) END)) > 0) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 9)) then `tbl_client`.`id` end)) AS count")) ->where('tbl_appointment.app_status', '=', 'Missed') - ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id); + ->where('tbl_partner_facility.county_id', Auth::user()->county_id); $appointment_missed_to_fourteen = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') @@ -6965,7 +8521,7 @@ public function filter_missed_appointment_charts(Request $request) WHEN ( locate( '-', `tbl_client`.`dob` ) > 0 ) THEN date_format( str_to_date( `tbl_client`.`dob`, '%Y-%m-%d' ), '%Y-%m-%d' ) END)) >= 10) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 14)) then `tbl_client`.`id` end)) AS count")) ->where('tbl_appointment.app_status', '=', 'Missed') - ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id); + ->where('tbl_partner_facility.county_id', Auth::user()->county_id); $appointment_missed_to_nineteen = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') @@ -6975,7 +8531,7 @@ public function filter_missed_appointment_charts(Request $request) WHEN ( locate( '-', `tbl_client`.`dob` ) > 0 ) THEN date_format( str_to_date( `tbl_client`.`dob`, '%Y-%m-%d' ), '%Y-%m-%d' ) END)) >= 15) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 19)) then `tbl_client`.`id` end)) AS count")) ->where('tbl_appointment.app_status', '=', 'Missed') - ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id); + ->where('tbl_partner_facility.county_id', Auth::user()->county_id); $appointment_missed_to_twentyfour = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') @@ -6985,7 +8541,7 @@ public function filter_missed_appointment_charts(Request $request) WHEN ( locate( '-', `tbl_client`.`dob` ) > 0 ) THEN date_format( str_to_date( `tbl_client`.`dob`, '%Y-%m-%d' ), '%Y-%m-%d' ) END)) >= 20) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 24)) then `tbl_client`.`id` end)) AS count")) ->where('tbl_appointment.app_status', '=', 'Missed') - ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id); + ->where('tbl_partner_facility.county_id', Auth::user()->county_id); $appointment_missed_to_twentyfive_above = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') @@ -6995,7 +8551,7 @@ public function filter_missed_appointment_charts(Request $request) WHEN ( locate( '-', `tbl_client`.`dob` ) > 0 ) THEN date_format( str_to_date( `tbl_client`.`dob`, '%Y-%m-%d' ), '%Y-%m-%d' ) END)) >= 25)) then `tbl_client`.`id` end)) AS count")) ->where('tbl_appointment.app_status', '=', 'Missed') - ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id); + ->where('tbl_partner_facility.county_id', Auth::user()->county_id); $appointment_missed_to_uknown_age = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') @@ -7010,27 +8566,27 @@ public function filter_missed_appointment_charts(Request $request) WHEN ( locate( '-', `tbl_client`.`dob` ) > 0 ) THEN date_format( str_to_date( `tbl_client`.`dob`, '%Y-%m-%d' ), '%Y-%m-%d' ) END")) ->where('tbl_appointment.app_status', '=', 'Missed') - ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id); + ->where('tbl_partner_facility.county_id', Auth::user()->county_id); // defaulted appointment by gender $appointment_defaulted_female = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') ->where('tbl_appointment.app_status', '=', 'Defaulted') ->where('tbl_client.gender', '=', '1') - ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id); + ->where('tbl_partner_facility.county_id', Auth::user()->county_id); $appointment_defaulted_male = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') ->where('tbl_appointment.app_status', '=', 'Defaulted') ->where('tbl_client.gender', '=', '2') - ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id); + ->where('tbl_partner_facility.county_id', Auth::user()->county_id); $appointment_defaulted_uknown_gender = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') ->where('tbl_appointment.app_status', '=', 'Defaulted') ->where('tbl_client.gender', '!=', '1') ->where('tbl_client.gender', '!=', '2') - ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id); + ->where('tbl_partner_facility.county_id', Auth::user()->county_id); // defaulted appointment by age $appointment_defaulted_to_nine = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') @@ -7041,7 +8597,7 @@ public function filter_missed_appointment_charts(Request $request) WHEN ( locate( '-', `tbl_client`.`dob` ) > 0 ) THEN date_format( str_to_date( `tbl_client`.`dob`, '%Y-%m-%d' ), '%Y-%m-%d' ) END)) > 0) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 9)) then `tbl_client`.`id` end)) AS count")) ->where('tbl_appointment.app_status', '=', 'Defaulted') - ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id); + ->where('tbl_partner_facility.county_id', Auth::user()->county_id); $appointment_defaulted_to_fourteen = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') @@ -7051,7 +8607,7 @@ public function filter_missed_appointment_charts(Request $request) WHEN ( locate( '-', `tbl_client`.`dob` ) > 0 ) THEN date_format( str_to_date( `tbl_client`.`dob`, '%Y-%m-%d' ), '%Y-%m-%d' ) END)) >= 10) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 14)) then `tbl_client`.`id` end)) AS count")) ->where('tbl_appointment.app_status', '=', 'Defaulted') - ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id); + ->where('tbl_partner_facility.county_id', Auth::user()->county_id); $appointment_defaulted_to_nineteen = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') @@ -7061,7 +8617,7 @@ public function filter_missed_appointment_charts(Request $request) WHEN ( locate( '-', `tbl_client`.`dob` ) > 0 ) THEN date_format( str_to_date( `tbl_client`.`dob`, '%Y-%m-%d' ), '%Y-%m-%d' ) END)) >= 15) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 19)) then `tbl_client`.`id` end)) AS count")) ->where('tbl_appointment.app_status', '=', 'Defaulted') - ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id); + ->where('tbl_partner_facility.county_id', Auth::user()->county_id); $appointment_defaulted_to_twentyfour = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') @@ -7071,7 +8627,7 @@ public function filter_missed_appointment_charts(Request $request) WHEN ( locate( '-', `tbl_client`.`dob` ) > 0 ) THEN date_format( str_to_date( `tbl_client`.`dob`, '%Y-%m-%d' ), '%Y-%m-%d' ) END)) >= 20) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 24)) then `tbl_client`.`id` end)) AS count")) ->where('tbl_appointment.app_status', '=', 'Defaulted') - ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id); + ->where('tbl_partner_facility.county_id', Auth::user()->county_id); $appointment_defaulted_to_twentyfive_above = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') @@ -7081,7 +8637,7 @@ public function filter_missed_appointment_charts(Request $request) WHEN ( locate( '-', `tbl_client`.`dob` ) > 0 ) THEN date_format( str_to_date( `tbl_client`.`dob`, '%Y-%m-%d' ), '%Y-%m-%d' ) END)) >= 25)) then `tbl_client`.`id` end)) AS count")) ->where('tbl_appointment.app_status', '=', 'Defaulted') - ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id); + ->where('tbl_partner_facility.county_id', Auth::user()->county_id); $appointment_defaulted_to_uknown_age = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') @@ -7096,27 +8652,27 @@ public function filter_missed_appointment_charts(Request $request) WHEN ( locate( '-', `tbl_client`.`dob` ) > 0 ) THEN date_format( str_to_date( `tbl_client`.`dob`, '%Y-%m-%d' ), '%Y-%m-%d' ) END")) ->where('tbl_appointment.app_status', '=', 'Defaulted') - ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id); + ->where('tbl_partner_facility.county_id', Auth::user()->county_id); // ltfu appointment by gender $appointment_ltfu_female = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') ->where('tbl_appointment.app_status', '=', 'LTFU') ->where('tbl_client.gender', '=', '1') - ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id); + ->where('tbl_partner_facility.county_id', Auth::user()->county_id); $appointment_ltfu_male = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') ->where('tbl_appointment.app_status', '=', 'LTFU') ->where('tbl_client.gender', '=', '2') - ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id); + ->where('tbl_partner_facility.county_id', Auth::user()->county_id); $appointment_ltfu_uknown_gender = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') ->where('tbl_appointment.app_status', '=', 'LTFU') ->where('tbl_client.gender', '!=', '1') ->where('tbl_client.gender', '!=', '2') - ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id); + ->where('tbl_partner_facility.county_id', Auth::user()->county_id); // ltfu appointment by age $appointment_ltfu_to_nine = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') @@ -7127,7 +8683,7 @@ public function filter_missed_appointment_charts(Request $request) WHEN ( locate( '-', `tbl_client`.`dob` ) > 0 ) THEN date_format( str_to_date( `tbl_client`.`dob`, '%Y-%m-%d' ), '%Y-%m-%d' ) END)) > 0) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 9)) then `tbl_client`.`id` end)) AS count")) ->where('tbl_appointment.app_status', '=', 'LTFU') - ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id); + ->where('tbl_partner_facility.county_id', Auth::user()->county_id); $appointment_ltfu_to_fourteen = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') @@ -7137,7 +8693,7 @@ public function filter_missed_appointment_charts(Request $request) WHEN ( locate( '-', `tbl_client`.`dob` ) > 0 ) THEN date_format( str_to_date( `tbl_client`.`dob`, '%Y-%m-%d' ), '%Y-%m-%d' ) END)) >= 10) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 14)) then `tbl_client`.`id` end)) AS count")) ->where('tbl_appointment.app_status', '=', 'LTFU') - ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id); + ->where('tbl_partner_facility.county_id', Auth::user()->county_id); $appointment_ltfu_to_nineteen = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') @@ -7147,7 +8703,7 @@ public function filter_missed_appointment_charts(Request $request) WHEN ( locate( '-', `tbl_client`.`dob` ) > 0 ) THEN date_format( str_to_date( `tbl_client`.`dob`, '%Y-%m-%d' ), '%Y-%m-%d' ) END)) >= 15) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 19)) then `tbl_client`.`id` end)) AS count")) ->where('tbl_appointment.app_status', '=', 'LTFU') - ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id); + ->where('tbl_partner_facility.county_id', Auth::user()->county_id); $appointment_ltfu_to_twentyfour = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') @@ -7157,7 +8713,7 @@ public function filter_missed_appointment_charts(Request $request) WHEN ( locate( '-', `tbl_client`.`dob` ) > 0 ) THEN date_format( str_to_date( `tbl_client`.`dob`, '%Y-%m-%d' ), '%Y-%m-%d' ) END)) >= 20) and ((year(curdate()) - year(`tbl_client`.`dob`)) <= 24)) then `tbl_client`.`id` end)) AS count")) ->where('tbl_appointment.app_status', '=', 'LTFU') - ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id); + ->where('tbl_partner_facility.county_id', Auth::user()->county_id); $appointment_ltfu_to_twentyfive_above = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') @@ -7167,7 +8723,7 @@ public function filter_missed_appointment_charts(Request $request) WHEN ( locate( '-', `tbl_client`.`dob` ) > 0 ) THEN date_format( str_to_date( `tbl_client`.`dob`, '%Y-%m-%d' ), '%Y-%m-%d' ) END)) >= 25)) then `tbl_client`.`id` end)) AS count")) ->where('tbl_appointment.app_status', '=', 'LTFU') - ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id); + ->where('tbl_partner_facility.county_id', Auth::user()->county_id); $appointment_ltfu_to_uknown_age = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') ->join('tbl_partner_facility', 'tbl_client.mfl_code', '=', 'tbl_partner_facility.mfl_code') @@ -7182,7 +8738,7 @@ public function filter_missed_appointment_charts(Request $request) WHEN ( locate( '-', `tbl_client`.`dob` ) > 0 ) THEN date_format( str_to_date( `tbl_client`.`dob`, '%Y-%m-%d' ), '%Y-%m-%d' ) END")) ->where('tbl_appointment.app_status', '=', 'LTFU') - ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id); + ->where('tbl_partner_facility.county_id', Auth::user()->county_id); } if (Auth::user()->access_level == 'Admin' || Auth::user()->access_level == 'Donor') { $appointment_not_honoured = Appointments::join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') diff --git a/resources/views/new_dashboard/appointment_dashboard.blade.php b/resources/views/new_dashboard/appointment_dashboard.blade.php index f4349ae..0a5e679 100644 --- a/resources/views/new_dashboard/appointment_dashboard.blade.php +++ b/resources/views/new_dashboard/appointment_dashboard.blade.php @@ -10,7 +10,7 @@
  • --> -@if (Auth::user()->access_level == 'Admin' || Auth::user()->access_level == 'Partner' || Auth::user()->access_level == 'Donor') +@if (Auth::user()->access_level == 'Admin' || Auth::user()->access_level == 'Partner' || Auth::user()->access_level == 'Donor' || Auth::user()->access_level == 'County' || Auth::user()->access_level == 'Sub County')
    diff --git a/resources/views/new_dashboard/client_dashboard.blade.php b/resources/views/new_dashboard/client_dashboard.blade.php index 68215ea..7eabcf5 100644 --- a/resources/views/new_dashboard/client_dashboard.blade.php +++ b/resources/views/new_dashboard/client_dashboard.blade.php @@ -10,7 +10,7 @@
  • --> -@if (Auth::user()->access_level == 'Admin' || Auth::user()->access_level == 'Partner' || Auth::user()->access_level == 'Donor') +@if (Auth::user()->access_level == 'Admin' || Auth::user()->access_level == 'Partner' || Auth::user()->access_level == 'Donor' || Auth::user()->access_level == 'County' || Auth::user()->access_level == 'Sub County')
    {{ csrf_field() }} @@ -77,7 +77,7 @@
    - +
    @@ -93,7 +93,7 @@
    - +
    @@ -140,7 +140,7 @@
    - +
    @@ -157,7 +157,7 @@
    - +
    diff --git a/resources/views/new_dashboard/missed_dashboard.blade.php b/resources/views/new_dashboard/missed_dashboard.blade.php index 2dbb746..86d7cad 100644 --- a/resources/views/new_dashboard/missed_dashboard.blade.php +++ b/resources/views/new_dashboard/missed_dashboard.blade.php @@ -10,7 +10,7 @@
  • --> -@if (Auth::user()->access_level == 'Admin' || Auth::user()->access_level == 'Partner' || Auth::user()->access_level == 'Donor') +@if (Auth::user()->access_level == 'Admin' || Auth::user()->access_level == 'Partner' || Auth::user()->access_level == 'Donor' || Auth::user()->access_level == 'County' || Auth::user()->access_level == 'Sub County')
    From 8dc2b71ccae4fdea51064fed99b0873d2f390dce Mon Sep 17 00:00:00 2001 From: Ronald-pro <36841157+Ronald-pro@users.noreply.github.com> Date: Tue, 6 Dec 2022 11:26:13 +0300 Subject: [PATCH 128/171] populated not honored appointments on app calendar --- app/Http/Controllers/CalendarController.php | 45 +++++++++++----- .../appointment_calender.blade.php | 10 +++- .../views/reports/cal_appointments.blade.php | 54 +++++++++++++++++++ routes/web.php | 1 + 4 files changed, 94 insertions(+), 16 deletions(-) diff --git a/app/Http/Controllers/CalendarController.php b/app/Http/Controllers/CalendarController.php index 56bb2e1..4097a91 100644 --- a/app/Http/Controllers/CalendarController.php +++ b/app/Http/Controllers/CalendarController.php @@ -24,7 +24,7 @@ public function app_calendar() $name = 'Total Apps:'; $app_calendar_data = Appointments::join('tbl_appointment_types', 'tbl_appointment_types.id', '=', 'tbl_appointment.app_type_1') ->join('tbl_client', 'tbl_client.id', '=', 'tbl_appointment.client_id') - ->select('tbl_client.clinic_number', 'tbl_client.file_no', 'tbl_client.phone_no', 'tbl_appointment_types.name as app_type', DB::raw("CONCAT(`tbl_client`.`f_name`, ' ', `tbl_client`.`m_name`, ' ', `tbl_client`.`l_name`) as client_name"), 'tbl_appointment.appntmnt_date as start', DB::raw("CONCAT('$this->url_path','/id_all/', tbl_appointment.id) as url"), DB::raw("CONCAT('Total Apps: ', ' ', COUNT(tbl_appointment_types.id)) as title"), 'tbl_appointment.appntmnt_date as end') + ->select('tbl_client.clinic_number', 'tbl_client.file_no', 'tbl_client.phone_no', 'tbl_appointment.app_status', 'tbl_appointment_types.name as app_type', DB::raw("CONCAT(`tbl_client`.`f_name`, ' ', `tbl_client`.`m_name`, ' ', `tbl_client`.`l_name`) as client_name"), 'tbl_appointment.appntmnt_date as start', DB::raw("CONCAT('$this->url_path','/id_all/', tbl_appointment.id) as url"), DB::raw("CONCAT('Total Apps: ', ' ', COUNT(tbl_appointment_types.id)) as title"), 'tbl_appointment.appntmnt_date as end') ->groupBy('tbl_appointment.appntmnt_date') ->where('tbl_client.mfl_code', Auth::user()->facility_id) ->get(); @@ -39,7 +39,7 @@ public function refill_calendar() $app_calendar_data = Appointments::join('tbl_appointment_types', 'tbl_appointment_types.id', '=', 'tbl_appointment.app_type_1') ->join('tbl_client', 'tbl_client.id', '=', 'tbl_appointment.client_id') ->join('tbl_clinic', 'tbl_clinic.id', '=', 'tbl_client.clinic_id') - ->select('tbl_client.clinic_number', 'tbl_clinic.name as clinic', 'tbl_client.file_no', 'tbl_client.phone_no', 'tbl_appointment_types.name as app_type', DB::raw("CONCAT(`tbl_client`.`f_name`, ' ', `tbl_client`.`m_name`, ' ', `tbl_client`.`l_name`) as client_name"), 'tbl_appointment.appntmnt_date as start', DB::raw("CONCAT('$this->url_path','/id/', tbl_appointment.id) as url"), DB::raw("CONCAT('Re-fill: ', ' ', COUNT(tbl_appointment_types.id)) as title"), 'tbl_appointment.appntmnt_date as end') + ->select('tbl_client.clinic_number', 'tbl_clinic.name as clinic', 'tbl_client.file_no', 'tbl_appointment.app_status', 'tbl_client.phone_no', 'tbl_appointment_types.name as app_type', DB::raw("CONCAT(`tbl_client`.`f_name`, ' ', `tbl_client`.`m_name`, ' ', `tbl_client`.`l_name`) as client_name"), 'tbl_appointment.appntmnt_date as start', DB::raw("CONCAT('$this->url_path','/id/', tbl_appointment.id) as url"), DB::raw("CONCAT('Re-fill: ', ' ', COUNT(tbl_appointment_types.id)) as title"), 'tbl_appointment.appntmnt_date as end') ->groupBy('tbl_appointment.appntmnt_date') ->where('tbl_appointment_types.name', '=', 'Re-fill') ->where('tbl_client.mfl_code', Auth::user()->facility_id) @@ -55,7 +55,7 @@ public function refill_apps() $app_calendar_data = Appointments::join('tbl_appointment_types', 'tbl_appointment_types.id', '=', 'tbl_appointment.app_type_1') ->join('tbl_client', 'tbl_client.id', '=', 'tbl_appointment.client_id') ->join('tbl_clinic', 'tbl_clinic.id', '=', 'tbl_client.clinic_id') - ->select('tbl_client.clinic_number', 'tbl_clinic.name as clinic', 'tbl_client.file_no', 'tbl_client.phone_no', 'tbl_appointment_types.name as app_type', DB::raw("CONCAT(`tbl_client`.`f_name`, ' ', `tbl_client`.`m_name`, ' ', `tbl_client`.`l_name`) as client_name"), 'tbl_appointment.appntmnt_date as start', DB::raw("CONCAT('$this->url_path','/id/', tbl_appointment.id) as url"), DB::raw("CONCAT('Re-fill: ', ' ', COUNT(tbl_appointment_types.id)) as title"), 'tbl_appointment.appntmnt_date as end') + ->select('tbl_client.clinic_number', 'tbl_clinic.name as clinic', 'tbl_client.file_no', 'tbl_appointment.app_status', 'tbl_client.phone_no', 'tbl_appointment_types.name as app_type', DB::raw("CONCAT(`tbl_client`.`f_name`, ' ', `tbl_client`.`m_name`, ' ', `tbl_client`.`l_name`) as client_name"), 'tbl_appointment.appntmnt_date as start', DB::raw("CONCAT('$this->url_path','/id/', tbl_appointment.id) as url"), DB::raw("CONCAT('Re-fill: ', ' ', COUNT(tbl_appointment_types.id)) as title"), 'tbl_appointment.appntmnt_date as end') ->groupBy('tbl_appointment.appntmnt_date') ->where('tbl_appointment_types.name', '=', 'Re-fill') ->where('tbl_client.mfl_code', Auth::user()->facility_id) @@ -69,7 +69,7 @@ public function clinical_calendar() if (Auth::user()->access_level == 'Facility') { $app_calendar_data = Appointments::join('tbl_appointment_types', 'tbl_appointment_types.id', '=', 'tbl_appointment.app_type_1') ->join('tbl_client', 'tbl_client.id', '=', 'tbl_appointment.client_id') - ->select('tbl_client.clinic_number', 'tbl_client.file_no', 'tbl_client.phone_no', 'tbl_appointment_types.name as app_type', DB::raw("CONCAT(`tbl_client`.`f_name`, ' ', `tbl_client`.`m_name`, ' ', `tbl_client`.`l_name`) as client_name"), 'tbl_appointment.appntmnt_date as start', DB::raw("CONCAT('$this->url_path','/id/', tbl_appointment.id) as url"), DB::raw("CONCAT('Clinical Review: ', ' ', COUNT(tbl_appointment_types.id)) as title"), 'tbl_appointment.appntmnt_date as end') + ->select('tbl_client.clinic_number', 'tbl_client.file_no', 'tbl_client.phone_no', 'tbl_appointment.app_status', 'tbl_appointment_types.name as app_type', DB::raw("CONCAT(`tbl_client`.`f_name`, ' ', `tbl_client`.`m_name`, ' ', `tbl_client`.`l_name`) as client_name"), 'tbl_appointment.appntmnt_date as start', DB::raw("CONCAT('$this->url_path','/id/', tbl_appointment.id) as url"), DB::raw("CONCAT('Clinical Review: ', ' ', COUNT(tbl_appointment_types.id)) as title"), 'tbl_appointment.appntmnt_date as end') ->groupBy('tbl_appointment.appntmnt_date') ->where('tbl_appointment_types.name', '=', 'Clinical Review') ->where('tbl_client.mfl_code', Auth::user()->facility_id) @@ -83,7 +83,7 @@ public function adherence_calendar() if (Auth::user()->access_level == 'Facility') { $app_calendar_data = Appointments::join('tbl_appointment_types', 'tbl_appointment_types.id', '=', 'tbl_appointment.app_type_1') ->join('tbl_client', 'tbl_client.id', '=', 'tbl_appointment.client_id') - ->select('tbl_client.clinic_number', 'tbl_client.file_no', 'tbl_client.phone_no', 'tbl_appointment_types.name as app_type', DB::raw("CONCAT('$this->url_path','/id/', tbl_appointment.id) as url"), DB::raw("CONCAT(`tbl_client`.`f_name`, ' ', `tbl_client`.`m_name`, ' ', `tbl_client`.`l_name`) as client_name"), 'tbl_appointment.appntmnt_date as start', DB::raw("CONCAT('Adherence: ', ' ', COUNT(tbl_appointment_types.id)) as title"), 'tbl_appointment.appntmnt_date as end') + ->select('tbl_client.clinic_number', 'tbl_client.file_no', 'tbl_client.phone_no', 'tbl_appointment.app_status', 'tbl_appointment_types.name as app_type', DB::raw("CONCAT('$this->url_path','/id/', tbl_appointment.id) as url"), DB::raw("CONCAT(`tbl_client`.`f_name`, ' ', `tbl_client`.`m_name`, ' ', `tbl_client`.`l_name`) as client_name"), 'tbl_appointment.appntmnt_date as start', DB::raw("CONCAT('Adherence: ', ' ', COUNT(tbl_appointment_types.id)) as title"), 'tbl_appointment.appntmnt_date as end') ->groupBy('tbl_appointment.appntmnt_date') ->where('tbl_appointment_types.name', '=', 'Enhanced Adherence') ->where('tbl_client.mfl_code', Auth::user()->facility_id) @@ -97,7 +97,7 @@ public function lab_calendar() if (Auth::user()->access_level == 'Facility') { $app_calendar_data = Appointments::join('tbl_appointment_types', 'tbl_appointment_types.id', '=', 'tbl_appointment.app_type_1') ->join('tbl_client', 'tbl_client.id', '=', 'tbl_appointment.client_id') - ->select('tbl_client.clinic_number', 'tbl_client.file_no', 'tbl_client.phone_no', 'tbl_appointment_types.name as app_type', DB::raw("CONCAT(`tbl_client`.`f_name`, ' ', `tbl_client`.`m_name`, ' ', `tbl_client`.`l_name`) as client_name"), 'tbl_appointment.appntmnt_date as start', DB::raw("CONCAT('$this->url_path','/id/', tbl_appointment.id) as url"), DB::raw("CONCAT('Lab Investigation: ', ' ', COUNT(tbl_appointment_types.id)) as title"), 'tbl_appointment.appntmnt_date as end') + ->select('tbl_client.clinic_number', 'tbl_client.file_no', 'tbl_client.phone_no', 'tbl_appointment.app_status', 'tbl_appointment_types.name as app_type', DB::raw("CONCAT(`tbl_client`.`f_name`, ' ', `tbl_client`.`m_name`, ' ', `tbl_client`.`l_name`) as client_name"), 'tbl_appointment.appntmnt_date as start', DB::raw("CONCAT('$this->url_path','/id/', tbl_appointment.id) as url"), DB::raw("CONCAT('Lab Investigation: ', ' ', COUNT(tbl_appointment_types.id)) as title"), 'tbl_appointment.appntmnt_date as end') ->groupBy('tbl_appointment.appntmnt_date') ->where('tbl_appointment_types.name', '=', 'Lab Investigation') ->where('tbl_client.mfl_code', Auth::user()->facility_id) @@ -111,7 +111,7 @@ public function viral_load() if (Auth::user()->access_level == 'Facility') { $app_calendar_data = Appointments::join('tbl_appointment_types', 'tbl_appointment_types.id', '=', 'tbl_appointment.app_type_1') ->join('tbl_client', 'tbl_client.id', '=', 'tbl_appointment.client_id') - ->select('tbl_client.clinic_number', 'tbl_client.file_no', 'tbl_client.phone_no', 'tbl_appointment_types.name as app_type', DB::raw("CONCAT(`tbl_client`.`f_name`, ' ', `tbl_client`.`m_name`, ' ', `tbl_client`.`l_name`) as client_name"), 'tbl_appointment.appntmnt_date as start', DB::raw("CONCAT('$this->url_path','/id/', tbl_appointment.id) as url"), DB::raw("CONCAT('Viral Load: ', ' ', COUNT(tbl_appointment_types.id)) as title"), 'tbl_appointment.appntmnt_date as end') + ->select('tbl_client.clinic_number', 'tbl_client.file_no', 'tbl_client.phone_no', 'tbl_appointment.app_status', 'tbl_appointment_types.name as app_type', DB::raw("CONCAT(`tbl_client`.`f_name`, ' ', `tbl_client`.`m_name`, ' ', `tbl_client`.`l_name`) as client_name"), 'tbl_appointment.appntmnt_date as start', DB::raw("CONCAT('$this->url_path','/id/', tbl_appointment.id) as url"), DB::raw("CONCAT('Viral Load: ', ' ', COUNT(tbl_appointment_types.id)) as title"), 'tbl_appointment.appntmnt_date as end') ->groupBy('tbl_appointment.appntmnt_date') ->where('tbl_appointment_types.name', '=', 'Viral Load') ->where('tbl_client.mfl_code', Auth::user()->facility_id) @@ -125,7 +125,7 @@ public function other_calendar() if (Auth::user()->access_level == 'Facility') { $app_calendar_data = Appointments::join('tbl_appointment_types', 'tbl_appointment_types.id', '=', 'tbl_appointment.app_type_1') ->join('tbl_client', 'tbl_client.id', '=', 'tbl_appointment.client_id') - ->select('tbl_client.clinic_number', 'tbl_client.file_no', 'tbl_client.phone_no', 'tbl_appointment_types.name as app_type', DB::raw("CONCAT(`tbl_client`.`f_name`, ' ', `tbl_client`.`m_name`, ' ', `tbl_client`.`l_name`) as client_name"), 'tbl_appointment.appntmnt_date as start', DB::raw("CONCAT('$this->url_path','/id/', tbl_appointment.id) as url"), DB::raw("CONCAT('Other: ', ' ', COUNT(tbl_appointment_types.id)) as title"), 'tbl_appointment.appntmnt_date as end') + ->select('tbl_client.clinic_number', 'tbl_client.file_no', 'tbl_client.phone_no', 'tbl_appointment.app_status', 'tbl_appointment_types.name as app_type', DB::raw("CONCAT(`tbl_client`.`f_name`, ' ', `tbl_client`.`m_name`, ' ', `tbl_client`.`l_name`) as client_name"), 'tbl_appointment.appntmnt_date as start', DB::raw("CONCAT('$this->url_path','/id/', tbl_appointment.id) as url"), DB::raw("CONCAT('Other: ', ' ', COUNT(tbl_appointment_types.id)) as title"), 'tbl_appointment.appntmnt_date as end') ->groupBy('tbl_appointment.appntmnt_date') ->where('tbl_appointment_types.name', '=', 'Other') ->where('tbl_client.mfl_code', Auth::user()->facility_id) @@ -139,7 +139,7 @@ public function pcr_calendar() if (Auth::user()->access_level == 'Facility') { $app_calendar_data = Appointments::join('tbl_appointment_types', 'tbl_appointment_types.id', '=', 'tbl_appointment.app_type_1') ->join('tbl_client', 'tbl_client.id', '=', 'tbl_appointment.client_id') - ->select('tbl_client.clinic_number', 'tbl_client.file_no', 'tbl_client.phone_no', 'tbl_appointment_types.name as app_type', DB::raw("CONCAT(`tbl_client`.`f_name`, ' ', `tbl_client`.`m_name`, ' ', `tbl_client`.`l_name`) as client_name"), 'tbl_appointment.appntmnt_date as start', DB::raw("CONCAT('$this->url_path','/id/', tbl_appointment.id) as url"), DB::raw("CONCAT('PCR: ', ' ', COUNT(tbl_appointment_types.id)) as title"), 'tbl_appointment.appntmnt_date as end') + ->select('tbl_client.clinic_number', 'tbl_client.file_no', 'tbl_client.phone_no', 'tbl_appointment.app_status', 'tbl_appointment_types.name as app_type', DB::raw("CONCAT(`tbl_client`.`f_name`, ' ', `tbl_client`.`m_name`, ' ', `tbl_client`.`l_name`) as client_name"), 'tbl_appointment.appntmnt_date as start', DB::raw("CONCAT('$this->url_path','/id/', tbl_appointment.id) as url"), DB::raw("CONCAT('PCR: ', ' ', COUNT(tbl_appointment_types.id)) as title"), 'tbl_appointment.appntmnt_date as end') ->groupBy('tbl_appointment.appntmnt_date') ->where('tbl_appointment_types.name', '=', 'PCR') ->where('tbl_client.mfl_code', Auth::user()->facility_id) @@ -153,7 +153,7 @@ public function normal_calender() if (Auth::user()->access_level == 'Facility') { $app_calendar_data = Appointments::join('tbl_appointment_types', 'tbl_appointment_types.id', '=', 'tbl_appointment.app_type_1') ->join('tbl_client', 'tbl_client.id', '=', 'tbl_appointment.client_id') - ->select('tbl_client.clinic_number', 'tbl_client.file_no', 'tbl_client.phone_no', 'tbl_appointment_types.name as app_type', DB::raw("CONCAT(`tbl_client`.`f_name`, ' ', `tbl_client`.`m_name`, ' ', `tbl_client`.`l_name`) as client_name"), 'tbl_appointment.appntmnt_date as start', DB::raw("CONCAT('$this->url_path','/id/', tbl_appointment.id) as url"), DB::raw("CONCAT('Normal: ', ' ', COUNT(tbl_appointment_types.id)) as title"), 'tbl_appointment.appntmnt_date as end') + ->select('tbl_client.clinic_number', 'tbl_client.file_no', 'tbl_client.phone_no', 'tbl_appointment.app_status', 'tbl_appointment_types.name as app_type', DB::raw("CONCAT(`tbl_client`.`f_name`, ' ', `tbl_client`.`m_name`, ' ', `tbl_client`.`l_name`) as client_name"), 'tbl_appointment.appntmnt_date as start', DB::raw("CONCAT('$this->url_path','/id/', tbl_appointment.id) as url"), DB::raw("CONCAT('Normal: ', ' ', COUNT(tbl_appointment_types.id)) as title"), 'tbl_appointment.appntmnt_date as end') ->groupBy('tbl_appointment.appntmnt_date') ->where('tbl_appointment_types.name', '=', 'Normal') ->where('tbl_client.mfl_code', Auth::user()->facility_id) @@ -167,7 +167,7 @@ public function vl_cd_calendar() if (Auth::user()->access_level == 'Facility') { $app_calendar_data = Appointments::join('tbl_appointment_types', 'tbl_appointment_types.id', '=', 'tbl_appointment.app_type_1') ->join('tbl_client', 'tbl_client.id', '=', 'tbl_appointment.client_id') - ->select('tbl_client.clinic_number', 'tbl_client.file_no', 'tbl_client.phone_no', 'tbl_appointment_types.name as app_type', DB::raw("CONCAT(`tbl_client`.`f_name`, ' ', `tbl_client`.`m_name`, ' ', `tbl_client`.`l_name`) as client_name"), 'tbl_appointment.appntmnt_date as start', DB::raw("CONCAT('$this->url_path','/id/', tbl_appointment.id) as url"), DB::raw("CONCAT('VL/CD4: ', ' ', COUNT(tbl_appointment_types.id)) as title"), 'tbl_appointment.appntmnt_date as end') + ->select('tbl_client.clinic_number', 'tbl_client.file_no', 'tbl_client.phone_no', 'tbl_appointment.app_status', 'tbl_appointment_types.name as app_type', DB::raw("CONCAT(`tbl_client`.`f_name`, ' ', `tbl_client`.`m_name`, ' ', `tbl_client`.`l_name`) as client_name"), 'tbl_appointment.appntmnt_date as start', DB::raw("CONCAT('$this->url_path','/id/', tbl_appointment.id) as url"), DB::raw("CONCAT('VL/CD4: ', ' ', COUNT(tbl_appointment_types.id)) as title"), 'tbl_appointment.appntmnt_date as end') ->groupBy('tbl_appointment.appntmnt_date') ->where('tbl_appointment_types.name', '=', 'VL/CD4') ->where('tbl_client.mfl_code', Auth::user()->facility_id) @@ -181,7 +181,7 @@ public function honored_calendar() if (Auth::user()->access_level == 'Facility') { $app_calendar_data = Appointments::join('tbl_appointment_types', 'tbl_appointment_types.id', '=', 'tbl_appointment.app_type_1') ->join('tbl_client', 'tbl_client.id', '=', 'tbl_appointment.client_id') - ->select('tbl_client.clinic_number', 'tbl_client.file_no', 'tbl_client.phone_no', 'tbl_appointment_types.name as app_type', DB::raw("CONCAT(`tbl_client`.`f_name`, ' ', `tbl_client`.`m_name`, ' ', `tbl_client`.`l_name`) as client_name"), 'tbl_appointment.appntmnt_date as start', DB::raw("CONCAT('$this->url_path','/id/', tbl_appointment.id) as url"), DB::raw("CONCAT('Honored Apps: ', ' ', COUNT(tbl_appointment.id)) as title"), 'tbl_appointment.appntmnt_date as end') + ->select('tbl_client.clinic_number', 'tbl_client.file_no', 'tbl_client.phone_no', 'tbl_appointment.app_status', 'tbl_appointment_types.name as app_type', DB::raw("CONCAT(`tbl_client`.`f_name`, ' ', `tbl_client`.`m_name`, ' ', `tbl_client`.`l_name`) as client_name"), 'tbl_appointment.appntmnt_date as start', DB::raw("CONCAT('$this->url_path','/id/', tbl_appointment.id) as url"), DB::raw("CONCAT('Honored Apps: ', ' ', COUNT(tbl_appointment.id)) as title"), 'tbl_appointment.appntmnt_date as end') ->groupBy('tbl_appointment.appntmnt_date') ->where('tbl_appointment.date_attended', '=', DB::raw('tbl_appointment.appntmnt_date')) ->where('tbl_client.mfl_code', Auth::user()->facility_id) @@ -190,12 +190,27 @@ public function honored_calendar() } } + public function not_honored_calendar() + { + if (Auth::user()->access_level == 'Facility') { + $app_calendar_data = Appointments::join('tbl_appointment_types', 'tbl_appointment_types.id', '=', 'tbl_appointment.app_type_1') + ->join('tbl_client', 'tbl_client.id', '=', 'tbl_appointment.client_id') + ->select('tbl_client.clinic_number', 'tbl_client.file_no', 'tbl_appointment.app_status', 'tbl_client.phone_no', 'tbl_appointment_types.name as app_type', DB::raw("CONCAT(`tbl_client`.`f_name`, ' ', `tbl_client`.`m_name`, ' ', `tbl_client`.`l_name`) as client_name"), 'tbl_appointment.appntmnt_date as start', DB::raw("CONCAT('$this->url_path','/id/', tbl_appointment.id) as url"), DB::raw("CONCAT('Not Honored: ', ' ', COUNT(tbl_appointment.id)) as title"), 'tbl_appointment.appntmnt_date as end') + ->groupBy('tbl_appointment.appntmnt_date') + ->whereIn('tbl_appointment.app_status', ['Defaulted', 'LTFU', 'Missed']) + // ->where('tbl_appointment.date_attended', '!=', DB::raw('tbl_appointment.appntmnt_date')) + ->where('tbl_client.mfl_code', Auth::user()->facility_id) + ->get(); + return response()->json($app_calendar_data); + } + } + public function unscheduled_calendar() { if (Auth::user()->access_level == 'Facility') { $app_calendar_data = Appointments::join('tbl_appointment_types', 'tbl_appointment_types.id', '=', 'tbl_appointment.app_type_1') ->join('tbl_client', 'tbl_client.id', '=', 'tbl_appointment.client_id') - ->select('tbl_client.clinic_number', 'tbl_client.file_no', 'tbl_client.phone_no', 'tbl_appointment_types.name as app_type', DB::raw("CONCAT(`tbl_client`.`f_name`, ' ', `tbl_client`.`m_name`, ' ', `tbl_client`.`l_name`) as client_name"), 'tbl_appointment.appntmnt_date as start', DB::raw("CONCAT('$this->url_path','/id/', tbl_appointment.id) as url"), DB::raw("CONCAT('Un-Scheduled: ', ' ', COUNT(tbl_appointment.visit_type)) as title"), 'tbl_appointment.appntmnt_date as end') + ->select('tbl_client.clinic_number', 'tbl_client.file_no', 'tbl_appointment.app_status', 'tbl_client.phone_no', 'tbl_appointment_types.name as app_type', DB::raw("CONCAT(`tbl_client`.`f_name`, ' ', `tbl_client`.`m_name`, ' ', `tbl_client`.`l_name`) as client_name"), 'tbl_appointment.appntmnt_date as start', DB::raw("CONCAT('$this->url_path','/id/', tbl_appointment.id) as url"), DB::raw("CONCAT('Un-Scheduled: ', ' ', COUNT(tbl_appointment.visit_type)) as title"), 'tbl_appointment.appntmnt_date as end') ->where('tbl_appointment.visit_type', '=', 'Un-Scheduled') ->where('tbl_client.mfl_code', Auth::user()->facility_id) ->groupBy('tbl_appointment.appntmnt_date') @@ -217,13 +232,14 @@ public function current_appointments($slug, $id) $app_type = $row->app_type_1; $unscheduled_app = $row->visit_type; $honored_app = $row->date_attended; + $not_honored_app = $row->app_status; } $query = DB::table('tbl_client') ->join('tbl_appointment', 'tbl_client.id', '=', 'tbl_appointment.client_id') ->join('tbl_appointment_types', 'tbl_appointment.app_type_1', '=', 'tbl_appointment_types.id') ->join('tbl_clinic', 'tbl_client.clinic_id', '=', 'tbl_clinic.id') - ->select('tbl_client.file_no', 'tbl_appointment.id as appointment_id', 'tbl_appointment.date_attended', 'tbl_appointment.visit_type', 'tbl_client.f_name', 'tbl_client.m_name', 'tbl_client.l_name', 'tbl_client.phone_no', 'tbl_client.status', 'tbl_client.clinic_number', 'tbl_client.id as client_id', 'tbl_appointment.appntmnt_date', 'tbl_appointment.app_type_1', 'tbl_appointment_types.id as appointment_types_id', 'tbl_appointment_types.name as appointment_types', 'tbl_clinic.name as clinic') + ->select('tbl_client.file_no', 'tbl_appointment.id as appointment_id', 'tbl_appointment.date_attended', 'tbl_appointment.visit_type', 'tbl_client.f_name', 'tbl_client.m_name', 'tbl_client.l_name', 'tbl_client.phone_no', 'tbl_client.status', 'tbl_client.clinic_number', 'tbl_client.id as client_id', 'tbl_appointment.app_status', 'tbl_appointment.appntmnt_date', 'tbl_appointment.app_type_1', 'tbl_appointment_types.id as appointment_types_id', 'tbl_appointment_types.name as appointment_types', 'tbl_clinic.name as clinic') ->where('tbl_client.status', 'Active') ->where('tbl_client.mfl_code', Auth::user()->facility_id) ->where('tbl_appointment.appntmnt_date', $app_date); @@ -232,6 +248,7 @@ public function current_appointments($slug, $id) $query->where('tbl_appointment.app_type_1', $app_type); $query->where('tbl_appointment.visit_type', $unscheduled_app); $query->where('tbl_appointment.date_attended', $honored_app); + $query->where('tbl_appointment.app_status', $not_honored_app); } diff --git a/resources/views/appointments/appointment_calender.blade.php b/resources/views/appointments/appointment_calender.blade.php index 5de3fc5..6111328 100644 --- a/resources/views/appointments/appointment_calender.blade.php +++ b/resources/views/appointments/appointment_calender.blade.php @@ -30,7 +30,6 @@ @section('page-js') - @@ -71,7 +70,9 @@ function draw_calendar() { right: 'month,agendaWeek,agendaDay' }, editable: true, - windowResize: true, + windowResize: function(view) { + // alert('The calendar has adjusted to a window resize'); + }, eventSources: [ { url: '{{ route('app_count_calendar') }}', @@ -117,6 +118,11 @@ function draw_calendar() { color: '#3374FF', textColor: 'black' }, + { + url: '{{ route('not_honored_calendar') }}', + color: '#FF7D33', + textColor: 'black' + }, { url: '{{ route('pcr_calendar') }}', color: '#33FFE5', diff --git a/resources/views/reports/cal_appointments.blade.php b/resources/views/reports/cal_appointments.blade.php index e226597..4b4d16e 100644 --- a/resources/views/reports/cal_appointments.blade.php +++ b/resources/views/reports/cal_appointments.blade.php @@ -28,6 +28,7 @@ Phone No Appointment Date Appointment Type + Appointment Status Clinic Action @@ -44,6 +45,7 @@ {{$row->phone_no}} {{$row->appntmnt_date}} {{$row->appointment_types}} + {{$row->app_status}} {{$row->clinic}} @@ -61,3 +63,55 @@ @endsection +@section('page-js') + + + + + +@endsection diff --git a/routes/web.php b/routes/web.php index 734cfa2..0bd7174 100644 --- a/routes/web.php +++ b/routes/web.php @@ -164,6 +164,7 @@ Route::get('report/vl_cd_calendar', ['uses' => 'App\Http\Controllers\CalendarController@vl_cd_calendar', 'as' => 'vl_cd_calendar']); Route::get('report/current-appointments/{slug}/{id}', ['uses' => 'App\Http\Controllers\CalendarController@current_appointments', 'as' => 'current_appointments']); Route::get('report/honored_calendar', ['uses' => 'App\Http\Controllers\CalendarController@honored_calendar', 'as' => 'honored_calendar']); + Route::get('report/not_honored_calendar', ['uses' => 'App\Http\Controllers\CalendarController@not_honored_calendar', 'as' => 'not_honored_calendar']); Route::get('report/unscheduled_calendar', ['uses' => 'App\Http\Controllers\CalendarController@unscheduled_calendar', 'as' => 'unscheduled_calendar']); // wellness routes From 98e8d1e4dcacda88fbbf91805be5f4806b56f822 Mon Sep 17 00:00:00 2001 From: Ronald-pro <36841157+Ronald-pro@users.noreply.github.com> Date: Thu, 8 Dec 2022 10:33:53 +0300 Subject: [PATCH 129/171] added app summary table on app calendar --- .../appointment_calender.blade.php | 30 +-- .../views/reports/cal_appointments.blade.php | 189 ++++++++++++------ resources/views/uptake/index.blade.php | 2 +- 3 files changed, 142 insertions(+), 79 deletions(-) diff --git a/resources/views/appointments/appointment_calender.blade.php b/resources/views/appointments/appointment_calender.blade.php index 6111328..331c1bd 100644 --- a/resources/views/appointments/appointment_calender.blade.php +++ b/resources/views/appointments/appointment_calender.blade.php @@ -113,26 +113,26 @@ function draw_calendar() { color: '#FFFF00', textColor: 'black' }, - { - url: '{{ route('honored_calendar') }}', - color: '#3374FF', - textColor: 'black' - }, - { - url: '{{ route('not_honored_calendar') }}', - color: '#FF7D33', - textColor: 'black' - }, + // { + // url: '{{ route('honored_calendar') }}', + // color: '#3374FF', + // textColor: 'black' + // }, + // { + // url: '{{ route('not_honored_calendar') }}', + // color: '#FF7D33', + // textColor: 'black' + // }, { url: '{{ route('pcr_calendar') }}', color: '#33FFE5', textColor: 'black' - }, - { - url: '{{ route('unscheduled_calendar') }}', - color: '#FFFF00', - textColor: 'black' } + // { + // url: '{{ route('unscheduled_calendar') }}', + // color: '#FFFF00', + // textColor: 'black' + // } ] }); diff --git a/resources/views/reports/cal_appointments.blade.php b/resources/views/reports/cal_appointments.blade.php index 4b4d16e..3aaf8a3 100644 --- a/resources/views/reports/cal_appointments.blade.php +++ b/resources/views/reports/cal_appointments.blade.php @@ -12,63 +12,126 @@
    +
    +
    +
    +

    Appointments Summary

    + +
    + + + + + + + + + + + + + + + + + + + + + + @foreach ($result as $results) + + + + + app_status, 'Defaulted') ?> + app_status, 'Missed') ?> + app_status, 'LTFU') ?> + visit_type, 'Un-Scheduled') ?> + app_status, 'Notified') ?> + app_status, 'Booked') ?> + + @endforeach + + + + + + + + + + + +
    DateHonoredUnscheduledScheduledMissedDefaultedIIT
    {{ $results->appntmnt_date}} {{ $sum_honored}} {{ $sum_unscheduled}} {{ $sum_scheduled}} {{ $sum_missed}} {{ $sum_defaulted}} {{ $sum_ltfu}}
    +
    +
    +
    +
    +

    Appointments List

    - - - - - - - - - - - - - - - - - - @if (count($result) > 0) - @foreach($result as $row) - - - - - - - - - - - - - @endforeach - @endif - -
    No.UPNFile No Client NamePhone NoAppointment DateAppointment TypeAppointment StatusClinicAction
    {{ $loop->iteration }} {{$row->clinic_number}} {{$row->file_no}} {{$row->f_name.' '.$row->m_name.' '.$row->l_name}} {{$row->phone_no}} {{$row->appntmnt_date}} {{$row->appointment_types}} {{$row->app_status}} {{$row->clinic}} - - -
    + + + + + + + + + + + + + + + + + + @if (count($result) > 0) + @foreach($result as $row) + + + + + + + + + @if($row->app_status == 'Notified') + + @elseif($row->app_status == 'LTFU') + + @else + + @endif + + + + @endforeach + @endif + +
    No.UPNFile No Client NamePhone NoAppointment DateAppointment TypeAppointment StatusClinicAction
    {{ $loop->iteration }} {{$row->clinic_number}} {{$row->file_no}} {{$row->f_name.' '.$row->m_name.' '.$row->l_name}} {{$row->phone_no}} {{$row->appntmnt_date}} {{$row->appointment_types}} Honored IIT {{$row->app_status}} {{$row->clinic}} + + +
    - + @endsection @section('page-js') - - + + }); + -@endsection +@endsection \ No newline at end of file diff --git a/resources/views/uptake/index.blade.php b/resources/views/uptake/index.blade.php index ca09b02..fba6899 100644 --- a/resources/views/uptake/index.blade.php +++ b/resources/views/uptake/index.blade.php @@ -1321,7 +1321,7 @@ Scheduled_App = parseInt(data.scheduledappointment) Honored_App = parseInt(data.honoredappointment) - $('#table').DataTable().ajax.reload(); + // $('#table').DataTable().ajax.reload(); uptakeCascade.series[0].setData([Txcurr, Registered_Clients, Consented_Clients, 0]); appointmentuptakeCascade.series[0].setData([, Scheduled_App, , 0, Honored_App]); From 40f6cb3cda186c4df81a88de16610a7f1cc4b023 Mon Sep 17 00:00:00 2001 From: Ronald-pro <36841157+Ronald-pro@users.noreply.github.com> Date: Thu, 8 Dec 2022 11:10:49 +0300 Subject: [PATCH 130/171] included upi no field on client lists --- .../Controllers/AppointmentController.php | 12 ++++---- app/Http/Controllers/ClientListController.php | 30 ++++++++++++------- app/Http/Controllers/NewReportController.php | 9 ++++-- .../future_appointments.blade.php | 2 ++ .../appointments/future_apps_edit.blade.php | 2 ++ .../views/clients/client_extract.blade.php | 2 ++ .../views/clients/client_profile.blade.php | 2 ++ resources/views/new_reports/clients.blade.php | 2 ++ 8 files changed, 42 insertions(+), 19 deletions(-) diff --git a/app/Http/Controllers/AppointmentController.php b/app/Http/Controllers/AppointmentController.php index 2130317..1683988 100644 --- a/app/Http/Controllers/AppointmentController.php +++ b/app/Http/Controllers/AppointmentController.php @@ -23,7 +23,7 @@ public function index() if (Auth::user()->access_level == 'Facility') { $all_future_apps = Appointments::join('tbl_client', 'tbl_client.id', '=', 'tbl_appointment.client_id') ->join('tbl_appointment_types', 'tbl_appointment_types.id', '=', 'tbl_appointment.app_type_1') - ->select('tbl_appointment.id', 'tbl_appointment.client_id', 'tbl_client.clinic_number', 'tbl_appointment.appntmnt_date', 'tbl_appointment_types.name as app_type') + ->select('tbl_appointment.id', 'tbl_appointment.client_id', 'tbl_client.clinic_number', 'tbl_client.upi_no', 'tbl_appointment.appntmnt_date', 'tbl_appointment_types.name as app_type') ->where('tbl_appointment.appntmnt_date', '>', Now()) ->where('tbl_client.mfl_code', Auth::user()->facility_id) ->get(); @@ -44,7 +44,7 @@ public function editappointment(Request $request) 'expln_app' => "EDITED", ]); - + if ($appointment) { Session::flash('statuscode', 'success'); return redirect('report/future/appointments')->with('status', 'Appointment was updated successfully!'); @@ -61,14 +61,14 @@ public function get_future_appointments() if (Auth::user()->access_level == 'Admin') { $all_future_appointments = Appointments::join('tbl_client', 'tbl_client.id', '=', 'tbl_appointment.client_id') ->join('tbl_appointment_types', 'tbl_appointment_types.id', '=', 'tbl_appointment.app_type_1') - ->selectRaw('tbl_client.clinic_number, tbl_client.file_no, tbl_client.f_name, tbl_client.m_name, tbl_client.l_name, tbl_client.phone_no, tbl_appointment.appntmnt_date, tbl_appointment_types.name as app_type') + ->selectRaw('tbl_client.clinic_number, tbl_client.upi_no, tbl_client.file_no, tbl_client.f_name, tbl_client.m_name, tbl_client.l_name, tbl_client.phone_no, tbl_appointment.appntmnt_date, tbl_appointment_types.name as app_type') ->where('tbl_appointment.appntmnt_date', '>', Now()); } if (Auth::user()->access_level == 'Facility') { $all_future_appointments = Appointments::join('tbl_client', 'tbl_client.id', '=', 'tbl_appointment.client_id') ->join('tbl_appointment_types', 'tbl_appointment_types.id', '=', 'tbl_appointment.app_type_1') - ->selectRaw('tbl_client.clinic_number, tbl_client.file_no, tbl_client.f_name, tbl_client.m_name, tbl_client.l_name, tbl_client.phone_no, tbl_appointment.appntmnt_date, tbl_appointment_types.name as app_type') + ->selectRaw('tbl_client.clinic_number, tbl_client.upi_no, tbl_client.file_no, tbl_client.f_name, tbl_client.m_name, tbl_client.l_name, tbl_client.phone_no, tbl_appointment.appntmnt_date, tbl_appointment_types.name as app_type') ->where('tbl_client.mfl_code', Auth::user()->facility_id) ->where('tbl_appointment.appntmnt_date', '>', Now()); } @@ -76,7 +76,7 @@ public function get_future_appointments() if (Auth::user()->access_level == 'Partner') { $all_future_appointments = Appointments::join('tbl_client', 'tbl_client.id', '=', 'tbl_appointment.client_id') ->join('tbl_appointment_types', 'tbl_appointment_types.id', '=', 'tbl_appointment.app_type_1') - ->selectRaw('tbl_client.clinic_number, tbl_client.file_no, tbl_client.f_name, tbl_client.m_name, tbl_client.l_name, tbl_client.phone_no, tbl_appointment.appntmnt_date, tbl_appointment_types.name as app_type') + ->selectRaw('tbl_client.clinic_number, tbl_client.upi_no, tbl_client.file_no, tbl_client.f_name, tbl_client.m_name, tbl_client.l_name, tbl_client.phone_no, tbl_appointment.appntmnt_date, tbl_appointment_types.name as app_type') ->where('tbl_client.partner_id', Auth::user()->partner_id) ->where('tbl_appointment.appntmnt_date', '>', Now()); } @@ -84,7 +84,7 @@ public function get_future_appointments() if (Auth::user()->access_level == 'Donor') { $all_future_appointments = Appointments::join('tbl_client', 'tbl_client.id', '=', 'tbl_appointment.client_id') ->join('tbl_appointment_types', 'tbl_appointment_types.id', '=', 'tbl_appointment.app_type_1') - ->selectRaw('tbl_client.clinic_number, tbl_client.file_no, tbl_client.f_name, tbl_client.m_name, tbl_client.l_name, tbl_client.phone_no, tbl_appointment.appntmnt_date, tbl_appointment_types.name as app_type') + ->selectRaw('tbl_client.clinic_number, tbl_client.upi_no, tbl_client.file_no, tbl_client.f_name, tbl_client.m_name, tbl_client.l_name, tbl_client.phone_no, tbl_appointment.appntmnt_date, tbl_appointment_types.name as app_type') ->where('donor_id', Auth::user()->donor_id) ->where('tbl_appointment.appntmnt_date', '>', Now()); } diff --git a/app/Http/Controllers/ClientListController.php b/app/Http/Controllers/ClientListController.php index 46c558e..03f5251 100644 --- a/app/Http/Controllers/ClientListController.php +++ b/app/Http/Controllers/ClientListController.php @@ -74,7 +74,8 @@ public function get_client_profile() 'tbl_gender.name as gender', 'tbl_groups.name as group_name', 'tbl_language.name as language', - 'tbl_marital_status.marital' + 'tbl_marital_status.marital', + 'tbl_client.upi_no' ) // ->where('tbl_client.clinic_number', 'LIKE', "%{$upn_search}%") ->where('tbl_client.mfl_code', Auth::user()->facility_id) @@ -214,7 +215,8 @@ public function profile_search(Request $request) 'tbl_gender.name as gender', 'tbl_groups.name as group_name', 'tbl_language.name as language', - 'tbl_marital_status.marital' + 'tbl_marital_status.marital', + 'tbl_client.upi_no' ) ->where('tbl_client.clinic_number', 'LIKE', '%' . $upn_search . '%') ->whereNull('tbl_client.hei_no') @@ -655,7 +657,8 @@ public function client_extract() 'client_report.mfl_code', 'client_report.facility_name', 'client_report.consented', - 'tbl_client.wellness_enable' + 'tbl_client.wellness_enable', + 'tbl_client.upi_no' ) ->where('client_report.mfl_code', Auth::user()->facility_id) ->get(); @@ -680,7 +683,8 @@ public function client_extract() 'client_report.mfl_code', 'client_report.facility_name', 'client_report.consented', - 'tbl_client.wellness_enable' + 'tbl_client.wellness_enable', + 'tbl_client.upi_no' ) ->where('client_report.partner_id', Auth::user()->partner_id) ->get(); @@ -706,7 +710,8 @@ public function client_extract() 'client_report.mfl_code', 'client_report.facility_name', 'client_report.consented', - 'tbl_client.wellness_enable' + 'tbl_client.wellness_enable', + 'tbl_client.upi_no' ) ->get(); $client_extract; @@ -731,7 +736,8 @@ public function client_extract() 'client_report.mfl_code', 'client_report.facility_name', 'client_report.consented', - 'tbl_client.wellness_enable' + 'tbl_client.wellness_enable', + 'tbl_client.upi_no' ) ->get(); } @@ -762,7 +768,8 @@ public function filter_client_extract(Request $request) 'client_report.mfl_code', 'client_report.facility_name', 'client_report.consented', - 'tbl_client.wellness_enable' + 'tbl_client.wellness_enable', + 'tbl_client.upi_no' ) ->where('client_report.mfl_code', Auth::user()->facility_id) ->whereDate('client_report.created_at', '>=', date($request->from)) @@ -789,7 +796,8 @@ public function filter_client_extract(Request $request) 'client_report.mfl_code', 'client_report.facility_name', 'client_report.consented', - 'tbl_client.wellness_enable' + 'tbl_client.wellness_enable', + 'tbl_client.upi_no' ) ->whereDate('client_report.created_at', '>=', date($request->from)) ->whereDate('client_report.created_at', '<=', date($request->to)) @@ -816,7 +824,8 @@ public function filter_client_extract(Request $request) 'client_report.mfl_code', 'client_report.facility_name', 'client_report.consented', - 'tbl_client.wellness_enable' + 'tbl_client.wellness_enable', + 'tbl_client.upi_no' ) ->whereDate('client_report.created_at', '>=', date($request->from)) ->whereDate('client_report.created_at', '<=', date($request->to)) @@ -842,7 +851,8 @@ public function filter_client_extract(Request $request) 'client_report.mfl_code', 'client_report.facility_name', 'client_report.consented', - 'tbl_client.wellness_enable' + 'tbl_client.wellness_enable', + 'tbl_client.upi_no' ) ->whereDate('client_report.created_at', '>=', date($request->from)) ->whereDate('client_report.created_at', '<=', date($request->to)) diff --git a/app/Http/Controllers/NewReportController.php b/app/Http/Controllers/NewReportController.php index 60dde96..100518c 100644 --- a/app/Http/Controllers/NewReportController.php +++ b/app/Http/Controllers/NewReportController.php @@ -78,7 +78,8 @@ public function clients_list() 'tbl_client.locator_sub_county', 'tbl_client.locator_ward', 'tbl_client.locator_village', - 'tbl_client.locator_location' + 'tbl_client.locator_location', + 'tbl_client.upi_no' ) ->where('tbl_client.status', '=', 'Active') ->whereNull('tbl_client.hei_no') @@ -135,7 +136,8 @@ public function clients_list() 'tbl_client.locator_sub_county', 'tbl_client.locator_ward', 'tbl_client.locator_village', - 'tbl_client.locator_location' + 'tbl_client.locator_location', + 'tbl_client.upi_no' ) ->where('tbl_client.status', '=', 'Active') ->whereNull('tbl_client.hei_no') @@ -192,7 +194,8 @@ public function clients_list() 'tbl_client.locator_sub_county', 'tbl_client.locator_ward', 'tbl_client.locator_village', - 'tbl_client.locator_location' + 'tbl_client.locator_location', + 'tbl_client.upi_no' ) ->where('tbl_client.status', '=', 'Active') ->whereNull('tbl_client.hei_no') diff --git a/resources/views/appointments/future_appointments.blade.php b/resources/views/appointments/future_appointments.blade.php index be206d5..25a85af 100644 --- a/resources/views/appointments/future_appointments.blade.php +++ b/resources/views/appointments/future_appointments.blade.php @@ -26,6 +26,7 @@ No. Clinic Number + UPI Number Serial No First Name Middle Name @@ -42,6 +43,7 @@ {{ $loop->iteration }} {{$result->clinic_number}} + {{$result->upi_no}} {{$result->file_no}} {{$result->f_name}} {{$result->m_name}} diff --git a/resources/views/appointments/future_apps_edit.blade.php b/resources/views/appointments/future_apps_edit.blade.php index 7a27572..3183001 100644 --- a/resources/views/appointments/future_apps_edit.blade.php +++ b/resources/views/appointments/future_apps_edit.blade.php @@ -25,6 +25,7 @@ No. Clinic Number + UPI Number Appointment Date Appointment Type Action @@ -37,6 +38,7 @@ {{ $loop->iteration }} {{$appointment->clinic_number}} + {{$appointment->upi_no}} {{$appointment->appntmnt_date}} {{$appointment->app_type}} diff --git a/resources/views/clients/client_extract.blade.php b/resources/views/clients/client_extract.blade.php index cc1479e..2f614ea 100644 --- a/resources/views/clients/client_extract.blade.php +++ b/resources/views/clients/client_extract.blade.php @@ -70,6 +70,7 @@ No. Clinic Number + UPI Number Gender Group Marital Status @@ -97,6 +98,7 @@ {{ $loop->iteration }} {{$clients->clinic_number}} + {{$clients->upi_no}} {{$clients->gender}} {{$clients->group_name}} {{$clients->marital}} diff --git a/resources/views/clients/client_profile.blade.php b/resources/views/clients/client_profile.blade.php index cb6d0cc..0700114 100644 --- a/resources/views/clients/client_profile.blade.php +++ b/resources/views/clients/client_profile.blade.php @@ -95,6 +95,7 @@ No Full Name + UPI Number Mobile Marital Status Language @@ -119,6 +120,7 @@ {{$loop->iteration }} {{$result->client_name }} + {{$result->upi_no }} {{$result->phone_no}} {{$result->marital}} {{$result->language}} diff --git a/resources/views/new_reports/clients.blade.php b/resources/views/new_reports/clients.blade.php index 73d1f7f..1288133 100644 --- a/resources/views/new_reports/clients.blade.php +++ b/resources/views/new_reports/clients.blade.php @@ -20,6 +20,7 @@ No. CCC Number + UPI Number Client Name Gender DOB @@ -40,6 +41,7 @@ {{ $loop->iteration }} {{$client->clinic_number}} + {{$client->upi_no}} {{$client->f_name}} {{$client->m_name}} {{$client->l_name}} {{$client->gender_name}} {{$client->dob}} From d2731cc3d950feaac72f808fa25e47db8f047dcc Mon Sep 17 00:00:00 2001 From: Ronald-pro <36841157+Ronald-pro@users.noreply.github.com> Date: Fri, 16 Dec 2022 08:49:17 +0300 Subject: [PATCH 131/171] upi dashboards views --- app/Http/Controllers/CalendarController.php | 8 +- app/Http/Controllers/UpiController.php | 41 ++ app/Models/Upi.php | 18 + .../views/dashboard/upi_dashboard.blade.php | 622 ++++++++++++++++++ .../views/reports/cal_appointments.blade.php | 10 +- routes/web.php | 3 + 6 files changed, 697 insertions(+), 5 deletions(-) create mode 100644 app/Http/Controllers/UpiController.php create mode 100644 app/Models/Upi.php create mode 100644 resources/views/dashboard/upi_dashboard.blade.php diff --git a/app/Http/Controllers/CalendarController.php b/app/Http/Controllers/CalendarController.php index 4097a91..c9aafda 100644 --- a/app/Http/Controllers/CalendarController.php +++ b/app/Http/Controllers/CalendarController.php @@ -21,10 +21,10 @@ public function app_calendar() { if (Auth::user()->access_level == 'Facility') { - $name = 'Total Apps:'; + $name = 'Total:'; $app_calendar_data = Appointments::join('tbl_appointment_types', 'tbl_appointment_types.id', '=', 'tbl_appointment.app_type_1') ->join('tbl_client', 'tbl_client.id', '=', 'tbl_appointment.client_id') - ->select('tbl_client.clinic_number', 'tbl_client.file_no', 'tbl_client.phone_no', 'tbl_appointment.app_status', 'tbl_appointment_types.name as app_type', DB::raw("CONCAT(`tbl_client`.`f_name`, ' ', `tbl_client`.`m_name`, ' ', `tbl_client`.`l_name`) as client_name"), 'tbl_appointment.appntmnt_date as start', DB::raw("CONCAT('$this->url_path','/id_all/', tbl_appointment.id) as url"), DB::raw("CONCAT('Total Apps: ', ' ', COUNT(tbl_appointment_types.id)) as title"), 'tbl_appointment.appntmnt_date as end') + ->select('tbl_client.clinic_number', 'tbl_client.file_no', 'tbl_client.phone_no', 'tbl_appointment.app_status', 'tbl_appointment_types.name as app_type', DB::raw("CONCAT(`tbl_client`.`f_name`, ' ', `tbl_client`.`m_name`, ' ', `tbl_client`.`l_name`) as client_name"), 'tbl_appointment.appntmnt_date as start', DB::raw("CONCAT('$this->url_path','/id_all/', tbl_appointment.id) as url"), DB::raw("CONCAT('Total: ', ' ', COUNT(tbl_appointment_types.id)) as title"), 'tbl_appointment.appntmnt_date as end') ->groupBy('tbl_appointment.appntmnt_date') ->where('tbl_client.mfl_code', Auth::user()->facility_id) ->get(); @@ -39,7 +39,7 @@ public function refill_calendar() $app_calendar_data = Appointments::join('tbl_appointment_types', 'tbl_appointment_types.id', '=', 'tbl_appointment.app_type_1') ->join('tbl_client', 'tbl_client.id', '=', 'tbl_appointment.client_id') ->join('tbl_clinic', 'tbl_clinic.id', '=', 'tbl_client.clinic_id') - ->select('tbl_client.clinic_number', 'tbl_clinic.name as clinic', 'tbl_client.file_no', 'tbl_appointment.app_status', 'tbl_client.phone_no', 'tbl_appointment_types.name as app_type', DB::raw("CONCAT(`tbl_client`.`f_name`, ' ', `tbl_client`.`m_name`, ' ', `tbl_client`.`l_name`) as client_name"), 'tbl_appointment.appntmnt_date as start', DB::raw("CONCAT('$this->url_path','/id/', tbl_appointment.id) as url"), DB::raw("CONCAT('Re-fill: ', ' ', COUNT(tbl_appointment_types.id)) as title"), 'tbl_appointment.appntmnt_date as end') + ->select('tbl_client.clinic_number', 'tbl_clinic.name as clinic', 'tbl_client.file_no', 'tbl_appointment.app_status', 'tbl_client.phone_no', 'tbl_appointment_types.name as app_type', DB::raw("CONCAT(`tbl_client`.`f_name`, ' ', `tbl_client`.`m_name`, ' ', `tbl_client`.`l_name`) as client_name"), 'tbl_appointment.appntmnt_date as start', DB::raw("CONCAT('$this->url_path','/id/', tbl_appointment.id) as url"), DB::raw("CONCAT('Refill: ', ' ', COUNT(tbl_appointment_types.id)) as title"), 'tbl_appointment.appntmnt_date as end') ->groupBy('tbl_appointment.appntmnt_date') ->where('tbl_appointment_types.name', '=', 'Re-fill') ->where('tbl_client.mfl_code', Auth::user()->facility_id) @@ -55,7 +55,7 @@ public function refill_apps() $app_calendar_data = Appointments::join('tbl_appointment_types', 'tbl_appointment_types.id', '=', 'tbl_appointment.app_type_1') ->join('tbl_client', 'tbl_client.id', '=', 'tbl_appointment.client_id') ->join('tbl_clinic', 'tbl_clinic.id', '=', 'tbl_client.clinic_id') - ->select('tbl_client.clinic_number', 'tbl_clinic.name as clinic', 'tbl_client.file_no', 'tbl_appointment.app_status', 'tbl_client.phone_no', 'tbl_appointment_types.name as app_type', DB::raw("CONCAT(`tbl_client`.`f_name`, ' ', `tbl_client`.`m_name`, ' ', `tbl_client`.`l_name`) as client_name"), 'tbl_appointment.appntmnt_date as start', DB::raw("CONCAT('$this->url_path','/id/', tbl_appointment.id) as url"), DB::raw("CONCAT('Re-fill: ', ' ', COUNT(tbl_appointment_types.id)) as title"), 'tbl_appointment.appntmnt_date as end') + ->select('tbl_client.clinic_number', 'tbl_clinic.name as clinic', 'tbl_client.file_no', 'tbl_appointment.app_status', 'tbl_client.phone_no', 'tbl_appointment_types.name as app_type', DB::raw("CONCAT(`tbl_client`.`f_name`, ' ', `tbl_client`.`m_name`, ' ', `tbl_client`.`l_name`) as client_name"), 'tbl_appointment.appntmnt_date as start', DB::raw("CONCAT('$this->url_path','/id/', tbl_appointment.id) as url"), DB::raw("CONCAT('Refill: ', ' ', COUNT(tbl_appointment_types.id)) as title"), 'tbl_appointment.appntmnt_date as end') ->groupBy('tbl_appointment.appntmnt_date') ->where('tbl_appointment_types.name', '=', 'Re-fill') ->where('tbl_client.mfl_code', Auth::user()->facility_id) diff --git a/app/Http/Controllers/UpiController.php b/app/Http/Controllers/UpiController.php new file mode 100644 index 0000000..54dbff1 --- /dev/null +++ b/app/Http/Controllers/UpiController.php @@ -0,0 +1,41 @@ +access_level == 'Admin') { + + //$verification_gender = DB::select('CALL sp_rpt_upi_gender(?,?,?,?)', array("%","%", "%", "%")); + $verification_age = DB::select('CALL sp_rpt_upi_gender(?,?,?,?)', array("%","%", "%", "%")); + $verification_list = DB::select('CALL sp_rpt_upi_verification_list(?,?,?,?,?)', array("National","%","%", "%", "%")); + $verification_count = DB::select('CALL sp_rpt_upi_verification_list(?,?,?,?,?)', array("National", "%","%", "%", "%")); + } + if (Auth::user()->access_level == 'Facility') { + $facility = Auth::user()->facility_id; + + $verification_gender = DB::select('CALL sp_rpt_upi_gender(?,?,?,?)', array($facility,"%", "%", "%")); + $verification_age = DB::select('CALL sp_rpt_upi_age(?,?,?,?)', array($facility,"%", "%", "%")); + $verification_list = DB::select('CALL sp_rpt_upi_verification_list(?,?,?,?,?)', array("Facility",$facility,"%", "%", "%")); + $verification_count = DB::select('CALL sp_rpt_upi_verification_list(?,?,?,?,?)', array("Partner",$facility,"%", "%", "%")); + } + if (Auth::user()->access_level == 'Partner') { + $partner = Auth::user()->partner_id; + + $verification_gender = DB::select('CALL sp_rpt_upi_gender(?,?,?,?)', array("%", $partner , "%", "%")); + $verification_age = DB::select('CALL sp_rpt_upi_age(?,?,?,?)', array("%",$partner, "%", "%")); + $verification_list = DB::select('CALL sp_rpt_upi_verification_list(?,?,?,?,?)', array("Partner","%", $partner, "%", "%")); + $verification_count = DB::select('CALL sp_rpt_upi_verification_list(?,?,?,?,?)', array("National","%",$partner, "%", "%")); + } + + //dd($verification_age); + return view('dashboard.upi_dashboard', compact('verification_age', 'verification_gender', 'verification_list', 'verification_count')); + } +} diff --git a/app/Models/Upi.php b/app/Models/Upi.php new file mode 100644 index 0000000..f2fd30f --- /dev/null +++ b/app/Models/Upi.php @@ -0,0 +1,18 @@ + + + +@endsection + +@section('main-content') + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +@endsection \ No newline at end of file diff --git a/resources/views/reports/cal_appointments.blade.php b/resources/views/reports/cal_appointments.blade.php index 3aaf8a3..2a0ad68 100644 --- a/resources/views/reports/cal_appointments.blade.php +++ b/resources/views/reports/cal_appointments.blade.php @@ -15,7 +15,7 @@
    -

    Appointments Summary

    +
    @@ -62,6 +62,14 @@ + + @if(empty($results->appointment_types)) + Appointments Summary - For ALL + @else +

    Appointments Summary - For {{ $results->appointment_types}}

    + @endif + +
    {{ $sum_defaulted}} {{ $sum_ltfu}}
    diff --git a/routes/web.php b/routes/web.php index 0bd7174..a5183b3 100644 --- a/routes/web.php +++ b/routes/web.php @@ -264,4 +264,7 @@ // Route::get('/home/uptake', ['uses' => 'App\Http\Controllers\UptakeController@index', 'as' => 'uptake']); Route::get('/home/uptake', ['uses' => 'App\Http\Controllers\UptakeController@registered', 'as' => 'registered']); Route::get('/filter_uptake', ['uses' => 'App\Http\Controllers\UptakeController@filter_uptake', 'as' => 'filter_uptake']); + + //upi dashboard + Route::get('/upi/dashboard', ['uses' => 'App\Http\Controllers\UpiController@index', 'as' => 'upi_dashboard']); }); From 770297c900eb42aff109fce34663b329fd8e3b07 Mon Sep 17 00:00:00 2001 From: Ronald-pro <36841157+Ronald-pro@users.noreply.github.com> Date: Fri, 16 Dec 2022 11:26:06 +0300 Subject: [PATCH 132/171] populated verified and not verified chart % --- app/Http/Controllers/UpiController.php | 27 ++++++++++++++-- .../views/dashboard/upi_dashboard.blade.php | 31 ++++++++++++------- .../large-vertical-sidebar/sidebar.blade.php | 3 ++ .../new_dashboard/main_dashbaord.blade.php | 2 +- 4 files changed, 48 insertions(+), 15 deletions(-) diff --git a/app/Http/Controllers/UpiController.php b/app/Http/Controllers/UpiController.php index 54dbff1..ba889cf 100644 --- a/app/Http/Controllers/UpiController.php +++ b/app/Http/Controllers/UpiController.php @@ -13,10 +13,11 @@ public function index() { if (Auth::user()->access_level == 'Admin') { - //$verification_gender = DB::select('CALL sp_rpt_upi_gender(?,?,?,?)', array("%","%", "%", "%")); - $verification_age = DB::select('CALL sp_rpt_upi_gender(?,?,?,?)', array("%","%", "%", "%")); + $verification_gender = DB::select('CALL sp_rpt_upi_gender(?,?,?,?)', array("%","%", "%", "%")); + $verification_age = DB::select('CALL sp_rpt_upi_age(?,?,?,?)', array("%","%", "%", "%")); $verification_list = DB::select('CALL sp_rpt_upi_verification_list(?,?,?,?,?)', array("National","%","%", "%", "%")); $verification_count = DB::select('CALL sp_rpt_upi_verification_list(?,?,?,?,?)', array("National", "%","%", "%", "%")); + $verification_count_total = DB::select('CALL sp_rpt_upi_verification_summary(?,?,?,?,?)', array("National", "%","%", "%", "%")); } if (Auth::user()->access_level == 'Facility') { $facility = Auth::user()->facility_id; @@ -25,6 +26,7 @@ public function index() $verification_age = DB::select('CALL sp_rpt_upi_age(?,?,?,?)', array($facility,"%", "%", "%")); $verification_list = DB::select('CALL sp_rpt_upi_verification_list(?,?,?,?,?)', array("Facility",$facility,"%", "%", "%")); $verification_count = DB::select('CALL sp_rpt_upi_verification_list(?,?,?,?,?)', array("Partner",$facility,"%", "%", "%")); + $verification_count_total = DB::select('CALL sp_rpt_upi_verification_summary(?,?,?,?,?)', array("Facility", $facility,"%", "%", "%")); } if (Auth::user()->access_level == 'Partner') { $partner = Auth::user()->partner_id; @@ -33,9 +35,28 @@ public function index() $verification_age = DB::select('CALL sp_rpt_upi_age(?,?,?,?)', array("%",$partner, "%", "%")); $verification_list = DB::select('CALL sp_rpt_upi_verification_list(?,?,?,?,?)', array("Partner","%", $partner, "%", "%")); $verification_count = DB::select('CALL sp_rpt_upi_verification_list(?,?,?,?,?)', array("National","%",$partner, "%", "%")); + $verification_count_total = DB::select('CALL sp_rpt_upi_verification_summary(?,?,?,?,?)', array("Partner", "%", $partner, "%", "%")); + } + if (Auth::user()->access_level == 'County') { + $county = Auth::user()->county_id; + + $verification_gender = DB::select('CALL sp_rpt_upi_gender(?,?,?,?)', array("%", "%", $county, "%")); + $verification_age = DB::select('CALL sp_rpt_upi_age(?,?,?,?)', array("%","%", $county, "%")); + $verification_list = DB::select('CALL sp_rpt_upi_verification_list(?,?,?,?,?)', array("Partner","%", "%", $county, "%")); + $verification_count = DB::select('CALL sp_rpt_upi_verification_list(?,?,?,?,?)', array("National","%","%", $county, "%")); + $verification_count_total = DB::select('CALL sp_rpt_upi_verification_summary(?,?,?,?,?)', array("National", "%", "%", $county, "%")); + } + if (Auth::user()->access_level == 'Sub County') { + $subcounty = Auth::user()->subcounty_id; + + $verification_gender = DB::select('CALL sp_rpt_upi_gender(?,?,?,?)', array("%", "%", "%", $subcounty)); + $verification_age = DB::select('CALL sp_rpt_upi_age(?,?,?,?)', array("%","%", "%", $subcounty)); + $verification_list = DB::select('CALL sp_rpt_upi_verification_list(?,?,?,?,?)', array("Partner","%", "%", "%", $subcounty)); + $verification_count = DB::select('CALL sp_rpt_upi_verification_list(?,?,?,?,?)', array("National","%","%", "%", $subcounty)); + $verification_count_total = DB::select('CALL sp_rpt_upi_verification_summary(?,?,?,?,?)', array("National", "%", "%", "%", $subcounty)); } //dd($verification_age); - return view('dashboard.upi_dashboard', compact('verification_age', 'verification_gender', 'verification_list', 'verification_count')); + return view('dashboard.upi_dashboard', compact('verification_age', 'verification_count_total', 'verification_gender', 'verification_list', 'verification_count')); } } diff --git a/resources/views/dashboard/upi_dashboard.blade.php b/resources/views/dashboard/upi_dashboard.blade.php index 2ddda20..038875a 100644 --- a/resources/views/dashboard/upi_dashboard.blade.php +++ b/resources/views/dashboard/upi_dashboard.blade.php @@ -35,7 +35,7 @@
    -

    {{ number_format(json_decode($verification_count[0]->total)) }}

    +

    {{ number_format(json_decode($verification_count_total[0]->total)) }}

    Registered

    @@ -47,21 +47,21 @@
    -

    {{ number_format(json_decode($verification_count[0]->verified)) }}

    +

    {{ number_format(json_decode($verification_count_total[0]->verified)) }}

    Verified

    -

    {{ number_format(json_decode($verification_count[0]->verified)) }}%

    +

    {{ json_decode($verification_count_total[0]->percenct_verified) }}%

    -
    +
    -

    {{ number_format(json_decode($verification_count[0]->not_verified)) }}

    +

    {{ number_format(json_decode($verification_count_total[0]->not_verified)) }}

    Not Verified

    -

    {{ number_format(json_decode($verification_count[0]->verified)) }}%

    +

    {{ json_decode($verification_count_total[0]->percenct_not_verified) }}%

    @@ -94,11 +94,14 @@

    +

    + +
    @@ -141,7 +144,7 @@
    @endif - @if (Auth::user()->access_level == 'Partner') + @if (Auth::user()->access_level == 'Partner' || Auth::user()->access_level == 'County' || Auth::user()->access_level == 'Sub County')

    Verification Status by Facility

    @@ -320,8 +323,9 @@ var Clients_Verification_Age = ; var Clients_Verification_Gender = ; var Verification_Facility = ; + var Verified_Vs_Not_Verified = ; - console.log(Verification_Facility); + console.log(Verified_Vs_Not_Verified); // verified age var Verified_To_Nine = Clients_Verification_Age.findIndex(item => item.Age === '0-9'); @@ -382,7 +386,7 @@ console.log(Final_Not_Verified_To_Fourteen); - // verified vs not verified + // verified vs not verified gender var Verified_Male = Clients_Verification_Gender.findIndex(item => item.Gender === 'M'); var Final_Verified_Male = (Clients_Verification_Gender[Verified_Male].percenct_verified * 1) //male verified var Verified_Female = Clients_Verification_Gender.findIndex(item => item.Gender === 'F'); @@ -392,6 +396,9 @@ var Not_Verified_Female = Clients_Verification_Gender.findIndex(item => item.Gender === 'F'); var Final_Not_Verified_Female = (Clients_Verification_Gender[Not_Verified_Female].percenct_not_verified * 1) //female not verified + // verified vs not verified summary + var Verified = (Verified_Vs_Not_Verified[0].percenct_verified * 1) //verified + var Not_Verified = (Verified_Vs_Not_Verified[0].percenct_not_verified * 1) //not verified var VerificationAge = Highcharts.chart('verification_age', { @@ -456,6 +463,8 @@ }] }); + + var VerificationFacility = Highcharts.chart('verification_facility', { chart: { type: 'column' @@ -598,11 +607,11 @@ data: [{ name: 'Verified', color: '#01058A', - y: Final_Verified_To_Nine, + y: Verified, z: 92 }, { name: 'Not Verified', - y: Final_Not_Verified_To_Nine, + y: Not_Verified, color: '#97080F', z: 235 }] diff --git a/resources/views/layouts/large-vertical-sidebar/sidebar.blade.php b/resources/views/layouts/large-vertical-sidebar/sidebar.blade.php index 117d2d7..e31e4cd 100644 --- a/resources/views/layouts/large-vertical-sidebar/sidebar.blade.php +++ b/resources/views/layouts/large-vertical-sidebar/sidebar.blade.php @@ -110,6 +110,9 @@ Appointment Register + + Client Verification + @endif @if (Auth::user()->access_level == 'Admin' || Auth::user()->access_level == 'Partner' || Auth::user()->access_level == 'Donor' || Auth::user()->access_level == 'County' || Auth::user()->access_level == 'Sub County') diff --git a/resources/views/new_dashboard/main_dashbaord.blade.php b/resources/views/new_dashboard/main_dashbaord.blade.php index 33db8b4..0c60265 100644 --- a/resources/views/new_dashboard/main_dashbaord.blade.php +++ b/resources/views/new_dashboard/main_dashbaord.blade.php @@ -200,7 +200,7 @@
    - @if (Auth::user()->access_level == 'Admin' || Auth::user()->access_level == 'Partner' || Auth::user()->access_level == 'Donor') + @if (Auth::user()->access_level == 'Admin' || Auth::user()->access_level == 'Partner' || Auth::user()->access_level == 'Donor' || Auth::user()->access_level == 'County' || Auth::user()->access_level == 'Sub County')
    From b2ac9c95648e2bf81837f1c65b0fee5173fddb7e Mon Sep 17 00:00:00 2001 From: Ronald-pro <36841157+Ronald-pro@users.noreply.github.com> Date: Fri, 16 Dec 2022 11:32:23 +0300 Subject: [PATCH 133/171] sidebar for verification --- .../views/layouts/large-vertical-sidebar/sidebar.blade.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/resources/views/layouts/large-vertical-sidebar/sidebar.blade.php b/resources/views/layouts/large-vertical-sidebar/sidebar.blade.php index e31e4cd..d2e3a04 100644 --- a/resources/views/layouts/large-vertical-sidebar/sidebar.blade.php +++ b/resources/views/layouts/large-vertical-sidebar/sidebar.blade.php @@ -120,6 +120,9 @@ Summary + + Client Verification + @endif From 14b65d58f2c6d82dd48445794de146f365f6a842 Mon Sep 17 00:00:00 2001 From: Ronald-pro <36841157+Ronald-pro@users.noreply.github.com> Date: Fri, 16 Dec 2022 11:46:04 +0300 Subject: [PATCH 134/171] change on national verification list --- .../views/dashboard/upi_dashboard.blade.php | 38 ++++++++++++++++++- 1 file changed, 36 insertions(+), 2 deletions(-) diff --git a/resources/views/dashboard/upi_dashboard.blade.php b/resources/views/dashboard/upi_dashboard.blade.php index 038875a..6aecc90 100644 --- a/resources/views/dashboard/upi_dashboard.blade.php +++ b/resources/views/dashboard/upi_dashboard.blade.php @@ -185,7 +185,7 @@

    Verification Status by Partner

    - +
    @@ -319,6 +319,40 @@ }, 'excel', 'pdf', 'print' ] }); + $('#verification_table_national').DataTable({ + columnDefs: [{ + targets: [0], + orderData: [0, 1] + }, { + targets: [1], + orderData: [1, 0] + }, { + targets: [4], + orderData: [4, 0] + }], + "paging": true, + "responsive": true, + "ordering": true, + "info": true, + dom: 'Bfrtip', + buttons: [{ + extend: 'copy', + title: 'Partner List', + filename: 'Partner List' + }, + { + extend: 'csv', + exportOptions: { + columns: ':visible', + modifier: { + page: 'all' + } + }, + title: 'Partner List', + filename: 'Partner List' + }, 'excel', 'pdf', 'print' + ] + }); // appointment var Clients_Verification_Age = ; var Clients_Verification_Gender = ; @@ -464,7 +498,7 @@ }] }); - + var VerificationFacility = Highcharts.chart('verification_facility', { chart: { type: 'column' From 6046532cc69b1ec81ba3b8f2190901f1081d6879 Mon Sep 17 00:00:00 2001 From: Ronald-pro <36841157+Ronald-pro@users.noreply.github.com> Date: Fri, 16 Dec 2022 13:25:30 +0300 Subject: [PATCH 135/171] set limit on graphs y-axis --- resources/views/dashboard/upi_dashboard.blade.php | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/resources/views/dashboard/upi_dashboard.blade.php b/resources/views/dashboard/upi_dashboard.blade.php index 6aecc90..33b3289 100644 --- a/resources/views/dashboard/upi_dashboard.blade.php +++ b/resources/views/dashboard/upi_dashboard.blade.php @@ -462,6 +462,7 @@ crosshair: true }, yAxis: { + max: 100, title: { useHTML: true, text: 'Percentage' @@ -513,6 +514,7 @@ }, yAxis: { min: 0, + max: 100, title: { text: 'Percentage' }, @@ -530,6 +532,7 @@ tooltip: { formatter: function() { return '' + this.x + '
    ' + + this.series.name + ': ' + this.y + this.series.name + ': ' + this.y; } }, @@ -545,7 +548,7 @@ data: Verification_Facility.map(function(x) { return { name: x.name, - y: parseInt(x.verified, 10) + y: parseInt(x.percenct_verified, 10) } }) @@ -555,7 +558,7 @@ data: Verification_Facility.map(function(x) { return { name: x.name, - y: parseInt(x.not_verified, 10) + y: parseInt(x.percenct_not_verified, 10) } }) @@ -579,6 +582,7 @@ crosshair: true }, yAxis: { + max: 100, title: { useHTML: true, text: 'Percentage' From 8cec30870da0892fa8f3a5dde47b494f5adc4dba Mon Sep 17 00:00:00 2001 From: Ronald-pro <36841157+Ronald-pro@users.noreply.github.com> Date: Fri, 16 Dec 2022 17:16:49 +0300 Subject: [PATCH 136/171] changes on upi dashboard --- .../views/dashboard/upi_dashboard.blade.php | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/resources/views/dashboard/upi_dashboard.blade.php b/resources/views/dashboard/upi_dashboard.blade.php index 33b3289..6ced1f7 100644 --- a/resources/views/dashboard/upi_dashboard.blade.php +++ b/resources/views/dashboard/upi_dashboard.blade.php @@ -32,7 +32,7 @@
    -
    +

    {{ number_format(json_decode($verification_count_total[0]->total)) }}

    @@ -44,24 +44,28 @@
    -
    +

    {{ number_format(json_decode($verification_count_total[0]->verified)) }}

    Verified

    -

    {{ json_decode($verification_count_total[0]->percenct_verified) }}%

    +

    {{ json_decode($verification_count_total[0]->percenct_verified) }}%

    + +
    -
    +

    {{ number_format(json_decode($verification_count_total[0]->not_verified)) }}

    Not Verified

    -

    {{ json_decode($verification_count_total[0]->percenct_not_verified) }}%

    + +

    {{ json_decode($verification_count_total[0]->percenct_not_verified) }}%

    +
    @@ -121,7 +125,7 @@
    - + @@ -132,7 +136,7 @@ - + @endforeach @endif @@ -532,7 +536,6 @@ tooltip: { formatter: function() { return '' + this.x + '
    ' + - this.series.name + ': ' + this.y + this.series.name + ': ' + this.y; } }, From 4ccb435c9dfb8d402f3db00f9650076e31760985 Mon Sep 17 00:00:00 2001 From: Ronald-pro <36841157+Ronald-pro@users.noreply.github.com> Date: Mon, 9 Jan 2023 13:40:52 +0300 Subject: [PATCH 137/171] appointment dashboard view --- .../Controllers/FinalDashboardController.php | 11 +- .../views/dashboard/appointment.blade.php | 995 ++++++++++++++++++ .../views/dashboard/upi_dashboard.blade.php | 4 +- routes/web.php | 1 + 4 files changed, 1000 insertions(+), 11 deletions(-) create mode 100644 resources/views/dashboard/appointment.blade.php diff --git a/app/Http/Controllers/FinalDashboardController.php b/app/Http/Controllers/FinalDashboardController.php index 93eaea1..7319eb1 100644 --- a/app/Http/Controllers/FinalDashboardController.php +++ b/app/Http/Controllers/FinalDashboardController.php @@ -20,15 +20,8 @@ class FinalDashboardController extends Controller { - public function dashboard() + public function appointment() { - // $dob = Client::select(\DB::raw(" year(curdate()) - year(`tbl_client`.`dob`) as age")) - // ->where('status', '=', 'Active') - // ->whereNull('hei_no') - // ->pluck('age'); - - // dd($dob); - $tonine = AgeDashboard::select('ToNinenonconsented')->sum('ToNinenonconsented'); - dd(json_encode($tonine)); + return view('dashboard.appointment'); } } diff --git a/resources/views/dashboard/appointment.blade.php b/resources/views/dashboard/appointment.blade.php new file mode 100644 index 0000000..405a6d5 --- /dev/null +++ b/resources/views/dashboard/appointment.blade.php @@ -0,0 +1,995 @@ +@extends('layouts.master') +@section('page-css') + + + +@endsection + +@section('main-content') + + + +
    NoClinic Number Client Name Verification StatusActionPhone Number
    {{$result->clinic_number}} {{$result->client_name}} {{$result->verification_status}}{{$result->mobile_no}}
    + + + + + + + + + + + + + + + + + + +
    NUPI NoClinic NoClient NameDOBPhone NoSMS ConsentStatusPhone NoAppointment KeptAppointment Not Kept
    + +
    + +
    + @endif + + +
    +
    + +
    +
    + +
    + + + +
    + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +@endsection \ No newline at end of file diff --git a/resources/views/dashboard/upi_dashboard.blade.php b/resources/views/dashboard/upi_dashboard.blade.php index 6ced1f7..bf8e78e 100644 --- a/resources/views/dashboard/upi_dashboard.blade.php +++ b/resources/views/dashboard/upi_dashboard.blade.php @@ -5,7 +5,7 @@ @endsection @@ -99,7 +118,7 @@
    - @if (count($partners) > 0) @foreach($partners as $partner) @@ -181,12 +200,8 @@
    -
    - -
    -
    - - +
    +
    @@ -197,12 +212,9 @@
    -
    - -
    -
    +
    - +
    @@ -266,7 +278,7 @@
    -
    +
    -
    +
    -
    +
    +
    +
    +
    -
    +
    +
    +
    +
    +
    +
    +
    - +
    @@ -315,14 +336,109 @@
    +
    + + +
    +
    +
    + + + +
    +@endif +@if (Auth::user()->access_level == 'Partner') +
    +
    + {{ csrf_field() }} +
    +
    +
    + +
    +
    +
    +
    + +
    +
    +
    +
    + +
    +
    +
    +
    + +
    +
    +
    +
    + +
    +
    +
    +
    + +
    +
    + +
    -
    - +
    +
    -
    +
    - +
    +
    +
    +
    +
    +
    +
    +
    + +
    @@ -360,7 +476,7 @@
    -
    +
    -
    +
    -
    +
    +
    +
    @@ -411,12 +523,9 @@
    -
    - -
    -
    +
    - +
    @@ -467,12 +576,8 @@
    -
    - -
    -
    - - +
    +
    @@ -483,12 +588,9 @@
    -
    - -
    -
    +
    - +
    @@ -621,23 +723,10 @@
    -
    -
    -
    -
    -
    -
    -

    -

    Indicator Definition

    - -
    - -
    -
    -
    - - -
    +
    +

    Indicator Definition

    +

    Appointment Honored & Not Honored

    +

    {{ json_encode($indicator_k[0]->description) }}

    @@ -668,6 +757,36 @@
    + @if (Auth::user()->access_level == 'Sub County' || Auth::user()->access_level == 'Partner') + +
    +
    + +
    +
    +

    +
    +
    + + +
    +
    + @endif + @if (Auth::user()->access_level == 'County') + +
    +
    + +
    +
    +

    +
    +
    + + +
    +
    + @endif @if (Auth::user()->access_level == 'Admin' || Auth::user()->access_level == 'Donor')
    @@ -922,22 +1041,14 @@
    -
    -
    -
    -
    -
    -

    -

    Indicator Definition

    -
    - -
    -
    - -
    +
    +

    Indicator Definition

    +

    Missed Appointments

    +

    {{ json_encode($indicator_m[0]->description) }}

    +
    @@ -978,6 +1089,36 @@
    + @if (Auth::user()->access_level == 'Sub County' || Auth::user()->access_level == 'Partner') + +
    +
    + +
    +
    +

    +
    +
    + + +
    +
    + @endif + @if (Auth::user()->access_level == 'County') + +
    +
    + +
    +
    +

    +
    +
    + + +
    +
    + @endif @if (Auth::user()->access_level == 'Admin' || Auth::user()->access_level == 'Donor')
    @@ -1172,7 +1313,7 @@ // console.log(authenticated); Swal.fire({ - title: "Please wait, Loading Charts!", + title: "Please wait, loading...", showConfirmButton: false, allowOutsideClick: false }); @@ -1202,19 +1343,25 @@ missedCounty(data.missed_county); missedPartner(data.missed_partner); } - if (authenticated == 'County' || authenticated == 'Sub County') { + if (authenticated == 'County') { appPartner(data.appointment_partner) missedPartner(data.missed_partner); } + if (authenticated == 'Partner' || authenticated == 'Sub County') { + appFacility(data.appointment_facility) + missedFacility(data.missed_facility) + } missedPeriod(data.app_period); for (var x = 0; x < consent.length; x++) { - consented = consent[x].consented; + consented = (consent[x].consented).toLocaleString(); + console.log(consented); if (consented == undefined || consented == null) { consented = 0; } else { consented = consented.toLocaleString(); + console.log(consented); } percnt_consented = Math.round(consent[x].percent_consented).toFixed(0) + '%'; } @@ -1313,29 +1460,29 @@ } contacted = missed[x].called; - if (contacted == undefined || contacted == null) { - contacted = 0; - } else { - contacted = contacted.toLocaleString(); - } - contacted_missed = missed[x].missed_called; - if (contacted_missed == undefined || contacted_missed == null) { - contacted_missed = 0; - } else { - contacted_missed = contacted_missed.toLocaleString(); - } - contacted_defaulted = missed[x].defaulted_called; - if (contacted_defaulted == undefined || contacted_defaulted == null) { - contacted_defaulted = 0; - } else { - contacted_defaulted = contacted_defaulted.toLocaleString(); - } - contacted_iit = missed[x].iit_called; - if (contacted_iit == undefined || contacted_iit == null) { - contacted_iit = 0; - } else { - contacted_iit = contacted_iit.toLocaleString(); - } + if (contacted == undefined || contacted == null) { + contacted = 0; + } else { + contacted = contacted.toLocaleString(); + } + contacted_missed = missed[x].missed_called; + if (contacted_missed == undefined || contacted_missed == null) { + contacted_missed = 0; + } else { + contacted_missed = contacted_missed.toLocaleString(); + } + contacted_defaulted = missed[x].defaulted_called; + if (contacted_defaulted == undefined || contacted_defaulted == null) { + contacted_defaulted = 0; + } else { + contacted_defaulted = contacted_defaulted.toLocaleString(); + } + contacted_iit = missed[x].iit_called; + if (contacted_iit == undefined || contacted_iit == null) { + contacted_iit = 0; + } else { + contacted_iit = contacted_iit.toLocaleString(); + } traced = missed[x].physically_traced; if (traced == undefined || traced == null) { @@ -1448,7 +1595,7 @@ } }); Swal.fire({ - title: "Please wait, Loading Charts!", + title: "Please wait, loading...", showConfirmButton: false, allowOutsideClick: false }); @@ -1475,7 +1622,7 @@ const missed = data.client_missed; appGender(data.appointment_gender); appAge(data.appointment_age); - appMarital(data.appointment_marital);; + appMarital(data.appointment_marital); missedAge(data.missed_age); missedGender(data.missed_gender); @@ -1486,10 +1633,14 @@ missedCounty(data.missed_county); missedPartner(data.missed_partner); } - if (authenticated == 'County' || authenticated == 'Sub County') { + if (authenticated == 'County') { appPartner(data.appointment_partner) missedPartner(data.missed_partner); } + if (authenticated == 'Partner' || authenticated == 'Sub County') { + appFacility(data.appointment_facility) + missedFacility(data.missed_facility) + } missedPeriod(data.app_period); console.log(missed); @@ -1501,7 +1652,7 @@ } else { consented = consented.toLocaleString(); } - percnt_consented = Math.round(consent[x].percent_consented).toFixed(1); + percnt_consented = Math.round(consent[x].percent_consented).toFixed(1) + '%'; } for (var x = 0; x < apps.length; x++) { all_appointments = apps[x].total_app; @@ -1534,9 +1685,10 @@ } else { sms_sent = sms_sent.toLocaleString(); } - percnt_kept = parseFloat(apps[x].percent_kept).toFixed(1); - percnt_not_kept = parseFloat(apps[x].percent_not_kept).toFixed(1); - percnt_future = parseFloat(apps[x].percent_future).toFixed(1); + + percnt_kept = parseFloat(apps[x].percent_kept).toFixed(1) + '%'; + percnt_not_kept = parseFloat(apps[x].percent_not_kept).toFixed(1) + '%'; + percnt_future = parseFloat(apps[x].percent_future).toFixed(1) + '%'; } for (var x = 0; x < tx.length; x++) { tx_curr = tx[x].tx_cur; @@ -1758,10 +1910,15 @@ function appAge(data) { let age_group = []; + let kept_app = []; + let not_kept_app = []; + let total = []; let percent_kept = []; let percent_not_kept = []; for (let i = 0; i < data.length; i++) { age_group.push(data[i].age_group); + + not_kept_app.push(data[i].not_kept_app) parseFloat(percent_kept.push(data[i].percent_kept)).toFixed(1); parseFloat(percent_not_kept.push(data[i].percent_not_kept)).toFixed(1); } @@ -1798,12 +1955,11 @@ function appAge(data) { } }, tooltip: { - headerFormat: '{point.key}', - pointFormat: '' + - '', - footerFormat: '
    {series.name}: {point.y:.1f}
    ', - shared: true, - useHTML: true + + formatter: function() { + return '' + this.x + '
    ' + + this.series.name + ': ' + this.y + '%'; + } }, plotOptions: { column: { @@ -1831,8 +1987,8 @@ function appGender(data) { let percent_not_kept = []; for (let i = 0; i < data.length; i++) { gender.push(data[i].gender); - parseFloat(percent_kept.push(data[i].percent_kept)).toFixed(1); - parseFloat(percent_not_kept.push(data[i].percent_not_kept)).toFixed(1); + Math.round(percent_kept.push(data[i].percent_kept)).toFixed(1); + Math.round(percent_not_kept.push(data[i].percent_not_kept)).toFixed(1); } Highcharts.chart('appointment_gender', { chart: { @@ -1867,12 +2023,11 @@ function appGender(data) { } }, tooltip: { - headerFormat: '{point.key}', - pointFormat: '' + - '', - footerFormat: '
    {series.name}: {point.y:.1f}
    ', - shared: true, - useHTML: true + + formatter: function() { + return '' + this.x + '
    ' + + this.series.name + ': ' + this.y + '%'; + } }, plotOptions: { column: { @@ -1899,8 +2054,8 @@ function appMarital(data) { let percent_not_kept = []; for (let i = 0; i < data.length; i++) { marital.push(data[i].marital); - parseFloat(percent_kept.push(data[i].percent_kept)).toFixed(1); - parseFloat(percent_not_kept.push(data[i].percent_not_kept)).toFixed(1); + Math.round(percent_kept.push(data[i].percent_kept)).toFixed(1); + Math.round(percent_not_kept.push(data[i].percent_not_kept)).toFixed(1); } Highcharts.chart('distribution_marital', { chart: { @@ -1944,7 +2099,7 @@ function appMarital(data) { tooltip: { formatter: function() { return '' + this.x + '
    ' + - this.series.name + ': ' + this.y; + this.series.name + ': ' + this.y + '%'; } }, plotOptions: { @@ -1974,8 +2129,8 @@ function missedGender(data) { let percent_not_kept = []; for (let i = 0; i < data.length; i++) { gender.push(data[i].gender); - parseFloat(percent_rtc.push(data[i].percent_rtc)).toFixed(1); - parseFloat(percent_not_kept.push(data[i].percent_not_kept)).toFixed(1); + Math.round(percent_rtc.push(data[i].percent_rtc)).toFixed(1); + Math.round(percent_not_kept.push(data[i].percent_not_kept)).toFixed(1); } Highcharts.chart('missed_gender', { chart: { @@ -2016,7 +2171,7 @@ function missedGender(data) { tooltip: { formatter: function() { return '' + this.x + '
    ' + - this.series.name + ': ' + this.y; + this.series.name + ': ' + this.y + '%'; } }, plotOptions: { @@ -2047,8 +2202,8 @@ function missedAge(data) { let percent_not_kept = []; for (let i = 0; i < data.length; i++) { age_group.push(data[i].age_group); - parseFloat(percent_rtc.push(data[i].percent_rtc)).toFixed(1); - parseFloat(percent_not_kept.push(data[i].percent_not_kept)).toFixed(1); + Math.round(percent_rtc.push(data[i].percent_rtc)).toFixed(1); + Math.round(percent_not_kept.push(data[i].percent_not_kept)).toFixed(1); } Highcharts.chart('missed_age', { chart: { @@ -2089,7 +2244,7 @@ function missedAge(data) { tooltip: { formatter: function() { return '' + this.x + '
    ' + - this.series.name + ': ' + this.y; + this.series.name + ': ' + this.y + '%'; } }, plotOptions: { @@ -2120,8 +2275,8 @@ function missedMarital(data) { let percent_not_kept = []; for (let i = 0; i < data.length; i++) { marital.push(data[i].marital); - parseFloat(percent_rtc.push(data[i].percent_rtc)).toFixed(1); - parseFloat(percent_not_kept.push(data[i].percent_not_kept)).toFixed(1); + Math.round(percent_rtc.push(data[i].percent_rtc)).toFixed(1); + Math.round(percent_not_kept.push(data[i].percent_not_kept)).toFixed(1); } Highcharts.chart('missed_marital', { chart: { @@ -2162,7 +2317,7 @@ function missedMarital(data) { tooltip: { formatter: function() { return '' + this.x + '
    ' + - this.series.name + ': ' + this.y; + this.series.name + ': ' + this.y + '%'; } }, plotOptions: { @@ -2193,8 +2348,8 @@ function missedPeriod(data) { let percent_not_kept = []; for (let i = 0; i < data.length; i++) { new_date.push(data[i].new_date); - parseFloat(percent_rtc.push(data[i].percent_rtc)).toFixed(1); - parseFloat(percent_not_kept.push(data[i].percent_not_kept)).toFixed(1); + Math.round(percent_rtc.push(data[i].percent_rtc)).toFixed(1); + Math.round(percent_not_kept.push(data[i].percent_not_kept)).toFixed(1); } Highcharts.chart('missed_period', { chart: { @@ -2235,7 +2390,7 @@ function missedPeriod(data) { tooltip: { formatter: function() { return '' + this.x + '
    ' + - this.series.name + ': ' + this.y; + this.series.name + ': ' + this.y + '%'; } }, plotOptions: { @@ -2267,8 +2422,8 @@ function appCounty(data) { let percent_not_kept = []; for (let i = 0; i < data.length; i++) { county.push(data[i].county); - parseFloat(percent_kept.push(data[i].percent_kept)).toFixed(1); - parseFloat(percent_not_kept.push(data[i].percent_not_kept)).toFixed(1); + Math.round(percent_kept.push(data[i].percent_kept)).toFixed(1); + Math.round(percent_not_kept.push(data[i].percent_not_kept)).toFixed(1); } Highcharts.chart('distribution_county', { chart: { @@ -2311,7 +2466,7 @@ function appCounty(data) { tooltip: { formatter: function() { return '' + this.x + '
    ' + - this.series.name + ': ' + this.y; + this.series.name + ': ' + this.y + '%'; } }, plotOptions: { @@ -2341,8 +2496,8 @@ function missedCounty(data) { let percent_not_kept = []; for (let i = 0; i < data.length; i++) { county.push(data[i].county); - parseFloat(percent_rtc.push(data[i].percent_rtc)).toFixed(1); - parseFloat(percent_not_kept.push(data[i].percent_not_kept)).toFixed(1); + Math.round(percent_rtc.push(data[i].percent_rtc)).toFixed(1); + Math.round(percent_not_kept.push(data[i].percent_not_kept)).toFixed(1); } Highcharts.chart('missed_county', { chart: { @@ -2383,7 +2538,7 @@ function missedCounty(data) { tooltip: { formatter: function() { return '' + this.x + '
    ' + - this.series.name + ': ' + this.y; + this.series.name + ': ' + this.y + '%'; } }, plotOptions: { @@ -2414,8 +2569,8 @@ function missedPartner(data) { let percent_not_kept = []; for (let i = 0; i < data.length; i++) { partner.push(data[i].partner); - parseFloat(percent_rtc.push(data[i].percent_rtc)).toFixed(1); - parseFloat(percent_not_kept.push(data[i].percent_not_kept)).toFixed(1); + Math.round(percent_rtc.push(data[i].percent_rtc)).toFixed(1); + Math.round(percent_not_kept.push(data[i].percent_not_kept)).toFixed(1); } Highcharts.chart('missed_partner', { chart: { @@ -2456,7 +2611,7 @@ function missedPartner(data) { tooltip: { formatter: function() { return '' + this.x + '
    ' + - this.series.name + ': ' + this.y; + this.series.name + ': ' + this.y + '%'; } }, plotOptions: { @@ -2487,8 +2642,8 @@ function appPartner(data) { let percent_not_kept = []; for (let i = 0; i < data.length; i++) { partner.push(data[i].partner); - parseFloat(percent_kept.push(data[i].percent_kept)).toFixed(1); - parseFloat(percent_not_kept.push(data[i].percent_not_kept)).toFixed(1); + Math.round(percent_kept.push(data[i].percent_kept)).toFixed(1); + Math.round(percent_not_kept.push(data[i].percent_not_kept)).toFixed(1); } Highcharts.chart('distribution_partner', { chart: { @@ -2530,7 +2685,7 @@ function appPartner(data) { tooltip: { formatter: function() { return '' + this.x + '
    ' + - this.series.name + ': ' + this.y; + this.series.name + ': ' + this.y + '%'; } }, plotOptions: { @@ -2555,15 +2710,15 @@ function appPartner(data) { } } - if (authenticated == 'County' || authenticated == 'Sub County') { + if (authenticated == 'County') { function missedPartner(data) { let partner = []; let percent_rtc = []; let percent_not_kept = []; for (let i = 0; i < data.length; i++) { partner.push(data[i].partner); - parseFloat(percent_rtc.push(data[i].percent_rtc)).toFixed(); - parseFloat(percent_not_kept.push(data[i].percent_not_kept)).toFixed(1); + Math.round(percent_rtc.push(data[i].percent_rtc)).toFixed(); + Math.round(percent_not_kept.push(data[i].percent_not_kept)).toFixed(1); } Highcharts.chart('missed_partner', { chart: { @@ -2604,7 +2759,7 @@ function missedPartner(data) { tooltip: { formatter: function() { return '' + this.x + '
    ' + - this.series.name + ': ' + this.y; + this.series.name + ': ' + this.y + '%'; } }, plotOptions: { @@ -2635,8 +2790,8 @@ function appPartner(data) { let percent_not_kept = []; for (let i = 0; i < data.length; i++) { partner.push(data[i].partner); - parseFloat(percent_kept.push(data[i].percent_kept)).toFixed(1); - parseFloat(percent_not_kept.push(data[i].percent_not_kept)).toFixed(1); + Math.round(percent_kept.push(data[i].percent_kept)).toFixed(1); + Math.round(percent_not_kept.push(data[i].percent_not_kept)).toFixed(1); } Highcharts.chart('distribution_partner', { chart: { @@ -2678,7 +2833,81 @@ function appPartner(data) { tooltip: { formatter: function() { return '' + this.x + '
    ' + - this.series.name + ': ' + this.y; + this.series.name + ': ' + this.y + '%'; + } + }, + plotOptions: { + column: { + pointPadding: 0.2, + borderWidth: 0 + } + }, + series: [{ + name: 'Kept', + color: '#01058A', + data: percent_kept + + }, { + name: 'Not Kept', + color: '#97080F', + data: percent_not_kept + + }], + + }); + } + } + if (authenticated == 'Partner' || authenticated == 'Sub County') { + function appFacility(data) { + let facility = []; + let percent_kept = []; + let percent_not_kept = []; + for (let i = 0; i < data.length; i++) { + facility.push(data[i].facility); + Math.round(percent_kept.push(data[i].percent_kept)).toFixed(1); + Math.round(percent_not_kept.push(data[i].percent_not_kept)).toFixed(1); + } + Highcharts.chart('distribution_facility', { + chart: { + type: 'column' + }, + legend: { + itemStyle: { + fontFamily: 'Manrope', + fontSize: '12px' + } + }, + title: { + text: 'Appointment Distribution by Facility', + style: { + fontFamily: 'Manrope', + fontSize: '12px' + } + }, + xAxis: { + categories: facility, + }, + yAxis: { + min: 0, + max: 100, + title: { + text: 'Percentage' + }, + stackLabels: { + enabled: true, + style: { + fontWeight: 'bold', + color: ( // theme + Highcharts.defaultOptions.title.style && + Highcharts.defaultOptions.title.style.color + ) || 'gray' + } + } + }, + tooltip: { + formatter: function() { + return '' + this.x + '
    ' + + this.series.name + ': ' + this.y + '%'; } }, plotOptions: { @@ -2701,6 +2930,79 @@ function appPartner(data) { }); } + + function missedFacility(data) { + let facility = []; + let percent_rtc = []; + let percent_not_kept = []; + for (let i = 0; i < data.length; i++) { + facility.push(data[i].facility); + Math.round(percent_rtc.push(data[i].percent_rtc)).toFixed(); + Math.round(percent_not_kept.push(data[i].percent_not_kept)).toFixed(1); + } + Highcharts.chart('missed_facility', { + chart: { + type: 'column' + }, + legend: { + itemStyle: { + fontFamily: 'Manrope', + fontSize: '12px' + } + }, + title: { + text: 'Missed Appointment Distribution by Facility', + style: { + fontFamily: 'Manrope', + fontSize: '12px' + } + }, + xAxis: { + categories: facility, + }, + yAxis: { + min: 0, + max: 100, + title: { + text: 'Percentage' + }, + stackLabels: { + enabled: true, + style: { + fontWeight: 'bold', + color: ( // theme + Highcharts.defaultOptions.title.style && + Highcharts.defaultOptions.title.style.color + ) || 'gray' + } + } + }, + tooltip: { + formatter: function() { + return '' + this.x + '
    ' + + this.series.name + ': ' + this.y + '%'; + } + }, + plotOptions: { + column: { + pointPadding: 0.2, + borderWidth: 0 + } + }, + series: [{ + name: 'Missed', + color: '#01058A', + data: percent_not_kept + + }, { + name: 'Returned To Care', + color: '#97080F', + data: percent_rtc + + }], + + }); + } } From 78847e3553bd37e92001eac7e6de9b7d642e7684 Mon Sep 17 00:00:00 2001 From: Ronald-pro <36841157+Ronald-pro@users.noreply.github.com> Date: Wed, 8 Feb 2023 15:36:41 +0300 Subject: [PATCH 148/171] labelling and added missing client info on the linelist --- .../Controllers/FinalDashboardController.php | 16 ++++- app/Http/Controllers/UserController.php | 55 +++++++++++++++++ .../views/dashboard/appointment.blade.php | 8 +++ .../large-vertical-sidebar/header.blade.php | 59 ++++++++++++++++++- routes/web.php | 1 + 5 files changed, 136 insertions(+), 3 deletions(-) diff --git a/app/Http/Controllers/FinalDashboardController.php b/app/Http/Controllers/FinalDashboardController.php index 0fd2e61..3f3e807 100644 --- a/app/Http/Controllers/FinalDashboardController.php +++ b/app/Http/Controllers/FinalDashboardController.php @@ -47,6 +47,8 @@ public function index() 'etl_client_detail.dob', 'etl_client_detail.consented', 'etl_client_detail.client_status', + 'etl_client_detail.client_name', + 'etl_client_detail.phone_no', DB::raw('COUNT(etl_appointment_detail.app_kept) AS kept_app '), DB::raw('SUM(etl_appointment_detail.app_not_kept) AS not_kept_app ') ) @@ -60,6 +62,8 @@ public function index() 'etl_client_detail.dob', 'etl_client_detail.consented', 'etl_client_detail.client_status', + 'etl_client_detail.client_name', + 'etl_client_detail.phone_no', 'etl_appointment_detail.days_defaulted', 'etl_appointment_detail.final_outcome' ) @@ -186,6 +190,8 @@ public function appointment() 'etl_client_detail.dob', 'etl_client_detail.consented', 'etl_client_detail.client_status', + 'etl_client_detail.client_name', + 'etl_client_detail.phone_no', DB::raw('COUNT(etl_appointment_detail.app_kept) AS kept_app '), DB::raw('SUM(etl_appointment_detail.app_not_kept) AS not_kept_app ') ) @@ -306,7 +312,9 @@ public function appointment() 'etl_client_detail.consented', 'etl_client_detail.client_status', 'etl_appointment_detail.days_defaulted', - 'etl_appointment_detail.final_outcome' + 'etl_appointment_detail.final_outcome', + 'etl_client_detail.client_name', + 'etl_client_detail.phone_no' ) ->join('etl_appointment_detail', 'etl_client_detail.client_id', '=', 'etl_appointment_detail.client_id') ->where('etl_client_detail.mfl_code', Auth::user()->facility_id) @@ -1564,6 +1572,8 @@ public function filter_data(Request $request) 'etl_client_detail.dob', 'etl_client_detail.consented', 'etl_client_detail.client_status', + 'etl_client_detail.client_name', + 'etl_client_detail.phone_no', DB::raw('COUNT(etl_appointment_detail.app_kept) AS kept_app '), DB::raw('SUM(etl_appointment_detail.app_not_kept) AS not_kept_app ') ) @@ -1674,7 +1684,9 @@ public function filter_data(Request $request) 'etl_client_detail.consented', 'etl_client_detail.client_status', 'etl_appointment_detail.days_defaulted', - 'etl_appointment_detail.final_outcome' + 'etl_appointment_detail.final_outcome', + 'etl_client_detail.client_name', + 'etl_client_detail.phone_no' ) ->join('etl_appointment_detail', 'etl_client_detail.client_id', '=', 'etl_appointment_detail.client_id') ->where('etl_client_detail.mfl_code', Auth::user()->facility_id) diff --git a/app/Http/Controllers/UserController.php b/app/Http/Controllers/UserController.php index a633410..fddf284 100644 --- a/app/Http/Controllers/UserController.php +++ b/app/Http/Controllers/UserController.php @@ -21,6 +21,61 @@ class UserController extends Controller { // + public function user_info() + { + if (Auth::user()->access_level == 'Sub County') { + $data = []; + + $user_info = DB::table('tbl_users')->select( + 'tbl_sub_county.name as sub_county' + )->join('tbl_partner_facility', 'tbl_users.subcounty_id', '=', 'tbl_partner_facility.sub_county_id') + ->join('tbl_sub_county', 'tbl_partner_facility.sub_county_id', '=', 'tbl_sub_county.id') + ->where('tbl_sub_county.id', '=', Auth::user()->subcounty_id) + ->groupBy('tbl_sub_county.name'); + $data["user_info"] = $user_info->get(); + + return $data; + } + if (Auth::user()->access_level == 'County') { + $data = []; + + $user_info = DB::table('tbl_users')->select( + 'tbl_county.name as county' + )->join('tbl_partner_facility', 'tbl_users.county_id', '=', 'tbl_partner_facility.county_id') + ->join('tbl_county', 'tbl_partner_facility.county_id', '=', 'tbl_county.id') + ->where('tbl_county.id', '=', Auth::user()->county_id) + ->groupBy('tbl_county.name'); + $data["user_info"] = $user_info->get(); + + return $data; + } + if (Auth::user()->access_level == 'Facility') { + $data = []; + + $user_info = DB::table('tbl_users')->select( + 'tbl_master_facility.name as facility', 'tbl_master_facility.code' + )->join('tbl_partner_facility', 'tbl_users.facility_id', '=', 'tbl_partner_facility.mfl_code') + ->join('tbl_master_facility', 'tbl_partner_facility.mfl_code', '=', 'tbl_master_facility.code') + ->where('tbl_master_facility.code', '=', Auth::user()->facility_id) + ->groupBy('tbl_master_facility.name'); + $data["user_info"] = $user_info->get(); + + return $data; + } + if (Auth::user()->access_level == 'Partner') { + $data = []; + + $user_info = DB::table('tbl_users')->select( + 'tbl_partner.name as partner' + )->join('tbl_partner_facility', 'tbl_users.facility_id', '=', 'tbl_partner_facility.mfl_code') + ->join('tbl_partner', 'tbl_partner_facility.partner_id', '=', 'tbl_partner.id') + ->where('tbl_partner.id', '=', Auth::user()->partner_id) + ->groupBy('tbl_partner.name'); + $data["user_info"] = $user_info->get(); + + return $data; + } + } public function showUsers() { if (Auth::user()->access_level == 'Partner') { diff --git a/resources/views/dashboard/appointment.blade.php b/resources/views/dashboard/appointment.blade.php index a5d362f..0203047 100644 --- a/resources/views/dashboard/appointment.blade.php +++ b/resources/views/dashboard/appointment.blade.php @@ -831,7 +831,9 @@ NUPI No Clinic No + Client Name DOB + Phone No SMS Consent Status Appointment Kept @@ -845,7 +847,9 @@ {{$result->upi_no}} {{$result->ccc_number}} + {{$result->client_name}} {{$result->dob}} + {{$result->phone_no}} {{$result->consented}} {{$result->client_status}} {{$result->kept_app}} @@ -1160,7 +1164,9 @@ NUPI No Clinic No + Client Name DOB + Phone No SMS Consent Status No of Days Missed @@ -1174,7 +1180,9 @@ {{$result->upi_no}} {{$result->ccc_number}} + {{$result->client_name}} {{$result->dob}} + {{$result->phone_no}} {{$result->consented}} {{$result->client_status}} {{$result->days_defaulted}} diff --git a/resources/views/layouts/large-vertical-sidebar/header.blade.php b/resources/views/layouts/large-vertical-sidebar/header.blade.php index 53904af..0a96546 100644 --- a/resources/views/layouts/large-vertical-sidebar/header.blade.php +++ b/resources/views/layouts/large-vertical-sidebar/header.blade.php @@ -1,6 +1,7 @@
    + + @if (Auth::user()->access_level == 'Sub County') +
    +
    Sub County
    + @elseif(Auth::user()->access_level == 'County') +
    +
    County
    + @elseif(Auth::user()->access_level == 'Partner') +
    + @elseif(Auth::user()->access_level == 'Facility') +
    + @else +
    National Super Administrator
    + @endif
    @@ -33,6 +48,7 @@
    ushauri +
    + + \ No newline at end of file diff --git a/routes/web.php b/routes/web.php index 751b7a7..4038a64 100644 --- a/routes/web.php +++ b/routes/web.php @@ -270,4 +270,5 @@ Route::get('/home/appointment', ['uses' => 'App\Http\Controllers\FinalDashboardController@index', 'as' => 'appointment-dashboard']); Route::get('/appointment/data', ['uses' => 'App\Http\Controllers\FinalDashboardController@appointment', 'as' => 'appointment_data']); Route::get('/filter_app_data', ['uses' => 'App\Http\Controllers\FinalDashboardController@filter_data', 'as' => 'filter_app_data']); + Route::get('/user/info', ['uses' => 'App\Http\Controllers\UserController@user_info', 'as' => 'user_info']); }); From ef5e50bdaae49a42f40696f29428181404b569d5 Mon Sep 17 00:00:00 2001 From: Ronald-pro <36841157+Ronald-pro@users.noreply.github.com> Date: Thu, 9 Feb 2023 17:07:07 +0300 Subject: [PATCH 149/171] cards rearrangment,styling and other fixes --- .../Controllers/FinalDashboardController.php | 57 +- .../views/dashboard/appointment.blade.php | 682 ++++++++++-------- .../large-vertical-sidebar/header.blade.php | 3 + 3 files changed, 439 insertions(+), 303 deletions(-) diff --git a/app/Http/Controllers/FinalDashboardController.php b/app/Http/Controllers/FinalDashboardController.php index 3f3e807..f0e9ed9 100644 --- a/app/Http/Controllers/FinalDashboardController.php +++ b/app/Http/Controllers/FinalDashboardController.php @@ -48,6 +48,7 @@ public function index() 'etl_client_detail.consented', 'etl_client_detail.client_status', 'etl_client_detail.client_name', + 'etl_client_detail.dsd_status', 'etl_client_detail.phone_no', DB::raw('COUNT(etl_appointment_detail.app_kept) AS kept_app '), DB::raw('SUM(etl_appointment_detail.app_not_kept) AS not_kept_app ') @@ -64,6 +65,7 @@ public function index() 'etl_client_detail.client_status', 'etl_client_detail.client_name', 'etl_client_detail.phone_no', + 'etl_client_detail.dsd_status', 'etl_appointment_detail.days_defaulted', 'etl_appointment_detail.final_outcome' ) @@ -163,6 +165,7 @@ public function appointment() ) ->whereNotNull('gender') ->where('mfl_code', Auth::user()->facility_id) + ->orderBy('percent_kept', 'DESC') ->groupBy('gender'); $appointment_age = ETLAppointment::select( 'age_group', @@ -183,6 +186,7 @@ public function appointment() ) ->whereNotNull('marital') ->where('mfl_code', Auth::user()->facility_id) + ->orderBy('percent_kept', 'DESC') ->groupBy('marital'); $client_list = DB::table('etl_client_detail')->select( 'etl_client_detail.upi_no', @@ -270,6 +274,7 @@ public function appointment() ) ->whereNotNull('gender') ->where('mfl_code', Auth::user()->facility_id) + ->orderBy('percent_rtc', 'DESC') ->groupBy('gender'); $missed_marital = DB::table('etl_appointment_detail')->select( 'marital', @@ -280,6 +285,7 @@ public function appointment() ) ->whereNotNull('marital') ->where('mfl_code', Auth::user()->facility_id) + ->orderBy('percent_rtc', 'DESC') ->groupBy('marital'); $missed_county = DB::table('etl_appointment_detail')->select( 'county', @@ -328,7 +334,7 @@ public function appointment() ->where('mfl_code', Auth::user()->facility_id) ->where('appointment_date', '<=', date("Y-M-D")) ->where(DB::raw('DATE_FORMAT(appointment_date, "%Y-%M")'), '>=', "2017-January") - ->orderBy('new_date', 'ASC') + ->orderBy('appointment_date', 'ASC') ->groupBy('new_date'); $data["all_appoinments"] = $all_appoinments->get(); @@ -382,6 +388,7 @@ public function appointment() DB::raw('AVG(percent_not_kept) AS percent_not_kept ') ) ->whereNotNull('gender') + ->orderBy('percent_kept', 'DESC') ->groupBy('gender'); $appointment_age = ETLAppointment::select( 'age_group', @@ -400,6 +407,7 @@ public function appointment() DB::raw('ROUND(AVG(percent_not_kept),1) AS percent_not_kept ') ) ->whereNotNull('marital') + ->orderBy('percent_kept', 'DESC') ->groupBy('marital'); $appointment_county = ETLAppointment::select( 'county', @@ -409,6 +417,7 @@ public function appointment() DB::raw('ROUND(AVG(percent_not_kept),1) AS percent_not_kept ') ) ->whereNotNull('county') + ->orderBy('percent_kept', 'DESC') ->groupBy('county'); $appointment_partner = ETLAppointment::select( 'partner', @@ -418,6 +427,7 @@ public function appointment() DB::raw('ROUND(AVG(percent_not_kept),1) AS percent_not_kept ') ) ->whereNotNull('partner') + ->orderBy('percent_kept', 'DESC') ->groupBy('partner'); $appointment_facility = DB::table('etl_appointment_detail')->select( 'facility', @@ -472,6 +482,7 @@ public function appointment() DB::raw('ROUND(AVG(percent_not_kept),1) AS percent_not_kept ') ) ->whereNotNull('gender') + ->orderBy('percent_rtc', 'DESC') ->groupBy('gender'); $missed_marital = DB::table('etl_appointment_detail')->select( 'marital', @@ -481,6 +492,7 @@ public function appointment() DB::raw('ROUND(AVG(percent_not_kept),1) AS percent_not_kept ') ) ->whereNotNull('marital') + ->orderBy('percent_rtc', 'DESC') ->groupBy('marital'); $missed_county = DB::table('etl_appointment_detail')->select( 'county', @@ -490,6 +502,7 @@ public function appointment() DB::raw('ROUND(AVG(percent_not_kept),1) AS percent_not_kept ') ) ->whereNotNull('county') + ->orderBy('percent_rtc', 'DESC') ->groupBy('county'); $missed_partner = DB::table('etl_appointment_detail')->select( 'partner', @@ -499,6 +512,7 @@ public function appointment() DB::raw('ROUND(AVG(percent_not_kept),1) AS percent_not_kept ') ) ->whereNotNull('partner') + ->orderBy('percent_rtc', 'DESC') ->groupBy('partner'); $missed_facility = DB::table('etl_appointment_detail')->select( 'facility', @@ -519,7 +533,7 @@ public function appointment() )->whereNotNull('appointment_date') ->where('appointment_date', '<=', date("Y-M-D")) ->where(DB::raw('DATE_FORMAT(appointment_date, "%Y-%M")'), '>=', "2017-January") - ->orderBy('new_date', 'ASC') + ->orderBy('appointment_date', 'ASC') ->groupBy('new_date'); $data["all_appoinments"] = $all_appoinments->get(); @@ -576,6 +590,7 @@ public function appointment() ) ->whereNotNull('gender') ->where('partner_id', Auth::user()->partner_id) + ->orderBy('percent_kept', 'DESC') ->groupBy('gender'); $appointment_age = ETLAppointment::select( 'age_group', @@ -596,6 +611,7 @@ public function appointment() ) ->whereNotNull('marital') ->where('partner_id', Auth::user()->partner_id) + ->orderBy('percent_kept', 'DESC') ->groupBy('marital'); $appointment_county = ETLAppointment::select( 'county', @@ -611,6 +627,7 @@ public function appointment() DB::raw('SUM(app_not_kept) AS not_kept_app ') ) ->where('partner_id', Auth::user()->partner_id) + ->orderBy('percent_kept', 'DESC') ->groupBy('partner'); $appointment_facility = DB::table('etl_appointment_detail')->select( 'facility', @@ -620,6 +637,7 @@ public function appointment() DB::raw('AVG(percent_not_kept) AS percent_not_kept ') ) ->where('partner_id', Auth::user()->partner_id) + ->orderBy('percent_kept', 'DESC') ->groupBy('facility'); $client_list = DB::table('etl_client_detail')->select( DB::raw('COUNT(ccc_number) AS ccc_number ') @@ -671,6 +689,7 @@ public function appointment() ) ->whereNotNull('gender') ->where('partner_id', Auth::user()->partner_id) + ->orderBy('percent_rtc', 'DESC') ->groupBy('gender'); $missed_marital = DB::table('etl_appointment_detail')->select( 'marital', @@ -681,6 +700,7 @@ public function appointment() ) ->whereNotNull('marital') ->where('partner_id', Auth::user()->partner_id) + ->orderBy('percent_rtc', 'DESC') ->groupBy('marital'); $missed_county = DB::table('etl_appointment_detail')->select( 'county', @@ -705,6 +725,7 @@ public function appointment() ) ->where('partner_id', Auth::user()->partner_id) ->whereNotNull('facility') + ->orderBy('percent_rtc', 'DESC') ->groupBy('facility'); $client_app_list = DB::table('etl_client_detail')->select( DB::raw('COUNT(ccc_number) AS ccc_number ') @@ -717,7 +738,7 @@ public function appointment() ->where('partner_id', Auth::user()->partner_id) ->where('appointment_date', '<=', date("Y-M-D")) ->where(DB::raw('DATE_FORMAT(appointment_date, "%Y-%M")'), '>=', "2017-January") - ->orderBy('new_date', 'ASC') + ->orderBy('appointment_date', 'ASC') ->groupBy('new_date'); $data["all_appoinments"] = $all_appoinments->get(); @@ -774,6 +795,7 @@ public function appointment() ) ->whereNotNull('gender') ->where('subcounty_id', Auth::user()->subcounty_id) + ->orderBy('percent_kept', 'DESC') ->groupBy('gender'); $appointment_age = ETLAppointment::select( 'age_group', @@ -794,6 +816,7 @@ public function appointment() ) ->whereNotNull('marital') ->where('subcounty_id', Auth::user()->subcounty_id) + ->orderBy('percent_kept', 'DESC') ->groupBy('marital'); $appointment_county = ETLAppointment::select( 'county', @@ -820,6 +843,7 @@ public function appointment() ) ->whereNotNull('facility') ->where('subcounty_id', Auth::user()->subcounty_id) + ->orderBy('percent_kept', 'DESC') ->groupBy('facility'); $client_list = DB::table('etl_client_detail')->select( DB::raw('COUNT(ccc_number) AS ccc_number ') @@ -871,6 +895,7 @@ public function appointment() ) ->whereNotNull('gender') ->where('subcounty_id', Auth::user()->subcounty_id) + ->orderBy('percent_rtc', 'DESC') ->groupBy('gender'); $missed_marital = DB::table('etl_appointment_detail')->select( 'marital', @@ -881,6 +906,7 @@ public function appointment() ) ->whereNotNull('marital') ->where('subcounty_id', Auth::user()->subcounty_id) + ->orderBy('percent_rtc', 'DESC') ->groupBy('marital'); $missed_county = DB::table('etl_appointment_detail')->select( 'county', @@ -888,6 +914,7 @@ public function appointment() DB::raw('SUM(CASE WHEN final_outcome = "Client returned to care" THEN 1 ELSE 0 END) AS final_outcome') ) ->where('subcounty_id', Auth::user()->subcounty_id) + ->orderBy('percent_rtc', 'DESC') ->groupBy('county'); $missed_partner = DB::table('etl_appointment_detail')->select( 'partner', @@ -907,6 +934,7 @@ public function appointment() ) ->where('subcounty_id', Auth::user()->subcounty_id) ->whereNotNull('facility') + ->orderBy('percent_rtc', 'DESC') ->groupBy('facility'); $client_app_list = DB::table('etl_client_detail')->select( DB::raw('COUNT(ccc_number) AS ccc_number ') @@ -919,7 +947,7 @@ public function appointment() ->where('subcounty_id', Auth::user()->subcounty_id) ->where('appointment_date', '<=', date("Y-M-D")) ->where(DB::raw('DATE_FORMAT(appointment_date, "%Y-%M")'), '>=', "2017-January") - ->orderBy('new_date', 'ASC') + ->orderBy('appointment_date', 'ASC') ->groupBy('new_date'); $data["all_appoinments"] = $all_appoinments->get(); @@ -976,6 +1004,7 @@ public function appointment() ) ->whereNotNull('gender') ->where('county_id', Auth::user()->county_id) + ->orderBy('percent_kept', 'DESC') ->groupBy('gender'); $appointment_age = ETLAppointment::select( 'age_group', @@ -996,6 +1025,7 @@ public function appointment() ) ->whereNotNull('marital') ->where('county_id', Auth::user()->county_id) + ->orderBy('percent_kept', 'DESC') ->groupBy('marital'); $appointment_county = ETLAppointment::select( 'county', @@ -1013,6 +1043,7 @@ public function appointment() ) ->whereNotNull('partner') ->where('county_id', Auth::user()->county_id) + ->orderBy('percent_kept', 'DESC') ->groupBy('partner'); $appointment_facility = DB::table('etl_appointment_detail')->select( 'facility', @@ -1023,6 +1054,7 @@ public function appointment() ) ->whereNotNull('facility') ->where('county_id', Auth::user()->county_id) + ->orderBy('percent_kept', 'DESC') ->groupBy('facility'); $client_list = DB::table('etl_client_detail')->select( DB::raw('COUNT(ccc_number) AS ccc_number ') @@ -1075,6 +1107,7 @@ public function appointment() ) ->whereNotNull('gender') ->where('county_id', Auth::user()->county_id) + ->orderBy('percent_rtc', 'DESC') ->groupBy('gender'); $missed_marital = DB::table('etl_appointment_detail')->select( 'marital', @@ -1085,6 +1118,7 @@ public function appointment() ) ->whereNotNull('marital') ->where('county_id', Auth::user()->county_id) + ->orderBy('percent_rtc', 'DESC') ->groupBy('marital'); $missed_county = DB::table('etl_appointment_detail')->select( 'county', @@ -1102,6 +1136,7 @@ public function appointment() ) ->whereNotNull('partner') ->where('county_id', Auth::user()->county_id) + ->orderBy('percent_rtc', 'DESC') ->groupBy('partner'); $missed_facility = DB::table('etl_appointment_detail')->select( 'facility', @@ -1112,6 +1147,7 @@ public function appointment() ) ->where('county_id', Auth::user()->county_id) ->whereNotNull('facility') + ->orderBy('percent_rtc', 'DESC') ->groupBy('facility'); $client_app_list = DB::table('etl_client_detail')->select( DB::raw('COUNT(ccc_number) AS ccc_number ') @@ -1124,7 +1160,7 @@ public function appointment() ->where('county_id', Auth::user()->county_id) ->where('appointment_date', '<=', date("Y-M-D")) ->where(DB::raw('DATE_FORMAT(appointment_date, "%Y-%M")'), '>=', "2017-January") - ->orderBy('new_date', 'ASC') + ->orderBy('appointment_date', 'ASC') ->groupBy('new_date'); $data["all_appoinments"] = $all_appoinments->get(); @@ -1318,7 +1354,7 @@ public function filter_data(Request $request) )->whereNotNull('appointment_date') ->where('appointment_date', '<=', date("Y-M-D")) ->where(DB::raw('DATE_FORMAT(appointment_date, "%Y-%M")'), '>=', "2017-January") - ->orderBy('new_date', 'ASC') + ->orderBy('appointment_date', 'ASC') ->groupBy('new_date'); if (!empty($selected_partners)) { @@ -1573,6 +1609,7 @@ public function filter_data(Request $request) 'etl_client_detail.consented', 'etl_client_detail.client_status', 'etl_client_detail.client_name', + 'etl_client_detail.dsd_status', 'etl_client_detail.phone_no', DB::raw('COUNT(etl_appointment_detail.app_kept) AS kept_app '), DB::raw('SUM(etl_appointment_detail.app_not_kept) AS not_kept_app ') @@ -1700,7 +1737,7 @@ public function filter_data(Request $request) ->where('mfl_code', Auth::user()->facility_id) ->where('appointment_date', '<=', date("Y-M-D")) ->where(DB::raw('DATE_FORMAT(appointment_date, "%Y-%M")'), '>=', "2017-January") - ->orderBy('new_date', 'ASC') + ->orderBy('appointment_date', 'ASC') ->groupBy('new_date'); if (!empty($selected_partners)) { @@ -2069,7 +2106,7 @@ public function filter_data(Request $request) ->where('partner_id', Auth::user()->partner_id) ->where('appointment_date', '<=', date("Y-M-D")) ->where(DB::raw('DATE_FORMAT(appointment_date, "%Y-%M")'), '>=', "2017-January") - ->orderBy('new_date', 'ASC') + ->orderBy('appointment_date', 'ASC') ->groupBy('new_date'); if (!empty($selected_partners)) { @@ -2450,7 +2487,7 @@ public function filter_data(Request $request) ->where('subcounty_id', Auth::user()->subcounty_id) ->where('appointment_date', '<=', date("Y-M-D")) ->where(DB::raw('DATE_FORMAT(appointment_date, "%Y-%M")'), '>=', "2017-January") - ->orderBy('new_date', 'ASC') + ->orderBy('appointment_date', 'ASC') ->groupBy('new_date'); if (!empty($selected_partners)) { @@ -2834,7 +2871,7 @@ public function filter_data(Request $request) ->where('county_id', Auth::user()->county_id) ->where('appointment_date', '<=', date("Y-M-D")) ->where(DB::raw('DATE_FORMAT(appointment_date, "%Y-%M")'), '>=', "2017-January") - ->orderBy('new_date', 'ASC') + ->orderBy('appointment_date', 'ASC') ->groupBy('new_date'); if (!empty($selected_partners)) { diff --git a/resources/views/dashboard/appointment.blade.php b/resources/views/dashboard/appointment.blade.php index 0203047..510381c 100644 --- a/resources/views/dashboard/appointment.blade.php +++ b/resources/views/dashboard/appointment.blade.php @@ -7,7 +7,7 @@ font-family: 'Manrope'; font-style: normal; font-weight: 500; - font-size: 12px; + font-size: 16px; line-height: 16px; color: #FFFFFF; } @@ -85,7 +85,6 @@ font-family: 'Manrope'; font-style: normal; font-weight: 700; - font-size: 10px; line-height: 120%; /* identical to box height, or 20px */ letter-spacing: -0.3px; @@ -100,6 +99,18 @@ border: 1px solid #E5F7FF; border-radius: 10px; } + + .box_pec { + top: 12px; + right: 10px; + float: right; + position: absolute; + + } + .no_count { + font-weight: 700; + font-size: 24px; + } @endsection @@ -118,7 +129,7 @@
    - @if (count($partners) > 0) @foreach($partners as $partner) @@ -131,7 +142,7 @@
    - @if (count($counties) > 0) @foreach($counties as $county) @@ -143,7 +154,7 @@
    - @if (count($sub_counties) > 0) @foreach($sub_counties as $sub_county) @@ -155,7 +166,7 @@
    - @if (count($facilities) > 0) @foreach($facilities as $facility) @@ -167,7 +178,7 @@
    - @@ -176,7 +187,7 @@
    - @if (count($clinics) > 0) @foreach($clinics as $clinic) @@ -188,7 +199,7 @@
    - @@ -243,7 +254,7 @@
    - @if (count($partners) > 0) @foreach($partners as $partner) @@ -256,7 +267,19 @@
    - + + @if (count($counties) > 0) + @foreach($counties as $county) + + @endforeach + @endif + +
    +
    +
    +
    + + + + + + + + + + + + + + + + + +
    @@ -225,7 +225,7 @@
    - +
    @@ -337,7 +337,7 @@
    - +
    @@ -350,7 +350,7 @@
    - +
    @@ -448,7 +448,7 @@
    - +
    @@ -461,7 +461,7 @@
    - +
    @@ -535,7 +535,7 @@
    - +
    @@ -548,7 +548,7 @@
    - +
    @@ -600,7 +600,7 @@
    - +
    @@ -612,8 +612,7 @@
    - - +
    @@ -846,7 +845,24 @@ + @if (count($client_list) > 0) + @foreach($client_list as $result) + + {{$result->upi_no}} + {{$result->ccc_number}} + {{$result->client_name}} + {{$result->dob}} + {{$result->phone_no}} + {{$result->consented}} + {{$result->dsd_status}} + {{$result->client_status}} + {{$result->kept_app}} + {{$result->not_kept_app}} + + + @endforeach + @endif @@ -1408,20 +1424,20 @@ missedMarital(data.missed_marital); if (authenticated == 'Facility') { - $.each(data.client_list, function(key, value) { - $('#client').append("\ - " + value.upi_no + "\ - " + value.ccc_number + "\ - " + value.client_name + "\ - " + value.dob + "\ - " + value.phone_no + "\ - " + value.consented + "\ - " + value.dsd_status + "\ - " + value.client_status + "\ - " + value.kept_app + "\ - " + value.not_kept_app + "\ - "); - }) + // $.each(data.client_list, function(key, value) { + // $('#client').append("\ + // " + value.upi_no + "\ + // " + value.ccc_number + "\ + // " + value.client_name + "\ + // " + value.dob + "\ + // " + value.phone_no + "\ + // " + value.consented + "\ + // " + value.dsd_status + "\ + // " + value.client_status + "\ + // " + value.kept_app + "\ + // " + value.not_kept_app + "\ + // "); + // }) } if (authenticated == 'Admin' || authenticated == 'Donor') { appCounty(data.appointment_county); From 2a4b0ceee98416f970fb7b76b437aab4a46ce6dd Mon Sep 17 00:00:00 2001 From: Ronald-pro <36841157+Ronald-pro@users.noreply.github.com> Date: Fri, 10 Feb 2023 11:08:12 +0300 Subject: [PATCH 151/171] percentage rounding --- .../Controllers/FinalDashboardController.php | 12 +-- .../views/dashboard/appointment.blade.php | 75 +++++++++---------- .../large-vertical-sidebar/header.blade.php | 4 +- 3 files changed, 43 insertions(+), 48 deletions(-) diff --git a/app/Http/Controllers/FinalDashboardController.php b/app/Http/Controllers/FinalDashboardController.php index 0e03ae9..bdf93df 100644 --- a/app/Http/Controllers/FinalDashboardController.php +++ b/app/Http/Controllers/FinalDashboardController.php @@ -384,8 +384,8 @@ public function appointment() 'gender', DB::raw('SUM(app_kept) AS kept_app '), DB::raw('SUM(app_not_kept) AS not_kept_app '), - DB::raw('AVG(percent_kept) AS percent_kept '), - DB::raw('AVG(percent_not_kept) AS percent_not_kept ') + DB::raw('ROUND(AVG(percent_kept),1) AS percent_kept '), + DB::raw('ROUND(AVG(percent_not_kept),1) AS percent_not_kept ') ) ->whereNotNull('gender') ->orderBy('percent_kept', 'DESC') @@ -394,8 +394,8 @@ public function appointment() 'age_group', DB::raw('SUM(app_kept) AS kept_app '), DB::raw('SUM(app_not_kept) AS not_kept_app '), - DB::raw('AVG(percent_kept) AS percent_kept '), - DB::raw('AVG(percent_not_kept) AS percent_not_kept ') + DB::raw('ROUND(AVG(percent_kept),1) AS percent_kept '), + DB::raw('ROUND(AVG(percent_not_kept),1) AS percent_not_kept ') ) ->whereNotNull('age_group') ->groupBy('age_group'); @@ -633,8 +633,8 @@ public function appointment() 'facility', DB::raw('SUM(app_kept) AS kept_app '), DB::raw('SUM(app_not_kept) AS not_kept_app '), - DB::raw('AVG(percent_kept) AS percent_kept '), - DB::raw('AVG(percent_not_kept) AS percent_not_kept ') + DB::raw('ROUND(AVG(percent_kept),1) AS percent_kept '), + DB::raw('ROUND(AVG(percent_not_kept),1) AS percent_not_kept ') ) ->where('partner_id', Auth::user()->partner_id) ->orderBy('percent_kept', 'DESC') diff --git a/resources/views/dashboard/appointment.blade.php b/resources/views/dashboard/appointment.blade.php index d7a9120..d6ef2d1 100644 --- a/resources/views/dashboard/appointment.blade.php +++ b/resources/views/dashboard/appointment.blade.php @@ -106,11 +106,20 @@ float: right; position: absolute; + } .no_count { font-weight: 700; font-size: 24px; } + .sub_missed { + font-weight: 700; + font-size: 18px; + } + .no_pec { + font-weight: 700; + font-size: 16px; + } @endsection @@ -661,7 +670,7 @@ Clients Consented

    -

    +

    @@ -673,7 +682,7 @@
    Booked Appointments -

    +

    @@ -690,7 +699,7 @@ Appointments Kept

    -

    +

    @@ -703,7 +712,7 @@ Appointments Not Kept

    -

    +

    @@ -717,7 +726,7 @@ Future Appointments

    -

    +

    @@ -907,17 +916,17 @@
    Missed - +
    Defaulted - +
    IIT - +
    @@ -935,17 +944,17 @@
    Missed -

    +

    Defaulted -

    +

    IIT -

    +

    @@ -967,17 +976,17 @@
    Missed -

    +

    Defaulted -

    +

    IIT -

    +

    @@ -995,17 +1004,17 @@
    Missed -

    +

    Defaulted -

    +

    IIT -

    +

    @@ -1022,19 +1031,19 @@
    -
    +
    Missed -

    +

    -
    +
    Defaulted -

    +

    IIT -

    +

    @@ -1731,20 +1740,6 @@ missedGender(data.missed_gender); missedMarital(data.missed_marital); if (authenticated == 'Facility') { - $.each(data.client_list, function(key, value) { - $('#client').append("\ - " + value.upi_no + "\ - " + value.ccc_number + "\ - " + value.client_name + "\ - " + value.dob + "\ - " + value.phone_no + "\ - " + value.consented + "\ - " + value.dsd_status + "\ - " + value.client_status + "\ - " + value.kept_app + "\ - " + value.not_kept_app + "\ - "); - }) } if (authenticated == 'Admin' || authenticated == 'Donor') { @@ -1765,7 +1760,7 @@ console.log(missed); for (var x = 0; x < consent.length; x++) { - consented = consent[x].consented; + consented = parseInt(consent[x].consented); console.log(consented); if (consented == undefined || consented == null) { consented = 0; @@ -1811,7 +1806,7 @@ percnt_future = Math.round(apps[x].percent_future).toFixed(1) + '%'; } for (var x = 0; x < tx.length; x++) { - tx_curr = tx[x].tx_cur; + tx_curr = parseInt(tx[x].tx_cur).toLocaleString(); } for (var x = 0; x < missed.length; x++) { app_missed = missed[x].not_kept_app; @@ -1820,7 +1815,7 @@ } else { app_missed = app_missed.toLocaleString(); } - consent_app = missed[x].consent; + consent_app = parseInt(missed[x].consent); if (consent_app == undefined || consent_app == null) { consent_app = 0; } else { @@ -1920,7 +1915,7 @@ traced_iit = traced_iit.toLocaleString(); } - outcome = missed[x].final_outcome; + outcome = parseInt(missed[x].final_outcome); if (outcome == undefined || outcome == null) { outcome = 0; } else { diff --git a/resources/views/layouts/large-vertical-sidebar/header.blade.php b/resources/views/layouts/large-vertical-sidebar/header.blade.php index d910632..ca29713 100644 --- a/resources/views/layouts/large-vertical-sidebar/header.blade.php +++ b/resources/views/layouts/large-vertical-sidebar/header.blade.php @@ -27,7 +27,7 @@
    - +
    From b39c12adb1081e92b9710855a8d056c5d8f46b0a Mon Sep 17 00:00:00 2001 From: Ronald-pro <36841157+Ronald-pro@users.noreply.github.com> Date: Fri, 10 Feb 2023 17:05:58 +0300 Subject: [PATCH 152/171] fixed number count matching and additional styling clean up --- .../Controllers/FinalDashboardController.php | 125 +++++++++--------- .../styles/css/themes/dark-purple.min.css | 2 +- .../styles/css/themes/lite-purple.min.css | 2 +- .../views/dashboard/appointment.blade.php | 71 +++++----- 4 files changed, 106 insertions(+), 94 deletions(-) diff --git a/app/Http/Controllers/FinalDashboardController.php b/app/Http/Controllers/FinalDashboardController.php index bdf93df..4111826 100644 --- a/app/Http/Controllers/FinalDashboardController.php +++ b/app/Http/Controllers/FinalDashboardController.php @@ -138,7 +138,7 @@ public function appointment() $data = []; $all_appoinments = ETLAppointment::select( - DB::raw('COUNT(*) as total_app'), + DB::raw('(SUM(app_kept)+SUM(app_not_kept)+SUM(future)) as total_app'), DB::raw('SUM(app_kept) AS kept_app '), DB::raw('SUM(app_not_kept) AS not_kept_app '), DB::raw('SUM(future) AS future '), @@ -232,23 +232,23 @@ public function appointment() // missed appointment $client_missed = DB::table('etl_appointment_detail')->select( DB::raw('SUM(app_not_kept) AS not_kept_app '), - DB::raw('SUM(received_sms) AS messages '), + DB::raw('SUM(CASE WHEN appointment_status = "Missed" OR appointment_status = "Defaulted" OR appointment_status = "IIT" THEN received_sms END) AS messages '), DB::raw('SUM(CASE WHEN received_sms = 1 AND appointment_status = "Missed" THEN 1 ELSE 0 END) AS missed_messages '), DB::raw('SUM(CASE WHEN received_sms = 1 AND appointment_status = "Defaulted" THEN 1 ELSE 0 END) AS defaulted_messages '), DB::raw('SUM(CASE WHEN received_sms = 1 AND appointment_status = "IIT" THEN 1 ELSE 0 END) AS iit_messages '), - DB::raw('SUM(called) AS called '), + DB::raw('SUM(CASE WHEN appointment_status = "Missed" OR appointment_status = "Defaulted" OR appointment_status = "IIT" THEN called END) AS called '), DB::raw('SUM(CASE WHEN called = 1 AND appointment_status = "Missed" THEN 1 ELSE 0 END) AS missed_called '), DB::raw('SUM(CASE WHEN called = 1 AND appointment_status = "Defaulted" THEN 1 ELSE 0 END) AS defaulted_called '), DB::raw('SUM(CASE WHEN called = 1 AND appointment_status = "IIT" THEN 1 ELSE 0 END) AS iit_called '), - DB::raw('SUM(physically_traced) AS physically_traced '), + DB::raw('SUM(CASE WHEN appointment_status = "Missed" OR appointment_status = "Defaulted" OR appointment_status = "IIT" THEN physically_traced END) AS physically_traced '), DB::raw('SUM(CASE WHEN physically_traced = 1 AND appointment_status = "Missed" THEN 1 ELSE 0 END) AS missed_traced '), DB::raw('SUM(CASE WHEN physically_traced = 1 AND appointment_status = "Defaulted" THEN 1 ELSE 0 END) AS defaulted_traced '), DB::raw('SUM(CASE WHEN physically_traced = 1 AND appointment_status = "IIT" THEN 1 ELSE 0 END) AS iit_traced '), - DB::raw('SUM(CASE WHEN final_outcome = "Client returned to care" THEN 1 ELSE 0 END) AS final_outcome'), + DB::raw('SUM(CASE WHEN appointment_status = "Missed" OR appointment_status = "Defaulted" OR appointment_status = "IIT" THEN rtc_no END) AS final_outcome'), DB::raw('SUM(CASE WHEN final_outcome = "Client returned to care" AND appointment_status = "Missed" THEN 1 ELSE 0 END) AS missed_outcome '), DB::raw('SUM(CASE WHEN final_outcome = "Client returned to care" AND appointment_status = "Defaulted" THEN 1 ELSE 0 END) AS defaulted_outcome '), DB::raw('SUM(CASE WHEN final_outcome = "Client returned to care" AND appointment_status = "IIT" THEN 1 ELSE 0 END) AS iit_outcome '), - DB::raw('SUM(CASE WHEN appointment_status = "Missed" OR appointment_status = "Defaulted" OR appointment_status = "IIT" AND consent = "Yes" THEN 1 ELSE 0 END) AS consent '), + DB::raw('SUM(CASE WHEN appointment_status = "Missed" OR appointment_status = "Defaulted" OR appointment_status = "IIT" THEN consent_no END) AS consent '), DB::raw('SUM(CASE WHEN consent = "Yes" AND appointment_status = "Missed" THEN 1 ELSE 0 END) AS missed_consent '), DB::raw('SUM(CASE WHEN consent = "Yes" AND appointment_status = "Defaulted" THEN 1 ELSE 0 END) AS defaulted_consent '), DB::raw('SUM(CASE WHEN consent = "Yes" AND appointment_status = "IIT" THEN 1 ELSE 0 END) AS iit_consent ') @@ -334,6 +334,7 @@ public function appointment() ->where('mfl_code', Auth::user()->facility_id) ->where('appointment_date', '<=', date("Y-M-D")) ->where(DB::raw('DATE_FORMAT(appointment_date, "%Y-%M")'), '>=', "2017-January") + ->where(DB::raw('DATE_FORMAT(appointment_date, "%Y-%M")'), '<=', date('Y-M')) ->orderBy('appointment_date', 'ASC') ->groupBy('new_date'); @@ -364,7 +365,7 @@ public function appointment() $data = []; $all_appoinments = ETLAppointment::select( - DB::raw('COUNT(*) as total_app'), + DB::raw('(SUM(app_kept)+SUM(app_not_kept)+SUM(future)) as total_app'), DB::raw('SUM(app_kept) AS kept_app '), DB::raw('SUM(app_not_kept) AS not_kept_app '), DB::raw('SUM(future) AS future '), @@ -443,23 +444,23 @@ public function appointment() // missed appointment $client_missed = DB::table('etl_appointment_detail')->select( DB::raw('SUM(app_not_kept) AS not_kept_app '), - DB::raw('SUM(received_sms) AS messages '), + DB::raw('SUM(CASE WHEN appointment_status = "Missed" OR appointment_status = "Defaulted" OR appointment_status = "IIT" THEN received_sms END) AS messages '), DB::raw('SUM(CASE WHEN received_sms = 1 AND appointment_status = "Missed" THEN 1 ELSE 0 END) AS missed_messages '), DB::raw('SUM(CASE WHEN received_sms = 1 AND appointment_status = "Defaulted" THEN 1 ELSE 0 END) AS defaulted_messages '), DB::raw('SUM(CASE WHEN received_sms = 1 AND appointment_status = "IIT" THEN 1 ELSE 0 END) AS iit_messages '), - DB::raw('SUM(called) AS called '), + DB::raw('SUM(CASE WHEN appointment_status = "Missed" OR appointment_status = "Defaulted" OR appointment_status = "IIT" THEN called END) AS called '), DB::raw('SUM(CASE WHEN called = 1 AND appointment_status = "Missed" THEN 1 ELSE 0 END) AS missed_called '), DB::raw('SUM(CASE WHEN called = 1 AND appointment_status = "Defaulted" THEN 1 ELSE 0 END) AS defaulted_called '), DB::raw('SUM(CASE WHEN called = 1 AND appointment_status = "IIT" THEN 1 ELSE 0 END) AS iit_called '), - DB::raw('SUM(physically_traced) AS physically_traced '), + DB::raw('SUM(CASE WHEN appointment_status = "Missed" OR appointment_status = "Defaulted" OR appointment_status = "IIT" THEN physically_traced END) AS physically_traced '), DB::raw('SUM(CASE WHEN physically_traced = 1 AND appointment_status = "Missed" THEN 1 ELSE 0 END) AS missed_traced '), DB::raw('SUM(CASE WHEN physically_traced = 1 AND appointment_status = "Defaulted" THEN 1 ELSE 0 END) AS defaulted_traced '), DB::raw('SUM(CASE WHEN physically_traced = 1 AND appointment_status = "IIT" THEN 1 ELSE 0 END) AS iit_traced '), - DB::raw('SUM(CASE WHEN final_outcome = "Client returned to care" THEN 1 ELSE 0 END) AS final_outcome'), + DB::raw('SUM(CASE WHEN appointment_status = "Missed" OR appointment_status = "Defaulted" OR appointment_status = "IIT" THEN rtc_no END) AS final_outcome'), DB::raw('SUM(CASE WHEN final_outcome = "Client returned to care" AND appointment_status = "Missed" THEN 1 ELSE 0 END) AS missed_outcome '), DB::raw('SUM(CASE WHEN final_outcome = "Client returned to care" AND appointment_status = "Defaulted" THEN 1 ELSE 0 END) AS defaulted_outcome '), DB::raw('SUM(CASE WHEN final_outcome = "Client returned to care" AND appointment_status = "IIT" THEN 1 ELSE 0 END) AS iit_outcome '), - DB::raw('SUM(CASE WHEN consent = "Yes" AND appointment_status = "Missed" OR appointment_status = "Defaulted" OR appointment_status = "IIT" THEN 1 ELSE 0 END) AS consent '), + DB::raw('SUM(CASE WHEN appointment_status = "Missed" OR appointment_status = "Defaulted" OR appointment_status = "IIT" THEN consent_no END) AS consent '), DB::raw('SUM(CASE WHEN consent = "Yes" AND appointment_status = "Missed" THEN 1 ELSE 0 END) AS missed_consent '), DB::raw('SUM(CASE WHEN consent = "Yes" AND appointment_status = "Defaulted" THEN 1 ELSE 0 END) AS defaulted_consent '), DB::raw('SUM(CASE WHEN consent = "Yes" AND appointment_status = "IIT" THEN 1 ELSE 0 END) AS iit_consent ') @@ -533,6 +534,7 @@ public function appointment() )->whereNotNull('appointment_date') ->where('appointment_date', '<=', date("Y-M-D")) ->where(DB::raw('DATE_FORMAT(appointment_date, "%Y-%M")'), '>=', "2017-January") + ->where(DB::raw('DATE_FORMAT(appointment_date, "%Y-%M")'), '<=', date('Y-M')) ->orderBy('appointment_date', 'ASC') ->groupBy('new_date'); @@ -563,7 +565,7 @@ public function appointment() $data = []; $all_appoinments = ETLAppointment::select( - DB::raw('COUNT(*) as total_app'), + DB::raw('(SUM(app_kept)+SUM(app_not_kept)+SUM(future)) as total_app'), DB::raw('SUM(app_kept) AS kept_app '), DB::raw('SUM(app_not_kept) AS not_kept_app '), DB::raw('SUM(future) AS future '), @@ -647,23 +649,23 @@ public function appointment() // missed appointment $client_missed = DB::table('etl_appointment_detail')->select( DB::raw('SUM(app_not_kept) AS not_kept_app '), - DB::raw('SUM(received_sms) AS messages '), + DB::raw('SUM(CASE WHEN appointment_status = "Missed" OR appointment_status = "Defaulted" OR appointment_status = "IIT" THEN received_sms END) AS messages '), DB::raw('SUM(CASE WHEN received_sms = 1 AND appointment_status = "Missed" THEN 1 ELSE 0 END) AS missed_messages '), DB::raw('SUM(CASE WHEN received_sms = 1 AND appointment_status = "Defaulted" THEN 1 ELSE 0 END) AS defaulted_messages '), DB::raw('SUM(CASE WHEN received_sms = 1 AND appointment_status = "IIT" THEN 1 ELSE 0 END) AS iit_messages '), - DB::raw('SUM(called) AS called '), + DB::raw('SUM(CASE WHEN appointment_status = "Missed" OR appointment_status = "Defaulted" OR appointment_status = "IIT" THEN called END) AS called '), DB::raw('SUM(CASE WHEN called = 1 AND appointment_status = "Missed" THEN 1 ELSE 0 END) AS missed_called '), DB::raw('SUM(CASE WHEN called = 1 AND appointment_status = "Defaulted" THEN 1 ELSE 0 END) AS defaulted_called '), DB::raw('SUM(CASE WHEN called = 1 AND appointment_status = "IIT" THEN 1 ELSE 0 END) AS iit_called '), - DB::raw('SUM(physically_traced) AS physically_traced '), + DB::raw('SUM(CASE WHEN appointment_status = "Missed" OR appointment_status = "Defaulted" OR appointment_status = "IIT" THEN physically_traced END) AS physically_traced '), DB::raw('SUM(CASE WHEN physically_traced = 1 AND appointment_status = "Missed" THEN 1 ELSE 0 END) AS missed_traced '), DB::raw('SUM(CASE WHEN physically_traced = 1 AND appointment_status = "Defaulted" THEN 1 ELSE 0 END) AS defaulted_traced '), DB::raw('SUM(CASE WHEN physically_traced = 1 AND appointment_status = "IIT" THEN 1 ELSE 0 END) AS iit_traced '), - DB::raw('SUM(CASE WHEN final_outcome = "Client returned to care" THEN 1 ELSE 0 END) AS final_outcome'), + DB::raw('SUM(CASE WHEN appointment_status = "Missed" OR appointment_status = "Defaulted" OR appointment_status = "IIT" THEN rtc_no END) AS final_outcome'), DB::raw('SUM(CASE WHEN final_outcome = "Client returned to care" AND appointment_status = "Missed" THEN 1 ELSE 0 END) AS missed_outcome '), DB::raw('SUM(CASE WHEN final_outcome = "Client returned to care" AND appointment_status = "Defaulted" THEN 1 ELSE 0 END) AS defaulted_outcome '), DB::raw('SUM(CASE WHEN final_outcome = "Client returned to care" AND appointment_status = "IIT" THEN 1 ELSE 0 END) AS iit_outcome '), - DB::raw('SUM(CASE WHEN consent = "Yes" AND appointment_status = "Missed" OR appointment_status = "Defaulted" OR appointment_status = "IIT" THEN 1 ELSE 0 END) AS consent '), + DB::raw('SUM(CASE WHEN appointment_status = "Missed" OR appointment_status = "Defaulted" OR appointment_status = "IIT" THEN consent_no END) AS consent '), DB::raw('SUM(CASE WHEN consent = "Yes" AND appointment_status = "Missed" THEN 1 ELSE 0 END) AS missed_consent '), DB::raw('SUM(CASE WHEN consent = "Yes" AND appointment_status = "Defaulted" THEN 1 ELSE 0 END) AS defaulted_consent '), DB::raw('SUM(CASE WHEN consent = "Yes" AND appointment_status = "IIT" THEN 1 ELSE 0 END) AS iit_consent ') @@ -738,6 +740,7 @@ public function appointment() ->where('partner_id', Auth::user()->partner_id) ->where('appointment_date', '<=', date("Y-M-D")) ->where(DB::raw('DATE_FORMAT(appointment_date, "%Y-%M")'), '>=', "2017-January") + ->where(DB::raw('DATE_FORMAT(appointment_date, "%Y-%M")'), '<=', date('Y-M')) ->orderBy('appointment_date', 'ASC') ->groupBy('new_date'); @@ -768,7 +771,7 @@ public function appointment() $data = []; $all_appoinments = ETLAppointment::select( - DB::raw('COUNT(*) as total_app'), + DB::raw('(SUM(app_kept)+SUM(app_not_kept)+SUM(future)) as total_app'), DB::raw('SUM(app_kept) AS kept_app '), DB::raw('SUM(app_not_kept) AS not_kept_app '), DB::raw('SUM(future) AS future '), @@ -853,23 +856,23 @@ public function appointment() // missed appointment $client_missed = DB::table('etl_appointment_detail')->select( DB::raw('SUM(app_not_kept) AS not_kept_app '), - DB::raw('SUM(received_sms) AS messages '), + DB::raw('SUM(CASE WHEN appointment_status = "Missed" OR appointment_status = "Defaulted" OR appointment_status = "IIT" THEN received_sms END) AS messages '), DB::raw('SUM(CASE WHEN received_sms = 1 AND appointment_status = "Missed" THEN 1 ELSE 0 END) AS missed_messages '), DB::raw('SUM(CASE WHEN received_sms = 1 AND appointment_status = "Defaulted" THEN 1 ELSE 0 END) AS defaulted_messages '), DB::raw('SUM(CASE WHEN received_sms = 1 AND appointment_status = "IIT" THEN 1 ELSE 0 END) AS iit_messages '), - DB::raw('SUM(called) AS called '), + DB::raw('SUM(CASE WHEN appointment_status = "Missed" OR appointment_status = "Defaulted" OR appointment_status = "IIT" THEN called END) AS called '), DB::raw('SUM(CASE WHEN called = 1 AND appointment_status = "Missed" THEN 1 ELSE 0 END) AS missed_called '), DB::raw('SUM(CASE WHEN called = 1 AND appointment_status = "Defaulted" THEN 1 ELSE 0 END) AS defaulted_called '), DB::raw('SUM(CASE WHEN called = 1 AND appointment_status = "IIT" THEN 1 ELSE 0 END) AS iit_called '), - DB::raw('SUM(physically_traced) AS physically_traced '), + DB::raw('SUM(CASE WHEN appointment_status = "Missed" OR appointment_status = "Defaulted" OR appointment_status = "IIT" THEN physically_traced END) AS physically_traced '), DB::raw('SUM(CASE WHEN physically_traced = 1 AND appointment_status = "Missed" THEN 1 ELSE 0 END) AS missed_traced '), DB::raw('SUM(CASE WHEN physically_traced = 1 AND appointment_status = "Defaulted" THEN 1 ELSE 0 END) AS defaulted_traced '), DB::raw('SUM(CASE WHEN physically_traced = 1 AND appointment_status = "IIT" THEN 1 ELSE 0 END) AS iit_traced '), - DB::raw('SUM(CASE WHEN final_outcome = "Client returned to care" THEN 1 ELSE 0 END) AS final_outcome'), + DB::raw('SUM(CASE WHEN appointment_status = "Missed" OR appointment_status = "Defaulted" OR appointment_status = "IIT" THEN rtc_no END) AS final_outcome'), DB::raw('SUM(CASE WHEN final_outcome = "Client returned to care" AND appointment_status = "Missed" THEN 1 ELSE 0 END) AS missed_outcome '), DB::raw('SUM(CASE WHEN final_outcome = "Client returned to care" AND appointment_status = "Defaulted" THEN 1 ELSE 0 END) AS defaulted_outcome '), DB::raw('SUM(CASE WHEN final_outcome = "Client returned to care" AND appointment_status = "IIT" THEN 1 ELSE 0 END) AS iit_outcome '), - DB::raw('SUM(CASE WHEN consent = "Yes" AND appointment_status = "Missed" OR appointment_status = "Defaulted" OR appointment_status = "IIT" THEN 1 ELSE 0 END) AS consent '), + DB::raw('SUM(CASE WHEN appointment_status = "Missed" OR appointment_status = "Defaulted" OR appointment_status = "IIT" THEN consent_no END) AS consent '), DB::raw('SUM(CASE WHEN consent = "Yes" AND appointment_status = "Missed" THEN 1 ELSE 0 END) AS missed_consent '), DB::raw('SUM(CASE WHEN consent = "Yes" AND appointment_status = "Defaulted" THEN 1 ELSE 0 END) AS defaulted_consent '), DB::raw('SUM(CASE WHEN consent = "Yes" AND appointment_status = "IIT" THEN 1 ELSE 0 END) AS iit_consent ') @@ -947,6 +950,7 @@ public function appointment() ->where('subcounty_id', Auth::user()->subcounty_id) ->where('appointment_date', '<=', date("Y-M-D")) ->where(DB::raw('DATE_FORMAT(appointment_date, "%Y-%M")'), '>=', "2017-January") + ->where(DB::raw('DATE_FORMAT(appointment_date, "%Y-%M")'), '<=', date('Y-M')) ->orderBy('appointment_date', 'ASC') ->groupBy('new_date'); @@ -977,7 +981,7 @@ public function appointment() $data = []; $all_appoinments = ETLAppointment::select( - DB::raw('COUNT(*) as total_app'), + DB::raw('(SUM(app_kept)+SUM(app_not_kept)+SUM(future)) as total_app'), DB::raw('SUM(app_kept) AS kept_app '), DB::raw('SUM(app_not_kept) AS not_kept_app '), DB::raw('SUM(future) AS future '), @@ -1064,23 +1068,23 @@ public function appointment() // missed appointment $client_missed = DB::table('etl_appointment_detail')->select( DB::raw('SUM(app_not_kept) AS not_kept_app '), - DB::raw('SUM(received_sms) AS messages '), + DB::raw('SUM(CASE WHEN appointment_status = "Missed" OR appointment_status = "Defaulted" OR appointment_status = "IIT" THEN received_sms END) AS messages '), DB::raw('SUM(CASE WHEN received_sms = 1 AND appointment_status = "Missed" THEN 1 ELSE 0 END) AS missed_messages '), DB::raw('SUM(CASE WHEN received_sms = 1 AND appointment_status = "Defaulted" THEN 1 ELSE 0 END) AS defaulted_messages '), DB::raw('SUM(CASE WHEN received_sms = 1 AND appointment_status = "IIT" THEN 1 ELSE 0 END) AS iit_messages '), - DB::raw('SUM(called) AS called '), + DB::raw('SUM(CASE WHEN appointment_status = "Missed" OR appointment_status = "Defaulted" OR appointment_status = "IIT" THEN called END) AS called '), DB::raw('SUM(CASE WHEN called = 1 AND appointment_status = "Missed" THEN 1 ELSE 0 END) AS missed_called '), DB::raw('SUM(CASE WHEN called = 1 AND appointment_status = "Defaulted" THEN 1 ELSE 0 END) AS defaulted_called '), DB::raw('SUM(CASE WHEN called = 1 AND appointment_status = "IIT" THEN 1 ELSE 0 END) AS iit_called '), - DB::raw('SUM(physically_traced) AS physically_traced '), + DB::raw('SUM(CASE WHEN appointment_status = "Missed" OR appointment_status = "Defaulted" OR appointment_status = "IIT" THEN physically_traced END) AS physically_traced '), DB::raw('SUM(CASE WHEN physically_traced = 1 AND appointment_status = "Missed" THEN 1 ELSE 0 END) AS missed_traced '), DB::raw('SUM(CASE WHEN physically_traced = 1 AND appointment_status = "Defaulted" THEN 1 ELSE 0 END) AS defaulted_traced '), DB::raw('SUM(CASE WHEN physically_traced = 1 AND appointment_status = "IIT" THEN 1 ELSE 0 END) AS iit_traced '), - DB::raw('SUM(CASE WHEN final_outcome = "Client returned to care" THEN 1 ELSE 0 END) AS final_outcome'), + DB::raw('SUM(CASE WHEN appointment_status = "Missed" OR appointment_status = "Defaulted" OR appointment_status = "IIT" THEN rtc_no END) AS final_outcome'), DB::raw('SUM(CASE WHEN final_outcome = "Client returned to care" AND appointment_status = "Missed" THEN 1 ELSE 0 END) AS missed_outcome '), DB::raw('SUM(CASE WHEN final_outcome = "Client returned to care" AND appointment_status = "Defaulted" THEN 1 ELSE 0 END) AS defaulted_outcome '), DB::raw('SUM(CASE WHEN final_outcome = "Client returned to care" AND appointment_status = "IIT" THEN 1 ELSE 0 END) AS iit_outcome '), - DB::raw('SUM(CASE WHEN consent = "Yes" AND appointment_status = "Missed" OR appointment_status = "Defaulted" OR appointment_status = "IIT" THEN 1 ELSE 0 END) AS consent '), + DB::raw('SUM(CASE WHEN appointment_status = "Missed" OR appointment_status = "Defaulted" OR appointment_status = "IIT" THEN consent_no END) AS consent '), DB::raw('SUM(CASE WHEN consent = "Yes" AND appointment_status = "Missed" THEN 1 ELSE 0 END) AS missed_consent '), DB::raw('SUM(CASE WHEN consent = "Yes" AND appointment_status = "Defaulted" THEN 1 ELSE 0 END) AS defaulted_consent '), DB::raw('SUM(CASE WHEN consent = "Yes" AND appointment_status = "IIT" THEN 1 ELSE 0 END) AS iit_consent ') @@ -1160,6 +1164,7 @@ public function appointment() ->where('county_id', Auth::user()->county_id) ->where('appointment_date', '<=', date("Y-M-D")) ->where(DB::raw('DATE_FORMAT(appointment_date, "%Y-%M")'), '>=', "2017-January") + ->where(DB::raw('DATE_FORMAT(appointment_date, "%Y-%M")'), '<=', date('Y-M')) ->orderBy('appointment_date', 'ASC') ->groupBy('new_date'); @@ -1202,7 +1207,7 @@ public function filter_data(Request $request) $selected_site = $request->site; $all_appoinments = ETLAppointment::select( - DB::raw('COUNT(*) as total_app'), + DB::raw('(SUM(app_kept)+SUM(app_not_kept)+SUM(future)) as total_app'), DB::raw('SUM(app_kept) AS kept_app '), DB::raw('SUM(app_not_kept) AS not_kept_app '), DB::raw('SUM(future) AS future '), @@ -1277,23 +1282,23 @@ public function filter_data(Request $request) // missed appointment $client_missed = DB::table('etl_appointment_detail')->select( DB::raw('SUM(app_not_kept) AS not_kept_app '), - DB::raw('SUM(received_sms) AS messages '), + DB::raw('SUM(CASE WHEN appointment_status = "Missed" OR appointment_status = "Defaulted" OR appointment_status = "IIT" THEN received_sms END) AS messages '), DB::raw('SUM(CASE WHEN received_sms = 1 AND appointment_status = "Missed" THEN 1 ELSE 0 END) AS missed_messages '), DB::raw('SUM(CASE WHEN received_sms = 1 AND appointment_status = "Defaulted" THEN 1 ELSE 0 END) AS defaulted_messages '), DB::raw('SUM(CASE WHEN received_sms = 1 AND appointment_status = "IIT" THEN 1 ELSE 0 END) AS iit_messages '), - DB::raw('SUM(called) AS called '), + DB::raw('SUM(CASE WHEN appointment_status = "Missed" OR appointment_status = "Defaulted" OR appointment_status = "IIT" THEN called END) AS called '), DB::raw('SUM(CASE WHEN called = 1 AND appointment_status = "Missed" THEN 1 ELSE 0 END) AS missed_called '), DB::raw('SUM(CASE WHEN called = 1 AND appointment_status = "Defaulted" THEN 1 ELSE 0 END) AS defaulted_called '), DB::raw('SUM(CASE WHEN called = 1 AND appointment_status = "IIT" THEN 1 ELSE 0 END) AS iit_called '), - DB::raw('SUM(physically_traced) AS physically_traced '), + DB::raw('SUM(CASE WHEN appointment_status = "Missed" OR appointment_status = "Defaulted" OR appointment_status = "IIT" THEN physically_traced END) AS physically_traced '), DB::raw('SUM(CASE WHEN physically_traced = 1 AND appointment_status = "Missed" THEN 1 ELSE 0 END) AS missed_traced '), DB::raw('SUM(CASE WHEN physically_traced = 1 AND appointment_status = "Defaulted" THEN 1 ELSE 0 END) AS defaulted_traced '), DB::raw('SUM(CASE WHEN physically_traced = 1 AND appointment_status = "IIT" THEN 1 ELSE 0 END) AS iit_traced '), - DB::raw('SUM(CASE WHEN final_outcome = "Client returned to care" THEN 1 ELSE 0 END) AS final_outcome'), + DB::raw('SUM(CASE WHEN appointment_status = "Missed" OR appointment_status = "Defaulted" OR appointment_status = "IIT" THEN rtc_no END) AS final_outcome'), DB::raw('SUM(CASE WHEN final_outcome = "Client returned to care" AND appointment_status = "Missed" THEN 1 ELSE 0 END) AS missed_outcome '), DB::raw('SUM(CASE WHEN final_outcome = "Client returned to care" AND appointment_status = "Defaulted" THEN 1 ELSE 0 END) AS defaulted_outcome '), DB::raw('SUM(CASE WHEN final_outcome = "Client returned to care" AND appointment_status = "IIT" THEN 1 ELSE 0 END) AS iit_outcome '), - DB::raw('SUM(CASE WHEN consent = "Yes" AND appointment_status = "Missed" OR appointment_status = "Defaulted" OR appointment_status = "IIT" THEN 1 ELSE 0 END) AS consent '), + DB::raw('SUM(CASE WHEN appointment_status = "Missed" OR appointment_status = "Defaulted" OR appointment_status = "IIT" THEN consent_no END) AS consent '), DB::raw('SUM(CASE WHEN consent = "Yes" AND appointment_status = "Missed" THEN 1 ELSE 0 END) AS missed_consent '), DB::raw('SUM(CASE WHEN consent = "Yes" AND appointment_status = "Defaulted" THEN 1 ELSE 0 END) AS defaulted_consent '), DB::raw('SUM(CASE WHEN consent = "Yes" AND appointment_status = "IIT" THEN 1 ELSE 0 END) AS iit_consent ') @@ -1554,7 +1559,7 @@ public function filter_data(Request $request) $selected_site = $request->site; $data = []; $all_appoinments = ETLAppointment::select( - DB::raw('COUNT(*) as total_app'), + DB::raw('(SUM(app_kept)+SUM(app_not_kept)+SUM(future)) as total_app'), DB::raw('SUM(app_kept) AS kept_app '), DB::raw('SUM(app_not_kept) AS not_kept_app '), DB::raw('SUM(future) AS future '), @@ -1647,23 +1652,23 @@ public function filter_data(Request $request) // missed appointment $client_missed = DB::table('etl_appointment_detail')->select( DB::raw('SUM(app_not_kept) AS not_kept_app '), - DB::raw('SUM(received_sms) AS messages '), + DB::raw('SUM(CASE WHEN appointment_status = "Missed" OR appointment_status = "Defaulted" OR appointment_status = "IIT" THEN received_sms END) AS messages '), DB::raw('SUM(CASE WHEN received_sms = 1 AND appointment_status = "Missed" THEN 1 ELSE 0 END) AS missed_messages '), DB::raw('SUM(CASE WHEN received_sms = 1 AND appointment_status = "Defaulted" THEN 1 ELSE 0 END) AS defaulted_messages '), DB::raw('SUM(CASE WHEN received_sms = 1 AND appointment_status = "IIT" THEN 1 ELSE 0 END) AS iit_messages '), - DB::raw('SUM(called) AS called '), + DB::raw('SUM(CASE WHEN appointment_status = "Missed" OR appointment_status = "Defaulted" OR appointment_status = "IIT" THEN called END) AS called '), DB::raw('SUM(CASE WHEN called = 1 AND appointment_status = "Missed" THEN 1 ELSE 0 END) AS missed_called '), DB::raw('SUM(CASE WHEN called = 1 AND appointment_status = "Defaulted" THEN 1 ELSE 0 END) AS defaulted_called '), DB::raw('SUM(CASE WHEN called = 1 AND appointment_status = "IIT" THEN 1 ELSE 0 END) AS iit_called '), - DB::raw('SUM(physically_traced) AS physically_traced '), + DB::raw('SUM(CASE WHEN appointment_status = "Missed" OR appointment_status = "Defaulted" OR appointment_status = "IIT" THEN physically_traced END) AS physically_traced '), DB::raw('SUM(CASE WHEN physically_traced = 1 AND appointment_status = "Missed" THEN 1 ELSE 0 END) AS missed_traced '), DB::raw('SUM(CASE WHEN physically_traced = 1 AND appointment_status = "Defaulted" THEN 1 ELSE 0 END) AS defaulted_traced '), DB::raw('SUM(CASE WHEN physically_traced = 1 AND appointment_status = "IIT" THEN 1 ELSE 0 END) AS iit_traced '), - DB::raw('SUM(CASE WHEN final_outcome = "Client returned to care" THEN 1 ELSE 0 END) AS final_outcome'), + DB::raw('SUM(CASE WHEN appointment_status = "Missed" OR appointment_status = "Defaulted" OR appointment_status = "IIT" THEN rtc_no END) AS final_outcome'), DB::raw('SUM(CASE WHEN final_outcome = "Client returned to care" AND appointment_status = "Missed" THEN 1 ELSE 0 END) AS missed_outcome '), DB::raw('SUM(CASE WHEN final_outcome = "Client returned to care" AND appointment_status = "Defaulted" THEN 1 ELSE 0 END) AS defaulted_outcome '), DB::raw('SUM(CASE WHEN final_outcome = "Client returned to care" AND appointment_status = "IIT" THEN 1 ELSE 0 END) AS iit_outcome '), - DB::raw('SUM(CASE WHEN consent = "Yes" AND appointment_status = "Missed" OR appointment_status = "Defaulted" OR appointment_status = "IIT" THEN 1 ELSE 0 END) AS consent '), + DB::raw('SUM(CASE WHEN appointment_status = "Missed" OR appointment_status = "Defaulted" OR appointment_status = "IIT" THEN consent_no END) AS consent '), DB::raw('SUM(CASE WHEN consent = "Yes" AND appointment_status = "Missed" THEN 1 ELSE 0 END) AS missed_consent '), DB::raw('SUM(CASE WHEN consent = "Yes" AND appointment_status = "Defaulted" THEN 1 ELSE 0 END) AS defaulted_consent '), DB::raw('SUM(CASE WHEN consent = "Yes" AND appointment_status = "IIT" THEN 1 ELSE 0 END) AS iit_consent ') @@ -1938,7 +1943,7 @@ public function filter_data(Request $request) $data = []; $all_appoinments = ETLAppointment::select( - DB::raw('COUNT(*) as total_app'), + DB::raw('(SUM(app_kept)+SUM(app_not_kept)+SUM(future)) as total_app'), DB::raw('SUM(app_kept) AS kept_app '), DB::raw('SUM(app_not_kept) AS not_kept_app '), DB::raw('SUM(future) AS future '), @@ -2018,23 +2023,23 @@ public function filter_data(Request $request) // missed appointment $client_missed = DB::table('etl_appointment_detail')->select( DB::raw('SUM(app_not_kept) AS not_kept_app '), - DB::raw('SUM(received_sms) AS messages '), + DB::raw('SUM(CASE WHEN appointment_status = "Missed" OR appointment_status = "Defaulted" OR appointment_status = "IIT" THEN received_sms END) AS messages '), DB::raw('SUM(CASE WHEN received_sms = 1 AND appointment_status = "Missed" THEN 1 ELSE 0 END) AS missed_messages '), DB::raw('SUM(CASE WHEN received_sms = 1 AND appointment_status = "Defaulted" THEN 1 ELSE 0 END) AS defaulted_messages '), DB::raw('SUM(CASE WHEN received_sms = 1 AND appointment_status = "IIT" THEN 1 ELSE 0 END) AS iit_messages '), - DB::raw('SUM(called) AS called '), + DB::raw('SUM(CASE WHEN appointment_status = "Missed" OR appointment_status = "Defaulted" OR appointment_status = "IIT" THEN called END) AS called '), DB::raw('SUM(CASE WHEN called = 1 AND appointment_status = "Missed" THEN 1 ELSE 0 END) AS missed_called '), DB::raw('SUM(CASE WHEN called = 1 AND appointment_status = "Defaulted" THEN 1 ELSE 0 END) AS defaulted_called '), DB::raw('SUM(CASE WHEN called = 1 AND appointment_status = "IIT" THEN 1 ELSE 0 END) AS iit_called '), - DB::raw('SUM(physically_traced) AS physically_traced '), + DB::raw('SUM(CASE WHEN appointment_status = "Missed" OR appointment_status = "Defaulted" OR appointment_status = "IIT" THEN physically_traced END) AS physically_traced '), DB::raw('SUM(CASE WHEN physically_traced = 1 AND appointment_status = "Missed" THEN 1 ELSE 0 END) AS missed_traced '), DB::raw('SUM(CASE WHEN physically_traced = 1 AND appointment_status = "Defaulted" THEN 1 ELSE 0 END) AS defaulted_traced '), DB::raw('SUM(CASE WHEN physically_traced = 1 AND appointment_status = "IIT" THEN 1 ELSE 0 END) AS iit_traced '), - DB::raw('SUM(CASE WHEN final_outcome = "Client returned to care" THEN 1 ELSE 0 END) AS final_outcome'), + DB::raw('SUM(CASE WHEN appointment_status = "Missed" OR appointment_status = "Defaulted" OR appointment_status = "IIT" THEN rtc_no END) AS final_outcome'), DB::raw('SUM(CASE WHEN final_outcome = "Client returned to care" AND appointment_status = "Missed" THEN 1 ELSE 0 END) AS missed_outcome '), DB::raw('SUM(CASE WHEN final_outcome = "Client returned to care" AND appointment_status = "Defaulted" THEN 1 ELSE 0 END) AS defaulted_outcome '), DB::raw('SUM(CASE WHEN final_outcome = "Client returned to care" AND appointment_status = "IIT" THEN 1 ELSE 0 END) AS iit_outcome '), - DB::raw('SUM(CASE WHEN consent = "Yes" AND appointment_status = "Missed" OR appointment_status = "Defaulted" OR appointment_status = "IIT" THEN 1 ELSE 0 END) AS consent '), + DB::raw('SUM(CASE WHEN appointment_status = "Missed" OR appointment_status = "Defaulted" OR appointment_status = "IIT" THEN consent_no END) AS consent '), DB::raw('SUM(CASE WHEN consent = "Yes" AND appointment_status = "Missed" THEN 1 ELSE 0 END) AS missed_consent '), DB::raw('SUM(CASE WHEN consent = "Yes" AND appointment_status = "Defaulted" THEN 1 ELSE 0 END) AS defaulted_consent '), DB::raw('SUM(CASE WHEN consent = "Yes" AND appointment_status = "IIT" THEN 1 ELSE 0 END) AS iit_consent ') @@ -2316,7 +2321,7 @@ public function filter_data(Request $request) $selected_site = $request->site; $all_appoinments = ETLAppointment::select( - DB::raw('COUNT(*) as total_app'), + DB::raw('(SUM(app_kept)+SUM(app_not_kept)+SUM(future)) as total_app'), DB::raw('SUM(app_kept) AS kept_app '), DB::raw('SUM(app_not_kept) AS not_kept_app '), DB::raw('SUM(future) AS future '), @@ -2397,23 +2402,23 @@ public function filter_data(Request $request) // missed appointment $client_missed = DB::table('etl_appointment_detail')->select( DB::raw('SUM(app_not_kept) AS not_kept_app '), - DB::raw('SUM(received_sms) AS messages '), + DB::raw('SUM(CASE WHEN appointment_status = "Missed" OR appointment_status = "Defaulted" OR appointment_status = "IIT" THEN received_sms END) AS messages '), DB::raw('SUM(CASE WHEN received_sms = 1 AND appointment_status = "Missed" THEN 1 ELSE 0 END) AS missed_messages '), DB::raw('SUM(CASE WHEN received_sms = 1 AND appointment_status = "Defaulted" THEN 1 ELSE 0 END) AS defaulted_messages '), DB::raw('SUM(CASE WHEN received_sms = 1 AND appointment_status = "IIT" THEN 1 ELSE 0 END) AS iit_messages '), - DB::raw('SUM(called) AS called '), + DB::raw('SUM(CASE WHEN appointment_status = "Missed" OR appointment_status = "Defaulted" OR appointment_status = "IIT" THEN called END) AS called '), DB::raw('SUM(CASE WHEN called = 1 AND appointment_status = "Missed" THEN 1 ELSE 0 END) AS missed_called '), DB::raw('SUM(CASE WHEN called = 1 AND appointment_status = "Defaulted" THEN 1 ELSE 0 END) AS defaulted_called '), DB::raw('SUM(CASE WHEN called = 1 AND appointment_status = "IIT" THEN 1 ELSE 0 END) AS iit_called '), - DB::raw('SUM(physically_traced) AS physically_traced '), + DB::raw('SUM(CASE WHEN appointment_status = "Missed" OR appointment_status = "Defaulted" OR appointment_status = "IIT" THEN physically_traced END) AS physically_traced '), DB::raw('SUM(CASE WHEN physically_traced = 1 AND appointment_status = "Missed" THEN 1 ELSE 0 END) AS missed_traced '), DB::raw('SUM(CASE WHEN physically_traced = 1 AND appointment_status = "Defaulted" THEN 1 ELSE 0 END) AS defaulted_traced '), DB::raw('SUM(CASE WHEN physically_traced = 1 AND appointment_status = "IIT" THEN 1 ELSE 0 END) AS iit_traced '), - DB::raw('SUM(CASE WHEN final_outcome = "Client returned to care" THEN 1 ELSE 0 END) AS final_outcome'), + DB::raw('SUM(CASE WHEN appointment_status = "Missed" OR appointment_status = "Defaulted" OR appointment_status = "IIT" THEN rtc_no END) AS final_outcome'), DB::raw('SUM(CASE WHEN final_outcome = "Client returned to care" AND appointment_status = "Missed" THEN 1 ELSE 0 END) AS missed_outcome '), DB::raw('SUM(CASE WHEN final_outcome = "Client returned to care" AND appointment_status = "Defaulted" THEN 1 ELSE 0 END) AS defaulted_outcome '), DB::raw('SUM(CASE WHEN final_outcome = "Client returned to care" AND appointment_status = "IIT" THEN 1 ELSE 0 END) AS iit_outcome '), - DB::raw('SUM(CASE WHEN consent = "Yes" AND appointment_status = "Missed" OR appointment_status = "Defaulted" OR appointment_status = "IIT" THEN 1 ELSE 0 END) AS consent '), + DB::raw('SUM(CASE WHEN appointment_status = "Missed" OR appointment_status = "Defaulted" OR appointment_status = "IIT" THEN consent_no END) AS consent '), DB::raw('SUM(CASE WHEN consent = "Yes" AND appointment_status = "Missed" THEN 1 ELSE 0 END) AS missed_consent '), DB::raw('SUM(CASE WHEN consent = "Yes" AND appointment_status = "Defaulted" THEN 1 ELSE 0 END) AS defaulted_consent '), DB::raw('SUM(CASE WHEN consent = "Yes" AND appointment_status = "IIT" THEN 1 ELSE 0 END) AS iit_consent ') @@ -2697,7 +2702,7 @@ public function filter_data(Request $request) $selected_site = $request->site; $all_appoinments = ETLAppointment::select( - DB::raw('COUNT(*) as total_app'), + DB::raw('(SUM(app_kept)+SUM(app_not_kept)+SUM(future)) as total_app'), DB::raw('SUM(app_kept) AS kept_app '), DB::raw('SUM(app_not_kept) AS not_kept_app '), DB::raw('SUM(future) AS future '), @@ -2780,23 +2785,23 @@ public function filter_data(Request $request) // missed appointment $client_missed = DB::table('etl_appointment_detail')->select( DB::raw('SUM(app_not_kept) AS not_kept_app '), - DB::raw('SUM(received_sms) AS messages '), + DB::raw('SUM(CASE WHEN appointment_status = "Missed" OR appointment_status = "Defaulted" OR appointment_status = "IIT" THEN received_sms END) AS messages '), DB::raw('SUM(CASE WHEN received_sms = 1 AND appointment_status = "Missed" THEN 1 ELSE 0 END) AS missed_messages '), DB::raw('SUM(CASE WHEN received_sms = 1 AND appointment_status = "Defaulted" THEN 1 ELSE 0 END) AS defaulted_messages '), DB::raw('SUM(CASE WHEN received_sms = 1 AND appointment_status = "IIT" THEN 1 ELSE 0 END) AS iit_messages '), - DB::raw('SUM(called) AS called '), + DB::raw('SUM(CASE WHEN appointment_status = "Missed" OR appointment_status = "Defaulted" OR appointment_status = "IIT" THEN called END) AS called '), DB::raw('SUM(CASE WHEN called = 1 AND appointment_status = "Missed" THEN 1 ELSE 0 END) AS missed_called '), DB::raw('SUM(CASE WHEN called = 1 AND appointment_status = "Defaulted" THEN 1 ELSE 0 END) AS defaulted_called '), DB::raw('SUM(CASE WHEN called = 1 AND appointment_status = "IIT" THEN 1 ELSE 0 END) AS iit_called '), - DB::raw('SUM(physically_traced) AS physically_traced '), + DB::raw('SUM(CASE WHEN appointment_status = "Missed" OR appointment_status = "Defaulted" OR appointment_status = "IIT" THEN physically_traced END) AS physically_traced '), DB::raw('SUM(CASE WHEN physically_traced = 1 AND appointment_status = "Missed" THEN 1 ELSE 0 END) AS missed_traced '), DB::raw('SUM(CASE WHEN physically_traced = 1 AND appointment_status = "Defaulted" THEN 1 ELSE 0 END) AS defaulted_traced '), DB::raw('SUM(CASE WHEN physically_traced = 1 AND appointment_status = "IIT" THEN 1 ELSE 0 END) AS iit_traced '), - DB::raw('SUM(CASE WHEN final_outcome = "Client returned to care" THEN 1 ELSE 0 END) AS final_outcome'), + DB::raw('SUM(CASE WHEN appointment_status = "Missed" OR appointment_status = "Defaulted" OR appointment_status = "IIT" THEN rtc_no END) AS final_outcome'), DB::raw('SUM(CASE WHEN final_outcome = "Client returned to care" AND appointment_status = "Missed" THEN 1 ELSE 0 END) AS missed_outcome '), DB::raw('SUM(CASE WHEN final_outcome = "Client returned to care" AND appointment_status = "Defaulted" THEN 1 ELSE 0 END) AS defaulted_outcome '), DB::raw('SUM(CASE WHEN final_outcome = "Client returned to care" AND appointment_status = "IIT" THEN 1 ELSE 0 END) AS iit_outcome '), - DB::raw('SUM(CASE WHEN consent = "Yes" AND appointment_status = "Missed" OR appointment_status = "Defaulted" OR appointment_status = "IIT" THEN 1 ELSE 0 END) AS consent '), + DB::raw('SUM(CASE WHEN appointment_status = "Missed" OR appointment_status = "Defaulted" OR appointment_status = "IIT" THEN consent_no END) AS consent '), DB::raw('SUM(CASE WHEN consent = "Yes" AND appointment_status = "Missed" THEN 1 ELSE 0 END) AS missed_consent '), DB::raw('SUM(CASE WHEN consent = "Yes" AND appointment_status = "Defaulted" THEN 1 ELSE 0 END) AS defaulted_consent '), DB::raw('SUM(CASE WHEN consent = "Yes" AND appointment_status = "IIT" THEN 1 ELSE 0 END) AS iit_consent ') diff --git a/public/assets/styles/css/themes/dark-purple.min.css b/public/assets/styles/css/themes/dark-purple.min.css index d455d58..d81523d 100644 --- a/public/assets/styles/css/themes/dark-purple.min.css +++ b/public/assets/styles/css/themes/dark-purple.min.css @@ -30468,7 +30468,7 @@ blockquote { } /* -// dark theme +// dark theme */ .dark-theme { diff --git a/public/assets/styles/css/themes/lite-purple.min.css b/public/assets/styles/css/themes/lite-purple.min.css index d54cc6e..1326e54 100644 --- a/public/assets/styles/css/themes/lite-purple.min.css +++ b/public/assets/styles/css/themes/lite-purple.min.css @@ -32938,7 +32938,7 @@ blockquote { } /* -// dark theme +// dark theme */ .dark-theme { diff --git a/resources/views/dashboard/appointment.blade.php b/resources/views/dashboard/appointment.blade.php index d6ef2d1..2e2b971 100644 --- a/resources/views/dashboard/appointment.blade.php +++ b/resources/views/dashboard/appointment.blade.php @@ -4,7 +4,7 @@ @endsection @@ -656,7 +663,7 @@
    - TX_Curr + TX_Curr

    @@ -667,8 +674,8 @@
    - Clients Consented -

    + Clients Consented +

    @@ -681,8 +688,8 @@
    - Booked Appointments -

    + Booked Appointments +

    @@ -696,8 +703,8 @@
    - Appointments Kept -

    + Appointments Kept +

    @@ -709,8 +716,8 @@
    - Appointments Not Kept -

    + Appointments Not Kept +

    @@ -723,7 +730,7 @@
    - Future Appointments + Future Appointments

    @@ -898,7 +905,7 @@
    - Clients With Missed Appointment + Clients With Missed Appointment

    @@ -909,23 +916,23 @@
    - Consented Clients Who Missed + Consented Clients Who Missed
    - Missed + Missed
    - Defaulted + Defaulted
    - IIT + IIT
    @@ -937,23 +944,23 @@
    - Clients Who Received SMS + Clients Who Received SMS

    - Missed + Missed

    - Defaulted + Defaulted

    - IIT + IIT

    @@ -968,24 +975,24 @@
    - Clients Called + Clients Called

    - Missed + Missed

    - Defaulted + Defaulted

    - IIT + IIT

    @@ -997,23 +1004,23 @@
    - Clients Physically Traced + Clients Physically Traced

    - Missed + Missed

    - Defaulted + Defaulted

    - IIT + IIT

    @@ -1025,24 +1032,24 @@
    - Clients Who RTC + Clients Who RTC

    - Missed + Missed

    - Defaulted + Defaulted

    - IIT + IIT

    From 3f390eaf3d7f01add5ee13fc600cb98038feb686 Mon Sep 17 00:00:00 2001 From: Ronald-pro <36841157+Ronald-pro@users.noreply.github.com> Date: Mon, 13 Feb 2023 13:15:23 +0300 Subject: [PATCH 153/171] clean up on the font sizing --- .../Controllers/FinalDashboardController.php | 74 +------------ .../views/dashboard/appointment.blade.php | 104 +++++++++--------- resources/views/layouts/master.blade.php | 2 +- 3 files changed, 57 insertions(+), 123 deletions(-) diff --git a/app/Http/Controllers/FinalDashboardController.php b/app/Http/Controllers/FinalDashboardController.php index 4111826..01d2696 100644 --- a/app/Http/Controllers/FinalDashboardController.php +++ b/app/Http/Controllers/FinalDashboardController.php @@ -430,16 +430,7 @@ public function appointment() ->whereNotNull('partner') ->orderBy('percent_kept', 'DESC') ->groupBy('partner'); - $appointment_facility = DB::table('etl_appointment_detail')->select( - 'facility', - DB::raw('SUM(app_kept) AS kept_app '), - DB::raw('SUM(app_not_kept) AS not_kept_app '), - ) - ->groupBy('facility'); - $client_list = DB::table('etl_client_detail')->select( - DB::raw('COUNT(ccc_number) AS ccc_number ') - ); // missed appointment $client_missed = DB::table('etl_appointment_detail')->select( @@ -515,18 +506,7 @@ public function appointment() ->whereNotNull('partner') ->orderBy('percent_rtc', 'DESC') ->groupBy('partner'); - $missed_facility = DB::table('etl_appointment_detail')->select( - 'facility', - DB::raw('SUM(app_not_kept) AS not_kept_app '), - DB::raw('SUM(CASE WHEN final_outcome = "Client returned to care" THEN 1 ELSE 0 END) AS final_outcome'), - DB::raw('ROUND(AVG(percent_rtc),1) AS percent_rtc '), - DB::raw('ROUND(AVG(percent_not_kept),1) AS percent_not_kept ') - ) - ->whereNotNull('facility') - ->groupBy('facility'); - $client_app_list = DB::table('etl_client_detail')->select( - DB::raw('COUNT(ccc_number) AS ccc_number ') - ); + $app_period = DB::table('etl_appointment_detail')->select( DB::raw('DATE_FORMAT(appointment_date, "%Y-%M") AS new_date'), DB::raw('ROUND(AVG(percent_rtc),1) AS percent_rtc '), @@ -546,16 +526,12 @@ public function appointment() $data["appointment_marital"] = $appointment_marital->get(); $data["appointment_county"] = $appointment_county->get(); $data["appointment_partner"] = $appointment_partner->get(); - $data["appointment_facility"] = $appointment_facility->get(); - $data["client_list"] = $client_list->get(); $data["client_missed"] = $client_missed->get(); $data["missed_age"] = $missed_age->get(); $data["missed_gender"] = $missed_gender->get(); $data["missed_marital"] = $missed_marital->get(); $data["missed_county"] = $missed_county->get(); $data["missed_partner"] = $missed_partner->get(); - $data["missed_facility"] = $missed_facility->get(); - $data["client_app_list"] = $client_app_list->get(); $data["app_period"] = $app_period->get(); return $data; @@ -1268,16 +1244,6 @@ public function filter_data(Request $request) ) ->whereNotNull('partner') ->groupBy('partner'); - $appointment_facility = DB::table('etl_appointment_detail')->select( - 'facility', - DB::raw('SUM(app_kept) AS kept_app '), - DB::raw('SUM(app_not_kept) AS not_kept_app '), - - ) - ->groupBy('facility'); - $client_list = DB::table('etl_client_detail')->select( - DB::raw('COUNT(ccc_number) AS ccc_number ') - ); // missed appointment $client_missed = DB::table('etl_appointment_detail')->select( @@ -1349,9 +1315,6 @@ public function filter_data(Request $request) ) ->whereNotNull('partner') ->groupBy('partner'); - $client_app_list = DB::table('etl_client_detail')->select( - DB::raw('COUNT(ccc_number) AS ccc_number ') - ); $app_period = DB::table('etl_appointment_detail')->select( DB::raw('DATE_FORMAT(appointment_date, "%Y-%M") AS new_date'), DB::raw('ROUND(AVG(percent_rtc),1) AS percent_rtc '), @@ -1371,15 +1334,12 @@ public function filter_data(Request $request) $appointment_marital = $appointment_marital->where('partner_id', $selected_partners); $appointment_county = $appointment_county->where('partner_id', $selected_partners); $appointment_partner = $appointment_partner->where('partner_id', $selected_partners); - $appointment_facility = $appointment_facility->where('partner_id', $selected_partners); - $client_list = $client_list->where('partner_id', $selected_partners); $client_missed = $client_missed->where('partner_id', $selected_partners); $missed_age = $missed_age->where('partner_id', $selected_partners); $missed_gender = $missed_gender->where('partner_id', $selected_partners); $missed_marital = $missed_marital->where('partner_id', $selected_partners); $missed_county = $missed_county->where('partner_id', $selected_partners); $missed_partner = $missed_partner->where('partner_id', $selected_partners); - $client_app_list = $client_app_list->where('partner_id', $selected_partners); $app_period = $app_period->where('partner_id', $selected_partners); } if (!empty($selected_counties)) { @@ -1391,15 +1351,12 @@ public function filter_data(Request $request) $appointment_marital = $appointment_marital->where('county_id', $selected_counties); $appointment_county = $appointment_county->where('county_id', $selected_counties); $appointment_partner = $appointment_partner->where('county_id', $selected_counties); - $appointment_facility = $appointment_facility->where('county_id', $selected_counties); - $client_list = $client_list->where('county_id', $selected_counties); $client_missed = $client_missed->where('county_id', $selected_counties); $missed_age = $missed_age->where('county_id', $selected_counties); $missed_gender = $missed_gender->where('county_id', $selected_counties); $missed_marital = $missed_marital->where('county_id', $selected_counties); $missed_county = $missed_county->where('county_id', $selected_counties); $missed_partner = $missed_partner->where('county_id', $selected_counties); - $client_app_list = $client_app_list->where('county_id', $selected_counties); $app_period = $app_period->where('county_id', $selected_counties); } if (!empty($selected_subcounties)) { @@ -1411,15 +1368,12 @@ public function filter_data(Request $request) $appointment_marital = $appointment_marital->where('subcounty_id', $selected_subcounties); $appointment_county = $appointment_county->where('subcounty_id', $selected_subcounties); $appointment_partner = $appointment_partner->where('subcounty_id', $selected_subcounties); - $appointment_facility = $appointment_facility->where('subcounty_id', $selected_subcounties); - $client_list = $client_list->where('subcounty_id', $selected_subcounties); $client_missed = $client_missed->where('subcounty_id', $selected_subcounties); $missed_age = $missed_age->where('subcounty_id', $selected_subcounties); $missed_gender = $missed_gender->where('subcounty_id', $selected_subcounties); $missed_marital = $missed_marital->where('subcounty_id', $selected_subcounties); $missed_county = $missed_county->where('subcounty_id', $selected_subcounties); $missed_partner = $missed_partner->where('subcounty_id', $selected_subcounties); - $client_app_list = $client_app_list->where('subcounty_id', $selected_subcounties); $app_period = $app_period->where('subcounty_id', $selected_subcounties); } if (!empty($selected_facilites)) { @@ -1431,15 +1385,12 @@ public function filter_data(Request $request) $appointment_marital = $appointment_marital->where('mfl_code', $selected_facilites); $appointment_county = $appointment_county->where('mfl_code', $selected_facilites); $appointment_partner = $appointment_partner->where('mfl_code', $selected_facilites); - $appointment_facility = $appointment_facility->where('mfl_code', $selected_facilites); - $client_list = $client_list->where('mfl_code', $selected_facilites); $client_missed = $client_missed->where('mfl_code', $selected_facilites); $missed_age = $missed_age->where('mfl_code', $selected_facilites); $missed_gender = $missed_gender->where('mfl_code', $selected_facilites); $missed_marital = $missed_marital->where('mfl_code', $selected_facilites); $missed_county = $missed_county->where('mfl_code', $selected_facilites); $missed_partner = $missed_partner->where('mfl_code', $selected_facilites); - $client_app_list = $client_app_list->where('mfl_code', $selected_facilites); $app_period = $app_period->where('mfl_code', $selected_facilites); } @@ -1452,15 +1403,12 @@ public function filter_data(Request $request) $appointment_marital = $appointment_marital->where('clinic_type', $selected_clinics); $appointment_county = $appointment_county->where('clinic_type', $selected_clinics); $appointment_partner = $appointment_partner->where('clinic_type', $selected_clinics); - $appointment_facility = $appointment_facility->where('clinic_type', $selected_clinics); - $client_list = $client_list->where('etl_client_detail.clinic_type', $selected_clinics); $client_missed = $client_missed->where('clinic_type', $selected_clinics); $missed_age = $missed_age->where('clinic_type', $selected_clinics); $missed_gender = $missed_gender->where('clinic_type', $selected_clinics); $missed_marital = $missed_marital->where('clinic_type', $selected_clinics); $missed_county = $missed_county->where('clinic_type', $selected_clinics); $missed_partner = $missed_partner->where('clinic_type', $selected_clinics); - $client_app_list = $client_app_list->where('etl_client_detail.clinic_type', $selected_clinics); $app_period = $app_period->where('clinic_type', $selected_clinics); } if (!empty($selected_appointments)) { @@ -1472,15 +1420,12 @@ public function filter_data(Request $request) $appointment_marital = $appointment_marital; $appointment_county = $appointment_county; $appointment_partner = $appointment_partner; - $appointment_facility = $appointment_facility; - $client_list = $client_list; $client_missed = $client_missed->where('appointment_status', $selected_appointments); $missed_age = $missed_age->where('appointment_status', $selected_appointments); $missed_gender = $missed_gender->where('appointment_status', $selected_appointments); $missed_marital = $missed_marital->where('appointment_status', $selected_appointments); $missed_county = $missed_county->where('appointment_status', $selected_appointments); $missed_partner = $missed_partner->where('appointment_status', $selected_appointments); - $client_app_list = $client_app_list; $app_period = $app_period->where('appointment_status', $selected_appointments); } if (!empty($selected_from || $selected_to)) { @@ -1492,36 +1437,30 @@ public function filter_data(Request $request) $appointment_marital = $appointment_marital->where('appointment_date', '>=', date($request->from))->where('appointment_date', '<=', date($request->to)); $appointment_county = $appointment_county->where('appointment_date', '>=', date($request->from))->where('appointment_date', '<=', date($request->to)); $appointment_partner = $appointment_partner->where('appointment_date', '>=', date($request->from))->where('appointment_date', '<=', date($request->to)); - $appointment_facility = $appointment_facility->where('appointment_date', '>=', date($request->from))->where('appointment_date', '<=', date($request->to)); - $client_list = $client_list; $client_missed = $client_missed->where('appointment_date', '>=', date($request->from))->where('appointment_date', '<=', date($request->to)); $missed_age = $missed_age->where('appointment_date', '>=', date($request->from))->where('appointment_date', '<=', date($request->to)); $missed_gender = $missed_gender->where('appointment_date', '>=', date($request->from))->where('appointment_date', '<=', date($request->to)); $missed_marital = $missed_marital->where('appointment_date', '>=', date($request->from))->where('appointment_date', '<=', date($request->to)); $missed_county = $missed_county->where('appointment_date', '>=', date($request->from))->where('appointment_date', '<=', date($request->to)); $missed_partner = $missed_partner->where('appointment_date', '>=', date($request->from))->where('appointment_date', '<=', date($request->to)); - $client_app_list = $client_app_list; $app_period = $app_period->where('appointment_date', '>=', date($request->from))->where('appointment_date', '<=', date($request->to)); } if (!empty($selected_sites)) { $all_appoinments = $all_appoinments->where('facility_type', $selected_sites); $consented_clients = $consented_clients->where('facility_type', $selected_sites); - $all_tx_curr = $all_tx_curr->where('facility_type', $selected_sites); + $all_tx_curr = $all_tx_curr->join('tbl_master_facility', 'tbl_tx_cur.mfl_code', '=', 'tbl_master_facility.code')->where('tbl_master_facility.facility_type', $selected_sites); $appointment_gender = $appointment_gender->where('facility_type', $selected_sites); $appointment_age = $appointment_age->where('facility_type', $selected_sites); $appointment_marital = $appointment_marital->where('facility_type', $selected_sites); $appointment_county = $appointment_county->where('facility_type', $selected_sites); $appointment_partner = $appointment_partner->where('facility_type', $selected_sites); - $appointment_facility = $appointment_facility->where('facility_type', $selected_sites); - $client_list = $client_list->where('facility_type', $selected_sites); $client_missed = $client_missed->where('facility_type', $selected_sites); $missed_age = $missed_age->where('facility_type', $selected_sites); $missed_gender = $missed_gender->where('facility_type', $selected_sites); $missed_marital = $missed_marital->where('facility_type', $selected_sites); $missed_county = $missed_county->where('facility_type', $selected_sites); $missed_partner = $missed_partner->where('facility_type', $selected_sites); - $client_app_list = $client_app_list->where('facility_type', $selected_sites); $app_period = $app_period->where('facility_type', $selected_sites); } @@ -1533,15 +1472,12 @@ public function filter_data(Request $request) $data["appointment_marital"] = $appointment_marital->get(); $data["appointment_county"] = $appointment_county->get(); $data["appointment_partner"] = $appointment_partner->get(); - $data["appointment_facility"] = $appointment_facility->get(); - $data["client_list"] = $client_list->get(); $data["client_missed"] = $client_missed->get(); $data["missed_age"] = $missed_age->get(); $data["missed_gender"] = $missed_gender->get(); $data["missed_marital"] = $missed_marital->get(); $data["missed_county"] = $missed_county->get(); $data["missed_partner"] = $missed_partner->get(); - $data["client_app_list"] = $client_app_list->get(); $data["app_period"] = $app_period->get(); return $data; @@ -2266,7 +2202,7 @@ public function filter_data(Request $request) if (!empty($selected_sites)) { $all_appoinments = $all_appoinments->where('facility_type', $selected_sites); $consented_clients = $consented_clients->where('facility_type', $selected_sites); - $all_tx_curr = $all_tx_curr->where('facility_type', $selected_sites); + $all_tx_curr = $all_tx_curr->join('tbl_master_facility', 'tbl_tx_cur.mfl_code', '=', 'tbl_master_facility.code')->where('tbl_master_facility.facility_type', $selected_sites); $appointment_gender = $appointment_gender->where('facility_type', $selected_sites); $appointment_age = $appointment_age->where('facility_type', $selected_sites); $appointment_marital = $appointment_marital->where('facility_type', $selected_sites); @@ -2647,7 +2583,7 @@ public function filter_data(Request $request) if (!empty($selected_sites)) { $all_appoinments = $all_appoinments->where('facility_type', $selected_sites); $consented_clients = $consented_clients->where('facility_type', $selected_sites); - $all_tx_curr = $all_tx_curr->where('facility_type', $selected_sites); + $all_tx_curr = $all_tx_curr->join('tbl_master_facility', 'tbl_tx_cur.mfl_code', '=', 'tbl_master_facility.code')->where('tbl_master_facility.facility_type', $selected_sites); $appointment_gender = $appointment_gender->where('facility_type', $selected_sites); $appointment_age = $appointment_age->where('facility_type', $selected_sites); $appointment_marital = $appointment_marital->where('facility_type', $selected_sites); @@ -3031,7 +2967,7 @@ public function filter_data(Request $request) if (!empty($selected_sites)) { $all_appoinments = $all_appoinments->where('facility_type', $selected_sites); $consented_clients = $consented_clients->where('facility_type', $selected_sites); - $all_tx_curr = $all_tx_curr->where('facility_type', $selected_sites); + $all_tx_curr = $all_tx_curr->join('tbl_master_facility', 'tbl_tx_cur.mfl_code', '=', 'tbl_master_facility.code')->where('tbl_master_facility.facility_type', $selected_sites); $appointment_gender = $appointment_gender->where('facility_type', $selected_sites); $appointment_age = $appointment_age->where('facility_type', $selected_sites); $appointment_marital = $appointment_marital->where('facility_type', $selected_sites); diff --git a/resources/views/dashboard/appointment.blade.php b/resources/views/dashboard/appointment.blade.php index 2e2b971..3cf2663 100644 --- a/resources/views/dashboard/appointment.blade.php +++ b/resources/views/dashboard/appointment.blade.php @@ -69,7 +69,6 @@ } .Indicator { - font-family: 'Manrope'; font-style: normal; font-weight: 700; font-size: 12px; @@ -82,7 +81,6 @@ } .Definition { - font-family: 'Manrope'; font-style: normal; font-weight: 700; line-height: 120%; @@ -114,7 +112,7 @@ } .sub_missed { font-weight: 700; - font-size: 18px; + font-size: 14px; } .no_pec { font-weight: 700; @@ -1767,7 +1765,7 @@ console.log(missed); for (var x = 0; x < consent.length; x++) { - consented = parseInt(consent[x].consented); + consented = consent[x].consented; console.log(consented); if (consented == undefined || consented == null) { consented = 0; @@ -1822,7 +1820,7 @@ } else { app_missed = app_missed.toLocaleString(); } - consent_app = parseInt(missed[x].consent); + consent_app = missed[x].consent; if (consent_app == undefined || consent_app == null) { consent_app = 0; } else { @@ -1922,7 +1920,7 @@ traced_iit = traced_iit.toLocaleString(); } - outcome = parseInt(missed[x].final_outcome); + outcome = missed[x].final_outcome; if (outcome == undefined || outcome == null) { outcome = 0; } else { @@ -2050,19 +2048,19 @@ function appAge(data) { }, legend: { itemStyle: { - fontFamily: 'Manrope', + fontFamily: 'Inter', fontSize: '12px' } }, title: { text: 'Appointment Distribution by Age', style: { - fontFamily: 'Manrope', - fontSize: '12px' + fontFamily: 'Inter', + fontSize: '14px' } }, style: { - fontFamily: 'Manrope' + fontFamily: 'Inter' }, xAxis: { @@ -2118,18 +2116,18 @@ function appGender(data) { }, legend: { itemStyle: { - fontFamily: 'Manrope', + fontFamily: 'Inter', fontSize: '12px' } }, style: { - fontFamily: 'Manrope' + fontFamily: 'Inter' }, title: { text: 'Appointment Distribution by Gender', style: { - fontFamily: 'Manrope', - fontSize: '12px' + fontFamily: 'Inter', + fontSize: '14px' } }, @@ -2185,15 +2183,15 @@ function appMarital(data) { }, legend: { itemStyle: { - fontFamily: 'Manrope', + fontFamily: 'Inter', fontSize: '12px' } }, title: { text: 'Appointment Distribution by Marital Status', style: { - fontFamily: 'Manrope', - fontSize: '12px' + fontFamily: 'Inter', + fontSize: '14px' } }, xAxis: { @@ -2260,15 +2258,15 @@ function missedGender(data) { }, legend: { itemStyle: { - fontFamily: 'Manrope', + fontFamily: 'Inter', fontSize: '12px' } }, title: { text: 'Missed Appointment Distribution by Gender', style: { - fontFamily: 'Manrope', - fontSize: '12px' + fontFamily: 'Inter', + fontSize: '14px' } }, xAxis: { @@ -2333,15 +2331,15 @@ function missedAge(data) { }, legend: { itemStyle: { - fontFamily: 'Manrope', + fontFamily: 'Inter', fontSize: '12px' } }, title: { text: 'Missed Appointment Distribution by Age', style: { - fontFamily: 'Manrope', - fontSize: '12px' + fontFamily: 'Inter', + fontSize: '14px' } }, xAxis: { @@ -2406,15 +2404,15 @@ function missedMarital(data) { }, legend: { itemStyle: { - fontFamily: 'Manrope', + fontFamily: 'Inter', fontSize: '12px' } }, title: { text: 'Missed Client Distribution by Marital Status', style: { - fontFamily: 'Manrope', - fontSize: '12px' + fontFamily: 'Inter', + fontSize: '14px' } }, xAxis: { @@ -2479,15 +2477,15 @@ function missedPeriod(data) { }, legend: { itemStyle: { - fontFamily: 'Manrope', + fontFamily: 'Inter', fontSize: '12px' } }, title: { text: 'Missed Client Distribution by Period', style: { - fontFamily: 'Manrope', - fontSize: '12px' + fontFamily: 'Inter', + fontSize: '14px' } }, xAxis: { @@ -2553,15 +2551,15 @@ function appCounty(data) { }, legend: { itemStyle: { - fontFamily: 'Manrope', + fontFamily: 'Inter', fontSize: '12px' } }, title: { text: 'Appointment Distribution by County', style: { - fontFamily: 'Manrope', - fontSize: '12px' + fontFamily: 'Inter', + fontSize: '14px' } }, xAxis: { @@ -2627,15 +2625,15 @@ function missedCounty(data) { }, legend: { itemStyle: { - fontFamily: 'Manrope', + fontFamily: 'Inter', fontSize: '12px' } }, title: { text: 'Missed Client Distribution by County', style: { - fontFamily: 'Manrope', - fontSize: '12px' + fontFamily: 'Inter', + fontSize: '14px' } }, xAxis: { @@ -2700,15 +2698,15 @@ function missedPartner(data) { }, legend: { itemStyle: { - fontFamily: 'Manrope', + fontFamily: 'Inter', fontSize: '12px' } }, title: { text: 'Missed Client Distribution by Partner', style: { - fontFamily: 'Manrope', - fontSize: '12px' + fontFamily: 'Inter', + fontSize: '14px' } }, xAxis: { @@ -2773,15 +2771,15 @@ function appPartner(data) { }, legend: { itemStyle: { - fontFamily: 'Manrope', + fontFamily: 'Inter', fontSize: '12px' } }, title: { text: 'Appointment Distribution by Partner', style: { - fontFamily: 'Manrope', - fontSize: '12px' + fontFamily: 'Inter', + fontSize: '14px' } }, xAxis: { @@ -2848,15 +2846,15 @@ function missedPartner(data) { }, legend: { itemStyle: { - fontFamily: 'Manrope', + fontFamily: 'Inter', fontSize: '12px' } }, title: { text: 'Missed Client Distribution by Partner', style: { - fontFamily: 'Manrope', - fontSize: '12px' + fontFamily: 'Inter', + fontSize: '14px' } }, xAxis: { @@ -2921,15 +2919,15 @@ function appPartner(data) { }, legend: { itemStyle: { - fontFamily: 'Manrope', + fontFamily: 'Inter', fontSize: '12px' } }, title: { text: 'Appointment Distribution by Partner', style: { - fontFamily: 'Manrope', - fontSize: '12px' + fontFamily: 'Inter', + fontSize: '14px' } }, xAxis: { @@ -2995,15 +2993,15 @@ function appFacility(data) { }, legend: { itemStyle: { - fontFamily: 'Manrope', + fontFamily: 'Inter', fontSize: '12px' } }, title: { text: 'Appointment Distribution by Facility', style: { - fontFamily: 'Manrope', - fontSize: '12px' + fontFamily: 'Inter', + fontSize: '14px' } }, xAxis: { @@ -3068,15 +3066,15 @@ function missedFacility(data) { }, legend: { itemStyle: { - fontFamily: 'Manrope', + fontFamily: 'Inter', fontSize: '12px' } }, title: { text: 'Missed Appointment Distribution by Facility', style: { - fontFamily: 'Manrope', - fontSize: '12px' + fontFamily: 'Inter', + fontSize: '14px' } }, xAxis: { diff --git a/resources/views/layouts/master.blade.php b/resources/views/layouts/master.blade.php index f433936..959eb64 100644 --- a/resources/views/layouts/master.blade.php +++ b/resources/views/layouts/master.blade.php @@ -9,7 +9,7 @@ Ushauri - Getting better one text at a time - + @yield('before-css') From 0abbb721a505fb20546bae6e80fc7c3360b646b3 Mon Sep 17 00:00:00 2001 From: Ronald-pro <36841157+Ronald-pro@users.noreply.github.com> Date: Wed, 15 Feb 2023 10:36:39 +0300 Subject: [PATCH 154/171] code clean up --- .../Controllers/FinalDashboardController.php | 104 ++++++++++-------- .../views/dashboard/appointment.blade.php | 21 +++- resources/views/layouts/master.blade.php | 4 +- 3 files changed, 78 insertions(+), 51 deletions(-) diff --git a/app/Http/Controllers/FinalDashboardController.php b/app/Http/Controllers/FinalDashboardController.php index 01d2696..9ecdc38 100644 --- a/app/Http/Controllers/FinalDashboardController.php +++ b/app/Http/Controllers/FinalDashboardController.php @@ -1180,7 +1180,7 @@ public function filter_data(Request $request) $selected_appointments = $request->appointments; $selected_from = $request->from; $selected_to = $request->to; - $selected_site = $request->site; + $selected_site = $request->sites; $all_appoinments = ETLAppointment::select( DB::raw('(SUM(app_kept)+SUM(app_not_kept)+SUM(future)) as total_app'), @@ -1446,22 +1446,39 @@ public function filter_data(Request $request) $app_period = $app_period->where('appointment_date', '>=', date($request->from))->where('appointment_date', '<=', date($request->to)); } - if (!empty($selected_sites)) { - $all_appoinments = $all_appoinments->where('facility_type', $selected_sites); - $consented_clients = $consented_clients->where('facility_type', $selected_sites); - $all_tx_curr = $all_tx_curr->join('tbl_master_facility', 'tbl_tx_cur.mfl_code', '=', 'tbl_master_facility.code')->where('tbl_master_facility.facility_type', $selected_sites); - $appointment_gender = $appointment_gender->where('facility_type', $selected_sites); - $appointment_age = $appointment_age->where('facility_type', $selected_sites); - $appointment_marital = $appointment_marital->where('facility_type', $selected_sites); - $appointment_county = $appointment_county->where('facility_type', $selected_sites); - $appointment_partner = $appointment_partner->where('facility_type', $selected_sites); - $client_missed = $client_missed->where('facility_type', $selected_sites); - $missed_age = $missed_age->where('facility_type', $selected_sites); - $missed_gender = $missed_gender->where('facility_type', $selected_sites); - $missed_marital = $missed_marital->where('facility_type', $selected_sites); - $missed_county = $missed_county->where('facility_type', $selected_sites); - $missed_partner = $missed_partner->where('facility_type', $selected_sites); - $app_period = $app_period->where('facility_type', $selected_sites); + if (!empty($selected_site == 'EMR Based')) { + $all_appoinments = $all_appoinments->where('facility_type', '=', 'EMR Based'); + $consented_clients = $consented_clients->where('facility_type', '=', 'EMR Based'); + $all_tx_curr = $all_tx_curr->join('etl_client_detail', 'tbl_tx_cur.mfl_code', '=', 'etl_client_detail.mfl_code')->where('etl_client_detail.facility_type', '=', 'EMR Based')->groupBy('etl_client_detail.mfl_code'); + $appointment_gender = $appointment_gender->where('facility_type', '=', 'EMR Based'); + $appointment_age = $appointment_age->where('facility_type', '=', 'EMR Based'); + $appointment_marital = $appointment_marital->where('facility_type', '=', 'EMR Based'); + $appointment_county = $appointment_county->where('facility_type', '=', 'EMR Based'); + $appointment_partner = $appointment_partner->where('facility_type', '=', 'EMR Based'); + $client_missed = $client_missed->where('facility_type', '=', 'EMR Based'); + $missed_age = $missed_age->where('facility_type', '=', 'EMR Based'); + $missed_gender = $missed_gender->where('facility_type', '=', 'EMR Based'); + $missed_marital = $missed_marital->where('facility_type', '=', 'EMR Based'); + $missed_county = $missed_county->where('facility_type', '=', 'EMR Based'); + $missed_partner = $missed_partner->where('facility_type', '=', 'EMR Based'); + $app_period = $app_period->where('facility_type', '=', 'EMR Based'); + } + if (!empty($selected_site == 'Paper Based')) { + $all_appoinments = $all_appoinments->where('facility_type', '=', 'Paper Based'); + $consented_clients = $consented_clients->where('facility_type', '=', 'Paper Based'); + $all_tx_curr = $all_tx_curr->join('etl_client_detail', 'tbl_tx_cur.mfl_code', '=', 'etl_client_detail.mfl_code')->where('etl_client_detail.facility_type', '=', 'Paper Based')->groupBy('etl_client_detail.mfl_code'); + $appointment_gender = $appointment_gender->where('facility_type', '=', 'Paper Based'); + $appointment_age = $appointment_age->where('facility_type', '=', 'Paper Based'); + $appointment_marital = $appointment_marital->where('facility_type', '=', 'Paper Based'); + $appointment_county = $appointment_county->where('facility_type', '=', 'Paper Based'); + $appointment_partner = $appointment_partner->where('facility_type', '=', 'Paper Based'); + $client_missed = $client_missed->where('facility_type', '=', 'Paper Based'); + $missed_age = $missed_age->where('facility_type', '=', 'Paper Based'); + $missed_gender = $missed_gender->where('facility_type', '=', 'Paper Based'); + $missed_marital = $missed_marital->where('facility_type', '=', 'Paper Based'); + $missed_county = $missed_county->where('facility_type', '=', 'Paper Based'); + $missed_partner = $missed_partner->where('facility_type', '=', 'Paper Based'); + $app_period = $app_period->where('facility_type', '=', 'Paper Based'); } $data["all_appoinments"] = $all_appoinments->get(); @@ -1826,7 +1843,7 @@ public function filter_data(Request $request) if (!empty($selected_sites)) { $all_appoinments = $all_appoinments->where('facility_type', $selected_sites); $consented_clients = $consented_clients->where('facility_type', $selected_sites); - $all_tx_curr = $all_tx_curr->where('facility_type', $selected_sites); + $all_tx_curr = $all_tx_curr->join('etl_client_detail', 'tbl_tx_cur.mfl_code', '=', 'etl_client_detail.mfl_code')->where('etl_client_detail.facility_type', '=', 'EMR Based')->groupBy('etl_client_detail.mfl_code'); $appointment_gender = $appointment_gender->where('facility_type', $selected_sites); $appointment_age = $appointment_age->where('facility_type', $selected_sites); $appointment_marital = $appointment_marital->where('facility_type', $selected_sites); @@ -1875,7 +1892,7 @@ public function filter_data(Request $request) $selected_appointments = $request->appointments; $selected_from = $request->from; $selected_to = $request->to; - $selected_site = $request->site; + $selected_site = $request->sites; $data = []; $all_appoinments = ETLAppointment::select( @@ -2199,26 +2216,26 @@ public function filter_data(Request $request) $app_period = $app_period->where('appointment_date', '>=', date($request->from))->where('appointment_date', '<=', date($request->to)); } - if (!empty($selected_sites)) { - $all_appoinments = $all_appoinments->where('facility_type', $selected_sites); - $consented_clients = $consented_clients->where('facility_type', $selected_sites); - $all_tx_curr = $all_tx_curr->join('tbl_master_facility', 'tbl_tx_cur.mfl_code', '=', 'tbl_master_facility.code')->where('tbl_master_facility.facility_type', $selected_sites); - $appointment_gender = $appointment_gender->where('facility_type', $selected_sites); - $appointment_age = $appointment_age->where('facility_type', $selected_sites); - $appointment_marital = $appointment_marital->where('facility_type', $selected_sites); - $appointment_county = $appointment_county->where('facility_type', $selected_sites); - $appointment_partner = $appointment_partner->where('facility_type', $selected_sites); - $appointment_facility = $appointment_facility->where('facility_type', $selected_sites); - $client_list = $client_list->where('facility_type', $selected_sites); - $client_missed = $client_missed->where('facility_type', $selected_sites); - $missed_age = $missed_age->where('facility_type', $selected_sites); - $missed_gender = $missed_gender->where('facility_type', $selected_sites); - $missed_marital = $missed_marital->where('facility_type', $selected_sites); - $missed_county = $missed_county->where('facility_type', $selected_sites); - $missed_partner = $missed_partner->where('facility_type', $selected_sites); - $missed_facility = $missed_facility->where('facility_type', $selected_sites); - $client_app_list = $client_app_list->where('facility_type', $selected_sites); - $app_period = $app_period->where('facility_type', $selected_sites); + if (!empty($selected_site)) { + $all_appoinments = $all_appoinments->where('facility_type', $selected_site); + $consented_clients = $consented_clients->where('facility_type', $selected_site); + $all_tx_curr = $all_tx_curr->join('etl_client_detail', 'tbl_tx_cur.mfl_code', '=', 'etl_client_detail.mfl_code')->where('etl_client_detail.facility_type', $selected_site)->groupBy('etl_client_detail.mfl_code'); + $appointment_gender = $appointment_gender->where('facility_type', $selected_site); + $appointment_age = $appointment_age->where('facility_type', $selected_site); + $appointment_marital = $appointment_marital->where('facility_type', $selected_site); + $appointment_county = $appointment_county->where('facility_type', $selected_site); + $appointment_partner = $appointment_partner->where('facility_type', $selected_site); + $appointment_facility = $appointment_facility->where('facility_type', $selected_site); + $client_list = $client_list->where('facility_type', $selected_site); + $client_missed = $client_missed->where('facility_type', $selected_site); + $missed_age = $missed_age->where('facility_type', $selected_site); + $missed_gender = $missed_gender->where('facility_type', $selected_site); + $missed_marital = $missed_marital->where('facility_type', $selected_site); + $missed_county = $missed_county->where('facility_type', $selected_site); + $missed_partner = $missed_partner->where('facility_type', $selected_site); + $missed_facility = $missed_facility->where('facility_type', $selected_site); + $client_app_list = $client_app_list->where('facility_type', $selected_site); + $app_period = $app_period->where('facility_type', $selected_site); } $data["all_appoinments"] = $all_appoinments->get(); @@ -2254,7 +2271,7 @@ public function filter_data(Request $request) $selected_appointments = $request->appointments; $selected_from = $request->from; $selected_to = $request->to; - $selected_site = $request->site; + $selected_sites = $request->sites; $all_appoinments = ETLAppointment::select( DB::raw('(SUM(app_kept)+SUM(app_not_kept)+SUM(future)) as total_app'), @@ -2583,7 +2600,7 @@ public function filter_data(Request $request) if (!empty($selected_sites)) { $all_appoinments = $all_appoinments->where('facility_type', $selected_sites); $consented_clients = $consented_clients->where('facility_type', $selected_sites); - $all_tx_curr = $all_tx_curr->join('tbl_master_facility', 'tbl_tx_cur.mfl_code', '=', 'tbl_master_facility.code')->where('tbl_master_facility.facility_type', $selected_sites); + $all_tx_curr = $all_tx_curr->join('etl_client_detail', 'tbl_tx_cur.mfl_code', '=', 'etl_client_detail.mfl_code')->where('etl_client_detail.facility_type', $selected_sites)->groupBy('etl_client_detail.mfl_code'); $appointment_gender = $appointment_gender->where('facility_type', $selected_sites); $appointment_age = $appointment_age->where('facility_type', $selected_sites); $appointment_marital = $appointment_marital->where('facility_type', $selected_sites); @@ -2635,7 +2652,7 @@ public function filter_data(Request $request) $selected_appointments = $request->appointments; $selected_from = $request->from; $selected_to = $request->to; - $selected_site = $request->site; + $selected_sites = $request->sites; $all_appoinments = ETLAppointment::select( DB::raw('(SUM(app_kept)+SUM(app_not_kept)+SUM(future)) as total_app'), @@ -2967,7 +2984,7 @@ public function filter_data(Request $request) if (!empty($selected_sites)) { $all_appoinments = $all_appoinments->where('facility_type', $selected_sites); $consented_clients = $consented_clients->where('facility_type', $selected_sites); - $all_tx_curr = $all_tx_curr->join('tbl_master_facility', 'tbl_tx_cur.mfl_code', '=', 'tbl_master_facility.code')->where('tbl_master_facility.facility_type', $selected_sites); + $all_tx_curr = $all_tx_curr->join('etl_client_detail', 'tbl_tx_cur.mfl_code', '=', 'etl_client_detail.mfl_code')->where('etl_client_detail.facility_type', $selected_sites)->groupBy('etl_client_detail.mfl_code'); $appointment_gender = $appointment_gender->where('facility_type', $selected_sites); $appointment_age = $appointment_age->where('facility_type', $selected_sites); $appointment_marital = $appointment_marital->where('facility_type', $selected_sites); @@ -3009,4 +3026,5 @@ public function filter_data(Request $request) return $data; } } + } diff --git a/resources/views/dashboard/appointment.blade.php b/resources/views/dashboard/appointment.blade.php index 3cf2663..a630088 100644 --- a/resources/views/dashboard/appointment.blade.php +++ b/resources/views/dashboard/appointment.blade.php @@ -87,15 +87,22 @@ /* identical to box height, or 20px */ letter-spacing: -0.3px; text-transform: capitalize; + font-size: 12px; color: #888888; } + .Definitions { + font-style: normal; + font-size: 12px; + color: #888888; + } .Indications { box-sizing: border-box; background: rgba(229, 247, 255, 0.28); border: 1px solid #E5F7FF; border-radius: 10px; + font-size: 14px; } .box_pec { @@ -393,7 +400,7 @@
    - + @if (count($sub_counties) > 0) @foreach($sub_counties as $sub_county) @@ -420,6 +427,7 @@ @if (count($facilities) > 0) @foreach($facilities as $facility) + @endforeach @endif @@ -429,7 +437,7 @@
    @@ -441,6 +449,7 @@ @if (count($clinics) > 0) @foreach($clinics as $clinic) + @endforeach @endif @@ -450,7 +459,7 @@
    + - + @if (count($counties) > 0) @foreach($counties as $county) @@ -176,7 +182,7 @@
    + + + + +
    +
    +
    -
    -
    - -
    -
    +
    +
    @@ -246,7 +253,7 @@
    - +
    @@ -312,7 +319,16 @@
    - + + + + +
    +
    +
    +
    +
    -
    -
    - -
    -
    +
    +
    @@ -371,7 +379,7 @@
    - +
    @@ -399,8 +407,8 @@
    - + @if (count($counties) > 0) @foreach($counties as $county) @@ -411,8 +419,8 @@
    - + @if (count($sub_counties) > 0) @foreach($sub_counties as $sub_county) @@ -423,23 +431,23 @@
    - - - @endforeach - @endif + +
    - + + @if (count($facilities) > 0) + @foreach($facilities as $facility) - - + + @endforeach + @endif
    @@ -458,8 +466,8 @@
    - + @@ -471,7 +479,7 @@
    - +
    @@ -484,7 +492,7 @@
    - +
    @@ -512,7 +520,16 @@
    - + + + + +
    +
    +
    +
    +
    -
    -
    - -
    -
    +
    +
    @@ -571,7 +580,7 @@
    - +
    @@ -623,7 +632,7 @@
    - +
    @@ -635,7 +644,7 @@
    - +
    @@ -670,7 +679,7 @@
    - TX_Curr + TX_Curr

    @@ -681,7 +690,7 @@
    - Clients Consented + Clients Consented

    @@ -695,7 +704,7 @@
    - Booked Appointments + Booked Appointments

    @@ -710,7 +719,7 @@
    - Appointments Kept + Appointments Kept

    @@ -868,7 +877,7 @@ - @if (count($client_list) > 0) + @if (count($client_list) > 0) @foreach($client_list as $result) @@ -951,7 +960,7 @@
    - Clients Who Received SMS + Clients Who Received SMS

    @@ -1011,7 +1020,7 @@
    - Clients Physically Traced + Clients Physically Traced

    @@ -1321,6 +1330,7 @@ }); }); + $(document).ready(function() { $('select[name="county"]').on('change', function() { var countyID = $(this).val(); @@ -1365,6 +1375,107 @@ }); + } + }); + } else { + $('select[name="facility"]').empty(); + } + }); + }); + $(document).ready(function() { + $('select[name="county"]').on('change', function() { + var countyID = $(this).val(); + if (countyID) { + $.ajax({ + url: '/get_county_facilities/' + countyID, + type: "GET", + dataType: "json", + success: function(data) { + + + $('select[name="facility"]').empty(); + $('select[name="facility"]').append(''); + $.each(data, function(key, value) { + $('select[name="facility"]').append(''); + }); + + + } + }); + } else { + $('select[name="facility"]').empty(); + } + }); + }); + + $(document).ready(function() { + $('select[name="partner"]').on('change', function() { + var partnerID = $(this).val(); + if (partnerID) { + $.ajax({ + url: '/get_partner_sub_counties/' + partnerID, + type: "GET", + dataType: "json", + success: function(data) { + + + $('select[name="subcounty"]').empty(); + $('select[name="subcounty"]').append(''); + $.each(data, function(key, value) { + $('select[name="subcounty"]').append(''); + }); + + + } + }); + } else { + $('select[name="subcounty"]').empty(); + } + }); + }); + $(document).ready(function() { + $('select[name="partner"]').on('change', function() { + var partnerID = $(this).val(); + if (partnerID) { + $.ajax({ + url: '/get_partner_facilities/' + partnerID, + type: "GET", + dataType: "json", + success: function(data) { + + + $('select[name="facility"]').empty(); + $('select[name="facility"]').append(''); + $.each(data, function(key, value) { + $('select[name="facility"]').append(''); + }); + + + } + }); + } else { + $('select[name="facility"]').empty(); + } + }); + }); + $(document).ready(function() { + $('select[name="site"]').on('change', function() { + var siteID = $(this).val(); + if (siteID) { + $.ajax({ + url: '/get_sitetype_facilities/' + siteID, + type: "GET", + dataType: "json", + success: function(data) { + + + $('select[name="facility"]').empty(); + $('select[name="facility"]').append(''); + $.each(data, function(key, value) { + $('select[name="facility"]').append(''); + }); + + } }); } else { @@ -1449,9 +1560,9 @@ // $.each(data.client_list, function(key, value) { // $('#client').append("\ - // " + value.upi_no + "\ - // " + value.ccc_number + "\ - // " + value.client_name + "\ + // " + value.upi_no + "\ + // " + value.ccc_number + "\ + // " + value.client_name + "\ // " + value.dob + "\ // " + value.phone_no + "\ // " + value.consented + "\ @@ -1459,7 +1570,7 @@ // " + value.client_status + "\ // " + value.kept_app + "\ // " + value.not_kept_app + "\ - // "); + // "); // }) } if (authenticated == 'Admin' || authenticated == 'Donor') { @@ -1745,6 +1856,7 @@ const consent = data.consented_clients; const apps = data.all_appoinments; const tx = data.all_tx_curr; + console.log(tx); const missed = data.client_missed; appGender(data.appointment_gender); appAge(data.appointment_age); @@ -1820,7 +1932,13 @@ percnt_future = Math.round(apps[x].percent_future).toFixed(1) + '%'; } for (var x = 0; x < tx.length; x++) { - tx_curr = parseInt(tx[x].tx_cur).toLocaleString(); + tx_curr = tx[x].tx_cur + if (tx_curr == undefined || tx_curr == null || isNaN(tx_curr)) { + tx_curr = 0; + } else { + tx_curr = tx_curr.toLocaleString(); + } + } for (var x = 0; x < missed.length; x++) { app_missed = missed[x].not_kept_app; diff --git a/resources/views/layouts/master.blade.php b/resources/views/layouts/master.blade.php index 062bd2a..20a4e74 100644 --- a/resources/views/layouts/master.blade.php +++ b/resources/views/layouts/master.blade.php @@ -164,8 +164,8 @@ - + @endif + + diff --git a/routes/web.php b/routes/web.php index 4038a64..2c5516b 100644 --- a/routes/web.php +++ b/routes/web.php @@ -271,4 +271,9 @@ Route::get('/appointment/data', ['uses' => 'App\Http\Controllers\FinalDashboardController@appointment', 'as' => 'appointment_data']); Route::get('/filter_app_data', ['uses' => 'App\Http\Controllers\FinalDashboardController@filter_data', 'as' => 'filter_app_data']); Route::get('/user/info', ['uses' => 'App\Http\Controllers\UserController@user_info', 'as' => 'user_info']); + Route::get('/get_county_facilities/{id}', ['uses' => 'App\Http\Controllers\FinalDashboardController@get_county_facilities', 'as' => 'get_county_facilities']); + Route::get('/get_partner_sub_counties/{id}', ['uses' => 'App\Http\Controllers\FinalDashboardController@get_partner_sub_counties', 'as' => 'get_partner_sub_counties']); + Route::get('/get_partner_facilities/{id}', ['uses' => 'App\Http\Controllers\FinalDashboardController@get_partner_facilities', 'as' => 'get_partner_facilities']); + Route::get('/get_sitetype_facilities/{id}', ['uses' => 'App\Http\Controllers\FinalDashboardController@get_sitetype_facilities', 'as' => 'get_sitetype_facilities']); + }); From 946f35cbdda8aefbc8ea8327c1efee0e30a506ad Mon Sep 17 00:00:00 2001 From: Ronald-pro <36841157+Ronald-pro@users.noreply.github.com> Date: Tue, 21 Feb 2023 20:44:22 +0300 Subject: [PATCH 156/171] fixed error on duplicate dates on messeges list --- .../Controllers/FinalDashboardController.php | 86 +++++----- app/Http/Controllers/NewReportController.php | 18 +- .../views/dashboard/appointment.blade.php | 12 +- .../views/layouts/common/footer.blade.php | 2 +- .../large-vertical-sidebar/sidebar.blade.php | 15 +- resources/views/users/passreset.blade.php | 155 +++++++++--------- 6 files changed, 149 insertions(+), 139 deletions(-) diff --git a/app/Http/Controllers/FinalDashboardController.php b/app/Http/Controllers/FinalDashboardController.php index 1c5c78b..b2cfc40 100644 --- a/app/Http/Controllers/FinalDashboardController.php +++ b/app/Http/Controllers/FinalDashboardController.php @@ -1379,7 +1379,7 @@ public function filter_data(Request $request) if (!empty($selected_facilites)) { $all_appoinments = $all_appoinments->where('mfl_code', $selected_facilites); $consented_clients = $consented_clients->where('mfl_code', $selected_facilites); - $all_tx_curr = $all_tx_curr->where('tbl_partner_facility.mfl_code', $selected_facilites); + $all_tx_curr = $all_tx_curr->where('tbl_partner_facility.mfl_code', $selected_facilites)->groupBy('tbl_partner_facility.mfl_code'); $appointment_gender = $appointment_gender->where('mfl_code', $selected_facilites); $appointment_age = $appointment_age->where('mfl_code', $selected_facilites); $appointment_marital = $appointment_marital->where('mfl_code', $selected_facilites); @@ -1446,39 +1446,22 @@ public function filter_data(Request $request) $app_period = $app_period->where('appointment_date', '>=', date($request->from))->where('appointment_date', '<=', date($request->to)); } - if (!empty($selected_site == 'EMR Based')) { - $all_appoinments = $all_appoinments->where('facility_type', '=', 'EMR Based'); - $consented_clients = $consented_clients->where('facility_type', '=', 'EMR Based'); - $all_tx_curr = $all_tx_curr->join('etl_client_detail', 'tbl_tx_cur.mfl_code', '=', 'etl_client_detail.mfl_code')->where('etl_client_detail.facility_type', '=', 'EMR Based')->groupBy('etl_client_detail.mfl_code'); - $appointment_gender = $appointment_gender->where('facility_type', '=', 'EMR Based'); - $appointment_age = $appointment_age->where('facility_type', '=', 'EMR Based'); - $appointment_marital = $appointment_marital->where('facility_type', '=', 'EMR Based'); - $appointment_county = $appointment_county->where('facility_type', '=', 'EMR Based'); - $appointment_partner = $appointment_partner->where('facility_type', '=', 'EMR Based'); - $client_missed = $client_missed->where('facility_type', '=', 'EMR Based'); - $missed_age = $missed_age->where('facility_type', '=', 'EMR Based'); - $missed_gender = $missed_gender->where('facility_type', '=', 'EMR Based'); - $missed_marital = $missed_marital->where('facility_type', '=', 'EMR Based'); - $missed_county = $missed_county->where('facility_type', '=', 'EMR Based'); - $missed_partner = $missed_partner->where('facility_type', '=', 'EMR Based'); - $app_period = $app_period->where('facility_type', '=', 'EMR Based'); - } - if (!empty($selected_site == 'Paper Based')) { - $all_appoinments = $all_appoinments->where('facility_type', '=', 'Paper Based'); - $consented_clients = $consented_clients->where('facility_type', '=', 'Paper Based'); - $all_tx_curr = $all_tx_curr->join('etl_client_detail', 'tbl_tx_cur.mfl_code', '=', 'etl_client_detail.mfl_code')->where('etl_client_detail.facility_type', '=', 'Paper Based')->groupBy('etl_client_detail.mfl_code'); - $appointment_gender = $appointment_gender->where('facility_type', '=', 'Paper Based'); - $appointment_age = $appointment_age->where('facility_type', '=', 'Paper Based'); - $appointment_marital = $appointment_marital->where('facility_type', '=', 'Paper Based'); - $appointment_county = $appointment_county->where('facility_type', '=', 'Paper Based'); - $appointment_partner = $appointment_partner->where('facility_type', '=', 'Paper Based'); - $client_missed = $client_missed->where('facility_type', '=', 'Paper Based'); - $missed_age = $missed_age->where('facility_type', '=', 'Paper Based'); - $missed_gender = $missed_gender->where('facility_type', '=', 'Paper Based'); - $missed_marital = $missed_marital->where('facility_type', '=', 'Paper Based'); - $missed_county = $missed_county->where('facility_type', '=', 'Paper Based'); - $missed_partner = $missed_partner->where('facility_type', '=', 'Paper Based'); - $app_period = $app_period->where('facility_type', '=', 'Paper Based'); + if (!empty($selected_site)) { + $all_appoinments = $all_appoinments->where('facility_type', $selected_site); + $consented_clients = $consented_clients->where('facility_type', $selected_site); + $all_tx_curr = $all_tx_curr; + $appointment_gender = $appointment_gender->where('facility_type', $selected_site); + $appointment_age = $appointment_age->where('facility_type', $selected_site); + $appointment_marital = $appointment_marital->where('facility_type', $selected_site); + $appointment_county = $appointment_county->where('facility_type', $selected_site); + $appointment_partner = $appointment_partner->where('facility_type', $selected_site); + $client_missed = $client_missed->where('facility_type', $selected_site); + $missed_age = $missed_age->where('facility_type', $selected_site); + $missed_gender = $missed_gender->where('facility_type', $selected_site); + $missed_marital = $missed_marital->where('facility_type', $selected_site); + $missed_county = $missed_county->where('facility_type', $selected_site); + $missed_partner = $missed_partner->where('facility_type', $selected_site); + $app_period = $app_period->where('facility_type', $selected_site); } $data["all_appoinments"] = $all_appoinments->get(); @@ -3110,14 +3093,35 @@ public function get_partner_facilities(Request $request, $id) public function get_sitetype_facilities(Request $request, $id) { $partner_ids = array(); - $id = $request->site; - $facilities = PartnerFacility::join('tbl_master_facility', 'tbl_partner_facility.mfl_code', '=', 'tbl_master_facility.code') - ->where("tbl_master_facility.site_type", $id) - ->orderBy('tbl_master_facility.name', 'ASC') - ->pluck("tbl_master_facility.name", "tbl_master_facility.code"); + if (!empty($id == 'EMR Based' || $id == 'Paper Based')) { + $facilities = PartnerFacility::join('tbl_master_facility', 'tbl_partner_facility.mfl_code', '=', 'tbl_master_facility.code') + ->where("tbl_master_facility.site_type", $id) + ->orderBy('tbl_master_facility.name', 'ASC') + ->pluck("tbl_master_facility.name", "tbl_master_facility.code"); + } + + if (Auth::user()->access_level == 'Partner') { + $facilities = PartnerFacility::join('tbl_master_facility', 'tbl_partner_facility.mfl_code', '=', 'tbl_master_facility.code') + ->where("tbl_master_facility.site_type", $id) + ->where("tbl_partner_facility.partner_id", '=', Auth::user()->partner_id) + ->orderBy('tbl_master_facility.name', 'ASC') + ->pluck("tbl_master_facility.name", "tbl_master_facility.code"); + } + if (Auth::user()->access_level == 'County') { + $facilities = PartnerFacility::join('tbl_master_facility', 'tbl_partner_facility.mfl_code', '=', 'tbl_master_facility.code') + ->where("tbl_master_facility.site_type", $id) + ->where("tbl_partner_facility.county_id", '=', Auth::user()->county_id) + ->orderBy('tbl_master_facility.name', 'ASC') + ->pluck("tbl_master_facility.name", "tbl_master_facility.code"); + } + if (Auth::user()->access_level == 'Sub County') { + $facilities = PartnerFacility::join('tbl_master_facility', 'tbl_partner_facility.mfl_code', '=', 'tbl_master_facility.code') + ->where("tbl_master_facility.site_type", $id) + ->where("tbl_partner_facility.sub_county_id", '=', Auth::user()->subcounty_id) + ->orderBy('tbl_master_facility.name', 'ASC') + ->pluck("tbl_master_facility.name", "tbl_master_facility.code"); + } return json_encode($facilities); } - - } diff --git a/app/Http/Controllers/NewReportController.php b/app/Http/Controllers/NewReportController.php index 100518c..8d2b035 100644 --- a/app/Http/Controllers/NewReportController.php +++ b/app/Http/Controllers/NewReportController.php @@ -390,7 +390,7 @@ public function client_message(Request $request) $selected_to = $request->date_to; if (Auth::user()->access_level == 'Admin' || Auth::user()->access_level == 'Donor') { $client_messages = Appointments::join('tbl_client', 'tbl_appointment.client_id', 'tbl_client.id') - ->join('tbl_clnt_outgoing', 'tbl_client.id', 'tbl_clnt_outgoing.clnt_usr_id') + ->join('tbl_clnt_outgoing', 'tbl_appointment.id', 'tbl_clnt_outgoing.appointment_id') ->join('tbl_gender', 'tbl_client.gender', 'tbl_gender.id') ->join('tbl_language', 'tbl_client.language_id', 'tbl_language.id') ->join('tbl_appointment_types', 'tbl_appointment.app_type_1', 'tbl_appointment_types.id') @@ -421,13 +421,13 @@ public function client_message(Request $request) 'tbl_sub_county.name as subcounty' ) ->where('tbl_client.status', '=', 'Active') - ->where('tbl_clnt_outgoing.created_at', '>=', date($request->date_from)) - ->where('tbl_clnt_outgoing.created_at', '<=', date($request->date_to)) + ->where('tbl_appointment.appntmnt_date', '>=', date($request->date_from)) + ->where('tbl_appointment.appntmnt_date', '<=', date($request->date_to)) ->get(); } if (Auth::user()->access_level == 'Partner') { $client_messages = Appointments::join('tbl_client', 'tbl_appointment.client_id', 'tbl_client.id') - ->join('tbl_clnt_outgoing', 'tbl_client.id', 'tbl_clnt_outgoing.clnt_usr_id') + ->join('tbl_clnt_outgoing', 'tbl_appointment.id', 'tbl_clnt_outgoing.appointment_id') ->join('tbl_gender', 'tbl_client.gender', 'tbl_gender.id') ->join('tbl_language', 'tbl_client.language_id', 'tbl_language.id') ->join('tbl_appointment_types', 'tbl_appointment.app_type_1', 'tbl_appointment_types.id') @@ -458,14 +458,14 @@ public function client_message(Request $request) 'tbl_sub_county.name as subcounty' ) ->where('tbl_client.status', '=', 'Active') - ->where('tbl_clnt_outgoing.created_at', '>=', date($request->date_from)) - ->where('tbl_clnt_outgoing.created_at', '<=', date($request->date_to)) + ->where('tbl_appointment.appntmnt_date', '>=', date($request->date_from)) + ->where('tbl_appointment.appntmnt_date', '<=', date($request->date_to)) ->where('tbl_partner_facility.partner_id', Auth::user()->partner_id) ->get(); } if (Auth::user()->access_level == 'Facility') { $client_messages = Appointments::join('tbl_client', 'tbl_appointment.client_id', 'tbl_client.id') - ->join('tbl_clnt_outgoing', 'tbl_client.id', 'tbl_clnt_outgoing.clnt_usr_id') + ->join('tbl_clnt_outgoing', 'tbl_appointment.id', 'tbl_clnt_outgoing.appointment_id') ->join('tbl_gender', 'tbl_client.gender', 'tbl_gender.id') ->join('tbl_language', 'tbl_client.language_id', 'tbl_language.id') ->join('tbl_appointment_types', 'tbl_appointment.app_type_1', 'tbl_appointment_types.id') @@ -496,8 +496,8 @@ public function client_message(Request $request) 'tbl_sub_county.name as subcounty' ) ->where('tbl_client.status', '=', 'Active') - ->where('tbl_clnt_outgoing.created_at', '>=', date($request->date_from)) - ->where('tbl_clnt_outgoing.created_at', '<=', date($request->date_to)) + ->whereDate('tbl_appointment.appntmnt_date', '>=', date($request->date_from)) + ->whereDate('tbl_appointment.appntmnt_date', '<=', date($request->date_to)) ->where('tbl_partner_facility.mfl_code', Auth::user()->facility_id) ->get(); } diff --git a/resources/views/dashboard/appointment.blade.php b/resources/views/dashboard/appointment.blade.php index d1355c7..90fb6ef 100644 --- a/resources/views/dashboard/appointment.blade.php +++ b/resources/views/dashboard/appointment.blade.php @@ -157,7 +157,7 @@
    -
    +
    -
    +
    -
    +
    -
    +
    -
    +
    - -
    - -
    - + + {{ csrf_field() }} +
    + + +
    + +
    + +
    -
    -
    -
    - -
    - +
    +
    + +
    + +
    -
    - + -
    -
    - +
    + -
    - ushauri - ushauri - ushauri -
    - -
    -
    + Login +
    +
    + ushauri + ushauri + ushauri +
    +
    +
    +
    +
    - + - + - - - - + + + + - + \ No newline at end of file + $(".password").keyup(function() { + var password = $("#new_password").val(); + var password2 = $("#confirm_new_password").val(); + if (password == password2) { + $(".btn_div").show(); + } else { + $(".btn_div").hide(); + } + }); + \ No newline at end of file From d89dd15ca660cc0ab8fa9e3435e842d117dc64da Mon Sep 17 00:00:00 2001 From: Ronald-pro <36841157+Ronald-pro@users.noreply.github.com> Date: Wed, 22 Feb 2023 12:01:17 +0300 Subject: [PATCH 157/171] added sms status on appointment calender list --- app/Http/Controllers/CalendarController.php | 9 +- app/Http/Controllers/PmtcController.php | 8 ++ resources/views/pmtct/new_pmtct.blade.php | 102 ++++++++++++++++++ .../views/reports/cal_appointments.blade.php | 8 +- 4 files changed, 123 insertions(+), 4 deletions(-) create mode 100644 resources/views/pmtct/new_pmtct.blade.php diff --git a/app/Http/Controllers/CalendarController.php b/app/Http/Controllers/CalendarController.php index c9aafda..dc2e3db 100644 --- a/app/Http/Controllers/CalendarController.php +++ b/app/Http/Controllers/CalendarController.php @@ -235,13 +235,16 @@ public function current_appointments($slug, $id) $not_honored_app = $row->app_status; } - $query = DB::table('tbl_client') - ->join('tbl_appointment', 'tbl_client.id', '=', 'tbl_appointment.client_id') + $query = DB::table('tbl_appointment') + ->join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') ->join('tbl_appointment_types', 'tbl_appointment.app_type_1', '=', 'tbl_appointment_types.id') ->join('tbl_clinic', 'tbl_client.clinic_id', '=', 'tbl_clinic.id') - ->select('tbl_client.file_no', 'tbl_appointment.id as appointment_id', 'tbl_appointment.date_attended', 'tbl_appointment.visit_type', 'tbl_client.f_name', 'tbl_client.m_name', 'tbl_client.l_name', 'tbl_client.phone_no', 'tbl_client.status', 'tbl_client.clinic_number', 'tbl_client.id as client_id', 'tbl_appointment.app_status', 'tbl_appointment.appntmnt_date', 'tbl_appointment.app_type_1', 'tbl_appointment_types.id as appointment_types_id', 'tbl_appointment_types.name as appointment_types', 'tbl_clinic.name as clinic') + ->join('tbl_clnt_outgoing', 'tbl_appointment.id', '=', 'tbl_clnt_outgoing.appointment_id') + ->select('tbl_client.file_no', 'tbl_appointment.id as appointment_id', 'tbl_appointment.date_attended', 'tbl_appointment.visit_type', 'tbl_client.f_name', 'tbl_client.m_name', 'tbl_client.l_name', 'tbl_client.phone_no', 'tbl_client.status', 'tbl_client.clinic_number', 'tbl_client.id as client_id', 'tbl_appointment.app_status', 'tbl_appointment.appntmnt_date', 'tbl_appointment.app_type_1', 'tbl_appointment_types.id as appointment_types_id', 'tbl_appointment_types.name as appointment_types', 'tbl_clinic.name as clinic', + 'tbl_clnt_outgoing.status', 'tbl_clnt_outgoing.callback_status', 'tbl_clnt_outgoing.failure_reason', 'tbl_client.smsenable') ->where('tbl_client.status', 'Active') ->where('tbl_client.mfl_code', Auth::user()->facility_id) + ->groupBy('tbl_client.id') ->where('tbl_appointment.appntmnt_date', $app_date); if ($slug == 'id') { diff --git a/app/Http/Controllers/PmtcController.php b/app/Http/Controllers/PmtcController.php index 0785fb7..a99fd08 100644 --- a/app/Http/Controllers/PmtcController.php +++ b/app/Http/Controllers/PmtcController.php @@ -4116,4 +4116,12 @@ public function filter_hei_dashboard(Request $request) return $data; } + + public function pmtct_enrollment() + { + $pmtct_anc = DB::table('tbl_pmtct_anc')->join('tbl_client', 'tbl_pmtct_anc.client_id','=', 'tbl_client.id') + ->select('tbl_client.f_name', 'tbl_client.l_name', 'tbl_client.clinic_number', 'tbl_pmtct_anc.visit_number') + ->get(); + + } } diff --git a/resources/views/pmtct/new_pmtct.blade.php b/resources/views/pmtct/new_pmtct.blade.php new file mode 100644 index 0000000..5089891 --- /dev/null +++ b/resources/views/pmtct/new_pmtct.blade.php @@ -0,0 +1,102 @@ +@extends('layouts.master') +@section('page-css') + + +@endsection + +@section('main-content') + + +
    +
    + +
    +

    New PMTCT Listing

    +

    Showing

    + +
    + + + + + + + + + + + + + + + + + +
    No.Clinic NumberClient Name
    {{ $loop->iteration }}
    + +
    + +
    +
    +
    + + +@endsection + +@section('page-js') + + + + + +@endsection \ No newline at end of file diff --git a/resources/views/reports/cal_appointments.blade.php b/resources/views/reports/cal_appointments.blade.php index 2a0ad68..043c110 100644 --- a/resources/views/reports/cal_appointments.blade.php +++ b/resources/views/reports/cal_appointments.blade.php @@ -66,7 +66,7 @@ @if(empty($results->appointment_types)) Appointments Summary - For ALL @else -

    Appointments Summary - For {{ $results->appointment_types}}

    +

    Appointments Summary

    @endif @@ -91,9 +91,12 @@ File No Client Name Phone No + Consented Appointment Date Appointment Type Appointment Status + Message Status + Failure Reason Clinic Action @@ -108,6 +111,7 @@ {{$row->file_no}} {{$row->f_name.' '.$row->m_name.' '.$row->l_name}} {{$row->phone_no}} + {{$row->smsenable}} {{$row->appntmnt_date}} {{$row->appointment_types}} @if($row->app_status == 'Notified') @@ -117,6 +121,8 @@ @else {{$row->app_status}} @endif + {{$row->callback_status}} + {{$row->failure_reason}} {{$row->clinic}} From 3fc679e1c0f5d2d9525735e12b042255d2ede9b1 Mon Sep 17 00:00:00 2001 From: Ronald-pro <36841157+Ronald-pro@users.noreply.github.com> Date: Thu, 23 Feb 2023 12:04:57 +0300 Subject: [PATCH 158/171] added sms status on appointment calender list --- resources/views/reports/cal_appointments.blade.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/resources/views/reports/cal_appointments.blade.php b/resources/views/reports/cal_appointments.blade.php index 043c110..1644f75 100644 --- a/resources/views/reports/cal_appointments.blade.php +++ b/resources/views/reports/cal_appointments.blade.php @@ -66,7 +66,7 @@ @if(empty($results->appointment_types)) Appointments Summary - For ALL @else -

    Appointments Summary

    +

    Appointments Summary

    @endif From 17ce5b2ead64fd075313785a0e9c44ed96c9130c Mon Sep 17 00:00:00 2001 From: Ronald-pro <36841157+Ronald-pro@users.noreply.github.com> Date: Thu, 23 Feb 2023 12:46:34 +0300 Subject: [PATCH 159/171] fixed error on app calendar --- app/Http/Controllers/CalendarController.php | 11 +++++------ resources/views/reports/cal_appointments.blade.php | 9 ++++----- 2 files changed, 9 insertions(+), 11 deletions(-) diff --git a/app/Http/Controllers/CalendarController.php b/app/Http/Controllers/CalendarController.php index dc2e3db..1e4aa78 100644 --- a/app/Http/Controllers/CalendarController.php +++ b/app/Http/Controllers/CalendarController.php @@ -235,16 +235,15 @@ public function current_appointments($slug, $id) $not_honored_app = $row->app_status; } - $query = DB::table('tbl_appointment') - ->join('tbl_client', 'tbl_appointment.client_id', '=', 'tbl_client.id') + $query = DB::table('tbl_client') + ->join('tbl_appointment', 'tbl_client.id', '=', 'tbl_appointment.client_id') ->join('tbl_appointment_types', 'tbl_appointment.app_type_1', '=', 'tbl_appointment_types.id') ->join('tbl_clinic', 'tbl_client.clinic_id', '=', 'tbl_clinic.id') - ->join('tbl_clnt_outgoing', 'tbl_appointment.id', '=', 'tbl_clnt_outgoing.appointment_id') - ->select('tbl_client.file_no', 'tbl_appointment.id as appointment_id', 'tbl_appointment.date_attended', 'tbl_appointment.visit_type', 'tbl_client.f_name', 'tbl_client.m_name', 'tbl_client.l_name', 'tbl_client.phone_no', 'tbl_client.status', 'tbl_client.clinic_number', 'tbl_client.id as client_id', 'tbl_appointment.app_status', 'tbl_appointment.appntmnt_date', 'tbl_appointment.app_type_1', 'tbl_appointment_types.id as appointment_types_id', 'tbl_appointment_types.name as appointment_types', 'tbl_clinic.name as clinic', - 'tbl_clnt_outgoing.status', 'tbl_clnt_outgoing.callback_status', 'tbl_clnt_outgoing.failure_reason', 'tbl_client.smsenable') + ->leftJoin('tbl_clnt_outgoing', 'tbl_appointment.id', '=', 'tbl_clnt_outgoing.appointment_id') + ->select('tbl_client.file_no', 'tbl_client.smsenable', 'tbl_appointment.id as appointment_id', 'tbl_appointment.date_attended', 'tbl_appointment.visit_type', 'tbl_client.f_name', 'tbl_client.m_name', 'tbl_client.l_name', 'tbl_client.phone_no', 'tbl_client.status', 'tbl_client.clinic_number', 'tbl_client.id as client_id', 'tbl_appointment.app_status', 'tbl_appointment.appntmnt_date', 'tbl_appointment.app_type_1', 'tbl_appointment_types.id as appointment_types_id', 'tbl_appointment_types.name as appointment_types', 'tbl_clinic.name as clinic', + 'tbl_clnt_outgoing.status', 'tbl_clnt_outgoing.callback_status', 'tbl_clnt_outgoing.failure_reason') ->where('tbl_client.status', 'Active') ->where('tbl_client.mfl_code', Auth::user()->facility_id) - ->groupBy('tbl_client.id') ->where('tbl_appointment.appntmnt_date', $app_date); if ($slug == 'id') { diff --git a/resources/views/reports/cal_appointments.blade.php b/resources/views/reports/cal_appointments.blade.php index 1644f75..289846e 100644 --- a/resources/views/reports/cal_appointments.blade.php +++ b/resources/views/reports/cal_appointments.blade.php @@ -1,3 +1,4 @@ + @extends('layouts.master') @section('page-css') @@ -62,14 +63,12 @@ {{ $sum_defaulted}} {{ $sum_ltfu}} + - @if(empty($results->appointment_types)) - Appointments Summary - For ALL - @else

    Appointments Summary

    - @endif +
    @@ -191,4 +190,4 @@ -@endsection \ No newline at end of file +@endsection From 4e0d6fbd87b3395d27b714c70c8830e9c28cff95 Mon Sep 17 00:00:00 2001 From: Ronald-pro <36841157+Ronald-pro@users.noreply.github.com> Date: Thu, 23 Feb 2023 13:04:38 +0300 Subject: [PATCH 160/171] commented auth error --- .../large-vertical-sidebar/header.blade.php | 82 +++++++++---------- 1 file changed, 41 insertions(+), 41 deletions(-) diff --git a/resources/views/layouts/large-vertical-sidebar/header.blade.php b/resources/views/layouts/large-vertical-sidebar/header.blade.php index ca29713..07a6c7c 100644 --- a/resources/views/layouts/large-vertical-sidebar/header.blade.php +++ b/resources/views/layouts/large-vertical-sidebar/header.blade.php @@ -80,46 +80,46 @@
    \ No newline at end of file From df644d6a07776ef0e9ac5ef330d787777e7f3e22 Mon Sep 17 00:00:00 2001 From: Ronald-pro <36841157+Ronald-pro@users.noreply.github.com> Date: Wed, 1 Mar 2023 09:08:44 +0300 Subject: [PATCH 161/171] refactored migration controller --- app/Http/Controllers/MigrationController.php | 5 ++-- .../views/dashboard/appointment.blade.php | 23 ++++++++++++++++--- 2 files changed, 23 insertions(+), 5 deletions(-) diff --git a/app/Http/Controllers/MigrationController.php b/app/Http/Controllers/MigrationController.php index 12e83b0..4aef2e5 100644 --- a/app/Http/Controllers/MigrationController.php +++ b/app/Http/Controllers/MigrationController.php @@ -3,18 +3,19 @@ namespace App\Http\Controllers; use Illuminate\Http\Request; +use Illuminate\Support\Facades\Schema; use DB; class MigrationController extends Controller { public function pull_todays_appointments() { - $drop_table = DB::statement('DROP TABLE tbl_todays_appointment'); + $drop_table = Schema::dropIfExists('tbl_todays_appointment'); $create_table_with_data = DB::statement('CREATE TABLE tbl_todays_appointment AS SELECT * FROM todays_appointments'); } public function pull_past_appointment_new() { - $drop_table = DB::statement('DROP TABLE tbl_past_appointment_new'); + $drop_table = Schema::dropIfExists('tbl_past_appointment_new'); $create_table_with_data = DB::statement('CREATE TABLE tbl_past_appointment_new AS SELECT * FROM past_appointments_view'); } public function sync_tracing_outcome() diff --git a/resources/views/dashboard/appointment.blade.php b/resources/views/dashboard/appointment.blade.php index 90fb6ef..3238447 100644 --- a/resources/views/dashboard/appointment.blade.php +++ b/resources/views/dashboard/appointment.blade.php @@ -1518,7 +1518,7 @@ { extend: 'pdf', title: 'Clients List', - filename: 'Adults List' + filename: 'Clients List' }, { extend: 'print', @@ -1856,7 +1856,8 @@ const consent = data.consented_clients; const apps = data.all_appoinments; const tx = data.all_tx_curr; - console.log(tx); + const client_app = data.client_app_list; + console.log(client_app); const missed = data.client_missed; appGender(data.appointment_gender); appAge(data.appointment_age); @@ -1866,7 +1867,23 @@ missedGender(data.missed_gender); missedMarital(data.missed_marital); if (authenticated == 'Facility') { - + // $('#table_client')[0].reset(); + // $("tbody").html(""); + // $.each(data.client_app_list, function(index, value) { + // var row = $("" + + // value.upi_no + "" + + // value.ccc_number + "" + + // value.dob + "" + + // value.phone_no + "" + + // value.consented + "" + + // value.dsd_status + "" + + // value.client_status + "" + + // value.kept_app + "" + + // value.not_kept_app + ""); + + // $("tbody").append(row); + // }); + // $("#table_client").html(data.client_app_list); } if (authenticated == 'Admin' || authenticated == 'Donor') { appCounty(data.appointment_county); From 189fa9cd2e5f75b294176de01131aa2704b4f64e Mon Sep 17 00:00:00 2001 From: Ronald-pro <36841157+Ronald-pro@users.noreply.github.com> Date: Wed, 1 Mar 2023 14:42:58 +0300 Subject: [PATCH 162/171] fixed future apps showing honored on the calendar --- resources/views/reports/cal_appointments.blade.php | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/resources/views/reports/cal_appointments.blade.php b/resources/views/reports/cal_appointments.blade.php index 289846e..c6f435c 100644 --- a/resources/views/reports/cal_appointments.blade.php +++ b/resources/views/reports/cal_appointments.blade.php @@ -49,7 +49,11 @@ app_status, 'Missed') ?> app_status, 'LTFU') ?> visit_type, 'Un-Scheduled') ?> + @if($results->app_status == 'Notified' && $results->appntmnt_date > date("Y-m-d")) + app_status, 'Notified') ?> + @elseif($results->app_status == 'Notified' && $results->appntmnt_date < date("Y-m-d")) app_status, 'Notified') ?> + @endif app_status, 'Booked') ?> @endforeach @@ -90,10 +94,10 @@ File No Client Name Phone No - Consented Appointment Date Appointment Type Appointment Status + Consented Message Status Failure Reason Clinic @@ -110,16 +114,18 @@ {{$row->file_no}} {{$row->f_name.' '.$row->m_name.' '.$row->l_name}} {{$row->phone_no}} - {{$row->smsenable}} {{$row->appntmnt_date}} {{$row->appointment_types}} - @if($row->app_status == 'Notified') + @if($row->app_status == 'Notified' && $row->appntmnt_date > date("Y-m-d")) + Booked + @elseif($row->app_status == 'Notified' && $row->appntmnt_date < date("Y-m-d")) Honored @elseif($row->app_status == 'LTFU') IIT @else {{$row->app_status}} @endif + {{$row->smsenable}} {{$row->callback_status}} {{$row->failure_reason}} {{$row->clinic}} From bbf02e82d57fa230476ac7c0de4a34d7376ea578 Mon Sep 17 00:00:00 2001 From: Ronald-pro <36841157+Ronald-pro@users.noreply.github.com> Date: Mon, 6 Mar 2023 21:54:28 +0300 Subject: [PATCH 163/171] updated appointment on distinct client_id --- .../Controllers/FinalDashboardController.php | 618 +++++++++--------- .../views/dashboard/appointment.blade.php | 347 +++++----- 2 files changed, 484 insertions(+), 481 deletions(-) diff --git a/app/Http/Controllers/FinalDashboardController.php b/app/Http/Controllers/FinalDashboardController.php index b2cfc40..83fb5cc 100644 --- a/app/Http/Controllers/FinalDashboardController.php +++ b/app/Http/Controllers/FinalDashboardController.php @@ -230,30 +230,31 @@ public function appointment() ->where('mfl_code', Auth::user()->facility_id) ->groupBy('facility'); // missed appointment - $client_missed = DB::table('etl_appointment_detail')->select( - DB::raw('SUM(app_not_kept) AS not_kept_app '), - DB::raw('SUM(CASE WHEN appointment_status = "Missed" OR appointment_status = "Defaulted" OR appointment_status = "IIT" THEN received_sms END) AS messages '), - DB::raw('SUM(CASE WHEN received_sms = 1 AND appointment_status = "Missed" THEN 1 ELSE 0 END) AS missed_messages '), - DB::raw('SUM(CASE WHEN received_sms = 1 AND appointment_status = "Defaulted" THEN 1 ELSE 0 END) AS defaulted_messages '), - DB::raw('SUM(CASE WHEN received_sms = 1 AND appointment_status = "IIT" THEN 1 ELSE 0 END) AS iit_messages '), - DB::raw('SUM(CASE WHEN appointment_status = "Missed" OR appointment_status = "Defaulted" OR appointment_status = "IIT" THEN called END) AS called '), - DB::raw('SUM(CASE WHEN called = 1 AND appointment_status = "Missed" THEN 1 ELSE 0 END) AS missed_called '), - DB::raw('SUM(CASE WHEN called = 1 AND appointment_status = "Defaulted" THEN 1 ELSE 0 END) AS defaulted_called '), - DB::raw('SUM(CASE WHEN called = 1 AND appointment_status = "IIT" THEN 1 ELSE 0 END) AS iit_called '), - DB::raw('SUM(CASE WHEN appointment_status = "Missed" OR appointment_status = "Defaulted" OR appointment_status = "IIT" THEN physically_traced END) AS physically_traced '), - DB::raw('SUM(CASE WHEN physically_traced = 1 AND appointment_status = "Missed" THEN 1 ELSE 0 END) AS missed_traced '), - DB::raw('SUM(CASE WHEN physically_traced = 1 AND appointment_status = "Defaulted" THEN 1 ELSE 0 END) AS defaulted_traced '), - DB::raw('SUM(CASE WHEN physically_traced = 1 AND appointment_status = "IIT" THEN 1 ELSE 0 END) AS iit_traced '), - DB::raw('SUM(CASE WHEN appointment_status = "Missed" OR appointment_status = "Defaulted" OR appointment_status = "IIT" THEN rtc_no END) AS final_outcome'), - DB::raw('SUM(CASE WHEN final_outcome = "Client returned to care" AND appointment_status = "Missed" THEN 1 ELSE 0 END) AS missed_outcome '), - DB::raw('SUM(CASE WHEN final_outcome = "Client returned to care" AND appointment_status = "Defaulted" THEN 1 ELSE 0 END) AS defaulted_outcome '), - DB::raw('SUM(CASE WHEN final_outcome = "Client returned to care" AND appointment_status = "IIT" THEN 1 ELSE 0 END) AS iit_outcome '), - DB::raw('SUM(CASE WHEN appointment_status = "Missed" OR appointment_status = "Defaulted" OR appointment_status = "IIT" THEN consent_no END) AS consent '), - DB::raw('SUM(CASE WHEN consent = "Yes" AND appointment_status = "Missed" THEN 1 ELSE 0 END) AS missed_consent '), - DB::raw('SUM(CASE WHEN consent = "Yes" AND appointment_status = "Defaulted" THEN 1 ELSE 0 END) AS defaulted_consent '), - DB::raw('SUM(CASE WHEN consent = "Yes" AND appointment_status = "IIT" THEN 1 ELSE 0 END) AS iit_consent ') + $client_missed = DB::table('etl_appointment_detail')->selectRaw(' + SUM(CASE WHEN app_not_kept = 1 THEN 1 ELSE 0 END) AS not_kept_app, + SUM(CASE WHEN appointment_status = "Missed" OR appointment_status = "Defaulted" OR appointment_status = "IIT" THEN received_sms END) AS messages, + SUM(CASE WHEN received_sms = 1 AND appointment_status = "Missed" THEN 1 ELSE 0 END) AS missed_messages, + SUM(CASE WHEN received_sms = 1 AND appointment_status = "Defaulted" THEN 1 ELSE 0 END) AS defaulted_messages, + SUM(CASE WHEN received_sms = 1 AND appointment_status = "IIT" THEN 1 ELSE 0 END) AS iit_messages, + SUM(CASE WHEN appointment_status = "Missed" OR appointment_status = "Defaulted" OR appointment_status = "IIT" THEN called END) AS called, + SUM(CASE WHEN called = 1 AND appointment_status = "Missed" THEN 1 ELSE 0 END) AS missed_called, + SUM(CASE WHEN called = 1 AND appointment_status = "Defaulted" THEN 1 ELSE 0 END) AS defaulted_called, + SUM(CASE WHEN called = 1 AND appointment_status = "IIT" THEN 1 ELSE 0 END) AS iit_called, + SUM(CASE WHEN appointment_status = "Missed" OR appointment_status = "Defaulted" OR appointment_status = "IIT" THEN physically_traced END) AS physically_traced, + SUM(CASE WHEN physically_traced = 1 AND appointment_status = "Missed" THEN 1 ELSE 0 END) AS missed_traced, + SUM(CASE WHEN physically_traced = 1 AND appointment_status = "Defaulted" THEN 1 ELSE 0 END) AS defaulted_traced, + SUM(CASE WHEN physically_traced = 1 AND appointment_status = "IIT" THEN 1 ELSE 0 END) AS iit_traced, + SUM(CASE WHEN appointment_status = "Missed" OR appointment_status = "Defaulted" OR appointment_status = "IIT" THEN rtc_no END) AS final_outcome, + SUM(CASE WHEN final_outcome = "Client returned to care" AND appointment_status = "Missed" THEN 1 ELSE 0 END) AS missed_outcome, + SUM(CASE WHEN final_outcome = "Client returned to care" AND appointment_status = "Defaulted" THEN 1 ELSE 0 END) AS defaulted_outcome, + SUM(CASE WHEN final_outcome = "Client returned to care" AND appointment_status = "IIT" THEN 1 ELSE 0 END) AS iit_outcome, + SUM(CASE WHEN appointment_status = "Missed" OR appointment_status = "Defaulted" OR appointment_status = "IIT" THEN consent_no END) AS consent, + SUM(CASE WHEN consent = "Yes" AND appointment_status = "Missed" THEN 1 ELSE 0 END) AS missed_consent, + SUM(CASE WHEN consent = "Yes" AND appointment_status = "Defaulted" THEN 1 ELSE 0 END) AS defaulted_consent, + SUM(CASE WHEN consent = "Yes" AND appointment_status = "IIT" THEN 1 ELSE 0 END) AS iit_consent ' ) - ->where('mfl_code', Auth::user()->facility_id); + ->where('mfl_code', Auth::user()->facility_id) + ->groupBy('client_id'); $missed_age = DB::table('etl_appointment_detail')->select( 'age_group', @@ -364,68 +365,68 @@ public function appointment() $data = []; - $all_appoinments = ETLAppointment::select( - DB::raw('(SUM(app_kept)+SUM(app_not_kept)+SUM(future)) as total_app'), - DB::raw('SUM(app_kept) AS kept_app '), - DB::raw('SUM(app_not_kept) AS not_kept_app '), - DB::raw('SUM(future) AS future '), - DB::raw('SUM(received_sms) AS messages '), - DB::raw('AVG(percent_kept) AS percent_kept '), - DB::raw('AVG(percent_not_kept) AS percent_not_kept '), - DB::raw('AVG(percent_future) AS percent_future ') + $all_appoinments = ETLAppointment::selectRaw(' + (SUM(app_kept)+SUM(app_not_kept)+SUM(future)) as total_app, + SUM(app_kept) AS kept_app, + SUM(app_not_kept) AS not_kept_app, + SUM(future) AS future, + SUM(received_sms) AS messages, + AVG(percent_kept) AS percent_kept, + AVG(percent_not_kept) AS percent_not_kept, + AVG(percent_future) AS percent_future ' ); - $consented_clients = ETLClient::select( - DB::raw('SUM(CASE WHEN consented = "Yes" THEN 1 ELSE 0 END) AS consented '), - DB::raw('AVG(percent_consented) AS percent_consented ') + $consented_clients = ETLClient::selectRaw( + 'SUM(CASE WHEN consented = "Yes" THEN 1 ELSE 0 END) AS consented, + AVG(percent_consented) AS percent_consented ' ); $all_tx_curr = Txcurr::select(DB::raw('SUM(tbl_tx_cur.tx_cur) as tx_cur')) ->join('tbl_partner_facility', 'tbl_tx_cur.mfl_code', '=', 'tbl_partner_facility.mfl_code'); - $appointment_gender = ETLAppointment::select( - 'gender', - DB::raw('SUM(app_kept) AS kept_app '), - DB::raw('SUM(app_not_kept) AS not_kept_app '), - DB::raw('ROUND(AVG(percent_kept),1) AS percent_kept '), - DB::raw('ROUND(AVG(percent_not_kept),1) AS percent_not_kept ') + $appointment_gender = ETLAppointment::selectRaw( + 'gender, + SUM(app_kept) AS kept_app, + SUM(app_not_kept) AS not_kept_app, + ROUND(AVG(percent_kept),1) AS percent_kept, + ROUND(AVG(percent_not_kept),1) AS percent_not_kept ' ) ->whereNotNull('gender') ->orderBy('percent_kept', 'DESC') ->groupBy('gender'); - $appointment_age = ETLAppointment::select( - 'age_group', - DB::raw('SUM(app_kept) AS kept_app '), - DB::raw('SUM(app_not_kept) AS not_kept_app '), - DB::raw('ROUND(AVG(percent_kept),1) AS percent_kept '), - DB::raw('ROUND(AVG(percent_not_kept),1) AS percent_not_kept ') + $appointment_age = ETLAppointment::selectRaw( + 'age_group, + SUM(app_kept) AS kept_app, + SUM(app_not_kept) AS not_kept_app, + ROUND(AVG(percent_kept),1) AS percent_kept, + ROUND(AVG(percent_not_kept),1) AS percent_not_kept ' ) ->whereNotNull('age_group') ->groupBy('age_group'); - $appointment_marital = ETLAppointment::select( - 'marital', - DB::raw('SUM(app_kept) AS kept_app '), - DB::raw('SUM(app_not_kept) AS not_kept_app '), - DB::raw('ROUND(AVG(percent_kept),1) AS percent_kept '), - DB::raw('ROUND(AVG(percent_not_kept),1) AS percent_not_kept ') + $appointment_marital = ETLAppointment::selectRaw( + 'marital, + SUM(app_kept) AS kept_app, + SUM(app_not_kept) AS not_kept_app, + ROUND(AVG(percent_kept),1) AS percent_kept, + ROUND(AVG(percent_not_kept),1) AS percent_not_kept ' ) ->whereNotNull('marital') ->orderBy('percent_kept', 'DESC') ->groupBy('marital'); - $appointment_county = ETLAppointment::select( - 'county', - DB::raw('SUM(app_kept) AS kept_app '), - DB::raw('SUM(app_not_kept) AS not_kept_app '), - DB::raw('ROUND(AVG(percent_kept),1) AS percent_kept '), - DB::raw('ROUND(AVG(percent_not_kept),1) AS percent_not_kept ') + $appointment_county = ETLAppointment::selectRaw( + 'county, + SUM(app_kept) AS kept_app, + SUM(app_not_kept) AS not_kept_app, + ROUND(AVG(percent_kept),1) AS percent_kept, + ROUND(AVG(percent_not_kept),1) AS percent_not_kept ' ) ->whereNotNull('county') ->orderBy('percent_kept', 'DESC') ->groupBy('county'); - $appointment_partner = ETLAppointment::select( - 'partner', - DB::raw('SUM(app_kept) AS kept_app '), - DB::raw('SUM(app_not_kept) AS not_kept_app '), - DB::raw('ROUND(AVG(percent_kept),1) AS percent_kept '), - DB::raw('ROUND(AVG(percent_not_kept),1) AS percent_not_kept ') + $appointment_partner = ETLAppointment::selectRaw( + 'partner, + SUM(app_kept) AS kept_app, + SUM(app_not_kept) AS not_kept_app, + ROUND(AVG(percent_kept),1) AS percent_kept, + ROUND(AVG(percent_not_kept),1) AS percent_not_kept ' ) ->whereNotNull('partner') ->orderBy('percent_kept', 'DESC') @@ -433,84 +434,84 @@ public function appointment() // missed appointment - $client_missed = DB::table('etl_appointment_detail')->select( - DB::raw('SUM(app_not_kept) AS not_kept_app '), - DB::raw('SUM(CASE WHEN appointment_status = "Missed" OR appointment_status = "Defaulted" OR appointment_status = "IIT" THEN received_sms END) AS messages '), - DB::raw('SUM(CASE WHEN received_sms = 1 AND appointment_status = "Missed" THEN 1 ELSE 0 END) AS missed_messages '), - DB::raw('SUM(CASE WHEN received_sms = 1 AND appointment_status = "Defaulted" THEN 1 ELSE 0 END) AS defaulted_messages '), - DB::raw('SUM(CASE WHEN received_sms = 1 AND appointment_status = "IIT" THEN 1 ELSE 0 END) AS iit_messages '), - DB::raw('SUM(CASE WHEN appointment_status = "Missed" OR appointment_status = "Defaulted" OR appointment_status = "IIT" THEN called END) AS called '), - DB::raw('SUM(CASE WHEN called = 1 AND appointment_status = "Missed" THEN 1 ELSE 0 END) AS missed_called '), - DB::raw('SUM(CASE WHEN called = 1 AND appointment_status = "Defaulted" THEN 1 ELSE 0 END) AS defaulted_called '), - DB::raw('SUM(CASE WHEN called = 1 AND appointment_status = "IIT" THEN 1 ELSE 0 END) AS iit_called '), - DB::raw('SUM(CASE WHEN appointment_status = "Missed" OR appointment_status = "Defaulted" OR appointment_status = "IIT" THEN physically_traced END) AS physically_traced '), - DB::raw('SUM(CASE WHEN physically_traced = 1 AND appointment_status = "Missed" THEN 1 ELSE 0 END) AS missed_traced '), - DB::raw('SUM(CASE WHEN physically_traced = 1 AND appointment_status = "Defaulted" THEN 1 ELSE 0 END) AS defaulted_traced '), - DB::raw('SUM(CASE WHEN physically_traced = 1 AND appointment_status = "IIT" THEN 1 ELSE 0 END) AS iit_traced '), - DB::raw('SUM(CASE WHEN appointment_status = "Missed" OR appointment_status = "Defaulted" OR appointment_status = "IIT" THEN rtc_no END) AS final_outcome'), - DB::raw('SUM(CASE WHEN final_outcome = "Client returned to care" AND appointment_status = "Missed" THEN 1 ELSE 0 END) AS missed_outcome '), - DB::raw('SUM(CASE WHEN final_outcome = "Client returned to care" AND appointment_status = "Defaulted" THEN 1 ELSE 0 END) AS defaulted_outcome '), - DB::raw('SUM(CASE WHEN final_outcome = "Client returned to care" AND appointment_status = "IIT" THEN 1 ELSE 0 END) AS iit_outcome '), - DB::raw('SUM(CASE WHEN appointment_status = "Missed" OR appointment_status = "Defaulted" OR appointment_status = "IIT" THEN consent_no END) AS consent '), - DB::raw('SUM(CASE WHEN consent = "Yes" AND appointment_status = "Missed" THEN 1 ELSE 0 END) AS missed_consent '), - DB::raw('SUM(CASE WHEN consent = "Yes" AND appointment_status = "Defaulted" THEN 1 ELSE 0 END) AS defaulted_consent '), - DB::raw('SUM(CASE WHEN consent = "Yes" AND appointment_status = "IIT" THEN 1 ELSE 0 END) AS iit_consent ') + $client_missed = DB::table('etl_appointment_detail')->groupBy('client_id')->selectRaw(' + SUM(CASE WHEN app_not_kept = 1 THEN 1 ELSE 0 END) AS not_kept_app, + SUM(CASE WHEN appointment_status = "Missed" OR appointment_status = "Defaulted" OR appointment_status = "IIT" THEN received_sms END) AS messages, + SUM(CASE WHEN received_sms = 1 AND appointment_status = "Missed" THEN 1 ELSE 0 END) AS missed_messages, + SUM(CASE WHEN received_sms = 1 AND appointment_status = "Defaulted" THEN 1 ELSE 0 END) AS defaulted_messages, + SUM(CASE WHEN received_sms = 1 AND appointment_status = "IIT" THEN 1 ELSE 0 END) AS iit_messages, + SUM(CASE WHEN appointment_status = "Missed" OR appointment_status = "Defaulted" OR appointment_status = "IIT" THEN called END) AS called, + SUM(CASE WHEN called = 1 AND appointment_status = "Missed" THEN 1 ELSE 0 END) AS missed_called, + SUM(CASE WHEN called = 1 AND appointment_status = "Defaulted" THEN 1 ELSE 0 END) AS defaulted_called, + SUM(CASE WHEN called = 1 AND appointment_status = "IIT" THEN 1 ELSE 0 END) AS iit_called, + SUM(CASE WHEN appointment_status = "Missed" OR appointment_status = "Defaulted" OR appointment_status = "IIT" THEN physically_traced END) AS physically_traced, + SUM(CASE WHEN physically_traced = 1 AND appointment_status = "Missed" THEN 1 ELSE 0 END) AS missed_traced, + SUM(CASE WHEN physically_traced = 1 AND appointment_status = "Defaulted" THEN 1 ELSE 0 END) AS defaulted_traced, + SUM(CASE WHEN physically_traced = 1 AND appointment_status = "IIT" THEN 1 ELSE 0 END) AS iit_traced, + SUM(CASE WHEN appointment_status = "Missed" OR appointment_status = "Defaulted" OR appointment_status = "IIT" THEN rtc_no END) AS final_outcome, + SUM(CASE WHEN final_outcome = "Client returned to care" AND appointment_status = "Missed" THEN 1 ELSE 0 END) AS missed_outcome, + SUM(CASE WHEN final_outcome = "Client returned to care" AND appointment_status = "Defaulted" THEN 1 ELSE 0 END) AS defaulted_outcome, + SUM(CASE WHEN final_outcome = "Client returned to care" AND appointment_status = "IIT" THEN 1 ELSE 0 END) AS iit_outcome, + SUM(CASE WHEN appointment_status = "Missed" OR appointment_status = "Defaulted" OR appointment_status = "IIT" THEN consent_no END) AS consent, + SUM(CASE WHEN consent = "Yes" AND appointment_status = "Missed" THEN 1 ELSE 0 END) AS missed_consent, + SUM(CASE WHEN consent = "Yes" AND appointment_status = "Defaulted" THEN 1 ELSE 0 END) AS defaulted_consent, + SUM(CASE WHEN consent = "Yes" AND appointment_status = "IIT" THEN 1 ELSE 0 END) AS iit_consent ' ); - $missed_age = DB::table('etl_appointment_detail')->select( - 'age_group', - DB::raw('SUM(app_not_kept) AS not_kept_app '), - DB::raw('SUM(CASE WHEN final_outcome = "Client returned to care" THEN 1 ELSE 0 END) AS final_outcome'), - DB::raw('ROUND(AVG(percent_rtc),1) AS percent_rtc '), - DB::raw('ROUND(AVG(percent_not_kept),1) AS percent_not_kept ') + $missed_age = DB::table('etl_appointment_detail')->selectRaw( + 'age_group, + SUM(app_not_kept) AS not_kept_app, + SUM(CASE WHEN final_outcome = "Client returned to care" THEN 1 ELSE 0 END) AS final_outcome, + ROUND(AVG(percent_rtc),1) AS percent_rtc, + ROUND(AVG(percent_not_kept),1) AS percent_not_kept ' ) ->whereNotNull('age_group') ->groupBy('age_group'); - $missed_gender = DB::table('etl_appointment_detail')->select( - 'gender', - DB::raw('SUM(app_not_kept) AS not_kept_app '), - DB::raw('SUM(CASE WHEN final_outcome = "Client returned to care" THEN 1 ELSE 0 END) AS final_outcome'), - DB::raw('ROUND(AVG(percent_rtc),1) AS percent_rtc '), - DB::raw('ROUND(AVG(percent_not_kept),1) AS percent_not_kept ') + $missed_gender = DB::table('etl_appointment_detail')->selectRaw( + 'gender, + SUM(app_not_kept) AS not_kept_app, + SUM(CASE WHEN final_outcome = "Client returned to care" THEN 1 ELSE 0 END) AS final_outcome, + ROUND(AVG(percent_rtc),1) AS percent_rtc, + ROUND(AVG(percent_not_kept),1) AS percent_not_kept ' ) ->whereNotNull('gender') ->orderBy('percent_rtc', 'DESC') ->groupBy('gender'); - $missed_marital = DB::table('etl_appointment_detail')->select( - 'marital', - DB::raw('SUM(app_not_kept) AS not_kept_app '), - DB::raw('SUM(CASE WHEN final_outcome = "Client returned to care" THEN 1 ELSE 0 END) AS final_outcome'), - DB::raw('ROUND(AVG(percent_rtc),1) AS percent_rtc '), - DB::raw('ROUND(AVG(percent_not_kept),1) AS percent_not_kept ') + $missed_marital = DB::table('etl_appointment_detail')->selectRaw( + 'marital, + SUM(app_not_kept) AS not_kept_app, + SUM(CASE WHEN final_outcome = "Client returned to care" THEN 1 ELSE 0 END) AS final_outcome, + ROUND(AVG(percent_rtc),1) AS percent_rtc, + ROUND(AVG(percent_not_kept),1) AS percent_not_kept ' ) ->whereNotNull('marital') ->orderBy('percent_rtc', 'DESC') ->groupBy('marital'); - $missed_county = DB::table('etl_appointment_detail')->select( - 'county', - DB::raw('SUM(app_not_kept) AS not_kept_app '), - DB::raw('SUM(CASE WHEN final_outcome = "Client returned to care" THEN 1 ELSE 0 END) AS final_outcome'), - DB::raw('ROUND(AVG(percent_rtc),1) AS percent_rtc '), - DB::raw('ROUND(AVG(percent_not_kept),1) AS percent_not_kept ') + $missed_county = DB::table('etl_appointment_detail')->selectRaw( + 'county, + SUM(app_not_kept) AS not_kept_app, + SUM(CASE WHEN final_outcome = "Client returned to care" THEN 1 ELSE 0 END) AS final_outcome, + ROUND(AVG(percent_rtc),1) AS percent_rtc, + ROUND(AVG(percent_not_kept),1) AS percent_not_kept ' ) ->whereNotNull('county') ->orderBy('percent_rtc', 'DESC') ->groupBy('county'); - $missed_partner = DB::table('etl_appointment_detail')->select( - 'partner', - DB::raw('SUM(app_not_kept) AS not_kept_app '), - DB::raw('SUM(CASE WHEN final_outcome = "Client returned to care" THEN 1 ELSE 0 END) AS final_outcome'), - DB::raw('ROUND(AVG(percent_rtc),1) AS percent_rtc '), - DB::raw('ROUND(AVG(percent_not_kept),1) AS percent_not_kept ') + $missed_partner = DB::table('etl_appointment_detail')->selectRaw( + 'partner, + SUM(app_not_kept) AS not_kept_app, + SUM(CASE WHEN final_outcome = "Client returned to care" THEN 1 ELSE 0 END) AS final_outcome, + ROUND(AVG(percent_rtc),1) AS percent_rtc, + ROUND(AVG(percent_not_kept),1) AS percent_not_kept ' ) ->whereNotNull('partner') ->orderBy('percent_rtc', 'DESC') ->groupBy('partner'); - $app_period = DB::table('etl_appointment_detail')->select( - DB::raw('DATE_FORMAT(appointment_date, "%Y-%M") AS new_date'), - DB::raw('ROUND(AVG(percent_rtc),1) AS percent_rtc '), - DB::raw('ROUND(AVG(percent_not_kept),1) AS percent_not_kept ') + $app_period = DB::table('etl_appointment_detail')->selectRaw( + 'DATE_FORMAT(appointment_date, "%Y-%M") AS new_date, + ROUND(AVG(percent_rtc),1) AS percent_rtc , + ROUND(AVG(percent_not_kept),1) AS percent_not_kept ' )->whereNotNull('appointment_date') ->where('appointment_date', '<=', date("Y-M-D")) ->where(DB::raw('DATE_FORMAT(appointment_date, "%Y-%M")'), '>=', "2017-January") @@ -623,30 +624,31 @@ public function appointment() ->where('partner_id', Auth::user()->partner_id); // missed appointment - $client_missed = DB::table('etl_appointment_detail')->select( - DB::raw('SUM(app_not_kept) AS not_kept_app '), - DB::raw('SUM(CASE WHEN appointment_status = "Missed" OR appointment_status = "Defaulted" OR appointment_status = "IIT" THEN received_sms END) AS messages '), - DB::raw('SUM(CASE WHEN received_sms = 1 AND appointment_status = "Missed" THEN 1 ELSE 0 END) AS missed_messages '), - DB::raw('SUM(CASE WHEN received_sms = 1 AND appointment_status = "Defaulted" THEN 1 ELSE 0 END) AS defaulted_messages '), - DB::raw('SUM(CASE WHEN received_sms = 1 AND appointment_status = "IIT" THEN 1 ELSE 0 END) AS iit_messages '), - DB::raw('SUM(CASE WHEN appointment_status = "Missed" OR appointment_status = "Defaulted" OR appointment_status = "IIT" THEN called END) AS called '), - DB::raw('SUM(CASE WHEN called = 1 AND appointment_status = "Missed" THEN 1 ELSE 0 END) AS missed_called '), - DB::raw('SUM(CASE WHEN called = 1 AND appointment_status = "Defaulted" THEN 1 ELSE 0 END) AS defaulted_called '), - DB::raw('SUM(CASE WHEN called = 1 AND appointment_status = "IIT" THEN 1 ELSE 0 END) AS iit_called '), - DB::raw('SUM(CASE WHEN appointment_status = "Missed" OR appointment_status = "Defaulted" OR appointment_status = "IIT" THEN physically_traced END) AS physically_traced '), - DB::raw('SUM(CASE WHEN physically_traced = 1 AND appointment_status = "Missed" THEN 1 ELSE 0 END) AS missed_traced '), - DB::raw('SUM(CASE WHEN physically_traced = 1 AND appointment_status = "Defaulted" THEN 1 ELSE 0 END) AS defaulted_traced '), - DB::raw('SUM(CASE WHEN physically_traced = 1 AND appointment_status = "IIT" THEN 1 ELSE 0 END) AS iit_traced '), - DB::raw('SUM(CASE WHEN appointment_status = "Missed" OR appointment_status = "Defaulted" OR appointment_status = "IIT" THEN rtc_no END) AS final_outcome'), - DB::raw('SUM(CASE WHEN final_outcome = "Client returned to care" AND appointment_status = "Missed" THEN 1 ELSE 0 END) AS missed_outcome '), - DB::raw('SUM(CASE WHEN final_outcome = "Client returned to care" AND appointment_status = "Defaulted" THEN 1 ELSE 0 END) AS defaulted_outcome '), - DB::raw('SUM(CASE WHEN final_outcome = "Client returned to care" AND appointment_status = "IIT" THEN 1 ELSE 0 END) AS iit_outcome '), - DB::raw('SUM(CASE WHEN appointment_status = "Missed" OR appointment_status = "Defaulted" OR appointment_status = "IIT" THEN consent_no END) AS consent '), - DB::raw('SUM(CASE WHEN consent = "Yes" AND appointment_status = "Missed" THEN 1 ELSE 0 END) AS missed_consent '), - DB::raw('SUM(CASE WHEN consent = "Yes" AND appointment_status = "Defaulted" THEN 1 ELSE 0 END) AS defaulted_consent '), - DB::raw('SUM(CASE WHEN consent = "Yes" AND appointment_status = "IIT" THEN 1 ELSE 0 END) AS iit_consent ') + $client_missed = DB::table('etl_appointment_detail')->selectRaw(' + SUM(CASE WHEN app_not_kept = 1 THEN 1 ELSE 0 END) AS not_kept_app, + SUM(CASE WHEN appointment_status = "Missed" OR appointment_status = "Defaulted" OR appointment_status = "IIT" THEN received_sms END) AS messages, + SUM(CASE WHEN received_sms = 1 AND appointment_status = "Missed" THEN 1 ELSE 0 END) AS missed_messages, + SUM(CASE WHEN received_sms = 1 AND appointment_status = "Defaulted" THEN 1 ELSE 0 END) AS defaulted_messages, + SUM(CASE WHEN received_sms = 1 AND appointment_status = "IIT" THEN 1 ELSE 0 END) AS iit_messages, + SUM(CASE WHEN appointment_status = "Missed" OR appointment_status = "Defaulted" OR appointment_status = "IIT" THEN called END) AS called, + SUM(CASE WHEN called = 1 AND appointment_status = "Missed" THEN 1 ELSE 0 END) AS missed_called, + SUM(CASE WHEN called = 1 AND appointment_status = "Defaulted" THEN 1 ELSE 0 END) AS defaulted_called, + SUM(CASE WHEN called = 1 AND appointment_status = "IIT" THEN 1 ELSE 0 END) AS iit_called, + SUM(CASE WHEN appointment_status = "Missed" OR appointment_status = "Defaulted" OR appointment_status = "IIT" THEN physically_traced END) AS physically_traced, + SUM(CASE WHEN physically_traced = 1 AND appointment_status = "Missed" THEN 1 ELSE 0 END) AS missed_traced, + SUM(CASE WHEN physically_traced = 1 AND appointment_status = "Defaulted" THEN 1 ELSE 0 END) AS defaulted_traced, + SUM(CASE WHEN physically_traced = 1 AND appointment_status = "IIT" THEN 1 ELSE 0 END) AS iit_traced, + SUM(CASE WHEN appointment_status = "Missed" OR appointment_status = "Defaulted" OR appointment_status = "IIT" THEN rtc_no END) AS final_outcome, + SUM(CASE WHEN final_outcome = "Client returned to care" AND appointment_status = "Missed" THEN 1 ELSE 0 END) AS missed_outcome, + SUM(CASE WHEN final_outcome = "Client returned to care" AND appointment_status = "Defaulted" THEN 1 ELSE 0 END) AS defaulted_outcome, + SUM(CASE WHEN final_outcome = "Client returned to care" AND appointment_status = "IIT" THEN 1 ELSE 0 END) AS iit_outcome, + SUM(CASE WHEN appointment_status = "Missed" OR appointment_status = "Defaulted" OR appointment_status = "IIT" THEN consent_no END) AS consent, + SUM(CASE WHEN consent = "Yes" AND appointment_status = "Missed" THEN 1 ELSE 0 END) AS missed_consent, + SUM(CASE WHEN consent = "Yes" AND appointment_status = "Defaulted" THEN 1 ELSE 0 END) AS defaulted_consent, + SUM(CASE WHEN consent = "Yes" AND appointment_status = "IIT" THEN 1 ELSE 0 END) AS iit_consent ' ) - ->where('partner_id', Auth::user()->partner_id); + ->where('partner_id', Auth::user()->partner_id) + ->groupBy('client_id'); $missed_age = DB::table('etl_appointment_detail')->select( 'age_group', @@ -830,30 +832,31 @@ public function appointment() ->where('subcounty_id', Auth::user()->subcounty_id); // missed appointment - $client_missed = DB::table('etl_appointment_detail')->select( - DB::raw('SUM(app_not_kept) AS not_kept_app '), - DB::raw('SUM(CASE WHEN appointment_status = "Missed" OR appointment_status = "Defaulted" OR appointment_status = "IIT" THEN received_sms END) AS messages '), - DB::raw('SUM(CASE WHEN received_sms = 1 AND appointment_status = "Missed" THEN 1 ELSE 0 END) AS missed_messages '), - DB::raw('SUM(CASE WHEN received_sms = 1 AND appointment_status = "Defaulted" THEN 1 ELSE 0 END) AS defaulted_messages '), - DB::raw('SUM(CASE WHEN received_sms = 1 AND appointment_status = "IIT" THEN 1 ELSE 0 END) AS iit_messages '), - DB::raw('SUM(CASE WHEN appointment_status = "Missed" OR appointment_status = "Defaulted" OR appointment_status = "IIT" THEN called END) AS called '), - DB::raw('SUM(CASE WHEN called = 1 AND appointment_status = "Missed" THEN 1 ELSE 0 END) AS missed_called '), - DB::raw('SUM(CASE WHEN called = 1 AND appointment_status = "Defaulted" THEN 1 ELSE 0 END) AS defaulted_called '), - DB::raw('SUM(CASE WHEN called = 1 AND appointment_status = "IIT" THEN 1 ELSE 0 END) AS iit_called '), - DB::raw('SUM(CASE WHEN appointment_status = "Missed" OR appointment_status = "Defaulted" OR appointment_status = "IIT" THEN physically_traced END) AS physically_traced '), - DB::raw('SUM(CASE WHEN physically_traced = 1 AND appointment_status = "Missed" THEN 1 ELSE 0 END) AS missed_traced '), - DB::raw('SUM(CASE WHEN physically_traced = 1 AND appointment_status = "Defaulted" THEN 1 ELSE 0 END) AS defaulted_traced '), - DB::raw('SUM(CASE WHEN physically_traced = 1 AND appointment_status = "IIT" THEN 1 ELSE 0 END) AS iit_traced '), - DB::raw('SUM(CASE WHEN appointment_status = "Missed" OR appointment_status = "Defaulted" OR appointment_status = "IIT" THEN rtc_no END) AS final_outcome'), - DB::raw('SUM(CASE WHEN final_outcome = "Client returned to care" AND appointment_status = "Missed" THEN 1 ELSE 0 END) AS missed_outcome '), - DB::raw('SUM(CASE WHEN final_outcome = "Client returned to care" AND appointment_status = "Defaulted" THEN 1 ELSE 0 END) AS defaulted_outcome '), - DB::raw('SUM(CASE WHEN final_outcome = "Client returned to care" AND appointment_status = "IIT" THEN 1 ELSE 0 END) AS iit_outcome '), - DB::raw('SUM(CASE WHEN appointment_status = "Missed" OR appointment_status = "Defaulted" OR appointment_status = "IIT" THEN consent_no END) AS consent '), - DB::raw('SUM(CASE WHEN consent = "Yes" AND appointment_status = "Missed" THEN 1 ELSE 0 END) AS missed_consent '), - DB::raw('SUM(CASE WHEN consent = "Yes" AND appointment_status = "Defaulted" THEN 1 ELSE 0 END) AS defaulted_consent '), - DB::raw('SUM(CASE WHEN consent = "Yes" AND appointment_status = "IIT" THEN 1 ELSE 0 END) AS iit_consent ') + $client_missed = DB::table('etl_appointment_detail')->selectRaw(' + SUM(CASE WHEN app_not_kept = 1 THEN 1 ELSE 0 END) AS not_kept_app, + SUM(CASE WHEN appointment_status = "Missed" OR appointment_status = "Defaulted" OR appointment_status = "IIT" THEN received_sms END) AS messages, + SUM(CASE WHEN received_sms = 1 AND appointment_status = "Missed" THEN 1 ELSE 0 END) AS missed_messages, + SUM(CASE WHEN received_sms = 1 AND appointment_status = "Defaulted" THEN 1 ELSE 0 END) AS defaulted_messages, + SUM(CASE WHEN received_sms = 1 AND appointment_status = "IIT" THEN 1 ELSE 0 END) AS iit_messages, + SUM(CASE WHEN appointment_status = "Missed" OR appointment_status = "Defaulted" OR appointment_status = "IIT" THEN called END) AS called, + SUM(CASE WHEN called = 1 AND appointment_status = "Missed" THEN 1 ELSE 0 END) AS missed_called, + SUM(CASE WHEN called = 1 AND appointment_status = "Defaulted" THEN 1 ELSE 0 END) AS defaulted_called, + SUM(CASE WHEN called = 1 AND appointment_status = "IIT" THEN 1 ELSE 0 END) AS iit_called, + SUM(CASE WHEN appointment_status = "Missed" OR appointment_status = "Defaulted" OR appointment_status = "IIT" THEN physically_traced END) AS physically_traced, + SUM(CASE WHEN physically_traced = 1 AND appointment_status = "Missed" THEN 1 ELSE 0 END) AS missed_traced, + SUM(CASE WHEN physically_traced = 1 AND appointment_status = "Defaulted" THEN 1 ELSE 0 END) AS defaulted_traced, + SUM(CASE WHEN physically_traced = 1 AND appointment_status = "IIT" THEN 1 ELSE 0 END) AS iit_traced, + SUM(CASE WHEN appointment_status = "Missed" OR appointment_status = "Defaulted" OR appointment_status = "IIT" THEN rtc_no END) AS final_outcome, + SUM(CASE WHEN final_outcome = "Client returned to care" AND appointment_status = "Missed" THEN 1 ELSE 0 END) AS missed_outcome, + SUM(CASE WHEN final_outcome = "Client returned to care" AND appointment_status = "Defaulted" THEN 1 ELSE 0 END) AS defaulted_outcome, + SUM(CASE WHEN final_outcome = "Client returned to care" AND appointment_status = "IIT" THEN 1 ELSE 0 END) AS iit_outcome, + SUM(CASE WHEN appointment_status = "Missed" OR appointment_status = "Defaulted" OR appointment_status = "IIT" THEN consent_no END) AS consent, + SUM(CASE WHEN consent = "Yes" AND appointment_status = "Missed" THEN 1 ELSE 0 END) AS missed_consent, + SUM(CASE WHEN consent = "Yes" AND appointment_status = "Defaulted" THEN 1 ELSE 0 END) AS defaulted_consent, + SUM(CASE WHEN consent = "Yes" AND appointment_status = "IIT" THEN 1 ELSE 0 END) AS iit_consent ' ) - ->where('subcounty_id', Auth::user()->subcounty_id); + ->where('subcounty_id', Auth::user()->subcounty_id) + ->groupBy('client_id'); $missed_age = DB::table('etl_appointment_detail')->select( 'age_group', @@ -1042,31 +1045,32 @@ public function appointment() ->where('county_id', Auth::user()->county_id); // missed appointment - $client_missed = DB::table('etl_appointment_detail')->select( - DB::raw('SUM(app_not_kept) AS not_kept_app '), - DB::raw('SUM(CASE WHEN appointment_status = "Missed" OR appointment_status = "Defaulted" OR appointment_status = "IIT" THEN received_sms END) AS messages '), - DB::raw('SUM(CASE WHEN received_sms = 1 AND appointment_status = "Missed" THEN 1 ELSE 0 END) AS missed_messages '), - DB::raw('SUM(CASE WHEN received_sms = 1 AND appointment_status = "Defaulted" THEN 1 ELSE 0 END) AS defaulted_messages '), - DB::raw('SUM(CASE WHEN received_sms = 1 AND appointment_status = "IIT" THEN 1 ELSE 0 END) AS iit_messages '), - DB::raw('SUM(CASE WHEN appointment_status = "Missed" OR appointment_status = "Defaulted" OR appointment_status = "IIT" THEN called END) AS called '), - DB::raw('SUM(CASE WHEN called = 1 AND appointment_status = "Missed" THEN 1 ELSE 0 END) AS missed_called '), - DB::raw('SUM(CASE WHEN called = 1 AND appointment_status = "Defaulted" THEN 1 ELSE 0 END) AS defaulted_called '), - DB::raw('SUM(CASE WHEN called = 1 AND appointment_status = "IIT" THEN 1 ELSE 0 END) AS iit_called '), - DB::raw('SUM(CASE WHEN appointment_status = "Missed" OR appointment_status = "Defaulted" OR appointment_status = "IIT" THEN physically_traced END) AS physically_traced '), - DB::raw('SUM(CASE WHEN physically_traced = 1 AND appointment_status = "Missed" THEN 1 ELSE 0 END) AS missed_traced '), - DB::raw('SUM(CASE WHEN physically_traced = 1 AND appointment_status = "Defaulted" THEN 1 ELSE 0 END) AS defaulted_traced '), - DB::raw('SUM(CASE WHEN physically_traced = 1 AND appointment_status = "IIT" THEN 1 ELSE 0 END) AS iit_traced '), - DB::raw('SUM(CASE WHEN appointment_status = "Missed" OR appointment_status = "Defaulted" OR appointment_status = "IIT" THEN rtc_no END) AS final_outcome'), - DB::raw('SUM(CASE WHEN final_outcome = "Client returned to care" AND appointment_status = "Missed" THEN 1 ELSE 0 END) AS missed_outcome '), - DB::raw('SUM(CASE WHEN final_outcome = "Client returned to care" AND appointment_status = "Defaulted" THEN 1 ELSE 0 END) AS defaulted_outcome '), - DB::raw('SUM(CASE WHEN final_outcome = "Client returned to care" AND appointment_status = "IIT" THEN 1 ELSE 0 END) AS iit_outcome '), - DB::raw('SUM(CASE WHEN appointment_status = "Missed" OR appointment_status = "Defaulted" OR appointment_status = "IIT" THEN consent_no END) AS consent '), - DB::raw('SUM(CASE WHEN consent = "Yes" AND appointment_status = "Missed" THEN 1 ELSE 0 END) AS missed_consent '), - DB::raw('SUM(CASE WHEN consent = "Yes" AND appointment_status = "Defaulted" THEN 1 ELSE 0 END) AS defaulted_consent '), - DB::raw('SUM(CASE WHEN consent = "Yes" AND appointment_status = "IIT" THEN 1 ELSE 0 END) AS iit_consent ') + $client_missed = DB::table('etl_appointment_detail')->selectRaw(' + SUM(CASE WHEN app_not_kept = 1 THEN 1 ELSE 0 END) AS not_kept_app, + SUM(CASE WHEN appointment_status = "Missed" OR appointment_status = "Defaulted" OR appointment_status = "IIT" THEN received_sms END) AS messages, + SUM(CASE WHEN received_sms = 1 AND appointment_status = "Missed" THEN 1 ELSE 0 END) AS missed_messages, + SUM(CASE WHEN received_sms = 1 AND appointment_status = "Defaulted" THEN 1 ELSE 0 END) AS defaulted_messages, + SUM(CASE WHEN received_sms = 1 AND appointment_status = "IIT" THEN 1 ELSE 0 END) AS iit_messages, + SUM(CASE WHEN appointment_status = "Missed" OR appointment_status = "Defaulted" OR appointment_status = "IIT" THEN called END) AS called, + SUM(CASE WHEN called = 1 AND appointment_status = "Missed" THEN 1 ELSE 0 END) AS missed_called, + SUM(CASE WHEN called = 1 AND appointment_status = "Defaulted" THEN 1 ELSE 0 END) AS defaulted_called, + SUM(CASE WHEN called = 1 AND appointment_status = "IIT" THEN 1 ELSE 0 END) AS iit_called, + SUM(CASE WHEN appointment_status = "Missed" OR appointment_status = "Defaulted" OR appointment_status = "IIT" THEN physically_traced END) AS physically_traced, + SUM(CASE WHEN physically_traced = 1 AND appointment_status = "Missed" THEN 1 ELSE 0 END) AS missed_traced, + SUM(CASE WHEN physically_traced = 1 AND appointment_status = "Defaulted" THEN 1 ELSE 0 END) AS defaulted_traced, + SUM(CASE WHEN physically_traced = 1 AND appointment_status = "IIT" THEN 1 ELSE 0 END) AS iit_traced, + SUM(CASE WHEN appointment_status = "Missed" OR appointment_status = "Defaulted" OR appointment_status = "IIT" THEN rtc_no END) AS final_outcome, + SUM(CASE WHEN final_outcome = "Client returned to care" AND appointment_status = "Missed" THEN 1 ELSE 0 END) AS missed_outcome, + SUM(CASE WHEN final_outcome = "Client returned to care" AND appointment_status = "Defaulted" THEN 1 ELSE 0 END) AS defaulted_outcome, + SUM(CASE WHEN final_outcome = "Client returned to care" AND appointment_status = "IIT" THEN 1 ELSE 0 END) AS iit_outcome, + SUM(CASE WHEN appointment_status = "Missed" OR appointment_status = "Defaulted" OR appointment_status = "IIT" THEN consent_no END) AS consent, + SUM(CASE WHEN consent = "Yes" AND appointment_status = "Missed" THEN 1 ELSE 0 END) AS missed_consent, + SUM(CASE WHEN consent = "Yes" AND appointment_status = "Defaulted" THEN 1 ELSE 0 END) AS defaulted_consent, + SUM(CASE WHEN consent = "Yes" AND appointment_status = "IIT" THEN 1 ELSE 0 END) AS iit_consent ' ) - ->where('county_id', Auth::user()->county_id); + ->where('county_id', Auth::user()->county_id) + ->groupBy('client_id'); $missed_age = DB::table('etl_appointment_detail')->select( 'age_group', @@ -1246,29 +1250,29 @@ public function filter_data(Request $request) ->groupBy('partner'); // missed appointment - $client_missed = DB::table('etl_appointment_detail')->select( - DB::raw('SUM(app_not_kept) AS not_kept_app '), - DB::raw('SUM(CASE WHEN appointment_status = "Missed" OR appointment_status = "Defaulted" OR appointment_status = "IIT" THEN received_sms END) AS messages '), - DB::raw('SUM(CASE WHEN received_sms = 1 AND appointment_status = "Missed" THEN 1 ELSE 0 END) AS missed_messages '), - DB::raw('SUM(CASE WHEN received_sms = 1 AND appointment_status = "Defaulted" THEN 1 ELSE 0 END) AS defaulted_messages '), - DB::raw('SUM(CASE WHEN received_sms = 1 AND appointment_status = "IIT" THEN 1 ELSE 0 END) AS iit_messages '), - DB::raw('SUM(CASE WHEN appointment_status = "Missed" OR appointment_status = "Defaulted" OR appointment_status = "IIT" THEN called END) AS called '), - DB::raw('SUM(CASE WHEN called = 1 AND appointment_status = "Missed" THEN 1 ELSE 0 END) AS missed_called '), - DB::raw('SUM(CASE WHEN called = 1 AND appointment_status = "Defaulted" THEN 1 ELSE 0 END) AS defaulted_called '), - DB::raw('SUM(CASE WHEN called = 1 AND appointment_status = "IIT" THEN 1 ELSE 0 END) AS iit_called '), - DB::raw('SUM(CASE WHEN appointment_status = "Missed" OR appointment_status = "Defaulted" OR appointment_status = "IIT" THEN physically_traced END) AS physically_traced '), - DB::raw('SUM(CASE WHEN physically_traced = 1 AND appointment_status = "Missed" THEN 1 ELSE 0 END) AS missed_traced '), - DB::raw('SUM(CASE WHEN physically_traced = 1 AND appointment_status = "Defaulted" THEN 1 ELSE 0 END) AS defaulted_traced '), - DB::raw('SUM(CASE WHEN physically_traced = 1 AND appointment_status = "IIT" THEN 1 ELSE 0 END) AS iit_traced '), - DB::raw('SUM(CASE WHEN appointment_status = "Missed" OR appointment_status = "Defaulted" OR appointment_status = "IIT" THEN rtc_no END) AS final_outcome'), - DB::raw('SUM(CASE WHEN final_outcome = "Client returned to care" AND appointment_status = "Missed" THEN 1 ELSE 0 END) AS missed_outcome '), - DB::raw('SUM(CASE WHEN final_outcome = "Client returned to care" AND appointment_status = "Defaulted" THEN 1 ELSE 0 END) AS defaulted_outcome '), - DB::raw('SUM(CASE WHEN final_outcome = "Client returned to care" AND appointment_status = "IIT" THEN 1 ELSE 0 END) AS iit_outcome '), - DB::raw('SUM(CASE WHEN appointment_status = "Missed" OR appointment_status = "Defaulted" OR appointment_status = "IIT" THEN consent_no END) AS consent '), - DB::raw('SUM(CASE WHEN consent = "Yes" AND appointment_status = "Missed" THEN 1 ELSE 0 END) AS missed_consent '), - DB::raw('SUM(CASE WHEN consent = "Yes" AND appointment_status = "Defaulted" THEN 1 ELSE 0 END) AS defaulted_consent '), - DB::raw('SUM(CASE WHEN consent = "Yes" AND appointment_status = "IIT" THEN 1 ELSE 0 END) AS iit_consent ') - ); + $client_missed = DB::table('etl_appointment_detail')->selectRaw(' + SUM(CASE WHEN app_not_kept = 1 THEN 1 ELSE 0 END) AS not_kept_app, + SUM(CASE WHEN appointment_status = "Missed" OR appointment_status = "Defaulted" OR appointment_status = "IIT" THEN received_sms END) AS messages, + SUM(CASE WHEN received_sms = 1 AND appointment_status = "Missed" THEN 1 ELSE 0 END) AS missed_messages, + SUM(CASE WHEN received_sms = 1 AND appointment_status = "Defaulted" THEN 1 ELSE 0 END) AS defaulted_messages, + SUM(CASE WHEN received_sms = 1 AND appointment_status = "IIT" THEN 1 ELSE 0 END) AS iit_messages, + SUM(CASE WHEN appointment_status = "Missed" OR appointment_status = "Defaulted" OR appointment_status = "IIT" THEN called END) AS called, + SUM(CASE WHEN called = 1 AND appointment_status = "Missed" THEN 1 ELSE 0 END) AS missed_called, + SUM(CASE WHEN called = 1 AND appointment_status = "Defaulted" THEN 1 ELSE 0 END) AS defaulted_called, + SUM(CASE WHEN called = 1 AND appointment_status = "IIT" THEN 1 ELSE 0 END) AS iit_called, + SUM(CASE WHEN appointment_status = "Missed" OR appointment_status = "Defaulted" OR appointment_status = "IIT" THEN physically_traced END) AS physically_traced, + SUM(CASE WHEN physically_traced = 1 AND appointment_status = "Missed" THEN 1 ELSE 0 END) AS missed_traced, + SUM(CASE WHEN physically_traced = 1 AND appointment_status = "Defaulted" THEN 1 ELSE 0 END) AS defaulted_traced, + SUM(CASE WHEN physically_traced = 1 AND appointment_status = "IIT" THEN 1 ELSE 0 END) AS iit_traced, + SUM(CASE WHEN appointment_status = "Missed" OR appointment_status = "Defaulted" OR appointment_status = "IIT" THEN rtc_no END) AS final_outcome, + SUM(CASE WHEN final_outcome = "Client returned to care" AND appointment_status = "Missed" THEN 1 ELSE 0 END) AS missed_outcome, + SUM(CASE WHEN final_outcome = "Client returned to care" AND appointment_status = "Defaulted" THEN 1 ELSE 0 END) AS defaulted_outcome, + SUM(CASE WHEN final_outcome = "Client returned to care" AND appointment_status = "IIT" THEN 1 ELSE 0 END) AS iit_outcome, + SUM(CASE WHEN appointment_status = "Missed" OR appointment_status = "Defaulted" OR appointment_status = "IIT" THEN consent_no END) AS consent, + SUM(CASE WHEN consent = "Yes" AND appointment_status = "Missed" THEN 1 ELSE 0 END) AS missed_consent, + SUM(CASE WHEN consent = "Yes" AND appointment_status = "Defaulted" THEN 1 ELSE 0 END) AS defaulted_consent, + SUM(CASE WHEN consent = "Yes" AND appointment_status = "IIT" THEN 1 ELSE 0 END) AS iit_consent ' + )->groupBy('client_id'); $missed_age = DB::table('etl_appointment_detail')->select( 'age_group', @@ -1586,30 +1590,31 @@ public function filter_data(Request $request) ->where('mfl_code', Auth::user()->facility_id) ->groupBy('facility'); // missed appointment - $client_missed = DB::table('etl_appointment_detail')->select( - DB::raw('SUM(app_not_kept) AS not_kept_app '), - DB::raw('SUM(CASE WHEN appointment_status = "Missed" OR appointment_status = "Defaulted" OR appointment_status = "IIT" THEN received_sms END) AS messages '), - DB::raw('SUM(CASE WHEN received_sms = 1 AND appointment_status = "Missed" THEN 1 ELSE 0 END) AS missed_messages '), - DB::raw('SUM(CASE WHEN received_sms = 1 AND appointment_status = "Defaulted" THEN 1 ELSE 0 END) AS defaulted_messages '), - DB::raw('SUM(CASE WHEN received_sms = 1 AND appointment_status = "IIT" THEN 1 ELSE 0 END) AS iit_messages '), - DB::raw('SUM(CASE WHEN appointment_status = "Missed" OR appointment_status = "Defaulted" OR appointment_status = "IIT" THEN called END) AS called '), - DB::raw('SUM(CASE WHEN called = 1 AND appointment_status = "Missed" THEN 1 ELSE 0 END) AS missed_called '), - DB::raw('SUM(CASE WHEN called = 1 AND appointment_status = "Defaulted" THEN 1 ELSE 0 END) AS defaulted_called '), - DB::raw('SUM(CASE WHEN called = 1 AND appointment_status = "IIT" THEN 1 ELSE 0 END) AS iit_called '), - DB::raw('SUM(CASE WHEN appointment_status = "Missed" OR appointment_status = "Defaulted" OR appointment_status = "IIT" THEN physically_traced END) AS physically_traced '), - DB::raw('SUM(CASE WHEN physically_traced = 1 AND appointment_status = "Missed" THEN 1 ELSE 0 END) AS missed_traced '), - DB::raw('SUM(CASE WHEN physically_traced = 1 AND appointment_status = "Defaulted" THEN 1 ELSE 0 END) AS defaulted_traced '), - DB::raw('SUM(CASE WHEN physically_traced = 1 AND appointment_status = "IIT" THEN 1 ELSE 0 END) AS iit_traced '), - DB::raw('SUM(CASE WHEN appointment_status = "Missed" OR appointment_status = "Defaulted" OR appointment_status = "IIT" THEN rtc_no END) AS final_outcome'), - DB::raw('SUM(CASE WHEN final_outcome = "Client returned to care" AND appointment_status = "Missed" THEN 1 ELSE 0 END) AS missed_outcome '), - DB::raw('SUM(CASE WHEN final_outcome = "Client returned to care" AND appointment_status = "Defaulted" THEN 1 ELSE 0 END) AS defaulted_outcome '), - DB::raw('SUM(CASE WHEN final_outcome = "Client returned to care" AND appointment_status = "IIT" THEN 1 ELSE 0 END) AS iit_outcome '), - DB::raw('SUM(CASE WHEN appointment_status = "Missed" OR appointment_status = "Defaulted" OR appointment_status = "IIT" THEN consent_no END) AS consent '), - DB::raw('SUM(CASE WHEN consent = "Yes" AND appointment_status = "Missed" THEN 1 ELSE 0 END) AS missed_consent '), - DB::raw('SUM(CASE WHEN consent = "Yes" AND appointment_status = "Defaulted" THEN 1 ELSE 0 END) AS defaulted_consent '), - DB::raw('SUM(CASE WHEN consent = "Yes" AND appointment_status = "IIT" THEN 1 ELSE 0 END) AS iit_consent ') + $client_missed = DB::table('etl_appointment_detail')->selectRaw(' + SUM(CASE WHEN app_not_kept = 1 THEN 1 ELSE 0 END) AS not_kept_app, + SUM(CASE WHEN appointment_status = "Missed" OR appointment_status = "Defaulted" OR appointment_status = "IIT" THEN received_sms END) AS messages, + SUM(CASE WHEN received_sms = 1 AND appointment_status = "Missed" THEN 1 ELSE 0 END) AS missed_messages, + SUM(CASE WHEN received_sms = 1 AND appointment_status = "Defaulted" THEN 1 ELSE 0 END) AS defaulted_messages, + SUM(CASE WHEN received_sms = 1 AND appointment_status = "IIT" THEN 1 ELSE 0 END) AS iit_messages, + SUM(CASE WHEN appointment_status = "Missed" OR appointment_status = "Defaulted" OR appointment_status = "IIT" THEN called END) AS called, + SUM(CASE WHEN called = 1 AND appointment_status = "Missed" THEN 1 ELSE 0 END) AS missed_called, + SUM(CASE WHEN called = 1 AND appointment_status = "Defaulted" THEN 1 ELSE 0 END) AS defaulted_called, + SUM(CASE WHEN called = 1 AND appointment_status = "IIT" THEN 1 ELSE 0 END) AS iit_called, + SUM(CASE WHEN appointment_status = "Missed" OR appointment_status = "Defaulted" OR appointment_status = "IIT" THEN physically_traced END) AS physically_traced, + SUM(CASE WHEN physically_traced = 1 AND appointment_status = "Missed" THEN 1 ELSE 0 END) AS missed_traced, + SUM(CASE WHEN physically_traced = 1 AND appointment_status = "Defaulted" THEN 1 ELSE 0 END) AS defaulted_traced, + SUM(CASE WHEN physically_traced = 1 AND appointment_status = "IIT" THEN 1 ELSE 0 END) AS iit_traced, + SUM(CASE WHEN appointment_status = "Missed" OR appointment_status = "Defaulted" OR appointment_status = "IIT" THEN rtc_no END) AS final_outcome, + SUM(CASE WHEN final_outcome = "Client returned to care" AND appointment_status = "Missed" THEN 1 ELSE 0 END) AS missed_outcome, + SUM(CASE WHEN final_outcome = "Client returned to care" AND appointment_status = "Defaulted" THEN 1 ELSE 0 END) AS defaulted_outcome, + SUM(CASE WHEN final_outcome = "Client returned to care" AND appointment_status = "IIT" THEN 1 ELSE 0 END) AS iit_outcome, + SUM(CASE WHEN appointment_status = "Missed" OR appointment_status = "Defaulted" OR appointment_status = "IIT" THEN consent_no END) AS consent, + SUM(CASE WHEN consent = "Yes" AND appointment_status = "Missed" THEN 1 ELSE 0 END) AS missed_consent, + SUM(CASE WHEN consent = "Yes" AND appointment_status = "Defaulted" THEN 1 ELSE 0 END) AS defaulted_consent, + SUM(CASE WHEN consent = "Yes" AND appointment_status = "IIT" THEN 1 ELSE 0 END) AS iit_consent ' ) - ->where('mfl_code', Auth::user()->facility_id); + ->where('mfl_code', Auth::user()->facility_id) + ->groupBy('client_id'); $missed_age = DB::table('etl_appointment_detail')->select( 'age_group', @@ -1957,30 +1962,31 @@ public function filter_data(Request $request) ->where('partner_id', Auth::user()->partner_id); // missed appointment - $client_missed = DB::table('etl_appointment_detail')->select( - DB::raw('SUM(app_not_kept) AS not_kept_app '), - DB::raw('SUM(CASE WHEN appointment_status = "Missed" OR appointment_status = "Defaulted" OR appointment_status = "IIT" THEN received_sms END) AS messages '), - DB::raw('SUM(CASE WHEN received_sms = 1 AND appointment_status = "Missed" THEN 1 ELSE 0 END) AS missed_messages '), - DB::raw('SUM(CASE WHEN received_sms = 1 AND appointment_status = "Defaulted" THEN 1 ELSE 0 END) AS defaulted_messages '), - DB::raw('SUM(CASE WHEN received_sms = 1 AND appointment_status = "IIT" THEN 1 ELSE 0 END) AS iit_messages '), - DB::raw('SUM(CASE WHEN appointment_status = "Missed" OR appointment_status = "Defaulted" OR appointment_status = "IIT" THEN called END) AS called '), - DB::raw('SUM(CASE WHEN called = 1 AND appointment_status = "Missed" THEN 1 ELSE 0 END) AS missed_called '), - DB::raw('SUM(CASE WHEN called = 1 AND appointment_status = "Defaulted" THEN 1 ELSE 0 END) AS defaulted_called '), - DB::raw('SUM(CASE WHEN called = 1 AND appointment_status = "IIT" THEN 1 ELSE 0 END) AS iit_called '), - DB::raw('SUM(CASE WHEN appointment_status = "Missed" OR appointment_status = "Defaulted" OR appointment_status = "IIT" THEN physically_traced END) AS physically_traced '), - DB::raw('SUM(CASE WHEN physically_traced = 1 AND appointment_status = "Missed" THEN 1 ELSE 0 END) AS missed_traced '), - DB::raw('SUM(CASE WHEN physically_traced = 1 AND appointment_status = "Defaulted" THEN 1 ELSE 0 END) AS defaulted_traced '), - DB::raw('SUM(CASE WHEN physically_traced = 1 AND appointment_status = "IIT" THEN 1 ELSE 0 END) AS iit_traced '), - DB::raw('SUM(CASE WHEN appointment_status = "Missed" OR appointment_status = "Defaulted" OR appointment_status = "IIT" THEN rtc_no END) AS final_outcome'), - DB::raw('SUM(CASE WHEN final_outcome = "Client returned to care" AND appointment_status = "Missed" THEN 1 ELSE 0 END) AS missed_outcome '), - DB::raw('SUM(CASE WHEN final_outcome = "Client returned to care" AND appointment_status = "Defaulted" THEN 1 ELSE 0 END) AS defaulted_outcome '), - DB::raw('SUM(CASE WHEN final_outcome = "Client returned to care" AND appointment_status = "IIT" THEN 1 ELSE 0 END) AS iit_outcome '), - DB::raw('SUM(CASE WHEN appointment_status = "Missed" OR appointment_status = "Defaulted" OR appointment_status = "IIT" THEN consent_no END) AS consent '), - DB::raw('SUM(CASE WHEN consent = "Yes" AND appointment_status = "Missed" THEN 1 ELSE 0 END) AS missed_consent '), - DB::raw('SUM(CASE WHEN consent = "Yes" AND appointment_status = "Defaulted" THEN 1 ELSE 0 END) AS defaulted_consent '), - DB::raw('SUM(CASE WHEN consent = "Yes" AND appointment_status = "IIT" THEN 1 ELSE 0 END) AS iit_consent ') + $client_missed = DB::table('etl_appointment_detail')->selectRaw(' + SUM(CASE WHEN app_not_kept = 1 THEN 1 ELSE 0 END) AS not_kept_app, + SUM(CASE WHEN appointment_status = "Missed" OR appointment_status = "Defaulted" OR appointment_status = "IIT" THEN received_sms END) AS messages, + SUM(CASE WHEN received_sms = 1 AND appointment_status = "Missed" THEN 1 ELSE 0 END) AS missed_messages, + SUM(CASE WHEN received_sms = 1 AND appointment_status = "Defaulted" THEN 1 ELSE 0 END) AS defaulted_messages, + SUM(CASE WHEN received_sms = 1 AND appointment_status = "IIT" THEN 1 ELSE 0 END) AS iit_messages, + SUM(CASE WHEN appointment_status = "Missed" OR appointment_status = "Defaulted" OR appointment_status = "IIT" THEN called END) AS called, + SUM(CASE WHEN called = 1 AND appointment_status = "Missed" THEN 1 ELSE 0 END) AS missed_called, + SUM(CASE WHEN called = 1 AND appointment_status = "Defaulted" THEN 1 ELSE 0 END) AS defaulted_called, + SUM(CASE WHEN called = 1 AND appointment_status = "IIT" THEN 1 ELSE 0 END) AS iit_called, + SUM(CASE WHEN appointment_status = "Missed" OR appointment_status = "Defaulted" OR appointment_status = "IIT" THEN physically_traced END) AS physically_traced, + SUM(CASE WHEN physically_traced = 1 AND appointment_status = "Missed" THEN 1 ELSE 0 END) AS missed_traced, + SUM(CASE WHEN physically_traced = 1 AND appointment_status = "Defaulted" THEN 1 ELSE 0 END) AS defaulted_traced, + SUM(CASE WHEN physically_traced = 1 AND appointment_status = "IIT" THEN 1 ELSE 0 END) AS iit_traced, + SUM(CASE WHEN appointment_status = "Missed" OR appointment_status = "Defaulted" OR appointment_status = "IIT" THEN rtc_no END) AS final_outcome, + SUM(CASE WHEN final_outcome = "Client returned to care" AND appointment_status = "Missed" THEN 1 ELSE 0 END) AS missed_outcome, + SUM(CASE WHEN final_outcome = "Client returned to care" AND appointment_status = "Defaulted" THEN 1 ELSE 0 END) AS defaulted_outcome, + SUM(CASE WHEN final_outcome = "Client returned to care" AND appointment_status = "IIT" THEN 1 ELSE 0 END) AS iit_outcome, + SUM(CASE WHEN appointment_status = "Missed" OR appointment_status = "Defaulted" OR appointment_status = "IIT" THEN consent_no END) AS consent, + SUM(CASE WHEN consent = "Yes" AND appointment_status = "Missed" THEN 1 ELSE 0 END) AS missed_consent, + SUM(CASE WHEN consent = "Yes" AND appointment_status = "Defaulted" THEN 1 ELSE 0 END) AS defaulted_consent, + SUM(CASE WHEN consent = "Yes" AND appointment_status = "IIT" THEN 1 ELSE 0 END) AS iit_consent ' ) - ->where('partner_id', Auth::user()->partner_id); + ->where('partner_id', Auth::user()->partner_id) + ->groupBy('client_id'); $missed_age = DB::table('etl_appointment_detail')->select( 'age_group', @@ -2336,30 +2342,31 @@ public function filter_data(Request $request) ->where('subcounty_id', Auth::user()->subcounty_id); // missed appointment - $client_missed = DB::table('etl_appointment_detail')->select( - DB::raw('SUM(app_not_kept) AS not_kept_app '), - DB::raw('SUM(CASE WHEN appointment_status = "Missed" OR appointment_status = "Defaulted" OR appointment_status = "IIT" THEN received_sms END) AS messages '), - DB::raw('SUM(CASE WHEN received_sms = 1 AND appointment_status = "Missed" THEN 1 ELSE 0 END) AS missed_messages '), - DB::raw('SUM(CASE WHEN received_sms = 1 AND appointment_status = "Defaulted" THEN 1 ELSE 0 END) AS defaulted_messages '), - DB::raw('SUM(CASE WHEN received_sms = 1 AND appointment_status = "IIT" THEN 1 ELSE 0 END) AS iit_messages '), - DB::raw('SUM(CASE WHEN appointment_status = "Missed" OR appointment_status = "Defaulted" OR appointment_status = "IIT" THEN called END) AS called '), - DB::raw('SUM(CASE WHEN called = 1 AND appointment_status = "Missed" THEN 1 ELSE 0 END) AS missed_called '), - DB::raw('SUM(CASE WHEN called = 1 AND appointment_status = "Defaulted" THEN 1 ELSE 0 END) AS defaulted_called '), - DB::raw('SUM(CASE WHEN called = 1 AND appointment_status = "IIT" THEN 1 ELSE 0 END) AS iit_called '), - DB::raw('SUM(CASE WHEN appointment_status = "Missed" OR appointment_status = "Defaulted" OR appointment_status = "IIT" THEN physically_traced END) AS physically_traced '), - DB::raw('SUM(CASE WHEN physically_traced = 1 AND appointment_status = "Missed" THEN 1 ELSE 0 END) AS missed_traced '), - DB::raw('SUM(CASE WHEN physically_traced = 1 AND appointment_status = "Defaulted" THEN 1 ELSE 0 END) AS defaulted_traced '), - DB::raw('SUM(CASE WHEN physically_traced = 1 AND appointment_status = "IIT" THEN 1 ELSE 0 END) AS iit_traced '), - DB::raw('SUM(CASE WHEN appointment_status = "Missed" OR appointment_status = "Defaulted" OR appointment_status = "IIT" THEN rtc_no END) AS final_outcome'), - DB::raw('SUM(CASE WHEN final_outcome = "Client returned to care" AND appointment_status = "Missed" THEN 1 ELSE 0 END) AS missed_outcome '), - DB::raw('SUM(CASE WHEN final_outcome = "Client returned to care" AND appointment_status = "Defaulted" THEN 1 ELSE 0 END) AS defaulted_outcome '), - DB::raw('SUM(CASE WHEN final_outcome = "Client returned to care" AND appointment_status = "IIT" THEN 1 ELSE 0 END) AS iit_outcome '), - DB::raw('SUM(CASE WHEN appointment_status = "Missed" OR appointment_status = "Defaulted" OR appointment_status = "IIT" THEN consent_no END) AS consent '), - DB::raw('SUM(CASE WHEN consent = "Yes" AND appointment_status = "Missed" THEN 1 ELSE 0 END) AS missed_consent '), - DB::raw('SUM(CASE WHEN consent = "Yes" AND appointment_status = "Defaulted" THEN 1 ELSE 0 END) AS defaulted_consent '), - DB::raw('SUM(CASE WHEN consent = "Yes" AND appointment_status = "IIT" THEN 1 ELSE 0 END) AS iit_consent ') + $client_missed = DB::table('etl_appointment_detail')->selectRaw(' + SUM(CASE WHEN app_not_kept = 1 THEN 1 ELSE 0 END) AS not_kept_app, + SUM(CASE WHEN appointment_status = "Missed" OR appointment_status = "Defaulted" OR appointment_status = "IIT" THEN received_sms END) AS messages, + SUM(CASE WHEN received_sms = 1 AND appointment_status = "Missed" THEN 1 ELSE 0 END) AS missed_messages, + SUM(CASE WHEN received_sms = 1 AND appointment_status = "Defaulted" THEN 1 ELSE 0 END) AS defaulted_messages, + SUM(CASE WHEN received_sms = 1 AND appointment_status = "IIT" THEN 1 ELSE 0 END) AS iit_messages, + SUM(CASE WHEN appointment_status = "Missed" OR appointment_status = "Defaulted" OR appointment_status = "IIT" THEN called END) AS called, + SUM(CASE WHEN called = 1 AND appointment_status = "Missed" THEN 1 ELSE 0 END) AS missed_called, + SUM(CASE WHEN called = 1 AND appointment_status = "Defaulted" THEN 1 ELSE 0 END) AS defaulted_called, + SUM(CASE WHEN called = 1 AND appointment_status = "IIT" THEN 1 ELSE 0 END) AS iit_called, + SUM(CASE WHEN appointment_status = "Missed" OR appointment_status = "Defaulted" OR appointment_status = "IIT" THEN physically_traced END) AS physically_traced, + SUM(CASE WHEN physically_traced = 1 AND appointment_status = "Missed" THEN 1 ELSE 0 END) AS missed_traced, + SUM(CASE WHEN physically_traced = 1 AND appointment_status = "Defaulted" THEN 1 ELSE 0 END) AS defaulted_traced, + SUM(CASE WHEN physically_traced = 1 AND appointment_status = "IIT" THEN 1 ELSE 0 END) AS iit_traced, + SUM(CASE WHEN appointment_status = "Missed" OR appointment_status = "Defaulted" OR appointment_status = "IIT" THEN rtc_no END) AS final_outcome, + SUM(CASE WHEN final_outcome = "Client returned to care" AND appointment_status = "Missed" THEN 1 ELSE 0 END) AS missed_outcome, + SUM(CASE WHEN final_outcome = "Client returned to care" AND appointment_status = "Defaulted" THEN 1 ELSE 0 END) AS defaulted_outcome, + SUM(CASE WHEN final_outcome = "Client returned to care" AND appointment_status = "IIT" THEN 1 ELSE 0 END) AS iit_outcome, + SUM(CASE WHEN appointment_status = "Missed" OR appointment_status = "Defaulted" OR appointment_status = "IIT" THEN consent_no END) AS consent, + SUM(CASE WHEN consent = "Yes" AND appointment_status = "Missed" THEN 1 ELSE 0 END) AS missed_consent, + SUM(CASE WHEN consent = "Yes" AND appointment_status = "Defaulted" THEN 1 ELSE 0 END) AS defaulted_consent, + SUM(CASE WHEN consent = "Yes" AND appointment_status = "IIT" THEN 1 ELSE 0 END) AS iit_consent ' ) - ->where('subcounty_id', Auth::user()->subcounty_id); + ->where('subcounty_id', Auth::user()->subcounty_id) + ->groupBy('client_id'); $missed_age = DB::table('etl_appointment_detail')->select( 'age_group', @@ -2719,31 +2726,32 @@ public function filter_data(Request $request) ->where('county_id', Auth::user()->county_id); // missed appointment - $client_missed = DB::table('etl_appointment_detail')->select( - DB::raw('SUM(app_not_kept) AS not_kept_app '), - DB::raw('SUM(CASE WHEN appointment_status = "Missed" OR appointment_status = "Defaulted" OR appointment_status = "IIT" THEN received_sms END) AS messages '), - DB::raw('SUM(CASE WHEN received_sms = 1 AND appointment_status = "Missed" THEN 1 ELSE 0 END) AS missed_messages '), - DB::raw('SUM(CASE WHEN received_sms = 1 AND appointment_status = "Defaulted" THEN 1 ELSE 0 END) AS defaulted_messages '), - DB::raw('SUM(CASE WHEN received_sms = 1 AND appointment_status = "IIT" THEN 1 ELSE 0 END) AS iit_messages '), - DB::raw('SUM(CASE WHEN appointment_status = "Missed" OR appointment_status = "Defaulted" OR appointment_status = "IIT" THEN called END) AS called '), - DB::raw('SUM(CASE WHEN called = 1 AND appointment_status = "Missed" THEN 1 ELSE 0 END) AS missed_called '), - DB::raw('SUM(CASE WHEN called = 1 AND appointment_status = "Defaulted" THEN 1 ELSE 0 END) AS defaulted_called '), - DB::raw('SUM(CASE WHEN called = 1 AND appointment_status = "IIT" THEN 1 ELSE 0 END) AS iit_called '), - DB::raw('SUM(CASE WHEN appointment_status = "Missed" OR appointment_status = "Defaulted" OR appointment_status = "IIT" THEN physically_traced END) AS physically_traced '), - DB::raw('SUM(CASE WHEN physically_traced = 1 AND appointment_status = "Missed" THEN 1 ELSE 0 END) AS missed_traced '), - DB::raw('SUM(CASE WHEN physically_traced = 1 AND appointment_status = "Defaulted" THEN 1 ELSE 0 END) AS defaulted_traced '), - DB::raw('SUM(CASE WHEN physically_traced = 1 AND appointment_status = "IIT" THEN 1 ELSE 0 END) AS iit_traced '), - DB::raw('SUM(CASE WHEN appointment_status = "Missed" OR appointment_status = "Defaulted" OR appointment_status = "IIT" THEN rtc_no END) AS final_outcome'), - DB::raw('SUM(CASE WHEN final_outcome = "Client returned to care" AND appointment_status = "Missed" THEN 1 ELSE 0 END) AS missed_outcome '), - DB::raw('SUM(CASE WHEN final_outcome = "Client returned to care" AND appointment_status = "Defaulted" THEN 1 ELSE 0 END) AS defaulted_outcome '), - DB::raw('SUM(CASE WHEN final_outcome = "Client returned to care" AND appointment_status = "IIT" THEN 1 ELSE 0 END) AS iit_outcome '), - DB::raw('SUM(CASE WHEN appointment_status = "Missed" OR appointment_status = "Defaulted" OR appointment_status = "IIT" THEN consent_no END) AS consent '), - DB::raw('SUM(CASE WHEN consent = "Yes" AND appointment_status = "Missed" THEN 1 ELSE 0 END) AS missed_consent '), - DB::raw('SUM(CASE WHEN consent = "Yes" AND appointment_status = "Defaulted" THEN 1 ELSE 0 END) AS defaulted_consent '), - DB::raw('SUM(CASE WHEN consent = "Yes" AND appointment_status = "IIT" THEN 1 ELSE 0 END) AS iit_consent ') + $client_missed = DB::table('etl_appointment_detail')->selectRaw(' + SUM(CASE WHEN app_not_kept = 1 THEN 1 ELSE 0 END) AS not_kept_app, + SUM(CASE WHEN appointment_status = "Missed" OR appointment_status = "Defaulted" OR appointment_status = "IIT" THEN received_sms END) AS messages, + SUM(CASE WHEN received_sms = 1 AND appointment_status = "Missed" THEN 1 ELSE 0 END) AS missed_messages, + SUM(CASE WHEN received_sms = 1 AND appointment_status = "Defaulted" THEN 1 ELSE 0 END) AS defaulted_messages, + SUM(CASE WHEN received_sms = 1 AND appointment_status = "IIT" THEN 1 ELSE 0 END) AS iit_messages, + SUM(CASE WHEN appointment_status = "Missed" OR appointment_status = "Defaulted" OR appointment_status = "IIT" THEN called END) AS called, + SUM(CASE WHEN called = 1 AND appointment_status = "Missed" THEN 1 ELSE 0 END) AS missed_called, + SUM(CASE WHEN called = 1 AND appointment_status = "Defaulted" THEN 1 ELSE 0 END) AS defaulted_called, + SUM(CASE WHEN called = 1 AND appointment_status = "IIT" THEN 1 ELSE 0 END) AS iit_called, + SUM(CASE WHEN appointment_status = "Missed" OR appointment_status = "Defaulted" OR appointment_status = "IIT" THEN physically_traced END) AS physically_traced, + SUM(CASE WHEN physically_traced = 1 AND appointment_status = "Missed" THEN 1 ELSE 0 END) AS missed_traced, + SUM(CASE WHEN physically_traced = 1 AND appointment_status = "Defaulted" THEN 1 ELSE 0 END) AS defaulted_traced, + SUM(CASE WHEN physically_traced = 1 AND appointment_status = "IIT" THEN 1 ELSE 0 END) AS iit_traced, + SUM(CASE WHEN appointment_status = "Missed" OR appointment_status = "Defaulted" OR appointment_status = "IIT" THEN rtc_no END) AS final_outcome, + SUM(CASE WHEN final_outcome = "Client returned to care" AND appointment_status = "Missed" THEN 1 ELSE 0 END) AS missed_outcome, + SUM(CASE WHEN final_outcome = "Client returned to care" AND appointment_status = "Defaulted" THEN 1 ELSE 0 END) AS defaulted_outcome, + SUM(CASE WHEN final_outcome = "Client returned to care" AND appointment_status = "IIT" THEN 1 ELSE 0 END) AS iit_outcome, + SUM(CASE WHEN appointment_status = "Missed" OR appointment_status = "Defaulted" OR appointment_status = "IIT" THEN consent_no END) AS consent, + SUM(CASE WHEN consent = "Yes" AND appointment_status = "Missed" THEN 1 ELSE 0 END) AS missed_consent, + SUM(CASE WHEN consent = "Yes" AND appointment_status = "Defaulted" THEN 1 ELSE 0 END) AS defaulted_consent, + SUM(CASE WHEN consent = "Yes" AND appointment_status = "IIT" THEN 1 ELSE 0 END) AS iit_consent ' ) - ->where('county_id', Auth::user()->county_id); + ->where('county_id', Auth::user()->county_id) + ->groupBy('client_id'); $missed_age = DB::table('etl_appointment_detail')->select( 'age_group', diff --git a/resources/views/dashboard/appointment.blade.php b/resources/views/dashboard/appointment.blade.php index 3238447..a1e03a9 100644 --- a/resources/views/dashboard/appointment.blade.php +++ b/resources/views/dashboard/appointment.blade.php @@ -1549,6 +1549,7 @@ const apps = data.all_appoinments; const tx = data.all_tx_curr; const missed = data.client_missed; + console.log(missed); appGender(data.appointment_gender); appAge(data.appointment_age); appMarital(data.appointment_marital); @@ -1640,136 +1641,134 @@ tx_curr = parseInt(tx[x].tx_cur).toLocaleString(); } + let app_missed = 0; + let consent_app = 0; + let consent_missed = 0; + let consent_defaulted = 0; + let consent_iit = 0; + let sms = 0; + let sms_missed = 0; + let sms_defaulted = 0; + let sms_iit = 0; + let contacted = 0; + let contacted_missed = 0; + let contacted_defaulted = 0; + let contacted_iit = 0; + let traced = 0; + let traced_missed = 0; + let traced_defaulted = 0; + let traced_iit = 0; + let outcome = 0; + let outcome_missed = 0; + let outcome_defaulted = 0; + let outcome_iit = 0; for (var x = 0; x < missed.length; x++) { - app_missed = missed[x].not_kept_app; - if (app_missed == undefined || app_missed == null) { - app_missed = 0; + if (missed[x].not_kept_app > 0) { + app_missed++; } else { - app_missed = app_missed.toLocaleString(); + app_missed; } - consent_app = parseInt(missed[x].consent); - if (consent_app == undefined || consent_app == null) { - consent_app = 0; + if (missed[x].consent > 0) { + consent_app++; } else { - consent_app = consent_app.toLocaleString(); + consent_app; } - consent_missed = parseInt(missed[x].missed_consent); - if (consent_missed == undefined || consent_missed == null) { - consent_missed = 0; + if (missed[x].missed_consent > 0) { + consent_missed++; } else { - consent_missed = consent_missed.toLocaleString(); + consent_missed; } - consent_defaulted = parseInt(missed[x].defaulted_consent); - if (consent_defaulted == undefined || consent_defaulted == null) { - consent_defaulted = 0; + if (missed[x].defaulted_consent > 0) { + consent_defaulted++; } else { - consent_defaulted = consent_defaulted.toLocaleString(); + consent_defaulted; } - consent_iit = parseInt(missed[x].iit_consent); - if (consent_iit == undefined || consent_iit == null) { - consent_iit = 0; + if (missed[x].iit_consent > 0) { + consent_iit++; } else { - consent_iit = consent_iit.toLocaleString(); + consent_iit; } - sms = missed[x].messages; - if (sms == undefined || sms == null) { - sms = 0; + if (missed[x].messages > 0) { + sms++; } else { - sms = sms.toLocaleString(); + sms; } - sms_missed = parseInt(missed[x].missed_messages); - if (sms_missed == undefined || sms_missed == null) { - sms_missed = 0; + if (missed[x].missed_messages > 0) { + sms_missed++; } else { - sms_missed = sms_missed.toLocaleString(); + sms_missed; } - sms_defaulted = parseInt(missed[x].defaulted_messages); - if (sms_defaulted == undefined || sms_defaulted == null) { - sms_defaulted = 0; + if (missed[x].defaulted_messages > 0) { + sms_defaulted++; } else { - sms_defaulted = sms_defaulted.toLocaleString(); + sms_defaulted; } - sms_iit = parseInt(missed[x].iit_messages); - if (sms_iit == undefined || sms_iit == null) { - sms_iit = 0; + if (missed[x].iit_messages > 0) { + sms_iit++; } else { - sms_iit = sms_iit.toLocaleString(); + sms_iit; } - - contacted = missed[x].called; - if (contacted == undefined || contacted == null) { - contacted = 0; + if (missed[x].called > 0) { + contacted++; } else { - contacted = contacted.toLocaleString(); + contacted; } - contacted_missed = parseInt(missed[x].missed_called); - if (contacted_missed == undefined || contacted_missed == null) { - contacted_missed = 0; + if (missed[x].missed_called > 0) { + contacted_missed++; } else { - contacted_missed = contacted_missed.toLocaleString(); + contacted_missed; } - contacted_defaulted = parseInt(missed[x].defaulted_called); - if (contacted_defaulted == undefined || contacted_defaulted == null) { - contacted_defaulted = 0; + if (missed[x].defaulted_called > 0) { + contacted_defaulted++; } else { - contacted_defaulted = contacted_defaulted.toLocaleString(); + contacted_defaulted; } - contacted_iit = parseInt(missed[x].iit_called); - if (contacted_iit == undefined || contacted_iit == null) { - contacted_iit = 0; + if (missed[x].iit_called > 0) { + contacted_iit++; } else { - contacted_iit = contacted_iit.toLocaleString(); + contacted_iit; } - - traced = missed[x].physically_traced; - if (traced == undefined || traced == null) { - traced = 0; + if (missed[x].physically_traced > 0) { + traced++; } else { - traced = traced.toLocaleString(); + traced; } - traced_missed = parseInt(missed[x].missed_traced); - if (traced_missed == undefined || traced_missed == null) { - traced_missed = 0; + if (missed[x].missed_traced > 0) { + traced_missed++; } else { - traced_missed = traced_missed.toLocaleString(); + traced_missed; } - traced_defaulted = parseInt(missed[x].defaulted_traced); - if (traced_defaulted == undefined || traced_defaulted == null) { - traced_defaulted = 0; + if (missed[x].defaulted_traced > 0) { + traced_defaulted++; } else { - traced_defaulted = traced_defaulted.toLocaleString(); + traced_defaulted; } - traced_iit = parseInt(missed[x].iit_traced); - if (traced_iit == undefined || traced_iit == null) { - traced_iit = 0; + if (missed[x].iit_traced > 0) { + traced_iit++; } else { - traced_iit = traced_iit.toLocaleString(); + traced_iit; } - - outcome = parseInt(missed[x].final_outcome); - if (outcome == undefined || outcome == null) { - outcome = 0; + if (missed[x].final_outcome > 0) { + outcome++; } else { - outcome = outcome.toLocaleString(); + outcome; } - outcome_missed = parseInt(missed[x].missed_outcome); - if (outcome_missed == undefined || outcome_missed == null) { - outcome_missed = 0; + if (missed[x].missed_outcome > 0) { + outcome_missed++; } else { - outcome_missed = outcome_missed.toLocaleString(); + outcome_missed; } - outcome_defaulted = parseInt(missed[x].defaulted_outcome); - if (outcome_defaulted == undefined || outcome_defaulted == null) { - outcome_defaulted = 0; + if (missed[x].defaulted_outcome > 0) { + outcome_defaulted++; } else { - outcome_defaulted = outcome_defaulted.toLocaleString(); + outcome_defaulted; } - outcome_iit = parseInt(missed[x].iit_outcome); - if (outcome_iit == undefined || outcome_iit == null) { - outcome_iit = 0; + if (missed[x].iit_outcome > 0) { + outcome_iit++; } else { - outcome_iit = outcome_iit.toLocaleString(); + outcome_iit; } + } $("#tx_curr").html(tx_curr); $("#consented").html(consented); @@ -1867,7 +1866,7 @@ missedGender(data.missed_gender); missedMarital(data.missed_marital); if (authenticated == 'Facility') { - // $('#table_client')[0].reset(); + // $('#table_client')[0].reset(); // $("tbody").html(""); // $.each(data.client_app_list, function(index, value) { // var row = $("" + @@ -1957,136 +1956,132 @@ } } + let app_missed = 0; + let consent_app = 0; + let consent_missed = 0; + let consent_defaulted = 0; + let consent_iit = 0; + let sms = 0; + let sms_missed = 0; + let sms_defaulted = 0; + let sms_iit = 0; + let contacted = 0; + let contacted_missed = 0; + let contacted_defaulted = 0; + let contacted_iit = 0; + let traced = 0; + let traced_missed = 0; + let traced_defaulted = 0; + let traced_iit = 0; + let outcome = 0; + let outcome_missed = 0; + let outcome_defaulted = 0; + let outcome_iit = 0; for (var x = 0; x < missed.length; x++) { - app_missed = missed[x].not_kept_app; - if (app_missed == undefined || app_missed == null) { - app_missed = 0; + if (missed[x].not_kept_app > 0) { + app_missed++; } else { - app_missed = app_missed.toLocaleString(); + app_missed; } - consent_app = missed[x].consent; - if (consent_app == undefined || consent_app == null) { - consent_app = 0; + if (missed[x].consent > 0) { + consent_app++; } else { - consent_app = consent_app.toLocaleString(); + consent_app; } - consent_missed = missed[x].missed_consent; - if (consent_missed == undefined || consent_missed == null) { - consent_missed = 0; + if (missed[x].missed_consent > 0) { + consent_missed++; } else { - consent_missed = consent_missed.toLocaleString(); + consent_missed; } - consent_defaulted = missed[x].defaulted_consent; - if (consent_defaulted == undefined || consent_defaulted == null) { - consent_defaulted = 0; + if (missed[x].defaulted_consent > 0) { + consent_defaulted++; } else { - consent_defaulted = consent_defaulted.toLocaleString(); + consent_defaulted; } - consent_iit = missed[x].iit_consent; - if (consent_iit == undefined || consent_iit == null) { - consent_iit = 0; + if (missed[x].iit_consent > 0) { + consent_iit++; } else { - consent_iit = consent_iit.toLocaleString(); + consent_iit; } - sms = missed[x].messages; - if (sms == undefined || sms == null) { - sms = 0; + if (missed[x].messages > 0) { + sms++; } else { - sms = sms.toLocaleString(); + sms; } - sms_missed = missed[x].missed_messages; - if (sms_missed == undefined || sms_missed == null) { - sms_missed = 0; + if (missed[x].missed_messages > 0) { + sms_missed++; } else { - sms_missed = sms_missed.toLocaleString(); + sms_missed; } - sms_defaulted = missed[x].defaulted_messages; - if (sms_defaulted == undefined || sms_defaulted == null) { - sms_defaulted = 0; + if (missed[x].defaulted_messages > 0) { + sms_defaulted++; } else { - sms_defaulted = sms_defaulted.toLocaleString(); + sms_defaulted; } - sms_iit = missed[x].iit_messages; - if (sms_iit == undefined || sms_iit == null) { - sms_iit = 0; + if (missed[x].iit_messages > 0) { + sms_iit++; } else { - sms_iit = sms_iit.toLocaleString(); + sms_iit; } - - contacted = missed[x].called; - if (contacted == undefined || contacted == null) { - contacted = 0; + if (missed[x].called > 0) { + contacted++; } else { - contacted = contacted.toLocaleString(); + contacted; } - contacted_missed = missed[x].missed_called; - if (contacted_missed == undefined || contacted_missed == null) { - contacted_missed = 0; + if (missed[x].missed_called > 0) { + contacted_missed++; } else { - contacted_missed = contacted_missed.toLocaleString(); + contacted_missed; } - contacted_defaulted = missed[x].defaulted_called; - if (contacted_defaulted == undefined || contacted_defaulted == null) { - contacted_defaulted = 0; + if (missed[x].defaulted_called > 0) { + contacted_defaulted++; } else { - contacted_defaulted = contacted_defaulted.toLocaleString(); + contacted_defaulted; } - contacted_iit = missed[x].iit_called; - if (contacted_iit == undefined || contacted_iit == null) { - contacted_iit = 0; + if (missed[x].iit_called > 0) { + contacted_iit++; } else { - contacted_iit = contacted_iit.toLocaleString(); + contacted_iit; } - - - traced = missed[x].physically_traced; - if (traced == undefined || traced == null) { - traced = 0; + if (missed[x].physically_traced > 0) { + traced++; } else { - traced = traced.toLocaleString(); + traced; } - traced_missed = missed[x].missed_traced; - if (traced_missed == undefined || traced_missed == null) { - traced_missed = 0; + if (missed[x].missed_traced > 0) { + traced_missed++; } else { - traced_missed = traced_missed.toLocaleString(); + traced_missed; } - traced_defaulted = missed[x].defaulted_traced; - if (traced_defaulted == undefined || traced_defaulted == null) { - traced_defaulted = 0; + if (missed[x].defaulted_traced > 0) { + traced_defaulted++; } else { - traced_defaulted = traced_defaulted.toLocaleString(); + traced_defaulted; } - traced_iit = missed[x].iit_traced; - if (traced_iit == undefined || traced_iit == null) { - traced_iit = 0; + if (missed[x].iit_traced > 0) { + traced_iit++; } else { - traced_iit = traced_iit.toLocaleString(); + traced_iit; } - - outcome = missed[x].final_outcome; - if (outcome == undefined || outcome == null) { - outcome = 0; + if (missed[x].final_outcome > 0) { + outcome++; } else { - outcome = outcome.toLocaleString(); + outcome; } - outcome_missed = missed[x].missed_outcome; - if (outcome_missed == undefined || outcome_missed == null) { - outcome_missed = 0; + if (missed[x].missed_outcome > 0) { + outcome_missed++; } else { - outcome_missed = outcome_missed.toLocaleString(); + outcome_missed; } - outcome_defaulted = missed[x].defaulted_outcome; - if (outcome_defaulted == undefined || outcome_defaulted == null) { - outcome_defaulted = 0; + if (missed[x].defaulted_outcome > 0) { + outcome_defaulted++; } else { - outcome_defaulted = outcome_defaulted.toLocaleString(); + outcome_defaulted; } - outcome_iit = missed[x].iit_outcome; - if (outcome_iit == undefined || outcome_iit == null) { - outcome_iit = 0; + if (missed[x].iit_outcome > 0) { + outcome_iit++; } else { - outcome_iit = outcome_iit.toLocaleString(); + outcome_iit; } } From dcc887cf7aef0992995afd1a1096ca4eeb417411 Mon Sep 17 00:00:00 2001 From: Ronald-pro <36841157+Ronald-pro@users.noreply.github.com> Date: Tue, 7 Mar 2023 16:51:37 +0300 Subject: [PATCH 164/171] reverted iit to ltfu and cards single color code --- .../Controllers/FinalDashboardController.php | 59 ++++++++++--------- .../views/dashboard/appointment.blade.php | 22 ++++--- 2 files changed, 43 insertions(+), 38 deletions(-) diff --git a/app/Http/Controllers/FinalDashboardController.php b/app/Http/Controllers/FinalDashboardController.php index 83fb5cc..e4393ab 100644 --- a/app/Http/Controllers/FinalDashboardController.php +++ b/app/Http/Controllers/FinalDashboardController.php @@ -188,20 +188,21 @@ public function appointment() ->where('mfl_code', Auth::user()->facility_id) ->orderBy('percent_kept', 'DESC') ->groupBy('marital'); - $client_list = DB::table('etl_client_detail')->select( - 'etl_client_detail.upi_no', - 'etl_client_detail.ccc_number', - 'etl_client_detail.dob', - 'etl_client_detail.consented', - 'etl_client_detail.client_status', - 'etl_client_detail.client_name', - 'etl_client_detail.phone_no', - DB::raw('COUNT(etl_appointment_detail.app_kept) AS kept_app '), - DB::raw('SUM(etl_appointment_detail.app_not_kept) AS not_kept_app ') - ) - ->join('etl_appointment_detail', 'etl_client_detail.client_id', '=', 'etl_appointment_detail.client_id') - ->where('etl_client_detail.mfl_code', Auth::user()->facility_id) - ->groupBy('etl_appointment_detail.client_id'); + $client_list = DB::table('etl_client_detail')->select( + 'etl_client_detail.upi_no', + 'etl_client_detail.ccc_number', + 'etl_client_detail.dob', + 'etl_client_detail.consented', + 'etl_client_detail.client_status', + 'etl_client_detail.client_name', + 'etl_client_detail.dsd_status', + 'etl_client_detail.phone_no', + DB::raw('COUNT(etl_appointment_detail.app_kept) AS kept_app '), + DB::raw('SUM(etl_appointment_detail.app_not_kept) AS not_kept_app ') + ) + ->join('etl_appointment_detail', 'etl_client_detail.client_id', '=', 'etl_appointment_detail.client_id') + ->where('etl_client_detail.mfl_code', Auth::user()->facility_id) + ->groupBy('etl_appointment_detail.client_id'); $appointment_county = ETLAppointment::select( 'county', DB::raw('SUM(app_kept) AS kept_app '), @@ -1547,21 +1548,21 @@ public function filter_data(Request $request) ->whereNotNull('marital') ->where('mfl_code', Auth::user()->facility_id) ->groupBy('marital'); - $client_list = DB::table('etl_client_detail')->select( - 'etl_client_detail.upi_no', - 'etl_client_detail.ccc_number', - 'etl_client_detail.dob', - 'etl_client_detail.consented', - 'etl_client_detail.client_status', - 'etl_client_detail.client_name', - 'etl_client_detail.dsd_status', - 'etl_client_detail.phone_no', - DB::raw('COUNT(etl_appointment_detail.app_kept) AS kept_app '), - DB::raw('SUM(etl_appointment_detail.app_not_kept) AS not_kept_app ') - ) - ->join('etl_appointment_detail', 'etl_client_detail.client_id', '=', 'etl_appointment_detail.client_id') - ->where('etl_client_detail.mfl_code', Auth::user()->facility_id) - ->groupBy('etl_appointment_detail.client_id'); + $client_list = DB::table('etl_client_detail')->select( + 'etl_client_detail.upi_no', + 'etl_client_detail.ccc_number', + 'etl_client_detail.dob', + 'etl_client_detail.consented', + 'etl_client_detail.client_status', + 'etl_client_detail.client_name', + 'etl_client_detail.dsd_status', + 'etl_client_detail.phone_no', + DB::raw('COUNT(etl_appointment_detail.app_kept) AS kept_app '), + DB::raw('SUM(etl_appointment_detail.app_not_kept) AS not_kept_app ') + ) + ->join('etl_appointment_detail', 'etl_client_detail.client_id', '=', 'etl_appointment_detail.client_id') + ->where('etl_client_detail.mfl_code', Auth::user()->facility_id) + ->groupBy('etl_appointment_detail.client_id'); $appointment_county = ETLAppointment::select( 'county', DB::raw('SUM(app_kept) AS kept_app '), diff --git a/resources/views/dashboard/appointment.blade.php b/resources/views/dashboard/appointment.blade.php index a1e03a9..2289e21 100644 --- a/resources/views/dashboard/appointment.blade.php +++ b/resources/views/dashboard/appointment.blade.php @@ -22,7 +22,7 @@ .Booked { - background: #8AC53E; + background: #369FFF; border: 1px solid #E5F7FF; border-radius: 10px; @@ -30,7 +30,7 @@ .Consented { - background: #FF993A; + background: #369FFF; box-shadow: 0px 10px 30px rgba(184, 146, 222, 0.4); border-radius: 10px; @@ -54,7 +54,7 @@ .Future { - background: #8AC53E; + background: #369FFF; border: 1px solid #E5F7FF; border-radius: 10px; @@ -62,7 +62,7 @@ .Not_Kept { - background: #FF993A; + background: #369FFF; box-shadow: 0px 10px 30px rgba(184, 146, 222, 0.4); border-radius: 10px; @@ -948,7 +948,7 @@
    - IIT + LTFU
    @@ -976,7 +976,7 @@
    - IIT + LTFU

    @@ -1008,7 +1008,7 @@
    - IIT + LTFU

    @@ -1036,7 +1036,7 @@
    - IIT + LTFU

    @@ -1065,7 +1065,7 @@
    - IIT + LTFU

    @@ -1304,6 +1304,8 @@ placeholder: "Site Type" }); + + $(document).ready(function() { $('select[name="partner"]').on('change', function() { var partnerID = $(this).val(); @@ -2132,6 +2134,8 @@ }); + + $('#table_missed').DataTable({ columnDefs: [{ targets: [0], From 2fa156650cf6760549a8e10a997b4af33c5dc8da Mon Sep 17 00:00:00 2001 From: Ronald-pro <36841157+Ronald-pro@users.noreply.github.com> Date: Tue, 7 Mar 2023 22:00:35 +0300 Subject: [PATCH 165/171] commented out previous app dashboards --- .../layouts/large-vertical-sidebar/sidebar.blade.php | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/resources/views/layouts/large-vertical-sidebar/sidebar.blade.php b/resources/views/layouts/large-vertical-sidebar/sidebar.blade.php index 1793b48..3e4afa5 100644 --- a/resources/views/layouts/large-vertical-sidebar/sidebar.blade.php +++ b/resources/views/layouts/large-vertical-sidebar/sidebar.blade.php @@ -233,7 +233,7 @@ @if (Auth::user()->access_level == 'Admin' || Auth::user()->access_level == 'Partner' || Auth::user()->access_level == 'Donor' || Auth::user()->access_level == 'County' || Auth::user()->access_level == 'Sub County') -