Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

changes made to the read me to cater for windows users and also for an automated batch file #18

Open
wants to merge 22 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@ Homestead.json
/.idea
/_ide_helper.php
/storage/
composer.phar
3 changes: 3 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
language: php

services:
- mysql

php:
- 5.6
- 7.0
Expand Down
14 changes: 14 additions & 0 deletions AutoStart.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
@echo off
rem this is for windows users only
rem change the drive path to what suits your server
re
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this line is incorrect?



cd C:\path to folder\

start php artisan serve --host xx.xx.xx.xx --port 8000

rem auto display of the web browser
rem this will automatically open the application using your default set web browser

start http://xx.xx.xx.xx:8000
1 change: 1 addition & 0 deletions app/Http/Controllers/APIController.php
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,7 @@ public function getAllRemainingPrescriptions() {
}

$clinic = Clinic::getCurrentClinic();
// TODO Fix for large number of records
$prescriptions = Prescription::whereIn('patient_id', $clinic->patients()->lists('id'))
->where('issued', false)->orderBy('id')
->with('prescriptionDrugs.dosage', 'prescriptionDrugs.frequency', 'prescriptionPharmacyDrugs',
Expand Down
84 changes: 82 additions & 2 deletions app/Http/Controllers/PatientController.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,97 @@
use Illuminate\Support\Facades\Validator;

class PatientController extends Controller {

/**
* Get the patients list
* @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
*/
public function getPatientList() {
$clinic = Clinic::getCurrentClinic();
$patients = $clinic->patients;
return view('patients.patients', ['patients' => $patients]);
return view('patients.patients', ['patients' => []]);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We are returning an empty list here?

}


/**
* Get the patients list for data tables, server side processing
* @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
*/
public function listPatients(Request $request)
{
$clinic = Clinic::getCurrentClinic();

$draw = $request->query('draw');
$start = $request->query('start');
$length = $request->query('length');
$search = $request->query('search');
$order = $request->query('order');
$query = $search['value'];
$orderByColIdx = $order[0]["column"];
$orderByDirection = $order[0]["dir"];

$orderByCol = 'first_name';
if ($orderByColIdx == 2) {
$orderByCol = 'phone';
} else if ($orderByColIdx == 3) {
$orderByCol = 'address';
} else if ($orderByColIdx == 4) {
$orderByCol = 'dob';
$orderByDirection = $orderByDirection == 'asc' ? 'desc' : 'asc';
}

Log::debug("Draw -> $draw, Start-> $start, Length-> $length, OrderByColumn-> $orderByColIdx, Query-> $query");

$totalRecords = $clinic->patients()->count();
$filteredRecords = $totalRecords;

$patients = $clinic->patients();

if (!empty($query)) {
$patients = $patients->where(DB::raw('concat(first_name, " ", last_name)'), 'like', "%$query%");
$filteredRecords = $patients->count();
}

$patients = $patients->orderBy($orderByCol, $orderByDirection)
->skip($start)->take($length)->get();

$data = [];
foreach ($patients as $patient) {
$buttons = '';
if (\Gate::allows('delete', $patient)) {
$buttons = "
<button class=\"btn btn-sm btn-danger\" data-toggle=\"modal\"
data-target=\"#confirmDeletePatientModal\"
onclick=\"showConfirmDelete($patient->id,'$patient->first_name $patient->last_name')\">
<i class=\"fa fa-recycle fa-lg\" data-toggle=\"tooltip\"
data-placement=\"bottom\" title=\"\"
data-original-title=\"Delete this patient?
You won't be able to delete this patient if the patient has any records
associated to him/her in the system.\"></i>
</button>";
}

$row = [
$patient->id,
$patient->first_name . ' ' . $patient->last_name,
$patient->phone,
$patient->address,
\Utils::getAge($patient->dob),
$buttons
];

$data[] = $row;
}

$result = [
'draw' => $draw,
'recordsTotal' => $totalRecords,
'recordsFiltered' => $filteredRecords,
'data' => $data
];

return response()->json($result);
}

/**
* Adds a patient to the system
*
Expand Down
20 changes: 14 additions & 6 deletions app/Http/Controllers/UtilityController.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,17 +49,24 @@ public function getDashboard() {
}

$clinic = Clinic::getCurrentClinic();
$prescriptions = Prescription::whereIn('patient_id', $clinic->patients()->lists('id'));
$idList = $clinic->patients()->pluck('id')->toArray();

$prescriptions = collect();
$batch_size = 10000;
foreach (array_chunk($idList, $batch_size) as $idListBatch) {
$prescriptions = Prescription::whereIn('patient_id', $idListBatch)->get()->toBase()->merge($prescriptions);
}

$prescriptionCount = $prescriptions->where('issued', 1)->count();
$payments = Payment::whereIn('prescription_id',
$prescriptions->where('issued', 1)->lists('id'))->sum('amount');

$prescriptions->where('issued', 1)->pluck('id'))->sum('amount');
$stats = $this->calcClinicStats($clinic);

return view('dashboard', [
'clinic' => $clinic, 'prescriptionCount' => $prescriptionCount,
'payments' => $payments, 'stats' => $stats
'clinic' => $clinic,
'prescriptionCount' => $prescriptionCount,
'payments' => $payments,
'stats' => $stats
]);
}

Expand All @@ -79,7 +86,8 @@ private function calcClinicStats($clinic) {
];

$date = date('Y-m-d H:i:s', strtotime("-6 months"));
$patientIds = $clinic->patients()->lists('id')->toArray();
// $patientIds = $clinic->patients()->lists('id')->toArray();
$patientIds = [];
if (count($patientIds) > 0) {
$patientIds = implode(",", $patientIds);
$query = "SELECT MONTH(created_at) AS m,COUNT(*) AS c FROM `prescriptions` WHERE `patient_id`
Expand Down
2 changes: 1 addition & 1 deletion app/Http/routes.php
Original file line number Diff line number Diff line change
Expand Up @@ -101,10 +101,10 @@
*/
Route::group(['prefix' => 'patients'], function () {
Route::get('/', ['as' => 'patients', 'uses' => 'PatientController@getPatientList']);

/*
* PATIENTS
*/
Route::get('/list', ['as' => 'listPatients', 'uses' => 'PatientController@listPatients']);
Route::post('addPatient', ['as' => 'addPatient', 'uses' => 'PatientController@addPatient']);
Route::get('patient/{id}', ['as' => 'patient', 'uses' => 'PatientController@getPatient']);
Route::any('deletePatient/{id}', ['as' => 'deletePatient', 'uses' => 'PatientController@deletePatient']);
Expand Down
12 changes: 12 additions & 0 deletions database/seeds/PatientTableSeeder.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,17 @@ public function run()
});
}
}

