def test__parse_bsrf__pend_created(): """Tests that PendBSRF is properly created for new raw_string.""" parse.parse_bsrf('b 1 mg r f') pend = models.PendBSRF.objects.get(original='b 1 mg r f') assert pend.brand_name == 'B' assert pend.strength == '1 mg' assert pend.route == 'r' assert pend.dosage_form == 'f'
def test__parse_bsrf__output_without_sub(): """Tests for output format without substitution.""" output = parse.parse_bsrf('a') assert 'brand_name' in output assert 'strength' in output assert 'route' in output assert 'dosage_form' in output
def test__parse_bsrf__no_raw_bsrf(): """Tests handling of a blank raw_bsrf.""" output = parse.parse_bsrf(None) assert 'brand_name' in output assert 'strength' in output assert 'route' in output assert 'dosage_form' in output assert output['brand_name'] is None assert output['strength'] is None assert output['route'] is None assert output['dosage_form'] is None
def test__parse_bsrf__valid__b__with_spaces(): """Tests handling of "B" formatted string with spaces in brand name.""" output = parse.parse_bsrf('b b1 b2') assert 'brand_name' in output assert 'strength' in output assert 'route' in output assert 'dosage_form' in output assert output['brand_name'] == 'B B1 B2' assert output['strength'] is None assert output['route'] is None assert output['dosage_form'] is None
def test__parse_bsrf__valid__b(): """Tests handling of "B" formatted string.""" output = parse.parse_bsrf('b') assert 'brand_name' in output assert 'strength' in output assert 'route' in output assert 'dosage_form' in output assert output['brand_name'] == 'B' assert output['strength'] is None assert output['route'] is None assert output['dosage_form'] is None
def test__parse_bsrf__valid__b_s____r__f(): """Tests handling of "B S R F" formatted string.""" output = parse.parse_bsrf('b 1 mg r f') assert 'brand_name' in output assert 'strength' in output assert 'route' in output assert 'dosage_form' in output assert output['brand_name'] == 'B' assert output['strength'] == '1 mg' assert output['route'] == 'r' assert output['dosage_form'] == 'f'
def test__parse_bsrf__valid__with_sub(): """Tests for proper parse handling with valid data and a sub.""" models.SubsBSRF.objects.create(original='b s r f', brand_name='b', strength='s', route='r', dosage_form='f') output = parse.parse_bsrf('b s r f') assert 'brand_name' in output assert 'strength' in output assert 'route' in output assert 'dosage_form' in output assert output['brand_name'] == 'b' assert output['strength'] == 's' assert output['route'] == 'r' assert output['dosage_form'] == 'f'
def _update_drug(self, drug): """Updates the Drug instance.""" data = self.validated_data # Parse the BSRF data bsrf = parse.parse_bsrf(data['bsrf']) # Parse the generic data generic_name = parse.parse_generic(data['generic_name']) # Assemble the generic_product name generic_product = parse.assemble_generic_product(bsrf, generic_name) # Parse the manufacturer data manufacturer = parse.parse_manufacturer(data['manufacturer']) # Get ATC instance atc = self._get_atc_instance() # Get PTC instance ptc = self._get_ptc_instance() # Update the Drug instance drug.brand_name = bsrf['brand_name'] drug.strength = bsrf['strength'] drug.route = bsrf['route'] drug.dosage_form = bsrf['dosage_form'] drug.generic_name = generic_name drug.manufacturer = manufacturer drug.schedule = data['schedule'] drug.atc = atc drug.ptc = ptc drug.generic_product = generic_product drug.save() return drug