def fetch_patientlist(): if request.method == 'POST': session['patientlist'] = request.form["get-list"] app.logger.info(f'session["patientlist"]= {session["patientlist"]}') requests_object = fetch(session['patientlist']) # requests object write_out(app.root_path, "test-argo-pl-group.json", dumps(requests_object.json(), indent=4)) write_out(app.root_path, "test-argo-pl-group.yml", yaml(requests_object.json())) py_group = pyfhir(requests_object.json(), Type="Group") app.logger.info(f'group id = {py_group.id}') session['md_string'] = md_template( 'fetch_patientlist.md', base_name=session['base_name'], url_string=requests_object.url, count=requests_object.json()['quantity']) session["use_case"] = "endpoint" my_string = '''## After Fetching the List of User Facing lists, a Patient list is selected using a simple Fetch operation: <br>Click on the blue buttons below to continue...''' return render_template('group_details.html', my_intro=my_string, title="Fetch Patient List", current_time=datetime.datetime.now(), ht_offset=425, seq_ht=425, my_string=session['md_string'], pyfhir=py_group)
def remove_containers(self): delete_targets = getattr(self.args, "delete_targets") if len(delete_targets) < 1: raise ValueError("you must supply at least one container id or name to delete") force = getattr(self.args, "force") for d in delete_targets: con = self.client.containers.get(d) con.remove(force) write_out(con["id"])
def display_all_image_info(self): col_fmt = "{0:40}{1:12}{2:14}{3:18}{4:14}" write_out( col_fmt.format("REPOSITORY", "TAG", "IMAGE ID", "CREATED", "SIZE")) for i in self.client.images.list(): for r in i["repoTags"]: rsplit = r.rindex(":") name = r[0:rsplit - 1] tag = r[rsplit + 1:] write_out( col_fmt.format(name, tag, i["id"][:12], stringTimeToHuman(i["created"]), convert_size(i["size"])))
def bundle_to_file(dict_bundle, type='bundle'): write_out(app.root_path, f"test-argo-pl-{type}.json", dumps(dict_bundle, indent=4)) write_out(app.root_path, f"test-argo-pl-{type}.yml", y_dump(dict_bundle, sort_keys=False))
def fwd(): ''' reassemble message bundle: new bundle id, timestamp new messageheader.id and sender and source and destination if "intermed-no-change" is checked then add provenance for MH elif "intermed-change" is checked then add provenance for MH and and sender Org and remove coverage use prov template as dicts with variable add static text for forwarding messages ''' now = datetime.datetime.utcnow() fhir_now = FD.FHIRDate(f'{str(now.isoformat())}Z') #get existing bundle and modify app.logger.info(f'****** see what is in session = {session}') f_name = session['f_names'][-1] app.logger.info( f'line nnnn f_name list = {session["f_names"]} f_name item = {f_name}') data = read_in(in_path=app.root_path, f_name=f_name) # most recent saved bundle #data = cache.get('notification_bundle') #app.logger.info(f'data = {data}') #convert to r4models b = pyfhir(loads(data)) b.id = str(uuid.uuid1()) b.timestamp = fhir_now mh = b.entry[0].resource mh.id = str(uuid.uuid1()) b.entry[0].fullUrl = uuid.UUID(mh.id).urn mh.sender.reference = "urn:uuid:4f7c997a-d6a4-11ea-814c-b5baa7182d44" # hardcoded for now mh.sender.display = "Da Vinci Intermediary" # hardcoded for now mh.source.name = "Da Vinci Intermediary Source Application" mh.source.endpoint = "https://example.org/Endpoints/P999" mh.source.contact.system = 'phone' mh.source.contact.value = '+1-800-555-5555' session['resource_list'][0] = f'MessageHeader/{mh.id}' ################### ADD Provenance ################################SHOULD BE REMOVED NOT NEEDED ANYMORE app.logger.info( f'************intermed is {request.form["intermed"]}*************') provenance = get_prov( target=f'MessageHeader/{mh.id}', author=mh.author.reference, org=mh.responsible.reference, sender=mh.sender.reference, activity=request.form['intermed'], now=now, ) prov_entry = B.BundleEntry() prov_entry.fullUrl = uuid.UUID(provenance.id).urn prov_entry.resource = provenance b.entry.insert(1, prov_entry) session['resource_list'].insert(1, f'Provenance/{provenance.id}') ################### ADD new sender Org ################################ sender = getattr(fhirtemplates, 'sender') # hardcode org for now org = pyfhir(sender) #convert to fhirclient model add_profile(org) org_entry = B.BundleEntry() org_entry.fullUrl = uuid.UUID(org.id).urn org_entry.resource = org b.entry.append(org_entry) session['resource_list'].append(f'Organization/{org.id}') ################### Remove Coverage and Referenced Org ################################SHOULD BE REMOVED NOT NEEDED ANYMORE if request.form[ 'intermed'] == 'amend': # example for intermediary as sender with change in content try: coverage_index = next((index for (index, r) in enumerate(b.entry) if r.resource.resource_type == 'Coverage')) except StopIteration: pass else: coverage = b.entry.pop(coverage_index).resource session['resource_list'].pop(coverage_index) payor_url = coverage.payor[0].reference try: payor_index = next((index for (index, r) in enumerate(b.entry) if r.fullUrl == payor_url)) except StopIteration: pass else: b.entry.pop(payor_index) session['resource_list'].pop(payor_index) # writing to ig examples file and running the IG Build: notification_bundle = dumps(b.as_json(), indent=2) #app.logger.info(f'notification_bundle = {message_bundles[0]}') f_name = f'davinci-notification-bundle-{b.id}.json' write_out(app.root_path, f_name, notification_bundle) app.logger.info( f'writing example notification bundle to {app.root_path}/test_output/{f_name}' ) session['f_names'].append( f_name) # keep track of f_names for session to delete later session.modified = True app.logger.info(f'****** see what is in session = {session}***') return render_template( 'sub_template5.html', title="Forwarding Notification Bundle Prep", endpoint_urls=alerts_servers, endpoint='$process-message', notification_bundle=notification_bundle, b_id=b.id, forwarding=True, )
def mb(): ''' fetch encounter ids - 1 for single bundle, multiple for batching using a transaction bundle create messageheader, coverage, orgs 1 and 2 fetch graph of resources as list create bundle ''' ################### Assemble Bundle ################################ app.logger.info(f'****** line 492 see what is in session = {session}***') #app.logger.info(f'****** line 465 see what is in cache = {cache.get("encounters")}***') #encounters = cache.get("encounters") # get resources from cache session['resource_list'] = [] message_bundles = [] now = datetime.datetime.utcnow() is_message_bundle = len(session['my_encounters']) < 2 cache_notif_bundle = cache.get("notification_bundle") ################ #for loop over encounters if encounter length >1 then create transaction bundle if not is_message_bundle and cache_notif_bundle: #if cached use it instead for b in loads(cache_notif_bundle)["entry"]: session['resource_list'].append( f'{b["resource"]["resourceType"]}/{b["resource"]["id"]}') for r in b["resource"]["entry"]: session['resource_list'].append( f'{r["resource"]["resourceType"]}/{r["resource"]["id"]}') return render_template( 'sub_template5.html', my_string= 'Getting Resources ready for Tansaction Bundle of Da Vinci Notification Message Bundle...', title="Notification Bundle Prep", endpoint_urls=alerts_servers, endpoint='transaction', notification_bundle=cache_notif_bundle, b_id=loads(cache_notif_bundle)["id"], ) else: ################# for r_id, ver in session['my_encounters']: #encounters: encounter = fetch('Encounter', _id=r_id, ver=ver) #as dict encounter = pyfhir( r_dict=encounter) # convert encounter to pyfhir instance add_profile(encounter) # add profile if not already there resources = [encounter] # create messageheader mh = getattr(fhirtemplates, 'messageheader') # resources as dict mh = pyfhir(mh) #convert to fhirclient mh.id = str(uuid.uuid1()) mh.focus[0].reference = f"Encounter/{encounter.id}" if encounter.status == "in-progress" and encounter.class_fhir.code == "EMER": mh.eventCoding.code = 'notification-admit' mh.eventCoding.display = 'Notification Admit' elif encounter.status == "in-progress" and encounter.class_fhir.code == "IMP": mh.eventCoding.code = 'notification-transfer' mh.eventCoding.display = 'Notification Transfer' mh.meta.profile[1] = profile_list['MessageHeader_transfer'] elif encounter.status == "finished": mh.eventCoding.code = 'notification-discharge' mh.eventCoding.display = 'Notification Discharge' mh.meta.profile[1] = profile_list['MessageHeader_discharge'] # TODO add discharge subtypes and handle other statuses mh.focus[ 0].display = f'{mh.eventCoding.display}({encounter.type[0].text})' # mh.destination[0].name = list(alerts_servers.keys())[0] # mh.destination[0].endpoint = list(alerts_servers.values())[0] # TODO make a selection for the destination mh.sender.reference = encounter.serviceProvider.reference mh.sender.display = encounter.serviceProvider.display mh.author.reference = encounter.participant[0].individual.reference mh.author.display = encounter.participant[0].individual.display mh.responsible.reference = encounter.serviceProvider.reference mh.responsible.display = encounter.serviceProvider.display resources.insert(0, mh) for i in get_ids: # [{Type:Type, args=(args)}] Type = i['Type'] args = i['args'] is_req = i['is_req'] my_id = get_r_id(encounter, *args) app.logger.info(f'******my_id = {my_id}') resource = fetch(Type, _id=my_id, ver=None) append_resource(resource, resources, Type=Type, id=my_id, is_req=is_req) resource = search( 'Condition', patient=get_r_id(encounter, 'subject', 'reference'), encounter=encounter.id, ) # fetch condition append_resource(resource, resources, Type='Condition') resource = search( 'Coverage', patient=get_r_id(encounter, 'subject', 'reference'), ) # fetch coverage coverage = pyfhir(r_dict=resource) append_resource(resource, resources, Type='Coverage') if coverage: my_id = get_r_id(coverage, 'payor', 'reference') resource = fetch( 'Organization', _id=my_id, ) # fetch coverage append_resource(resource, resources, Type='Organization', id=my_id) # assume sender = author i.e. no separate sender initially save for intermediary # sender = getattr(fhirtemplates,'sender') # hardcode org for now # resource = pyfhir(sender) #convert to fhirclient model # add_profile(resource) # resources.append(resource) message_bundles.append(bundler( resources, 'message', validate_me)) # returns as json string! session['resource_list'] = session['resource_list'] + [ f'{r.resource_type}/{r.id}' for r in resources ] ################### End Assemble Bundle ################################ # endfor loop over encounters, if encounter length > 1 then create transaction Bundles # writing to ig examples file and running the IG Build: #f_name = f'davinci_notification_bundle_{now.strftime("%Y%m%d%H%M%S.%f")}.json' if is_message_bundle: my_string = "Getting Resources ready for Da Vinci Notification Message Bundle..." app.logger.info(f' type my_string = {type(my_string)}') notification_bundle = message_bundles[0] endpoint = '$process-message' else: ''' if message_bundles length > 2 then bundle as transaction. loop through message bundles and convert back to pyfhir object and save to array then bundle again in a transaction and get a transaction as json string back. (modify the function to do this too) ''' pyfhir_messages = [pyfhir(loads(b)) for b in message_bundles] notification_bundle = bundler(pyfhir_messages, 'transaction', validate_me) my_string = 'Getting Resources ready for Tansaction Bundle of Da Vinci Notification Message Bundle...' endpoint = 'transaction' cache.set('notification_bundle', notification_bundle) b_id = loads(notification_bundle)["id"] f_name = f'davinci-notification-bundle-{b_id}.json' write_out(app.root_path, f_name, notification_bundle) app.logger.info( f'writing example notification bundle to {app.root_path}/test_output/{f_name}' ) session['f_names'].append( f_name) # keep track of f_names for session to delete later session.modified = True app.logger.info(f'****** see what is in session = {session}***') #app.logger.info(f'notification_bundle = {message_bundles[0]}') #cache.set('notification_bundle', notification_bundle, timeout=60*15 ) #app.logger.info(f'****** line 574 see what is in cache = {cache.get("notification_bundle")}***') return render_template( 'sub_template5.html', my_string=my_string, title="Notification Bundle Prep", endpoint_urls=alerts_servers, endpoint=endpoint, notification_bundle=notification_bundle, b_id=loads(notification_bundle)["id"], )