Extend this Django shell application to answer the question: "What is the contract rate for a specific service type on a specific date?"
Time Expectation: 2 hours Difficulty: Intermediate
You're working on a contract management platform where users need to query contract rates for different service types at different points in time. Contracts have rates for multiple service types when first created, but amendments can selectively change rates for specific services on different effective dates.
Build Django models and search functionality that can accurately determine an active contract rate for a specific service type for a specific date, accounting for amendments that can selectively override specific service rates.
Your task is to:
- Design Django models to store the contract data
- Implement a search function that returns the correct rate for a service type on any date
- Write tests to ensure your solution works correctly
You'll be working with contracts that look like this:
{
"contract_id": "CTR-001",
"effective_date": "2024-01-01",
"service_rates": [
{"service_type": "office_visit", "rate": 100.00},
{"service_type": "lab_work", "rate": 50.00},
{"service_type": "imaging", "rate": 200.00}
],
"amendments": [
{"effective_date": "2024-06-01", "service_type": "office_visit", "rate": 120.00},
{"effective_date": "2024-09-01", "service_type": "office_visit", "rate": 130.00},
{"effective_date": "2024-09-01", "service_type": "lab_work", "rate": 55.00},
{"effective_date": "2024-12-01", "service_type": "telehealth", "rate": 80.00}
]
}Design Django models that can store the contract data structure shown above. Consider what models and relationships you'll need.
Implement: get_service_rate_on_date(contract_id, service_type, query_date)
- Returns the rate for a specific service that was active on the specified date
- Must handle amendments correctly
Include any tests you feel are necessary to validate your solution.
-
Setup the environment:
python -m venv venv source venv/bin/activate # On Windows: venv\Scripts\activate pip install -r requirements.txt
-
Verify the environment works:
python manage.py testYou should see 1 test pass.
-
Implement your solution in these files:
contracts/models.py- Django models for contracts and amendmentscontracts/services.py- Search function implementationcontracts/tests.py- Test suite
-
Run tests as you develop:
python manage.py test contracts