예제 #1
0
파일: api.py 프로젝트: anukat2015/opal-1
    def create(self, request):
        """
        * Create a subrecord
        * Ping our integration upstream interface
        * Render the created subrecord back to the requester

        Raise appropriate errors for:

        * Nonexistant episode
        * Unexpected fields being passed in
        """
        from opal.models import Episode, PatientSubrecord

        subrecord = self.model()
        try:
            episode = Episode.objects.get(pk=request.data['episode_id'])
        except Episode.DoesNotExist:
            return Response('Nonexistant episode', status=status.HTTP_400_BAD_REQUEST)
        pre = episode.to_dict(request.user)

        if isinstance(subrecord, PatientSubrecord):
            del request.data['episode_id']
            patient_id = episode.patient.pk
            request.data['patient_id'] = patient_id

        try:
            subrecord.update_from_dict(request.data, request.user)
        except exceptions.APIError:
            return Response({'error': 'Unexpected field name'}, status=status.HTTP_400_BAD_REQUEST)

        episode = Episode.objects.get(pk=episode.pk)
        post = episode.to_dict(request.user)
        glossolalia.change(pre, post)

        return Response(subrecord.to_dict(request.user), status=status.HTTP_201_CREATED)
예제 #2
0
파일: api.py 프로젝트: anukat2015/opal-1
 def update(self, request, item):
     pre = self._item_to_dict(item, request.user)
     try:
         item.update_from_dict(request.data, request.user)
     except exceptions.APIError:
         return Response({'error': 'Unexpected field name'},
                         status=status.HTTP_400_BAD_REQUEST)
     except exceptions.ConsistencyError:
         return Response({'error': 'Item has changed'}, status=status.HTTP_409_CONFLICT)
     glossolalia.change(pre, self._item_to_dict(item, request.user))
     return Response(item.to_dict(request.user), status=status.HTTP_202_ACCEPTED)
예제 #3
0
파일: api.py 프로젝트: wjt/opal
 def update(self, request, item):
     pre = self._item_to_dict(item, request.user)
     try:
         item.update_from_dict(request.data, request.user)
     except exceptions.APIError:
         return Response({'error': 'Unexpected field name'},
                         status=status.HTTP_400_BAD_REQUEST)
     except exceptions.ConsistencyError:
         return Response({'error': 'Item has changed'},
                         status=status.HTTP_409_CONFLICT)
     glossolalia.change(pre, self._item_to_dict(item, request.user))
     return Response(item.to_dict(request.user),
                     status=status.HTTP_202_ACCEPTED)
예제 #4
0
 def test_change_calls_send_upstream(self, sender):
     with patch('opal.core.glossolalia.INTEGRATING', new=True):
         change = glossolalia.change({}, {'foo': 'bar'})
         self.assertEqual('change', sender.call_args[0][0])
         self.assertEqual(
             'bar',
             json.loads(sender.call_args[0][1]['data'])['post']['foo'])
예제 #5
0
파일: views.py 프로젝트: anukat2015/opal-1
def episode_detail_view(request, pk):
    try:
        episode = models.Episode.objects.get(pk=pk)
    except models.Episode.DoesNotExist:
        return HttpResponseNotFound()

    if request.method == 'GET':
        serialized = episode.to_dict(request.user)
        return _build_json_response(serialized)

    data = _get_request_data(request)

    try:
        pre = episode.to_dict(request.user)
        episode.update_from_dict(data, request.user)
        post = episode.to_dict(request.user)
        glossolalia.change(pre, post)
        return _build_json_response(episode.to_dict(request.user, shallow=True))
    except exceptions.ConsistencyError:
        return _build_json_response({'error': 'Item has changed'}, 409)
예제 #6
0
def episode_detail_view(request, pk):
    try:
        episode = models.Episode.objects.get(pk=pk)
    except models.Episode.DoesNotExist:
        return HttpResponseNotFound()

    if request.method == 'GET':
        serialized = episode.to_dict(request.user)
        return _build_json_response(serialized)

    data = _get_request_data(request)

    try:
        pre = episode.to_dict(request.user)
        episode.update_from_dict(data, request.user)
        post = episode.to_dict(request.user)
        glossolalia.change(pre, post)
        return _build_json_response(episode.to_dict(request.user,
                                                    shallow=True))
    except exceptions.ConsistencyError:
        return _build_json_response({'error': 'Item has changed'}, 409)
예제 #7
0
파일: api.py 프로젝트: wjt/opal
    def create(self, request):
        """
        * Create a subrecord
        * Ping our integration upstream interface
        * Render the created subrecord back to the requester

        Raise appropriate errors for:

        * Nonexistant episode
        * Unexpected fields being passed in
        """
        from opal.models import Episode, PatientSubrecord

        subrecord = self.model()
        try:
            episode = Episode.objects.get(pk=request.data['episode_id'])
        except Episode.DoesNotExist:
            return Response('Nonexistant episode',
                            status=status.HTTP_400_BAD_REQUEST)
        pre = episode.to_dict(request.user)

        if isinstance(subrecord, PatientSubrecord):
            del request.data['episode_id']
            patient_id = episode.patient.pk
            request.data['patient_id'] = patient_id

        try:
            subrecord.update_from_dict(request.data, request.user)
        except exceptions.APIError:
            return Response({'error': 'Unexpected field name'},
                            status=status.HTTP_400_BAD_REQUEST)

        episode = Episode.objects.get(pk=episode.pk)
        post = episode.to_dict(request.user)
        glossolalia.change(pre, post)

        return Response(subrecord.to_dict(request.user),
                        status=status.HTTP_201_CREATED)
예제 #8
0
파일: api.py 프로젝트: wjt/opal
 def destroy(self, request, item):
     pre = self._item_to_dict(item, request.user)
     item.delete()
     glossolalia.change(pre, self._item_to_dict(item, request.user))
     return Response('deleted', status=status.HTTP_202_ACCEPTED)
예제 #9
0
 def test_change_not_integratng(self, sender):
     with patch('opal.core.glossolalia.INTEGRATING', new=False):
         change = glossolalia.change(None, None)
         self.assertEqual(
             None, change)  # Mostly a proxy for "Does this stacktrace?"
         self.assertFalse(sender.called)
예제 #10
0
파일: api.py 프로젝트: anukat2015/opal-1
 def destroy(self, request, item):
     pre = self._item_to_dict(item, request.user)
     item.delete()
     glossolalia.change(pre, self._item_to_dict(item, request.user))
     return Response('deleted', status=status.HTTP_202_ACCEPTED)
예제 #11
0
 def test_change_calls_send_upstream(self, sender):
     with patch('opal.core.glossolalia.INTEGRATING', new=True):
         change = glossolalia.change({}, {'foo': 'bar'})
         self.assertEqual('change', sender.call_args[0][0])
         self.assertEqual('bar', json.loads(sender.call_args[0][1]['data'])['post']['foo'])
예제 #12
0
 def test_change_not_integratng(self, sender):
     with patch('opal.core.glossolalia.INTEGRATING', new=False):
         change = glossolalia.change(None, None)
         self.assertEqual(None, change) # Mostly a proxy for "Does this stacktrace?"
         self.assertFalse(sender.called)