-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #107 from andrewthong/development
Rapid test submission
- Loading branch information
Showing
9 changed files
with
310 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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]); | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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', | ||
]; | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
34 changes: 34 additions & 0 deletions
34
...ations/2021_12_03_220411_add_pfizer_biontech_paediatric_to_vaccine_distribution_table.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'); | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters