Skip to content

Commit

Permalink
Merge pull request #18 from RUGSoftEng/development
Browse files Browse the repository at this point in the history
Sprint end pull request.
  • Loading branch information
Daanra authored May 22, 2018
2 parents 91a6a99 + 3ce6588 commit 2f7432f
Show file tree
Hide file tree
Showing 445 changed files with 309,386 additions and 333 deletions.
2 changes: 2 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,5 @@ PUSHER_APP_CLUSTER=mt1

MIX_PUSHER_APP_KEY="${PUSHER_APP_KEY}"
MIX_PUSHER_APP_CLUSTER="${PUSHER_APP_CLUSTER}"

EVIDENCIO_KEY=
14 changes: 10 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,17 @@ A more detailed description is available in the Requirements Document under the

Follow the instructions in the [Laravel documentation](https://laravel.com/docs/5.6/installation) to install required dependencies and the Laravel package itself.

Clone the repository and create your own `.env` file by copying `.env.example` and providing necessary data. Then run these commands inside the repository:
Clone the repository and create your own `.env` file by copying `.env.example` and providing necessary data. Please provide Evidencio API key here as well. Then run these commands inside the repository:

composer install
php artisan key:generate

To create the database structure please run the following command:

php artisan migrate

You will also need to run it every time there is a new database migration available.

### How to run

Run the following command:
Expand All @@ -25,15 +31,15 @@ Run the following command:
### Troubleshooting


#### NOTE: in Windows, this server will run from a command prompt.
#### NOTE: in Windows, this server will run from a command prompt.
If you are using Apache through XAMPP (**maybe** even without XAMPP), you can change the following file:

XAMPP\apache\conf\httpd.conf
(If not through XAMPP, then in the respective apache directory)
(If not through XAMPP, then in the respective apache directory)
Under the DocumentRoot setting in the file, you need to change the line:

C:\xampp\htdocs

into:

yourDirectory\2018-Evidencio\public
Expand Down
29 changes: 29 additions & 0 deletions app/CommentReply.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?php

namespace App;

use Illuminate\Database\Eloquent\Model;

/**
* Reply written to a VerificationComment
*
* @property timestamp created_at
* @property string text
*/
class CommentReply extends Model
{
protected $table = 'comment_replies';
public $timestamps = false;

protected $fillable = ['text'];

public function author()
{
return $this->belongsTo('App\User','author_id');
}

public function verificationComment()
{
return $this->belongsTo('App\VerificationComment','verification_comment_id');
}
}
96 changes: 96 additions & 0 deletions app/EvidencioAPI.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
<?php

namespace App;

use Exceptions\JsonDecodeException;

class EvidencioAPI
{
/**
* Helper method to perform an API call
* @param string $path URL to the call without leading "https://www.evidencio.com/api/"
* @param array $params list of parameters as a key-value array
* @return array API response converted into a PHP variable
* @throws JsonDecodeException if JSON response could not be decoded
* Other possible exceptions are listed in Guzzle's documentation
*/
private static function fetch($path, $params = [])
{
$client = new \GuzzleHttp\Client(['base_uri' => 'https://www.evidencio.com/api/']);
$res = $client->post($path,
[
'headers' => [
'Accept' => 'application/json',
'Authorization' => config('app.evidencio_key')
],
'form_params' => $params
]);

$json = json_decode($res->getBody(),true);

if(is_null($json))
{
throw new JsonDecodeException($res->getBody());
}
return $json;
}

/**
* Get basic Evidencio model statistics
* @return array decoded JSON containing number of models that you are
* authorised to use and number of your own models (created using that API key)
*/
public static function overview()
{
return self::fetch("overview");
}

/**
* Search fro Evidencio models
* @param string $query phrase to search for
* @return array decoded JSON containing all the Evidencio models (with all
* their data) matching the phrase
*/
public static function search($query)
{
return self::fetch("search",["query" => $query]);
}

/**
* Get all Evidencio models
* @return array decoded JSON containing all Evidencio models with all their data
*/
public static function models()
{
return self::fetch("models");
}

/**
* Get Evidencio model
* @param int $id requested Evidencio model id
* @return array decoded JSON containing requested Evidencio model data
*/
public static function getModel($id)
{
return self::fetch("model",["id" => $id]);
}

/**
* Run Evidencio model
* @param int $id Evidencio model id
* @param array $values a key-value array containing Evidencio model variable
* ids and their corresponding values
* @return array decoded JSON containing the result and additional information
*/
public static function run($id,$values)
{
foreach ($values as $value) {
if (is_numeric($value)) {
$value = floatval($value);
}
}
$values["id"] = $id;
return self::fetch("run",$values);
}

}
20 changes: 20 additions & 0 deletions app/Exceptions/JsonDecodeException.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?php

namespace App\Exceptions;

use Exception;

class JsonDecodeException extends Exception {

/*
* @param $response the code that could not be decoded
* @see Exception
*/
public function __construct($response, $code = 0, Exception $previous = null) {

$message = "Could not decode API response to JSON: '".$response."'.";

parent::__construct($message, $code, $previous);
}

}
53 changes: 53 additions & 0 deletions app/Field.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
<?php

namespace App;

use Illuminate\Database\Eloquent\Model;

/**
* Fields that are provided in an input step. They can be either categorical
* (then they contain a number of options and have empty continuous attributes)
* or continuous (they provide additional attributes)
*
* @property string friendly_title Title that is friendly to a patient
* @property string friendly_description Description that is friendly to a patient
* @property int continuous_field_max Maximum input value (Applies only to
* continuous fields)
* @property int continuous_field_min Minimum input value (Applies only to
* continuous fields)
* @property int continuous_field_step_by Interval between possible input values
* (Applies only to continuous fields)
* @property int continuous_field_unit Unit of the value (kilograms, years, etc.)
* (Applies only to continuous fields)
* @property int evidencio_variable_id Evidencio API variable id associated with
* this field in the designer page
*/
class Field extends Model
{
public $timestamps = false;

protected $fillable = [
'evidencio_variable_id','friendly_title','friendly_description','continuous_field_max','continuous_field_min','continuous_field_step_by','continuous_field_unit'
];

/**
* Possible options of a field (Applies only to categorical fields)
*/
public function options()
{
return $this->hasMany('App\Option','categorical_field_id');
}

/**
* Input steps that have this field
*/
public function inputSteps()
{
return $this->belongsToMany('App\Step','field_in_input_steps','field_id','input_step_id');
}

public function usedInRunsInSteps()
{
return $this->belongsToMany('App\Step','model_run_field_mappings','field_id','step_id');
}
}
7 changes: 6 additions & 1 deletion app/Http/Controllers/Auth/RegisterController.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ protected function validator(array $data)
{
return Validator::make($data, [
'name' => 'required|string|max:255',
'first_name' => 'required|string|max:30',
'last_name' => 'required|string|max:30',
'email' => 'required|string|email|max:255|unique:users',
'password' => 'required|string|min:6|confirmed',
]);
Expand All @@ -65,8 +67,11 @@ protected function create(array $data)
{
return User::create([
'name' => $data['name'],
'first_name' => $data['first_name'],
'last_name' => $data['last_name'],
'language_code' => 'en',
'email' => $data['email'],
'password' => Hash::make($data['password']),
'password' => Hash::make($data['password'])
]);
}
}
Loading

0 comments on commit 2f7432f

Please sign in to comment.