[TOc]
pyenv == 1.2.26
pgadmin4 == 5.1
vscode == 1.55.1
macOS == 11.2.3
https://www.erdcloud.com/d/6JveQxBkK8PHyFBtY
-
git clone
$ git clone https://github.com/withyeah/OMOP_API.git
-
가상환경 생성 및 실행
$ python -m venv venv # macOS $ source venv/bin/activate # windows $ source venv/Scripts/activate
-
패키지 설치
$ pip install -r requirements.txt
-
run server
$ python manage.py runserver
-
datetime 모듈 사용
-
from datetime import datetime current_time = datetime.now() person_time_list = Person.objects.values('birth_datetime')
- person_time_list를 for문 순회
- current_time을 이용해 각 person의 현재 나이 계산
- 각 나이별 조건문을 이용해서 나이대에 해당하는 딕셔너리로 누적합
-
키워드 검색 기능, pagination 포함
-
키워드 검색 기능
-
# settings.py REST_FRAMEWORK = { 'DEFAULT_FILTER_BACKENDS': ['django_filters.rest_framework.DjangoFilterBackend'] }
# views.py class ConceptList(generics.ListAPIView): queryset = Concept.objects.all() serializer_class = ConceptSerializer filter_backends = [DjangoFilterBackend] filterset_fields = ['concept_name']
-
pagination
-
# settings.py REST_FRAMEWORK = { 'DEFAULT_PAGINATION_CLASS': 'rest_framework.pagination.LimitOffsetPagination', 'PAGE_SIZE': 100 }
# paginators.py class PatientsSetPagination(PageNumberPagination): page_size = 100 page_size_query_param = 'page_size' max_page_size = 1000
# views.py from .paginators import PatientsSetPagination @api_view(['GET']) def patient_view(request): paginator = PatientsSetPagination() paginator.page_size = 10 patient_objects = Person.objects.all() result_page = paginator.paginate_queryset(patient_objects, request) serializer = PersonSerializer(result_page, many=True) return paginator.get_paginated_response(serializer.data)
concept id와 concept name 매칭, pagination, 키워드 검색
- concept id와 concept name 매칭