Skip to content

Commit 4536330

Browse files
Merge pull request #24 from ScottSucksAtProgramming/Reporting
Merged
2 parents ffc6875 + 7291486 commit 4536330

File tree

59 files changed

+2088
-542
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

59 files changed

+2088
-542
lines changed

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ Temporary Items
4848
#* ------------------------------- Brownie --------------------------------- #
4949
.hypothesis/
5050
build/
51-
reports/
51+
5252

5353

5454
brownie-config.yaml

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -164,9 +164,9 @@ _For more examples, please refer to the [Documentation](https://example.com)_
164164
flexibility and ease of extension.
165165
- [x] Documentation update.
166166
- [x] Continued Test Suite expansion.
167-
- [ ] Version 0.3.0 - Alpha - In Progress!!
168-
- [ ] Basic Report Generation
169-
- [ ] Version 0.0.0 - Beta
167+
- [x] Version 0.3.0 - Alpha - Released on November 7th, 2022
168+
- [x] Basic Report Generation
169+
- [ ] Version 0.0.0 - Beta - Next Up!!
170170
- [ ] Command Line User Interface
171171
- [ ] Version 0.1.0 - Beta
172172
- [ ] Order Tracking

docs/Builders and DataItems Structure copy.svg

Lines changed: 1 addition & 0 deletions
Loading

docs/Builders and DataItems Structure-1.svg

Lines changed: 1 addition & 0 deletions
Loading

docs/Builders and DataItems Structure.svg

Lines changed: 1 addition & 0 deletions
Loading

docs/DataItems Relationship Structure.svg

Lines changed: 1 addition & 0 deletions
Loading
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
id,adjustment_date,event_code,medication_code,amount,reporting_period_id,reference_id
2+
0,1658523600,IMPORT,fentanyl,7450,2200000,Narcotics Bi-Annual Report - June 2022 - Wantagh-Levittown VAC
3+
1,1658523600,IMPORT,morphine,690000,2200000,Narcotics Bi-Annual Report - June 2022 - Wantagh-Levittown VAC
4+
2,1658523600,IMPORT,midazolam,663400,2200000,Narcotics Bi-Annual Report - June 2022 - Wantagh-Levittown VAC
5+
6+
7+
,,,,,,
8+
,,,,,,
9+
,,,,,,
10+
,,,,,,
11+
,,,,,,
12+
,,in mcg,in mg,,,
13+
,Fentanyl,-359560,-359.56,,,
14+
,Midazolam,211800,211.8,,,
15+
,Morphine,689950,689.95,,,
237 KB
Loading

docs/mermaid-diagram-2022-10-26-220415.svg

Lines changed: 1 addition & 0 deletions
Loading

docs/mermaid-diagram-2022-10-28-173900.svg

Lines changed: 1 addition & 0 deletions
Loading
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
# Introducing Narcotics Tracker v0.2.5.
2+
3+
| Version | Release Date | Audience |
4+
| :------ | :----------- | :--------- |
5+
| 0.3.0 | 11/07/2022 | Developers |
6+
7+
**Message from ScottSucksAtProgramming:**
8+
9+
> Hooray! Version 0.3.0 is here! This is not a gigantic update but it marks the
10+
> completion of the primary goal I had for this project. With a single command
11+
> the Narcotics Tracker can now print out all the information required for the
12+
> NYS Semi-Annual Controlled Substance Inventory Form for EMS Agencies'
13+
> (DOH-3848). This will make reporting each period far far easier than doing it
14+
> manually.
15+
16+
## Reports Package
17+
18+
The Reports Package has been added to the main directory of the Narcotics
19+
Tracker.
20+
21+
### Interface
22+
23+
The Report Module within the Interfaces sub-package contains the protocol for
24+
reports. It is similar to the Command Protocol and is using the Command Design
25+
Pattern for its implementation. The receiver can be set via the initializer.
26+
The run method will execute the report and return the results.
27+
28+
### Return Medication Stock Report
29+
30+
This report returns the current amount of a specified medication in the
31+
inventory. Amount is currently returned as a float. This may be adjusted later
32+
to return a dictionary to conform to the other reports.
33+
34+
### Return Current Inventory
35+
36+
THis report returns the current amount of all 'active' medications in the
37+
'medications' table in the inventory. This report is designed to be used for
38+
regular inventory stock counts. Where the physical inventory count can be
39+
compared to the return value of this report. This report currently returns the
40+
data as a list of dictionaries.
41+
42+
### Bi-Annual Narcotics Inventory Report
43+
44+
This is the big guy! This will cycle through all active medications from the
45+
'medications' table and all data from the current, 'open' reporting period to
46+
return the following:
47+
48+
- Starting amount of the medication in milliliters.
49+
- Amount of the medication received from orders in milliliters.
50+
- Amount of the medication used by providers in milliliters.
51+
- Amount of the medication wasted by providers in milliliters.
52+
- Amount of the medication destroyed at a reverse distributor in milliliters.
53+
- Amount of the medication lost or stolen in milliliters.
54+
- Final amount of the medication in milliliters.
55+
56+
When adjustments are up to date, this report should be accurate and can be used
57+
to complete this report without issue.
58+
59+
## Next Up!
60+
61+
The next release will see the implementation of a command line interface! Wish
62+
me luck!

narcotics_tracker/builders/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,3 +67,4 @@
6767
Review the documentation of specific builders for more information on
6868
their usage and available methods.
6969
"""
70+
from narcotics_tracker.builders.medication_builder import MedicationBuilder

narcotics_tracker/builders/adjustment_builder.py

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
"""
77
from typing import Union
88

9+
from narcotics_tracker import commands
910
from narcotics_tracker.builders.dataitem_builder import DataItemBuilder
1011
from narcotics_tracker.items.adjustments import Adjustment
1112

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

6768
def build(self) -> Adjustment:
6869
"""Validates attributes and returns the Adjustment object."""
70+
self._evaluate_and_fix_dates()
71+
self._convert_adjustment_amount_to_standard()
72+
self._apply_event_modifier()
73+
74+
adjustment = self._dataitem
75+
self._reset()
76+
return adjustment
77+
78+
def _evaluate_and_fix_dates(self) -> None:
79+
"""Runs dates through validator. Sets the instance variables correctly."""
6980
self._dataitem.created_date = self._service_provider.datetime.validate(
7081
self._dataitem.created_date
7182
)
@@ -76,9 +87,23 @@ def build(self) -> Adjustment:
7687
self._dataitem.adjustment_date
7788
)
7889

