Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Laian Braum's Solution #34

Open
wants to merge 77 commits into
base: main
Choose a base branch
from
Open

Laian Braum's Solution #34

wants to merge 77 commits into from

Conversation

lzizn
Copy link

@lzizn lzizn commented Aug 15, 2024

Description

Goal: Increase the efficiency of the front desk staff by providing a prioritized list of patients who are most likely to respond positively, reducing the time spent contacting patients who may not be available.

This API leverages patient demographics and behavioral data to compute a score (higher is better) that represents how likely a patient is to accepting an appointment offer.

Checklist:

  • I have performed a self-review of my own code
  • I have tested my code to prove my fix is effective or that my feature works
  • I have commented my code in areas where it's hard to make the code speak for itself
  • My changes breaks no tests

Implementation details

  1. Data Normalization

    • A patient has different data fields, where each one has its own characteristics. Data Normalization transforms this data into a common scale, normally from 0 to 1, allowing one to evaluate and grade patients equally.
  2. Multi-Criteria Decision Analysis (MCDA):

    • Weighs patient behavior and demographic factors to calculate a score.
  3. Penalty Adjustment:

    • Applies a penalty of 0.1 point for every 10km above a distance of 100km from the facility, increasing the importance of distance, since the distance weight is only 10%. (I can't change the weights because it is a requirement, but it doesn't say anything about applying penalties... As one said in The Office: "I just Kobayashi Maru'd the whole thing")
  4. Randomization of patients with low behavior score:

    • Patients that score poorly on behavior metrics most likely will have a overall bad score and won't be placed above the top. However, the poor behavior might be due to lack of invites, thus the need to provide such patients a chance to still be invited for appointments.

Technologies & Concepts Used

  • Typescript (I started with JS and only moved to TS later)
  • Node.js
  • Express.js
  • Jest
  • Swagger
  • Clean Architecture
  • Multi-Criteria Decision Analysis (MCDA)
  • Haversine Formula (Used for calculating distance between two coordinates).

API Endpoints

1. GET /api/patients-recommended

  • Description: Returns an ordered list of patients most likely to accept an appointment.
  • Parameters:
    • latitude (required): Latitude of the facility.
    • longitude (required): Longitude of the facility.
  • Response:
    • A JSON array of patients with their computed scores.
  • Swagger Documentation: Available at /api-docs

Installing and running

git clone https://github.com/lzizn/backend-interview.git
cd backend-interview
npm install
npm run dev # runs dev server with nodemon
# or
npm run start # transpiles from TS to JS (dist/) and runs with node

Running Tests

The project includes unit and integration tests written with Jest and supertest to ensure the reliability of core functions and avoid regression during development.

npm run test # runs all tests
npm run test:coverage # runs all tests and collects coverage report
npm run test:unit # only unit tests
npm run test:integration # only integration tests

Swagger

Access the Swagger UI and see the full API documentation on GET /api-docs

swagger-ui

Test Coverage

This project has 100% of test coverage, including unit and integration tests.

Test Coverage

lzizn added 30 commits August 13, 2024 21:55
…een 0 to 1

- avoid division by 0 and return 0.5 in that case
- ensure to return 1 when value is greater than max
- ensure to return 0 when value is less than min
…een 0 to 1

- avoid division by 0 and return 0.5 in that case
- ensure to return 1 when value is greater than max
- ensure to return 0 when value is less than min
…urns min and max values for "age", "acceptedOffers", "cancelledOffers" and "averageReplyTime"
…urns min and max values for "age", "acceptedOffers", "cancelledOffers" and "averageReplyTime"
…e values must always be greater than min and less than max
…0 and 1, representing how likely the patient is to accept an appointment
…0 and 1, representing how likely the patient is to accept an appointment
…ty coords and returns patients with distance, score and littleBehaviorScore
…ty coords and returns patients with distance, score and littleBehaviorScore
… attend the appointment, including highest scores and random patients with little behavior score
… attend the appointment, including highest scores and random patients with little behavior score
lzizn added 29 commits August 14, 2024 16:12
…s all dependencies and injects them on controller instance)
… it and adapts its response to express responses
… it and adapts its response to express responses
…e value is lower than min and greater than max
…er than 1, acting as a penalty for patients further away than 100 kilometers
…onse in order to cleanup, allowing flag debug that returns all data
…prioritizing patiens with lowest distance and highest behavior score
…racts 0.1 points for every 10km above max distance (100km)
@lzizn lzizn changed the title Laian Braum's Assessment Laian Braum's Solution Aug 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant