Reputation: 665
Am building Software for a clinic using VS2010 Pro.
Among the requirements are:
Middle two digits for Male patient is 11.
Middle two digits for Female patient is 22
The Final two digits range from 0 to 99.
eg for Male patient enrolled today:2012-03-02.
My Question is:
What is the Maximum of patients that can be enrolled per day?
here is part of my code:
public string GetCurrentDate()
{
DateTime currentDate = DateTime.Now;
string todaydate = currentDate.ToShortDateString().ToString();
return todaydate;
}
public int RadomNum()
{
return _random.Next(00, 99);
}
public string GeneratePatientNumber(Gender gender)
{
return GetCurrentDate() + "-" + (int)gender + "-" + RadomNum();
}
Upvotes: 1
Views: 141
Reputation: 15367
In theory 200 per day: 100 for males, 100 for females.
Btw, note that since you generate a random number you can have non unique numbers.
It would be better to search for the last used ID (0-100) and then use the next one. And maybe even taking into account that there are gaps when patients are removed from the system. For this you would have to write a function that returns the first UNUSED id for a gender and date.
something like:
id = GetFirstFreeId(GetCurrentDate(), gender);
and use that id for the new patient.
Also it is better (from a performance point of view to use):
return string.Format("{0}-{1}-{2}", GetCurrentDate(), (int)gender, RadomNum());
And also it should be RandomNum instead of RadomNum, but this is just a typo.
Upvotes: 0
Reputation:
Why does it need to be random? Why not just use a sequential number, i.e., male patients are 2012-03-02-22-00 - 2012-03-02-22-99.
Do they only intend to register a maximum of 100 new patients a day for each gender?
Upvotes: 1
Reputation: 27619
Are you asking what the maximum number of patients you can register per day? If so then for each gender the only things varying are the last two digits so you have 100 possible patient codes per gender based on that pattern.
That having been said a few things should be noted.
Firstly your random number generation means that you may well hit on an already generated pateient number before you use all the available possibilities. Are random numbers needed to keep them non-sequential? If so then you should either do something like shuffle a list of the numbers 0 to 100 initially and then keep picking from that or if you are likely to use a small portion of them then you could get away with just checking for if the generated ID exists already.
Also since RandomNum()
is an int then you will probably want to make sure its padded to two digits before including it in your patient number.
Upvotes: 3