79-
adjustment = self._dataitem
80-
self._reset()
81-
return adjustment
90+
def _convert_adjustment_amount_to_standard(self) -> None:
91+
"""Converts the adjustment amount in the standard unit."""
92+
med_code = self._dataitem.medication_code
93+
amount = self._dataitem.amount
94+
preferred_unit = commands.ReturnPreferredUnit().execute(med_code)
95+
converted_amount = self._service_provider.conversion.to_standard(
96+
amount, preferred_unit
97+
)
98+
self._dataitem.amount = converted_amount
99+
100+
def _apply_event_modifier(self) -> None:
101+
"""Retrieves the event modifier and applies it to the the amount."""
102+
event_code = self._dataitem.event_code
103+
104+
event_modifier = commands.ReturnEventModifier().execute(event_code)
105+
106+
self._dataitem.amount = self._dataitem.amount * event_modifier
82107

83108
def set_adjustment_date(self, date: Union[int, str]) -> "AdjustmentBuilder":
84109
"""Sets the adjustment date to the passed value.

narcotics_tracker/builders/dataitem_builder.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,11 @@
88
"""
99
from typing import Union
1010

11-
from narcotics_tracker.builders.interfaces.builder import BuilderInterface
11+
from narcotics_tracker.builders.interfaces.builder import Builder
1212
from narcotics_tracker.services.service_manager import ServiceManager
1313

1414

