Assignment #1 (Database Unix Prog)
Assignment #1 (Database Unix Prog)
Write a Unix /bin/bash program to search a medication list and produce a report as requested by
the user.
The file medslist is a flat plain text file with the following format shown in the table below.
01 - 04 Category
05 - 18 Dose
19 - 26 Medication Code
27 - 39 Generic Name
40 - 46 On-Hand (inventory)
Example of the " medslist " file... (The first two lines represent columns numbers, not in file)
0 1 2 3 4 5 6
123456789012345678901234567890123456789012345678901234567890
comm 30A6314 ifosfamide 12
home6314 5341209 urokinase 37
...
etc.
Program Requirements
● Continually prompt the user to enter a Medication Code or portion thereof (should not
have to re-run program for each search). Use “ZZZ” (upper case only) to exit program
from the "Enter Medication Code" prompt.
● Ask the user if they wish to see the corresponding Generic Name (G) or Dose (D); reject
any other input with an error message (“Please enter only G or D.”) and re-prompt user
continually if necessary.
● Search only the Medication Code field of the data file displaying the all occurrences of
matching Medication Code (s) and corresponding Generic Name or Dose.
○ E.g. A search for the Medication Code "6314", should not display any information
about Medication Code "5341209". i.e. the search must be restricted to the
information in the Medication Code field.
● Print a separator character (e.g. colon) between the information fields (see sample
output).
● Include partial matches of Medication Code (e.g. 234 is contained in Medication Code
12345). Keep the search case-sensitive.
● Use the sample data file from the course website. Sample file is not exhaustive or
representative of all situations. For example, don't expect particular values in the
Category field (only letters, etc.) to limit your search of the Medication Code field.
● If no match is found, output "No such Medication Code."
● If you create any temporary files, they must be cleaned up by your program before it
terminates.
● Your program must perform its search and report strictly based on column numbers.
The data file may contain any type of character in any field. (e.g. do not assume that the
Medication Code consists of only numbers or that the Dose must contain letters)
● Your script must be directly executable (i.e. run with "./search" not "bash search")
● Your program must not use any text processing utilities like awk, sed, or perl.
● You must not modify the given data file. Your program must work on any data file of the
format given above - not just the given sample data file.
$ ./search
Enter Medication Code? 6314
See Generic Name (G/g) or Dose (D/d)? G
A6314 : ifosfamide
Enter Medication Code? 23
See Generic Name (G/g) or Dose (D/d)? j
Please enter only G or D.
See Generic Name (G/g) or Dose (D/d)? d
12345 : ug 200
9230 : pg 6000
Enter Medication Code? foo
See Generic Name (G/g) or Dose (D/d)? D
No such Medication Code.
Enter Medication Code? ZZZ
Good bye.
$
Short-cut easy approach: Do all the lab exercises first, in particular Lab 4, Lab 5, and Lab 6.
Review your notes on loops. Apply lessons learned. Design your program structure ahead of
time. Program incrementally -- code a few lines at a time and get it working.
School of Hard Knocks long way: Skip the labs and start coding! Type in your whole
program, pray, then try running it. Stumble, get stuck, be prepared to waste a lot of time
"discovering" things covered in the lab exercises. Expect on having to re-write your program a
few times.
A word on testing
Part of the task of this assignment is to think of your own test cases to see if your program
meets the specified requirements. You should not rely on the short sample above as your entire
test suite. Of course, if your program's behaviour does not even match even the given sample,
this likely indicates serious deficiencies which you need to address before submitting.
Sample datafile
Use the datafile within our Unix environment at the following path:
~lhiraki/open/ccps393/medslist
Simply use this path as the input file for your program. While hard-coding the path and name of
the datafile is not normally recommended, please go ahead and hard-code this path for ease of
marking. Do not have your program prompt the user to enter a filename, etc.
Note:
1. Your program must read this data file from the path given above. Do not make a local
copy in your home directory.
2. Your program must run from any directory on this Unix system (portable). Do not make
path references to files or directories within your home directory.
Grading Scheme
Grading credit is intended to reflect the value to the customer. If your program has a few bugs
and is delivered "as-is" to the customer. How much value does it still offer to the customer, and
how much do you think the customer would want to pay?
You need to meet all requirements of a lower tier before being eligible for a higher tier. If you
meet all Tier 1 requirements and most of the Tier 2 requirements, you are still at only Tier 1.
Even if you had all the Tier 4 requirements met, but did not meet Tier 2, you would still be at Tier
1.
Programs are expected to be free from syntax errors. Programs will be tested on the TMU SCS
(moon) system. Programs with compile problems are not ready for submission and will receive
zero.
Grading Notes
Recall principle: Client value. How useful is your program at the nursing station of a hospital?
Example 1
Student's program works fine with no technical deficiencies but is missing the comprehensive
section. Result: Tier 0 not achieved. Overall mark is 0/5.
Example 2
Student's program produces a false match (outside key field). The search was not restricted to
the key field. There are no other technical deficiencies. Result: Tier 0 achieved. Overall mark is
1/5.
Example 3
Student's program output is incomplete in listing all matches (e.g. only 2 of expected 3 matching
drugs shown). Result: Tier 1. Overall mark is 2/5.
Example 4
Student's program correctly restricts search to key field and produces correct and complete
output, but allows only one enquiry per run or does not allow user to make multiple attempts at
the G/D prompt. Result: Tier 2. Overall mark is 3/5.
Example 5
Student's program includes display of wrong columns (e.g. drug dose shown as 3 instead of 30).
This is the only error. Code correctly restricts search (no false or missing matches); control flow
and prompting are complete and correct. Result: Tier 1. Overall mark is 2/5.
Example 6
Student's program meets all functional requirements, but is missing some title block information
and the shebang line (#!/bin/bash). Result: Tier 3. Overall mark is 4/5.
Example 7
Student's program meets the Tier 2 requirements but the student does not attend the customer
presentation by the due date. Result: Tier 1 (one level reduction). Overall mark is 2/5.
Submission instructions
1. Name your file "search" (not search.sh, midterm_prog, medication, etc.)
2. Please follow the instructions in D2L (Content-> Assignments -> Unix moon submission
instructions).