TurnStile is a client managment system that allows providers to send emails and text to clients. This could be used to eliminate in-person waiting.
Current implementation is the customer facing web application. The next phase of development would be implemenating a digital queueing system to keep clients in line.
To start your Phoenix server:
- run
create extension fuzzystrmatch
in psql. This is required to run levenstein distance queries. - Install dependencies with
mix deps.get
- Create and migrate your database with
mix ecto.setup
- Start Phoenix endpoint with
mix phx.server
or inside IEx withiex -S mix phx.server
To set enviromnent:
- MIX_ENV=dev iex -S mix phx.server
- see link
Now you can visit localhost:4000
from your browser.
Ready to run in production? Please check our deployment guides.
- Employee: Auth, schema, auth migration, auth html
mix phx.gen.auth Staff Employee employees
- half of context created here
- in auth migration: add roles with
execute("create type employee_role as enum #{TurnStile.Utils.convert_to_parens_string(EmployeePermissionRolesEnum.get_employee_all_roles())}")
- Employee: context, complete html, route resources
mix phx.gen.html Staff Employee employees --no-schema
- other half of context created here
- Organization: non-auth migration, context, schema, page html, resources
mix phx.gen.html Company Organization organizations name:string slug:string email:string phone:string
- User: schema and migration
mix phx.gen.schema Patient User users first_name:string last_name_string health_num:integer phone_num:integer
- User: context and functionality
mix phx.gen.context Patient.User users first_name:string last_name_string health_num:integer phone_num:integer
- User: live view
mix phx.gen.live Patients User users -no-schema --no-context
- Opertations Admin: Auth, schema, auth migration, auth html
mix phx.gen.auth Operations Admin admins
- in auth migration: add roles with
execute("create type admin_role as enum #{TurnStile.Utils.convert_to_parens_string(AdminPermissionRolesEnum.get_admin_all_roles())}")
- half of context created here
- Opertations Admin: context, complete web html, route resources
mix phx.gen.html Operations Admin admins --no-schema
- other half of context created here
Developement
- Using CLI (must be installed), or from the dashboard under the phone number, set the system to "listen" for incoming requests on the webhook.
- In router expose api route outside the app flow:
- i.e.
POST /sms_messages
- Exposed a public, non-local, access URL to the app:
- i.e.
ngrok http 4000
- Use this URL in the webhook to allow twilio application access:
- i.e.
https://7114-108-60-178-251.ngrok-free.app/sms_messages
- Use the CLI command to set the webhook to listen.
- This
sid
is phone number sid. This is found in the dashboard under the active phone number -> properties ->Phone Number SID
twilio api:core:incoming-phone-numbers:update \ --sid PN3ae43ff9946669eeeb7d41deba57fac4 \ --sms-url "https://7114-108-60-178-251.ngrok-free.app/sms_messages"
- Using TwinML and this tutorial we immideatlely resonsd to incoming messages.
- For Flash messages to appear in child components, the
put_flash
must be called in the child component.
- instalpostgres
- install Phoenix
- clone application
mix deps.get
mix ecto.setup
mix ecto.migrate
mix phx.server
- Visit localhost:4000
Ternary operator syntax
disable_input = if action && action === :select, do: true, else: false
Temlating syntax notes:
attribue: variable
: this works as valid elixir- always use
get_field
. Checks all parts of the changeset for values - readonly, title, and value usage
<%= text_input f, :phone, value: Ecto.Changeset.get_field(@changeset, :phone), readonly: @disable_input, title: @disabled_hover_info %>
<%= error_tag f, :phone %>
- radio button usage
<%= radio_button(f, :alert_format_set, :sms, phx_change: "radio_click", checked: Ecto.Changeset.get_field(@changeset, :alert_format_set) == AlertFormatTypesMap.get_alert("SMS"), disabled: @disable_input, title: @disabled_hover_info)%>
LiveView Messaging Methods
- PUBSUB: subscrber in the liveView mount and broadcaster in the outer process.
- send:
- Process.send used to send from child to parent and is caught in handle_info
- Kernel.send
- send_update: Liveview.send_update used to update component
1-Many
Schema
belongs_to
singular in child:- i.e.
belongs_to(:employee, Employee)
- i.e.
has_many
plural in parent:- i.e.
has_many(:alerts, Alert)
- i.e.
Migration
references
appears only in child:- i.e.
add :employee_id, references("employees"), null: false
- i.e.
Business Logic