Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
4a28129
Fix typo
ScottSucksAtProgramming Oct 31, 2022
c9393e8
Refactor and simplify script
ScottSucksAtProgramming Oct 31, 2022
2b9b6fe
Refactor and simplify script
ScottSucksAtProgramming Oct 31, 2022
9fdef30
Move test DataItems into conftest
ScottSucksAtProgramming Oct 31, 2022
ad5e223
Add test objects into conftest, add diagrams
ScottSucksAtProgramming Nov 1, 2022
0184e0b
Update all tests to pass
ScottSucksAtProgramming Nov 1, 2022
e66f404
Add Reports Package and tests
ScottSucksAtProgramming Nov 1, 2022
38c4a51
Add interfaces sub-package
ScottSucksAtProgramming Nov 1, 2022
2d0e2ce
Add Report Interface
ScottSucksAtProgramming Nov 1, 2022
5a896a6
Add _receiver attribute
ScottSucksAtProgramming Nov 1, 2022
249d655
Add setup_integration_db fixture
ScottSucksAtProgramming Nov 2, 2022
97e7478
Add ReturnMedicationSock Report and tests
ScottSucksAtProgramming Nov 2, 2022
9516857
Fix bugs
ScottSucksAtProgramming Nov 2, 2022
b41b8db
Update with tests
ScottSucksAtProgramming Nov 2, 2022
c73d094
Update documentation and tests
ScottSucksAtProgramming Nov 2, 2022
6066613
Add ReturnCurrentInventory Report and test
ScottSucksAtProgramming Nov 2, 2022
539e0b9
Improve formatting
ScottSucksAtProgramming Nov 2, 2022
f06124f
Update documentation
ScottSucksAtProgramming Nov 2, 2022
248c8a1
Refactor method names
ScottSucksAtProgramming Nov 2, 2022
db5d6e3
Rename attribute
ScottSucksAtProgramming Nov 2, 2022
420f1be
Fix unit conversion issues
ScottSucksAtProgramming Nov 2, 2022
1ceeb97
Add ReturnCurrentReportingPeriod Report with tests
ScottSucksAtProgramming Nov 3, 2022
c22dcbc
Remove Report.
ScottSucksAtProgramming Nov 4, 2022
c3433a1
Add Command with Test
ScottSucksAtProgramming Nov 4, 2022
82c2e05
Add LoadMedication Command
ScottSucksAtProgramming Nov 4, 2022
29f9e8c
Fix conversion bug. No idea how.
ScottSucksAtProgramming Nov 4, 2022
30d7b88
Add Bi-Annual Report with tests
ScottSucksAtProgramming Nov 5, 2022
80e53ca
Add import to reports package
ScottSucksAtProgramming Nov 5, 2022
ac4b837
Add Script
ScottSucksAtProgramming Nov 5, 2022
f215f13
Add new Diagrams
ScottSucksAtProgramming Nov 7, 2022
be9e485
Update documentation
ScottSucksAtProgramming Nov 7, 2022
516a48f
Rename execute method to run for Reports
ScottSucksAtProgramming Nov 7, 2022
894a15a
Fix typo
ScottSucksAtProgramming Nov 7, 2022
63aa6c4
Add notes for v0.3.0-alpha release
ScottSucksAtProgramming Nov 7, 2022
7291486
Update Roadmap for new release.
ScottSucksAtProgramming Nov 7, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ Temporary Items
#* ------------------------------- Brownie --------------------------------- #
.hypothesis/
build/
reports/



brownie-config.yaml
Expand Down
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -164,9 +164,9 @@ _For more examples, please refer to the [Documentation](https://example.com)_
flexibility and ease of extension.
- [x] Documentation update.
- [x] Continued Test Suite expansion.
- [ ] Version 0.3.0 - Alpha - In Progress!!
- [ ] Basic Report Generation
- [ ] Version 0.0.0 - Beta
- [x] Version 0.3.0 - Alpha - Released on November 7th, 2022
- [x] Basic Report Generation
- [ ] Version 0.0.0 - Beta - Next Up!!
- [ ] Command Line User Interface
- [ ] Version 0.1.0 - Beta
- [ ] Order Tracking
Expand Down
1 change: 1 addition & 0 deletions docs/Builders and DataItems Structure copy.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions docs/Builders and DataItems Structure-1.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions docs/Builders and DataItems Structure.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions docs/DataItems Relationship Structure.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
15 changes: 15 additions & 0 deletions docs/Mock Inventory Table - Sheet1.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
id,adjustment_date,event_code,medication_code,amount,reporting_period_id,reference_id
0,1658523600,IMPORT,fentanyl,7450,2200000,Narcotics Bi-Annual Report - June 2022 - Wantagh-Levittown VAC
1,1658523600,IMPORT,morphine,690000,2200000,Narcotics Bi-Annual Report - June 2022 - Wantagh-Levittown VAC
2,1658523600,IMPORT,midazolam,663400,2200000,Narcotics Bi-Annual Report - June 2022 - Wantagh-Levittown VAC


,,,,,,
,,,,,,
,,,,,,
,,,,,,
,,,,,,
,,in mcg,in mg,,,
,Fentanyl,-359560,-359.56,,,
,Midazolam,211800,211.8,,,
,Morphine,689950,689.95,,,
Binary file added docs/Screenshot 2022-10-26 at 18.50.20.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions docs/mermaid-diagram-2022-10-26-220415.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions docs/mermaid-diagram-2022-10-28-173900.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
62 changes: 62 additions & 0 deletions docs/release_notes/Changes for Version 0.3.0.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
# Introducing Narcotics Tracker v0.2.5.

| Version | Release Date | Audience |
| :------ | :----------- | :--------- |
| 0.3.0 | 11/07/2022 | Developers |

**Message from ScottSucksAtProgramming:**

> Hooray! Version 0.3.0 is here! This is not a gigantic update but it marks the
> completion of the primary goal I had for this project. With a single command
> the Narcotics Tracker can now print out all the information required for the
> NYS Semi-Annual Controlled Substance Inventory Form for EMS Agencies'
> (DOH-3848). This will make reporting each period far far easier than doing it
> manually.

## Reports Package

The Reports Package has been added to the main directory of the Narcotics
Tracker.

### Interface

The Report Module within the Interfaces sub-package contains the protocol for
reports. It is similar to the Command Protocol and is using the Command Design
Pattern for its implementation. The receiver can be set via the initializer.
The run method will execute the report and return the results.

### Return Medication Stock Report

This report returns the current amount of a specified medication in the
inventory. Amount is currently returned as a float. This may be adjusted later
to return a dictionary to conform to the other reports.

### Return Current Inventory

THis report returns the current amount of all 'active' medications in the
'medications' table in the inventory. This report is designed to be used for
regular inventory stock counts. Where the physical inventory count can be
compared to the return value of this report. This report currently returns the
data as a list of dictionaries.

### Bi-Annual Narcotics Inventory Report

This is the big guy! This will cycle through all active medications from the
'medications' table and all data from the current, 'open' reporting period to
return the following:

- Starting amount of the medication in milliliters.
- Amount of the medication received from orders in milliliters.
- Amount of the medication used by providers in milliliters.
- Amount of the medication wasted by providers in milliliters.
- Amount of the medication destroyed at a reverse distributor in milliliters.
- Amount of the medication lost or stolen in milliliters.
- Final amount of the medication in milliliters.

When adjustments are up to date, this report should be accurate and can be used
to complete this report without issue.

## Next Up!

The next release will see the implementation of a command line interface! Wish
me luck!
1 change: 1 addition & 0 deletions narcotics_tracker/builders/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,3 +67,4 @@
Review the documentation of specific builders for more information on
their usage and available methods.
"""
from narcotics_tracker.builders.medication_builder import MedicationBuilder
31 changes: 28 additions & 3 deletions narcotics_tracker/builders/adjustment_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
"""
from typing import Union

from narcotics_tracker import commands
from narcotics_tracker.builders.dataitem_builder import DataItemBuilder
from narcotics_tracker.items.adjustments import Adjustment

Expand Down Expand Up @@ -66,6 +67,16 @@ def _reset(self) -> None:

def build(self) -> Adjustment:
"""Validates attributes and returns the Adjustment object."""
self._evaluate_and_fix_dates()
self._convert_adjustment_amount_to_standard()
self._apply_event_modifier()

adjustment = self._dataitem
self._reset()
return adjustment

def _evaluate_and_fix_dates(self) -> None:
"""Runs dates through validator. Sets the instance variables correctly."""
self._dataitem.created_date = self._service_provider.datetime.validate(
self._dataitem.created_date
)
Expand All @@ -76,9 +87,23 @@ def build(self) -> Adjustment:
self._dataitem.adjustment_date
)

adjustment = self._dataitem
self._reset()
return adjustment
def _convert_adjustment_amount_to_standard(self) -> None:
"""Converts the adjustment amount in the standard unit."""
med_code = self._dataitem.medication_code
amount = self._dataitem.amount
preferred_unit = commands.ReturnPreferredUnit().execute(med_code)
converted_amount = self._service_provider.conversion.to_standard(
amount, preferred_unit
)
self._dataitem.amount = converted_amount

def _apply_event_modifier(self) -> None:
"""Retrieves the event modifier and applies it to the the amount."""
event_code = self._dataitem.event_code

event_modifier = commands.ReturnEventModifier().execute(event_code)

self._dataitem.amount = self._dataitem.amount * event_modifier

def set_adjustment_date(self, date: Union[int, str]) -> "AdjustmentBuilder":
"""Sets the adjustment date to the passed value.
Expand Down
14 changes: 7 additions & 7 deletions narcotics_tracker/builders/dataitem_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@
"""
from typing import Union

