Created
October 12, 2017 17:00
-
-
Save kiproping/ff682218af5f8e30d17047c7e370c131 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| #!/bin/python | |
| import csv | |
| firstline = True | |
| def savetofile(file, content): | |
| with open(file, 'w') as file: | |
| file.write(content) | |
| def checkfirst(): | |
| global firstline | |
| if firstline: | |
| firstline = False | |
| return True | |
| else: | |
| return False | |
| file = 'PatientInfo.csv' | |
| csvfile = open(file, 'rb'); | |
| reader = csv.reader(csvfile) | |
| count = 1 | |
| for row in reader: | |
| if checkfirst(): | |
| continue | |
| fhir = """\ | |
| //Patient | |
| {{ | |
| "resourceType": "Patient", | |
| "id": "{count}", | |
| "active": true, | |
| "name": [{{ | |
| "use": "official", | |
| "family": "{lastn}", | |
| "given": [ | |
| "{firstn}", | |
| "{middlen}" | |
| ] | |
| }}], | |
| "gender": "{sex}" | |
| }} | |
| //Hematocrit | |
| {{ | |
| "resourceType": "Observation", | |
| "id": "{count}", | |
| "status": "final", | |
| "code": {{ | |
| "coding": [{{ | |
| "system": "http://loinc.org", | |
| "code": "4544-3", | |
| "display": "Hematocrit" | |
| }}] | |
| }}, | |
| "subject": {{ | |
| "reference": "Patient/{count}", | |
| "display": "{firstn}" | |
| }}, | |
| "valueQuantity": {{ | |
| "value": {hematocrit}, | |
| "unit": "%", | |
| "system": "http://unitsofmeasure.org", | |
| "code": "%" | |
| }} | |
| }} | |
| //Neutrophils | |
| {{ | |
| "resourceType": "Observation", | |
| "id": "{count}", | |
| "status": "final", | |
| "code": {{ | |
| "coding": [{{ | |
| "system": "http://loinc.org", | |
| "code": "770-8", | |
| "display": "Neutrophils" | |
| }}] | |
| }}, | |
| "subject": {{ | |
| "reference": "Patient/{count}", | |
| "display": "{firstn}" | |
| }}, | |
| "valueQuantity": {{ | |
| "value": {neutrophils}, | |
| "unit": "%", | |
| "system": "http://unitsofmeasure.org", | |
| "code": "%" | |
| }} | |
| }} | |
| //Sodium | |
| {{ | |
| "resourceType": "Observation", | |
| "id": "{count}", | |
| "status": "final", | |
| "code": {{ | |
| "coding": [{{ | |
| "system": "http://loinc.org", | |
| "code": "2947-0", | |
| "display": "Sodium" | |
| }}] | |
| }}, | |
| "subject": {{ | |
| "reference": "Patient/{count}", | |
| "display": "{firstn}" | |
| }}, | |
| "valueQuantity": {{ | |
| "value": {sodium}, | |
| "unit": "mmol/L", | |
| "system": "http://unitsofmeasure.org", | |
| "code": "mmol/L" | |
| }} | |
| }} | |
| //Glucose | |
| {{ | |
| "resourceType": "Observation", | |
| "id": "{count}", | |
| "status": "final", | |
| "code": {{ | |
| "coding": [{{ | |
| "system": "http://loinc.org", | |
| "code": "2339-0", | |
| "display": "Glucose" | |
| }}] | |
| }}, | |
| "subject": {{ | |
| "reference": "Patient/{count}", | |
| "display": "{firstn}" | |
| }}, | |
| "valueQuantity": {{ | |
| "value": {glucose}, | |
| "unit": "mmol/L", | |
| "system": "http://unitsofmeasure.org", | |
| "code": "mmol/L" | |
| }} | |
| }} | |
| //Ureanitrogen | |
| {{ | |
| "resourceType": "Observation", | |
| "id": "{count}", | |
| "status": "final", | |
| "code": {{ | |
| "coding": [{{ | |
| "system": "http://loinc.org", | |
| "code": "6299-2", | |
| "display": "Urea nitrogen" | |
| }}] | |
| }}, | |
| "subject": {{ | |
| "reference": "Patient/{count}", | |
| "display": "{firstn}" | |
| }}, | |
| "valueQuantity": {{ | |
| "value": {ureanitrogen}, | |
| "unit": "mg/dL ", | |
| "system": "http://unitsofmeasure.org", | |
| "code": "mg/dL " | |
| }} | |
| }} | |
| //Creatinine | |
| {{ | |
| "resourceType": "Observation", | |
| "id": "{count}", | |
| "status": "final", | |
| "code": {{ | |
| "coding": [{{ | |
| "system": "http://loinc.org", | |
| "code": "2160-0", | |
| "display": "Creatinine" | |
| }}] | |
| }}, | |
| "subject": {{ | |
| "reference": "Patient/{count}", | |
| "display": "{firstn}" | |
| }}, | |
| "valueQuantity": {{ | |
| "value": {creatinine}, | |
| "unit": "mg/dL", | |
| "system": "http://unitsofmeasure.org", | |
| "code": "mg/dL" | |
| }} | |
| }} | |
| //Body mass index | |
| {{ | |
| "resourceType": "Observation", | |
| "id": "{count}", | |
| "status": "final", | |
| "code": {{ | |
| "coding": [{{ | |
| "system": "http://loinc.org", | |
| "code": "2160-0", | |
| "display": "Body mass index" | |
| }}] | |
| }}, | |
| "subject": {{ | |
| "reference": "Patient/{count}", | |
| "display": "{firstn}" | |
| }}, | |
| "valueQuantity": {{ | |
| "value": {body}, | |
| "unit": "kg/m2", | |
| "system": "http://unitsofmeasure.org", | |
| "code": "kg/m2 " | |
| }} | |
| }} | |
| //Heart rate / pulse | |
| {{ | |
| "resourceType": "Observation", | |
| "id": "{count}", | |
| "status": "final", | |
| "code": {{ | |
| "coding": [{{ | |
| "system": "http://loinc.org", | |
| "code": "8867-4", | |
| "display": "Heart rate " | |
| }}] | |
| }}, | |
| "subject": {{ | |
| "reference": "Patient/{count}", | |
| "display": "{firstn}" | |
| }}, | |
| "valueQuantity": {{ | |
| "value": {heart}, | |
| "unit": "beats/min", | |
| "system": "http://unitsofmeasure.org", | |
| "code": "beats/min" | |
| }} | |
| }} | |
| //Respiration | |
| {{ | |
| "resourceType": "Observation", | |
| "id": "{count}", | |
| "status": "final", | |
| "code": {{ | |
| "coding": [{{ | |
| "system": "http://loinc.org", | |
| "code": "9279-1", | |
| "display": "Heart rate " | |
| }}] | |
| }}, | |
| "subject": {{ | |
| "reference": "Patient/{count}", | |
| "display": "{firstn}" | |
| }}, | |
| "valueQuantity": {{ | |
| "value": {respiration}, | |
| "unit": "breaths/min", | |
| "system": "http://unitsofmeasure.org", | |
| "code": "breaths/min" | |
| }} | |
| }} | |
| //Encounter | |
| {{ | |
| "resourceType": "Encounter", | |
| "id": "{count}", | |
| "status": "finished", | |
| "class": {{ | |
| "system": "http://hl7.org/fhir/v3/ActCode", | |
| "code": "IMP", | |
| "display": "inpatient encounter" | |
| }}, | |
| "period": {{ | |
| "start": "2012-08-29T00:00:00+00:00", | |
| "end": "2012-09-01T00:30:00+00:00" | |
| }}, | |
| "subject": {{ | |
| "reference": "Patient/{count}", | |
| "display": "{firstn}" | |
| }}, | |
| "serviceProvider":{{ | |
| "reference": "Organization/{org}", | |
| "display": "{org}" | |
| }} | |
| }} | |
| \ | |
| """ | |
| if row[7] == '1': | |
| fhir += """\ | |
| //dialysisrenalendstage | |
| {{ | |
| "resourceType": "Condition", | |
| "id": "1", | |
| "clinicalStatus": "resolved", | |
| "verificationStatus": "confirmed", | |
| "code": {{ | |
| "coding": [{{ | |
| "system": "http://snomed.info/sct", | |
| "code": "236435004", | |
| "display": "End stage renal failure on dialysis" | |
| }}] | |
| }}, | |
| "subject": {{ | |
| "reference": "Patient/{count}", | |
| "display": "{firstn}" | |
| }} | |
| }} | |
| \ | |
| """ | |
| if row[8] == '1': | |
| fhir += """\ | |
| //asthma | |
| {{ | |
| "resourceType": "Condition", | |
| "id": "1", | |
| "clinicalStatus": "resolved", | |
| "verificationStatus": "confirmed", | |
| "code": {{ | |
| "coding": [{{ | |
| "system": "http://snomed.info/sct", | |
| "code": "195967001", | |
| "display": "Asthma" | |
| }}] | |
| }}, | |
| "subject": {{ | |
| "reference": "Patient/{count}", | |
| "display": "{firstn}" | |
| }} | |
| }} | |
| \ | |
| """ | |
| if row[9] == '1': | |
| fhir += """\ | |
| //irondef | |
| {{ | |
| "resourceType": "Condition", | |
| "id": "1", | |
| "clinicalStatus": "resolved", | |
| "verificationStatus": "confirmed", | |
| "code": {{ | |
| "coding": [{{ | |
| "system": "http://snomed.info/sct", | |
| "code": "35240004", | |
| "display": "Iron deficiency" | |
| }}] | |
| }}, | |
| "subject": {{ | |
| "reference": "Patient/{count}", | |
| "display": "{firstn}" | |
| }} | |
| }} | |
| \ | |
| """ | |
| if row[10] == '1': | |
| fhir += """\ | |
| //pneum | |
| {{ | |
| "resourceType": "Condition", | |
| "id": "1", | |
| "clinicalStatus": "resolved", | |
| "verificationStatus": "confirmed", | |
| "code": {{ | |
| "coding": [{{ | |
| "system": "http://snomed.info/sct", | |
| "code": "233604007", | |
| "display": "Pneumonia" | |
| }}] | |
| }}, | |
| "subject": {{ | |
| "reference": "Patient/{count}", | |
| "display": "{firstn}" | |
| }} | |
| }} | |
| \ | |
| """ | |
| if row[11] == '1': | |
| fhir += """\ | |
| //substancedependence | |
| {{ | |
| "resourceType": "Condition", | |
| "id": "1", | |
| "clinicalStatus": "resolved", | |
| "verificationStatus": "confirmed", | |
| "code": {{ | |
| "coding": [{{ | |
| "system": "http://snomed.info/sct", | |
| "code": "361055000", | |
| "display": "Misuses drugs" | |
| }}] | |
| }}, | |
| "subject": {{ | |
| "reference": "Patient/{count}", | |
| "display": "{firstn}" | |
| }} | |
| }} | |
| \ | |
| """ | |
| if row[12] == '1': | |
| fhir += """\ | |
| //phsycholgicaldisordermajor | |
| {{ | |
| "resourceType": "Condition", | |
| "id": "1", | |
| "clinicalStatus": "resolved", | |
| "verificationStatus": "confirmed", | |
| "code": {{ | |
| "coding": [{{ | |
| "system": "http://snomed.info/sct", | |
| "code": "81659004", | |
| "display": "Psychological sign or symptom" | |
| }}] | |
| }}, | |
| "subject": {{ | |
| "reference": "Patient/{count}", | |
| "display": "{firstn}" | |
| }} | |
| }} | |
| \ | |
| """ | |
| if row[13] == '1': | |
| fhir += """\ | |
| //depress | |
| {{ | |
| "resourceType": "Condition", | |
| "id": "1", | |
| "clinicalStatus": "resolved", | |
| "verificationStatus": "confirmed", | |
| "code": {{ | |
| "coding": [{{ | |
| "system": "http://snomed.info/sct", | |
| "code": "35489007", | |
| "display": "Depressive disorder" | |
| }}] | |
| }}, | |
| "subject": {{ | |
| "reference": "Patient/{count}", | |
| "display": "{firstn}" | |
| }} | |
| }} | |
| \ | |
| """ | |
| if row[14] == '1': | |
| fhir += """\ | |
| //phsychother | |
| {{ | |
| "resourceType": "Condition", | |
| "id": "1", | |
| "clinicalStatus": "resolved", | |
| "verificationStatus": "confirmed", | |
| "code": {{ | |
| "coding": [{{ | |
| "system": "http://snomed.info/sct", | |
| "code": "81659004", | |
| "display": "Psychological sign or symptom" | |
| }}] | |
| }}, | |
| "subject": {{ | |
| "reference": "Patient/{count}", | |
| "display": "{firstn}" | |
| }} | |
| }} | |
| \ | |
| """ | |
| if row[15] == '1': | |
| fhir += """\ | |
| //fibriosisandother | |
| {{ | |
| "resourceType": "Condition", | |
| "id": "1", | |
| "clinicalStatus": "resolved", | |
| "verificationStatus": "confirmed", | |
| "code": {{ | |
| "coding": [{{ | |
| "system": "http://snomed.info/sct", | |
| "code": "263756000", | |
| "display": "Fibrosis" | |
| }}] | |
| }}, | |
| "subject": {{ | |
| "reference": "Patient/{count}", | |
| "display": "{firstn}" | |
| }} | |
| }} | |
| \ | |
| """ | |
| if row[16] == '1': | |
| fhir += """\ | |
| //malnutrition | |
| {{ | |
| "resourceType": "Condition", | |
| "id": "1", | |
| "clinicalStatus": "resolved", | |
| "verificationStatus": "confirmed", | |
| "code": {{ | |
| "coding": [{{ | |
| "system": "http://snomed.info/sct", | |
| "code": "263756000", | |
| "display": "Fibrosis" | |
| }}] | |
| }}, | |
| "subject": {{ | |
| "reference": "Patient/{count}", | |
| "display": "{firstn}" | |
| }} | |
| }} | |
| \ | |
| """ | |
| if row[17] == '1': | |
| fhir += """\ | |
| //hemo | |
| {{ | |
| "resourceType": "Condition", | |
| "id": "1", | |
| "clinicalStatus": "resolved", | |
| "verificationStatus": "confirmed", | |
| "code": {{ | |
| "coding": [{{ | |
| "system": "http://snomed.info/sct", | |
| "code": "34093004", | |
| "display": "Disorder of hematopoietic system" | |
| }}] | |
| }}, | |
| "subject": {{ | |
| "reference": "Patient/{count}", | |
| "display": "{firstn}" | |
| }} | |
| }} | |
| \ | |
| """ | |
| g = row[6] | |
| if g == 'M': | |
| gender = 'male' | |
| else: | |
| gender = 'female' | |
| fhir = fhir.format( | |
| count=1, | |
| firstn=row[0], | |
| middlen=row[1], | |
| lastn=row[2], | |
| sex=gender, | |
| hematocrit=row[18], | |
| neutrophils=row[19], | |
| sodium=row[20], | |
| glucose=row[21], | |
| ureanitrogen=row[22], | |
| creatinine=row[23], | |
| body=row[24], | |
| heart=row[25], | |
| respiration=row[26], | |
| org=row[29] | |
| ); | |
| file = 'files/patient{}.json'.format(count) | |
| savetofile(file, fhir) | |
| count +=1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment