예제 #1
0
    def list(self, request, *args, **kwargs):
        claim_date = request.GET.get('claimDateFrom')
        identifier = request.GET.get("identifier")

        queryset = self.get_queryset()

        if claim_date is not None:
            day, month, year = claim_date.split('-')
            try:
                claim_date_parsed = datetime.datetime(int(year), int(month),
                                                      int(day))
            except ValueError:
                result = OperationOutcomeConverter.build_for_400_bad_request(
                    "claimDateFrom should be in dd-mm-yyyy format")
                return Response(result.toDict(), status.HTTP_400_BAD_REQUEST)
            has_claim_in_range = Claim.objects\
                .filter(date_claimed__gte=claim_date_parsed)\
                .filter(insuree_id=OuterRef("id"))\
                .values("id")
            queryset = queryset.annotate(
                has_claim_in_range=Exists(has_claim_in_range)).filter(
                    has_claim_in_range=True)

        if identifier:
            queryset = queryset.filter(chf_id=identifier)

        serializer = PatientSerializer(self.paginate_queryset(queryset),
                                       many=True)
        return self.get_paginated_response(serializer.data)
예제 #2
0
def fhir_api_exception_handler(exc, context):
    response = call_default_exception_handler(exc, context)

    request_path = __get_path_from_context(context)
    if 'api_fhir' in request_path:
        from api_fhir.converters import OperationOutcomeConverter
        fhir_outcome = OperationOutcomeConverter.to_fhir_obj(exc)
        if not response:
            response = __create_server_error_response()
        response.data = fhir_outcome.toDict()

    return response
예제 #3
0
 def to_representation(self, obj):
     if isinstance(obj, HttpResponseBase):
         return OperationOutcomeConverter.to_fhir_obj(obj).toDict()
     elif isinstance(obj, FHIRBaseObject):
         return obj.toDict()
     return self.fhirConverter.to_fhir_obj(obj).toDict()
예제 #4
0
 def create_test_fhir_instance(self):
     exc = self.create_test_imis_instance()
     return OperationOutcomeConverter.to_fhir_obj(exc)
예제 #5
0
 def test_to_fhir_obj(self):
     exc = self.create_test_imis_instance()
     fhir_outcome = OperationOutcomeConverter.to_fhir_obj(exc)
     self.verify_fhir_instance(fhir_outcome)