Skip to content

floriansollami/rosa-interview

Repository files navigation

RosaInterview

This workspace has been generated by Nx, a Smart, fast and extensible build system.

System Design

Health Professional Model

The Health Professional (HP) model captures essential details about the HP, including their name, schedule, and timezone. The schedule is represented as a temporal expression, specifying the days of the week the HP is available and the time range for each day.

{
  "_id": "unique_id",
  "firstName": "John",
  "lastName": "Smith",
  "schedule": {
    "weekDays": [1, 2],
    "timeRange": {
      "start": "time_start",
      "end": "time_end"
    },
    "slotDuration": "PT15M"
  },
  "timezone": "Europe/Brussels"
}

14-Day Schedule Model

To manage the HP's schedule and availability, a 14-day rolling window is used. This decision is motivated by performance considerations and the use of the Bucket Pattern in MongoDB, which aggregates data into manageable chunks. This model includes both scheduled events (e.g., appointments) and availability slots.

{
  "_id": "42d41ce6-79ad-47b3-9f45-df6211de56fd",
  "availabilities": [
      // First Monday
      { "startTime": "2023-08-14T09:30:00.000Z", "endTime": "2023-08-14T12:00:00.000Z" },
      { "startTime": "2023-08-14T16:00:00.000Z", "endTime": "2023-08-14T20:00:00.000Z" },
      // First Tuesday
      { "startTime": "2023-08-15T11:00:00.000Z", "endTime": "2023-08-15T18:00:00.000Z" },
      // Second Monday
      { "startTime": "2023-08-21T09:30:00.000Z", "endTime": "2023-08-21T20:00:00.000Z" },
      // Second Tuesday
      { "startTime": "2023-08-22T09:30:00.000Z", "endTime": "2023-08-22T20:00:00.000Z" },
  ],
  "createdAt": "2023-08-13T00:00:00.000Z",
  "endDate": "2023-08-28T00:00:00.000Z",
  "healthProfessionalId": "c84cc145-1781-4e33-943d-7674242b322c",
  "scheduledEvents": [
    // Monday's event
    {
      "startTime": "2023-08-14T12:00:00.000Z",
      "endTime": "2023-08-14T16:00:00.000Z",
      "patientId": 67890,
      "status": "confirmed"
    },
    // Tuesday's event
    {
      "startTime": "2023-08-15T09:00:00.000Z",
      "endTime": "2023-08-15T11:00:00.000Z",
      "patientId": 12345,
      "status": "confirmed"
    },
    {
      "startTime": "2023-08-15T18:00:00.000Z",
      "endTime": "2023-08-15T20:00:00.000Z",
      "patientId": 23456,
      "status": "confirmed"
    }
  ],
  "startDate": "2023-08-13T00:00:00.000Z",
  "timezone": "Europe/Brussels",
  "updatedAt": "2023-08-13T00:00:00.000Z" 
}

Data Structure

A TreeMap is used to store scheduled events, ensuring they are sorted by date. This allows for efficient lookups and insertions (O(logN)), even as the number of events grows (probably overkill in the model but interesting to mention).

Optimizations and Future Improvements

  1. Data Archiving: To maintain system performance, older scheduled events should be moved to an archive collection. This collection could be optimized for storage rather than query performance.

  2. Concurrency: To handle concurrent operations, MongoDB's atomic operations or optimistic concurrency mechanisms should be used.

  3. Time-Series Collections: MongoDB's time-series collections could be leveraged for more efficient storage and querying of schedule objects.

  4. Algorithmic Efficiency: The function that computes availabilities could be optimized further (maybe by changing the design of the model?).

  5. Scheduled Jobs: The code was designed to work with a potential cron job that could be set up to periodically update the 14-day schedule and compute availabilities. This will help reducing the computational load at the time of each http request.


Start the app

To start the development server run nx serve rosa-interview. Open your browser and navigate to http://localhost:4200/. Happy coding!

Generate code

If you happen to use Nx plugins, you can leverage code generators that might come with it.

Run nx list to get a list of available plugins and whether they have generators. Then run nx list <plugin-name> to see what generators are available.

Learn more about Nx generators on the docs.

Running tasks

To execute tasks with Nx use the following syntax:

nx <target> <project> <...options>

You can also run multiple targets:

nx run-many -t <target1> <target2>

..or add -p to filter specific projects

nx run-many -t <target1> <target2> -p <proj1> <proj2>

Targets can be defined in the package.json or projects.json. Learn more in the docs.

Want better Editor Integration?

Have a look at the Nx Console extensions. It provides autocomplete support, a UI for exploring and running tasks & generators, and more! Available for VSCode, IntelliJ and comes with a LSP for Vim users.

Ready to deploy?

Just run nx build demoapp to build the application. The build artifacts will be stored in the dist/ directory, ready to be deployed.

Set up CI!

Nx comes with local caching already built-in (check your nx.json). On CI you might want to go a step further.

Connect with us!

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published