15-
class DataItemBuilder(BuilderInterface):
15+
class DataItemBuilder(Builder):
1616
"""Builds a generic DataItem. Intended to be inherited by other builders.
1717
1818
This class is meant to be inherited by other builders which create various
@@ -35,18 +35,18 @@ def __init__(self) -> None:
3535
"""Calls the _reset method."""
3636
self._reset()
3737

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

4242
return self
4343

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

49-
def set_created_date(self, date: Union[int, str] = None) -> BuilderInterface:
49+
def set_created_date(self, date: Union[int, str] = None) -> Builder:
5050
"""Sets the attribute to the current datetime, unless overridden.
5151
5252
Args:
@@ -57,7 +57,7 @@ def set_created_date(self, date: Union[int, str] = None) -> BuilderInterface:
5757
self._dataitem.created_date = date
5858
return self
5959

60-
def set_modified_date(self, date: Union[int, str] = None) -> BuilderInterface:
60+
def set_modified_date(self, date: Union[int, str] = None) -> Builder:
6161
"""Sets the attribute to the current datetime, unless overridden.
6262
6363
Args:
@@ -68,7 +68,7 @@ def set_modified_date(self, date: Union[int, str] = None) -> BuilderInterface:
6868
self._dataitem.modified_date = date
6969
return self
7070

71-
def set_modified_by(self, modified_by: str) -> BuilderInterface:
71+
def set_modified_by(self, modified_by: str) -> Builder:
7272
"""Sets the modified by attribute to the passed string."""
7373
self._dataitem.modified_by = modified_by
7474
return self

narcotics_tracker/builders/interfaces/builder.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
from narcotics_tracker.items.interfaces.dataitem_interface import DataItem
1111

1212

13-
class BuilderInterface(Protocol):
13+
class Builder(Protocol):
1414
"""Defines the protocol for concrete DataItem builders.
1515
1616
Abstract Methods:

narcotics_tracker/builders/reporting_period_builder.py

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
from narcotics_tracker.builders.dataitem_builder import DataItemBuilder
1111
from narcotics_tracker.items.reporting_periods import ReportingPeriod
12+
from narcotics_tracker.services.service_manager import ServiceManager
1213

1314

1415
class ReportingPeriodBuilder(DataItemBuilder):
@@ -63,9 +64,6 @@ def build(self) -> ReportingPeriod:
6364
self._dataitem.start_date = self._service_provider.datetime.validate(
6465
self._dataitem.start_date
6566
)
66-
self._dataitem.end_date = self._service_provider.datetime.validate(
67-
self._dataitem.end_date
68-
)
6967

7068
reporting_period = self._dataitem
7169
self._reset()
@@ -81,6 +79,12 @@ def set_start_date(self, date: Union[int, str] = None) -> "ReportingPeriodBuilde
8179
Returns:
8280
self: The instance of the builder.
8381
"""
82+
if type(date) == str:
83+
date = ServiceManager().datetime.convert_to_timestamp(date)
84+
85+
if date == None:
86+
raise ValueError("Must provide a start date.")
87+
8488
self._dataitem.start_date = date
8589
return self
8690

@@ -94,6 +98,9 @@ def set_end_date(self, date: int = None) -> "ReportingPeriodBuilder":
9498
Returns:
9599
self: The instance of the builder.
96100
"""
101+
if type(date) == str:
102+
date = ServiceManager().datetime.convert_to_timestamp(date)
103+
97104
self._dataitem.end_date = date
98105
return self
99106

narcotics_tracker/commands/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,13 +62,15 @@
6262
AddMedication,
6363
DeleteMedication,
6464
ListMedications,
65+
LoadMedication,
6566
ReturnPreferredUnit,
6667
UpdateMedication,
6768
)
6869
from narcotics_tracker.commands.reporting_period_commands import (
6970
AddReportingPeriod,
7071
DeleteReportingPeriod,
7172
ListReportingPeriods,
73+
LoadReportingPeriod,
7274
UpdateReportingPeriod,
7375
)
7476
from narcotics_tracker.commands.status_commands import (

narcotics_tracker/commands/event_commands.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -184,8 +184,8 @@ def __init__(self, receiver: "PersistenceService" = None) -> None:
184184
else:
185185
self._receiver = ServiceManager().persistence
186186

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

0 commit comments

Comments
 (0)