generated from CDCgov/template
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
endpoints to update person cluster on patient (#101)
## Description Adding two new endpoints to support updating the Person cluster a Patient belongs to. One is for assigning the Patient to a specific cluster, and another is for assigning them to a new cluster. ## Related Issues closes #96 ## Additional Notes - `POST /patient/<ref-id>/person` takes an empty payload, creates a new Person cluster, assigns the Patient to that cluster and returns back reference ids for both the Patient and Person. - `PATCH /patient/<ref-id>/person` takes a person ref id payload, assigned the Patient to that existing Person and returns back reference ids for both the Patient and Person.
- Loading branch information
1 parent
2533adb
commit e89fdda
Showing
9 changed files
with
588 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
""" | ||
recordlinker.routes.patient_router | ||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
This module implements the patient router for the RecordLinker API. Exposing | ||
the patient API endpoints. | ||
""" | ||
|
||
import uuid | ||
|
||
import fastapi | ||
import sqlalchemy.orm as orm | ||
|
||
from recordlinker import schemas | ||
from recordlinker.database import get_session | ||
from recordlinker.linking import mpi_service as service | ||
|
||
router = fastapi.APIRouter() | ||
|
||
|
||
@router.post( | ||
"/{patient_reference_id}/person", | ||
summary="Assign Patient to new Person", | ||
status_code=fastapi.status.HTTP_201_CREATED, | ||
) | ||
def create_person( | ||
patient_reference_id: uuid.UUID, session: orm.Session = fastapi.Depends(get_session) | ||
) -> schemas.PatientPersonRef: | ||
""" | ||
Create a new Person in the MPI database and link the Patient to them. | ||
""" | ||
patient = service.get_patient_by_reference_id(session, patient_reference_id) | ||
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, | ||
) | ||
def update_person( | ||
patient_reference_id: uuid.UUID, | ||
data: schemas.PersonRef, | ||
session: orm.Session = fastapi.Depends(get_session), | ||
) -> schemas.PatientPersonRef: | ||
""" | ||
Update the Person linked on the Patient. | ||
""" | ||
patient = service.get_patient_by_reference_id(session, patient_reference_id) | ||
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_400_BAD_REQUEST) | ||
|
||
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 | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import uuid | ||
|
||
import pydantic | ||
|
||
|
||
class PersonRef(pydantic.BaseModel): | ||
person_reference_id: uuid.UUID | ||
|
||
|
||
class PatientPersonRef(pydantic.BaseModel): | ||
patient_reference_id: uuid.UUID | ||
person_reference_id: uuid.UUID |
Oops, something went wrong.