diff --git a/.env.example b/.env.example index 4452475..a0dace5 100644 --- a/.env.example +++ b/.env.example @@ -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 diff --git a/app/Http/Controllers/RapidTestController.php b/app/Http/Controllers/RapidTestController.php new file mode 100644 index 0000000..4c79827 --- /dev/null +++ b/app/Http/Controllers/RapidTestController.php @@ -0,0 +1,73 @@ +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]); + } + } + +} diff --git a/app/Http/Controllers/VaccineController.php b/app/Http/Controllers/VaccineController.php index 0dc71c5..bf9c7b2 100644 --- a/app/Http/Controllers/VaccineController.php +++ b/app/Http/Controllers/VaccineController.php @@ -34,6 +34,7 @@ public function distribution( $split = false ) { 'moderna', 'astrazeneca', 'johnson', + 'pfizer_biontech_paediatric', ]; // provinces diff --git a/app/RapidTest.php b/app/RapidTest.php new file mode 100644 index 0000000..d9d0df9 --- /dev/null +++ b/app/RapidTest.php @@ -0,0 +1,23 @@ + [ + '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'), diff --git a/database/migrations/2021_12_03_220411_add_pfizer_biontech_paediatric_to_vaccine_distribution_table.php b/database/migrations/2021_12_03_220411_add_pfizer_biontech_paediatric_to_vaccine_distribution_table.php new file mode 100644 index 0000000..0937f98 --- /dev/null +++ b/database/migrations/2021_12_03_220411_add_pfizer_biontech_paediatric_to_vaccine_distribution_table.php @@ -0,0 +1,34 @@ +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'); + }); + } +} diff --git a/routes/api.php b/routes/api.php index 30cb5db..9a66e2a 100644 --- a/routes/api.php +++ b/routes/api.php @@ -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');