Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

♻️ Rename Person to Participant in all relevant files #60

Merged
merged 1 commit into from
Jan 22, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions dataservice/__init__.py
Original file line number Diff line number Diff line change
@@ -4,7 +4,7 @@

from dataservice import commands
from dataservice.extensions import db, migrate
from dataservice.api.person.models import Person
from dataservice.api.participant.models import Participant
from config import config


@@ -33,7 +33,7 @@ def register_shellcontext(app):
def shell_context():
"""Shell context objects."""
return {'db': db,
'Person': Person}
'Participant': Participant}

app.shell_context_processor(shell_context)

6 changes: 3 additions & 3 deletions dataservice/api/README.md
Original file line number Diff line number Diff line change
@@ -36,9 +36,9 @@ Links to the next and previous page are provided in the `_links`.
```
{
"_links": {
"next": "/persons?page=3",
"self": "/persons?page=2",
"prev": "/persons?page=1"
"next": "/participants?page=3",
"self": "/participants?page=2",
"prev": "/participants?page=1"
},
"_status": {
"code": 200,
4 changes: 2 additions & 2 deletions dataservice/api/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from flask import Blueprint
from flask_restplus import Api
from dataservice.api.person import person_api
from dataservice.api.participant import participant_api

api_v1 = Blueprint('api', __name__, url_prefix='/v1')

@@ -11,7 +11,7 @@
default='',
default_label='')

api.add_namespace(person_api)
api.add_namespace(participant_api)


@api.documentation
10 changes: 5 additions & 5 deletions dataservice/api/common/serializers.py
Original file line number Diff line number Diff line change
@@ -8,10 +8,10 @@
description='ID assigned by Kids First'),
'created_at': fields.String(
example=datetime.now().isoformat(),
description='Date Person was registered in with the DCC'),
description='Date Participant was registered in with the DCC'),
'modified_at': fields.String(
example=datetime.now().isoformat(),
description='Date of last update to the Persons data')
description='Date of last update to the Participants data')
})

_status_fields = Model('Status', {
@@ -30,13 +30,13 @@

_paginate_fields = Model('PaginateFields', {
'next': fields.String(
example='/persons?page=3',
example='/participants?page=3',
description='Location of the next page'),
'self': fields.String(
example='/persons?page=2',
example='/participants?page=2',
description='Location of the current page'),
'prev': fields.String(
example='/persons?page=1',
example='/participants?page=1',
description='Location of the previous page')
})

3 changes: 3 additions & 0 deletions dataservice/api/participant/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
A participant is one of the central entities of the Kid's First DCC.

### Fields
1 change: 1 addition & 0 deletions dataservice/api/participant/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from .resources import participant_api
Original file line number Diff line number Diff line change
@@ -2,15 +2,15 @@
from dataservice.api.common.model import Base


class Person(db.Model, Base):
class Participant(db.Model, Base):
"""
Person entity.
Participant entity.

:param _id: Unique id assigned by RDBMS
:param kf_id: Unique id given by the Kid's First DCC
:param external_id: Name given to person by contributor
:param external_id: Name given to participant by contributor
:param created_at: Time of object creation
:param modified_at: Last time of object modification
"""
__tablename__ = "person"
__tablename__ = "participant"
external_id = db.Column(db.String(32))
114 changes: 114 additions & 0 deletions dataservice/api/participant/resources.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
from flask import request
from flask_restplus import Namespace, Resource

from dataservice.extensions import db
from dataservice.api.participant import models
from dataservice.api.common.formatters import kf_response

description = open('dataservice/api/participant/README.md').read()

participant_api = Namespace(name='participants', description=description)

from dataservice.api.participant.serializers import ( # noqa
participant_fields,
participant_list,
participant_response
)


@participant_api.route('/')
class ParticipantList(Resource):
@participant_api.marshal_with(participant_list)
def get(self):
"""
Get all participants

Returns paginated participants
"""
participants = models.Participant.query.all()
return kf_response(participants, 200, '{} participants'.
format(len(participants)))

@participant_api.marshal_with(participant_response)
@participant_api.doc(responses={201: 'participant created',
400: 'invalid data'})
@participant_api.expect(participant_fields)
def post(self):
"""
Create a new participant

Creates a new participant and assigns a Kids First id
"""
body = request.json
participant = models.Participant(**body)
db.session.add(participant)
db.session.commit()

return kf_response(participant, 201, 'participant created')


@participant_api.route('/<string:kf_id>')
class Participant(Resource):
@participant_api.marshal_with(participant_response)
@participant_api.doc(responses={200: 'participant found',
404: 'participant not found'})
def get(self, kf_id):
"""
Get a participant by id
Gets a participant given a Kids First id
"""
participant = models.Participant.query.filter_by(kf_id=kf_id).\
one_or_none()
if not participant:
return self._not_found(kf_id)

return kf_response(participant, 200, 'participant found')

@participant_api.marshal_with(participant_response)
@participant_api.doc(responses={201: 'participant updated',
400: 'invalid data',
404: 'participant not found'})
@participant_api.expect(participant_fields)
def put(self, kf_id):
"""
Update an existing participant
"""
body = request.json
participant = models.Participant.query.\
filter_by(kf_id=kf_id).one_or_none()

if not participant:
self._not_found(kf_id)

participant.external_id = body.get('external_id')
db.session.commit()

return kf_response(participant, 201, 'participant updated')

@participant_api.marshal_with(participant_response)
@participant_api.doc(responses={204: 'participant deleted',
404: 'participant not found'})
def delete(self, kf_id):
"""
Delete participant by id

Deletes a participant given a Kids First id
"""
participant = models.Participant.query.\
filter_by(kf_id=kf_id).one_or_none()

if not participant:
self._not_found(kf_id)

db.session.delete(participant)
db.session.commit()

return kf_response(participant, 200, 'participant deleted')

def _not_found(self, kf_id):
"""
Temporary helper - will do error handling better later
"""
message = 'participant with kf_id \'{}\' not found'.format(kf_id)
return kf_response(code=404,
message=message)
34 changes: 34 additions & 0 deletions dataservice/api/participant/serializers.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
from flask_restplus import fields

from dataservice.api.common.serializers import (
base_entity,
base_response,
base_pagination,
_status_fields,
_paginate_fields
)
from dataservice.api.participant.resources import participant_api


participant_api.models['Status'] = _status_fields
participant_api.models['PaginateFields'] = _paginate_fields

# Fields unique to a Participant, used as the new participant request model
participant_fields = participant_api.model('ParticipantFields', {
'external_id': fields.String(
example='SUBJ-3993',
description='Identifier used in the original study data')
})

participant_model = participant_api.clone('Participant', base_entity,
participant_fields)

participant_list = participant_api.clone("ParticipantsList", base_pagination, {
"results": fields.List(fields.Nested(participant_model))
})

participant_response = participant_api.clone('ParticipantResponse',
base_response, {
'results': fields.Nested(
participant_model)
})
3 changes: 0 additions & 3 deletions dataservice/api/person/README.md

This file was deleted.

1 change: 0 additions & 1 deletion dataservice/api/person/__init__.py

This file was deleted.

108 changes: 0 additions & 108 deletions dataservice/api/person/resources.py

This file was deleted.

Loading