Hi Phako,
Thank you. I'm already following this practise. I have the following
additional Model:

class Checkins(models.Model):
    checkinno = models.AutoField(primary_key=True, unique=True)
    hospitalid = models.ForeignKey(
        customer, on_delete=models.CASCADE, null=True)
    date = models.DateField(default=timezone.now)
    time = models.CharField(max_length=25)
    consulted = models.IntegerField(default=0)
    closed = models.IntegerField(default=0)
    linkedclinic = models.ForeignKey(Clinic, on_delete=models.CASCADE)

Right now, the program's policy allows any doctor of that clinic to
see a patient who checked in to that clinic, so doctor is not a
ForeignKey for this. But later I may need to add this too.

What would you suggest for adding a unique number which gets
incremented for each new patient registration, and unique to each
clinic?
Sincerely yours,

Dr Joel G Mathew



On Thu, 18 Oct 2018 at 09:00, Phako Perez <13.phak...@gmail.com> wrote:
>
> I suggest to use another table for visit so you can add which doctor, 
> schedule time, and comments or so as a patient may have 1 visit or n...
>
> Sent from my iPhone
>
> On Oct 17, 2018, at 9:59 PM, Joel Mathew <j...@joel.su> wrote:
>
> A hospital id needs to be assigned to a patient and printed on their id card. 
> When they present their card or this number, their records can be retrieved 
> at any time. A checkin id is additionally generated each day based on the 
> date and time. A patient can have only one patient id but many checkin ids.
>
> What can be a good approach to solve this? Should I perhaps create another 
> table just to store the last patient id issued to each clinic?
>
>
>
>
> On Wed, 17 Oct 2018 at 21:49, Matthew Pava <matthew.p...@iss.com> wrote:
>>
>> A number is a number, and we don’t need to attach meaning to it.
>>
>> Why do you need to have continuous ids unique to each clinic?  As a 
>> developer, I would object to anyone forcing such a requirement.  If they 
>> insisted, then I would add a property that is calculated each time based on 
>> the count of patients in the clinic.
>>
>>
>>
>> From: django-users@googlegroups.com [mailto:django-users@googlegroups.com] 
>> On Behalf Of Joel Mathew
>> Sent: Wednesday, October 17, 2018 11:01 AM
>> To: django-users@googlegroups.com
>> Subject: Creating seperate unique ids within the same table
>>
>>
>>
>> I have an application which is a clinic management software which allows 
>> login into different clinics, and needs to keep patient records of each 
>> clinic seperately. The patient records are filed in one common model, with a 
>> ForeignKey referring to the clinic to which a patient belongs.
>>
>>
>>
>> Hitherto I had used the AutoField primary key of the customer model as a 
>> hospital identification number for the patient. This number is unique and 
>> used throughout the application to retrieve querysets related to the 
>> customer. My problem is this. I want each patient to have a unique 
>> automatically incrementing id which can be given to them. Obviously since 
>> all patient records (irrespective of which clinic the patient belongs to) 
>> are stored in one model, the ids are not seperated by clinic. cstid 1 may be 
>> of clinic 1, cstid 5 may again be of clinic 1, but cstid 6 may be of clinic 
>> 2.
>>
>>
>>
>> I need patients  of one clinic to have continuous ids unique to each clinic. 
>> What can I do to achieve this, within my defined models?
>>
>>
>>
>>     class Clinic(models.Model):
>>
>>         clinicid = models.AutoField(primary_key=True, unique=True)
>>
>>         name = models.CharField(max_length=60, unique=True)
>>
>>         label = models.SlugField(max_length=25, unique=True)
>>
>>         email = models.EmailField(max_length=50, default='')
>>
>>         mobile = models.CharField(max_length=15, default='')
>>
>>         alternate = models.CharField(max_length=15, default='', blank=True)
>>
>>         about = models.CharField(max_length=250, blank=True)
>>
>>         state = models.CharField(max_length=25)
>>
>>         city = models.CharField(max_length=35)
>>
>>         locality = models.CharField(max_length=35)
>>
>>         pincode = models.IntegerField(default=0)
>>
>>         address = models.TextField(max_length=80, default='', blank=True)
>>
>>         website = models.URLField(blank=True)
>>
>>         logo = models.ForeignKey(ProfilePic, blank=True, null=True, 
>> on_delete=models.CASCADE)
>>
>>         latitude = models.FloatField(blank=True)
>>
>>         longitude = models.FloatField(blank=True)
>>
>>         placeurl = models.URLField(blank=True)
>>
>>         class Meta:
>>
>>             unique_together = ["name", "mobile", "email"]
>>
>>         def __str__(self):
>>
>>             return self.name
>>
>>
>>
>>     class customer(models.Model):
>>
>>         # Need autoincrement, unique and primary
>>
>>         cstid = models.AutoField(primary_key=True, unique=True)
>>
>>         name = models.CharField(max_length=35)
>>
>>         age=models.IntegerField()
>>
>>         gender_choices = (
>>
>>             ('male', 'Male'),
>>
>>             ('female', 'Female'),
>>
>>             ('other', 'Something else'),
>>
>>             ('decline', 'Decline to answer'))
>>
>>         gender = models.CharField(
>>
>>             choices=gender_choices, max_length=10, default='male')
>>
>>         maritalstatus_choices = (
>>
>>             ('unmarried', 'Unmarried'),
>>
>>             ('married', 'Married'))
>>
>>         maritalstatus = models.CharField(
>>
>>             choices=maritalstatus_choices, max_length=10, 
>> default='Unmarried')
>>
>>         mobile = models.CharField(max_length=15, default='')
>>
>>         alternate = models.CharField(max_length=15, default='', blank=True)
>>
>>         email = models.CharField(max_length=50, default='', blank=True)
>>
>>         address = models.CharField(max_length=80, default='', blank=True)
>>
>>         city = models.CharField(max_length=25, default='', blank=True)
>>
>>         occupation = models.CharField(max_length=25, default='', blank=True)
>>
>>         bloodgroup_choices = (('apos', 'A+'),
>>
>>             ('aneg', 'A-'),
>>
>>             ('bpos', 'B+'),
>>
>>             ('bneg', 'B-'),
>>
>>             ('opos', 'O+'),
>>
>>             ('oneg', 'O-'),
>>
>>             ('abpos', 'AB+'),
>>
>>             ('abneg', 'AB-')
>>
>>             )
>>
>>         bloodgroup = models.CharField(choices=bloodgroup_choices, 
>> max_length=5, default='-', blank=True)
>>
>>         linkedclinic = models.ForeignKey(Clinic, on_delete=models.CASCADE)
>>
>>         class Meta:
>>
>>             unique_together = ["name", "mobile", "age", "linkedclinic"]
>>
>>         def __str__(self):
>>
>>             return self.name
>>
>>
>>
>> My thoughts are on counting the number of customer objects with specific 
>> ForeignKey of a clinic, and then updating hospital id field in the same 
>> model. But probably there's a more logical less tedious way of doing this? 
>> Or should I be creating seperate tables for each clinic?
>>
>> --
>> You received this message because you are subscribed to the Google Groups 
>> "Django users" group.
>> To unsubscribe from this group and stop receiving emails from it, send an 
>> email to django-users+unsubscr...@googlegroups.com.
>> To post to this group, send email to django-users@googlegroups.com.
>> Visit this group at https://groups.google.com/group/django-users.
>> To view this discussion on the web visit 
>> https://groups.google.com/d/msgid/django-users/CAA%3Diw_98pujPThLkq6FCqGPqJYkE1U4HF1RswQaGTv8QGc7xXw%40mail.gmail.com.
>> For more options, visit https://groups.google.com/d/optout.
>>
>> --
>> You received this message because you are subscribed to the Google Groups 
>> "Django users" group.
>> To unsubscribe from this group and stop receiving emails from it, send an 
>> email to django-users+unsubscr...@googlegroups.com.
>> To post to this group, send email to django-users@googlegroups.com.
>> Visit this group at https://groups.google.com/group/django-users.
>> To view this discussion on the web visit 
>> https://groups.google.com/d/msgid/django-users/02ed2d48826e4249a66072c8f660e77a%40ISS1.ISS.LOCAL.
>> For more options, visit https://groups.google.com/d/optout.
>
> --
> You received this message because you are subscribed to the Google Groups 
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an 
> email to django-users+unsubscr...@googlegroups.com.
> To post to this group, send email to django-users@googlegroups.com.
> Visit this group at https://groups.google.com/group/django-users.
> To view this discussion on the web visit 
> https://groups.google.com/d/msgid/django-users/CAA%3Diw__s-3KSPizNbqNKA1dQ1tc%3DUHuQoWifvae2HTS99DRnxA%40mail.gmail.com.
> For more options, visit https://groups.google.com/d/optout.
>
> --
> You received this message because you are subscribed to the Google Groups 
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an 
> email to django-users+unsubscr...@googlegroups.com.
> To post to this group, send email to django-users@googlegroups.com.
> Visit this group at https://groups.google.com/group/django-users.
> To view this discussion on the web visit 
> https://groups.google.com/d/msgid/django-users/6C618BEA-AFD2-400F-93C0-0DC1A43EBA5E%40gmail.com.
> For more options, visit https://groups.google.com/d/optout.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAA%3Diw_9in_VFvHNsDazu7WLvZP3owr%3D_rO1aSAPrvLoQx-8joQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to