def main(args): with spreadsheet(SAMPLE_SPREADSHEET_ID, SAMPLE_RANGE_NAME) as values: service_request_model = requests.get( 'https://raw.githubusercontent.com/cr-ste-justine/clin-FHIR/master/serviceRequest.json' ).json() row_parser = RowParser(values[0]) connection = get_connection(args) with db_transaction(connection): for row in values[1:]: service_request_row = row_parser.as_dict(row) service_request = copy.deepcopy(service_request_model) service_request['id'] = service_request_row['id'] service_request['status'] = service_request_row['status'] service_request['authoredOn'] = service_request_row[ 'authoredOn'] service_request['code']['text'] = service_request_row[ 'code.text'] service_request['subject'][ 'reference'] = f"Patient/{service_request_row['subject']}" service_request['requester'][ 'reference'] = f"PractitionerRole/{service_request_row['requester']}" service_request['specimen'][0][ 'reference'] = f"Specimen/{service_request_row['specimen']}" service_request['extension'][0]['valueReference']['reference'] = \ f"ClinicalImpression/{service_request_row['extension.valueReference']}" service_request_json = json.dumps(service_request, ensure_ascii=False) cursor = connection.cursor() insert_query = "insert into servicerequest (id, txid, resource, status) values (%s, 0, %s, 'created')" cursor.execute(insert_query, (service_request['id'], service_request_json))
def main(args): with spreadsheet(SAMPLE_SPREADSHEET_ID, SAMPLE_RANGE_NAME) as values: study_model = requests.get( 'https://raw.githubusercontent.com/cr-ste-justine/clin-FHIR/master/researchStudy.json').json() row_parser = RowParser(values[0]) connection = get_connection(args) with db_transaction(connection): for row in values[1:]: study_row = row_parser.as_dict(row) study = copy.deepcopy(study_model) study['id'] = study_row['id'] study['status'] = study_row['status'] study['title'] = study_row['title'] study['description'] = study_row['description'] study['sponsor']['reference'] = f"Organization/{study_row['sponsor']}" study['principalInvestigator']['reference'] = f"Practitioner/{study_row['principalInvestigator']}" study['enrollment'][0]['reference'] = f"Group/{study_row['enrolement']}" study['period']['start'] = study_row['period.start'] study['period']['end'] = study_row['period.end'] study_json = json.dumps(study, ensure_ascii=False) cursor = connection.cursor() insert_query = "insert into researchstudy (id, txid, resource, status) values (%s, 0, %s, 'created')" cursor.execute(insert_query, (study['id'], study_json))
def main(args): with spreadsheet(SAMPLE_SPREADSHEET_ID, SAMPLE_RANGE_NAME) as values: fmh_model = requests.get( 'https://raw.githubusercontent.com/cr-ste-justine/clin-FHIR/master/familyMemberHistory.json' ).json() row_parser = RowParser(values[0]) for row in values[1:]: fmh_row = row_parser.as_dict(row) fmh = copy.deepcopy(fmh_model) fmh['id'] = fmh_row['id'] fmh['status'] = fmh_row['status'] fmh['patient']['reference'] = f"Patient/{fmh_row['patient']}" fmh['date'] = fmh_row['date'] fmh['note'][0]['text'] = fmh_row['note'] fmh_json = json.dumps(fmh) response = requests.put( f"{args.url}/fhir/FamilyMemberHistory/{fmh['id']}", data=fmh_json, headers={ 'Authorization': f"Basic {args.token}", "Content-Type": "application/json" }) if response.status_code not in (201, 200): raise Exception( f'Aidobox did not return status code 201, status={response.status_code} \ntext={response.text} \nfmh={fmh_json}' )
def main(args): with spreadsheet(SAMPLE_SPREADSHEET_ID, SAMPLE_RANGE_NAME) as values: specimen_model = requests.get( 'https://raw.githubusercontent.com/cr-ste-justine/clin-FHIR/master/specimen.json' ).json() specimen_model.pop('parent') row_parser = RowParser(values[0]) connection = get_connection(args) with db_transaction(connection): for row in values[1:]: specimen_row = row_parser.as_dict(row) specimen = copy.deepcopy(specimen_model) specimen['id'] = specimen_row['id'] specimen['status'] = specimen_row['status'] specimen['subject'][ 'reference'] = f"Patient/{specimen_row['subject']}" specimen['request'][0][ 'reference'] = f"ServiceRequest/{specimen_row['request']}" specimen['container'][0]['identifier'][0][ 'value'] = specimen_row['container.identifier.value'] specimen_json = json.dumps(specimen, ensure_ascii=False) cursor = connection.cursor() insert_query = "insert into specimen (id, txid, resource, status) values (%s, 0, %s, 'created')" cursor.execute(insert_query, (specimen['id'], specimen_json))
def main(args): with spreadsheet(SAMPLE_SPREADSHEET_ID, SAMPLE_RANGE_NAME) as values: study_model = requests.get( 'https://raw.githubusercontent.com/cr-ste-justine/clin-FHIR/master/researchStudy.json').json() row_parser = RowParser(values[0]) for row in values[1:]: study_row = row_parser.as_dict(row) study = copy.deepcopy(study_model) study['id'] = study_row['id'] study['status'] = study_row['status'] study['title'] = study_row['title'] study['description'] = study_row['description'] study['sponsor']['reference'] = f"Organization/{study_row['sponsor']}" study['principalInvestigator']['reference'] = f"Practitioner/{study_row['principalInvestigator']}" study['enrollment'][0]['reference'] = f"Group/{study_row['enrolement']}" study['period']['start'] = study_row['period.start'] study['period']['end'] = study_row['period.end'] study_json = json.dumps(study) response = requests.put(f"{args.url}/fhir/ResearchStudy/{study['id']}", data=study_json, headers={'Authorization': f"Basic {args.token}", "Content-Type": "application/json"}) if response.status_code not in (201, 200): raise Exception(f'Aidobox did not return status code 201, status={response.status_code} \ntext={response.text} \nstudy={study_json}')
def main(args): with spreadsheet(SAMPLE_SPREADSHEET_ID, SAMPLE_RANGE_NAME) as values: service_request_model = requests.get( 'https://raw.githubusercontent.com/cr-ste-justine/clin-FHIR/master/serviceRequest.json' ).json() row_parser = RowParser(values[0]) for row in values[1:]: service_request_row = row_parser.as_dict(row) service_request = copy.deepcopy(service_request_model) service_request['id'] = service_request_row['id'] service_request['status'] = service_request_row['status'] service_request['authoredOn'] = service_request_row['authoredOn'] service_request['code']['text'] = service_request_row['code.text'] service_request['subject'][ 'reference'] = f"Patient/{service_request_row['subject']}" service_request['requester'][ 'reference'] = f"PractitionerRole/{service_request_row['requester']}" service_request['specimen'][0][ 'reference'] = f"Specimen/{service_request_row['specimen']}" service_request['extension'][0]['valueReference']['reference'] = \ f"ClinicalImpression/{service_request_row['extension.valueReference']}" service_request_json = json.dumps(service_request) response = requests.put( f"{args.url}/fhir/ServiceRequest/{service_request['id']}", data=service_request_json, headers={ 'Authorization': f"Basic {args.token}", "Content-Type": "application/json" }) if response.status_code not in (201, 200): raise Exception( f'Aidobox did not return status code 201, status={response.status_code} \ntext={response.text} \nservice_request={service_request_json}' )
def main(args): with spreadsheet(SAMPLE_SPREADSHEET_ID, SAMPLE_RANGE_NAME) as values: practitioner_model = requests.get( 'https://raw.githubusercontent.com/cr-ste-justine/clin-FHIR/master/practitioner.json' ).json() row_parser = RowParser(values[0][0:6]) connection = get_connection(args) with db_transaction(connection): for row in values[1:]: practitioner_row = row_parser.as_dict(row[0:6]) practitioner = copy.deepcopy(practitioner_model) practitioner['id'] = practitioner_row['id'] name = practitioner['name'][0] name['family'] = practitioner_row['name.family'] name['prefix'] = [practitioner_row['name.prefix']] md = practitioner_row['MD'] if md != 'null': practitioner['identifier'][0]['value'] = md else: practitioner['identifier'].pop(0) practitioner_json = json.dumps(practitioner, ensure_ascii=False) cursor = connection.cursor() insert_query = "insert into practitioner (id, txid, resource, status) values (%s, 0, %s, 'created')" cursor.execute(insert_query, (practitioner['id'], practitioner_json))
def main(args): with spreadsheet(SAMPLE_SPREADSHEET_ID, SAMPLE_RANGE_NAME) as values: practitioner_model = requests.get( 'https://raw.githubusercontent.com/cr-ste-justine/clin-FHIR/master/practitionerRole.json' ).json() row_parser = RowParser(values[0][0:6]) for row in values[1:]: practitioner_role_row = row_parser.as_dict(row[0:6]) practitioner_role = copy.deepcopy(practitioner_model) practitioner_role['id'] = practitioner_role_row['id'] practitioner_role['practitioner']['reference'] = \ f"Practitioner/{practitioner_role_row['practitioner']}" practitioner_role['organization']['reference'] = \ f"Organization/{practitioner_role_row['organization']}" code = practitioner_role['code'][0] code['coding'][0]['code'] = practitioner_role_row[ 'code.coding.code'] code['coding'][0]['display'] = practitioner_role_row[ 'code.coding.display'] code['text'] = practitioner_role_row['code.text'] practitioner_role_json = json.dumps(practitioner_role) response = requests.put( f"{args.url}/fhir/PractitionerRole/{practitioner_role['id']}", data=practitioner_role_json, headers={ 'Authorization': f"Basic {args.token}", "Content-Type": "application/json" }) if response.status_code not in (201, 200): raise Exception( f'Aidobox did not return status code 201, status={response.status_code} \ntext={response.text} \nparticipant={practitioner_role_json}' )
def main(args): with spreadsheet(SAMPLE_SPREADSHEET_ID, SAMPLE_RANGE_NAME) as values: specimen_model = requests.get( 'https://raw.githubusercontent.com/cr-ste-justine/clin-FHIR/master/specimen.json' ).json() specimen_model.pop('parent') row_parser = RowParser(values[0]) for row in values[1:]: specimen_row = row_parser.as_dict(row) specimen = copy.deepcopy(specimen_model) specimen['id'] = specimen_row['id'] specimen['status'] = specimen_row['status'] specimen['subject'][ 'reference'] = f"Patient/{specimen_row['subject']}" specimen['request'][0][ 'reference'] = f"ServiceRequest/{specimen_row['request']}" specimen['container'][0]['identifier'][0]['value'] = specimen_row[ 'container.identifier.value'] specimen_json = json.dumps(specimen) response = requests.put( f"{args.url}/fhir/Specimen/{specimen['id']}", data=specimen_json, headers={ 'Authorization': f"Basic {args.token}", "Content-Type": "application/json" }) if response.status_code not in (201, 200): raise Exception( f'Aidobox did not return status code 201, status={response.status_code} \ntext={response.text} \nspecimen={specimen_json}' )
def main(args): with spreadsheet(SAMPLE_SPREADSHEET_ID, SAMPLE_RANGE_NAME) as values: practitioner_model = requests.get( 'https://raw.githubusercontent.com/cr-ste-justine/clin-FHIR/master/practitioner.json' ).json() row_parser = RowParser(values[0][0:6]) for row in values[1:]: practitioner_row = row_parser.as_dict(row[0:6]) practitioner = copy.deepcopy(practitioner_model) practitioner['id'] = practitioner_row['id'] name = practitioner['name'][0] name['family'] = practitioner_row['name.family'] name['prefix'] = [practitioner_row['name.prefix']] md = practitioner_row['MD'] if md != 'null': practitioner['identifier'][0]['value'] = md else: practitioner['identifier'].pop(0) practitioner_json = json.dumps(practitioner) response = requests.put( f"{args.url}/fhir/Practitioner/{practitioner['id']}", data=practitioner_json, headers={ 'Authorization': f"Basic {args.token}", "Content-Type": "application/json" }) if response.status_code not in (201, 200): raise Exception( f'Aidobox did not return status code 201, status={response.status_code} \ntext={response.text} \nparticipant={practitioner_json}' )
def main(args): with spreadsheet(SAMPLE_SPREADSHEET_ID, SAMPLE_RANGE_NAME) as values: practitioner_model = requests.get( 'https://raw.githubusercontent.com/cr-ste-justine/clin-FHIR/master/practitionerRole.json' ).json() row_parser = RowParser(values[0][0:6]) connection = get_connection(args) with db_transaction(connection): for row in values[1:]: practitioner_role_row = row_parser.as_dict(row[0:6]) practitioner_role = copy.deepcopy(practitioner_model) practitioner_role['id'] = practitioner_role_row['id'] practitioner_role['practitioner']['reference'] = \ f"Practitioner/{practitioner_role_row['practitioner']}" practitioner_role['organization']['reference'] = \ f"Organization/{practitioner_role_row['organization']}" code = practitioner_role['code'][0] code['coding'][0]['code'] = practitioner_role_row[ 'code.coding.code'] code['coding'][0]['display'] = practitioner_role_row[ 'code.coding.display'] code['text'] = practitioner_role_row['code.text'] practitioner_role_json = json.dumps(practitioner_role, ensure_ascii=False) cursor = connection.cursor() insert_query = "insert into practitionerRole (id, txid, resource, status) values (%s, 0, %s, 'created')" cursor.execute( insert_query, (practitioner_role['id'], practitioner_role_json))
def main(args): with spreadsheet(SAMPLE_SPREADSHEET_ID, SAMPLE_RANGE_NAME) as values: clinical_impression_model = requests.get( 'https://raw.githubusercontent.com/cr-ste-justine/clin-FHIR/master/clinicalImpression.json' ).json() clinical_impression_model.pop('meta') row_parser = RowParser(values[0]) for row in values[1:]: clinical_impression_row = row_parser.as_dict(row) clinical_impression = copy.deepcopy(clinical_impression_model) clinical_impression['id'] = clinical_impression_row['id'] clinical_impression['effectiveDateTime'] = clinical_impression_row[ 'effectiveDateTime'] clinical_impression['subject'][ 'reference'] = f"Patient/{clinical_impression_row['subject']}" clinical_impression['assessor'][ 'reference'] = f"PractitionerRole/{clinical_impression_row['assessor']}" clinical_impression['extension'][0]['valueAge']['value'] = int( clinical_impression_row['valueAge']) clinical_impression['investigation'][0]['item'] = [] for r in row[5:9]: clinical_impression['investigation'][0]['item'].extend([{ 'reference': r }]) clinical_impression_json = json.dumps(clinical_impression) response = requests.put( f"{args.url}/fhir/ClinicalImpression/{clinical_impression['id']}", data=clinical_impression_json, headers={ 'Authorization': f"Basic {args.token}", "Content-Type": "application/json" }) if response.status_code not in (201, 200): raise Exception( f'Aidobox did not return status code 201, status={response.status_code} \ntext={response.text} \nclinical_impression={clinical_impression_json}' )
def main(args): with spreadsheet(SAMPLE_SPREADSHEET_ID, SAMPLE_RANGE_NAME) as values: organization_model = requests.get( 'https://raw.githubusercontent.com/cr-ste-justine/clin-FHIR/master/organization.json').json() row_parser = RowParser(values[0]) for row in values[1:]: organization_row = row_parser.as_dict(row) organization = copy.deepcopy(organization_model) organization['id'] = organization_row['id'] organization['name'] = organization_row['name'] organization['alias'] = [organization_row['alias']] organization_json = json.dumps(organization) response = requests.put(f"{args.url}/fhir/Organization/{organization['id']}", data=organization_json, headers={'Authorization': f"Basic {args.token}", "Content-Type": "application/json"}) if response.status_code not in (201, 200): raise Exception( f'Aidobox did not return status code 201, status={response.status_code} \ntext={response.text} \norg={organization_json}')
def main(args): with spreadsheet(SAMPLE_SPREADSHEET_ID, SAMPLE_RANGE_NAME) as values: fmh_model = requests.get( 'https://raw.githubusercontent.com/cr-ste-justine/clin-FHIR/master/familyMemberHistory.json' ).json() row_parser = RowParser(values[0]) connection = get_connection(args) with db_transaction(connection): for row in values[1:]: fmh_row = row_parser.as_dict(row) fmh = copy.deepcopy(fmh_model) fmh['id'] = fmh_row['id'] fmh['status'] = fmh_row['status'] fmh['patient']['reference'] = f"Patient/{fmh_row['patient']}" fmh['date'] = fmh_row['date'] fmh['note'][0]['text'] = fmh_row['note'] fmh_json = json.dumps(fmh, ensure_ascii=False) cursor = connection.cursor() insert_query = "insert into familymemberhistory (id, txid, resource, status) values (%s, 0, %s, 'created')" cursor.execute(insert_query, (fmh['id'], fmh_json))
def main(args): with spreadsheet(SAMPLE_SPREADSHEET_ID, SAMPLE_RANGE_NAME) as values: observation_pheno = requests.get('https://raw.githubusercontent.com/cr-ste-justine/clin-FHIR/master/observation_exemple_de_pheno.json').json() observation_notes = requests.get('https://raw.githubusercontent.com/cr-ste-justine/clin-FHIR/master/observation_exemple_de_notes.json').json() row_parser = RowParser(values[0]) connection = get_connection(args) with db_transaction(connection): for row in values[1:]: observation_row = row_parser.as_dict(row) is_pheno = observation_row['code.text'] == 'phenotype observation' observation = copy.deepcopy(observation_pheno) if is_pheno else copy.deepcopy(observation_notes) observation['id'] = observation_row['id'] observation['effectiveDateTime'] = observation_row['effectiveDateTime'] observation['subject']['reference'] = f"Patient/{observation_row['subject']}" observation['performer'][0]['reference'] = f"PractitionerRole/{observation_row['performer']}" row_note = observation_row.get('note') if row_note: observation['note'][0]['text'] = row_note else: observation.pop('note') if is_pheno: (code, display) = observation_row['valueCodeableConcept.code et .display'].split(', ') coding = observation['valueCodeableConcept']['coding'][0] coding['code'] = code coding['display'] = display coding['system'] = observation_row['valueCodableConcept.coding.system'] interpretation_coding = observation['interpretation'][0]['coding'][0] interpretation_coding['code'] = observation_row['interpretation.coding.code'] interpretation_coding['display'] = observation_row['interpretation.coding.display'] observation['interpretation'][0]['text'] = observation_row['interpretation.text'] observation_json = json.dumps(observation, ensure_ascii=False) cursor = connection.cursor() insert_query = "insert into observation (id, txid, resource, status) values (%s, 0, %s, 'created')" cursor.execute(insert_query, (observation['id'], observation_json))
def main(args): with spreadsheet(SAMPLE_SPREADSHEET_ID, SAMPLE_RANGE_NAME) as values: observation_pheno = requests.get('https://raw.githubusercontent.com/cr-ste-justine/clin-FHIR/master/observation_exemple_de_pheno.json').json() observation_notes = requests.get('https://raw.githubusercontent.com/cr-ste-justine/clin-FHIR/master/observation_exemple_de_notes.json').json() row_parser = RowParser(values[0]) for row in values[1:]: observation_row = row_parser.as_dict(row) is_pheno = observation_row['code.text'] == 'phenotype observation' observation = copy.deepcopy(observation_pheno) if is_pheno else copy.deepcopy(observation_notes) observation['id'] = observation_row['id'] observation['effectiveDateTime'] = observation_row['effectiveDateTime'] observation['subject']['reference'] = f"Patient/{observation_row['subject']}" observation['performer'][0]['reference'] = f"Practitioner/{observation_row['performer']}" row_note = observation_row.get('note') if row_note: observation['note'][0]['text'] = row_note else: observation.pop('note') if is_pheno: (code, display) = observation_row['valueCodeableConcept.code et .display'].split(', ') coding = observation['valueCodeableConcept']['coding'][0] coding['code'] = code coding['display'] = display coding['system'] = observation_row['valueCodableConcept.coding.system'] interpretation_coding = observation['interpretation'][0]['coding'][0] interpretation_coding['code'] = observation_row['interpretation.coding.code'] interpretation_coding['display'] = observation_row['interpretation.coding.display'] observation['interpretation'][0]['text'] = observation_row['interpretation.text'] observation_json = json.dumps(observation) response = requests.put(f"{args.url}/fhir/Observation/{observation['id']}", data=observation_json, headers={'Authorization': f"Basic {args.token}", "Content-Type": "application/json"}) if response.status_code not in (201, 200): raise Exception(f'Aidobox did not return status code 201, status={response.status_code} \ntext={response.text} \nobservation={observation_json}')
def main(args): with spreadsheet(SAMPLE_SPREADSHEET_ID, SAMPLE_RANGE_NAME) as values: clinical_impression_model = requests.get( 'https://raw.githubusercontent.com/cr-ste-justine/clin-FHIR/master/clinicalImpression.json' ).json() row_parser = RowParser(values[0]) connection = get_connection(args) with db_transaction(connection): for row in values[1:]: clinical_impression_row = row_parser.as_dict(row) clinical_impression = copy.deepcopy(clinical_impression_model) clinical_impression['id'] = clinical_impression_row['id'] clinical_impression['status'] = clinical_impression_row[ 'status'] clinical_impression[ 'effectiveDateTime'] = clinical_impression_row[ 'effectiveDateTime'] clinical_impression['subject'][ 'reference'] = f"Patient/{clinical_impression_row['subject']}" clinical_impression['assessor'][ 'reference'] = f"PractitionerRole/{clinical_impression_row['assessor']}" clinical_impression['extension'][0]['valueAge'][ 'value'] = clinical_impression_row['valueAge'] clinical_impression['investigation'][0]['item'] = [] for r in row[5:9]: clinical_impression['investigation'][0]['item'].extend([{ 'reference': r }]) clinical_impression_json = json.dumps(clinical_impression, ensure_ascii=False) cursor = connection.cursor() insert_query = "insert into clinicalImpression (id, txid, resource, status) values (%s, 0, %s, 'created')" cursor.execute( insert_query, (clinical_impression['id'], clinical_impression_json))
def main(args): with spreadsheet(SAMPLE_SPREADSHEET_ID, SAMPLE_RANGE_NAME) as values: patient_mother = requests.get( 'https://raw.githubusercontent.com/cr-ste-justine/clin-FHIR/master/patient_exemple_mother.json').json() patient_proband = requests.get( 'https://raw.githubusercontent.com/cr-ste-justine/clin-FHIR/master/patient_exemple_proband.json').json() patient_proband['link'].pop(2) # No brothers or sisters row_parser = RowParser(values[0][0:19]) for row in values[1:]: participant_row = row_parser.as_dict(row[0:19]) is_proband = participant_row['isProband'] == 'true' participant = copy.deepcopy(patient_proband) if is_proband else copy.deepcopy(patient_mother) participant['id'] = participant_row['id'] for identifier in participant['identifier']: if identifier['type']['coding'][0]['code'] == 'MR': identifier['value'] = participant_row['MR'] if identifier['type']['coding'][0]['code'] == 'JHN': identifier['value'] = participant_row['JHN'] birth_date = datetime.strptime(participant_row['birthdate'], '%y-%m-%d') participant['birthDate'] = birth_date.strftime('%Y-%m-%d') participant['active'] = bool(participant_row['active']) participant['gender'] = participant_row['gender'] name = participant['name'][0] name['use'] = participant_row['name.use'] name['family'] = participant_row['name.family'] name['given'] = [participant_row['name.given']] participant['managingOrganization']['reference'] = \ f"Organization/{participant_row['managingOrganization']}" participant['generalPractitioner'][0]['reference'] = \ f"PractitionerRole/{participant_row['generalPractitioner']}" for extension in participant['extension'][0]['extension']: if extension['url'] == 'familyId': extension['valueId'] = participant_row['familyId'] if extension['url'] == 'ethnicity': extension['valueCode'] = participant_row['ethnicity'] if extension['url'] == 'familyComposition': extension['valueCode'] = participant_row['familyComposition'] if extension['url'] == 'isProband': extension['valueBoolean'] = is_proband if is_proband: father = participant['link'][0] mother = participant['link'][1] if participant_row['FTH']: father['other']['reference'] = f"Patient/{participant_row['FTH']}" else: participant['link'].remove(father) if participant_row['MTH']: mother['other']['reference'] = f"Patient/{participant_row['MTH']}" else: participant['link'].remove(mother) participant_json = json.dumps(participant) response = requests.put(f"{args.url}/fhir/Patient/{participant['id']}", data=participant_json, headers={'Authorization': f"Basic {args.token}", "Content-Type": "application/json"}) if response.status_code not in (201, 200): raise Exception(f'Aidobox did not return status code 201, status={response.status_code} \ntext={response.text} \nparticipant={participant_json}')
def main(args): with spreadsheet(SAMPLE_SPREADSHEET_ID, SAMPLE_RANGE_NAME) as values: patient_mother = requests.get( 'https://raw.githubusercontent.com/cr-ste-justine/clin-FHIR/master/patient_exemple_mother.json' ).json() patient_proband = requests.get( 'https://raw.githubusercontent.com/cr-ste-justine/clin-FHIR/master/patient_exemple_proband.json' ).json() patient_proband['link'].pop(2) # No brothers or sisters row_parser = RowParser(values[0][0:19]) connection = get_connection(args) with db_transaction(connection): for row in values[1:]: participant_row = row_parser.as_dict(row[0:19]) is_proband = participant_row['isProband'] == 'true' participant = copy.deepcopy( patient_proband) if is_proband else copy.deepcopy( patient_mother) participant['id'] = participant_row['id'] for identifier in participant['identifier']: if identifier['type']['coding'][0]['code'] == 'MR': identifier['value'] = participant_row['MR'] if identifier['type']['coding'][0]['code'] == 'JHN': identifier['value'] = participant_row['JHN'] birth_date = datetime.strptime(participant_row['birthdate'], '%y-%m-%d') participant['birthDate'] = birth_date.strftime('%Y-%m-%d') participant['active'] = participant_row['active'] participant['gender'] = participant_row['gender'] participant['name']['use'] = participant_row['name.use'] participant['name']['family'] = participant_row['name.family'] participant['name']['given'] = [participant_row['name.given']] participant['managingOrganization']['reference'] = \ f"Organization/{participant_row['managingOrganization']}" participant['generalPractitioner'][0]['reference'] = \ f"PractitionerRole/{participant_row['generalPractitioner']}" for extension in participant['extension'][0]['extension']: if extension['url'] == 'familyId': extension['valueId'] = participant_row['familyId'] if extension['url'] == 'ethnicity': extension['valueCode'] = participant_row['ethnicity'] if extension['url'] == 'familyComposition': extension['valueCode'] = participant_row[ 'familyComposition'] if extension['url'] == 'isProband': extension['valueBoolean'] = participant_row[ 'isProband'] if is_proband: father = participant['link'][0] mother = participant['link'][1] if participant_row['FTH']: father['other'][ 'reference'] = f"Patient/{participant_row['FTH']}" else: participant['link'].remove(father) if participant_row['MTH']: mother['other'][ 'reference'] = f"Patient/{participant_row['MTH']}" else: participant['link'].remove(mother) participant_json = json.dumps(participant, ensure_ascii=False) cursor = connection.cursor() insert_query = "insert into patient (id, txid, resource, status) values (%s, 0, %s, 'created')" cursor.execute(insert_query, (participant['id'], participant_json))