Beispiel #1
0
 def put(self, token):
     try:
         data = self.parser.parse_args()
         validateObj = LanguageModel.validateData(data, request)
         if type(validateObj) is dict:
             return {"success": False, "errors": validateObj}, 400
         
         language_id = decodeID(token)
         language = LanguageModel.find_by_id(language_id)
         if not language or language.token != token:
             return {"success": False, 'message': 'Record Not Found'}, 404
         
             
         language.language_name = data['language_name']
         language.modified_on = datetime.now()
         language.modified_by = 1
         name=data['language_name']
         if name.strip():
             language.save_to_db()
         else :
             return {"success": False, "message":"String Should not be empty"}
         
         return {"success": True, "message": "Record updated successfully."}, 200
     except Exception as e:
         return {"success": False, "message": str(e)}
Beispiel #2
0
    def post(self, name, voice):
        #   if LanguageModel.find_by_name(name):
        #       return {'message': "A language with name '{}' already exists.".format(name)}, 400

        language = LanguageModel(name, voice)
        try:
            language.save_to_db()
        except:
            return {"message": "An error occurred creating the language."}, 500

        return language.json(), 201
Beispiel #3
0
    def put(self, name):
        language = LanguageModel.find_by_name(name)
        if not language:
            return {'message': 'Language not found'}, 404

        data = Language.parser.parse_args()
        updated_language = LanguageModel(name, **data)
        language.voice = updated_language.voice

        try:
            language.save_to_db()
        except:
            return {"message": "An error occurred updating the language."}, 500

        return language.json(), 201
Beispiel #4
0
 def get(self, language_name):
     language = LanguageModel.find_by_name(language_name)
     try:
         if language:
             return language.json()
     except Exception as e:
         return {"message": "Record not found'{}'".format(e)}, 404
Beispiel #5
0
 def get(cls, token):
     try:
         language_id = decodeID(token)
         language = LanguageModel.find_by_id(language_id)
         if not language or language.token != token:
             return {"success": False, 'message': 'Record Not Found'}, 404
         return language.json(), 200
     except Exception as e:
         return {"success": False, "message": str(e)}
Beispiel #6
0
 def delete(cls, language_name):
     language = LanguageModel.find_by_name(language_name)
     if language:
         language.deleted_by = 1
         language.deleted_on = datetime.now()
         language.save_to_db()
         #language.delete_from_db()
         return {'message': 'Record deleted'}
     else:
         return {"Message": "Record Not FOUND"}
Beispiel #7
0
 def post(self, language_name):
     db.create_all()
     db.session.commit()
     if LanguageModel.find_by_name(language_name):
         return {
             'message':
             "An Record with name '{}' already exists.".format(
                 language_name)
         }, 400
     language = LanguageModel(language_name)
     language.created_by = 1
     language.created_on = datetime.now()
     language.modified_by = 0
     language.deleted_by = 0
     try:
         language.save_to_db()
     except Exception as e:
         return {
             "message":
             "An error occurred while inserting the Record.'{}'".format(e)
         }
     return language.json(), 201
Beispiel #8
0
 def delete(cls, token):
     try:
         language_id = decodeID(token)
         language = LanguageModel.find_by_id(language_id)
         if not language or language.token != token:
             return {"success": False, 'message': 'Record Not Found'}, 404
         
         language.deleted_by =1
         language.deleted_on = datetime.now()
         language.save_to_db()
         #language.delete_from_db()
         return {"success": True, 'message': 'Record deleted.'}, 200
     except Exception as e:
         return {"success": False, "message": str(e)}
Beispiel #9
0
    def delete(self, name):
        language = LanguageModel.find_by_name(name)
        if language:
            language.delete_from_db()

        return {'message': 'Language deleted'}
Beispiel #10
0
 def get(self, name):
     language = LanguageModel.find_by_name(name)
     if language:
         return language.json()
     return {'message': 'Language not found'}, 404
