def generate(cls, patient_file_name=RI_PATIENTS_FILE): """Generates a patient file from raw data; replaces old patients file""" # Open the patient data file for writing generated data f = open(PATIENTS_FILE, 'w') top = True # Starting at the top of the file (need to write header here...) # Open the raw data file and read in the first (header) record pats = csv.reader(file(patient_file_name, 'U'), dialect='excel-tab') header = pats.next() # Read in patient data: for pat in pats: # create patient from header and row values p = dict((zip(header, pat))) # Add synthetic data patient_name = rndName(p['GENDER']) p['fname'] = patient_name[0] p['initial'] = patient_name[1] p['lname'] = patient_name[2] # Add random day of year to year of birth to get dob value # Make it for the prior year so vists, tests come after birth p['dob'] = rndDate(int(p['YOB']) - 1).isoformat() # Map raw GENDER to SMART encoding values # (For the moment, SMART only handles 'male' and 'female'...) gender = 'male' if p['GENDER'] == 'M' else 'female' p['gender'] = gender p['email'] = toEmail(patient_name) # Finally, add a random address: adr = rndAddress() p = dict(p.items() + adr.items()) p['home'] = '' if randint(0, 1) else rndTelephone() p['cell'] = '' if randint(0, 1) else rndTelephone() p['gestage'] = '' if randint(0, 1) else rndGestAge() # Write out the new patient data file: # Start with the header (writing only once at the top of the file): if top: head = p.keys() print >> f, "\t".join(head) top = False # Then write out the row: print >> f, "\t".join([p[field] for field in head]) f.close()
def generate(cls,patient_file_name=RI_PATIENTS_FILE): """Generates a patient file from raw data; replaces old patients file""" # Open the patient data file for writing generated data f = open(PATIENTS_FILE,'w') top = True # Starting at the top of the file (need to write header here...) # Open the raw data file and read in the first (header) record pats = csv.reader(file(patient_file_name,'U'),dialect='excel-tab') header = pats.next() # Read in patient data: for pat in pats: p=dict((zip(header,pat))) # create patient from header and row values # Add synthetic data patient_name = rndName(p['GENDER']) p['fname']=patient_name[0] p['initial']=patient_name[1] p['lname']=patient_name[2] # Add random day of year to year of birth to get dob value # Make it for the prior year so vists, tests come after birth p['dob']=rndDate(int(p['YOB'])-1).isoformat() # Map raw GENDER to SMART encoding values # (For the moment, SMART only handles 'male' and 'female'...) gender = 'male' if p['GENDER']=='M' else 'female' p['gender'] = gender p['email'] = toEmail(patient_name) # Finally, add a random address: adr = rndAddress() p = dict(p.items() + adr.items()) p['home'] = '' if randint(0,1) else rndTelephone() p['cell'] = '' if randint(0,1) else rndTelephone() p['gestage'] = '' if randint(0,1) else rndGestAge() # Write out the new patient data file: # Start with the header (writing only once at the top of the file): if top: head = p.keys() print >>f, "\t".join(head) top = False # Then write out the row: print >>f, "\t".join([ p[field] for field in head]) f.close()
def toJSON(self, prefix=""): if prefix: prefix += "-" patient = Patient.mpi[self.pid] return { "request": { "method": "PUT", "url": "Observation/" + prefix + "smokingstatus-" + self.id }, "resource": { "id": prefix + "smokingstatus-" + self.id, "resourceType": "Observation", "status": "final", "identifier": [{ "use": "official", "system": "http://www.bmc.nl/zorgportal/identifiers/observations", "value": prefix + self.id }], "text": { "status": "generated", "div": '<div xmlns="http://www.w3.org/1999/xhtml">' + 'Tobacco smoking status: %s</div>' % self.smokingStatusText }, "performer": [{ "reference": "Practitioner/" + prefix + "Practitioner-" + patient.gp }], "effectiveDateTime": rndDate(2016).isoformat(), "code": { "coding": [{ "system": "http://loinc.org", "code": "72166-2", "display": "Tobacco smoking status" }], "text": "Tobacco smoking status" }, "subject": { "reference": "Patient/" + prefix + self.pid }, "category": [{ "coding": [{ "system": "http://hl7.org/fhir/observation-category", "code": "social-history", "display": "Social History" }], "text": "Social History" }], "valueCodeableConcept": { "coding": [{ "system": "http://snomed.info/sct", "code": self.smokingStatusCode, "display": self.smokingStatusText }], "text": self.smokingStatusText } } }