def test_read_missing_id(self, mock_get_store): """Raises an error when the id was not provided at init""" resource = Patient() mock_get_store.return_value.normalize_resource.return_value = resource r = BaseResource(resource=resource) with pytest.raises(BadRequest, match="Resource ID is required"): r.read() assert mock_get_store.return_value.read.call_count == 0
def test_create_extra_id(self, mock_get_store): """Accepts the resource data when an id was provided""" resource = Patient(id="test") mock_get_store.return_value.normalize_resource.return_value = resource mock_get_store.return_value.create.return_value = resource mock_get_store.return_value.read.return_value = None r = BaseResource(resource=resource) r.create() assert r.id == "test" assert r.resource == resource
def test_delete_missing_id(self, mock_get_store): """Raises an error when the patch data is not provided""" resource = Patient() mock_get_store.return_value.normalize_resource.return_value = resource r = BaseResource(resource=resource) with pytest.raises( BadRequest, match="Resource ID is required to delete it", ): r = r.delete() assert mock_get_store.return_value.update.call_count == 0
def test_delete(self, mock_get_store): """Calls the delete method of the fhirstore client""" resource = Patient(id="test") mock_get_store.return_value.normalize_resource.return_value = resource r = BaseResource(resource=resource) r.delete() mock_get_store.return_value.delete.assert_called_once_with( "BaseResource", "test") assert r.resource is None assert r.id is None
def test_patch_missing_id(self, mock_get_store): """Raises an error when the resource id was not provided at init""" resource = Patient(gender="test") mock_get_store.return_value.normalize_resource.return_value = resource r = BaseResource(resource=resource) with pytest.raises( BadRequest, match="Resource ID is required to patch a resource", ): r.patch({"some": "patch"}) assert mock_get_store.return_value.patch.call_count == 0
def test_patch_missing_data(self, mock_get_store): """Raises an error when the patch data is not provided""" resource = Patient(id="test") mock_get_store.return_value.normalize_resource.return_value = resource r = BaseResource(id="test") with pytest.raises( BadRequest, match="Patch data is required to patch a resource", ): r.patch(None) assert mock_get_store.return_value.patch.call_count == 0
def test_read(self, mock_get_store): """Test read method. Calls the read method of the fhirstore client and registers the resource. """ resource = Patient(id="test") mock_get_store.return_value.normalize_resource.return_value = resource mock_get_store.return_value.read.return_value = resource r = BaseResource(id="test") r.read() mock_get_store.return_value.read.assert_called_once_with( "BaseResource", "test") assert r.resource == resource
def test_create(self, mock_uuid, mock_get_store): """Test create method. Calls the create method of the fhirstore client and registers the ID """ resource = Patient(gender="male") mock_get_store.return_value.normalize_resource.return_value = resource mock_get_store.return_value.create.return_value = resource mock_get_store.return_value.read.return_value = None r = BaseResource(resource=resource) r.create() mock_get_store.return_value.create.assert_called_once_with(resource) assert r.id == "uuid" assert r.resource == resource
def test_search_params(self, mock_get_store): """ Calls the search method of the fhirstore client using `params` """ resource = Patient(id="test") mock_get_store.return_value.normalize_resource.return_value = resource mock_get_store.return_value.search.return_value = resource r = BaseResource(resource=resource) params = MultiDict((("name", "Vincent"), )) res = r.search(params=params) assert res == resource mock_get_store.return_value.search.assert_called_once_with( "BaseResource", as_json=True, params=params, query_string=None) assert r.resource == resource assert r.id == resource.id
def test_search_qs(self, mock_get_store): """ Calls the search method of the fhirstore client using `query_string` """ resource = Patient(id="test") mock_get_store.return_value.normalize_resource.return_value = resource mock_get_store.return_value.search.return_value = resource r = BaseResource(resource=resource) res = r.search(query_string="name=Vincent") assert res == resource mock_get_store.return_value.search.assert_called_once_with( "BaseResource", as_json=True, params=None, query_string="name=Vincent") assert r.resource == resource assert r.id == resource.id
# page_file = "temp/pg"+str(count)+".png" # page.save(page_file, "PNG") # count = count+1 # for page_num in range(count): # page_file = "temp/pg"+str(page_num)+".png" # score_assessment_form(page_file, page_num, # wThresh=W_THRESH, hThresh=H_THRESH) # print("Raw Score:", subtotal) # creating FHIR resource for patient record pat = Patient({ "id": "1", "name": [{ "given": ["John"], "family": "Doe" }], "birthDate": "2019-01-24" }) print(pat) enc = Encounter() enc.subject = pat docref_json = { "resourceType": "DocumentReference", } doc = DocumentReference() obs = Observation() print("--finish--")