Ejemplo n.º 1
0
 def pending(self, req):
     """Retrieve the current account's pending connections requests."""
     try:
         account = get_current_user()
         dtos = services.connections.pending_requests(account.id)
         api_models = [PendingConnApiModel.from_conn_dto(d) for d in dtos]
         return PendingConnApiModel.ProtoCollection()(items=api_models)
     except exp.ServiceExp as e:
         handle_exception(e)
Ejemplo n.º 2
0
 def caregiver(self, req):
     """Retrieve the account's caregiver details."""
     try:
         account = get_current_user()
         caregiver_dto = services.accounts.caregiver_by_account(account.id)
         api_model = CaregiverApiModel.from_caregiver_dto(caregiver_dto)
         return api_model
     except exp.ServiceExp as e:
         handle_exception(e)
Ejemplo n.º 3
0
 def my(self, req):
     """Retrieve the current account's connections."""
     try:
         account = get_current_user()
         dtos = services.connections.my_connections(account.id)
         print(dtos)
         api_models = [ConnApiModel.from_conn_dto(d) for d in dtos]
         return ConnApiModel.ProtoCollection()(items=api_models)
     except exp.ServiceExp as e:
         handle_exception(e)
Ejemplo n.º 4
0
 def patients_list(self, req):
     """Retrieve the account's patients."""
     try:
         account = get_current_user()
         patient_dtos = services.accounts.patients_by_account(account.id)
         api_models = [
             PatientApiModel.from_patient_dto(p) for p in patient_dtos
         ]
         return PatientApiModel.ProtoCollection()(items=api_models)
     except exp.ServiceExp as e:
         handle_exception(e)
Ejemplo n.º 5
0
 def caregiver_update(self, req):
     """Update the account's caregiver details."""
     try:
         account = get_current_user()
         caregiver_dto = CaregiverApiModel.to_caregiver_dto(req)
         caregiver_dto = services.accounts.caregiver_update(
             account.id, caregiver_dto)
         api_model = CaregiverApiModel.from_caregiver_dto(caregiver_dto)
         return api_model
     except exp.ServiceExp as e:
         handle_exception(e)
Ejemplo n.º 6
0
 def new_thread(self, req):
     """Create a new thread."""
     recipients, text = req.recipients, req.text
     try:
         account = get_current_user()
         thread_dto = services.messages.create_thread(
             account.id, recipients, text)
         api_model = ThreadApiModel.from_thread_dto(thread_dto)
         return api_model
     except exp.ServiceExp as e:
         handle_exception(e)
Ejemplo n.º 7
0
 def inbox(self, req):
     """Retrieve the account's inbox."""
     try:
         account = get_current_user()
         thread_dtos = services.messages.threads(account.id)
         api_models = [
             ThreadApiModel.from_thread_dto(thd) for thd in thread_dtos
         ]
         return ThreadApiModel.ProtoCollection()(items=api_models)
     except exp.ServiceExp as e:
         handle_exception(e)
Ejemplo n.º 8
0
 def patients_update(self, req):
     """Create or update a single patient."""
     try:
         account = get_current_user()
         patient_dto = PatientApiModel.to_patient_dto(req)
         patient_dto = services.accounts.patient_update(
             account.id, patient_dto)
         api_model = PatientApiModel.from_patient_dto(patient_dto)
         return api_model
     except exp.ServiceExp as e:
         handle_exception(e)
Ejemplo n.º 9
0
 def account_update(self, req):
     """Update account information."""
     try:
         actor = get_current_user()
         account_dto = AccountApiModel.to_account_dto(req)
         account_dto = services.accounts.account_update(
             actor.id, account_dto)
         api_model = AccountApiModel.from_account_dto(account_dto)
         refresh_userdata()
         return api_model
     except exp.ServiceExp as e:
         handle_exception(e)
Ejemplo n.º 10
0
    def account_get(self, req):
        """Retrieve the account's profile information.

        :param req.account_id: (int) ID of the account to retrieve.
        """
        account_id = req.account_id
        try:
            account_dto = services.accounts.account_by_id(account_id)
            api_model = AccountApiModel.from_account_dto(account_dto)
            return api_model
        except exp.ServiceExp as e:
            handle_exception(e)
Ejemplo n.º 11
0
    def request(self, req):
        """Send a connection request to a user.

        :param req.account_id: (int) ID of the account receiving the request.
        """
        resp = SimpleResponse()
        to_id = req.account_id
        try:
            account = get_current_user()
            services.connections.send_request(account.id, to_id)
            return resp.ToMessage()
        except exp.ServiceExp as e:
            handle_exception(e)
Ejemplo n.º 12
0
    def patients_remove(self, req):
        """Remove a single patient.

        :param req.patient_id: (int) ID of the patient to remove.
        """
        patient_id = req.patient_id
        resp = SimpleResponse()
        try:
            account = get_current_user()
            services.accounts.patient_remove(account.id, patient_id)
            return resp.ToMessage()
        except exp.ServiceExp as e:
            handle_exception(e)
Ejemplo n.º 13
0
 def query(self, req):
     """Query for caregivers with search criteria."""
     try:
         account = get_current_user()
         query_dto = SearchApiModel.to_query_dto(req)
         result_dtos = services.search.query(account.id, query_dto)
         api_models = [
             SearchResultApiModel.from_result_dto(res)
             for res in result_dtos
         ]
         return SearchResultApiModel.ProtoCollection()(items=api_models)
     except exp.ServiceExp as e:
         handle_exception(e)
Ejemplo n.º 14
0
    def hide(self, req):
        """Hide a message in a thread.

        :param req.message_id: (int) ID of the message to hide.
        """
        resp = SimpleResponse()
        message_id = req.message_id
        try:
            account = get_current_user()
            services.messages.hide_message(account.id, message_id)
            return resp.ToMessage()
        except exp.ServiceExp as e:
            handle_exception(e)
Ejemplo n.º 15
0
    def leave(self, req):
        """Leave a thread.

        :param req.thread_id: (int) ID of the thread.
        """
        resp = SimpleResponse()
        thread_id = req.thread_id
        try:
            account = get_current_user()
            services.messages.leave_thread(account.id, thread_id)
            return resp.ToMessage()
        except exp.ServiceExp as e:
            handle_exception(e)
Ejemplo n.º 16
0
    def remove(self, req):
        """Remove an existing connection.

        :param req.account_id: (int) ID of the account to be removed.
        """
        resp = SimpleResponse()
        other_id = req.account_id
        try:
            account = get_current_user()
            services.connections.remove_connection(account.id, other_id)
            return resp.ToMessage()
        except exp.ServiceExp as e:
            handle_exception(e)
Ejemplo n.º 17
0
    def send(self, req):
        """Send a reply in a thread.

        :param req.thread_id: (int) ID of the thread.
        :param req.text: (str) message to send.
        """
        thread_id, text = req.thread_id, req.text
        try:
            account = get_current_user()
            msg_dto = services.messages.send(account.id, thread_id, text)
            api_model = MessageApiModel.from_message_dto(msg_dto)
            return api_model
        except exp.ServiceExp as e:
            handle_exception(e)
Ejemplo n.º 18
0
    def decline(self, req):
        """Decline a connection request form a user.

        :param req.account_id: (int)
            ID of the account that sent the connection request.
        """
        resp = SimpleResponse()
        from_id = req.account_id
        try:
            account = get_current_user()
            services.connections.decline_request(account.id, from_id)
            return resp.ToMessage()
        except exp.ServiceExp as e:
            handle_exception(e)
Ejemplo n.º 19
0
    def thread(self, req):
        """Retrieve messages in a thread.

        :param req.thread_id: (int) ID of the thread.
        """
        thread_id = req.thread_id
        try:
            account = get_current_user()
            msg_dtos = services.messages.messages(account.id, thread_id)
            api_models = [
                MessageApiModel.from_message_dto(msg) for msg in msg_dtos
            ]
            return MessageApiModel.ProtoCollection()(items=api_models)
        except exp.ServiceExp as e:
            handle_exception(e)