from narcotics_tracker.builders.interfaces.builder import BuilderInterface
from narcotics_tracker.builders.interfaces.builder import Builder
from narcotics_tracker.services.service_manager import ServiceManager


class DataItemBuilder(BuilderInterface):
class DataItemBuilder(Builder):
"""Builds a generic DataItem. Intended to be inherited by other builders.

This class is meant to be inherited by other builders which create various
Expand All @@ -35,18 +35,18 @@ def __init__(self) -> None:
"""Calls the _reset method."""
self._reset()

def set_table(self, table_name: str) -> BuilderInterface:
def set_table(self, table_name: str) -> Builder:
"""Sets the table attribute."""
self._dataitem.table = table_name

return self

def set_id(self, id_number: int = None) -> BuilderInterface:
def set_id(self, id_number: int = None) -> Builder:
"""Sets the id attribute to None, unless overridden."""
self._dataitem.id = id_number
return self

def set_created_date(self, date: Union[int, str] = None) -> BuilderInterface:
def set_created_date(self, date: Union[int, str] = None) -> Builder:
"""Sets the attribute to the current datetime, unless overridden.

Args:
Expand All @@ -57,7 +57,7 @@ def set_created_date(self, date: Union[int, str] = None) -> BuilderInterface:
self._dataitem.created_date = date
return self

def set_modified_date(self, date: Union[int, str] = None) -> BuilderInterface:
def set_modified_date(self, date: Union[int, str] = None) -> Builder:
"""Sets the attribute to the current datetime, unless overridden.

Args:
Expand All @@ -68,7 +68,7 @@ def set_modified_date(self, date: Union[int, str] = None) -> BuilderInterface:
self._dataitem.modified_date = date
return self

def set_modified_by(self, modified_by: str) -> BuilderInterface:
def set_modified_by(self, modified_by: str) -> Builder:
"""Sets the modified by attribute to the passed string."""
self._dataitem.modified_by = modified_by
return self
Expand Down
2 changes: 1 addition & 1 deletion narcotics_tracker/builders/interfaces/builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
from narcotics_tracker.items.interfaces.dataitem_interface import DataItem


class BuilderInterface(Protocol):
class Builder(Protocol):
"""Defines the protocol for concrete DataItem builders.

Abstract Methods:
Expand Down
13 changes: 10 additions & 3 deletions narcotics_tracker/builders/reporting_period_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

from narcotics_tracker.builders.dataitem_builder import DataItemBuilder
from narcotics_tracker.items.reporting_periods import ReportingPeriod
from narcotics_tracker.services.service_manager import ServiceManager


class ReportingPeriodBuilder(DataItemBuilder):
Expand Down Expand Up @@ -63,9 +64,6 @@ def build(self) -> ReportingPeriod:
self._dataitem.start_date = self._service_provider.datetime.validate(
self._dataitem.start_date
)
self._dataitem.end_date = self._service_provider.datetime.validate(
self._dataitem.end_date
)

reporting_period = self._dataitem
self._reset()
Expand All @@ -81,6 +79,12 @@ def set_start_date(self, date: Union[int, str] = None) -> "ReportingPeriodBuilde
Returns:
self: The instance of the builder.
"""
if type(date) == str:
date = ServiceManager().datetime.convert_to_timestamp(date)

if date == None:
raise ValueError("Must provide a start date.")

self._dataitem.start_date = date
return self

Expand All @@ -94,6 +98,9 @@ def set_end_date(self, date: int = None) -> "ReportingPeriodBuilder":
Returns:
self: The instance of the builder.
"""
if type(date) == str:
date = ServiceManager().datetime.convert_to_timestamp(date)

self._dataitem.end_date = date
return self

Expand Down
2 changes: 2 additions & 0 deletions narcotics_tracker/commands/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,13 +62,15 @@
AddMedication,
DeleteMedication,
ListMedications,
LoadMedication,
ReturnPreferredUnit,
UpdateMedication,
)
from narcotics_tracker.commands.reporting_period_commands import (
AddReportingPeriod,
DeleteReportingPeriod,
ListReportingPeriods,
LoadReportingPeriod,
UpdateReportingPeriod,
)
from narcotics_tracker.commands.status_commands import (
Expand Down
4 changes: 2 additions & 2 deletions narcotics_tracker/commands/event_commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -184,8 +184,8 @@ def __init__(self, receiver: "PersistenceService" = None) -> None:
else:
self._receiver = ServiceManager().persistence

def execute(self, event_code: str) -> int:
def execute(self, code: str) -> int:
"""Executes the command and returns the modifier."""
criteria = {"event_code": event_code}
criteria = {"event_code": code}
cursor = self._receiver.read("events", criteria)
return cursor.fetchall()[0][4]
Loading