Beispiel #11
0
    def update(self, provider_data: dict):
        """
        Updates attributes of the provider model object.

        Takes in a dict of serialized provider data.
        Returns the updated provider model object.
        """
        # import down here to avoid circular imports
        from models.designation import DesignationModel
        from models.language import LanguageModel
        from models.specialty import SpecialtyModel

        for key, value in provider_data.items():
            if key not in {
                    "specialty", "languages", "designations", "addresses",
                    "procedural_wait_times"
            }:
                setattr(self, key, value)

        if "specialty" in provider_data:
            specialty = provider_data["specialty"]
            specialty_id = specialty['id']

            self.specialty_id = specialty_id

        if "languages" in provider_data:
            languages = provider_data["languages"]

            existing_languages = self.languages

            # delete all existing languages because we are uploading a new list
            for language in existing_languages:
                # row will be deleted from the association table automatically
                self.languages.remove(language)

            for item in languages:
                language_obj = LanguageModel.find_by_id(item['id'])

                provider_model_obj_with_languages = self.languages

                append_to_association_table(self,
                                            child_model_obj=language_obj,
                                            parent_model_obj_with_attribute=
                                            provider_model_obj_with_languages)

        if "designations" in provider_data:
            designations = provider_data["designations"]

            existing_designations = self.designations

            # delete all existing designations because we are uploading a new list
            for designation in existing_designations:
                # row will be deleted from the association table automatically
                self.designations.remove(designation)

            for item in designations:

                designation_obj = DesignationModel.find_by_id(item['id'])

                provider_model_obj_with_designations = self.designations

                append_to_association_table(
                    self,
                    child_model_obj=designation_obj,
                    parent_model_obj_with_attribute=
                    provider_model_obj_with_designations)

        if "addresses" in provider_data:
            addresses = provider_data["addresses"]

            if addresses:
                address_model_list = []
                for place in addresses:
                    address_model = AddressModel(
                        address=place["address"],
                        latitude=place["latitude"],
                        longitude=place["longitude"],
                        geo=place["geo"],
                    )

                    if "start_hour" in place:
                        start_hour = place["start_hour"]
                        start_hour_dt = datetime.strptime(start_hour,
                                                          '%H:%M').time()
                        address_model.start_hour = start_hour_dt

                    if "end_hour" in place:
                        end_hour = place["end_hour"]
                        end_hour_dt = datetime.strptime(end_hour,
                                                        '%H:%M').time()
                        address_model.end_hour = end_hour_dt

                    if "is_wheelchair_accessible" in place:
                        is_wheelchair_accessible = place[
                            "is_wheelchair_accessible"]
                    else:
                        is_wheelchair_accessible = False

                    address_model.is_wheelchair_accessible = is_wheelchair_accessible

                    if "is_accepting_new_patients" in place:
                        is_accepting_new_patients = place[
                            "is_accepting_new_patients"]
                    else:
                        is_accepting_new_patients = False

                    address_model.is_accepting_new_patients = is_accepting_new_patients

                    if "fax" in place:
                        address_model.fax = place["fax"]

                    if "phone" in place:
                        address_model.phone = place["phone"]

                    address_model_list.append(address_model)

                # delete all previous addresses
                del self.addresses

                # add addresses from this request
                self.addresses = address_model_list

        if "procedural_wait_times" in provider_data:
            procedural_wait_times = provider_data["procedural_wait_times"]

            if procedural_wait_times:
                procedural_wait_times_model_list = []

                for procedural_wait_time in procedural_wait_times:
                    procedural_wait_time_model = ProceduralWaitTimeModel(
                        procedure=procedural_wait_time["procedure"],
                        wait_time=procedural_wait_time["wait_time"],
                    )

                    procedural_wait_times_model_list.append(
                        procedural_wait_time_model)

                # delete all previous procedural_wait_times
                del self.procedural_wait_times

                # add procedural_wait_times from this request
                self.procedural_wait_times = procedural_wait_times_model_list

            else:
                # if procedural_wait_times list is empty
                del self.procedural_wait_times

                self.procedural_wait_times = []

        return self
Beispiel #12
0
    "Orthopedic Surgery", "Otolaryngology - Head and Neck Surgery",
    "Paediatric Cardiology", "Paediatric Emergency Medicine",
    "Paediatric Haematology/Oncology", "Paediatric Radiology",
    "Paediatric Surgery", "Pain Medicine", "Palliative Medicine",
    "Pathology and Bacteriology", "Pediatric General Surgery", "Pediatrics",
    "Physical Medicine and Rehabilitation", "Plastic Surgery", "Psychiatry",
    "Public Health", "Public Health and Preventive Medicine",
    "Radiation Oncology", "Respirology", "Rheumatology", "Thoracic Surgery",
    "Transfusion Medicine", "Urology", "Vascular Surgery"
]

for designation in designations:
    with app.app_context():
        db.session.add(DesignationModel(name=designation))
        db.session.commit()

for language in languages:
    with app.app_context():
        db.session.add(LanguageModel(name=language))
        db.session.commit()

for provider_type in provider_types:
    with app.app_context():
        db.session.add(ProviderTypeModel(name=provider_type))
        db.session.commit()

for specialty in specialties:
    with app.app_context():
        db.session.add(SpecialtyModel(name=specialty))
        db.session.commit()
Beispiel #13
0
 def get(self):
     return {
         'languages': language_list_schema.dump(LanguageModel.find_all())
     }, 200
Beispiel #14
0
    def post(self):
        data = self.parser.parse_args()
        language = LanguageModel(**data)
        language.created_by = 1
        language.created_on = datetime.now()
        language.modified_by = 0
        language.deleted_by = 0
        language.modified_on = None
        language.deleted_on =  None
        
        try:
            validateObj = LanguageModel.validateData(data, request)

            if type(validateObj) is dict:
                return {"success": False, "errors": validateObj}, 400

            if LanguageModel.find_by_name(data['language_name']):
                return {"success": False, "message": "A language with that Record Name already exists"}, 400
            name=data['language_name']
            if name.strip():
                language.save_to_db()
                language.token = encodeID(language.language_id)
                language.save_to_db()
            else:
                return {"success": False, "message":"String Should not be empty"}
        except Exception as e:
            return {"message": "An error occurred creating the Record.'{}'".format(e)}, 500
        return language.json(), 201