예제 #1
0
    def test_search_not_found(self, mock_get_store):
        """
        Calls the search method and handles the case
        where no result is found.
        """
        resource = Patient(id="test")
        error = OperationOutcome(id="notfound",
                                 issue=[{
                                     "severity": "error",
                                     "code": "noop",
                                     "diagnostics": "bobo"
                                 }])
        mock_get_store.return_value.normalize_resource.return_value = resource
        mock_get_store.return_value.search.return_value = error
        r = BaseResource(resource=resource)

        res = r.search(query_string="name=NotFound")
        assert res == error

        mock_get_store.return_value.search.assert_called_once_with(
            "BaseResource",
            as_json=True,
            params=None,
            query_string="name=NotFound")
        assert r.resource == resource
        assert r.id == resource.id
예제 #2
0
파일: api.py 프로젝트: arkhn/warehouse-api
def patch(resource_type, id):
    if resource_type not in resources_models:
        raise OperationOutcome(f"Unknown resource type: {resource_type}")

    patch_data = request.get_json(force=True)
    model = resources_models[resource_type](id=id)
    return model.patch(patch_data).json()
예제 #3
0
파일: api.py 프로젝트: arkhn/warehouse-api
def read(resource_type, id):
    if resource_type not in resources_models:
        raise OperationOutcome(f"Unknown resource type: {resource_type}")

    model = resources_models[resource_type](id=id)

    return model.read().json()
예제 #4
0
파일: api.py 프로젝트: arkhn/warehouse-api
def create(resource_type):
    if resource_type not in resources_models:
        raise OperationOutcome(f"Unknown resource type: {resource_type}")

    resource_data = request.get_json(force=True)

    model = resources_models[resource_type](resource=resource_data)
    return model.create().json()
예제 #5
0
파일: api.py 프로젝트: arkhn/warehouse-api
def upload_bundle():
    # TODO methodology to avoid/process huge bundles
    bundle_data = request.get_json(force=True)

    if "resourceType" not in bundle_data or bundle_data["resourceType"] != "Bundle":
        raise OperationOutcome("input must be a FHIR Bundle resource")

    store = get_store()
    try:
        store.upload_bundle(bundle_data)
    except Exception as e:
        logging.error(f"Error while uploading bundle: {e}")
        return jsonify(success=False)

    return jsonify(success=True)
예제 #6
0
파일: api.py 프로젝트: arkhn/warehouse-api
def handle_bad_request(e):
    operation_outcome = OperationOutcome(
        issue=[{"severity": "error", "code": "invalid", "diagnostics": str(e)}]
    )
    return jsonify(operation_outcome.dict()), 400