// Uncomment for large number of patient records.
// $clinic = \App\Clinic::find(1);
//
// foreach ($clinic->users as $user) {
// //add patients to the clinic
// factory(App\Patient::class, 100000)->make()->each(function (\App\Patient $patient) use ($clinic, $user) {
// $patient->creator()->associate($user);
// $patient->clinic()->associate($clinic);
// $patient->save();
// });
// }
}
}
177 changes: 177 additions & 0 deletions docs/chr247.postman_collection.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,177 @@
{
"info": {
"_postman_id": "183abd2f-a810-4516-8714-9dc61610368e",
"name": "chr247",
"description": "chr247 APIs and pages",
"schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json"
},
"item": [
{
"name": "Login",
"event": [
{
"listen": "test",
"script": {
"id": "7c782fb2-28cd-430d-85f6-080c38d79121",
"exec": [
"pm.test(\"Status code is 200\", function () {",
" pm.response.to.have.status(200);",
" pm.response.to.be.withBody;",
"});",
"",
"pm.test(\"Check cookies\", function() {",
" pm.expect(pm.cookies.has(\"XSRF-TOKEN\")).to.be.true;",
" pm.expect(pm.cookies.has(\"chr247_session\")).to.be.true;",
"});",
"",
"pm.environment.set(\"xsrf_token\", pm.cookies.get(\"XSRF-TOKEN\"));",
"pm.environment.set(\"session\", pm.cookies.get(\"chr247_session\"));",
""
],
"type": "text/javascript"
}
}
],
"request": {
"method": "GET",
"header": [],
"url": {
"raw": "{{chr247_url}}/login",
"host": [
"{{chr247_url}}"
],
"path": [
"login"
]
}
},
"response": []
},
{
"name": "Login",
"event": [
{
"listen": "test",
"script": {
"id": "fee7c243-2c36-4ea3-adba-b832fd446f70",
"exec": [
"pm.test(\"Status code is 200\", function () {",
" pm.response.to.have.status(200);",
" pm.response.to.be.withBody;",
"});",
"",
""
],
"type": "text/javascript"
}
}
],
"request": {
"method": "POST",
"header": [],
"body": {
"mode": "formdata",
"formdata": [
{
"key": "password",
"value": "{{password}}",
"type": "text"
},
{
"key": "username",
"value": "{{username}}",
"type": "text"
}
]
},
"url": {
"raw": "{{chr247_url}}/login",
"host": [
"{{chr247_url}}"
],
"path": [
"login"
]
}
},
"response": []
},
{
"name": "List Patients",
"request": {
"method": "GET",
"header": [],
"url": {
"raw": "{{chr247_url}}/patients/list?order[0][column]=1&order[0][dir]=asc&start=0&length=10&search[value]=a&search[regex]=false&draw=1",
"host": [
"{{chr247_url}}"
],
"path": [
"patients",
"list"
],
"query": [
{
"key": "order[0][column]",
"value": "1"
},
{
"key": "order[0][dir]",
"value": "asc"
},
{
"key": "start",
"value": "0"
},
{
"key": "length",
"value": "10"
},
{
"key": "search[value]",
"value": "a"
},
{
"key": "search[regex]",
"value": "false"
},
{
"key": "draw",
"value": "1"
}
]
},
"description": "API used by data tables to paginate and load patients"
},
"response": []
}
],
"event": [
{
"listen": "prerequest",
"script": {
"id": "96ee9cc0-96a5-4fcd-b677-b47f58005cf0",
"type": "text/javascript",
"exec": [
"if(pm.environment.has(\"xsrf_token\")) {",
" pm.request.headers.add({",
" key: \"X-XSRF-TOKEN\",",
" value: \"{{xsrf_token}}\"",
" });",
"}"
]
}
},
{
"listen": "test",
"script": {
"id": "3a1eba76-6c9a-4497-8931-ab05d5115ff3",
"type": "text/javascript",
"exec": [
""
]
}
}
],
"protocolProfileBehavior": {}
}
Loading