Skip to content

Commit

Permalink
Merge pull request #24 from ScottSucksAtProgramming/Reporting
Browse files Browse the repository at this point in the history
Merged
  • Loading branch information
ScottSucksAtProgramming authored Nov 7, 2022
2 parents ffc6875 + 7291486 commit 4536330
Show file tree
Hide file tree
Showing 59 changed files with 2,088 additions and 542 deletions.
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

0 comments on commit 4536330

Please sign in to comment.