def createTimingResource(self): from fhirclient.models import timing, fhirdate timing_resource = timing.Timing() # once(frequency) per week(period/periodUnit) repeat = timing.TimingRepeat() repeat.frequency = int(self.frequency.value) repeat.periodUnit = self.frequency.unit repeat.period = float(self.frequency.unit_period) # Start Date start_fhirdate = fhirdate.FHIRDate(self.period.start) end_fhirdate = fhirdate.FHIRDate(self.period.end) print(start_fhirdate) print(end_fhirdate) print(fhirdate.FHIRDate(self.period.start)) from fhirclient.models import period fhir_period = period.Period() fhir_period.start = start_fhirdate fhir_period.end = end_fhirdate repeat.boundsPeriod = fhir_period timing_resource.repeat = repeat return timing_resource
def get_responseperiod_x(start,end): responseperiod_x = Ext.Extension() responseperiod_x.url = 'http://fhir.org/guides/argonaut-questionnaire/StructureDefinition/extension-responsePeriod' responseperiod_x.valuePeriod = P.Period() responseperiod_x.valuePeriod.start = FD.FHIRDate(start) responseperiod_x.valuePeriod.end = FD.FHIRDate(end) return responseperiod_x
def _create_FHIRPeriod(self, start=None, end=None): """ Creates a FHIRPeriod object :param self: needed to call _create_FHIRDate method :param start: start datetime object :param end: end datetime object :returns: FHIRPeriod object """ Period = period.Period() if start is not None: Period.start = self._create_FHIRDate(start) else: Period.start = self._create_FHIRDate(datetime.datetime.now()) if end is not None: Period.end = self._create_FHIRDate(end) return Period
def create_fhir_object(self): """ method: create_fhir_object() Create a fhir-client.model.address.Adress object and stores to the self.fhir attribute :return: None """ # Initialize FHIRclient Address object # Assign Address object attributes to FHIRclient Address object fa = fhir_address.Address() if self.address1: fa.line = [self.address1] if self.address2: fa.line.append(self.address2) if self.city: fa.city = self.city if self.state: fa.state = self.state if self.zipcode: fa.postalCode = self.zipcode fa.text = self.formatted_address() if isinstance(self.start_date, date) or isinstance(self.end_date, date): p = period.Period() if self.start_date: fhirdate_start = fhirdate.FHIRDate() fhirdate_start.date = self.start_date p.start = fhirdate_start if self.end_date: fhirdate_end = fhirdate.FHIRDate() fhirdate_end.date = self.end_date p.end = fhirdate_end fa.period = p if self.use: fa.use = self.use.lower() if self.is_postal and self.is_physical: fa.type = 'both' elif self.is_postal: fa.type = 'postal' elif self.is_physical: fa.type = 'physical' if self.district: fa.district = self.district if self.country: fa.country = self.country self.fhir = fa
def to_fhir(self) -> period.Period: fhir_period = period.Period() fhir_period.start = self.start.to_fhir() fhir_period.end = self.end.to_fhir() return fhir_period
if __name__ == "__main__": ct = ClinicalStudy.from_file("examples/NCT02348489.xml", local_schema=True) locations = [build_location(x) for x in ct.locations] foci = build_focus(ct.mesh_terms) print([x.as_json() for x in foci]) keywords = build_keyword(ct.keywords) print([x.as_json() for x in keywords]) identifiers = build_identifiers(ct.nct_id, ct.study_id, ct.secondary_id) print([x.as_json() for x in identifiers]) package = bundle.Bundle() package.type = "document" package.identifier = identifier.Identifier( dict(use='official', system="https://clinicaltrials.gov/ct2/show/", value=ct.nct_id)) entries = [] for location in locations: be = bundle.BundleEntry() be.resource_type = "Location" be.resource = location entries.append(be) study = researchstudy.ResearchStudy() study.identifier = identifiers print("Study Identifier: ", type(study.identifier[0])) study.period = period.Period( dict(start=ct.trail.study_first_posted.date.strftime("%Y-%m-%d"))) study.status = build_status(ct.status) entries.append(study) package.entry = entries print(json.dumps(package.as_json(), indent=4, separators=(',', ': ')))
def to_fhir(self): effective_period = period.Period() effective_period.start = self.start effective_period.end = self.end return effective_period
def make_appts(op, slot=None): # create Appt based on slot data logging.info('slot as json = {}', format(json.dumps(slot.as_json(), sort_keys=True, indent=4))) appt = Appt.Appointment() appt.id = '{}{}'.format(slot.id, timestamp()) appt.status = 'proposed' try: # mapping serviceType appt.serviceType = [] # codeable pattern for concept in slot.serviceType: appt.serviceType.append(map_cc(concept)) except TypeError: # element missing pass try: # mapping specialty appt.specialty = [] # codeable pattern for concept in slot.specialty: # only the first translation for now appt.specialty.append(map_cc(concept)) except TypeError: # element missing pass # mapping appointmetType try: concept = slot.appointmentType appt.appointmentType = map_cc(concept) except AttributeError: # element missing pass try: appt.reason = [] for concept in op['reason']: # create CodeableConcept based on op data - just text for now appt.reason.append = (CC.CodeableConcept({'text': concept})) except KeyError: # op missing pass appt.start = slot.start appt.end = slot.end appt.slot = [FRef.FHIRReference({'reference': 'Slot/{}'.format(slot.id)})] # option a appt.participant = [] ''' assume a list of participant references from op 'practitioner':[], 'organization':[], 'location-reference':[], 'patient-reference':[], 'patient-resource':[], do this one later... ''' try: for url in op['practitioner']: logging.info('practitioner is = {}'.format(op)) appt.participant.append(map_part(url)) except KeyError: pass try: for url in op['organization']: appt.participant.append(map_part(url)) except KeyError: pass try: for url in op['location-reference']: appt.participant.append(map_part(url)) except KeyError: pass try: for url in op['patient-reference']: #TODO add patient stub in for now appt.participant.append(map_part(url)) except KeyError: pass # mapping this comes from the query parameter to requested period there is only one and is required pd = Period.Period() fd = FDate.FHIRDate() try: fd.origval = op['start'] # start sp pd.start = fd except KeyError: fd.origval = '2017-09-07' # start sp pd.start = fd try: fd.origval = op['end'] # end sp pd.end = fd except KeyError: pass appt.requestedPeriod = [] appt.requestedPeriod.append(pd) return (appt)
def createPractitioner(dohmpifield, record): #extract fields from dohmpi from database field = [] for i in range(len(dohmpifield)): f1, = dohmpifield[i] # dohmpi loads from db as a list of onetuples. field.append(f1) # we make a traditional list to refer to. fnamei = field.index('provider_first') lnamei = field.index('provider_last') genderi = field.index('provider_gender_cd') deathyi = field.index('deathccyy') deathmi = field.index('deathmm') deathdi = field.index('deathdd') birthi = field.index('provider_dob_dob') provi = field.index('provider_license_no') # record is one record from the postgres db import fhirclient.models.practitioner as p # set practitioner id as provider licence numberS p = p.Practitioner({'id': record[provi]}) # resolve name import fhirclient.models.humanname as hn name = hn.HumanName() name.given = [record[fnamei]] name.family = [record[lnamei]] p.name = name # resolve gender if (record[genderi] == "1"): p.gender = 'male' elif (record[genderi] == "2"): p.gender = 'female' else: p.gender = 'unknown' # build and resolve birthdate birthdate = record[birthi] bsep1 = birthdate.index("/") bsep2 = birthdate.index("/", bsep1 + 1) birthdate = birthdate[-4:] + "-" + birthdate[0:bsep1] + "-" + birthdate[ bsep1 + 1:bsep2] p.birthDate = fhirclient.models.fhirdate.FHIRDate(birthdate) # build and resolve death date tz = "00:00:00-0600" # Utah is in the Mountain Time Zone, setting time as midnight. yyyy = record[deathyi] mm = record[deathmi] if (len(mm) < 2): mm = "0%s" % mm dd = record[deathdi] if (len(dd) < 2): dd = "0%s" % dd deathdate = "%s-%s-%sT%s" % (yyyy, mm, dd, tz) deathdate = fhirclient.models.fhirdate.FHIRDate(deathdate) # Create period import fhirclient.models.period as per per = per.Period() per.start = deathdate import fhirclient.models.fhirreference as ref location = ref.FHIRReference() location.reference = 'http://fhir.ehoth.net/deceased' location.display = 'deceased' # Create role import fhirclient.models.practitioner as r role = r.PractitionerPractitionerRole() role.healthcareservice = 'deceased' role.location = [location] role.period = per role.managingOrganization = location #print role.as_json() p.practitionerRole = [role] # return practitioner. return p
def createPatient(dohmpifield, record): #extract fields from dohmpi from database field = [] for i in range(len(dohmpifield)): f1, = dohmpifield[i] # dohmpi loads from db as a list of onetuples. field.append(f1) # we make a traditional list to refer to. fnamei = field.index('provider_first') lnamei = field.index('provider_last') genderi = field.index('provider_gender_cd') deathyi = field.index('deathccyy') deathmi = field.index('deathmm') deathdi = field.index('deathdd') birthi = field.index('provider_dob_dob') provi = field.index('provider_license_no') # record is one record from the postgres db import fhirclient.models.patient as p # set patient id as provider licence numberS pid = record[provi] p = p.Patient({}) import fhirclient.models.identifier as idf identifier = idf.Identifier() identifier.value = pid p.identifier = [identifier] # resolve name import fhirclient.models.humanname as hn name = hn.HumanName() name.given = [record[fnamei]] name.family = [record[lnamei]] p.name = [name] #[name.family, name.given] # resolve gender if (record[genderi] == "1"): p.gender = 'male' elif (record[genderi] == "2"): p.gender = 'female' else: p.gender = 'unknown' # build and resolve birthdate birthdate = record[birthi] bsep1 = birthdate.index("/") bsep2 = birthdate.index("/", bsep1 + 1) year = birthdate[-4:] month = birthdate[0:bsep1] if (len(month) < 2): month = "0%s" % month date = birthdate[bsep1 + 1:bsep2] if (len(date) < 2): date = "0%s" % date birthdate = year + "-" + month + "-" + date p.birthDate = fhirclient.models.fhirdate.FHIRDate(birthdate) # build and resolve death date tt = "12:00:00" #Setting time to noon yyyy = record[deathyi] mm = record[deathmi] if (len(mm) < 2): mm = "0%s" % mm dd = record[deathdi] if (len(dd) < 2): dd = "0%s" % dd deathdate = "%s-%s-%sT%s" % (yyyy, mm, dd, tt) deathdate = fhirclient.models.fhirdate.FHIRDate(deathdate) # Create period import fhirclient.models.period as per per = per.Period() per.start = deathdate p.deceasedBoolean = True p.deceasedDateTime = deathdate return p