Skip to content

Commit e6ae128

Browse files
Merge pull request #542 from biocore/csymons_reactivate_japanese
Reactivate Japanese Locale
2 parents 542547c + aefab1a commit e6ae128

File tree

12 files changed

+1021
-198
lines changed

12 files changed

+1021
-198
lines changed

microsetta_private_api/LEGACY/locale_data/japanese_gut.py

+9-9
Original file line numberDiff line numberDiff line change
@@ -6,24 +6,24 @@
66
_NEW_PARTICIPANT = {
77
'ADD_HUMAN_TITLE': '新しいプロフィール情報を追加する',
88
'SEL_AGE_RANGE': '参加者の年齢層を選択する:',
9-
'AGE_0_6': '',
10-
'AGE_7_12': '',
11-
'AGE_13_17': '',
9+
'AGE_0_6': '3ヶ月 - 6才',
10+
'AGE_7_12': '7〜12才',
11+
'AGE_13_17': '13〜17年',
1212
'AGE_18': '18歳以上',
1313

1414
'PARTICIPATION_AGREEMENT': '''''',
1515

1616
'EXHIBIT_A': '''''',
1717
'BILL_OF_RIGHTS': '''研究被験者の権利章典''',
1818
'TEXT_I_HAVE_READ_1': '私は同意書を読みました (又は代読してもらいました)。研究試験への参加を求められていることを理解し、この試験への参加に自由意志で同意します。私の個人データが処理される方法、関連した私の権利を理解しており、この同意書に記載されているように私のデータが処理されることに同意します。',
19-
'TEXT_I_HAVE_READ_SIMPLIFIED': '',
20-
'PERSON_ATTAINING_ASSENT': '',
21-
'TEXT_ASSENT_WITNESS': '',
22-
'OBTAINER_NAME': '',
23-
'TEXT_I_HAVE_READ_PARENT': '',
19+
'TEXT_I_HAVE_READ_SIMPLIFIED': 'はい、あなたはこの調査研究に参加します。',
20+
'PERSON_ATTAINING_ASSENT': '同意を得る人の署名',
21+
'TEXT_ASSENT_WITNESS': '私の判断において、参加者は自発的かつ自主的に同意し、研究に参加する意思を示す法的能力を持っています。',
22+
'OBTAINER_NAME': '同意を得る人の名前',
23+
'TEXT_I_HAVE_READ_PARENT': '私はこのフォームを読みました(または誰かが代読した)。私は、我が子の調査研究への参加に、同意を求められていることを理解しました。私は自発的に我が子がこの研究に参加することに同意します。我が子の個人データの処理方法、これに関連する権利、そして提供す',
2424
'PARTICIPANT_NAME': '参加者名',
2525
'PARTICIPANT_EMAIL': 'Eメール',
26-
'PARTICIPANT_PARENT_1': '',
26+
'PARTICIPANT_PARENT_1': '親/保護者の名前',
2727
'PARTICIPANT_PARENT_2': '',
2828
'PARTICIPANT_DECEASED_PARENTS': '',
2929
'DATE_SIGNED': 'DATE_SIGNED',

microsetta_private_api/api/__init__.py

+5-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@
1818
from ._source import (
1919
create_source, read_source, update_source, read_sources,
2020
create_human_source_from_consent, check_duplicate_source_name,
21-
scrub_source, check_source_ffq_prereqs, check_prompt_survey_update
21+
scrub_source, check_source_ffq_prereqs, check_prompt_survey_update,
22+
get_external_reports, get_external_report, get_external_report_bytes
2223
)
2324
from ._survey import (
2425
read_survey_template, read_survey_templates, read_answered_survey,
@@ -84,6 +85,9 @@
8485
'read_source',
8586
'check_source_ffq_prereqs',
8687
'check_prompt_survey_update',
88+
'get_external_reports',
89+
'get_external_report',
90+
'get_external_report_bytes',
8791
'update_source',
8892
'scrub_source',
8993
'read_sources',

microsetta_private_api/api/_source.py

+54-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import uuid
22
from datetime import date
3-
from flask import jsonify
3+
from flask import jsonify, make_response
44

55
from microsetta_private_api.api._account import _validate_account_access
66
from microsetta_private_api.api.literals import SRC_NOT_FOUND_MSG,\
@@ -194,3 +194,56 @@ def check_prompt_survey_update(account_id, source_id, token_info):
194194
s_t_r = SurveyTemplateRepo(t)
195195
prompt_update = s_t_r.check_prompt_survey_update(source_id)
196196
return jsonify({"prompt": prompt_update}), 200
197+
198+
199+
def get_external_reports(account_id, source_id, token_info):
200+
_validate_account_access(token_info, account_id)
201+
202+
with Transaction() as t:
203+
source_repo = SourceRepo(t)
204+
reports = source_repo.get_external_reports(source_id)
205+
for r in reports:
206+
r.file_contents = ""
207+
return jsonify(reports), 200
208+
209+
210+
def get_external_report(
211+
account_id, source_id, external_report_id, token_info
212+
):
213+
_validate_account_access(token_info, account_id)
214+
215+
with Transaction() as t:
216+
source_repo = SourceRepo(t)
217+
reports = source_repo.get_external_reports(
218+
source_id, external_report_id
219+
)
220+
if len(reports) != 1:
221+
return jsonify(code=404, message="Report not found"), 404
222+
223+
report = reports[0]
224+
225+
# Trying to jsonify the actual contents gets ugly, so we return
226+
# everything else here, and the contents in get_external_report_bytes
227+
report.file_contents = ""
228+
return jsonify(report.to_api()), 200
229+
230+
231+
def get_external_report_bytes(
232+
account_id, source_id, external_report_id, token_info
233+
):
234+
_validate_account_access(token_info, account_id)
235+
236+
with Transaction() as t:
237+
source_repo = SourceRepo(t)
238+
reports = source_repo.get_external_reports(
239+
source_id, external_report_id
240+
)
241+
242+
if len(reports) != 1:
243+
return jsonify(code=404, message="Report not found"), 404
244+
245+
report = reports[0]
246+
response = make_response(bytes(report.file_contents))
247+
response.headers.set("Content-Type", report.file_type)
248+
249+
return response

microsetta_private_api/api/microsetta_private_api.yaml

+112
Original file line numberDiff line numberDiff line change
@@ -679,6 +679,79 @@ paths:
679679
$ref: '#/components/responses/422UnprocessableEntity'
680680
# NB: This would be returned if source cannot be deleted bc has a sample assigned to it
681681

682+
'/accounts/{account_id}/sources/{source_id}/external_reports':
683+
get:
684+
operationId: microsetta_private_api.api.get_external_reports
685+
tags:
686+
- Sources
687+
summary: Get external reports attached to the source
688+
description: Get external reports attached to the source
689+
parameters:
690+
- $ref: '#/components/parameters/account_id'
691+
- $ref: '#/components/parameters/source_id'
692+
- $ref: '#/components/parameters/language_tag'
693+
responses:
694+
'200':
695+
description: Successfully returned list of external reports
696+
content:
697+
application/json:
698+
schema:
699+
type: array
700+
items:
701+
$ref: '#/components/schemas/external_report'
702+
'401':
703+
$ref: '#/components/responses/401Unauthorized'
704+
'403':
705+
$ref: '#/components/responses/403Forbidden'
706+
707+
'/accounts/{account_id}/sources/{source_id}/external_reports/{external_report_id}':
708+
get:
709+
operationId: microsetta_private_api.api.get_external_report
710+
tags:
711+
- Sources
712+
summary: Get full contents of external report
713+
description: Get full contents of external report
714+
parameters:
715+
- $ref: '#/components/parameters/account_id'
716+
- $ref: '#/components/parameters/source_id'
717+
- $ref: '#/components/parameters/external_report_id'
718+
- $ref: '#/components/parameters/language_tag'
719+
responses:
720+
'200':
721+
description: Successfully returned external report information
722+
content:
723+
application/json:
724+
schema:
725+
type: "object"
726+
'401':
727+
$ref: '#/components/responses/401Unauthorized'
728+
'403':
729+
$ref: '#/components/responses/403Forbidden'
730+
'404':
731+
$ref: '#/components/responses/404NotFound'
732+
733+
'/accounts/{account_id}/sources/{source_id}/external_reports/{external_report_id}/bytes':
734+
get:
735+
operationId: microsetta_private_api.api.get_external_report_bytes
736+
tags:
737+
- Sources
738+
summary: Get full contents of external report
739+
description: Get full contents of external report
740+
parameters:
741+
- $ref: '#/components/parameters/account_id'
742+
- $ref: '#/components/parameters/source_id'
743+
- $ref: '#/components/parameters/external_report_id'
744+
- $ref: '#/components/parameters/language_tag'
745+
responses:
746+
'200':
747+
description: Successfully returned contents of an external report
748+
'401':
749+
$ref: '#/components/responses/401Unauthorized'
750+
'403':
751+
$ref: '#/components/responses/403Forbidden'
752+
'404':
753+
$ref: '#/components/responses/404NotFound'
754+
682755
'/accounts/{account_id}/sources/{source_id}/check_ffq_prereqs':
683756
get:
684757
operationId: microsetta_private_api.api.check_source_ffq_prereqs
@@ -3049,6 +3122,12 @@ components:
30493122
description: Type of consent
30503123
schema:
30513124
$ref: '#/components/schemas/consent_type'
3125+
external_report_id:
3126+
name: external_report_id
3127+
in: path
3128+
description: Unique identifier of external report
3129+
schema:
3130+
$ref: '#/components/schemas/external_report_id'
30523131

30533132
# query parameters
30543133
activation_code:
@@ -3470,6 +3549,18 @@ components:
34703549
type: string
34713550
assent_content:
34723551
type: string
3552+
external_report_id:
3553+
type: string
3554+
file_name:
3555+
type: string
3556+
file_title:
3557+
type: string
3558+
file_type:
3559+
type: string
3560+
file_contents:
3561+
type: string
3562+
report_type:
3563+
enum: ["kit", "ffq"]
34733564
nonhuman_source:
34743565
type: object
34753566
properties:
@@ -3517,6 +3608,27 @@ components:
35173608
type: string
35183609
additionalProperties: false
35193610
additionalProperties: false
3611+
external_report:
3612+
type: object
3613+
properties:
3614+
external_report_id:
3615+
$ref: '#/components/schemas/external_report_id'
3616+
source_id:
3617+
$ref: '#/components/schemas/source_id'
3618+
file_name:
3619+
$ref: '#/components/schemas/file_name'
3620+
file_title:
3621+
$ref: '#/components/schemas/file_title'
3622+
file_type:
3623+
$ref: '#/components/schemas/file_type'
3624+
file_contents:
3625+
$ref: '#/components/schemas/file_contents'
3626+
report_type:
3627+
$ref: '#/components/schemas/report_type'
3628+
required:
3629+
- external_report_id
3630+
- source_id
3631+
- report_type
35203632

35213633
# survey template section
35223634
survey_template_id:

microsetta_private_api/db/migration_support.py

+54
Original file line numberDiff line numberDiff line change
@@ -742,6 +742,59 @@ def migrate_96(TRN):
742742
(r[0], hsi))
743743
TRN.execute()
744744

745+
@staticmethod
746+
def migrate_133(TRN):
747+
ffq_key_path = SERVER_CONFIG["japanese_ffqs_path_key"]
748+
ffq_file_path = SERVER_CONFIG["japanese_ffqs_path_reports"]
749+
750+
# The below string translates to "Food frequency questionnaire"
751+
JFFQ_FILE_LABEL = "食物摂取頻度調査票"
752+
753+
if not os.path.exists(ffq_key_path):
754+
print("Key not found:" + ffq_key_path)
755+
return
756+
757+
with open(ffq_key_path) as csv_file:
758+
csv_contents = csv.reader(csv_file)
759+
header = True
760+
761+
for csv_row in csv_contents:
762+
if header:
763+
header = False
764+
continue
765+
ffq_id, barcode = csv_row
766+
767+
# Find the source associated with the barcode and make sure
768+
# it wasn't scrubbed or removed
769+
TRN.add(
770+
"SELECT akb.source_id "
771+
"FROM ag.ag_kit_barcodes akb "
772+
"INNER JOIN ag.source s "
773+
"ON akb.source_id = s.id "
774+
"WHERE akb.barcode = %s AND s.date_revoked IS NULL",
775+
(barcode, )
776+
)
777+
rows = TRN.execute()[-1]
778+
779+
if len(rows) == 1:
780+
row = rows[0]
781+
source_id = row[0]
782+
pdf_name = ffq_id + ".pdf"
783+
pdf_path = ffq_file_path + pdf_name
784+
pdf_contents = open(pdf_path, "rb").read()
785+
786+
TRN.add(
787+
"INSERT INTO ag.external_reports ("
788+
"source_id, file_name, file_title, file_type, "
789+
"file_contents, report_type"
790+
") VALUES (%s, %s, %s, %s, %s, %s)",
791+
(source_id, pdf_name, JFFQ_FILE_LABEL,
792+
"application/pdf", pdf_contents, "ffq")
793+
)
794+
else:
795+
print("No mapping: " + ffq_id + " - " + barcode)
796+
TRN.execute()
797+
745798
MIGRATION_LOOKUP = {
746799
"0048.sql": migrate_48.__func__,
747800
"0050.sql": migrate_50.__func__,
@@ -753,6 +806,7 @@ def migrate_96(TRN):
753806
# "0082.sql": migrate_82.__func__
754807
# ...
755808
"0096.sql": migrate_96.__func__,
809+
"0133.sql": migrate_133.__func__
756810
}
757811

758812
@classmethod

0 commit comments

Comments
 (0)