Skip to content

Commit

Permalink
Merge pull request #107 from andrewthong/development
Browse files Browse the repository at this point in the history
Rapid test submission
  • Loading branch information
andrewthong authored Jan 4, 2022
2 parents e00db9b + 07738fb commit a1cab81
Show file tree
Hide file tree
Showing 9 changed files with 310 additions and 2 deletions.
6 changes: 6 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,12 @@ DB_DATABASE=laravel
DB_USERNAME=root
DB_PASSWORD=

MONGODB_HOST=127.0.0.1
MONGODB_PORT=27017
MONGODB_DATABASE=laravel
MONGODB_USERNAME=root
MONGODB_PASSWORD=

BROADCAST_DRIVER=log
CACHE_DRIVER=file
QUEUE_CONNECTION=sync
Expand Down
73 changes: 73 additions & 0 deletions app/Http/Controllers/RapidTestController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;

use App\RapidTest;

class RapidTestController extends Controller
{

public function submit(Request $request)
{

// simple validation; not using validator
$errors = [];

$fields = [
'age',
'postal_code',
'test_date',
'test_result',
];

foreach( $fields as $field ) {
if( !$request->has( $field ) ) {
$errors []= 'Missing '.$field;
}
}

// validate age (5 characters)
if( $request->has('age') ) {
$age = substr(trim($request->age), 0, 5);
}

// 3-char postal code
if( $request->has('postal_code') ) {
$postal_code = strtoupper(substr(trim($request->postal_code), 0, 3));
}

// validate date
if( $request->has('test_date') ) {
$test_date = substr(trim($request->test_date), 0, 10);
if( !preg_match('/^[0-9]{4}-[0-1][0-9]-[0-3][0-9]$/', $test_date) ) {
$errors []= 'Invalid date';
}
}

// validate result
if( $request->has('test_result') ) {
$test_result = strtolower(trim($request->test_result));
if( !in_array($test_result, ['positive', 'negative', 'invalid result']) ) {
$errors []= 'Invalid test result';
}
}

// check for errors
if( empty( $errors ) ) {
$record = new RapidTest;
$record->age = $age;
$record->postal_code = $postal_code;
$record->test_date = $test_date;
$record->test_result = $test_result;
// save
$record->save();
return response()->json(['created' => true]);
} else {
// return errors
return response()->json(['created' => false, 'errors' => $errors]);
}
}

}
1 change: 1 addition & 0 deletions app/Http/Controllers/VaccineController.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ public function distribution( $split = false ) {
'moderna',
'astrazeneca',
'johnson',
'pfizer_biontech_paediatric',
];

// provinces
Expand Down
23 changes: 23 additions & 0 deletions app/RapidTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?php

namespace App;

// mongoDB
use Jenssegers\Mongodb\Eloquent\Model;

class RapidTest extends Model
{
protected $connection = 'mongodb';

protected $collection = 'rapid_tests';

protected $dates = ['test_date'];

protected $fillable = [
'age',
'postal_code',
'test_date',
'test_result',
];

}
2 changes: 2 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,11 @@
"flynsarmy/csv-seeder": "2.*",
"fruitcake/laravel-cors": "^1.0",
"guzzlehttp/guzzle": "^7.0.1",
"jenssegers/mongodb": "^3.8",
"laravel/framework": "^8.0",
"laravel/passport": "^10.0",
"laravel/tinker": "^2.0",
"mongodb/mongodb": "^1.6",
"spatie/laravel-permission": "^3.17"
},
"require-dev": {
Expand Down
158 changes: 156 additions & 2 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 12 additions & 0 deletions config/database.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,18 @@
]) : [],
],

'mongodb' => [
'driver' => 'mongodb',
'host' => env('MONGODB_HOST', '127.0.0.1'),
'port' => env('MONGODB_PORT', 27017),
'database' => env('MONGODB_DATABASE', 'homestead'),
'username' => env('MONGODB_USERNAME', 'homestead'),
'password' => env('MONGODB_PASSWORD', 'secret'),
'options' => [
'database' => env('MONGODB_AUTHENTICATION_DATABASE', 'admin'),
],
],

'pgsql' => [
'driver' => 'pgsql',
'url' => env('DATABASE_URL'),
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

class AddPfizerBiontechPaediatricToVaccineDistributionTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::table('vaccine_distribution', function (Blueprint $table) {
$table->integer('pfizer_biontech_paediatric')->nullable();
$table->integer('pfizer_biontech_paediatric_administered')->nullable();
});
}

/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::table('vaccine_distribution', function (Blueprint $table) {
$table->dropColumn('pfizer_biontech_paediatric');
$table->dropColumn('pfizer_biontech_paediatric_administered');
});
}
}
3 changes: 3 additions & 0 deletions routes/api.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,9 @@
Route::get('reports/sub-regions/summary', 'SubRegionReportController@summary');
Route::get('reports/sub-regions/{code}', 'SubRegionReportController@report')->where('code', '[A-Za-z0-9_]+');

// open submissions
Route::post('collect/rapid-test', 'RapidTestController@submit');

// partner-specific
// set env then php artisan config:clear
Route::get('_p/'.env('PARTNER01', 'none').'/report-hr-vaccination', 'PartnerReportController@getHealthRegionVaccineReport');
Expand Down

0 comments on commit a1cab81

Please sign in to comment.