amr_aly

ninja_api

Mar 10th, 2021 (edited)
52
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. @api.get("/gyn/add_gyno")
  2. def get_gyno_form(request):
  3.     context = {
  4.         'obs_form': ObestetricForm,
  5.         'men_form': MenstrualForm,
  6.     }
  7.     return render(request, 'gyno/add_gyno.html', context)
  8.  
  9.  
  10. class ObestetricIn(Schema):
  11.     patient: int        #= models.ForeignKey(Patients, verbose_name='Patient Name:', on_delete=models.CASCADE)
  12.     obdate: date = None #= models.DateField(blank=True, null=True, verbose_name='Follow Up Date:')
  13.     gyn: bool           #= models.BooleanField(verbose_name='Gyn:', default=False)
  14.     g: int              #= models.IntegerField(default=0, blank=True, null=True, verbose_name='G:')
  15.     p: int              #= models.IntegerField(default=0, blank=True, null=True, verbose_name='P:')
  16.     a: int              #= models.IntegerField(default=0, blank=True, null=True, verbose_name='A:')
  17.     nvd: bool           #= models.BooleanField(default=False, verbose_name='NVD:')
  18.     cs: bool            #= models.BooleanField(default=False, verbose_name='CS:')
  19.     ld: str             #= models.CharField(max_length=150, blank=True, null=True, verbose_name='LD:')
  20.     lc: str             #= models.CharField(max_length=150, blank=True, null=True, verbose_name='LC:')
  21.     hist: str           #= models.TextField(max_length=250, verbose_name='History of previous obestetric complication(if any):', blank=True, null=True)
  22.  
  23. class MenstrualIn(Schema):
  24.     patient: int       #= models.ForeignKey(Patients, on_delete=models.CASCADE)
  25.     obestetric: int    #= models.ForeignKey(Obestetric, on_delete=models.CASCADE)
  26.     lmp: date = None   #= models.DateField(blank=True, null=True, verbose_name='LMP:')
  27.     edd: date = None   #= models.DateField(blank=True, null=True, verbose_name='EDD:')
  28.     ga: str            #= models.CharField(max_length=50, blank=True, null=True, verbose_name='G.A:')
  29.     remain: str        #= models.CharField(max_length=50, blank=True, null=True, verbose_name='Remaining Weeks:')
  30.  
  31. # Add gyn data with more than one form
  32. @api.post("/gyn/add_gyno")
  33. def add_gyno(request, obs: ObestetricIn = Form(...), men: MenstrualIn = Form(...)):
  34.     '''  '''
  35.     if request.method == 'POST':
  36.         obs = ObestetricForm(request.POST, prefix='obs')
  37.         men = MenstrualForm(request.POST, prefix='men')
  38.         if obs.is_valid() and men.is_valid():
  39.             obs_form = obs.save(commit=False)
  40.             obs_form.save()
  41.             obs_id = obs_form.id
  42.             pat_id = obs_form.patient_id
  43.             obestetric = Obestetric.objects.get(id=obs_id)
  44.  
  45.             men_form = men.save(commit=False)
  46.             men_form.obestetric_id = obs_id
  47.             men_form.patient_id = pat_id
  48.             men_form.save()
  49.            
  50.             return redirect(reverse('gyno:edit_gyno', kwargs={
  51.                                                         'obs_id': obs_form.id,
  52.                                                         'patient_id': pat_id,}))
  53.         else:
  54.             messages.success(request, 'Saving process failed ..!!')
  55.             return redirect(reverse('gyno:add_gyno'))
  56.     else:
  57.         obs = ObestetricForm(prefix='obs')
  58.         men = MenstrualForm(prefix='men')
  59.        
  60.     context = {
  61.         'obs_form': obs,
  62.         'men_form': men,
  63.     }
  64.     return render(request, 'gyno/add_gyno.html', context)
RAW Paste Data