From e7adf72c1bb66954982cb77b683b0f9f953709ac Mon Sep 17 00:00:00 2001 From: Marcelle <53578688+m-goggins@users.noreply.github.com> Date: Wed, 19 Feb 2025 10:59:02 -0800 Subject: [PATCH] removes deprecated API endpoints (#220) ## Description Removes deprecated API endpoints in `/patient` now that they have been replaced by endpoints in the `/person` router. ## Related Issues Fixes #160 --- src/recordlinker/routes/patient_router.py | 61 +------------------ tests/unit/routes/test_patient_router.py | 73 ++++------------------- 2 files changed, 13 insertions(+), 121 deletions(-) diff --git a/src/recordlinker/routes/patient_router.py b/src/recordlinker/routes/patient_router.py index c1bd9a2b..91dd99a2 100644 --- a/src/recordlinker/routes/patient_router.py +++ b/src/recordlinker/routes/patient_router.py @@ -19,64 +19,6 @@ router = fastapi.APIRouter() -@router.post( - "/{patient_reference_id}/person", - summary="Assign Patient to new Person", - status_code=fastapi.status.HTTP_201_CREATED, - deprecated=True, -) -def create_person( - patient_reference_id: uuid.UUID, session: orm.Session = fastapi.Depends(get_session) -) -> schemas.PatientPersonRef: - """ - **NOTE**: This endpoint is deprecated. Use the POST `/person` endpoint instead. - - **NOTE**: This endpoint will be removed in v25.3.0. - - Create a new Person in the MPI database and link the Patient to them. - """ - patient = service.get_patients_by_reference_ids(session, patient_reference_id)[0] - if patient is None: - raise fastapi.HTTPException(status_code=fastapi.status.HTTP_404_NOT_FOUND) - - person = service.update_person_cluster(session, [patient], commit=False) - return schemas.PatientPersonRef( - patient_reference_id=patient.reference_id, person_reference_id=person.reference_id - ) - - -@router.patch( - "/{patient_reference_id}/person", - summary="Assign Patient to existing Person", - status_code=fastapi.status.HTTP_200_OK, - deprecated=True, -) -def update_person( - patient_reference_id: uuid.UUID, - data: schemas.PersonRef, - session: orm.Session = fastapi.Depends(get_session), -) -> schemas.PatientPersonRef: - """ - **NOTE**: This endpoint is deprecated. Use the PATCH `/person/{person_reference_id}` endpoint instead. - - **NOTE**: This endpoint will be removed in v25.3.0. - - Update the Person linked on the Patient. - """ - patient = service.get_patients_by_reference_ids(session, patient_reference_id)[0] - if patient is None: - raise fastapi.HTTPException(status_code=fastapi.status.HTTP_404_NOT_FOUND) - - person = service.get_person_by_reference_id(session, data.person_reference_id) - if person is None: - raise fastapi.HTTPException(status_code=fastapi.status.HTTP_422_UNPROCESSABLE_ENTITY) - - person = service.update_person_cluster(session, [patient], person, commit=False) - return schemas.PatientPersonRef( - patient_reference_id=patient.reference_id, person_reference_id=person.reference_id - ) - - @router.post( "/", summary="Create a patient record and link to an existing person", @@ -136,7 +78,8 @@ def get_patient( person_reference_id=patient.person.reference_id, record=patient.record, external_patient_id=patient.external_patient_id, - external_person_id=patient.external_person_id) + external_person_id=patient.external_person_id, + ) @router.patch( diff --git a/tests/unit/routes/test_patient_router.py b/tests/unit/routes/test_patient_router.py index f28823a5..176f82e5 100644 --- a/tests/unit/routes/test_patient_router.py +++ b/tests/unit/routes/test_patient_router.py @@ -10,63 +10,6 @@ from recordlinker import models -class TestCreatePerson: - def test_invalid_reference_id(self, client): - response = client.post("/patient/123/person") - assert response.status_code == 422 - - def test_invalid_patient(self, client): - response = client.post(f"/patient/{uuid.uuid4()}/person") - assert response.status_code == 404 - - def test_create_person(self, client): - original_person = models.Person() - patient = models.Patient(person=original_person, data={}) - client.session.add(patient) - client.session.flush() - - resp = client.post(f"/patient/{patient.reference_id}/person") - assert resp.status_code == 201 - assert resp.json()["patient_reference_id"] == str(patient.reference_id) - assert resp.json()["person_reference_id"] != str(original_person.reference_id) - - -class TestUpdatePerson: - def test_invalid_reference_id(self, client): - response = client.patch("/patient/123/person") - assert response.status_code == 422 - - def test_invalid_patient(self, client): - data = {"person_reference_id": str(uuid.uuid4())} - response = client.patch(f"/patient/{uuid.uuid4()}/person", json=data) - assert response.status_code == 404 - - def test_invalid_person(self, client): - patient = models.Patient(person=models.Person(), data={}) - client.session.add(patient) - client.session.flush() - - data = {"person_reference_id": str(uuid.uuid4())} - response = client.patch(f"/patient/{patient.reference_id}/person", json=data) - assert response.status_code == 422 - - def test_update_person(self, client): - original_person = models.Person() - patient = models.Patient(person=original_person, data={}) - client.session.add(patient) - client.session.flush() - - new_person = models.Person() - client.session.add(new_person) - client.session.flush() - - data = {"person_reference_id": str(new_person.reference_id)} - resp = client.patch(f"/patient/{patient.reference_id}/person", json=data) - assert resp.status_code == 200 - assert resp.json()["patient_reference_id"] == str(patient.reference_id) - assert resp.json()["person_reference_id"] == str(new_person.reference_id) - - class TestCreatePatient: def test_missing_data(self, client): response = client.post("/patient") @@ -197,9 +140,14 @@ def test_invalid_patient(self, client): assert response.status_code == 404 def test_get_patient(self, client): - patient = models.Patient(person=models.Person(), data={ - "name": [{"given": ["John"], "family": "Doe"}], - }, external_patient_id="123", external_person_id="456") + patient = models.Patient( + person=models.Person(), + data={ + "name": [{"given": ["John"], "family": "Doe"}], + }, + external_patient_id="123", + external_person_id="456", + ) client.session.add(patient) client.session.flush() response = client.get(f"/patient/{patient.reference_id}") @@ -212,7 +160,9 @@ def test_get_patient(self, client): "birth_date": None, "sex": None, "address": [], - "name": [{"family": "Doe", "given": ["John"], "use": None, "prefix": [], "suffix": []}], + "name": [ + {"family": "Doe", "given": ["John"], "use": None, "prefix": [], "suffix": []} + ], "telecom": [], "race": None, "identifiers": [], @@ -220,4 +170,3 @@ def test_get_patient(self, client): "external_patient_id": "123", "external_person_id": "456", } -