-
Notifications
You must be signed in to change notification settings - Fork 0
/
drug_struct.py
47 lines (36 loc) · 1.52 KB
/
drug_struct.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
from marshmallow import Schema, fields, post_load, validate
class DrugStruct:
def __init__(self,
ndc: str,
drug_name: str,
gpi: str,
gcn: str,
brand_flag: str) -> None:
# National Drug Code - https://www.accessdata.fda.gov/scripts/cder/ndc/
self.ndc = ndc
self.drug_name = drug_name
# Generic Product Identifier
self.gpi = gpi
# Generic Code Number - generic formulation of a drug.
self.gcn = gcn
# Identifies whether the drug dispensed was paid at brand or generic
# (based on the client-specific Drug File).
self.brand_flag = brand_flag
@property
def drug_name(self):
result = self.__drug_name[0:250] if self.__drug_name else self.__drug_name
return result
@drug_name.setter
def drug_name(self, drug_name):
self.__drug_name = drug_name[0:250] if drug_name else drug_name
def has_drug_name(self):
return self.drug_name not in ['-', '', None]
class DrugStructSchema(Schema):
ndc = fields.Str(required=True, allow_none=False, validate=validate.Length(max=20))
drug_name = fields.Str(required=True, allow_none=False, validate=validate.Length(max=250))
gpi = fields.Str(required=True, allow_none=False, validate=validate.Length(max=200))
gcn = fields.Str(required=True, allow_none=False, validate=validate.Length(max=200))
brand_flag = fields.Str(required=True, allow_none=False, validate=validate.Length(max=20))
@post_load
def make_drug_struct(self, data):
return DrugStruct(**data)