Skip to content

Commit

Permalink
code refactoring using BLACK
Browse files Browse the repository at this point in the history
  • Loading branch information
ujjawalpoudel committed Apr 15, 2023
1 parent a21335f commit 0709fdb
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 7 deletions.
20 changes: 16 additions & 4 deletions app/models/medicalrecordDbModel.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,21 @@
from mongoengine import EmbeddedDocument, Document, EmbeddedDocumentField, FloatField, StringField, ListField, ReferenceField, DateTimeField
from mongoengine import (
EmbeddedDocument,
Document,
EmbeddedDocumentField,
FloatField,
StringField,
ListField,
ReferenceField,
DateTimeField,
)
from mongoengine.errors import ValidationError
import datetime


# Custom modules
from app.models.patientDbModel import Patient


class DefaultAttributes:
meta = {"allow_inheritance": True}
creation_date = DateTimeField()
Expand All @@ -21,11 +31,13 @@ def update(self, *args, **kwargs):
self.modified_date = datetime.datetime.now()
return super(DefaultAttributes, self).save(*args, **kwargs)


class Medication(EmbeddedDocument):
name = StringField(required=True)
dosage = StringField(required=True)
frequency = StringField(required=True)



# "MedicalRecord" model with validators
class MedicalRecord(Document):
bloodSugarLevel = FloatField(min_value=0, max_value=500)
Expand All @@ -40,8 +52,8 @@ class MedicalRecord(Document):
# Custom validation method for the "MedicalRecord" model
def clean(self):
# Check if systolic pressure is greater than diastolic pressure
if(self.systolicPressure and self.diastolicPressure):
if self.systolicPressure and self.diastolicPressure:
if self.systolicPressure < self.diastolicPressure:
raise ValidationError(
"Systolic pressure cannot be less than diastolic pressure"
)
)
3 changes: 2 additions & 1 deletion app/routes/chatbotCRUD.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,8 @@ def get_chatbot_user_by_id(id):
# Create response body with success message and user details
body = {
"msg": "Successfully get single user details.",
"data": json.loads(user.to_json()),
# "data": json.loads(user.to_json()),
"data": user.to_dict(),
}
# Return response with 200 OK status code and response body
return response(200, body)
Expand Down
8 changes: 6 additions & 2 deletions app/routes/medicalRecordCRUD.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,9 @@ def update_medicalrecord_by_id(id):


# * Define API, which read id and delete medical record
@medicalrecord_module.route("/<id>", methods=["DELETE"], endpoint="delete-medical-record")
@medicalrecord_module.route(
"/<id>", methods=["DELETE"], endpoint="delete-medical-record"
)
@error_handler
def delete_medicalrecord_by_id(id):
try:
Expand All @@ -87,7 +89,9 @@ def get_all_medicalrecords():


# * Define API, which takes document id and returns value of that document
@medicalrecord_module.route("/<id>", methods=["GET"], endpoint="get-single-medical-record")
@medicalrecord_module.route(
"/<id>", methods=["GET"], endpoint="get-single-medical-record"
)
@error_handler
def get_medicalrecord_by_id(id):
try:
Expand Down

0 comments on commit 0709fdb

Please sign in to comment.