-
Notifications
You must be signed in to change notification settings - Fork 2
API, Back End and Back End Tests
id
is the treatment id
patient_id
is the foreign id of the user who has been assigned treatment
title is
the title of the treatment
notes
are any notes belonging to a treatment.
start_date
is the start date of the treatment
end_date
is the end date of the treatment
start_time
is the start time of the treatment
end_time
is the end time of the treatment
is_completed
is whether or not the treatment is completed by the patient, and is set to false
parent_id
is used to assign any treatments to a parent treatment using the self reference trait of the Treatment model
id
is the id of rules
treatment_id
is the foreign id that reference the id on the treatment table to which this rule belongs
freq
is the frequency of the recurrence of a treatment, there are currently 4 types, yearly, monthly, weekly, and daily
interval
is the gap needed in the frequency of the recurrence dates
max_num_of_occurrences
is the count of the dates in the array of the occurrences of all dates
day_of_week
is the day of the week, which is in json, but is cast as an array in the model to allow for all days, like Mo, Tu, We, and so on.
week_of_month
is the number of the week when the dates should recur.
day_of_month
is the date of the month when the dates should recur
month_of_year
is the month of the year when the dates should recur
Note: This schema handles the rules needed to generate the dates for a recurring treatment using the rlanvin/php-rrule
library that follows the RFC 5545 International Calendaring and Scheduling Core Object Specification. Please refer to rlanvin/php-rrule
library’s RRule Creation wiki page for further explanations. Its corresponding values are provided in the comments within the schema
This is a model for the treatments schema in migrations and it has a factory trait (Treatment Factory), refresh database that allows you to use the test database as enabled in phpunit.xml
for TreatmentTest
in Feature and Unit Tests.
It allows to define the path in the model for the specific id of the treatment.
This defines the treatment model relationship with the user model. Please see the Laravel’s ORM, Eloquent, to define relationships and their types.
This defines the treatment model relationship with the rule model. A treatment has only one rule, or recurrence rule.
This is the model for the rules schema and we cast the day_of_week
into arrays in the model. Rules also has a factory trait that allows you to create a dummy data.
This describes the relationship of the rules with the treatment. A rule belongs to a treatment.
Allows you to use the parent_id schema to assign a treatment as a parent to another treatment and use this relationship to call out a
$treatment->parent()
or
$treatment->children()
This defines the traditional methods for the controller that define the actions for the api resource for treatments.
An authenticated user can get the access of the treatments assigned to them.
It takes a post request in Json and an authenticated user can create treatments, when validated. The validation rules can be found in rules of Treatment Request, which is an extends the generic Request.
It returns the response for a specific treatment model.
The authenticated user’s treatment can be deleted.
Rules Controller has 4 traditional methods defined for the controller namely, index, store, destroy and update
You get the rule associated with a treatment.
You can store a rule for a specific treatment. If the request payload is missing the end_date, we assign a max_num_of_occurrences or a count to the rules, to avoid an infinite occurrence of dates. This could be handled more formally.
We delete a specific rule
We update the specific rule
Allows the authorized users and validated the request as per the rules.
This service parses the dates for a given rule model to construct this service, dependency is established using Laravel’s reflection.
Its corresponding test is RulesParsingTest in feature test to see how it works, and also the results of the dates recurrence.
This returns a dummy treatment for the treatment model
We define a scope for the factory methods to generate 4 different types of rules, for each kind of recurrence, namely, yearly, monthly, weekly, and daily.
setup
Creates a fake authenticated user using Sanctum and creates a fake Treatment data using Treatment Factory
createTreatment
Allows the factory to create a Treatment for a given arguments
get_all_treatments
Allows you to create a treatment and get it through the treatment index route and asserts that there is a count of 1 in the response json and it contains the title of the treatment.
get_single_treatment
Allows you to test to get a specific treatment given an id, and asserts that the response json has the title of the treatment.
store_treatment
Allows you to make a temporary treatment and post it to the route treatments store and assert its creation, and assert that the response has the same values for the treatment made. It also tests that the database has the same values.
attributes_requires_while_storing_treatment
It allows you to test that the required parameters title and start date were passed in the treatments response and if not, it asserts the request is unprocessable.
delete_treatment
It tests to delete a specific treatment and asserts there is no content and the same is missing in the database.
update_treatment
It uses the route treatments update to patch or update data for a specific treatment and asserts if the request is ok. It also asserts If the database has these values.
while_updating_treatment_attributes_are_required
This tests whether the treatments update do not remove the required attributes and validates them and makes them unprocessable if the request doesn’t have one.
We test all the controller methods of the rules controller. The method names are self-explanatory for the tests it belongs to.
The method names in the tests are self-explanatory, namely, we tests to get all types of rules yearly, monthly, weekly, and daily. Note: It is faster to generate yearly recurrence than daily recurrence.
This tests allows you to check if you can update a treatment, specifically, the is_completed feature.
It_has_a_path
Allows you to test that the specific treatment created has a path
test_a_treatment_has_a_rule
Creates a yearly rule for a treatment id and checks the relationship exists.
If_treatment_is_deleted_then_rule_is_deleted
Allows you to test if a treatment is deleted then the rule associated with it is also deleted and is missing in the database, but not the other rules.
We test the relationship of the rule and the treatment
We test whether the user has many treatments.
It has the treatments routes in api resources. The full extended route list for treatments and rules could be accessed from the console command php artisan route:list
with the controller methods that define the action.
The rules api resource has shallow that means that in order to delete a rule or update a rule, you do not need the treatments in your route, as you can only get a rule, if you have provided a treatment, so we don’t need to do it twice. This is also visible through the route list console command.