amr_aly

Untitled

Mar 12th, 2021 (edited)
273
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 3.49 KB | None | 0 0
  1. #
  2. class ObesMenRelation(Schema):
  3.     id: int
  4.     obestetric_id: int = None #= models.ForeignKey(Obestetric, on_delete=models.CASCADE)
  5.     patient_id: int = None #= models.ForeignKey(Patients, verbose_name='Patient Name:', on_delete=models.CASCADE)
  6.     obdate: date = None # = models.DateField(blank=True, null=True, verbose_name='Follow Up Date:')
  7.     gyn: bool = False    #= models.BooleanField(verbose_name='Gyn:', default=False)
  8.     g: int = None     #= models.IntegerField(default=0, blank=True, null=True, verbose_name='G:')
  9.     p: int = None   # = models.IntegerField(default=0, blank=True, null=True, verbose_name='P:')
  10.     a: int = None   # = models.IntegerField(default=0, blank=True, null=True, verbose_name='A:')
  11.     nvd: bool = False  #     = models.BooleanField(default=False, verbose_name='NVD:')
  12.     cs: bool = False  #= models.BooleanField(default=False, verbose_name='CS:')
  13.     ld: str = ""  # = models.CharField(max_length=150, blank=True, null=True, verbose_name='LD:')
  14.     lc: str = ""  #= models.CharField(max_length=150, blank=True, null=True, verbose_name='LC:')
  15.     hist: str = ""
  16.     lmp: date = None        #= models.DateField(blank=True, null=True, verbose_name='LMP:')
  17.     edd: date = None        #= models.DateField(blank=True, null=True, verbose_name='EDD:')
  18.     ga: str  = ""      #= models.CharField(max_length=50, blank=True, null=True, verbose_name='G.A:')
  19.     remain: str = ""
  20.  
  21.  
  22. from typing import List    # Important import to get all objects without error
  23. @api.get('/all/obestetric/', response=List[ObesMenRelation])
  24. def get_obestetric(request):
  25.     # obs = Obestetric.objects.all().order_by('-id')
  26.     obs = Menstrual.objects.select_related('obestetric')
  27.     return obs
  28.  
  29.  
  30. ## This is my database
  31. clinicdb=# SELECT * from gyno_obestetric;
  32.  id | gyn | g | p | a | nvd | cs |   ld   |   lc   |               hist                | patient_id |   obdate
  33. ----+-----+---+---+---+-----+----+--------+--------+-----------------------------------+------------+------------
  34.   1 | f   | 1 | 0 | 0 | t   | f  | any ld | any lc | anything about obestetric history |          8 | 2021-03-12
  35.   2 | f   | 3 | 1 | 1 | f   | t  | any ld | any lc | any                               |          5 | 2021-03-12
  36. (2 rows)
  37.  
  38.  
  39. clinicdb=# SELECT * from gyno_menstrual;
  40.  id |    lmp     |    edd     | ga | remain | obestetric_id | patient_id
  41. ----+------------+------------+----+--------+---------------+------------
  42.  78 | 2021-01-01 | 2021-10-08 | 10 |     30 |             1 |          8
  43.  79 | 2020-07-01 | 2021-04-07 | 36 |      4 |             2 |          5
  44. (2 rows)
  45.  
  46.  
  47. ## This is the result after Execution from here(http://localhost:8000/api/docs#/default/apps_gyno_api_get_obestetric)
  48. [
  49.   {
  50.     "id": 78,
  51.     "obestetric_id": 1,
  52.     "patient_id": 8,
  53.     "obdate": null,
  54.     "gyn": false,
  55.     "g": null,     # why it is null
  56.     "p": null,     # why it is null
  57.     "a": null,     # why it is null
  58.     "nvd": false,  # why it is false
  59.     "cs": false,
  60.     "ld": "",      # why it is empty
  61.     "lc": "",      # why it is empty
  62.     "hist": "",    # why it is empty
  63.     "lmp": "2021-01-01",
  64.     "edd": "2021-10-08",
  65.     "ga": "10",
  66.     "remain": "30"
  67.   },
  68.   {
  69.     "id": 79,
  70.     "obestetric_id": 2,
  71.     "patient_id": 5,
  72.     "obdate": null,
  73.     "gyn": false,
  74.     "g": null,
  75.     "p": null,
  76.     "a": null,
  77.     "nvd": false,
  78.     "cs": false,
  79.     "ld": "",
  80.     "lc": "",
  81.     "hist": "",
  82.     "lmp": "2020-07-01",
  83.     "edd": "2021-04-07",
  84.     "ga": "36",
  85.     "remain": "4"
  86.   }
  87. ]
  88.  
Add Comment
Please, Sign In to add comment